diff --git a/app/durableObjects/ChatRoom.server.ts b/app/durableObjects/ChatRoom.server.ts index 36777773..3b408b05 100644 --- a/app/durableObjects/ChatRoom.server.ts +++ b/app/durableObjects/ChatRoom.server.ts @@ -58,17 +58,20 @@ export class ChatRoom extends Server { 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(`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