Skip to content

Instantly share code, notes, and snippets.

@johnou
Created November 9, 2019 19:16
Show Gist options
  • Save johnou/dc919444df86404ef38329a0356c6783 to your computer and use it in GitHub Desktop.
Save johnou/dc919444df86404ef38329a0356c6783 to your computer and use it in GitHub Desktop.
/**
* 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