Socket.IO stream
This is the module for bidirectional binary data transfer with Stream API through Socket.IO.
Installation
npm install socket.io-stream
Usage
If you are not familiar with Stream API, be sure to check out the docs. I also recommend checking out the awesome Stream Handbook.
For streaming between server and client, you will send stream instances first.
To receive streams, you just wrap socket with socket.io-stream, then listen any events as usual.
Server:
var io = ;var ss = ;var path = ; io;createStream() returns a new stream which can be sent by emit().
Client:
var io = ;var ss = ; var socket = io;var stream = ss;var filename = 'profile.jpg'; ;fs;You can stream data from a client to server, and vice versa.
// send data; // receive data;stream;Browser
This module can be used on the browser. To do so, just copy a file to a public directory.
$ cp node_modules/socket.io-stream/socket.io-stream.js somewhere/public/
You can also use browserify to create your own bundle.
$ npm install browserify -g
$ cd node_modules/socket.io-stream
$ browserify index.js -s ss > socket.io-stream.js
Upload progress
You can track upload progress like the following:
var blobStream = ss;var size = 0; blobStream; blobStream;Socket.IO v0.9 support
You have to set forceBase64 option true when using the library with socket.io v0.9.x.
ssforceBase64 = true;Documentation
ss(sio)
- sio
socket.io SocketA socket of Socket.IO, both for client and server - return
Socket
Look up an existing Socket instance based on sio (a socket of Socket.IO), or create one if it doesn't exist.
socket.emit(event, [arg1], [arg2], [...])
- event
StringThe event name
Emit an event with variable number of arguments including at least a stream.
; // send some streams at a time.; // as members of array or object.; // get streams through the ack callback;socket.on(event, listener)
- event
StringThe event name - listener
FunctionThe event handler function
Add a listener for event. listener will take stream(s) with any data as arguments.
; // access stream options;ss.createStream([options])
- options
Object- highWaterMark
Number - encoding
String - decodeStrings
Boolean - objectMode
Boolean - allowHalfOpen
Booleaniftrue, then the stream won't automatically close when the other endpoint ends. Default tofalse.
- highWaterMark
- return
Duplex Stream
Create a new duplex stream. See the docs for the details of stream and options.
var stream = ss; // with optionsvar stream = ss;ss.createBlobReadStream(blob, [options])
- options
Object- highWaterMark
Number - encoding
String - objectMode
Boolean
- highWaterMark
- return
Readable Stream
Create a new readable stream for Blob and File on browser. See the docs for the details of stream and options.
var stream = ss;ss.Buffer
Node Buffer class to use on browser, which is exposed for convenience. On Node environment, you should just use normal Buffer.
var stream = ss;stream;License
MIT

