my.onSocketOpen

Use this API to 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

Sample code

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

Parameters

Function listener

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

Object res

Property

Type

Description

header

Object

Indicates the HTTP response headers for a successful WebSocket connection.