Skip to content

WebSocketsAPI

Types

binaryType

type binaryType =
| @as("arraybuffer") Arraybuffer
| @as("blob") Blob

closeEvent

A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute. See CloseEvent on MDN

type closeEvent = {
type_: WebAPI.EventAPI.eventType,
target: Null.t<WebAPI.EventAPI.eventTarget>,
currentTarget: Null.t<WebAPI.EventAPI.eventTarget>,
eventPhase: int,
bubbles: bool,
cancelable: bool,
defaultPrevented: bool,
composed: bool,
isTrusted: bool,
timeStamp: float,
wasClean: bool,
code: int,
reason: string,
}

Record fields

type_

Returns the type of event, e.g. "click", "hashchange", or "submit". Read more on MDN

target

Returns the object to which event is dispatched (its target). Read more on MDN

currentTarget

Returns the object whose event listener's callback is currently being invoked. Read more on MDN

eventPhase
int

Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE. Read more on MDN

bubbles
bool

Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise. Read more on MDN

cancelable
bool

Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method. Read more on MDN

defaultPrevented
bool

Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise. Read more on MDN

composed
bool

Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise. Read more on MDN

isTrusted
bool

Returns true if event was dispatched by the user agent, and false otherwise. Read more on MDN

timeStamp
float

Returns the event's timestamp as the number of milliseconds measured relative to the time origin. Read more on MDN

wasClean
bool

Returns true if the connection closed cleanly; false otherwise. Read more on MDN

code
int

Returns the WebSocket connection close code provided by the server. Read more on MDN

reason
string

Returns the WebSocket connection close reason provided by the server. Read more on MDN

Module

There are methods and helpers defined in CloseEvent .

closeEventInit

type closeEventInit = {
mutable bubbles?: bool,
mutable cancelable?: bool,
mutable composed?: bool,
mutable wasClean?: bool,
mutable code?: int,
mutable reason?: string,
}

Record fields

bubbles
option< bool >
cancelable
option< bool >
composed
option< bool >
wasClean
option< bool >
code
option< int >
reason
option< string >

messageEvent

A message received by a target object. See MessageEvent on MDN

type messageEvent<'t> = {
type_: WebAPI.EventAPI.eventType,
target: Null.t<WebAPI.EventAPI.eventTarget>,
currentTarget: Null.t<WebAPI.EventAPI.eventTarget>,
eventPhase: int,
bubbles: bool,
cancelable: bool,
defaultPrevented: bool,
composed: bool,
isTrusted: bool,
timeStamp: float,
data: 't,
origin: string,
lastEventId: string,
source: Null.t<messageEventSource>,
ports: array<WebAPI.ChannelMessagingAPI.messagePort>,
}

Record fields

type_

Returns the type of event, e.g. "click", "hashchange", or "submit". Read more on MDN

target

Returns the object to which event is dispatched (its target). Read more on MDN

currentTarget

Returns the object whose event listener's callback is currently being invoked. Read more on MDN

eventPhase
int

Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE. Read more on MDN

bubbles
bool

Returns true or false depending on how event was initialized. True if event goes through its target's ancestors in reverse tree order, and false otherwise. Read more on MDN

cancelable
bool

Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method. Read more on MDN

defaultPrevented
bool

Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise. Read more on MDN

composed
bool

Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise. Read more on MDN

isTrusted
bool

Returns true if event was dispatched by the user agent, and false otherwise. Read more on MDN

timeStamp
float

Returns the event's timestamp as the number of milliseconds measured relative to the time origin. Read more on MDN

data
't

Returns the data of the message. Read more on MDN

origin
string

Returns the origin of the message, for server-sent events and cross-document messaging. Read more on MDN

lastEventId
string

Returns the last event ID string, for server-sent events. Read more on MDN

source
Null.t< messageEventSource >

Returns the WindowProxy of the source window, for cross-document messaging, and the MessagePort being attached, in the connect event fired at SharedWorkerGlobalScope objects. Read more on MDN

ports

Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging. Read more on MDN

Module

There are methods and helpers defined in MessageEvent .

messageEventInit

type messageEventInit<'t> = {
mutable bubbles?: bool,
mutable cancelable?: bool,
mutable composed?: bool,
mutable data?: 't,
mutable origin?: string,
mutable lastEventId?: string,
mutable source?: Null.t<messageEventSource>,
mutable ports?: array<
WebAPI.ChannelMessagingAPI.messagePort,
>,
}

Record fields

bubbles
option< bool >
cancelable
option< bool >
composed
option< bool >
data
option< 't >
origin
option< string >
lastEventId
option< string >
source
option< Null.t< messageEventSource > >
ports

messageEventSource

type messageEventSource = WebAPI.Prelude.any

webSocket

Provides the API for creating and managing a WebSocket connection to a server, as well as for sending and receiving data on the connection. See WebSocket on MDN

type webSocket = {
url: string,
readyState: int,
bufferedAmount: int,
extensions: string,
protocol: string,
mutable binaryType: binaryType,
}

Record fields

url
string

Returns the URL that was used to establish the WebSocket connection. Read more on MDN

readyState
int

Returns the state of the WebSocket object's connection. It can have the values described below. Read more on MDN

bufferedAmount
int

Returns the number of bytes of application data (UTF-8 text and binary data) that have been queued using send() but not yet been transmitted to the network.

If the WebSocket connection is closed, this attribute's value will only increase with each call to the send() method. (The number does not reset to zero once the connection closes.) Read more on MDN

extensions
string

Returns the extensions selected by the server, if any. Read more on MDN

protocol
string

Returns the subprotocol selected by the server, if any. It can be used in conjunction with the array form of the constructor's second argument to perform subprotocol negotiation. Read more on MDN

binaryType

Returns a string that indicates how binary data from the WebSocket object is exposed to scripts:

Can be set, to change how binary data is returned. The default is "blob". Read more on MDN

Module

There are methods and helpers defined in WebSocket .