my.onSocketMessage
Use this API to listen to the event of receiving server messages by WebSocket.
Supported types of mini programs: DSL
Callback Return Value
Property | Type | Description |
data | String / ArrayBuffer | The messages returned by the server, in text string or base64 encoded string. |
isBuffer | Boolean | Whether the message is base64-encoded.
|
Sample Code
copy
my.connectSocket({
url: 'Server URL'
})
my.onSocketMessage(function(res) {
console.log('Server content received:' + res.data)
})Note: The case is only for reference. Please use your own URL to test.