Skip to content

Commit 271996a

Browse files
conference: add additional logging
1 parent f16b218 commit 271996a

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

pkg/conference/matrix.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func (c *Conference) onNewParticipant(participantID ParticipantID, inviteEvent *
2323
"device_id": participantID.DeviceID,
2424
})
2525

26+
logger.Info("Incoming call invite")
27+
2628
// As per MSC3401, when the `session_id` field changes from an incoming `m.call.member` event,
2729
// any existing calls from this device in this call should be terminated.
2830
if participant := c.participants[participantID]; participant != nil {
@@ -78,6 +80,8 @@ func (c *Conference) onNewParticipant(participantID ParticipantID, inviteEvent *
7880
// our internal peer connection.
7981
func (c *Conference) onCandidates(participantID ParticipantID, ev *event.CallCandidatesEventContent) {
8082
if participant := c.getParticipant(participantID, nil); participant != nil {
83+
participant.logger.Info("Received remote ICE candidates")
84+
8185
// Convert the candidates to the WebRTC format.
8286
candidates := make([]webrtc.ICECandidateInit, len(ev.Candidates))
8387
for i, candidate := range ev.Candidates {
@@ -97,6 +101,8 @@ func (c *Conference) onCandidates(participantID ParticipantID, ev *event.CallCan
97101
// and that the call can now proceed.
98102
func (c *Conference) onSelectAnswer(participantID ParticipantID, ev *event.CallSelectAnswerEventContent) {
99103
if participant := c.getParticipant(participantID, nil); participant != nil {
104+
participant.logger.Info("Received remote answer selection")
105+
100106
if ev.SelectedPartyID != participantID.DeviceID.String() {
101107
c.logger.WithFields(logrus.Fields{
102108
"device_id": ev.SelectedPartyID,
@@ -109,5 +115,8 @@ func (c *Conference) onSelectAnswer(participantID ParticipantID, ev *event.CallS
109115

110116
// Process a message from the remote peer telling that it wants to hang up the call.
111117
func (c *Conference) onHangup(participantID ParticipantID, ev *event.CallHangupEventContent) {
112-
c.removeParticipant(participantID)
118+
if participant := c.participants[participantID]; participant != nil {
119+
participant.logger.Info("Received remote hangup")
120+
c.removeParticipant(participantID)
121+
}
113122
}

pkg/conference/processor.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,16 @@ func (c *Conference) processPeerMessage(message common.Message[ParticipantID, pe
5757
// determine the actual type of the message.
5858
switch msg := message.Content.(type) {
5959
case peer.JoinedTheCall:
60+
participant.logger.Info("Joined the call")
6061
c.resendMetadataToAllExcept(participant.id)
6162

6263
case peer.LeftTheCall:
64+
participant.logger.Info("Left the call")
6365
c.removeParticipant(message.Sender)
6466
c.signaling.SendHangup(participant.asMatrixRecipient(), event.CallHangupUnknownError)
6567

6668
case peer.NewTrackPublished:
69+
participant.logger.Infof("Published new track: %s", msg.Track.ID())
6770
key := event.SFUTrackDescription{
6871
StreamID: msg.Track.StreamID(),
6972
TrackID: msg.Track.ID(),
@@ -77,6 +80,7 @@ func (c *Conference) processPeerMessage(message common.Message[ParticipantID, pe
7780
participant.publishedTracks[key] = msg.Track
7881

7982
case peer.PublishedTrackFailed:
83+
participant.logger.Infof("Failed published track: %s", msg.Track.ID())
8084
delete(participant.publishedTracks, event.SFUTrackDescription{
8185
StreamID: msg.Track.StreamID(),
8286
TrackID: msg.Track.ID(),
@@ -91,6 +95,8 @@ func (c *Conference) processPeerMessage(message common.Message[ParticipantID, pe
9195
}
9296

9397
case peer.NewICECandidate:
98+
participant.logger.Info("Received a new local ICE candidate")
99+
94100
// Convert WebRTC ICE candidate to Matrix ICE candidate.
95101
jsonCandidate := msg.Candidate.ToJSON()
96102
candidates := []event.CallCandidate{{
@@ -101,17 +107,21 @@ func (c *Conference) processPeerMessage(message common.Message[ParticipantID, pe
101107
c.signaling.SendICECandidates(participant.asMatrixRecipient(), candidates)
102108

103109
case peer.ICEGatheringComplete:
110+
participant.logger.Info("Completed local ICE gathering")
111+
104112
// Send an empty array of candidates to indicate that ICE gathering is complete.
105113
c.signaling.SendCandidatesGatheringFinished(participant.asMatrixRecipient())
106114

107115
case peer.RenegotiationRequired:
116+
participant.logger.Info("Started renegotiation")
108117
participant.sendDataChannelMessage(event.SFUMessage{
109118
Op: event.SFUOperationOffer,
110119
SDP: msg.Offer.SDP,
111120
Metadata: c.getAvailableStreamsFor(participant.id),
112121
})
113122

114123
case peer.DataChannelMessage:
124+
participant.logger.Info("Sent data channel message")
115125
var sfuMessage event.SFUMessage
116126
if err := json.Unmarshal([]byte(msg.Message), &sfuMessage); err != nil {
117127
c.logger.Errorf("Failed to unmarshal SFU message: %v", err)
@@ -121,6 +131,7 @@ func (c *Conference) processPeerMessage(message common.Message[ParticipantID, pe
121131
c.handleDataChannelMessage(participant, sfuMessage)
122132

123133
case peer.DataChannelAvailable:
134+
participant.logger.Info("Connected data channel")
124135
participant.sendDataChannelMessage(event.SFUMessage{
125136
Op: event.SFUOperationMetadata,
126137
Metadata: c.getAvailableStreamsFor(participant.id),
@@ -135,6 +146,8 @@ func (c *Conference) processPeerMessage(message common.Message[ParticipantID, pe
135146
func (c *Conference) handleDataChannelMessage(participant *Participant, sfuMessage event.SFUMessage) {
136147
switch sfuMessage.Op {
137148
case event.SFUOperationSelect:
149+
participant.logger.Info("Sent select request over DC")
150+
138151
// Get the tracks that correspond to the tracks that the participant wants to receive.
139152
for _, track := range c.getTracks(sfuMessage.Start) {
140153
if err := participant.peer.SubscribeTo(track); err != nil {
@@ -144,12 +157,16 @@ func (c *Conference) handleDataChannelMessage(participant *Participant, sfuMessa
144157
}
145158

146159
case event.SFUOperationAnswer:
160+
participant.logger.Info("Sent SDP answer over DC")
161+
147162
if err := participant.peer.ProcessSDPAnswer(sfuMessage.SDP); err != nil {
148163
participant.logger.Errorf("Failed to set SDP answer: %v", err)
149164
return
150165
}
151166

152167
case event.SFUOperationPublish:
168+
participant.logger.Info("Sent SDP offer over DC")
169+
153170
answer, err := participant.peer.ProcessSDPOffer(sfuMessage.SDP)
154171
if err != nil {
155172
participant.logger.Errorf("Failed to set SDP offer: %v", err)
@@ -162,10 +179,14 @@ func (c *Conference) handleDataChannelMessage(participant *Participant, sfuMessa
162179
})
163180

164181
case event.SFUOperationUnpublish:
182+
participant.logger.Info("Sent unpublish over DC")
183+
165184
// TODO: Clarify the semantics of unpublish.
166185
case event.SFUOperationAlive:
167186
// FIXME: Handle the heartbeat message here (updating the last timestamp etc).
168187
case event.SFUOperationMetadata:
188+
participant.logger.Info("Sent metadata over DC")
189+
169190
participant.streamMetadata = sfuMessage.Metadata
170191
c.resendMetadataToAllExcept(participant.id)
171192
}

pkg/peer/webrtc.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (p *Peer[ID]) onRtpTrackReceived(remoteTrack *webrtc.TrackRemote, receiver
7171
func (p *Peer[ID]) onICECandidateGathered(candidate *webrtc.ICECandidate) {
7272
if candidate == nil {
7373
p.logger.Info("ICE candidate gathering finished")
74+
p.sink.Send(ICEGatheringComplete{})
7475
return
7576
}
7677

@@ -112,10 +113,6 @@ func (p *Peer[ID]) onICEConnectionStateChanged(state webrtc.ICEConnectionState)
112113

113114
func (p *Peer[ID]) onICEGatheringStateChanged(state webrtc.ICEGathererState) {
114115
p.logger.WithField("state", state).Debug("ICE gathering state changed")
115-
116-
if state == webrtc.ICEGathererStateComplete {
117-
p.sink.Send(ICEGatheringComplete{})
118-
}
119116
}
120117

121118
func (p *Peer[ID]) onSignalingStateChanged(state webrtc.SignalingState) {

0 commit comments

Comments
 (0)