-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
50 lines (44 loc) · 1.42 KB
/
client.js
File metadata and controls
50 lines (44 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var sharedb = require('sharedb/lib/client');
var richText = require('rich-text');
var Quill = require('quill');
var path = require('path');
sharedb.types.register(richText.type);
var title = prompt("Enter room name");
// Open WebSocket connection to ShareDB server
var socket = new WebSocket('ws://' + window.location.host);
var connection = new sharedb.Connection(socket);
// For testing reconnection
window.disconnect = function() {
connection.close();
};
window.connect = function() {
var socket = new WebSocket('ws://' + window.location.host);
connection.bindToSocket(socket);
};
// Create local Doc instance mapped to 'examples' collection document with id 'richtext'
var doc = connection.get('final', title);
doc.subscribe(function(err) {
if (err) throw err;
var toolbarOptions = [{'font':[]},
{'size': ['small', false, 'large', 'huge']},
'bold', 'italic', {'script': 'sub'}, {'script': 'super'},
{ 'indent': '-1'}, { 'indent': '+1' },
{'background': []}, {'color': []}, {'align': []},
'link', 'image', 'video'
];
var quill = new Quill('#editor', {
modules: {
toolbar: toolbarOptions
},
theme: 'snow'
});
quill.setContents(doc.data);
quill.on('text-change', function(delta, oldDelta, source) {
if (source !== 'user') return;
doc.submitOp(delta, {source: quill});
});
doc.on('op', function(op, source) {
if (source === quill) return;
quill.updateContents(op);
});
});