Skip to content

Commit

Permalink
Disable hibernation properly
Browse files Browse the repository at this point in the history
  • Loading branch information
third774 committed Oct 21, 2024
1 parent 222a7c6 commit f66d932
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
14 changes: 8 additions & 6 deletions app/durableObjects/ChatRoom.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class ChatRoom extends Server<Env> {
env: Env
db: DrizzleD1Database<Record<string, never>> | null

// static options = { hibernate: true }

constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env)
this.env = env
Expand All @@ -46,12 +48,12 @@ export class ChatRoom extends Server<Env> {
log({ eventName: 'onStart', meetingId })
this.db = getDb(this)
// TODO: make this a part of partyserver
this.ctx.setWebSocketAutoResponse(
new WebSocketRequestResponsePair(
JSON.stringify({ type: 'partyserver-ping' }),
JSON.stringify({ type: 'partyserver-pong' })
)
)
// this.ctx.setWebSocketAutoResponse(
// new WebSocketRequestResponsePair(
// JSON.stringify({ type: 'partyserver-ping' }),
// JSON.stringify({ type: 'partyserver-pong' })
// )
// )
}

async onConnect(
Expand Down
20 changes: 10 additions & 10 deletions app/hooks/useRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ export default function useRoom({
}
}, [websocket])

// setup a simple ping pong
useEffect(() => {
const interval = setInterval(() => {
websocket.send(
JSON.stringify({ type: 'partyserver-ping' } satisfies ClientMessage)
)
}, 5000)

return () => clearInterval(interval)
}, [websocket])
// // setup a simple ping pong
// useEffect(() => {
// const interval = setInterval(() => {
// websocket.send(
// JSON.stringify({ type: 'partyserver-ping' } satisfies ClientMessage)
// )
// }, 5000)
//
// return () => clearInterval(interval)
// }, [websocket])

const identity = useMemo(
() => roomState.users.find((u) => u.id === websocket.id),
Expand Down
15 changes: 8 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"cookie": "^0.6.0",
"drizzle-orm": "^0.33.0",
"nanoid": "^5.0.7",
"partyserver": "^0.0.51",
"partyserver": "^0.0.57",
"partysocket": "^1.0.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down

0 comments on commit f66d932

Please sign in to comment.