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

"a" leading sendEvent data #8

Closed
cTatu opened this issue Jul 22, 2019 · 3 comments
Closed

"a" leading sendEvent data #8

cTatu opened this issue Jul 22, 2019 · 3 comments
Labels

Comments

@cTatu
Copy link

cTatu commented Jul 22, 2019

Hi, the wrapper is amazing but I have a question about the _sendEvent function (line 249). I'm trying to implement the same wrapper for this flutter websocket plugin and looking at the raw data sent by your wrapper I noticed the key "a" on the object that will be sent to the other end of the socket. Why is that? I tried removing it and stringify the args object directly also works. Moreover removing it will make it easier for my to parse it on flutter.

Thank you!

ws-wrapper/lib/wrapper.js

Lines 247 to 252 in 0e544c6

_sendEvent(channel, eventName, args, isRequest) {
// Serialize data for sending over the socket
var data = {"a": args};
if(channel != null) {
data.c = channel;
}

@cTatu cTatu closed this as completed Jul 23, 2019
@bminer
Copy link
Owner

bminer commented Jul 29, 2019

It's just part of the protocol. Honestly, I chose a because it's short and requires little bandwidth. "a" stands for "arguments".

Please let me know if you have any other questions. Best of luck!

@cTatu
Copy link
Author

cTatu commented Jul 30, 2019

Awesome thank you, I was able to implement it successfully tough here it is :)

One more question, this wrapper supports binary data? I think would require adding a raw method of sending the data, without encoding it to json.

@bminer
Copy link
Owner

bminer commented Jul 30, 2019

Yes, the wrapper does support binary data, and it simply ignores any message that is invalid JSON.

From the docs:

If the message received by the WebSocket is not valid JSON or if the parsed Object does not match one of the above message types, then the message is simply ignored by ws-wrapper. Also if the JSON message contains a ws-wrapper property with the value false, the message will be ignored. This allows other libraries to use the same WebSocket and send messages that will not be processed by ws-wrapper.

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants