Taro.onSocketOpen(callback)
Listens on the event of enabling the WebSocket connection.
Type
(callback: Callback) => void
Parameters
Callback
The callback function for the event of enabling the WebSocket connection.
(result: OpenCallbackResult) => void
Property | Type |
---|---|
result | OpenCallbackResult |
OpenCallbackResult
Property | Type | Description |
---|---|---|
header | Record<string, any> | Connected HTTP response header |
Sample Code
Taro.connectSocket({
url: 'test.php'
})
Taro.onSocketOpen(function (res) {
console.log('WebSocket connection is open!')
})
API Support
API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | H5 | React Native |
---|---|---|---|---|---|
Taro.onSocketOpen | ✔️ | ✔️ | ✔️ |