interface IDurableObjectClientSocket
Since 0.2.0

The client half of a WebSocketPair, or the socket a Worker gets back from a Durable Object upgrade.

Distinct from IDurableObjectWebSocket because this side must be accept()ed and listened to, while the DO side is accepted by the runtime through state.acceptWebSocket and never listened to directly.

Methods

accept(): void

Begins handling the socket in this isolate.

Not to be confused with state.acceptWebSocket, which is the DO-side hibernation call — see IDurableObjectState.acceptWebSocket.

send(message: string | ArrayBuffer): void

Sends one frame to the peer.

close(
code?: number,
reason?: string
): void

Closes the connection.

addEventListener(
type: "message" | "close" | "error",
listener: (event: DurableObjectMessageEvent) => void
): void

Subscribes to a socket event.

Usage

import { type IDurableObjectClientSocket } from "cloudflare-plugin/src/index.ts";