my.sendSocketMessage

Use this API to send data over WebSocket connection. Call my.connectSocket first and send data after the my.onSocketOpen callback.

Sample Code

copy
my.sendSocketMessage({
    data: this.data.toSendMessage, // The data to be sent
    success: (res) => {
        my.alert({content: 'The data sent!' + this.data.toSendMessage});
    },
});

Note:The case is only for reference. Please use your own URL to test.

Parameters

PropertyType

Required

Description
dataStringYesThe data to be sent, in text string or base64 encoded string.
isBufferBooleanNoIf the value of this field is true, the data field represents the received base64 encoded binary strings. If the value of this field is empty, the data field represents normal strings.
successFunctionNoThe callback function for a successful API call.
failFunctionNoThe callback function for a failed API call.
completeFunctionNoThe callback function used when the API call is completed. This function is always executed no matter the call succeeds or fails.