Convert your socket.io sockets into duplex streams.
This module is based on the work of websocket-stream we modified the code to support socket.io
$ npm install @geut/socket.io-streamify
const streamify = require('@geut/socket.io-streamify')
const stream = streamify('http://localhost:3000')
stream.on('data', chunk => {
console.log(chunk.toString('utf8'))
})
stream.write('hello from client')
const { createServer } = require('@geut/socket.io-streamify')
createServer(3000, stream => {
stream.on('data', (data) => {
console.log(data.toString('utf8'))
stream.write('hi from server')
})
})
The available options differs depending on if you use this module in the browser or with node.js.
How much to allow the socket.bufferedAmount to grow before starting to throttle writes. This option has no effect in node.js.
Default: 1024 * 512
(512KiB)
How long to wait before checking if the socket buffer has drained sufficently for another write. This option has no effect in node.js.
Default: 1000
(1 second)
Send each chunk on its own, and do not try to pack them in a single websocket frame.
Default: false
Always convert to Buffer
in Node.js before sending.
Forces options.objectMode
to false
.
Default: true
Options for the socketIO instance.
Options are part of Socket.IO server.
function (stream) {}
Execute it every time the server gets a new socket connection.
Add a listener for a stream
event.
Remove a listener for a stream
event.
🐛 If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.
👥 Ideas and contributions to the project are welcome. You must follow this guideline.
MIT © A GEUT project