JSPM

@usecanvas/sharejs-wrapper

1.0.8
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q25261F

A wrapper around ShareJS for easier iOS development

Package Exports

  • @usecanvas/sharejs-wrapper

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@usecanvas/sharejs-wrapper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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
});

// Tell the client to connect to the ShareJS server.
share.connect(function onConnect() {
  // Get the current content of the document.
  console.log(share.content);

  // Send insert/remove operations to the server.
  share.insert(0, 'insert some text');
  share.remove(0, 'remove some text'.length);

  // Handle an `insert` event from the server.
  share.on('insert', function onInsert(op) {
    // Handle an insert
  });

  // Handle a `remove` event from the server.
  share.on('remove', function onRemove(op) {
    // Handle a remove
  });
});

/*
 * Handle an unexpected disconnect event from the server. This happens when the
 * client disconnects without having `.disconnect()` called, and several
 * reconnection attempts fail.
 */
share.on('disconnect', function onDisconnect(err) {
  console.log(err.message);
});

// Manually disconnect the client.
share.disconnect();

Example

An example can be found in test/server/public/main.js.