From e3f10d8b24efa8cdbf0bb32d4c42a093bca40cdf Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 1 Apr 2022 10:44:33 +0200 Subject: [PATCH] webrtc: add 'wait' option to disable waiting for initial connection establishment --- .../components/schemas/config/nodes/webrtc.yaml | 6 ++++++ go/pkg/nodes/webrtc/node.go | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/openapi/components/schemas/config/nodes/webrtc.yaml b/doc/openapi/components/schemas/config/nodes/webrtc.yaml index 17122dd35..8b6cd1e27 100644 --- a/doc/openapi/components/schemas/config/nodes/webrtc.yaml +++ b/doc/openapi/components/schemas/config/nodes/webrtc.yaml @@ -7,6 +7,12 @@ allOf: format: $ref: ../format_spec.yaml + wait: + type: boolean + default: true + description: | + Suspend start-up of VILLASnode until the connection with the remote peer has been established. + session: type: string title: Session indentifier diff --git a/go/pkg/nodes/webrtc/node.go b/go/pkg/nodes/webrtc/node.go index 9cb2e7e22..c763496ce 100644 --- a/go/pkg/nodes/webrtc/node.go +++ b/go/pkg/nodes/webrtc/node.go @@ -41,6 +41,7 @@ var ( Host: "villas.k8s.eonerc.rwth-aachen.de", Path: "/ws/signaling", }, + Wait: true, WebRTC: webrtc.Configuration{ ICEServers: []webrtc.ICEServer{ { @@ -79,6 +80,8 @@ type Config struct { Server *url.URL Session string + Wait bool + WebRTC webrtc.Configuration } @@ -93,6 +96,7 @@ func (n *Node) Parse(c []byte) error { var cfg struct { Session *string `json:"session"` Server *string `json:"server,omitempty"` + Wait *bool `json:"wait,omitemty"` Ice *struct { Servers []struct { URLs []string `json:"urls,omitempty"` @@ -106,6 +110,10 @@ func (n *Node) Parse(c []byte) error { return fmt.Errorf("failed to unmarshal config: %w", err) } + if cfg.Wait != nil { + n.Config.Wait = *cfg.Wait + } + if cfg.Session == nil || *cfg.Session == "" { return errors.New("missing or invalid session name") } else { @@ -153,9 +161,11 @@ func (n *Node) Start() error { n.DataChannelLock.Lock() defer n.DataChannelLock.Unlock() - n.Logger.Info("Waiting until datachannel is connected...") - for n.DataChannel == nil { - n.DataChannelConnected.Wait() + if n.Config.Wait { + n.Logger.Info("Waiting until datachannel is connected...") + for n.DataChannel == nil { + n.DataChannelConnected.Wait() + } } return n.BaseNode.Start()