@@ -17,6 +17,7 @@ limitations under the License.
1717package  conference
1818
1919import  (
20+ 	"github.com/matrix-org/waterfall/src/common" 
2021	"github.com/matrix-org/waterfall/src/peer" 
2122	"github.com/matrix-org/waterfall/src/signaling" 
2223	"github.com/pion/webrtc/v3" 
@@ -25,22 +26,22 @@ import (
2526)
2627
2728type  Conference  struct  {
28- 	id                 string 
29- 	config             Config 
30- 	signaling          signaling.MatrixSignaling 
31- 	participants       map [peer. ID ]* Participant 
32- 	peerEventsStream   chan  peer .Message 
33- 	logger             * logrus.Entry 
29+ 	id            string 
30+ 	config        Config 
31+ 	signaling     signaling.MatrixSignaling 
32+ 	participants  map [ParticipantID ]* Participant 
33+ 	peerEvents     chan  common .Message [ ParticipantID , peer. MessageContent ] 
34+ 	logger        * logrus.Entry 
3435}
3536
3637func  NewConference (confID  string , config  Config , signaling  signaling.MatrixSignaling ) * Conference  {
3738	conference  :=  & Conference {
38- 		id :                confID ,
39- 		config :            config ,
40- 		signaling :         signaling ,
41- 		participants :      make (map [peer. ID ]* Participant ),
42- 		peerEventsStream :  make (chan  peer .Message ),
43- 		logger :            logrus .WithFields (logrus.Fields {"conf_id" : confID }),
39+ 		id :           confID ,
40+ 		config :       config ,
41+ 		signaling :    signaling ,
42+ 		participants : make (map [ParticipantID ]* Participant ),
43+ 		peerEvents :    make (chan  common .Message [ ParticipantID , peer. MessageContent ] ),
44+ 		logger :       logrus .WithFields (logrus.Fields {"conf_id" : confID }),
4445	}
4546
4647	// Start conference "main loop". 
@@ -49,7 +50,7 @@ func NewConference(confID string, config Config, signaling signaling.MatrixSigna
4950}
5051
5152// New participant tries to join the conference. 
52- func  (c  * Conference ) OnNewParticipant (participantID  peer. ID , inviteEvent  * event.CallInviteEventContent ) {
53+ func  (c  * Conference ) OnNewParticipant (participantID  ParticipantID , inviteEvent  * event.CallInviteEventContent ) {
5354	// As per MSC3401, when the `session_id` field changes from an incoming `m.call.member` event, 
5455	// any existing calls from this device in this call should be terminated. 
5556	// TODO: Implement this. 
@@ -67,7 +68,16 @@ func (c *Conference) OnNewParticipant(participantID peer.ID, inviteEvent *event.
6768		}
6869	}
6970
70- 	peer , sdpOffer , err  :=  peer .NewPeer (participantID , c .id , inviteEvent .Offer .SDP , c .peerEventsStream )
71+ 	var  (
72+ 		participantlogger  =  logrus .WithFields (logrus.Fields {
73+ 			"user_id" :   participantID .UserID ,
74+ 			"device_id" : participantID .DeviceID ,
75+ 			"conf_id" :   c .id ,
76+ 		})
77+ 		messageSink  =  common .NewMessageSink (participantID , c .peerEvents )
78+ 	)
79+ 
80+ 	peer , sdpOffer , err  :=  peer .NewPeer (inviteEvent .Offer .SDP , messageSink , participantlogger )
7181	if  err  !=  nil  {
7282		c .logger .WithError (err ).Errorf ("Failed to create new peer" )
7383		return 
@@ -88,11 +98,11 @@ func (c *Conference) OnNewParticipant(participantID peer.ID, inviteEvent *event.
8898	c .signaling .SendSDPAnswer (recipient , streamMetadata , sdpOffer .SDP )
8999}
90100
91- func  (c  * Conference ) OnCandidates (peerID  peer. ID ,  candidatesEvent  * event.CallCandidatesEventContent ) {
92- 	if  participant  :=  c .getParticipant (peerID , nil ); participant  !=  nil  {
101+ func  (c  * Conference ) OnCandidates (participantID   ParticipantID ,  ev  * event.CallCandidatesEventContent ) {
102+ 	if  participant  :=  c .getParticipant (participantID , nil ); participant  !=  nil  {
93103		// Convert the candidates to the WebRTC format. 
94- 		candidates  :=  make ([]webrtc.ICECandidateInit , len (candidatesEvent .Candidates ))
95- 		for  i , candidate  :=  range  candidatesEvent .Candidates  {
104+ 		candidates  :=  make ([]webrtc.ICECandidateInit , len (ev .Candidates ))
105+ 		for  i , candidate  :=  range  ev .Candidates  {
96106			SDPMLineIndex  :=  uint16 (candidate .SDPMLineIndex )
97107			candidates [i ] =  webrtc.ICECandidateInit {
98108				Candidate :     candidate .Candidate ,
@@ -105,19 +115,19 @@ func (c *Conference) OnCandidates(peerID peer.ID, candidatesEvent *event.CallCan
105115	}
106116}
107117
108- func  (c  * Conference ) OnSelectAnswer (peerID  peer. ID ,  selectAnswerEvent  * event.CallSelectAnswerEventContent ) {
109- 	if  participant  :=  c .getParticipant (peerID , nil ); participant  !=  nil  {
110- 		if  selectAnswerEvent .SelectedPartyID  !=  peerID .DeviceID .String () {
118+ func  (c  * Conference ) OnSelectAnswer (participantID   ParticipantID ,  ev  * event.CallSelectAnswerEventContent ) {
119+ 	if  participant  :=  c .getParticipant (participantID , nil ); participant  !=  nil  {
120+ 		if  ev .SelectedPartyID  !=  participantID .DeviceID .String () {
111121			c .logger .WithFields (logrus.Fields {
112- 				"device_id" : selectAnswerEvent .SelectedPartyID ,
122+ 				"device_id" : ev .SelectedPartyID ,
113123			}).Errorf ("Call was answered on a different device, kicking this peer" )
114124			participant .peer .Terminate ()
115125		}
116126	}
117127}
118128
119- func  (c  * Conference ) OnHangup (peerID  peer. ID ,  hangupEvent  * event.CallHangupEventContent ) {
120- 	if  participant  :=  c .getParticipant (peerID , nil ); participant  !=  nil  {
129+ func  (c  * Conference ) OnHangup (participantID   ParticipantID ,  ev  * event.CallHangupEventContent ) {
130+ 	if  participant  :=  c .getParticipant (participantID , nil ); participant  !=  nil  {
121131		participant .peer .Terminate ()
122132	}
123133}
0 commit comments