SocketTask.onClose

Listen to the event of disabling 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 disabling the WebSocket connection.

Object res

Property

Type

Description

code

Number

The close status code of the WebSocket connection.

reason

String

The close reason of the WebSocket connection.

Sample code

copy
const socketTask = my.connectSocket({
  url: 'wss://...',  //  The url must start with ws:// or wss://
  multiple: true
});
socketTask.close();
socketTask.onClose((res) => {
  console.log('socketTask.onClose connection is closed!',res);
});