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

websocket-nats can't publish binary message(Uint8Array) #4

Closed
dbskccc opened this issue Nov 18, 2016 · 4 comments
Closed

websocket-nats can't publish binary message(Uint8Array) #4

dbskccc opened this issue Nov 18, 2016 · 4 comments

Comments

@dbskccc
Copy link

dbskccc commented Nov 18, 2016

we want to publish protobuf.js encoded message,when publish the encoded Uint8Array message,the encoded frame is not correct.

nats_con=NATS.connect("ws://192.168.1.103:4223"); nats_con.publish("foo","hello string from websocket"); nats_con.subscribe("foo",function (msg) { console.log("msg:",msg) }); //the frame of the below publish is error nats_con.publish("foo",new Uint8Array(16) ); console.log("script has exec finished");

@dbskccc
Copy link
Author

dbskccc commented Nov 18, 2016

well,translate the buffer to string first,it works.

message_str=String.fromCharCode.apply(null, buf);
nats_con.publish("foo",message_str )

@dbskccc dbskccc closed this as completed Nov 18, 2016
@isobit
Copy link
Owner

isobit commented Nov 18, 2016

Glad you were able to find a workaround!

This functionality is actually supported in node-nats using the Buffer API, which is shimmed by this in the browser. If you're using webpack or browserify, you should be able to use Buffer as it works in node.

However, I think it's a good idea to support TypedArray/ArrayBuffer as an equivalent to Buffer for binary messages out of the box, so I'm reopening this issue.

@isobit isobit reopened this Nov 18, 2016
@isobit isobit closed this as completed in 5be066b Nov 18, 2016
@isobit
Copy link
Owner

isobit commented Nov 18, 2016

It was a simple fix actually, you should be able to pass a Uint8Array directly to publish now.

@dbskccc
Copy link
Author

dbskccc commented Nov 18, 2016

thanks

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