diff --git a/server/activate.go b/server/activate.go index 5d70bc6c..a11be467 100644 --- a/server/activate.go +++ b/server/activate.go @@ -145,6 +145,10 @@ func (p *Plugin) OnActivate() (retErr error) { }() } + // rtcServer and rtcdManager are mutually exclusive throughout the entire lifetime of the plugin. + // Which one is used is decided here, during activation. + // We first check if RTCD is configured and allowed by the license. If so + // we try to initialize its connection and fail to start the plugin if that errors. if rtcdURL := cfg.getRTCDURL(); rtcdURL != "" && p.licenseChecker.RTCDAllowed() { rtcdManager, err := p.newRTCDClientManager(rtcdURL) if err != nil { @@ -186,15 +190,22 @@ func (p *Plugin) OnActivate() (retErr error) { return err } + // NodeID is set only when using the embedded service (no RTCD) since it's used to track which node is hosting + // a call and coordinate between nodes they may own the WS connection for other sessions in that same call. + // When RTCD is in place, there isn't a node hosting a call since this task is completely delegated to the RTCD side. + // Hence, in that case this field should be left empty. + p.nodeID = status.ClusterId + p.rtcServer = rtcServer + // The wsWriter routine is only necessary when running the embedded RTC server since + // it's a listener on rtcServer.ReceiveCh used to forward RTC messages (e.g. signaling) + // back to the client through the WS connection. The RTCD handler has a separate way to + // do this (see clientReader method). go p.wsWriter() } - p.mut.Lock() - p.nodeID = status.ClusterId - p.mut.Unlock() - + // Cluster events need to be handled regardless of whether the embedded RTC service or RTCD are in use. go p.clusterEventsHandler() p.LogDebug("activated", "ClusterID", status.ClusterId)