Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

WebSocket

Functions

close
(
socket
:
WebSocket
)
:
Promise(Void)

Closes the given websocket connection.

WebSocket.close(websocket)

If the reconnectOnClose flag was specified then the connection will reconnect using this function.

closeWithoutReconnecting
(
socket
:
WebSocket
)
:
Promise(Void)

Closes the given websocket connection without reconnecting, even if the reconnectOnClose flag was set.

WebSocket.closeWithoutReconnecting(websocket)
open
(
config
:
WebSocket.Config
)
:
WebSocket

Creates a websocket connection from the given configuration:

websocket =
  WebSocket.open({
    url: "wss://echo.websocket.org",
    reconnectOnClose: true,
    onMessage: handleMessage,
    onError: handleError,
    onClose: handleClose,
    onOpen: handleOpen
  })

If reconnectOnClose is set then when a connection is closed it tries to reconnect, using the same configuration (basically calls open again).

send
(
socket
:
WebSocket
data
:
String
)
:
Promise(Void)

Sends the given data to the given websocket connection.

WebSocket.send(websocket, "some data")