Created
November 9, 2019 19:16
-
-
Save johnou/dc919444df86404ef38329a0356c6783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Send message over WebSocket | |
* | |
* @param instanceId Instance ID | |
* @param bufferPtr Pointer to the message buffer | |
* @param length Length of the message in the buffer | |
*/ | |
WebSocketSend: function(instanceId, bufferPtr, length) { | |
var instance = webSocketState.instances[instanceId]; | |
if (!instance) return -1; | |
if (instance.ws === null) | |
return -3; | |
if (instance.ws.readyState !== 1) | |
return -6; | |
instance.ws.send(HEAPU8.buffer.slice(bufferPtr, bufferPtr + length)); | |
return 0; | |
}, | |
/// <summary> | |
/// Send binary data over the socket. | |
/// </summary> | |
/// <param name="data">Payload data.</param> | |
public void Send(byte[] data) | |
{ | |
int ret = WebSocketSend(this.instanceId, data, data.Length); | |
if (ret < 0) | |
throw WebSocketHelpers.GetErrorMessageFromCode(ret, null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment