cettia-javascript-client icon indicating copy to clipboard operation
cettia-javascript-client copied to clipboard

ArrayBuffer not sent as binary message

Open ralscha opened this issue 5 years ago • 1 comments

Hi There is a small bug in the tutorial (or in the code):
https://cettia.io/guides/cettia-tutorial/

The tutorial states

As the example suggests, event data can be basically anything as long as it is serializable, >regardless of whether data is binary or text. If at least one of the properties of the event data to >send is one of the following,

byte[] or ByteBuffer in the server. Buffer (Node.js only), ArrayBuffer, or Typed Arrays in the client.

I just tried to send an ArrayBuffer with send() and Cettia-Javascript sends it as text message. The reason for that is that the check if there is binary data in the message does not work for ArrayBuffer objects.

https://github.com/cettia/cettia-javascript-client/blob/master/src/cettia.es6#L556-L562

ArrayBuffer.isView(value) returns false when the value is an ArrayBuffer. It works when I wrap the ArrayBuffer for example in an Uint8Array, cettia-javascripts sends a binary message.

ralscha avatar Apr 24 '20 13:04 ralscha

Thanks for reporting a bug 😄 I've just confirmed that ArrayBuffer.isView returns false when an ArrayBuffer instance is given.

BTW sorry for the late response. Please ping my username so that I can receive notification.

flowersinthesand avatar May 08 '20 16:05 flowersinthesand