How to use the sharedb/lib/client.Connection 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 DefinitelyTyped / DefinitelyTyped / types / sharedb / sharedb-tests.ts View on Github external
function startClient(callback) {
    const socket = new WebSocket('ws://localhost:8080');
    const connection = new ShareDBClient.Connection(socket);
    const doc = connection.get('examples', 'counter');
    doc.subscribe(() => {
        doc.submitOp([{p: ['numClicks'], na: 1}]);
        callback();
    });
    // sharedb-mongo query object
    connection.createSubscribeQuery('examples', {numClicks: {$gte: 5}}, null, (err, results) => {
        console.log(err, results);
    });
    // SQL-ish query adapter that takes a string query condition
    connection.createSubscribeQuery('examples', 'numClicks >= 5', null, (err, results) => {
        console.log(err, results);
    });
}
github derbyjs / racer / lib / Model / connection.js View on Github external
Model.prototype.createConnection = function(bundle) {
  // Model::_createSocket should be defined by the socket plugin
  this.root.socket = this._createSocket(bundle);

  // The Share connection will bind to the socket by defining the onopen,
  // onmessage, etc. methods
  var model = this;
  this.root.connection = new Connection(this.root.socket);
  this.root.connection.on('state', function(state, reason) {
    model._setDiff(['$connection', 'state'], state);
    model._setDiff(['$connection', 'reason'], reason);
  });
  this._set(['$connection', 'state'], 'connected');

  this._finishCreateConnection();
};
github share / sharedb / examples / textarea / client.js View on Github external
var sharedb = require('sharedb/lib/client');
var StringBinding = require('sharedb-string-binding');

// Open WebSocket connection to ShareDB server
var ReconnectingWebSocket = require('reconnecting-websocket');
var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var connection = new sharedb.Connection(socket);

var element = document.querySelector('textarea');
var statusSpan = document.getElementById('status-span');
statusSpan.innerHTML = 'Not Connected';

element.style.backgroundColor = 'gray';
socket.onopen = function() {
  statusSpan.innerHTML = 'Connected';
  element.style.backgroundColor = 'white';
};

socket.onclose = function() {
  statusSpan.innerHTML = 'Closed';
  element.style.backgroundColor = 'gray';
};
github share / sharedb / examples / leaderboard / client / connection.js View on Github external
var ReconnectingWebSocket = require('reconnecting-websocket');
var sharedb = require('sharedb/lib/client');

// Expose a singleton WebSocket connection to ShareDB server
var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var connection = new sharedb.Connection(socket);
module.exports = connection;
github share / sharedb / examples / counter / client.js View on Github external
var ReconnectingWebSocket = require('reconnecting-websocket');
var sharedb = require('sharedb/lib/client');

// Open WebSocket connection to ShareDB server
var socket = new ReconnectingWebSocket('ws://' + window.location.host);
var connection = new sharedb.Connection(socket);

// Create local Doc instance mapped to 'examples' collection document with id 'counter'
var doc = connection.get('examples', 'counter');

// Get initial value of document and subscribe to changes
doc.subscribe(showNumbers);
// When document changes (by this client or any other, or the server),
// update the number on the page
doc.on('op', showNumbers);

function showNumbers() {
  document.querySelector('#num-clicks').textContent = doc.data.numClicks;
};

// When clicking on the '+1' button, change the number in the local
// document and sync the change to the server and other connected
github derbyjs / racer / test / Model / MockConnectionModel.js View on Github external
MockConnectionModel.prototype.createConnection = function() {
  var socketMock;
  socketMock = {
    send: function(message) {},
    close: function() {},
    onmessage: function() {},
    onclose: function() {},
    onerror: function() {},
    onopen: function() {},
    onconnecting: function() {}
  };
  this.root.connection = new ShareConnection(socketMock);
};
github EffectNode / EffectNode-GUI / src / enOS / Apps / NoteApp / Note.vue View on Github external
data () {
    let data = {}
    data.socket = new LLWebSocket({ uiAPI: this.uiAPI })
    data.connection = new sharedb.Connection(data.socket)
    return data
  },
  watch: {
github nicktogo / coeditor / lib / router.js View on Github external
this.socket.on('open', () => {
      let initData = {
        a         : 'meta',
        type      : 'init',
        sessionId : this.sessionId,
        clientId  : this.clientId
      };
      this.sendSocketMsg(JSON.stringify(initData));

      this.connection = new ShareDB.Connection(this.socket);

      this.coeditor.onSocketOpened();
      atom.notifications.addSuccess('Connected to: ' + this.socket.url);
    });
github pedrosanta / quill-sharedb-cursors / public / javascripts / main.js View on Github external
var ShareDB = require('sharedb/lib/client');
var Quill = require('quill');
var ReconnectingWebSocket = require('reconnectingwebsocket');
var cursors = require('./cursors' );
var utils = require('./utils');

import QuillCursors from 'quill-cursors/src/cursors';

ShareDB.types.register(require('rich-text').type);

Quill.register('modules/cursors', QuillCursors);

var shareDBSocket = new ReconnectingWebSocket(((location.protocol === 'https:') ? 'wss' : 'ws') + '://' + window.location.host + '/sharedb');

var shareDBConnection = new ShareDB.Connection(shareDBSocket);

var quill = window.quill = new Quill('#editor', {
  theme: 'snow',
  modules: {
    cursors: {
      autoRegisterListener: false
    },
    history: {
      userOnly: true
    }
  },
  readOnly: true
});

var doc = shareDBConnection.get('documents', 'foobar');