refactor(#35): Migrate realtime server to PartyKit and update client socket flow

This commit is contained in:
Josh Creek
2026-01-25 19:03:03 +00:00
parent 31026b9a63
commit dc5df3c177
9 changed files with 323 additions and 173 deletions
+31
View File
@@ -0,0 +1,31 @@
import type * as Party from "partykit/server";
export default class Server implements Party.Server {
constructor(readonly room: Party.Room) {}
onConnect(conn: Party.Connection, ctx: Party.ConnectionContext) {
// A websocket just connected!
console.log(
`Connected:
id: ${conn.id}
room: ${this.room.id}
url: ${new URL(ctx.request.url).pathname}`
);
// let's send a message to the connection
conn.send("hello from server");
}
onMessage(message: string, sender: Party.Connection) {
// let's log the message
console.log(`connection ${sender.id} sent message: ${message}`);
// as well as broadcast it to all the other connections in the room...
this.room.broadcast(
`${sender.id}: ${message}`,
// ...except for the connection it came from
[sender.id]
);
}
}
Server satisfies Party.Worker;