EzDevInfo.com

ShareJS

Collaborative editing in any app

How to get the current text in meteor-sharejs ace editor

Im trying to make a little markdown editor with a panel that shows the rendered markdown. My problem is dont seem to be able to get the current content, it always one step behind. Ive used

return ace.edit("editor").getValue();

Is there a way to bind to the object that the editor is using?


Source: (StackOverflow)

Node.js (with Express.js) not working with Share.js

I'm following the docs on the github of Share.js but can't seem to get it to work

https://github.com/share/ShareJS/wiki/Getting-started-%280.6.x%29

I built a base app with the Express generator. It put the main server file inside /bin/www which is not supposed to be modified (I tried it).

The problem is with the code below.

var connect = require('connect'),
    sharejs = require('share').server;

var server = connect(
      connect.logger(),
      connect.static(__dirname + '/public')
    );
var options = {db: {type: 'none'}}; // See docs for options. {type: 'redis'} to enable persistance.

// Attach the sharejs REST and Socket.io interfaces to the server
sharejs.attach(server, options);

server.listen(8000, function(){
    console.log('Server running at http://127.0.0.1:8000/');
});

It requires me to set up server.listen(...) in the app.js but it's already been done in the /bin/www file.

My app.js looks like the code below.

var express = require('express');
var engine = require('ejs-locals');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');



var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.engine('ejs', engine);
app.set('view engine', 'ejs');

// database setup
var dbConfig = require('./db.js');
var mongoose = require('mongoose');
// connect to DB
mongoose.connect(dbConfig.url, function (err) {
  if (err) {
    console.log(err);
  }
});


// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// Configuring Passport
var passport = require('passport');
var expressSession = require('express-session');
app.use(expressSession({
  secret: 'mySecretKey',
  resave: true,
  saveUninitialized: true
}));
app.use(passport.initialize());
app.use(passport.session());

 // Using the flash middleware provided by connect-flash to store messages in session
 // and displaying in templates
var flash = require('connect-flash');
app.use(flash());

// Initialize passport
var initPassport = require('./passport/init');
initPassport(passport);

// Configuring Routes
var routes = require('./routes/index')(passport);
var users = require('./routes/users');
var editor = require('./routes/editor')(passport);
app.use('/', routes);
app.use('/editor', editor);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  if (req.session.user) {
    app.locals.user = req.session.user
  }
  next(err);
});

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
      message: err.message,
      error: err
    });
  });
}

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
    message: err.message,
    error: {}
  });
});



module.exports = app;

Source: (StackOverflow)

Advertisements

Get count of documents without loading the whole collection in DerbyJS 0.6

How can I count the results of a query without loading the whole resultset into memory?

The easy way of counting documents returned by a query would be:

var q = model.query('mycollection', { date: today });
q.fetch(function() {
    var length = q.get().length;
});

But this would load the whole resultset into memory and "count" an array in javascript. When you have lots of data you don't want to do this. I think.

Counting the underlying mongodb collection is rather complicated since LiveDB (I think it is LiveDB) creates many mongodb documents for one derbyjs document.

The internets point to this google groups thread from 2013, but the solution described there (putting $count: true into the query options) doesn't seem to work in DerbyJS 0.6 and current mongodb.". query.extraRef is undefined.


Source: (StackOverflow)

Unable to install ShareJS with npm

Using VM (vagrant) Ubuntu 14.04.2 LTS. npm and nodeJS versions are up to date.

I'm trying to install shareJS via

sudo npm install share@"<0.7"

but this cause npm errors.

npm ERR! Linux 3.13.0-55-generic
npm ERR! argv "node" "/usr/bin/npm" "install" "share@<0.7"
npm ERR! node v0.12.7
npm ERR! npm  v2.14.1
npm ERR! path ../coffee-script/bin/coffee
npm ERR! code EPROTO
npm ERR! errno -71

npm ERR! EPROTO, symlink '../coffee-script/bin/coffee'
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>
npm ERR! Linux 3.13.0-55-generic
npm ERR! argv "node" "/usr/bin/npm" "install" "share@<0.7"
npm ERR! node v0.12.7
npm ERR! npm  v2.14.1
npm ERR! path npm-debug.log.8eb898407f81b59ca45e8e0a6a951820
npm ERR! code ETXTBSY
npm ERR! errno -26

Thought that problem with versions of node or npm, reinstalled them but that's did no effect. Also look similar to licence expired issue, but it was closed month ago.


Source: (StackOverflow)

I keep getting a console warning "Ignoring attempt to ingest data in state ready" from share.uncompressed.js file

I am using sharejs with primus for real time editing and any time i am about to use or start editing i get the warning "Ignoring attempt to ingest data in state ready" from the share.uncompressed.js script in my browser. Please does anyone know why this warning always appears. Because it seems to slow down the operational transformations that happen behind the scene thereby causing the real time editing to fail at some point. Please does anyone know anything about this.


Source: (StackOverflow)

Browser channel throws Error parsing forward channel Error: Invalid maps

I'm using browser channel to create a web socket in order to use sharejs and code mirror on my site. As the client tries to live-update the db on my server im continuously getting the error "Error parsing forward channel Error: Invalid maps". What is causing this?


Source: (StackOverflow)

Using ShareJS 0.7 with socket.io as its communication channel

I'm planning to develop a online-collaboration platform using ShareJS as an operational transformation (OT) implementation to synchronize the document on all clients.

Unfortunately the documentation of ShareJS is not completely updated to reflect the latest changes of version 0.7 (there were a lot of changes from version 0.6 to 0.7). Therefore I'm not entirely sure whether I can trust the repository's Readme or its wiki.

Right now I'm questioning one particular aspect: ShareJS requires me to provide a communication channel with a websocket-like API, which has to guarantee in-order message delivery. In the readme it is explicitly stated that socket.io does not provide in-order message delivery.

Is this still correct? Socket.io introduced a lot of changes in version 1.0 and I cannot find any usable information on socket.io's message delivery properties. Does anyone have experiences with using ShareJS and socket.io together?


Source: (StackOverflow)

Import "normal" MongoDB collections into DerbyJS 0.6

Same situation like this question, but with current DerbyJS (version 0.6):
Using imported docs from MongoDB in DerbyJS

I have a MongoDB collection with data that was not saved through my Derby app. I want to query against that and pull it into my Derby app.

Is this still possible?

The accepted answer there links to a dead link. The newest working link would be this: https://github.com/derbyjs/racer/blob/0.3/lib/descriptor/query/README.md

Which refers to the 0.3 branch for Racer (current master version is 0.6).


What I tried

  • Searching the internets
  • The naïve way:

    var query = model.query('projects-legacy', { public: true });
    model.fetch(query, function() {
      query.ref('_page.projects');
    })
    

    (doesn't work)


Source: (StackOverflow)