https://github.com/geut/socket.io-streamify
Convert your socket.io sockets into duplex streams.
https://github.com/geut/socket.io-streamify
duplex-stream socket socketio stream
Last synced: 4 months ago
JSON representation
Convert your socket.io sockets into duplex streams.
- Host: GitHub
- URL: https://github.com/geut/socket.io-streamify
- Owner: geut
- License: mit
- Created: 2019-09-18T22:14:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-18T23:12:08.000Z (over 5 years ago)
- Last Synced: 2025-01-02T14:31:45.583Z (5 months ago)
- Topics: duplex-stream, socket, socketio, stream
- Language: JavaScript
- Size: 10.7 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# socket.io-streamify
[](https://travis-ci.com/geut/socket.io-streamify)
[](https://standardjs.com)
[](https://github.com/RichardLitt/standard-readme)> Convert your socket.io sockets into duplex streams.
This module is based on the work of [websocket-stream](https://github.com/maxogden/websocket-stream) we modified the code to support socket.io
```
$ npm install @geut/socket.io-streamify
```### Client
```javascript
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')
```### Server
```javascript
const { createServer } = require('@geut/socket.io-streamify')createServer(3000, stream => {
stream.on('data', (data) => {
console.log(data.toString('utf8'))
stream.write('hi from server')
})
})
```#### `const stream = streamify(url|socket, [options])`
#### Options
The available options differs depending on if you use this module in the browser or with node.js.
##### `options.browserBufferSize`
How much to allow the [socket.bufferedAmount](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket#Attributes) to grow before starting to throttle writes. This option has no effect in node.js.
Default: `1024 * 512` (512KiB)
##### `options.browserBufferTimeout`
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)
##### `options.objectMode`
Send each chunk on its own, and do not try to pack them in a single
websocket frame.Default: `false`
##### `options.binary`
Always convert to `Buffer` in Node.js before sending.
Forces `options.objectMode` to `false`.Default: `true`
##### `options.socketIO`
Options for the socketIO instance.
#### `const io = streamify.createServer(port|server, [options], [callback])`
#### Options
Options are part of Socket.IO server.
#### Callback
`function (stream) {}`
Execute it every time the server gets a new socket connection.
#### `io.onStream(stream => {})`
Add a listener for a `stream` event.
#### `io.removeOnStream(stream => {})`
Remove a listener for a `stream` event.
:bug: If you found an issue we encourage you to report it on [github](https://github.com/geut/socket.io-streamify/issues). Please specify your OS and the actions to reproduce it.
:busts_in_silhouette: Ideas and contributions to the project are welcome. You must follow this [guideline](https://github.com/geut/socket.io-streamify/blob/master/CONTRIBUTING.md).
## License
MIT © A [**GEUT**](http://geutstudio.com/) project