SocketTask.onOpen

Listen to the event of enabling the WebSocket connection.

Prerequisites:

  • Supported SDK versions:
    • Android: 2.67.0
    • iOS: 2.80.0
  • Supported types of mini programs: DSL

Parameters

Function listener

The listener function to the event of enabling the WebSocket connection.

Object res

Property

Type

Description

socketTaskID

String

Indicates a socket task ID.

header

Object

Indicates the HTTP response headers for a successful WebSocket connection.

Sample code

copy
const socketTask = my.connectSocket({
  url: 'wss://...', // The url must start with ws:// or wss:// 
  multiple: true   // Under the multiple webSocket connection mode, SocketTask can be returned
});
socketTask.onOpen(res => {
  console.log(`WebSocket connection is established,socketTaskID = ${res.data.socketTaskID}`);
});