MCPcopy Create free account
hub / github.com/middleapi/orpc / message

Method message

packages/server/src/adapters/websocket/handler.ts:44–63  ·  view source on GitHub ↗

* Handles a single message received from a WebSocket. * * @warning Avoid calling this directly if `.upgrade()` is used. * * @param ws The WebSocket instance * @param data The message payload, usually place in `event.data`

(
    ws: MinimalWebsocket,
    data: string | ArrayBuffer | Blob,
    ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>
  )

Source from the content-addressed store, hash-verified

42 * @param data The message payload, usually place in `event.data`
43 */
44 async message(
45 ws: MinimalWebsocket,
46 data: string | ArrayBuffer | Blob,
47 ...rest: MaybeOptionalOptions<HandleStandardServerPeerMessageOptions<T>>
48 ): Promise<void> {
49 let peer = this.#peers.get(ws)
50
51 if (!peer) {
52 this.#peers.set(ws, peer = new ServerPeer(ws.send.bind(ws)))
53 }
54
55 const message = data instanceof Blob
56 ? await readAsBuffer(data)
57 : data
58
59 await peer.message(
60 message,
61 createServerPeerHandleRequestFn(this.#handler, resolveMaybeOptionalOptions(rest)),
62 )
63 }
64
65 /**
66 * Closes the WebSocket peer and cleans up.

Callers 1

upgradeMethod · 0.95

Calls 5

readAsBufferFunction · 0.90
setMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected