Skip to content

Commit

Permalink
Merge pull request #127 from cloudflare/log-onclose-events
Browse files Browse the repository at this point in the history
Add logging for onClose
  • Loading branch information
third774 authored Oct 4, 2024
2 parents 036b9d6 + ea5c893 commit 78c8447
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/durableObjects/ChatRoom.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ export class ChatRoom extends Server<Env> {
}
}

async onClose(
connection: Connection,
code: number,
reason: string,
wasClean: boolean
) {
const meetingId = await this.getMeetingId()
log({
eventName: 'onClose',
meetingId,
connectionId: connection.id,
code,
reason,
wasClean,
})
}

async onMessage(
connection: Connection<User>,
message: WSMessage
Expand Down
8 changes: 8 additions & 0 deletions app/utils/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ export type LogEvent =
foundInStorage: boolean
connectionId: string
}
| {
eventName: 'onClose'
meetingId?: string
connectionId: string
code: number
reason: string
wasClean: boolean
}
| {
eventName: 'userLeft'
meetingId?: string
Expand Down

0 comments on commit 78c8447

Please sign in to comment.