@geut/socket.io-streamify

1.0.0 • Public • Published

socket.io-streamify

Build Status JavaScript Style Guide standard-readme compliant

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

Install

$ npm install @geut/socket.io-streamify

Usage

Client

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

const { createServer } = require('@geut/socket.io-streamify')

createServer(3000, stream => {
  stream.on('data', (data) => {
    console.log(data.toString('utf8'))
    stream.write('hi from server')
  })
})

API

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 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.

Issues

🐛 If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.

Contributing

👥 Ideas and contributions to the project are welcome. You must follow this guideline.

License

MIT © A GEUT project

Readme

Keywords

Package Sidebar

Install

npm i @geut/socket.io-streamify

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

10.7 kB

Total Files

8

Last publish

Collaborators

  • geutuser
  • the-real-dk
  • tinchoz49
  • estebanprimost