Example #1
0
module.exports = function (db, store) {
    var plex = dataplex();
    plex.add('/users', function (opts) {
        return db.createReadStream({
            gt: [ 'user', defined(opts.gt, null) ],
            lt: [ 'user', defined(opts.lt, undefined) ]
        }).pipe(stringify());
    });
    plex.add('/save/music', function (opts) {
        var w = store.createWriteStream();
        var output = through();
        w.on('close', function () { output.end(w.key) });
        return duplexer(w, output);
    });
    stream.pipe(plex).pipe(stream);
};
Example #2
0
var wsServer = require('ws').Server 
var wsStream = require('websocket-stream')
var wss = new wsServer({noServer: true})
var ecstatic = require('ecstatic')
var www = ecstatic(__dirname + '/public')
var dataplex = require('dataplex')
var through = require('through2')

var plex = dataplex()
plex.setMaxListeners(0)
var conx = {}

plex.add('/v1/subscribe/:name/:channel', function(params, cb){

  var n = params.name, c = params.channel
  if(!conx[n]) {
    conx[n] = {}
  }
  if(!conx[n][c]){
    conx[n][c] = through(function(buf, x, next){
      this.push(buf)
      next()
    })
  }
  
  return conx[n][c]
})

plex.add('/v1/broadcast/:name/:channel', function(params, cb){
  var n = params.name, c = params.channel
  if(!conx[n]) {
Example #3
0
function onstream (stream) {
    var plex = dataplex();
    stream.pipe(plex).pipe(stream);
}