MCPcopy Create free account
hub / github.com/vercel/examples / open

Function open

websockets/nuxt/server/api/ws.ts:22–35  ·  view source on GitHub ↗
(peer)

Source from the content-addressed store, hash-verified

20
21export default defineWebSocketHandler({
22 open(peer) {
23 const identity = createIdentity()
24 peer.context.identity = identity
25
26 peer.subscribe(CHANNEL)
27
28 // Capture the roster of existing peers *before* adding self, so `welcome.peers`
29 // excludes the new peer (the client tracks self separately via `welcome.self`).
30 const roster = [...peers.values()]
31 peers.set(identity.id, identity)
32
33 send(peer, { t: 'welcome', self: identity, peers: roster })
34 peer.publish(CHANNEL, JSON.stringify({ t: 'join', peer: identity } satisfies ServerMessage))
35 },
36 message(peer, message) {
37 const identity = peer.context.identity as Peer | undefined
38 if (!identity) return

Callers 2

manage.pyFile · 0.50
agent.pyFile · 0.50

Calls 4

createIdentityFunction · 0.90
setMethod · 0.80
publishMethod · 0.80
sendFunction · 0.70

Tested by

no test coverage detected