Protocol mismatch: packets are sent as { "a": { "0": "connect" }} instead of { "a": ["connect"] }
martikaljuve opened this issue · 2 comments
WebSocketChannel emit
and request
pass the arguments
keyword to _wrapper._sendEvent
, but the Array-like arguments
object gets JSON.stringify-d into an object instead of an array.
For example, socket.emit('event-name', 'foo', 'bar')
sends:
{ "a": { "0": "event-name", "1": "foo", "2": "bar" } }
while the protocol states it should be:
{ "a": ["event-name", "foo", "bar"] }
The arguments
object could be turned into an array to match the protocol, e.g. using Array.from(arguments)
or [...arguments]
or Array.prototype.slice.call(arguments)
.
I only noticed this issue because I decoded the packets in C# instead of JavaScript.
Thanks for the library, I've used it in several projects already.
@martikaljuve - This is an excellent catch, so thank you!
For maximum browser compatibility, I think I prefer Array.prototype.slice.call(arguments)
as the fix here. Thoughts?
Also, as a side note, I'm planning on implementing a server-side Go library for this at some point next year. (So, obviously, the protocol has to be done right). If you have started a C# library and you have the freedom to open source it, I'd love to link to it from this project!