title: Taro.onSocketMessage(callback)
sidebar_label: onSocketMessage
Listens on the event of receiving server messages by WebSocket
Type
<T = any>(callback: Callback<T>) => void
Parameters
Callback
The callback function for the event of receiving server messages by WebSocket.
(result: CallbackResult<T>) => void
| Property | Type |
|---|---|
| result | CallbackResult<T> |
CallbackResult
| Property | Type | Description |
|---|---|---|
| data | T |
Messages returned by the server |
Sample Code
Taro.connectSocket({url: 'test.php'})Taro.onSocketMessage(function (res) {console.log('receive msg:' + res.data)})
API Support
| API | WeChat Mini-Program | Baidu Smart-Program | Alipay Mini-Program | H5 | React Native |
|---|---|---|---|---|---|
| Taro.onSocketMessage | ✔️ | ✔️ | ✔️ |
