How to use the livedb.memory function in livedb

To help you get started, we’ve selected a few livedb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cucumber-ltd / share-primus / example / server.js View on Github external
var livedb = require('livedb');
var share = require('share');
var sharePrimus = require('../lib');
var Primus = require('primus');
var argv = require('optimist').argv;

var app = express();
app.use(express.static(__dirname));
app.use(express.static(share.scriptsDir));
app.use(express.static(sharePrimus.scriptsDir));
var server = http.createServer(app);

var primus = new Primus(server, { transformer: argv.transformer });
primus.use('substream', require('substream'));

var db = new livedb.memory();
var backend = livedb.client(db);
var shareClient = share.server.createClient({backend:backend});

primus.on('connection', function (spark) {
  console.log('New client');
  var shareSpark = spark.substream('share');
  // Workaround for https://github.com/primus/primus/issues/121
  shareClient.listen(new sharePrimus.SparkStream(shareSpark));

  // Send some non-share messages over the same stream
  // Inspired by https://github.com/einaros/ws/blob/master/examples/serverstats/server.js
  var processSpark = spark.substream('process');
  var id = setInterval(function() {
    processSpark.write(JSON.stringify(process.memoryUsage()));
  }, 100);
github MisterTea / TidalWave / TidalWave / server / sharejs-handler.js View on Github external
var Duplex = require('stream').Duplex;
var browserChannel = require('browserchannel').server;
var livedb = require('livedb');
var sharejs = require('share');
var express = require('express');
var log = require('./logger').log;

var model = require('./model');
var Page = model.Page;
var PageVersion = model.PageVersion;
var User = model.User;

var database = livedb.memory();
var backend = livedb.client(database);

var LiveSync = require('./livesync');
LiveSync.init(backend.driver, database);

var pageConnectionMap = {};

exports.init = function(app) {
  backend.addProjection('_users', 'users', 'json0', {
    x: true
  });
  var share = sharejs.server.createClient({
    backend: backend
  });
  app.use(express.static(sharejs.scriptsDir));
  app.use(browserChannel({
github share / share-codemirror / examples / server.js View on Github external
var http = require('http');
var Duplex = require('stream').Duplex;
var browserChannel = require('browserchannel').server;
var express = require('express');
var livedb = require('livedb');
var sharejs = require('share');
var shareCodeMirror = require('..');

var backend = livedb.client(livedb.memory());
var share = sharejs.server.createClient({backend: backend});

var app = express();
app.use(express.static(__dirname));
app.use(express.static(shareCodeMirror.scriptsDir));
app.use(express.static(__dirname + '/../node_modules/codemirror/lib'));
app.use(express.static(sharejs.scriptsDir));
app.use(browserChannel(function (client) {
  var stream = new Duplex({objectMode: true});
  stream._write = function (chunk, encoding, callback) {
    if (client.state !== 'closed') {
      client.send(chunk);
    }
    callback();
  };
  stream._read = function () {

livedb

Realtime database wrapper

MIT
Latest version published 9 years ago

Package Health Score

61 / 100
Full package analysis

Popular livedb functions