Skip to content

Commit

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

* Wrap tests

* DC messages (#158)

* Implement data channel message type

* Update client implementation

* Update godeltaprof

* Fix dc init race

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

* Client metrics

* Implement rtc stats monitor

* Remove unnecessary parenthesis
  • Loading branch information
streamer45 authored Oct 9, 2024
1 parent 466f6a8 commit a44d499
Show file tree
Hide file tree
Showing 21 changed files with 1,197 additions and 338 deletions.
423 changes: 219 additions & 204 deletions client/api_test.go

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions client/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

func (c *Client) joinCall() error {
if err := c.SendWS(wsEventJoin, CallJoinMessage{
ChannelID: c.cfg.ChannelID,
JobID: c.cfg.JobID,
AV1Support: c.cfg.EnableAV1,
ChannelID: c.cfg.ChannelID,
JobID: c.cfg.JobID,
AV1Support: c.cfg.EnableAV1,
DCSignaling: c.cfg.EnableDCSignaling,
}, false); err != nil {
return fmt.Errorf("failed to send ws msg: %w", err)
}
Expand Down
7 changes: 6 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ type Client struct {

// WebRTC
pc *webrtc.PeerConnection
dc *webrtc.DataChannel
dc atomic.Pointer[webrtc.DataChannel]
iceCh chan webrtc.ICECandidateInit
receivers map[string][]*webrtc.RTPReceiver
voiceSender *webrtc.RTPSender
screenTransceivers []*webrtc.RTPTransceiver
rtcMon *rtcMonitor

state int32

Expand Down Expand Up @@ -225,6 +226,10 @@ func (c *Client) emit(eventType EventType, ctx any) {
func (c *Client) close() {
atomic.StoreInt32(&c.state, clientStateClosed)

if c.rtcMon != nil {
c.rtcMon.Stop()
}

if c.pc != nil {
if err := c.pc.Close(); err != nil {
c.log.Error("failed to close peer connection", slog.String("err", err.Error()))
Expand Down
5 changes: 5 additions & 0 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ type Config struct {
// EnableAV1 controls whether the client should advertise support
// for receiving the AV1 codec.
EnableAV1 bool
// EnableDCSignaling controls whether the client should use data channels
// for signaling of media tracks.
EnableDCSignaling bool
// EnableRTCMonitor controls whether the RTC monitor component should be enabled.
EnableRTCMonitor bool

wsURL string
}
Expand Down
14 changes: 8 additions & 6 deletions client/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,19 @@ func setupTestHelper(tb testing.TB, channelName string) *TestHelper {
}

th.adminClient, err = New(Config{
SiteURL: th.apiURL,
AuthToken: th.adminAPIClient.AuthToken,
ChannelID: channelID,
SiteURL: th.apiURL,
AuthToken: th.adminAPIClient.AuthToken,
ChannelID: channelID,
EnableRTCMonitor: true,
}, WithLogger(logger))
require.NoError(tb, err)
require.NotNil(tb, th.adminClient)

th.userClient, err = New(Config{
SiteURL: th.apiURL,
AuthToken: th.userAPIClient.AuthToken,
ChannelID: channelID,
SiteURL: th.apiURL,
AuthToken: th.userAPIClient.AuthToken,
ChannelID: channelID,
EnableRTCMonitor: true,
}, WithLogger(logger))
require.NoError(tb, err)
require.NotNil(tb, th.userClient)
Expand Down
Loading

0 comments on commit a44d499

Please sign in to comment.