ВОЙТИ

WebSocket

Represents a WebSocket object to connect to a server, and then send and receive data on the connection.

Methods

addEventListener

addEventListener(event: WebSocketEvents, listener: Function): void

Adds a handler for the specified event triggered by a Websocket object.

Parameters

  • WebSocket event type to listen for.

  • listener:

    Function

    Function to run when the event occurs.

Returns

  • Return:

    void

close

close(): void

Closes the WebSocket connection or connection attempt.

Returns

  • Return:

    void

removeEventListener

removeEventListener(event: WebSocketEvents, listener: Function): void

Removes a handler for the specified event triggered by a Websocket object.

Parameters

  • WebSocket event type whose event listener should be removed.

  • listener:

    Function

    Function to remove from the event target.

Returns

  • Return:

    void

send

send(data: String): void

Enqueues the specified data to be transmitted to the server over the WebSocket connection.

Parameters

  • data:

    String

    Text data to send to the server.

Returns

  • Return:

    void

Properties

onclose

onclose: Function

Event handler is called when the connection is open (ready to send and receive data).

onerror

onerror: Function

Event handler is called when an error occurs.

onmessage

onmessage: Function

Event handler is called when a message is received from the server.

readyState

readyState: WebSocketReadyState

Returns the current state of the WebSocket connection.

url

url: String

Returns the absolute URL of the WebSocket.