Skip to content

Commit

Permalink
Merge pull request #84 from cloudflare/try-to-retrieve-user-in-onConnect
Browse files Browse the repository at this point in the history
Try to retrieve user in onConnect
  • Loading branch information
third774 committed Aug 16, 2024
2 parents 28041a0 + f4faaa4 commit 49cb2cc
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 49cb2cc

Please sign in to comment.