Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,17 @@ func GetDisconnectionReason(reason livekit.DisconnectReason) DisconnectionReason
}

type RoomCallback struct {
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)
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)

// participant events are sent to the room as well
ParticipantCallback
Expand All @@ -184,18 +183,17 @@ func NewRoomCallback() *RoomCallback {
return &RoomCallback{
ParticipantCallback: *pc,

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) {},
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) {},
}
}

Expand All @@ -217,9 +215,6 @@ 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
}
Expand Down
5 changes: 3 additions & 2 deletions room.go
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if unknown_reason is optimal for onRestarting

Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,9 @@ func (r *Room) OnParticipantDisconnect(rp *RemoteParticipant, reason livekit.Dis

rp.unpublishAllTracks()
r.LocalParticipant.handleParticipantDisconnected(rp.Identity())

rp.info.DisconnectReason = reason
go r.callback.OnParticipantDisconnected(rp)
go r.callback.OnParticipantDisconnectedWithReason(rp, reason)
}

func (r *Room) OnSpeakersChanged(speakerUpdates []*livekit.SpeakerInfo) {
Expand Down Expand Up @@ -1003,7 +1004,7 @@ func (r *Room) OnRoomMoved(moved *livekit.RoomMovedResponse) {
r.OnRoomUpdate(moved.Room)

for _, rp := range r.GetRemoteParticipants() {
r.OnParticipantDisconnect(rp, livekit.DisconnectReason_ROOM_CLOSED)
r.OnParticipantDisconnect(rp, livekit.DisconnectReason_MIGRATION)
Comment on lines -1006 to +1007
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migration seems more optimal here? wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense.

}

go r.callback.OnRoomMoved(moved.Room.Name, moved.Token)
Expand Down
Loading