diff --git a/callback.go b/callback.go index 07ae9ba8..d1db4362 100644 --- a/callback.go +++ b/callback.go @@ -161,17 +161,18 @@ func GetDisconnectionReason(reason livekit.DisconnectReason) DisconnectionReason } type RoomCallback struct { - OnDisconnected func() - OnDisconnectedWithReason func(reason DisconnectionReason) - OnParticipantConnected func(*RemoteParticipant) - OnParticipantDisconnected func(*RemoteParticipant) - OnActiveSpeakersChanged func([]Participant) - OnRoomMetadataChanged func(metadata string) - OnRecordingStatusChanged func(isRecording bool) - OnRoomMoved func(roomName string, token string) - OnReconnecting func() - OnReconnected func() - OnLocalTrackSubscribed func(publication *LocalTrackPublication, lp *LocalParticipant) + OnDisconnected func() + OnDisconnectedWithReason func(reason DisconnectionReason) + OnParticipantConnected func(*RemoteParticipant) + OnParticipantDisconnected func(*RemoteParticipant) + OnParticipantDisconnectedWithReason func(*RemoteParticipant, livekit.DisconnectReason) + OnActiveSpeakersChanged func([]Participant) + OnRoomMetadataChanged func(metadata string) + OnRecordingStatusChanged func(isRecording bool) + OnRoomMoved func(roomName string, token string) + OnReconnecting func() + OnReconnected func() + OnLocalTrackSubscribed func(publication *LocalTrackPublication, lp *LocalParticipant) // participant events are sent to the room as well ParticipantCallback @@ -183,17 +184,18 @@ func NewRoomCallback() *RoomCallback { return &RoomCallback{ ParticipantCallback: *pc, - OnDisconnected: func() {}, - OnDisconnectedWithReason: func(reason DisconnectionReason) {}, - OnParticipantConnected: func(participant *RemoteParticipant) {}, - OnParticipantDisconnected: func(participant *RemoteParticipant) {}, - OnActiveSpeakersChanged: func(participants []Participant) {}, - OnRoomMetadataChanged: func(metadata string) {}, - OnRecordingStatusChanged: func(isRecording bool) {}, - OnRoomMoved: func(roomName string, token string) {}, - OnReconnecting: func() {}, - OnReconnected: func() {}, - OnLocalTrackSubscribed: func(publication *LocalTrackPublication, lp *LocalParticipant) {}, + OnDisconnected: func() {}, + OnDisconnectedWithReason: func(reason DisconnectionReason) {}, + OnParticipantConnected: func(participant *RemoteParticipant) {}, + OnParticipantDisconnected: func(participant *RemoteParticipant) {}, + OnParticipantDisconnectedWithReason: func(participant *RemoteParticipant, reason livekit.DisconnectReason) {}, + OnActiveSpeakersChanged: func(participants []Participant) {}, + OnRoomMetadataChanged: func(metadata string) {}, + OnRecordingStatusChanged: func(isRecording bool) {}, + OnRoomMoved: func(roomName string, token string) {}, + OnReconnecting: func() {}, + OnReconnected: func() {}, + OnLocalTrackSubscribed: func(publication *LocalTrackPublication, lp *LocalParticipant) {}, } } @@ -215,6 +217,9 @@ func (cb *RoomCallback) Merge(other *RoomCallback) { if other.OnParticipantDisconnected != nil { cb.OnParticipantDisconnected = other.OnParticipantDisconnected } + if other.OnParticipantDisconnectedWithReason != nil { + cb.OnParticipantDisconnectedWithReason = other.OnParticipantDisconnectedWithReason + } if other.OnActiveSpeakersChanged != nil { cb.OnActiveSpeakersChanged = other.OnActiveSpeakersChanged } diff --git a/room.go b/room.go index 0374339a..df4a9672 100644 --- a/room.go +++ b/room.go @@ -809,7 +809,7 @@ func (r *Room) OnRestarting() { r.callback.OnReconnecting() for _, rp := range r.GetRemoteParticipants() { - r.OnParticipantDisconnect(rp) + r.OnParticipantDisconnect(rp, livekit.DisconnectReason_UNKNOWN_REASON) } } @@ -878,7 +878,7 @@ func (r *Room) OnParticipantUpdate(participants []*livekit.ParticipantInfo) { isNew := rp == nil if pi.State == livekit.ParticipantInfo_DISCONNECTED { - r.OnParticipantDisconnect(rp) + r.OnParticipantDisconnect(rp, pi.GetDisconnectReason()) } else if isNew { rp = r.addRemoteParticipant(pi, true) r.clearParticipantDefers(livekit.ParticipantID(pi.Sid), pi) @@ -907,7 +907,7 @@ func (r *Room) OnParticipantUpdate(participants []*livekit.ParticipantInfo) { } } -func (r *Room) OnParticipantDisconnect(rp *RemoteParticipant) { +func (r *Room) OnParticipantDisconnect(rp *RemoteParticipant, reason livekit.DisconnectReason) { if rp == nil { return } @@ -921,6 +921,7 @@ func (r *Room) OnParticipantDisconnect(rp *RemoteParticipant) { rp.unpublishAllTracks() r.LocalParticipant.handleParticipantDisconnected(rp.Identity()) go r.callback.OnParticipantDisconnected(rp) + go r.callback.OnParticipantDisconnectedWithReason(rp, reason) } func (r *Room) OnSpeakersChanged(speakerUpdates []*livekit.SpeakerInfo) { @@ -1002,7 +1003,7 @@ func (r *Room) OnRoomMoved(moved *livekit.RoomMovedResponse) { r.OnRoomUpdate(moved.Room) for _, rp := range r.GetRemoteParticipants() { - r.OnParticipantDisconnect(rp) + r.OnParticipantDisconnect(rp, livekit.DisconnectReason_ROOM_CLOSED) } go r.callback.OnRoomMoved(moved.Room.Name, moved.Token)