Skip to content

Commit

Permalink
[MM-45894] Allow signaling through data channel (#865)
Browse files Browse the repository at this point in the history
* Allow signaling through data channel

* Update i18n

* Update calls-common

* DC messages (#870)

* Replace pako with faster fflate

* Mitigate signaling race

* Update dependencies

* Fix jest

* [MM-60561] RTC client metrics (#874)

* lt: add incoming track handler

* Enable RTC monitor in lt client

* Update dependencies

* Update server mocks

* Bump dependencies

* Update snapshots
  • Loading branch information
streamer45 authored Oct 9, 2024
1 parent 9b0129f commit 7a32972
Show file tree
Hide file tree
Showing 22 changed files with 336 additions and 71 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/Masterminds/semver v1.5.0
github.com/go-sql-driver/mysql v1.7.1
github.com/gorilla/mux v1.8.1
github.com/grafana/pyroscope-go/godeltaprof v0.1.7
github.com/grafana/pyroscope-go/godeltaprof v0.1.8
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.9
github.com/mattermost/calls-offloader v0.8.1-0.20240925183132-f81d68d229b8
Expand All @@ -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.17.2-0.20240925183117-466f6a8ed02f
github.com/mattermost/rtcd v0.17.2-0.20241009214839-a44d499cefcc
github.com/mattermost/squirrel v0.2.0
github.com/pkg/errors v0.9.1
github.com/rudderlabs/analytics-go v3.3.3+incompatible
Expand Down Expand Up @@ -76,7 +76,7 @@ require (
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/compress v1.17.10 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lufia/plan9stats v0.0.0-20240513124658-fba389f38bae // indirect
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWS
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/grafana/pyroscope-go/godeltaprof v0.1.7 h1:C11j63y7gymiW8VugJ9ZW0pWfxTZugdSJyC48olk5KY=
github.com/grafana/pyroscope-go/godeltaprof v0.1.7/go.mod h1:Tk376Nbldo4Cha9RgiU7ik8WKFkNpfds98aUzS8omLE=
github.com/grafana/pyroscope-go/godeltaprof v0.1.8 h1:iwOtYXeeVSAeYefJNaxDytgjKtUuKQbJqgAIjlnicKg=
github.com/grafana/pyroscope-go/godeltaprof v0.1.8/go.mod h1:2+l7K7twW49Ct4wFluZD3tZ6e0SjanjcUUBPVD/UuGU=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
Expand Down Expand Up @@ -335,9 +335,8 @@ github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:C
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.17.3/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
Expand Down Expand Up @@ -380,8 +379,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.17.2-0.20240925183117-466f6a8ed02f h1:bJiMgr9Lub1HR0S8yQ/QeXRlHUd0WmmYek72hW3sTk8=
github.com/mattermost/rtcd v0.17.2-0.20240925183117-466f6a8ed02f/go.mod h1:twellAs4hvfjDI/8PIq5viG5ej2zoBzvTGzFscbjKZc=
github.com/mattermost/rtcd v0.17.2-0.20241009214839-a44d499cefcc h1:KTdzXsjcrnawYH2uNwLW8WVe0vyYmuC8ckpR83Cj7Sg=
github.com/mattermost/rtcd v0.17.2-0.20241009214839-a44d499cefcc/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=
Expand Down
45 changes: 41 additions & 4 deletions lt/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,10 @@ func (u *User) Speak(text string) chan struct{} {
}

func (u *User) onConnect() {
// Waiting a second before transmitting to avoid
// the known race between incoming and outgoing track.
// This is needed as pion doesn't support perfect negotiation yet.
time.Sleep(time.Second)
if u.cfg.Unmuted {
go u.transmitAudio()
} else if u.cfg.Speak {
Expand Down Expand Up @@ -509,6 +513,33 @@ func (u *User) getCallsConfig() (map[string]any, error) {
return config, nil
}

func (u *User) handleTrack(ctx any) error {
m, ok := ctx.(map[string]any)
if !ok || m == nil {
return fmt.Errorf("failed to convert map")
}

track, ok := m["track"].(*webrtc.TrackRemote)
if !ok || track == nil {
return fmt.Errorf("failed to convert track")
}

// We don't currently do anything with the packets but we should still read
// them to properly calculate client stats.
buf := make([]byte, receiveMTU)
for {
_, _, readErr := track.Read(buf)
if readErr != nil {
if !errors.Is(readErr, io.EOF) {
u.log.Error("failed to read RTP packet for track",
slog.String("err", readErr.Error()),
slog.String("trackID", track.ID()))
}
return nil
}
}
}

func (u *User) Connect(stopCh chan struct{}) error {
u.log.Debug("connecting user")

Expand Down Expand Up @@ -597,16 +628,22 @@ func (u *User) Connect(stopCh chan struct{}) error {
u.callsConfig = callsConfig

enableAV1, _ := u.callsConfig["EnableAV1"].(bool)
enableDCSignaling, _ := u.callsConfig["EnableDCSignaling"].(bool)

callsClient, err := client.New(client.Config{
SiteURL: u.cfg.SiteURL,
AuthToken: apiClient.AuthToken,
ChannelID: u.cfg.ChannelID,
EnableAV1: enableAV1,
SiteURL: u.cfg.SiteURL,
AuthToken: apiClient.AuthToken,
ChannelID: u.cfg.ChannelID,
EnableAV1: enableAV1,
EnableDCSignaling: enableDCSignaling,
EnableRTCMonitor: true,
}, client.WithLogger(u.log))
if err != nil {
return fmt.Errorf("failed to create calls client: %w", err)
}
if err := callsClient.On(client.RTCTrackEvent, u.handleTrack); err != nil {
return fmt.Errorf("failed to add track handler: %w", err)
}

u.callsClient = callsClient

Expand Down
2 changes: 1 addition & 1 deletion lt/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/aws/aws-sdk-go v1.50.3
github.com/hajimehoshi/go-mp3 v0.3.4
github.com/mattermost/mattermost/server/public v0.0.12
github.com/mattermost/rtcd v0.17.2-0.20240925183117-466f6a8ed02f
github.com/mattermost/rtcd v0.17.2-0.20241009214839-a44d499cefcc
github.com/pion/rtp v1.8.6
github.com/pion/webrtc/v3 v3.2.41
gopkg.in/hraban/opus.v2 v2.0.0-20230925203106-0188a62cb302
Expand Down
4 changes: 2 additions & 2 deletions lt/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ github.com/mattermost/logr/v2 v2.0.21 h1:CMHsP+nrbRlEC4g7BwOk1GAnMtHkniFhlSQPXy5
github.com/mattermost/logr/v2 v2.0.21/go.mod h1:kZkB/zqKL9e+RY5gB3vGpsyenC+TpuiOenjMkvJJbzc=
github.com/mattermost/mattermost/server/public v0.0.12 h1:iunc9q4/XkArOrndEUn73uFw6v9TOEXEtp6Nm6Iv218=
github.com/mattermost/mattermost/server/public v0.0.12/go.mod h1:Bk+atJcELCIk9Yeq5FoqTr+gra9704+X4amrlwlTgSc=
github.com/mattermost/rtcd v0.17.2-0.20240925183117-466f6a8ed02f h1:bJiMgr9Lub1HR0S8yQ/QeXRlHUd0WmmYek72hW3sTk8=
github.com/mattermost/rtcd v0.17.2-0.20240925183117-466f6a8ed02f/go.mod h1:twellAs4hvfjDI/8PIq5viG5ej2zoBzvTGzFscbjKZc=
github.com/mattermost/rtcd v0.17.2-0.20241009214839-a44d499cefcc h1:KTdzXsjcrnawYH2uNwLW8WVe0vyYmuC8ckpR83Cj7Sg=
github.com/mattermost/rtcd v0.17.2-0.20241009214839-a44d499cefcc/go.mod h1:FVyFLa+7dWImCZ+0g9xoc/1fMRKMuXs6yAZP1mDKBIg=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00vh2OMYv+xgHpAMF4=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
14 changes: 14 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@
"type": "bool",
"default": false,
"help_text": "When set to true it enables using the AV1 codec to encode screen sharing tracks. This can result in improved screen sharing quality for clients that support it.\nNote: this setting won't apply when EnableSimulcast is true."
},
{
"key": "EnableDCSignaling",
"display_name": "Use data channels for signaling (Experimental)",
"type": "bool",
"default": false,
"help_text": "When set to true, clients will use WebRTC data channels for signaling of new media tracks. This can result in a more efficient and less race-prone process, especially in case of frequent WebSocket disconnections."
}
]
},
Expand Down Expand Up @@ -676,6 +683,13 @@
"type": "bool",
"default": false,
"help_text": "When set to true it enables using the AV1 codec to encode screen sharing tracks. This can result in improved screen sharing quality for clients that support it.\nNote: this setting won't apply when EnableSimulcast is true."
},
{
"key": "EnableDCSignaling",
"display_name": "Use data channels for signaling (Experimental)",
"type": "bool",
"default": false,
"help_text": "When set to true, clients will use WebRTC data channels for signaling of new media tracks. This can result in a more efficient and less race-prone process, especially in case of frequent WebSocket disconnections."
}
]
},
Expand Down
10 changes: 10 additions & 0 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ type clientConfig struct {
EnableAV1 *bool
// Let the server determine whether or not group calls are allowed (through license checks or otherwise)
GroupCallsAllowed bool
// When set to true it enables experimental support for using the data channel for signaling.
EnableDCSignaling *bool
}

type adminClientConfig struct {
Expand Down Expand Up @@ -265,6 +267,9 @@ func (c *configuration) SetDefaults() {
if c.EnableAV1 == nil {
c.EnableAV1 = model.NewBool(false)
}
if c.EnableDCSignaling == nil {
c.EnableDCSignaling = model.NewBool(false)
}
}

func (c *configuration) IsValid() error {
Expand Down Expand Up @@ -453,6 +458,10 @@ func (c *configuration) Clone() *configuration {
cfg.EnableAV1 = model.NewBool(*c.EnableAV1)
}

if c.EnableDCSignaling != nil {
cfg.EnableDCSignaling = model.NewBool(*c.EnableDCSignaling)
}

return &cfg
}

Expand Down Expand Up @@ -517,6 +526,7 @@ func (p *Plugin) getClientConfig(c *configuration) clientConfig {
HostControlsAllowed: p.licenseChecker.HostControlsAllowed(),
EnableAV1: c.EnableAV1,
GroupCallsAllowed: p.licenseChecker.GroupCallsAllowed(),
EnableDCSignaling: c.EnableDCSignaling,
}
}

Expand Down
102 changes: 102 additions & 0 deletions server/mocks/github.com/mattermost/rtcd/service/rtc/mock_Metrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7a32972

Please sign in to comment.