mirror of
https://github.com/jcreek/EstimationPoker.git
synced 2026-07-16 04:23:44 +00:00
refactor(#35): Migrate realtime server to PartyKit and update client socket flow
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user