Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol mismatch: packets are sent as { "a": { "0": "connect" }} instead of { "a": ["connect"] } #9

Closed
martikaljuve opened this issue Nov 22, 2019 · 2 comments

Comments

@martikaljuve
Copy link

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.

@bminer
Copy link
Owner

bminer commented Nov 22, 2019

@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?

@bminer
Copy link
Owner

bminer commented Nov 22, 2019

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!

@bminer bminer closed this as completed in 054083a Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants