store participant before webhook (#200)

* store participant before webhook

* delete participant before participant left event
This commit is contained in:
David Colburn
2021-11-21 11:41:16 -08:00
committed by GitHub
parent 6dcb29c559
commit a0b623914a
+12 -11
View File
@@ -253,13 +253,19 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName string, pi rout
opts := rtc.ParticipantOptions{
AutoSubscribe: pi.AutoSubscribe,
}
if err := room.Join(participant, &opts, r.iceServersForRoom(room.Room)); err != nil {
if err = room.Join(participant, &opts, r.iceServersForRoom(room.Room)); err != nil {
logger.Errorw("could not join room", err)
return
}
if err = r.roomStore.StoreParticipant(ctx, roomName, participant.ToProto()); err != nil {
logger.Errorw("could not store participant", err)
}
r.telemetry.ParticipantJoined(ctx, room.Room, participant.ToProto())
participant.OnClose(func(p types.Participant) {
if err := r.roomStore.DeleteParticipant(ctx, roomName, p.Identity()); err != nil {
logger.Errorw("could not delete participant", err)
}
r.telemetry.ParticipantLeft(ctx, room.Room, p.ToProto())
})
@@ -295,20 +301,15 @@ func (r *RoomManager) getOrCreateRoom(ctx context.Context, roomName string) (*rt
logger.Infow("room closed")
})
room.OnMetadataUpdate(func(metadata string) {
err := r.roomStore.StoreRoom(ctx, room.Room)
if err != nil {
if err := r.roomStore.StoreRoom(ctx, room.Room); err != nil {
logger.Errorw("could not handle metadata update", err)
}
})
room.OnParticipantChanged(func(p types.Participant) {
var err error
if p.State() == livekit.ParticipantInfo_DISCONNECTED {
err = r.roomStore.DeleteParticipant(ctx, roomName, p.Identity())
} else {
err = r.roomStore.StoreParticipant(ctx, roomName, p.ToProto())
}
if err != nil {
logger.Errorw("could not handle participant change", err)
if p.State() != livekit.ParticipantInfo_DISCONNECTED {
if err := r.roomStore.StoreParticipant(ctx, roomName, p.ToProto()); err != nil {
logger.Errorw("could not handle participant change", err)
}
}
})
r.lock.Lock()