@atlaskit/collab-provider 7.1.2 → 7.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/cjs/analytics/index.js +2 -2
- package/dist/cjs/channel.js +2 -2
- package/dist/cjs/provider/index.js +175 -154
- package/dist/cjs/socket-io-provider.js +4 -6
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/provider/index.js +94 -64
- package/dist/es2019/socket-io-provider.js +1 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/analytics/index.js +2 -2
- package/dist/esm/channel.js +2 -2
- package/dist/esm/provider/index.js +177 -154
- package/dist/esm/socket-io-provider.js +4 -5
- package/dist/esm/version.json +1 -1
- package/dist/types/analytics/index.d.ts +1 -1
- package/dist/types/channel.d.ts +1 -70
- package/dist/types/error-code-mapper.d.ts +1 -2
- package/dist/types/index.d.ts +1 -2
- package/dist/types/provider/catchup.d.ts +1 -16
- package/dist/types/provider/index.d.ts +13 -64
- package/dist/types/types.d.ts +127 -3
- package/package.json +9 -9
|
@@ -11,14 +11,15 @@ import _inherits from "@babel/runtime/helpers/inherits";
|
|
|
11
11
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
12
12
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
13
13
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
14
|
+
var _excluded = ["type"];
|
|
14
15
|
|
|
15
16
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
16
17
|
|
|
17
18
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
18
19
|
|
|
19
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
21
|
|
|
21
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
22
23
|
|
|
23
24
|
import { getVersion, sendableSteps } from 'prosemirror-collab';
|
|
24
25
|
import throttle from 'lodash/throttle';
|
|
@@ -42,6 +43,8 @@ export var CATCHUP_THROTTLE = 1 * 1000; // 1 second
|
|
|
42
43
|
|
|
43
44
|
var OUT_OF_SYNC_PERIOD = 3 * 1000; // 3 seconds
|
|
44
45
|
|
|
46
|
+
var noop = function noop() {};
|
|
47
|
+
|
|
45
48
|
export var MAX_STEP_REJECTED_ERROR = 15;
|
|
46
49
|
|
|
47
50
|
var commitStep = function commitStep(_ref) {
|
|
@@ -85,6 +88,39 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
85
88
|
|
|
86
89
|
_defineProperty(_assertThisInitialized(_this), "stepRejectCounter", 0);
|
|
87
90
|
|
|
91
|
+
_defineProperty(_assertThisInitialized(_this), "isChannelInitialized", false);
|
|
92
|
+
|
|
93
|
+
_defineProperty(_assertThisInitialized(_this), "initializeChannel", function () {
|
|
94
|
+
_this.channel.on('connected', function (_ref2) {
|
|
95
|
+
var sid = _ref2.sid,
|
|
96
|
+
initialized = _ref2.initialized;
|
|
97
|
+
_this.sessionId = sid;
|
|
98
|
+
|
|
99
|
+
_this.emit('connected', {
|
|
100
|
+
sid: sid
|
|
101
|
+
}); // If already initialized, `connected` means reconnected
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if (initialized && _this.disconnectedAt && // Offline longer than `OUT_OF_SYNC_PERIOD`
|
|
105
|
+
Date.now() - _this.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
|
|
106
|
+
_this.throttledCatchup();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_this.disconnectedAt = undefined;
|
|
110
|
+
}).on('init', function (_ref3) {
|
|
111
|
+
var doc = _ref3.doc,
|
|
112
|
+
version = _ref3.version,
|
|
113
|
+
metadata = _ref3.metadata;
|
|
114
|
+
|
|
115
|
+
// Initial document and version
|
|
116
|
+
_this.updateDocumentWithMetadata({
|
|
117
|
+
doc: doc,
|
|
118
|
+
version: version,
|
|
119
|
+
metadata: metadata
|
|
120
|
+
});
|
|
121
|
+
}).on('steps:added', _this.onStepsAdded.bind(_assertThisInitialized(_this))).on('participant:telepointer', _this.onParticipantTelepointer.bind(_assertThisInitialized(_this))).on('presence:joined', _this.onPresenceJoined.bind(_assertThisInitialized(_this))).on('presence', _this.onPresence.bind(_assertThisInitialized(_this))).on('participant:left', _this.onParticipantLeft.bind(_assertThisInitialized(_this))).on('participant:updated', _this.onParticipantUpdated.bind(_assertThisInitialized(_this))).on('metadata:changed', _this.onMetadataChanged.bind(_assertThisInitialized(_this))).on('disconnect', _this.onDisconnected.bind(_assertThisInitialized(_this))).on('error', _this.onErrorHandled.bind(_assertThisInitialized(_this))).connect();
|
|
122
|
+
});
|
|
123
|
+
|
|
88
124
|
_defineProperty(_assertThisInitialized(_this), "onStepsAdded", function (data) {
|
|
89
125
|
logger("Received steps", {
|
|
90
126
|
steps: data.steps,
|
|
@@ -112,8 +148,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
112
148
|
_this.throttledCatchup();
|
|
113
149
|
}
|
|
114
150
|
|
|
115
|
-
_this.updateParticipants([], data.steps.map(function (
|
|
116
|
-
var userId =
|
|
151
|
+
_this.updateParticipants([], data.steps.map(function (_ref4) {
|
|
152
|
+
var userId = _ref4.userId;
|
|
117
153
|
return userId;
|
|
118
154
|
}));
|
|
119
155
|
});
|
|
@@ -129,11 +165,11 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
129
165
|
_this.queue = _this.queue.filter(condition);
|
|
130
166
|
});
|
|
131
167
|
|
|
132
|
-
_defineProperty(_assertThisInitialized(_this), "updateDocumentWithMetadata", function (
|
|
133
|
-
var doc =
|
|
134
|
-
version =
|
|
135
|
-
metadata =
|
|
136
|
-
reserveCursor =
|
|
168
|
+
_defineProperty(_assertThisInitialized(_this), "updateDocumentWithMetadata", function (_ref5) {
|
|
169
|
+
var doc = _ref5.doc,
|
|
170
|
+
version = _ref5.version,
|
|
171
|
+
metadata = _ref5.metadata,
|
|
172
|
+
reserveCursor = _ref5.reserveCursor;
|
|
137
173
|
|
|
138
174
|
_this.emit('init', _objectSpread({
|
|
139
175
|
doc: doc,
|
|
@@ -263,15 +299,15 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
263
299
|
}, SEND_PRESENCE_INTERVAL);
|
|
264
300
|
});
|
|
265
301
|
|
|
266
|
-
_defineProperty(_assertThisInitialized(_this), "onPresenceJoined", function (
|
|
267
|
-
var sessionId =
|
|
302
|
+
_defineProperty(_assertThisInitialized(_this), "onPresenceJoined", function (_ref7) {
|
|
303
|
+
var sessionId = _ref7.sessionId;
|
|
268
304
|
logger('Participant joined with session: ', sessionId); // This expose existing users to the newly joined user
|
|
269
305
|
|
|
270
306
|
_this.sendPresence();
|
|
271
307
|
});
|
|
272
308
|
|
|
273
|
-
_defineProperty(_assertThisInitialized(_this), "onPresence", function (
|
|
274
|
-
var userId =
|
|
309
|
+
_defineProperty(_assertThisInitialized(_this), "onPresence", function (_ref8) {
|
|
310
|
+
var userId = _ref8.userId;
|
|
275
311
|
logger('onPresence userId: ', userId);
|
|
276
312
|
_this.userId = userId;
|
|
277
313
|
|
|
@@ -282,12 +318,14 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
282
318
|
|
|
283
319
|
_defineProperty(_assertThisInitialized(_this), "onMetadataChanged", function (metadata) {
|
|
284
320
|
if (metadata !== undefined && !isequal(_this.metadata, metadata)) {
|
|
321
|
+
_this.metadata = metadata;
|
|
322
|
+
|
|
285
323
|
_this.emit('metadata:changed', metadata);
|
|
286
324
|
}
|
|
287
325
|
});
|
|
288
326
|
|
|
289
|
-
_defineProperty(_assertThisInitialized(_this), "onParticipantLeft", function (
|
|
290
|
-
var sessionId =
|
|
327
|
+
_defineProperty(_assertThisInitialized(_this), "onParticipantLeft", function (_ref9) {
|
|
328
|
+
var sessionId = _ref9.sessionId;
|
|
291
329
|
logger("Participant left");
|
|
292
330
|
|
|
293
331
|
_this.participants.delete(sessionId);
|
|
@@ -299,11 +337,11 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
299
337
|
});
|
|
300
338
|
});
|
|
301
339
|
|
|
302
|
-
_defineProperty(_assertThisInitialized(_this), "onParticipantUpdated", function (
|
|
303
|
-
var sessionId =
|
|
304
|
-
timestamp =
|
|
305
|
-
userId =
|
|
306
|
-
clientId =
|
|
340
|
+
_defineProperty(_assertThisInitialized(_this), "onParticipantUpdated", function (_ref10) {
|
|
341
|
+
var sessionId = _ref10.sessionId,
|
|
342
|
+
timestamp = _ref10.timestamp,
|
|
343
|
+
userId = _ref10.userId,
|
|
344
|
+
clientId = _ref10.clientId;
|
|
307
345
|
|
|
308
346
|
_this.updateParticipant({
|
|
309
347
|
sessionId: sessionId,
|
|
@@ -313,12 +351,12 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
313
351
|
});
|
|
314
352
|
});
|
|
315
353
|
|
|
316
|
-
_defineProperty(_assertThisInitialized(_this), "onParticipantTelepointer", function (
|
|
317
|
-
var sessionId =
|
|
318
|
-
timestamp =
|
|
319
|
-
selection =
|
|
320
|
-
userId =
|
|
321
|
-
clientId =
|
|
354
|
+
_defineProperty(_assertThisInitialized(_this), "onParticipantTelepointer", function (_ref11) {
|
|
355
|
+
var sessionId = _ref11.sessionId,
|
|
356
|
+
timestamp = _ref11.timestamp,
|
|
357
|
+
selection = _ref11.selection,
|
|
358
|
+
userId = _ref11.userId,
|
|
359
|
+
clientId = _ref11.clientId;
|
|
322
360
|
|
|
323
361
|
if (sessionId === _this.sessionId) {
|
|
324
362
|
return;
|
|
@@ -347,14 +385,14 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
347
385
|
});
|
|
348
386
|
|
|
349
387
|
_defineProperty(_assertThisInitialized(_this), "updateParticipant", /*#__PURE__*/function () {
|
|
350
|
-
var
|
|
388
|
+
var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref12) {
|
|
351
389
|
var sessionId, timestamp, userId, clientId, getUser, _yield, _yield$name, name, _yield$email, email, _yield$avatar, avatar, isNewParticipant;
|
|
352
390
|
|
|
353
391
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
354
392
|
while (1) {
|
|
355
393
|
switch (_context2.prev = _context2.next) {
|
|
356
394
|
case 0:
|
|
357
|
-
sessionId =
|
|
395
|
+
sessionId = _ref12.sessionId, timestamp = _ref12.timestamp, userId = _ref12.userId, clientId = _ref12.clientId;
|
|
358
396
|
|
|
359
397
|
if (userId) {
|
|
360
398
|
_context2.next = 3;
|
|
@@ -407,7 +445,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
407
445
|
}));
|
|
408
446
|
|
|
409
447
|
return function (_x) {
|
|
410
|
-
return
|
|
448
|
+
return _ref13.apply(this, arguments);
|
|
411
449
|
};
|
|
412
450
|
}());
|
|
413
451
|
|
|
@@ -470,8 +508,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
470
508
|
}
|
|
471
509
|
});
|
|
472
510
|
|
|
473
|
-
_defineProperty(_assertThisInitialized(_this), "onDisconnected", function (
|
|
474
|
-
var reason =
|
|
511
|
+
_defineProperty(_assertThisInitialized(_this), "onDisconnected", function (_ref14) {
|
|
512
|
+
var reason = _ref14.reason;
|
|
475
513
|
_this.disconnectedAt = Date.now();
|
|
476
514
|
var left = Array.from(_this.participants.values());
|
|
477
515
|
|
|
@@ -489,8 +527,75 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
489
527
|
}
|
|
490
528
|
});
|
|
491
529
|
|
|
530
|
+
_defineProperty(_assertThisInitialized(_this), "getFinalAcknowledgedState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
531
|
+
var _this$getUnconfirmedS, _this$metadata$title;
|
|
532
|
+
|
|
533
|
+
var maxAttemptsToSync, count, unconfirmedSteps, _this$getUnconfirmedS2, _unconfirmedSteps, _state, state;
|
|
534
|
+
|
|
535
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
536
|
+
while (1) {
|
|
537
|
+
switch (_context3.prev = _context3.next) {
|
|
538
|
+
case 0:
|
|
539
|
+
maxAttemptsToSync = ACK_MAX_TRY;
|
|
540
|
+
count = 0;
|
|
541
|
+
unconfirmedSteps = (_this$getUnconfirmedS = _this.getUnconfirmedSteps()) === null || _this$getUnconfirmedS === void 0 ? void 0 : _this$getUnconfirmedS.steps;
|
|
542
|
+
|
|
543
|
+
case 3:
|
|
544
|
+
if (!(unconfirmedSteps && unconfirmedSteps.length)) {
|
|
545
|
+
_context3.next = 13;
|
|
546
|
+
break;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
_this.sendStepsFromCurrentState();
|
|
550
|
+
|
|
551
|
+
_context3.next = 7;
|
|
552
|
+
return sleep(500);
|
|
553
|
+
|
|
554
|
+
case 7:
|
|
555
|
+
unconfirmedSteps = (_this$getUnconfirmedS2 = _this.getUnconfirmedSteps()) === null || _this$getUnconfirmedS2 === void 0 ? void 0 : _this$getUnconfirmedS2.steps;
|
|
556
|
+
|
|
557
|
+
if (!(count++ >= maxAttemptsToSync)) {
|
|
558
|
+
_context3.next = 11;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (_this.onSyncUpError) {
|
|
563
|
+
_state = _this.getState();
|
|
564
|
+
|
|
565
|
+
_this.onSyncUpError({
|
|
566
|
+
lengthOfUnconfirmedSteps: (_unconfirmedSteps = unconfirmedSteps) === null || _unconfirmedSteps === void 0 ? void 0 : _unconfirmedSteps.length,
|
|
567
|
+
tries: count,
|
|
568
|
+
maxRetries: maxAttemptsToSync,
|
|
569
|
+
clientId: _this.clientId,
|
|
570
|
+
version: getVersion(_state)
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
throw new Error("Can't syncup with Collab Service");
|
|
575
|
+
|
|
576
|
+
case 11:
|
|
577
|
+
_context3.next = 3;
|
|
578
|
+
break;
|
|
579
|
+
|
|
580
|
+
case 13:
|
|
581
|
+
state = _this.getState();
|
|
582
|
+
return _context3.abrupt("return", {
|
|
583
|
+
content: state.doc.toJSON(),
|
|
584
|
+
title: (_this$metadata$title = _this.metadata.title) === null || _this$metadata$title === void 0 ? void 0 : _this$metadata$title.toString(),
|
|
585
|
+
stepVersion: getVersion(state)
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
case 15:
|
|
589
|
+
case "end":
|
|
590
|
+
return _context3.stop();
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}, _callee3);
|
|
594
|
+
})));
|
|
595
|
+
|
|
492
596
|
_this.config = config;
|
|
493
597
|
_this.channel = new Channel(config);
|
|
598
|
+
_this.isChannelInitialized = false;
|
|
494
599
|
|
|
495
600
|
if (config.analyticsClient) {
|
|
496
601
|
_this.analyticsClient = config.analyticsClient;
|
|
@@ -498,50 +603,35 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
498
603
|
|
|
499
604
|
return _this;
|
|
500
605
|
}
|
|
501
|
-
/**
|
|
502
|
-
* Called by collab plugin in editor when it's ready to
|
|
503
|
-
* initialize a collab session.
|
|
504
|
-
*/
|
|
505
|
-
|
|
506
606
|
|
|
507
607
|
_createClass(Provider, [{
|
|
508
608
|
key: "initialize",
|
|
509
|
-
value:
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
609
|
+
value:
|
|
610
|
+
/**
|
|
611
|
+
* Called by collab plugin in editor when it's ready to
|
|
612
|
+
* initialize a collab session.
|
|
613
|
+
*/
|
|
614
|
+
function initialize(getState) {
|
|
615
|
+
return this.setup({
|
|
616
|
+
getState: getState
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
}, {
|
|
620
|
+
key: "setup",
|
|
621
|
+
value: function setup(_ref16) {
|
|
622
|
+
var getState = _ref16.getState,
|
|
623
|
+
onSyncUpError = _ref16.onSyncUpError;
|
|
624
|
+
this.getState = getState;
|
|
625
|
+
this.onSyncUpError = onSyncUpError || noop;
|
|
626
|
+
this.clientId = getState().plugins.find(function (p) {
|
|
515
627
|
return p.key === 'collab$';
|
|
516
|
-
}).spec.config.clientID
|
|
517
|
-
this.channel.on('connected', function (_ref13) {
|
|
518
|
-
var sid = _ref13.sid,
|
|
519
|
-
initialized = _ref13.initialized;
|
|
520
|
-
_this2.sessionId = sid;
|
|
521
|
-
|
|
522
|
-
_this2.emit('connected', {
|
|
523
|
-
sid: sid
|
|
524
|
-
}); // If already initialized, `connected` means reconnected
|
|
628
|
+
}).spec.config.clientID;
|
|
525
629
|
|
|
630
|
+
if (!this.isChannelInitialized) {
|
|
631
|
+
this.initializeChannel();
|
|
632
|
+
this.isChannelInitialized = true;
|
|
633
|
+
}
|
|
526
634
|
|
|
527
|
-
if (initialized && _this2.disconnectedAt && // Offline longer than `OUT_OF_SYNC_PERIOD`
|
|
528
|
-
Date.now() - _this2.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
|
|
529
|
-
_this2.throttledCatchup();
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
_this2.disconnectedAt = undefined;
|
|
533
|
-
}).on('init', function (_ref14) {
|
|
534
|
-
var doc = _ref14.doc,
|
|
535
|
-
version = _ref14.version,
|
|
536
|
-
metadata = _ref14.metadata;
|
|
537
|
-
|
|
538
|
-
// Initial document and version
|
|
539
|
-
_this2.updateDocumentWithMetadata({
|
|
540
|
-
doc: doc,
|
|
541
|
-
version: version,
|
|
542
|
-
metadata: metadata
|
|
543
|
-
});
|
|
544
|
-
}).on('steps:added', this.onStepsAdded).on('participant:telepointer', this.onParticipantTelepointer).on('presence:joined', this.onPresenceJoined).on('presence', this.onPresence).on('participant:left', this.onParticipantLeft).on('participant:updated', this.onParticipantUpdated).on('metadata:changed', this.onMetadataChanged).on('disconnect', this.onDisconnected).on('error', this.onErrorHandled).connect();
|
|
545
635
|
return this;
|
|
546
636
|
}
|
|
547
637
|
/**
|
|
@@ -633,15 +723,15 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
633
723
|
}, {
|
|
634
724
|
key: "processSteps",
|
|
635
725
|
value: function processSteps(data) {
|
|
636
|
-
var
|
|
726
|
+
var _this2 = this;
|
|
637
727
|
|
|
638
728
|
var version = data.version,
|
|
639
729
|
steps = data.steps;
|
|
640
730
|
logger("Processing data. Version \"".concat(version, "\"."));
|
|
641
731
|
|
|
642
732
|
if (steps && steps.length) {
|
|
643
|
-
var clientIds = steps.map(function (
|
|
644
|
-
var clientId =
|
|
733
|
+
var clientIds = steps.map(function (_ref17) {
|
|
734
|
+
var clientId = _ref17.clientId;
|
|
645
735
|
return clientId;
|
|
646
736
|
});
|
|
647
737
|
this.emit('data', {
|
|
@@ -656,7 +746,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
656
746
|
|
|
657
747
|
if (clientIds.indexOf(this.clientId) === -1) {
|
|
658
748
|
setTimeout(function () {
|
|
659
|
-
return
|
|
749
|
+
return _this2.sendStepsFromCurrentState();
|
|
660
750
|
}, 100);
|
|
661
751
|
}
|
|
662
752
|
}
|
|
@@ -673,7 +763,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
673
763
|
}
|
|
674
764
|
|
|
675
765
|
var type = data.type,
|
|
676
|
-
rest = _objectWithoutProperties(data,
|
|
766
|
+
rest = _objectWithoutProperties(data, _excluded);
|
|
677
767
|
|
|
678
768
|
var userId = this.userId,
|
|
679
769
|
sessionId = this.sessionId,
|
|
@@ -694,30 +784,30 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
694
784
|
}, {
|
|
695
785
|
key: "emitTelepointersFromSteps",
|
|
696
786
|
value: function emitTelepointersFromSteps(steps) {
|
|
697
|
-
var
|
|
787
|
+
var _this3 = this;
|
|
698
788
|
|
|
699
789
|
steps.forEach(function (step) {
|
|
700
|
-
var _Array$from$filter = Array.from(
|
|
790
|
+
var _Array$from$filter = Array.from(_this3.participants.values()).filter(function (p) {
|
|
701
791
|
return p.clientId === step.clientId;
|
|
702
792
|
}),
|
|
703
793
|
_Array$from$filter2 = _slicedToArray(_Array$from$filter, 1),
|
|
704
794
|
participant = _Array$from$filter2[0];
|
|
705
795
|
|
|
706
796
|
if (participant) {
|
|
707
|
-
var
|
|
708
|
-
stepType =
|
|
709
|
-
to =
|
|
710
|
-
from =
|
|
711
|
-
|
|
712
|
-
slice =
|
|
797
|
+
var _ref18 = step,
|
|
798
|
+
stepType = _ref18.stepType,
|
|
799
|
+
to = _ref18.to,
|
|
800
|
+
from = _ref18.from,
|
|
801
|
+
_ref18$slice = _ref18.slice,
|
|
802
|
+
slice = _ref18$slice === void 0 ? {
|
|
713
803
|
content: []
|
|
714
|
-
} :
|
|
804
|
+
} : _ref18$slice;
|
|
715
805
|
|
|
716
806
|
var _slice$content = _slicedToArray(slice.content, 1),
|
|
717
807
|
node = _slice$content[0];
|
|
718
808
|
|
|
719
809
|
if (stepType === 'replace' && to === from && slice.content.length === 1 && node.type === 'text' && node.text.length === 1) {
|
|
720
|
-
|
|
810
|
+
_this3.emit('telepointer', {
|
|
721
811
|
sessionId: participant.sessionId,
|
|
722
812
|
selection: {
|
|
723
813
|
type: 'textSelection',
|
|
@@ -772,80 +862,13 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
772
862
|
this.channel.sendMetadata(metadata);
|
|
773
863
|
Object.assign(this.metadata, metadata);
|
|
774
864
|
}
|
|
775
|
-
/**
|
|
776
|
-
* Get latest state.
|
|
777
|
-
*
|
|
778
|
-
* NOTE: Should this actually convert to ADF instead?
|
|
779
|
-
*/
|
|
780
|
-
|
|
781
865
|
}, {
|
|
782
|
-
key: "
|
|
783
|
-
value:
|
|
784
|
-
var _getFinalAcknowledgedState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
785
|
-
var _this$getUnconfirmedS;
|
|
786
|
-
|
|
787
|
-
var state, count, unconfirmedSteps, _this$getUnconfirmedS2;
|
|
788
|
-
|
|
789
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
790
|
-
while (1) {
|
|
791
|
-
switch (_context3.prev = _context3.next) {
|
|
792
|
-
case 0:
|
|
793
|
-
state = this.getState();
|
|
794
|
-
count = 0;
|
|
795
|
-
unconfirmedSteps = this.getUnconfirmedSteps() && ((_this$getUnconfirmedS = this.getUnconfirmedSteps()) === null || _this$getUnconfirmedS === void 0 ? void 0 : _this$getUnconfirmedS.steps);
|
|
796
|
-
|
|
797
|
-
case 3:
|
|
798
|
-
if (!(unconfirmedSteps && unconfirmedSteps.length)) {
|
|
799
|
-
_context3.next = 12;
|
|
800
|
-
break;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
this.sendStepsFromCurrentState();
|
|
804
|
-
_context3.next = 7;
|
|
805
|
-
return sleep(500);
|
|
806
|
-
|
|
807
|
-
case 7:
|
|
808
|
-
unconfirmedSteps = this.getUnconfirmedSteps() && ((_this$getUnconfirmedS2 = this.getUnconfirmedSteps()) === null || _this$getUnconfirmedS2 === void 0 ? void 0 : _this$getUnconfirmedS2.steps);
|
|
809
|
-
|
|
810
|
-
if (!(count++ >= ACK_MAX_TRY)) {
|
|
811
|
-
_context3.next = 10;
|
|
812
|
-
break;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
throw new Error("Can't syncup with Collab Service");
|
|
816
|
-
|
|
817
|
-
case 10:
|
|
818
|
-
_context3.next = 3;
|
|
819
|
-
break;
|
|
820
|
-
|
|
821
|
-
case 12:
|
|
822
|
-
return _context3.abrupt("return", {
|
|
823
|
-
content: state.doc.toJSON(),
|
|
824
|
-
title: this.metadata.title,
|
|
825
|
-
stepVersion: getVersion(state)
|
|
826
|
-
});
|
|
827
|
-
|
|
828
|
-
case 13:
|
|
829
|
-
case "end":
|
|
830
|
-
return _context3.stop();
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
}, _callee3, this);
|
|
834
|
-
}));
|
|
835
|
-
|
|
836
|
-
function getFinalAcknowledgedState() {
|
|
837
|
-
return _getFinalAcknowledgedState.apply(this, arguments);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
return getFinalAcknowledgedState;
|
|
841
|
-
}()
|
|
866
|
+
key: "unsubscribeAll",
|
|
867
|
+
value:
|
|
842
868
|
/**
|
|
843
869
|
* Unsubscribe from all events emitted by this provider.
|
|
844
870
|
*/
|
|
845
|
-
|
|
846
|
-
}, {
|
|
847
|
-
key: "unsubscribeAll",
|
|
848
|
-
value: function unsubscribeAll() {
|
|
871
|
+
function unsubscribeAll() {
|
|
849
872
|
_get(_getPrototypeOf(Provider.prototype), "unsubscribeAll", this).call(this);
|
|
850
873
|
|
|
851
874
|
this.channel.disconnect();
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
4
|
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
6
|
|
|
7
7
|
import { Provider } from './provider';
|
|
8
8
|
import { io } from 'socket.io-client';
|
|
9
|
-
import urlParse from 'url-parse';
|
|
10
9
|
export function createSocketIOSocket(url, auth) {
|
|
11
|
-
var
|
|
12
|
-
pathname =
|
|
10
|
+
var _URL = new URL(url),
|
|
11
|
+
pathname = _URL.pathname;
|
|
13
12
|
|
|
14
13
|
return io(url, {
|
|
15
14
|
withCredentials: true,
|
package/dist/esm/version.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AnalyticsWebClient } from '@atlaskit/analytics-listeners';
|
|
2
2
|
import { GasPurePayload } from '@atlaskit/analytics-gas-types';
|
|
3
|
-
import { ErrorPayload } from '../
|
|
3
|
+
import { ErrorPayload } from '../types';
|
|
4
4
|
export declare const buildAnalyticsPayload: (subject: string, payload?: any) => GasPurePayload;
|
|
5
5
|
export declare const fireAnalyticsEvent: (analyticsClient?: AnalyticsWebClient | undefined, analyticsEvent?: GasPurePayload | undefined) => void;
|
|
6
6
|
export declare const triggerAnalyticsForStepsAddedSuccessfully: (analyticsClient?: AnalyticsWebClient | undefined) => void;
|
package/dist/types/channel.d.ts
CHANGED
|
@@ -1,74 +1,5 @@
|
|
|
1
1
|
import { Emitter } from './emitter';
|
|
2
|
-
import { Config, Socket } from './types';
|
|
3
|
-
export interface Metadata {
|
|
4
|
-
[key: string]: string | number | boolean;
|
|
5
|
-
}
|
|
6
|
-
export declare type InitPayload = {
|
|
7
|
-
doc: any;
|
|
8
|
-
version: number;
|
|
9
|
-
userId?: string;
|
|
10
|
-
metadata?: Metadata;
|
|
11
|
-
};
|
|
12
|
-
export declare type PresencePayload = {
|
|
13
|
-
sessionId: string;
|
|
14
|
-
userId: string;
|
|
15
|
-
clientId: string;
|
|
16
|
-
timestamp: number;
|
|
17
|
-
};
|
|
18
|
-
export declare type TelepointerPayload = PresencePayload & {
|
|
19
|
-
selection: {
|
|
20
|
-
type: 'textSelection' | 'nodeSelection';
|
|
21
|
-
anchor: number;
|
|
22
|
-
head: number;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export declare type StepJson = {
|
|
26
|
-
from?: number;
|
|
27
|
-
to?: number;
|
|
28
|
-
stepType?: string;
|
|
29
|
-
clientId: string;
|
|
30
|
-
userId: string;
|
|
31
|
-
};
|
|
32
|
-
export declare type StepsPayload = {
|
|
33
|
-
version: number;
|
|
34
|
-
steps: StepJson[];
|
|
35
|
-
};
|
|
36
|
-
export declare type ErrorPayload = {
|
|
37
|
-
message: string;
|
|
38
|
-
data?: {
|
|
39
|
-
status: number;
|
|
40
|
-
code?: string;
|
|
41
|
-
meta?: string;
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
export declare type ChannelEvent = {
|
|
45
|
-
connected: {
|
|
46
|
-
sid: string;
|
|
47
|
-
initialized: boolean;
|
|
48
|
-
};
|
|
49
|
-
init: InitPayload;
|
|
50
|
-
reconnected: null;
|
|
51
|
-
'presence:joined': PresencePayload;
|
|
52
|
-
presence: PresencePayload;
|
|
53
|
-
'participant:left': PresencePayload;
|
|
54
|
-
'participant:telepointer': TelepointerPayload;
|
|
55
|
-
'participant:updated': PresencePayload;
|
|
56
|
-
'steps:commit': StepsPayload & {
|
|
57
|
-
userId: string;
|
|
58
|
-
};
|
|
59
|
-
'steps:added': StepsPayload;
|
|
60
|
-
'metadata:changed': Metadata;
|
|
61
|
-
error: ErrorPayload;
|
|
62
|
-
disconnect: {
|
|
63
|
-
reason: string;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
export interface CatchupResponse {
|
|
67
|
-
doc?: string;
|
|
68
|
-
version?: number;
|
|
69
|
-
stepMaps?: any[];
|
|
70
|
-
metadata?: Metadata;
|
|
71
|
-
}
|
|
2
|
+
import type { Config, Socket, ChannelEvent, CatchupResponse, Metadata } from './types';
|
|
72
3
|
export declare class Channel extends Emitter<ChannelEvent> {
|
|
73
4
|
private connected;
|
|
74
5
|
private config;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
export { Provider } from './provider';
|
|
2
|
-
export type { CollabConnectedPayload, CollabDisconnectedPayload, CollabErrorPayload, CollabInitPayload, CollabDataPayload, CollabTelepointerPayload, CollabPresencePayload, CollabMetadataPayload, CollabLocalStepsPayload, CollabEvents, } from './
|
|
3
|
-
export type { Socket } from './types';
|
|
2
|
+
export type { CollabConnectedPayload, CollabDisconnectedPayload, CollabErrorPayload, CollabInitPayload, CollabDataPayload, CollabTelepointerPayload, CollabPresencePayload, CollabMetadataPayload, CollabLocalStepsPayload, CollabEvents, Socket, } from './types';
|
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CollabInitPayload } from '.';
|
|
1
|
+
import type { CatchupOptions } from '../types';
|
|
3
2
|
import { Mapping, Step } from 'prosemirror-transform';
|
|
4
|
-
import { Transaction } from 'prosemirror-state';
|
|
5
|
-
export interface CatchupOptions {
|
|
6
|
-
getCurrentPmVersion: () => number;
|
|
7
|
-
fetchCatchup: (fromVersion: number) => Promise<CatchupResponse>;
|
|
8
|
-
fitlerQueue: (condition: (stepsPayload: StepsPayload) => boolean) => void;
|
|
9
|
-
getUnconfirmedSteps: () => {
|
|
10
|
-
version: number;
|
|
11
|
-
steps: Step<any>[];
|
|
12
|
-
clientID: string | number;
|
|
13
|
-
origins: Transaction<any>[];
|
|
14
|
-
} | null | undefined;
|
|
15
|
-
updateDocumentWithMetadata: ({ doc, version, metadata, reserveCursor, }: CollabInitPayload) => void;
|
|
16
|
-
applyLocalsteps: (steps: Step[]) => void;
|
|
17
|
-
}
|
|
18
3
|
/**
|
|
19
4
|
* Rebase the steps based on the mapping pipeline.
|
|
20
5
|
* Some steps could be lost, if they are no longer
|