title: Taro.onSocketClose(callback)
sidebar_label: onSocketClose
Listens on the event of disabling the WebSocket connection.
Type
(callback: Callback) => void
Parameters
Callback
The callback function for the event of disabling the WebSocket connection.
(result: CallbackResult) => void
| Property | Type |
|---|---|
| result | CallbackResult |
CallbackResult
| Property | Type | Description |
|---|---|---|
| code | number |
A numeric value indicates the status code explaining why the connection has been disabled. |
| reason | string |
A readable string explaining why the connection has been disabled. |
Sample Code
Taro.connectSocket({url: 'test.php'})//Pay attention to the operation sequence//If you call wx.closeSocket before the wx.onSocketOpen callback for wx.connectSocket , WebSocket connection cannot be disabled.//You can only call wx.closeSocket to disable the connection when WebSocket is enabled.Taro.onSocketOpen(function () {Taro.closeSocket()})Taro.onSocketClose(function (res) {console.log('WebSocket Disabled!')})
API Support
| API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | H5 | React Native |
|---|---|---|---|---|---|
| Taro.onSocketClose | ✔️ | ✔️ | ✔️ |
