Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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({
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 () {