support for binary websockets#6
Conversation
|
I think the version in this pull req is fine, I'd like this to stay as simple as possible. another option is to make it so you can create your own WebSocket in the client or WebSocket-like object in node (require('ws').Client) and just do I think this works in the server but not in the client? also before I merge this can you double check that this isn't relevent https://twitter.com/maxogden/status/299248634996879360 also scroll to bottom of 15c4d4c |
|
The
To send binary data from the client you do To receive binary data on the client you do Hmm, need to investigate more. Having the same syntax on client and server would be great. |
|
seems like the API on the server should be |
|
No you're right, it does a Isn't |
|
oh I was just saying thats the API I would write, not necessarily what I know the API that is implemented. also if you have thoughts on this TODO it could be useful here https://github.com/maxogden/level.js/blob/master/index.js#L70 |
|
cause if you try to write a typed array in node it would probably get sent as |
|
So let's make stream.write('string');
stream.write(<TypedArray>/<Buffer>)just work on both sides and on the client the default type of a received buffer is |
|
sounds good! but I think it should be TypedArray/Buffer/ArrayBuffer (I think). also I dont really care about Buffer in the browser FWIW since they are super slow and just a hack for compatibility. I like https://github.com/chrisdickinson/bops better for solving that problem anyways |
|
What about function test (obj) {
return Buffer.isBuffer(obj) || /\[object (.+Array|Array.+)\]/.test(Object.prototype.toString.call(obj));
}
test(new Float32Array()) // true
test(new ArrayBuffer()) // true
test(new Buffer(3)) // true
test([]) // false |
|
Yeah, but people (or libraries!) will use buffers anyways... |
|
yea I know :( also +1 to that function, just put a comment in the code to explain what it does |
|
nah, that goes into npm anyway ;) |
|
just checking - are you gonna update this pull req still? |
|
sec...:D |
|
should be good to merge now. I tested it with demo.js and the client received binary packets. |
support for binary websockets
|
published as 0.1.0 |
The unopinionated API for using binary sockets (as in this PR) is:
The opinionated and more elegant API (not coded yet) could be:
What do you think?