interpretor / zyre.js

Node.js port of Zyre - an open-source framework for proximity-based peer-to-peer applications
Mozilla Public License 2.0
37 stars 7 forks source link

Send raw buffers using whisper and shout #5

Closed Dev1an closed 7 years ago

Dev1an commented 7 years ago

If I understand it correctly your API allows us only to send String messages.

Is it also possible to whisper raw buffers to other zyre peers?

interpretor commented 7 years ago

Yes, it's possible. I am already testing it in binary-messages. I am just not sure about usability, because if I change the API, a console.log(msg) will result in a <Buffer 61 73 64 66>. You would have to use console.log(msg.toString()) to read string messages. Sending messages would be no problem, as zyre.whisper() and zyre.shout() accept raw buffers as well.

If you want to test raw buffers now on your side, you could add "zyre.js": "interpretor/zyre.js#binary-messages" as a dependency in package.json. Let me know how you think about it, and then we could add this in a new release.

Dev1an commented 7 years ago

Maybe you can use the same api as the Readable Stream. So that you can change the encoding of messages using a method .setEncoding(encoding).

If you then want your new API to be backwards compatible with the current one, you could set the default encoding to "utf8". And users that need raw buffer access can simply call Zyre#setEncoding(null), an API they are already comfortable with since this is the common way to this in NodeJS API's.

interpretor commented 7 years ago

Good idea! I will look into this and update the binary-messages branch. Would be great if you test it when it's updated.

Dev1an commented 7 years ago

Sure, I would be happy to test it!

And thanks for your nice API, it makes things way simpler than trying to use the official NodeJS Zyre binding 🙂.

interpretor commented 7 years ago

I pushed a commit which adds support for multiple encodings plus the possibility to receive raw Buffers. https://github.com/interpretor/zyre.js/commit/d4fa9676d6576a72c0976d3c90f53c60102ca709

interpretor commented 7 years ago

Merged to master