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 13:41:16 -06: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{ opts := rtc.ParticipantOptions{
AutoSubscribe: pi.AutoSubscribe, 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) logger.Errorw("could not join room", err)
return 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()) r.telemetry.ParticipantJoined(ctx, room.Room, participant.ToProto())
participant.OnClose(func(p types.Participant) { 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()) 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") logger.Infow("room closed")
}) })
room.OnMetadataUpdate(func(metadata string) { room.OnMetadataUpdate(func(metadata string) {
err := r.roomStore.StoreRoom(ctx, room.Room) if err := r.roomStore.StoreRoom(ctx, room.Room); err != nil {
if err != nil {
logger.Errorw("could not handle metadata update", err) logger.Errorw("could not handle metadata update", err)
} }
}) })
room.OnParticipantChanged(func(p types.Participant) { room.OnParticipantChanged(func(p types.Participant) {
var err error if p.State() != livekit.ParticipantInfo_DISCONNECTED {
if p.State() == livekit.ParticipantInfo_DISCONNECTED { if err := r.roomStore.StoreParticipant(ctx, roomName, p.ToProto()); err != nil {
err = r.roomStore.DeleteParticipant(ctx, roomName, p.Identity()) logger.Errorw("could not handle participant change", err)
} else { }
err = r.roomStore.StoreParticipant(ctx, roomName, p.ToProto())
}
if err != nil {
logger.Errorw("could not handle participant change", err)
} }
}) })
r.lock.Lock() r.lock.Lock()