Skip to content

Commit

Permalink
Try to retrieve user in onConnect
Browse files Browse the repository at this point in the history
In case they're reconnecting!
  • Loading branch information
third774 committed Aug 15, 2024
1 parent 28041a0 commit f4faaa4
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions app/durableObjects/ChatRoom.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,20 @@ export class ChatRoom extends Server<Env> {
const username = await getUsername(ctx.request)
assertNonNullable(username)

const user: User = {
id: connection.id,
name: username,
joined: false,
raisedHand: false,
speaking: false,
tracks: {
audioEnabled: false,
videoEnabled: false,
screenShareEnabled: false,
},
let user = await this.ctx.storage.get<User>(`session-${connection.id}`)
if (user === undefined) {
user = {
id: connection.id,
name: username,
joined: false,
raisedHand: false,
speaking: false,
tracks: {
audioEnabled: false,
videoEnabled: false,
screenShareEnabled: false,
},
}
}

// store the user's data in storage
Expand Down

0 comments on commit f4faaa4

Please sign in to comment.