SocketTask.onMessage
Listen to the event of receiving server messages by WebSocket.
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 receiving server messages by WebSocket.
Object res
Property | Type | Description |
message | String | The messages returned by the server. |
isBuffer | Bool | Whether the message is base64-encoded. If the value of this field is |
Sample code
copy
const socketTask = my.connectSocket({
url: 'wss://...', //The url must start with ws:// or wss://
multiple: true
});
socketTask.onMessage((res) => {
console.log('socketTask.onMessage Received the message',res);
});