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: 27 additions & 22 deletions callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {},
}
}

Expand All @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions room.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
Loading