SocketTask overview

WebSocket task. This is returned when my.connectSocket JSAPI creates a multi-instance WebSocket (multiple = true). For details, see the multiple​ ​parameter.

Property

Property

Type

Required

Description

readyState

Number

Yes

The state of SocketTask. Valid values:

  • 0: Is connecting (CONNECTING)
  • 1: Has connected (OPEN)
  • 2: Is closing (CLOSING)
  • 3: Has closed (CLOSED)

Methods

Method name

Type

Description

SocketTask.send

Function

Send data via WebSocket.

SocketTask.close

Function

Close the WebSocket connection.

SocketTask.onOpen

Function

Listen to the event of enabling the WebSocket connection.

SocketTask.onClose

Function

Listen to the event of disabling the WebSocket connection.

SocketTask.onError

Function

Listen to WebSocket error events.

SocketTask.onMessage

Function

Listen to the event of receiving server messages by WebSocket.

SocketTask.offOpen

Function

Unlisten to the event of enabling the WebSocket connection.

SocketTask.offClose

Function

Unlisten to the event of disabling the WebSocket connection.

SocketTask.offError

Function

Unlisten to WebSocket error events.

SocketTask.offMessage

Function

Unlisten to the event of receiving server messages by WebSocket.