@@ -22,6 +22,7 @@ import (
2222	"github.com/matrix-org/waterfall/pkg/signaling" 
2323	"github.com/sirupsen/logrus" 
2424	"maunium.net/go/mautrix/event" 
25+ 	"maunium.net/go/mautrix/id" 
2526)
2627
2728type  Conference  =  common.Sender [conf.MatrixMessage ]
@@ -58,10 +59,11 @@ func newRouter(matrix *signaling.MatrixClient, config conf.Config) chan<- Router
5859			case  ConferenceEndedMessage :
5960				// Remove the conference that ended from the list. 
6061				delete (router .conferenceSinks , msg .conferenceID )
62+ 
6163				// Process the message that was not read by the conference. 
62- 				if   len ( msg . unread )  >   0  {
63- 					// FIXME : We must handle these messages!  
64- 					logrus . Warnf ( "Unread messages: %v" ,  len ( msg .unread ) )
64+ 				for   _ ,  msg   :=   range   msg . unread  {
65+ 					// TODO : We actually already know the type, so we can do this better.  
66+ 					router . handleMatrixEvent ( msg .RawEvent )
6567				}
6668			}
6769		}
@@ -72,22 +74,36 @@ func newRouter(matrix *signaling.MatrixClient, config conf.Config) chan<- Router
7274
7375// Handles incoming To-Device events that the SFU receives from clients. 
7476func  (r  * Router ) handleMatrixEvent (evt  * event.Event ) {
75- 	// Check if `conf_id` is present in the message (right messages do have it). 
76- 	rawConferenceID , ok  :=  evt .Content .Raw ["conf_id" ]
77- 	if  ! ok  {
78- 		return 
79- 	}
77+ 	var  (
78+ 		conferenceID  string 
79+ 		callID        string 
80+ 		deviceID      string 
81+ 		userID        =  evt .Sender 
82+ 	)
8083
81- 	// Try to parse the conference ID without parsing the whole event. 
82- 	conferenceID , ok  :=  rawConferenceID .(string )
83- 	if  ! ok  {
84- 		return 
84+ 	// Check if `conf_id` is present in the message (right messages do have it). 
85+ 	rawConferenceID , okConferenceId  :=  evt .Content .Raw ["conf_id" ]
86+ 	rawCallID , okCallId  :=  evt .Content .Raw ["call_id" ]
87+ 	rawDeviceID , okDeviceID  :=  evt .Content .Raw ["device_id" ]
88+ 
89+ 	if  okConferenceId  &&  okCallId  &&  okDeviceID  {
90+ 		// Extract the conference ID from the message. 
91+ 		conferenceID , okConferenceId  =  rawConferenceID .(string )
92+ 		callID , okCallId  =  rawCallID .(string )
93+ 		deviceID , okDeviceID  =  rawDeviceID .(string )
94+ 
95+ 		if  ! okConferenceId  ||  ! okCallId  ||  ! okDeviceID  {
96+ 			logrus .Warn ("Ignoring invalid message without IDs" )
97+ 			return 
98+ 		}
8599	}
86100
87101	logger  :=  logrus .WithFields (logrus.Fields {
88- 		"type" :    evt .Type .Type ,
89- 		"user_id" : evt .Sender .String (),
90- 		"conf_id" : conferenceID ,
102+ 		"type" :      evt .Type .Type ,
103+ 		"user_id" :   userID ,
104+ 		"conf_id" :   conferenceID ,
105+ 		"call_id" :   callID ,
106+ 		"device_id" : deviceID ,
91107	})
92108
93109	conference  :=  r .conferenceSinks [conferenceID ]
@@ -101,7 +117,7 @@ func (r *Router) handleMatrixEvent(evt *event.Event) {
101117			r .config ,
102118			r .matrix .CreateForConference (conferenceID ),
103119			createConferenceEndNotifier (conferenceID , r .channel ),
104- 			evt . Sender ,
120+ 			userID ,
105121			evt .Content .AsCallInvite (),
106122		)
107123		if  err  !=  nil  {
@@ -122,9 +138,10 @@ func (r *Router) handleMatrixEvent(evt *event.Event) {
122138	// A helper function to deal with messages that can't be sent due to the conference closed. 
123139	// Not a function due to the need to capture local environment. 
124140	sendToConference  :=  func (eventContent  conf.MessageContent ) {
141+ 		sender  :=  conf.ParticipantID {userID , id .DeviceID (deviceID ), callID }
125142		// At this point the conference is not nil. 
126143		// Let's check if the channel is still available. 
127- 		if  conference .Send (conf.MatrixMessage {UserID :  evt . Sender ,  Content :  eventContent }) !=  nil  {
144+ 		if  conference .Send (conf.MatrixMessage {Content :  eventContent ,  RawEvent :  evt ,  Sender :  sender }) !=  nil  {
128145			// If sending failed, then the conference is over. 
129146			delete (r .conferenceSinks , conferenceID )
130147			// Since we were not able to send the message, let's re-process it now. 
0 commit comments