SocketTask.close
Close the WebSocket connection.
Prerequisites:
- Supported SDK versions:
- Android: 2.67.0
- iOS: 2.80.0
- Supported types of mini programs: DSL
Sample code
See the following JavaScript sample code:
const socketTask = my.connectSocket({
url: 'wss://...',
multiple: true,
})
socketTask.onClose(()=>{
console.log('WebSocket is closed!');
});
socketTask.close();Parameters
The incoming parameter is of the Object type with the following properties:
Property | Type | Required | Description |
code | Number | No | The close status code of the WebSocket connection. Valid value:
|
reason | String | No | The close reason of the WebSocket connection. |
success | Function | No | The callback function for a successful API call. |
fail | Function | No | The callback function for a failed API call. |
complete | Function | No | The callback function used when the API call is completed. This function is always executed no matter the call succeeds or fails. |
success/fail/complete callback function
The following table provides the properties in the success/fail/complete callback function:
Property | Data type | Description |
error | Number | The error code. |
errorMessage | String | The error message. |
Error codes
Error code | Error message | Further action |
2 | Code can only be 1000, or between 3000 and 4999 | The close status code of the WebSocket connection can only be 1000 or between 3000 and 4999. Check the |