Skip to content
This repository has been archived by the owner on Apr 27, 2019. It is now read-only.
/ plexy Public archive

Create multiple duplex object streams that read and write through a single text stream.

License

Notifications You must be signed in to change notification settings

mmckegg/plexy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

plexy

Create multiple duplex object streams that read and write through a single text stream.

NPM

API

var Plexy = require('plexy')

Plexy(carrierStream, channelName)

Returns a duplex object stream.

Example

Server:

function CarrierStream(){ // allow streaming from and to multiple sources
  var stream = Through(function(data){
    this.outgoing.queue(data)  
  })

  stream.incoming = Through()
  stream.outgoing = Through()

  stream.incoming.on('data', function(data){
    stream.queue(data)
  })

  return stream
}

var carrierStream = CarrierStream()

var main = Plexy(carrierStream, 'main')
var sub = Plexy(carrierStream, 'sub')

// log any messages recieved from clients to console
main.on('data', function(data){
  console.write('main:', data)
})
sub.on('data', function(data){
  console.write('sub:', data)
})

var sock = shoe(function (stream) {
  carrierStream.outgoing.pipe(stream).pipe(carrierStream.incoming)
  stream.on('end', function () {
    carrierStream.outgoing.unpipe(stream)
    stream.unpipe(carrierStream.incoming)
  })
})

// send a message every 4 seconds to all connected clients on 'main' channel
setInterval(function(){
  main.write('hello all!')
}, 4000)

sock.install(server, '/stream')

Client:

var socket = Shoe('/stream')

var main = Plexy(socket, 'main')
var sub = Plexy(socket, 'sub')

// send some data to write on server console:
main.write('Some text')
main.write({message: 'an object'})

// log any messages recieved from server
main.on('data', function(data){
  console.write('main:', data)
})

sub.on('data', function(data){
  console.write('sub:', data)
})

About

Create multiple duplex object streams that read and write through a single text stream.

Resources

License

Stars

Watchers

Forks

Packages

No packages published