Skip to content

Commit

Permalink
[do] Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgpearce committed Oct 27, 2024
1 parent bc082d9 commit 6e27b9c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/synchronizers/synchronizer-ws-server-durable-object/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import type {Connection, WSMessage} from 'partyserver';
import {createRawPayload, ifPayloadValid} from '../common.ts';
import {EMPTY_STRING} from '../../common/strings.ts';
import {Server} from 'partyserver';

export class WsServerDurableObject extends Server {}
export class WsServerDurableObject extends Server {
onMessage(connection: Connection, message: WSMessage) {
const payload = message.toString();
ifPayloadValid(payload, (toClientId, remainder) => {
const forwardedPayload = createRawPayload(connection.id, remainder);
if (toClientId === EMPTY_STRING) {
this.broadcast(forwardedPayload, [connection.id]);
} else {
this.getConnection(toClientId)?.send(forwardedPayload);
}
});
}
}

0 comments on commit 6e27b9c

Please sign in to comment.