MCPcopy
hub / github.com/partykit/partykit / onConnect

Function onConnect

examples/basic/src/server.ts:49–64  ·  view source on GitHub ↗
(ws, room)

Source from the content-addressed store, hash-verified

47 })().catch(console.error);
48 },
49 onConnect(ws, room) {
50 console.log(room.env);
51
52 console.log(process.env.WHATUP);
53
54 console.log(SOME_GLOBAL);
55 // your business logic here
56 ws.addEventListener("message", (evt) => {
57 const connections = [...room.getConnections()];
58 if (evt.data === "ping") {
59 ws.send(`pong:${connections.length}`);
60 } else if ((evt.data as string).startsWith("latency")) {
61 ws.send(evt.data);
62 }
63 });
64 },
65
66 // onMessage(msg, conn, room) {
67 // if (msg === "ping") {

Callers

nothing calls this directly

Calls 2

getConnectionsMethod · 0.65
sendMethod · 0.45

Tested by

no test coverage detected