* 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>>
)
| 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. |
no test coverage detected