How to use the sharedb function in sharedb

To help you get started, we’ve selected a few sharedb 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 chili-epfl / collab-react-components / src / server / CollabServer.js View on Github external
const server = http.createServer(app);
  let db = null;
  if (CollabServer.options.db.type === 'mongo') {
    db = CollabServer.options.db.url
      ? ShareDBMongo(CollabServer.options.db.url)
      : {};
    console.log('CollabServer: Using MongoDB adapter');
  } else {
      'CollabServer: No Database specified, falling back to In Memory'

  // Create the ShareDB backend (that will need to be exported)
  CollabServer.backend = new ShareDB({ db });

  // Create the Websocket server
  new WebSocket.Server({ server }).on('connection', function(ws) {
    CollabServer.backend.listen(new WebsocketJSONStream(ws));
    console.log('New socket client on CollabServer instance');

  server.listen(CollabServer.options.port, function(err) {
    if (err) throw err;
      'CollabServer: Server listening on port ' + CollabServer.options.port