diff --git a/go.mod b/go.mod index c1563251..493355c9 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/mattermost/mattermost-plugin-calls/server/public v0.0.3 github.com/mattermost/mattermost/server/public v0.1.5-0.20240613070149-4b0ae20ef7b4 github.com/mattermost/morph v1.1.0 - github.com/mattermost/rtcd v0.18.0 + github.com/mattermost/rtcd v0.18.1-0.20241122194949-fc76bf6a2f16 github.com/mattermost/squirrel v0.2.0 github.com/pkg/errors v0.9.1 github.com/rudderlabs/analytics-go v3.3.3+incompatible diff --git a/go.sum b/go.sum index 489801d0..968621eb 100644 --- a/go.sum +++ b/go.sum @@ -375,8 +375,8 @@ github.com/mattermost/mattermost/server/public v0.1.5-0.20240613070149-4b0ae20ef github.com/mattermost/mattermost/server/public v0.1.5-0.20240613070149-4b0ae20ef7b4/go.mod h1:PDPb/iqzJJ5ZvK/m70oDF55AXN/cOvVFj96Yu4e6j+Q= github.com/mattermost/morph v1.1.0 h1:Q9vrJbeM3s2jfweGheq12EFIzdNp9a/6IovcbvOQ6Cw= github.com/mattermost/morph v1.1.0/go.mod h1:gD+EaqX2UMyyuzmF4PFh4r33XneQ8Nzi+0E8nXjMa3A= -github.com/mattermost/rtcd v0.18.0 h1:Wxbl8r8cq8hD4ufg0XUGXM8lHPzxNW73fw4SngCuJ+A= -github.com/mattermost/rtcd v0.18.0/go.mod h1:FVyFLa+7dWImCZ+0g9xoc/1fMRKMuXs6yAZP1mDKBIg= +github.com/mattermost/rtcd v0.18.1-0.20241122194949-fc76bf6a2f16 h1:3LonE6UDF+GT4LjC1hqPL1xLBORoHdxeid1VNmmZkIE= +github.com/mattermost/rtcd v0.18.1-0.20241122194949-fc76bf6a2f16/go.mod h1:FVyFLa+7dWImCZ+0g9xoc/1fMRKMuXs6yAZP1mDKBIg= github.com/mattermost/squirrel v0.2.0 h1:8ZWeyf+MWQ2cL7hu9REZgLtz2IJi51qqZEovI3T3TT8= github.com/mattermost/squirrel v0.2.0/go.mod h1:NPPtk+CdpWre4GxMGoOpzEVFVc0ZoEFyJBZGCtn9nSU= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= diff --git a/server/activate.go b/server/activate.go index 615107e3..6b419dac 100644 --- a/server/activate.go +++ b/server/activate.go @@ -8,6 +8,7 @@ import ( "fmt" "os" "path/filepath" + "runtime" "github.com/mattermost/mattermost-plugin-calls/server/cluster" "github.com/mattermost/mattermost-plugin-calls/server/enterprise" @@ -157,50 +158,47 @@ func (p *Plugin) OnActivate() (retErr error) { p.LogDebug("rtcd client manager initialized successfully") p.rtcdManager = rtcdManager + } else { + rtcServerConfig := rtc.ServerConfig{ + ICEAddressUDP: cfg.UDPServerAddress, + ICEAddressTCP: cfg.TCPServerAddress, + ICEPortUDP: *cfg.UDPServerPort, + ICEPortTCP: *cfg.TCPServerPort, + ICEHostOverride: cfg.ICEHostOverride, + ICEServers: rtc.ICEServers(cfg.getICEServers(false)), + TURNConfig: rtc.TURNConfig{ + CredentialsExpirationMinutes: *cfg.TURNCredentialsExpirationMinutes, + }, + EnableIPv6: *cfg.EnableIPv6, + UDPSocketsCount: runtime.NumCPU(), + } + if *cfg.ServerSideTURN { + rtcServerConfig.TURNConfig.StaticAuthSecret = cfg.TURNStaticAuthSecret + } + if cfg.ICEHostPortOverride != nil { + rtcServerConfig.ICEHostPortOverride = rtc.ICEHostPortOverride(fmt.Sprintf("%d", *cfg.ICEHostPortOverride)) + } + rtcServer, err := rtc.NewServer(rtcServerConfig, newLogger(p), p.metrics.RTCMetrics()) + if err != nil { + p.LogError(err.Error()) + return err + } - go p.clusterEventsHandler() - - p.LogDebug("activated", "ClusterID", status.ClusterId) - - return nil - } + if err := rtcServer.Start(); err != nil { + p.LogError(err.Error()) + return err + } - rtcServerConfig := rtc.ServerConfig{ - ICEAddressUDP: cfg.UDPServerAddress, - ICEAddressTCP: cfg.TCPServerAddress, - ICEPortUDP: *cfg.UDPServerPort, - ICEPortTCP: *cfg.TCPServerPort, - ICEHostOverride: cfg.ICEHostOverride, - ICEServers: rtc.ICEServers(cfg.getICEServers(false)), - TURNConfig: rtc.TURNConfig{ - CredentialsExpirationMinutes: *cfg.TURNCredentialsExpirationMinutes, - }, - EnableIPv6: *cfg.EnableIPv6, - } - if *cfg.ServerSideTURN { - rtcServerConfig.TURNConfig.StaticAuthSecret = cfg.TURNStaticAuthSecret - } - if cfg.ICEHostPortOverride != nil { - rtcServerConfig.ICEHostPortOverride = rtc.ICEHostPortOverride(fmt.Sprintf("%d", *cfg.ICEHostPortOverride)) - } - rtcServer, err := rtc.NewServer(rtcServerConfig, newLogger(p), p.metrics.RTCMetrics()) - if err != nil { - p.LogError(err.Error()) - return err - } + p.rtcServer = rtcServer - if err := rtcServer.Start(); err != nil { - p.LogError(err.Error()) - return err + go p.wsWriter() } p.mut.Lock() p.nodeID = status.ClusterId - p.rtcServer = rtcServer p.mut.Unlock() go p.clusterEventsHandler() - go p.wsWriter() p.LogDebug("activated", "ClusterID", status.ClusterId) diff --git a/server/websocket_test.go b/server/websocket_test.go index a4fb90ff..77c42c42 100644 --- a/server/websocket_test.go +++ b/server/websocket_test.go @@ -7,6 +7,7 @@ import ( "fmt" "net/http" "os" + "runtime" "sync" "testing" "time" @@ -678,8 +679,9 @@ func TestHandleJoin(t *testing.T) { mock.Anything, mock.Anything, mock.Anything, mock.Anything) rtcServer, err := rtc.NewServer(rtc.ServerConfig{ - ICEPortUDP: 33443, - ICEPortTCP: 33443, + ICEPortUDP: 33443, + ICEPortTCP: 33443, + UDPSocketsCount: runtime.NumCPU(), }, newLogger(&p), p.metrics.RTCMetrics()) require.NoError(t, err)