@@ -2,22 +2,30 @@ package conference
22
33import (
44 "github.com/pion/webrtc/v3"
5+ "github.com/sirupsen/logrus"
56 "golang.org/x/exp/slices"
67 "maunium.net/go/mautrix/event"
78)
89
9- // Handle the `SFUMessage` event from the DataChannel message.
10- func (c * Conference ) processSelectDCMessage (participant * Participant , msg event.SFUMessage ) {
11- participant .logger .Info ("Received select request over DC" )
10+ // Handle the `FocusEvent` from the DataChannel message.
11+ func (c * Conference ) processTrackSubscriptionDCMessage (
12+ participant * Participant , msg event.FocusCallTrackSubscriptionEventContent ,
13+ ) {
14+ participant .logger .Info ("Received track subscription request over DC" )
1215
1316 // Find tracks based on what we were asked for.
14- tracks := c .getTracks (msg .Start )
17+ tracks := c .getTracks (msg .Subscribe )
18+
19+ participant .logger .WithFields (logrus.Fields {
20+ "tracks_we_got" : tracks ,
21+ "tracks_we_want" : msg ,
22+ }).Debug ("Tracks to subscribe to" )
1523
1624 // Let's check if we have all the tracks that we were asked for are there.
1725 // If not, we will list which are not available (later on we must inform participant
1826 // about it unless the participant retries it).
19- if len (tracks ) != len (msg .Start ) {
20- for _ , expected := range msg .Start {
27+ if len (tracks ) != len (msg .Subscribe ) {
28+ for _ , expected := range msg .Subscribe {
2129 found := slices .IndexFunc (tracks , func (track * webrtc.TrackLocalStaticRTP ) bool {
2230 return track .ID () == expected .TrackID
2331 })
@@ -28,47 +36,61 @@ func (c *Conference) processSelectDCMessage(participant *Participant, msg event.
2836 }
2937 }
3038
31- // Subscribe to the found tracks.
39+ // Subscribe to the found tracks
3240 for _ , track := range tracks {
41+ participant .logger .WithField ("track_id" , track .ID ()).Debug ("Subscribing to track" )
3342 if err := participant .peer .SubscribeTo (track ); err != nil {
3443 participant .logger .Errorf ("Failed to subscribe to track: %v" , err )
3544 return
3645 }
3746 }
38- }
39-
40- func (c * Conference ) processAnswerDCMessage (participant * Participant , msg event.SFUMessage ) {
41- participant .logger .Info ("Received SDP answer over DC" )
4247
43- if err := participant .peer .ProcessSDPAnswer (msg .SDP ); err != nil {
44- participant .logger .Errorf ("Failed to set SDP answer: %v" , err )
45- return
46- }
48+ // TODO: Handle unsubscribe
4749}
4850
49- func (c * Conference ) processPublishDCMessage (participant * Participant , msg event.SFUMessage ) {
50- participant .logger . Info ( "Received SDP offer over DC" )
51+ func (c * Conference ) processNegotiateDCMessage (participant * Participant , msg event.FocusCallNegotiateEventContent ) {
52+ participant .streamMetadata = msg . SDPStreamMetadata
5153
52- answer , err := participant .peer .ProcessSDPOffer (msg .SDP )
53- if err != nil {
54- participant .logger .Errorf ("Failed to set SDP offer: %v" , err )
55- return
56- }
54+ if msg .Description .Type == event .CallDataTypeOffer {
55+ participant .logger .Info ("Received SDP offer over DC" )
5756
58- participant .streamMetadata = msg .Metadata
57+ answer , err := participant .peer .ProcessSDPOffer (msg .Description .SDP )
58+ if err != nil {
59+ participant .logger .Errorf ("Failed to set SDP offer: %v" , err )
60+ return
61+ }
62+
63+ participant .sendDataChannelMessage (event.Event {
64+ Type : event .FocusCallNegotiate ,
65+ Content : event.Content {
66+ Parsed : event.FocusCallNegotiateEventContent {
67+ Description : event.CallData {
68+ Type : event .CallDataType (answer .Type .String ()),
69+ SDP : answer .SDP ,
70+ },
71+ SDPStreamMetadata : c .getAvailableStreamsFor (participant .id ),
72+ },
73+ },
74+ })
75+ } else if msg .Description .Type == event .CallDataTypeAnswer {
76+ participant .logger .Info ("Received SDP answer over DC" )
5977
60- participant .sendDataChannelMessage (event.SFUMessage {
61- Op : event .SFUOperationAnswer ,
62- SDP : answer .SDP ,
63- Metadata : c .getAvailableStreamsFor (participant .id ),
64- })
78+ if err := participant .peer .ProcessSDPAnswer (msg .Description .SDP ); err != nil {
79+ participant .logger .Errorf ("Failed to set SDP answer: %v" , err )
80+ return
81+ }
82+ } else {
83+ participant .logger .Errorf ("Unknown SDP description type" )
84+ }
6585}
6686
67- func (c * Conference ) processAliveDCMessage (participant * Participant ) {
68- participant .peer .ProcessHeartbeat ()
87+ func (c * Conference ) processPongDCMessage (participant * Participant ) {
88+ participant .peer .ProcessPong ()
6989}
7090
71- func (c * Conference ) processMetadataDCMessage (participant * Participant , msg event.SFUMessage ) {
72- participant .streamMetadata = msg .Metadata
91+ func (c * Conference ) processMetadataDCMessage (
92+ participant * Participant , msg event.FocusCallSDPStreamMetadataChangedEventContent ,
93+ ) {
94+ participant .streamMetadata = msg .SDPStreamMetadata
7395 c .resendMetadataToAllExcept (participant .id )
7496}
0 commit comments