@@ -2,22 +2,32 @@ 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" )
15+
16+ // TODO: Handle unsubscribe
1217
1318 // Find tracks based on what we were asked for.
14- tracks := c .getTracks (msg .Start )
19+ tracks := c .getTracks (msg .Subscribe )
20+
21+ participant .logger .WithFields (logrus.Fields {
22+ "tracks_we_got" : tracks ,
23+ "tracks_we_want" : msg ,
24+ }).Debug ("Tracks to subscribe to" )
1525
1626 // Let's check if we have all the tracks that we were asked for are there.
1727 // If not, we will list which are not available (later on we must inform participant
1828 // about it unless the participant retries it).
19- if len (tracks ) != len (msg .Start ) {
20- for _ , expected := range msg .Start {
29+ if len (tracks ) != len (msg .Subscribe ) {
30+ for _ , expected := range msg .Subscribe {
2131 found := slices .IndexFunc (tracks , func (track * webrtc.TrackLocalStaticRTP ) bool {
2232 return track .ID () == expected .TrackID
2333 })
@@ -30,45 +40,58 @@ func (c *Conference) processSelectDCMessage(participant *Participant, msg event.
3040
3141 // Subscribe to the found tracks.
3242 for _ , track := range tracks {
43+ participant .logger .WithField ("track_id" , track .ID ()).Debug ("Subscribing to track" )
3344 if err := participant .peer .SubscribeTo (track ); err != nil {
3445 participant .logger .Errorf ("Failed to subscribe to track: %v" , err )
3546 return
3647 }
3748 }
3849}
3950
40- func (c * Conference ) processAnswerDCMessage (participant * Participant , msg event.SFUMessage ) {
41- participant .logger .Info ("Received SDP answer over DC" )
42-
43- if err := participant .peer .ProcessSDPAnswer (msg .SDP ); err != nil {
44- participant .logger .Errorf ("Failed to set SDP answer: %v" , err )
45- return
46- }
47- }
51+ func (c * Conference ) processNegotiateDCMessage (participant * Participant , msg event.FocusCallNegotiateEventContent ) {
52+ participant .streamMetadata = msg .SDPStreamMetadata
4853
49- func (c * Conference ) processPublishDCMessage (participant * Participant , msg event.SFUMessage ) {
50- participant .logger .Info ("Received SDP offer over DC" )
54+ switch msg .Description .Type {
55+ case event .CallDataTypeOffer :
56+ participant .logger .WithField ("SDP" , msg .Description .SDP ).Trace ("Received SDP offer over DC" )
5157
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- }
58+ answer , err := participant .peer .ProcessSDPOffer (msg . Description .SDP )
59+ if err != nil {
60+ participant .logger .Errorf ("Failed to set SDP offer: %v" , err )
61+ return
62+ }
5763
58- participant .streamMetadata = msg .Metadata
64+ participant .sendDataChannelMessage (event.Event {
65+ Type : event .FocusCallNegotiate ,
66+ Content : event.Content {
67+ Parsed : event.FocusCallNegotiateEventContent {
68+ Description : event.CallData {
69+ Type : event .CallDataType (answer .Type .String ()),
70+ SDP : answer .SDP ,
71+ },
72+ SDPStreamMetadata : c .getAvailableStreamsFor (participant .id ),
73+ },
74+ },
75+ })
76+ case event .CallDataTypeAnswer :
77+ participant .logger .WithField ("SDP" , msg .Description .SDP ).Trace ("Received SDP answer over DC" )
5978
60- participant .sendDataChannelMessage (event.SFUMessage {
61- Op : event .SFUOperationAnswer ,
62- SDP : answer .SDP ,
63- Metadata : c .getAvailableStreamsFor (participant .id ),
64- })
79+ if err := participant .peer .ProcessSDPAnswer (msg .Description .SDP ); err != nil {
80+ participant .logger .Errorf ("Failed to set SDP answer: %v" , err )
81+ return
82+ }
83+ default :
84+ participant .logger .Errorf ("Unknown SDP description type" )
85+ }
6586}
6687
67- func (c * Conference ) processAliveDCMessage (participant * Participant ) {
68- participant .peer .ProcessHeartbeat ()
88+ func (c * Conference ) processPongDCMessage (participant * Participant ) {
89+ participant .peer .ProcessPong ()
6990}
7091
71- func (c * Conference ) processMetadataDCMessage (participant * Participant , msg event.SFUMessage ) {
72- participant .streamMetadata = msg .Metadata
92+ func (c * Conference ) processMetadataDCMessage (
93+ participant * Participant , msg event.FocusCallSDPStreamMetadataChangedEventContent ,
94+ ) {
95+ participant .streamMetadata = msg .SDPStreamMetadata
7396 c .resendMetadataToAllExcept (participant .id )
7497}
0 commit comments