Skip to content

Commit

Permalink
wait 20 seconds before the room cleans up
Browse files Browse the repository at this point in the history
  • Loading branch information
jibon57 committed Sep 1, 2024
1 parent 7f3269e commit 136b8ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
4 changes: 2 additions & 2 deletions pkg/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const (
MaxPreloadedWhiteboardFileSize int64 = 5 * 1000000 // limit to 5MB

// all the time.Sleep() values
WaitBeforeTriggerOnAfterRoomEnded = 5 * time.Second
WaitBeforeTriggerOnAfterRoomEnded = 20 * time.Second
WaitBeforeSpeechServicesOnAfterRoomEnded = 3 * time.Second
WaitBeforeBreakoutRoomOnAfterRoomStart = 2 * time.Second
WaitBeforeAnalyticsStartProcessing = 30 * time.Second
WaitBeforeAnalyticsStartProcessing = 1 * time.Minute
MaxDurationWaitBeforeCleanRoomWebhook = 1 * time.Minute
WaitDurationIfRoomCreationLocked = 1 * time.Second

Expand Down
40 changes: 17 additions & 23 deletions pkg/models/nats_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,15 @@ func (m *NatsModel) OnAfterUserJoined(roomId, userId string) {
// but will broadcast as disconnected
func (m *NatsModel) OnAfterUserDisconnected(roomId, userId string) {
// now change the user's status
err := m.natsService.UpdateUserStatus(roomId, userId, natsservice.UserStatusDisconnected)
if err != nil {
log.Warnln(err)
}
_ = m.natsService.UpdateUserStatus(roomId, userId, natsservice.UserStatusDisconnected)

// notify to everyone of the room &
// 1. pause all the media but not from the list
userInfo, _ := m.natsService.GetUserInfo(roomId, userId)
if userInfo == nil {
log.Warnln(fmt.Sprintf("no user info found with id: %s, which may happend if room had ended before user left", userId))
// no way to continue
// if we do not get data, then we'll just update analytics
m.updateUserLeftAnalytics(roomId, userId)
return
}

_ = m.natsService.BroadcastSystemEventToEveryoneExceptUserId(plugnmeet.NatsMsgServerToClientEvents_USER_DISCONNECTED, roomId, userInfo, userId)

// we'll wait 5 seconds before declare this user as offline
Expand All @@ -72,23 +68,17 @@ func (m *NatsModel) OnAfterUserDisconnected(roomId, userId string) {
return
}
}
err = m.natsService.UpdateUserStatus(roomId, userId, natsservice.UserStatusOffline)
err := m.natsService.UpdateUserStatus(roomId, userId, natsservice.UserStatusOffline)
if err != nil {
log.Warnln(err)
}

// analytics
m.updateUserLeftAnalytics(roomId, userId)

// now broadcast to everyone
_ = m.natsService.BroadcastSystemEventToEveryoneExceptUserId(plugnmeet.NatsMsgServerToClientEvents_USER_OFFLINE, roomId, userInfo, userId)

now := fmt.Sprintf("%d", time.Now().UnixMilli())
m.analyticsModel.HandleEvent(&plugnmeet.AnalyticsDataMsg{
EventType: plugnmeet.AnalyticsEventType_ANALYTICS_EVENT_TYPE_USER,
EventName: plugnmeet.AnalyticsEvents_ANALYTICS_EVENT_USER_LEFT,
RoomId: roomId,
UserId: &userInfo.UserId,
HsetValue: &now,
})

// we'll wait another 30 seconds & delete this consumer,
// but we'll keep user's information in the bucket
// everything will be clean when the session ends.
Expand All @@ -106,9 +96,13 @@ func (m *NatsModel) OnAfterUserDisconnected(roomId, userId string) {
m.natsService.DeleteConsumer(roomId, userId)
}

func (m *NatsModel) onAfterUserLoggedOut(roomId, userId string) {
// delete consumer
m.natsService.DeleteConsumer(roomId, userId)
// now delete from the room users list & bucket
m.natsService.DeleteUser(roomId, userId)
func (m *NatsModel) updateUserLeftAnalytics(roomId, userId string) {
now := fmt.Sprintf("%d", time.Now().UnixMilli())
m.analyticsModel.HandleEvent(&plugnmeet.AnalyticsDataMsg{
EventType: plugnmeet.AnalyticsEventType_ANALYTICS_EVENT_TYPE_USER,
EventName: plugnmeet.AnalyticsEvents_ANALYTICS_EVENT_USER_LEFT,
RoomId: roomId,
UserId: &userId,
HsetValue: &now,
})
}

0 comments on commit 136b8ff

Please sign in to comment.