ShareJS Wrapper
This is a wrapper around the somewhat confusing
ShareJS API, and it also tries
to simplify handling disconnected WebSocket clients.
Documentation
The full documentation can be found
here.
Usage
The ShareJS Wrapper object is an event emitter. Create a wrapper, and the
wrapper should take care of setting itself up and emitting events at the proper
times.
var ShareJSWrapper = require('sharejs-wrapper');
var share = new ShareJSWrapper({
accessToken: user.apiAccessToken,
canvasID: canvasID,
realtimeURL: 'wss://api.usecanvas.com/realtime',
orgID: orgID
});
share.connect(function onConnect() {
console.log(share.content);
share.insert(0, 'insert some text');
share.remove(0, 'remove some text'.length);
share.on('insert', function onInsert(op) {
});
share.on('remove', function onRemove(op) {
});
});
share.on('disconnect', function onDisconnect(err) {
console.log(err.message);
});
share.disconnect();
Example
An example can be found in
test/server/public/main.js
.