GithubHelp home page GithubHelp logo

browser-stream's Introduction

BrowserStream

use Stream#pipe to send data to clients or servers.

wrap socket.io (or another web socket abstraction that gives a remote EventEmitter api) with a interface for creating streams.

DEPRECIATED

use mux-demux with shoe

I'm not gonna use or maintain this any more. If you want to use and maintain this module email me and I'll add you as owner.

install

npm install browser-stream

example

client

  var bs = require('browser-stream')(io.connect('http://localhost:3000'))
  var domnode = require('domnode') //see https://github.com/maxogden/dominode
  var opts = {options: 'pass an optional object with the createReadStream message. maybe useful!'})
  //pipe the 'whatever' stream to the dom with dominode.
  bs.createReadStream('whatever', options)
    .on('error', function (err) {
      //unexpected disconnect
      console.error(err)
    })
    .pipe(domnode('#list', '<li id="item"></li>'))

server

io = io.listen(app) //see https://github.com/LearnBoost/socket.io
var _bs = require('browser-stream')

io.sockets.on('connection', function (sock) {

  var bs = _bs(sock) 

  var whatever = new Stream() // SOME KIND OF STREAM
  bs.on('connection', function (stream, opts) {
    if(stream.name == 'whatever') 
      whatever.pipe(stream)
    //stream.options -- will be the same as `opts` from the client side!
    stream.on('error', function (err) {
      //the client has unexpectedly disconnected. tidy up!
      console.error(err)
    })
  })

}

this will connect whatever to the Dominode stream, rendering it, in the browser!

API

var _bs = require('browser-stream')

io.sockets.on('connection', function (sock) {
  var bs = _bs(sock)
  bs.on('connection', function (stream) {
    //stream is a pipable node.js `Stream` instance
  })
})

createReadStream (name, options)

open a ReadableStream from the other side. returns a ReadableStream. the other side of connection will emit a writable stream that is connected to this stream.

createWriteStream (name, options)

open a WritableStream to the other side. returns a WritableStream, the other side will emit a ReadableStream connected to this stream.

createStream (name, options)

open a Stream to the other side which is both readable and writable. returns a Stream, the other side will emit a Stream connected to this stream.

note to self, references to a class (Stream) should be capitalized, and in backticks. references to an instance should be lowercase, and not in backticks unless refuring to a specific variable in a code example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.