@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 CHANGED
@@ -1,5 +1,37 @@
1
1
  # @atlaskit/collab-provider
2
2
 
3
+ ## 7.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`5d5d6468ba9`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5d5d6468ba9) - Remove url-parse from collab-provider
8
+
9
+ Url-parse can be replaced with the built-in URL constructor
10
+
11
+ ## 7.1.5
12
+
13
+ ### Patch Changes
14
+
15
+ - [`f82fb6c48f7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f82fb6c48f7) - [ED-13911] Fix cycle dependencies
16
+ - [`97412280671`](https://bitbucket.org/atlassian/atlassian-frontend/commits/97412280671) - [ED-13939] Add analytics event to track "can't syncup with collab service" error
17
+ - [`88ada10af2c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/88ada10af2c) - [ED-14097] Moved getFinalAcknowledgedState control to editor and made the API public
18
+ - [`85648c038a4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/85648c038a4) - ED-13939 Rename newCollabSyncUpError analytics event to newCollabSyncUpErrorNoSteps
19
+ - [`e292f108d4b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e292f108d4b) - Ensure metadata is persisted when it is updated by another participant during an editing session
20
+ - Updated dependencies
21
+
22
+ ## 7.1.4
23
+
24
+ ### Patch Changes
25
+
26
+ - [`19d72473dfb`](https://bitbucket.org/atlassian/atlassian-frontend/commits/19d72473dfb) - ED-13912 refactor editor collab-provider and make sure that initializeChannel is only called once
27
+ - Updated dependencies
28
+
29
+ ## 7.1.3
30
+
31
+ ### Patch Changes
32
+
33
+ - [`c55c736ecea`](https://bitbucket.org/atlassian/atlassian-frontend/commits/c55c736ecea) - Patch VULN AFP-3486 AFP-3487 AFP-3488 AFP-3489
34
+
3
35
  ## 7.1.2
4
36
 
5
37
  ### Patch Changes
@@ -11,9 +11,9 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
11
11
 
12
12
  var _const = require("../helpers/const");
13
13
 
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
14
+ 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; }
15
15
 
16
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
16
+ 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) { (0, _defineProperty2.default)(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; }
17
17
 
18
18
  var buildAnalyticsPayload = function buildAnalyticsPayload(subject, payload) {
19
19
  return {
@@ -37,9 +37,9 @@ var _performance = require("./analytics/performance");
37
37
 
38
38
  var _analytics = require("./analytics");
39
39
 
40
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
40
+ 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; }
41
41
 
42
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
42
+ 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) { (0, _defineProperty2.default)(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; }
43
43
 
44
44
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
45
45
 
@@ -55,13 +55,15 @@ var _errorCodeMapper = require("../error-code-mapper");
55
55
 
56
56
  var _disconnectedReasonMapper = require("../disconnected-reason-mapper");
57
57
 
58
+ var _excluded = ["type"];
59
+
58
60
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
59
61
 
60
62
  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; } }
61
63
 
62
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
64
+ 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; }
63
65
 
64
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
66
+ 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) { (0, _defineProperty2.default)(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; }
65
67
 
66
68
  var logger = (0, _utils.createLogger)('Provider', 'black');
67
69
  var PARTICIPANT_UPDATE_INTERVAL = 300 * 1000; // 300 seconds
@@ -75,6 +77,8 @@ var CATCHUP_THROTTLE = 1 * 1000; // 1 second
75
77
  exports.CATCHUP_THROTTLE = CATCHUP_THROTTLE;
76
78
  var OUT_OF_SYNC_PERIOD = 3 * 1000; // 3 seconds
77
79
 
80
+ var noop = function noop() {};
81
+
78
82
  var MAX_STEP_REJECTED_ERROR = 15;
79
83
  exports.MAX_STEP_REJECTED_ERROR = MAX_STEP_REJECTED_ERROR;
80
84
 
@@ -115,6 +119,37 @@ var Provider = /*#__PURE__*/function (_Emitter) {
115
119
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "participants", new Map());
116
120
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "metadata", {});
117
121
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "stepRejectCounter", 0);
122
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isChannelInitialized", false);
123
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "initializeChannel", function () {
124
+ _this.channel.on('connected', function (_ref2) {
125
+ var sid = _ref2.sid,
126
+ initialized = _ref2.initialized;
127
+ _this.sessionId = sid;
128
+
129
+ _this.emit('connected', {
130
+ sid: sid
131
+ }); // If already initialized, `connected` means reconnected
132
+
133
+
134
+ if (initialized && _this.disconnectedAt && // Offline longer than `OUT_OF_SYNC_PERIOD`
135
+ Date.now() - _this.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
136
+ _this.throttledCatchup();
137
+ }
138
+
139
+ _this.disconnectedAt = undefined;
140
+ }).on('init', function (_ref3) {
141
+ var doc = _ref3.doc,
142
+ version = _ref3.version,
143
+ metadata = _ref3.metadata;
144
+
145
+ // Initial document and version
146
+ _this.updateDocumentWithMetadata({
147
+ doc: doc,
148
+ version: version,
149
+ metadata: metadata
150
+ });
151
+ }).on('steps:added', _this.onStepsAdded.bind((0, _assertThisInitialized2.default)(_this))).on('participant:telepointer', _this.onParticipantTelepointer.bind((0, _assertThisInitialized2.default)(_this))).on('presence:joined', _this.onPresenceJoined.bind((0, _assertThisInitialized2.default)(_this))).on('presence', _this.onPresence.bind((0, _assertThisInitialized2.default)(_this))).on('participant:left', _this.onParticipantLeft.bind((0, _assertThisInitialized2.default)(_this))).on('participant:updated', _this.onParticipantUpdated.bind((0, _assertThisInitialized2.default)(_this))).on('metadata:changed', _this.onMetadataChanged.bind((0, _assertThisInitialized2.default)(_this))).on('disconnect', _this.onDisconnected.bind((0, _assertThisInitialized2.default)(_this))).on('error', _this.onErrorHandled.bind((0, _assertThisInitialized2.default)(_this))).connect();
152
+ });
118
153
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onStepsAdded", function (data) {
119
154
  logger("Received steps", {
120
155
  steps: data.steps,
@@ -142,8 +177,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
142
177
  _this.throttledCatchup();
143
178
  }
144
179
 
145
- _this.updateParticipants([], data.steps.map(function (_ref2) {
146
- var userId = _ref2.userId;
180
+ _this.updateParticipants([], data.steps.map(function (_ref4) {
181
+ var userId = _ref4.userId;
147
182
  return userId;
148
183
  }));
149
184
  });
@@ -156,11 +191,11 @@ var Provider = /*#__PURE__*/function (_Emitter) {
156
191
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "fitlerQueue", function (condition) {
157
192
  _this.queue = _this.queue.filter(condition);
158
193
  });
159
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateDocumentWithMetadata", function (_ref3) {
160
- var doc = _ref3.doc,
161
- version = _ref3.version,
162
- metadata = _ref3.metadata,
163
- reserveCursor = _ref3.reserveCursor;
194
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateDocumentWithMetadata", function (_ref5) {
195
+ var doc = _ref5.doc,
196
+ version = _ref5.version,
197
+ metadata = _ref5.metadata,
198
+ reserveCursor = _ref5.reserveCursor;
164
199
 
165
200
  _this.emit('init', _objectSpread({
166
201
  doc: doc,
@@ -282,14 +317,14 @@ var Provider = /*#__PURE__*/function (_Emitter) {
282
317
  return _this.sendPresence();
283
318
  }, SEND_PRESENCE_INTERVAL);
284
319
  });
285
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onPresenceJoined", function (_ref5) {
286
- var sessionId = _ref5.sessionId;
320
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onPresenceJoined", function (_ref7) {
321
+ var sessionId = _ref7.sessionId;
287
322
  logger('Participant joined with session: ', sessionId); // This expose existing users to the newly joined user
288
323
 
289
324
  _this.sendPresence();
290
325
  });
291
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onPresence", function (_ref6) {
292
- var userId = _ref6.userId;
326
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onPresence", function (_ref8) {
327
+ var userId = _ref8.userId;
293
328
  logger('onPresence userId: ', userId);
294
329
  _this.userId = userId;
295
330
 
@@ -299,11 +334,13 @@ var Provider = /*#__PURE__*/function (_Emitter) {
299
334
  });
300
335
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMetadataChanged", function (metadata) {
301
336
  if (metadata !== undefined && !(0, _isEqual.default)(_this.metadata, metadata)) {
337
+ _this.metadata = metadata;
338
+
302
339
  _this.emit('metadata:changed', metadata);
303
340
  }
304
341
  });
305
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onParticipantLeft", function (_ref7) {
306
- var sessionId = _ref7.sessionId;
342
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onParticipantLeft", function (_ref9) {
343
+ var sessionId = _ref9.sessionId;
307
344
  logger("Participant left");
308
345
 
309
346
  _this.participants.delete(sessionId);
@@ -314,11 +351,11 @@ var Provider = /*#__PURE__*/function (_Emitter) {
314
351
  }]
315
352
  });
316
353
  });
317
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onParticipantUpdated", function (_ref8) {
318
- var sessionId = _ref8.sessionId,
319
- timestamp = _ref8.timestamp,
320
- userId = _ref8.userId,
321
- clientId = _ref8.clientId;
354
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onParticipantUpdated", function (_ref10) {
355
+ var sessionId = _ref10.sessionId,
356
+ timestamp = _ref10.timestamp,
357
+ userId = _ref10.userId,
358
+ clientId = _ref10.clientId;
322
359
 
323
360
  _this.updateParticipant({
324
361
  sessionId: sessionId,
@@ -327,12 +364,12 @@ var Provider = /*#__PURE__*/function (_Emitter) {
327
364
  clientId: clientId
328
365
  });
329
366
  });
330
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onParticipantTelepointer", function (_ref9) {
331
- var sessionId = _ref9.sessionId,
332
- timestamp = _ref9.timestamp,
333
- selection = _ref9.selection,
334
- userId = _ref9.userId,
335
- clientId = _ref9.clientId;
367
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onParticipantTelepointer", function (_ref11) {
368
+ var sessionId = _ref11.sessionId,
369
+ timestamp = _ref11.timestamp,
370
+ selection = _ref11.selection,
371
+ userId = _ref11.userId,
372
+ clientId = _ref11.clientId;
336
373
 
337
374
  if (sessionId === _this.sessionId) {
338
375
  return;
@@ -360,14 +397,14 @@ var Provider = /*#__PURE__*/function (_Emitter) {
360
397
  });
361
398
  });
362
399
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateParticipant", /*#__PURE__*/function () {
363
- var _ref11 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref10) {
400
+ var _ref13 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref12) {
364
401
  var sessionId, timestamp, userId, clientId, getUser, _yield, _yield$name, name, _yield$email, email, _yield$avatar, avatar, isNewParticipant;
365
402
 
366
403
  return _regenerator.default.wrap(function _callee2$(_context2) {
367
404
  while (1) {
368
405
  switch (_context2.prev = _context2.next) {
369
406
  case 0:
370
- sessionId = _ref10.sessionId, timestamp = _ref10.timestamp, userId = _ref10.userId, clientId = _ref10.clientId;
407
+ sessionId = _ref12.sessionId, timestamp = _ref12.timestamp, userId = _ref12.userId, clientId = _ref12.clientId;
371
408
 
372
409
  if (userId) {
373
410
  _context2.next = 3;
@@ -420,7 +457,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
420
457
  }));
421
458
 
422
459
  return function (_x) {
423
- return _ref11.apply(this, arguments);
460
+ return _ref13.apply(this, arguments);
424
461
  };
425
462
  }());
426
463
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "updateParticipants", function () {
@@ -480,8 +517,8 @@ var Provider = /*#__PURE__*/function (_Emitter) {
480
517
  return _disconnectedReasonMapper.DisconnectReason.UNKNOWN_DISCONNECT;
481
518
  }
482
519
  });
483
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onDisconnected", function (_ref12) {
484
- var reason = _ref12.reason;
520
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onDisconnected", function (_ref14) {
521
+ var reason = _ref14.reason;
485
522
  _this.disconnectedAt = Date.now();
486
523
  var left = Array.from(_this.participants.values());
487
524
 
@@ -498,8 +535,74 @@ var Provider = /*#__PURE__*/function (_Emitter) {
498
535
  });
499
536
  }
500
537
  });
538
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "getFinalAcknowledgedState", /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
539
+ var _this$getUnconfirmedS, _this$metadata$title;
540
+
541
+ var maxAttemptsToSync, count, unconfirmedSteps, _this$getUnconfirmedS2, _unconfirmedSteps, _state, state;
542
+
543
+ return _regenerator.default.wrap(function _callee3$(_context3) {
544
+ while (1) {
545
+ switch (_context3.prev = _context3.next) {
546
+ case 0:
547
+ maxAttemptsToSync = _const.ACK_MAX_TRY;
548
+ count = 0;
549
+ unconfirmedSteps = (_this$getUnconfirmedS = _this.getUnconfirmedSteps()) === null || _this$getUnconfirmedS === void 0 ? void 0 : _this$getUnconfirmedS.steps;
550
+
551
+ case 3:
552
+ if (!(unconfirmedSteps && unconfirmedSteps.length)) {
553
+ _context3.next = 13;
554
+ break;
555
+ }
556
+
557
+ _this.sendStepsFromCurrentState();
558
+
559
+ _context3.next = 7;
560
+ return (0, _utils.sleep)(500);
561
+
562
+ case 7:
563
+ unconfirmedSteps = (_this$getUnconfirmedS2 = _this.getUnconfirmedSteps()) === null || _this$getUnconfirmedS2 === void 0 ? void 0 : _this$getUnconfirmedS2.steps;
564
+
565
+ if (!(count++ >= maxAttemptsToSync)) {
566
+ _context3.next = 11;
567
+ break;
568
+ }
569
+
570
+ if (_this.onSyncUpError) {
571
+ _state = _this.getState();
572
+
573
+ _this.onSyncUpError({
574
+ lengthOfUnconfirmedSteps: (_unconfirmedSteps = unconfirmedSteps) === null || _unconfirmedSteps === void 0 ? void 0 : _unconfirmedSteps.length,
575
+ tries: count,
576
+ maxRetries: maxAttemptsToSync,
577
+ clientId: _this.clientId,
578
+ version: (0, _prosemirrorCollab.getVersion)(_state)
579
+ });
580
+ }
581
+
582
+ throw new Error("Can't syncup with Collab Service");
583
+
584
+ case 11:
585
+ _context3.next = 3;
586
+ break;
587
+
588
+ case 13:
589
+ state = _this.getState();
590
+ return _context3.abrupt("return", {
591
+ content: state.doc.toJSON(),
592
+ title: (_this$metadata$title = _this.metadata.title) === null || _this$metadata$title === void 0 ? void 0 : _this$metadata$title.toString(),
593
+ stepVersion: (0, _prosemirrorCollab.getVersion)(state)
594
+ });
595
+
596
+ case 15:
597
+ case "end":
598
+ return _context3.stop();
599
+ }
600
+ }
601
+ }, _callee3);
602
+ })));
501
603
  _this.config = config;
502
604
  _this.channel = new _channel.Channel(config);
605
+ _this.isChannelInitialized = false;
503
606
 
504
607
  if (config.analyticsClient) {
505
608
  _this.analyticsClient = config.analyticsClient;
@@ -507,50 +610,35 @@ var Provider = /*#__PURE__*/function (_Emitter) {
507
610
 
508
611
  return _this;
509
612
  }
510
- /**
511
- * Called by collab plugin in editor when it's ready to
512
- * initialize a collab session.
513
- */
514
-
515
613
 
516
614
  (0, _createClass2.default)(Provider, [{
517
615
  key: "initialize",
518
- value: function initialize(optionsOrGetState) {
519
- var _this2 = this;
520
-
521
- this.getState = typeof optionsOrGetState === 'function' ? optionsOrGetState : optionsOrGetState.getState;
522
- this.clientId = typeof optionsOrGetState === 'function' ? // Quick-hack to get clientID from native collab-plugin.
523
- this.getState().plugins.find(function (p) {
616
+ value:
617
+ /**
618
+ * Called by collab plugin in editor when it's ready to
619
+ * initialize a collab session.
620
+ */
621
+ function initialize(getState) {
622
+ return this.setup({
623
+ getState: getState
624
+ });
625
+ }
626
+ }, {
627
+ key: "setup",
628
+ value: function setup(_ref16) {
629
+ var getState = _ref16.getState,
630
+ onSyncUpError = _ref16.onSyncUpError;
631
+ this.getState = getState;
632
+ this.onSyncUpError = onSyncUpError || noop;
633
+ this.clientId = getState().plugins.find(function (p) {
524
634
  return p.key === 'collab$';
525
- }).spec.config.clientID : optionsOrGetState.clientId;
526
- this.channel.on('connected', function (_ref13) {
527
- var sid = _ref13.sid,
528
- initialized = _ref13.initialized;
529
- _this2.sessionId = sid;
530
-
531
- _this2.emit('connected', {
532
- sid: sid
533
- }); // If already initialized, `connected` means reconnected
534
-
535
-
536
- if (initialized && _this2.disconnectedAt && // Offline longer than `OUT_OF_SYNC_PERIOD`
537
- Date.now() - _this2.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
538
- _this2.throttledCatchup();
539
- }
635
+ }).spec.config.clientID;
540
636
 
541
- _this2.disconnectedAt = undefined;
542
- }).on('init', function (_ref14) {
543
- var doc = _ref14.doc,
544
- version = _ref14.version,
545
- metadata = _ref14.metadata;
637
+ if (!this.isChannelInitialized) {
638
+ this.initializeChannel();
639
+ this.isChannelInitialized = true;
640
+ }
546
641
 
547
- // Initial document and version
548
- _this2.updateDocumentWithMetadata({
549
- doc: doc,
550
- version: version,
551
- metadata: metadata
552
- });
553
- }).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();
554
642
  return this;
555
643
  }
556
644
  /**
@@ -642,15 +730,15 @@ var Provider = /*#__PURE__*/function (_Emitter) {
642
730
  }, {
643
731
  key: "processSteps",
644
732
  value: function processSteps(data) {
645
- var _this3 = this;
733
+ var _this2 = this;
646
734
 
647
735
  var version = data.version,
648
736
  steps = data.steps;
649
737
  logger("Processing data. Version \"".concat(version, "\"."));
650
738
 
651
739
  if (steps && steps.length) {
652
- var clientIds = steps.map(function (_ref15) {
653
- var clientId = _ref15.clientId;
740
+ var clientIds = steps.map(function (_ref17) {
741
+ var clientId = _ref17.clientId;
654
742
  return clientId;
655
743
  });
656
744
  this.emit('data', {
@@ -665,7 +753,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
665
753
 
666
754
  if (clientIds.indexOf(this.clientId) === -1) {
667
755
  setTimeout(function () {
668
- return _this3.sendStepsFromCurrentState();
756
+ return _this2.sendStepsFromCurrentState();
669
757
  }, 100);
670
758
  }
671
759
  }
@@ -682,7 +770,7 @@ var Provider = /*#__PURE__*/function (_Emitter) {
682
770
  }
683
771
 
684
772
  var type = data.type,
685
- rest = (0, _objectWithoutProperties2.default)(data, ["type"]);
773
+ rest = (0, _objectWithoutProperties2.default)(data, _excluded);
686
774
  var userId = this.userId,
687
775
  sessionId = this.sessionId,
688
776
  clientId = this.clientId;
@@ -702,30 +790,30 @@ var Provider = /*#__PURE__*/function (_Emitter) {
702
790
  }, {
703
791
  key: "emitTelepointersFromSteps",
704
792
  value: function emitTelepointersFromSteps(steps) {
705
- var _this4 = this;
793
+ var _this3 = this;
706
794
 
707
795
  steps.forEach(function (step) {
708
- var _Array$from$filter = Array.from(_this4.participants.values()).filter(function (p) {
796
+ var _Array$from$filter = Array.from(_this3.participants.values()).filter(function (p) {
709
797
  return p.clientId === step.clientId;
710
798
  }),
711
799
  _Array$from$filter2 = (0, _slicedToArray2.default)(_Array$from$filter, 1),
712
800
  participant = _Array$from$filter2[0];
713
801
 
714
802
  if (participant) {
715
- var _ref16 = step,
716
- stepType = _ref16.stepType,
717
- to = _ref16.to,
718
- from = _ref16.from,
719
- _ref16$slice = _ref16.slice,
720
- slice = _ref16$slice === void 0 ? {
803
+ var _ref18 = step,
804
+ stepType = _ref18.stepType,
805
+ to = _ref18.to,
806
+ from = _ref18.from,
807
+ _ref18$slice = _ref18.slice,
808
+ slice = _ref18$slice === void 0 ? {
721
809
  content: []
722
- } : _ref16$slice;
810
+ } : _ref18$slice;
723
811
 
724
812
  var _slice$content = (0, _slicedToArray2.default)(slice.content, 1),
725
813
  node = _slice$content[0];
726
814
 
727
815
  if (stepType === 'replace' && to === from && slice.content.length === 1 && node.type === 'text' && node.text.length === 1) {
728
- _this4.emit('telepointer', {
816
+ _this3.emit('telepointer', {
729
817
  sessionId: participant.sessionId,
730
818
  selection: {
731
819
  type: 'textSelection',
@@ -780,80 +868,13 @@ var Provider = /*#__PURE__*/function (_Emitter) {
780
868
  this.channel.sendMetadata(metadata);
781
869
  Object.assign(this.metadata, metadata);
782
870
  }
783
- /**
784
- * Get latest state.
785
- *
786
- * NOTE: Should this actually convert to ADF instead?
787
- */
788
-
789
871
  }, {
790
- key: "getFinalAcknowledgedState",
791
- value: function () {
792
- var _getFinalAcknowledgedState = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
793
- var _this$getUnconfirmedS;
794
-
795
- var state, count, unconfirmedSteps, _this$getUnconfirmedS2;
796
-
797
- return _regenerator.default.wrap(function _callee3$(_context3) {
798
- while (1) {
799
- switch (_context3.prev = _context3.next) {
800
- case 0:
801
- state = this.getState();
802
- count = 0;
803
- unconfirmedSteps = this.getUnconfirmedSteps() && ((_this$getUnconfirmedS = this.getUnconfirmedSteps()) === null || _this$getUnconfirmedS === void 0 ? void 0 : _this$getUnconfirmedS.steps);
804
-
805
- case 3:
806
- if (!(unconfirmedSteps && unconfirmedSteps.length)) {
807
- _context3.next = 12;
808
- break;
809
- }
810
-
811
- this.sendStepsFromCurrentState();
812
- _context3.next = 7;
813
- return (0, _utils.sleep)(500);
814
-
815
- case 7:
816
- unconfirmedSteps = this.getUnconfirmedSteps() && ((_this$getUnconfirmedS2 = this.getUnconfirmedSteps()) === null || _this$getUnconfirmedS2 === void 0 ? void 0 : _this$getUnconfirmedS2.steps);
817
-
818
- if (!(count++ >= _const.ACK_MAX_TRY)) {
819
- _context3.next = 10;
820
- break;
821
- }
822
-
823
- throw new Error("Can't syncup with Collab Service");
824
-
825
- case 10:
826
- _context3.next = 3;
827
- break;
828
-
829
- case 12:
830
- return _context3.abrupt("return", {
831
- content: state.doc.toJSON(),
832
- title: this.metadata.title,
833
- stepVersion: (0, _prosemirrorCollab.getVersion)(state)
834
- });
835
-
836
- case 13:
837
- case "end":
838
- return _context3.stop();
839
- }
840
- }
841
- }, _callee3, this);
842
- }));
843
-
844
- function getFinalAcknowledgedState() {
845
- return _getFinalAcknowledgedState.apply(this, arguments);
846
- }
847
-
848
- return getFinalAcknowledgedState;
849
- }()
872
+ key: "unsubscribeAll",
873
+ value:
850
874
  /**
851
875
  * Unsubscribe from all events emitted by this provider.
852
876
  */
853
-
854
- }, {
855
- key: "unsubscribeAll",
856
- value: function unsubscribeAll() {
877
+ function unsubscribeAll() {
857
878
  (0, _get2.default)((0, _getPrototypeOf2.default)(Provider.prototype), "unsubscribeAll", this).call(this);
858
879
  this.channel.disconnect();
859
880
  return this;
@@ -14,15 +14,13 @@ var _provider = require("./provider");
14
14
 
15
15
  var _socket = require("socket.io-client");
16
16
 
17
- var _urlParse2 = _interopRequireDefault(require("url-parse"));
17
+ 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; }
18
18
 
19
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
20
-
21
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+ 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) { (0, _defineProperty2.default)(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
20
 
23
21
  function createSocketIOSocket(url, auth) {
24
- var _urlParse = (0, _urlParse2.default)(url),
25
- pathname = _urlParse.pathname;
22
+ var _URL = new URL(url),
23
+ pathname = _URL.pathname;
26
24
 
27
25
  return (0, _socket.io)(url, {
28
26
  withCredentials: true,
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "7.1.2",
3
+ "version": "7.1.6",
4
4
  "sideEffects": false
5
5
  }