A browser-compatible WebSocket implementation (undici).

Stable since Node.js v22.4.0. Disable with --no-experimental-websocket.

See also:

Static variables

@:value(3)staticinlineread onlyCLOSED:Int = 3

@:value(2)staticinlineread onlyCLOSING:Int = 2

@:value(0)staticinlineread onlyCONNECTING:Int = 0

@:value(1)staticinlineread onlyOPEN:Int = 1

Constructor

new(url:String, ?protocols:EitherType<String, Array<String>>)

new(url:URL, ?protocols:EitherType<String, Array<String>>)

new(url:String, ?options:WebSocketInit)

new(url:URL, ?options:WebSocketInit)

Variables

Methods

Inherited Variables

Inherited Methods

Defined by EventTarget

addEventListener(type:String, listener:Function, ?options:EitherType<AddEventListenerOptions, Bool>):Void

addEventListener(type:String, listener:EventListener, ?options:EitherType<AddEventListenerOptions, Bool>):Void

Adds a new handler for the type event. Any given listener is added only once per type and per capture option value.

dispatchEvent(event:Event):Bool

Dispatches the event to the list of handlers for event.type.

Returns:

true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, otherwise false.

removeEventListener(type:String, listener:Function, ?options:EitherType<EventListenerOptions, Bool>):Void

removeEventListener(type:String, listener:EventListener, ?options:EitherType<EventListenerOptions, Bool>):Void

Removes the listener from the list of handlers for event type.