Skip to content

WebSocket

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3436

The WebSocket object provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection.

MDN Reference

readonly extensions: null | string

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3492

The WebSocket.extensions read-only property returns the extensions selected by the server.

MDN Reference


readonly protocol: null | string

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3486

The WebSocket.protocol read-only property returns the name of the sub-protocol the server selected; this will be one of the strings specified in the protocols parameter when creating the WebSocket object, or the empty string if no connection is established.

MDN Reference


readonly readyState: number

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3474

The WebSocket.readyState read-only property returns the current state of the WebSocket connection.

MDN Reference


readonly url: null | string

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3480

The WebSocket.url read-only property returns the absolute URL of the WebSocket as resolved by the constructor.

MDN Reference

accept(): void

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3454

void


addEventListener<Type>(type, handler, options?): void

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:878

The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.

MDN Reference

Type extends keyof WebSocketEventMap

Type

EventListenerOrEventListenerObject<WebSocketEventMap[Type]>

boolean | EventTargetAddEventListenerOptions

void

EventTarget.addEventListener


close(code?, reason?): void

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3466

The WebSocket.close() method closes the already CLOSED, this method does nothing.

MDN Reference

number

string

void


deserializeAttachment(): any

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3468

any


dispatchEvent(event): boolean

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:898

The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order.

MDN Reference

Event | MessageEvent | CloseEvent | ErrorEvent

boolean

EventTarget.dispatchEvent


removeEventListener<Type>(type, handler, options?): void

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:888

The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target.

MDN Reference

Type extends keyof WebSocketEventMap

Type

EventListenerOrEventListenerObject<WebSocketEventMap[Type]>

boolean | EventTargetEventListenerOptions

void

EventTarget.removeEventListener


send(message): void

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3460

The WebSocket.send() method enqueues the specified data to be transmitted to the server over the WebSocket connection, increasing the value of bufferedAmount by the number of bytes needed to contain the data.

MDN Reference

string | ArrayBuffer | ArrayBufferView<ArrayBufferLike>

void


serializeAttachment(attachment): void

Defined in: node_modules/.pnpm/@cloudflare+workers-types@4.20251118.0/node_modules/@cloudflare/workers-types/index.ts:3467

any

void