- commit
- a10f0508d6e7ea0039a5e83039e402548341de82
- parent
- af81ed7902a6e3a98db5a2db314951d8fa963c1f
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-05-06 05:12
use lists for messages to reduce overhead
Diffstat
| M | static/pad.js | 20 | ++++++++++---------- |
| M | static/via.js | 2 | +- |
2 files changed, 11 insertions, 11 deletions
diff --git a/static/pad.js b/static/pad.js
@@ -32,7 +32,7 @@ var backup = utils.throttled(function() {
32 32 }, 10000);
33 33
34 34 var sendChanges = utils.throttled(function() {
35 -1 via.send(room, {sender: id, type: 'changes', data: localChanges});
-1 35 via.send(room, [id, 'changes', localChanges]);
36 36 localChanges = [];
37 37 }, 500);
38 38
@@ -54,11 +54,11 @@ el.addEventListener('input', function() {
54 54 });
55 55
56 56 via.listen(room, function(msg) {
57 -1 if (msg.sender === id) {
-1 57 if (msg[0] === id) {
58 58 return;
59 -1 } else if (msg.type === 'open') {
-1 59 } else if (msg[1] === 'open') {
60 60 // request current document from peers
61 -1 via.send(room, {sender: id, type: 'request'});
-1 61 via.send(room, [id, 'request']);
62 62
63 63 // fall back to last saved document after timeout
64 64 setTimeout(function() {
@@ -72,12 +72,12 @@ via.listen(room, function(msg) {
72 72 });
73 73 }
74 74 }, 1000);
75 -1 } else if (msg.type === 'changes') {
76 -1 applyChanges(msg.data);
77 -1 } else if (msg.type === 'request') {
78 -1 via.send(room, {sender: id, type: 'text', data: el.value});
79 -1 } else if (msg.type === 'text' && !el.value) {
80 -1 setText(msg.data, 0, 0);
-1 75 } else if (msg[1] === 'changes') {
-1 76 applyChanges(msg[2]);
-1 77 } else if (msg[1] === 'request') {
-1 78 via.send(room, [id, 'text', el.value]);
-1 79 } else if (msg[1] === 'text' && !el.value) {
-1 80 setText(msg[2], 0, 0);
81 81 el.readOnly = false;
82 82 }
83 83 });
diff --git a/static/via.js b/static/via.js
@@ -16,7 +16,7 @@ export var send = function(key, data, beacon) {
16 16 export var listen = function(key, fn) {
17 17 var evtSource = new EventSource(baseUrl + 'msg/' + key);
18 18 evtSource.onmessage = msg => fn(JSON.parse(msg.data));
19 -1 evtSource.onopen = () => fn({type: 'open'});
-1 19 evtSource.onopen = () => fn([null, 'open']);
20 20 };
21 21
22 22 export var store = function(key, data, beacon) {