@atlaskit/collab-provider 8.4.0 → 8.6.0

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/dist/cjs/analytics/analytics-helper.js +135 -0
  3. package/dist/cjs/analytics/performance.js +6 -5
  4. package/dist/cjs/channel.js +242 -223
  5. package/dist/cjs/document/catchup.js +142 -0
  6. package/dist/cjs/document/document-service.js +587 -0
  7. package/dist/cjs/document/step-queue-state.js +56 -0
  8. package/dist/cjs/errors/error-code-mapper.js +86 -67
  9. package/dist/cjs/errors/error-types.js +329 -21
  10. package/dist/cjs/helpers/utils.js +1 -12
  11. package/dist/cjs/index.js +8 -1
  12. package/dist/cjs/metadata/metadata-service.js +82 -0
  13. package/dist/cjs/participants/participants-helper.js +52 -0
  14. package/dist/cjs/participants/participants-service.js +259 -0
  15. package/dist/cjs/participants/participants-state.js +56 -0
  16. package/dist/cjs/{provider/telepointers.js → participants/telepointers-helper.js} +6 -6
  17. package/dist/cjs/provider/commit-step.js +14 -6
  18. package/dist/cjs/provider/index.js +291 -780
  19. package/dist/cjs/types.js +6 -1
  20. package/dist/cjs/version-wrapper.js +1 -1
  21. package/dist/cjs/version.json +1 -1
  22. package/dist/es2019/analytics/{index.js → analytics-helper.js} +15 -4
  23. package/dist/es2019/analytics/performance.js +5 -6
  24. package/dist/es2019/channel.js +140 -113
  25. package/dist/es2019/{provider → document}/catchup.js +6 -4
  26. package/dist/es2019/document/document-service.js +472 -0
  27. package/dist/es2019/document/step-queue-state.js +35 -0
  28. package/dist/es2019/errors/error-code-mapper.js +87 -63
  29. package/dist/es2019/errors/error-types.js +221 -5
  30. package/dist/es2019/helpers/utils.js +0 -10
  31. package/dist/es2019/index.js +2 -1
  32. package/dist/es2019/metadata/metadata-service.js +61 -0
  33. package/dist/es2019/participants/participants-helper.js +25 -0
  34. package/dist/es2019/participants/participants-service.js +207 -0
  35. package/dist/es2019/participants/participants-state.js +30 -0
  36. package/dist/es2019/{provider/telepointers.js → participants/telepointers-helper.js} +2 -2
  37. package/dist/es2019/provider/commit-step.js +12 -5
  38. package/dist/es2019/provider/index.js +240 -640
  39. package/dist/es2019/types.js +8 -1
  40. package/dist/es2019/version-wrapper.js +1 -1
  41. package/dist/es2019/version.json +1 -1
  42. package/dist/esm/analytics/analytics-helper.js +128 -0
  43. package/dist/esm/analytics/performance.js +5 -6
  44. package/dist/esm/channel.js +243 -224
  45. package/dist/esm/document/catchup.js +133 -0
  46. package/dist/esm/document/document-service.js +579 -0
  47. package/dist/esm/document/step-queue-state.js +48 -0
  48. package/dist/esm/errors/error-code-mapper.js +87 -64
  49. package/dist/esm/errors/error-types.js +321 -18
  50. package/dist/esm/helpers/utils.js +0 -10
  51. package/dist/esm/index.js +2 -1
  52. package/dist/esm/metadata/metadata-service.js +74 -0
  53. package/dist/esm/participants/participants-helper.js +44 -0
  54. package/dist/esm/participants/participants-service.js +251 -0
  55. package/dist/esm/participants/participants-state.js +48 -0
  56. package/dist/esm/{provider/telepointers.js → participants/telepointers-helper.js} +4 -4
  57. package/dist/esm/provider/commit-step.js +12 -5
  58. package/dist/esm/provider/index.js +291 -779
  59. package/dist/esm/types.js +8 -1
  60. package/dist/esm/version-wrapper.js +1 -1
  61. package/dist/esm/version.json +1 -1
  62. package/dist/types/analytics/{index.d.ts → analytics-helper.d.ts} +3 -1
  63. package/dist/types/analytics/performance.d.ts +3 -1
  64. package/dist/types/analytics/ufo.d.ts +1 -1
  65. package/dist/types/channel.d.ts +13 -6
  66. package/dist/types/document/document-service.d.ts +86 -0
  67. package/dist/types/document/step-queue-state.d.ts +16 -0
  68. package/dist/types/errors/error-code-mapper.d.ts +2 -36
  69. package/dist/types/errors/error-types.d.ts +439 -4
  70. package/dist/types/helpers/const.d.ts +2 -2
  71. package/dist/types/helpers/utils.d.ts +0 -6
  72. package/dist/types/index.d.ts +3 -1
  73. package/dist/types/metadata/metadata-service.d.ts +25 -0
  74. package/dist/types/participants/participants-helper.d.ts +15 -0
  75. package/dist/types/participants/participants-service.d.ts +74 -0
  76. package/dist/types/participants/participants-state.d.ts +13 -0
  77. package/dist/types/participants/telepointers-helper.d.ts +4 -0
  78. package/dist/types/provider/commit-step.d.ts +17 -6
  79. package/dist/types/provider/index.d.ts +81 -78
  80. package/dist/types/types.d.ts +56 -31
  81. package/package.json +6 -6
  82. package/report.api.md +187 -21
  83. package/dist/cjs/analytics/index.js +0 -95
  84. package/dist/cjs/provider/catchup.js +0 -139
  85. package/dist/esm/analytics/index.js +0 -88
  86. package/dist/esm/provider/catchup.js +0 -130
  87. package/dist/types/provider/telepointers.d.ts +0 -5
  88. /package/dist/types/{provider → document}/catchup.d.ts +0 -0
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.MetadataService = void 0;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
12
+ var MetadataService = /*#__PURE__*/function () {
13
+ function MetadataService(providerEmitCallback, broadcastMetadata) {
14
+ var _this = this;
15
+ (0, _classCallCheck2.default)(this, MetadataService);
16
+ (0, _defineProperty2.default)(this, "metadata", {});
17
+ (0, _defineProperty2.default)(this, "getMetaData", function () {
18
+ return _this.metadata;
19
+ });
20
+ (0, _defineProperty2.default)(this, "getTitle", function () {
21
+ var _this$metadata$title;
22
+ return (_this$metadata$title = _this.metadata.title) === null || _this$metadata$title === void 0 ? void 0 : _this$metadata$title.toString();
23
+ });
24
+ (0, _defineProperty2.default)(this, "onMetadataChanged", function (metadata) {
25
+ if (metadata !== undefined && !(0, _isEqual.default)(_this.metadata, metadata) && Object.keys(metadata).length > 0) {
26
+ _this.metadata = metadata;
27
+ _this.providerEmitCallback('metadata:changed', metadata);
28
+ }
29
+ });
30
+ (0, _defineProperty2.default)(this, "updateMetadata", function (metadata) {
31
+ if (metadata && Object.keys(metadata).length > 0) {
32
+ _this.metadata = metadata;
33
+ _this.providerEmitCallback('metadata:changed', metadata);
34
+ }
35
+ });
36
+ this.providerEmitCallback = providerEmitCallback;
37
+ this.broadcastMetadata = broadcastMetadata;
38
+ }
39
+
40
+ /**
41
+ * Called when a metadata is changed externally from other clients/backend.
42
+ */
43
+ (0, _createClass2.default)(MetadataService, [{
44
+ key: "setTitle",
45
+ value: function setTitle(title, broadcast) {
46
+ if (broadcast) {
47
+ this.broadcastMetadata({
48
+ title: title
49
+ });
50
+ }
51
+ this.metadata.title = title;
52
+ }
53
+ }, {
54
+ key: "setEditorWidth",
55
+ value: function setEditorWidth(editorWidth, broadcast) {
56
+ if (broadcast) {
57
+ this.broadcastMetadata({
58
+ editorWidth: editorWidth
59
+ });
60
+ }
61
+ this.metadata.editorWidth = editorWidth;
62
+ }
63
+
64
+ /**
65
+ * Updates the local metadata and broadcasts the metadata to other clients/backend.
66
+ * @param metadata
67
+ */
68
+ }, {
69
+ key: "setMetadata",
70
+ value: function setMetadata(metadata) {
71
+ this.broadcastMetadata(metadata);
72
+ this.metadata = metadata;
73
+ }
74
+
75
+ /**
76
+ * Emits a change in document's metadata
77
+ * @param metadata
78
+ */
79
+ }]);
80
+ return MetadataService;
81
+ }();
82
+ exports.MetadataService = MetadataService;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createParticipantFromPayload = exports.PARTICIPANT_UPDATE_INTERVAL = void 0;
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
11
+ var PARTICIPANT_UPDATE_INTERVAL = 300 * 1000; // 300 seconds
12
+ exports.PARTICIPANT_UPDATE_INTERVAL = PARTICIPANT_UPDATE_INTERVAL;
13
+ var createParticipantFromPayload = /*#__PURE__*/function () {
14
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(payload, getUser) {
15
+ var _user, _user2, _user3;
16
+ var sessionId, timestamp, clientId, userId, user, participant;
17
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
18
+ while (1) {
19
+ switch (_context.prev = _context.next) {
20
+ case 0:
21
+ sessionId = payload.sessionId, timestamp = payload.timestamp, clientId = payload.clientId, userId = payload.userId;
22
+ if (!getUser) {
23
+ _context.next = 5;
24
+ break;
25
+ }
26
+ _context.next = 4;
27
+ return getUser(userId);
28
+ case 4:
29
+ user = _context.sent;
30
+ case 5:
31
+ participant = {
32
+ name: ((_user = user) === null || _user === void 0 ? void 0 : _user.name) || '',
33
+ email: ((_user2 = user) === null || _user2 === void 0 ? void 0 : _user2.email) || '',
34
+ avatar: ((_user3 = user) === null || _user3 === void 0 ? void 0 : _user3.avatar) || '',
35
+ sessionId: sessionId,
36
+ lastActive: timestamp,
37
+ userId: userId,
38
+ clientId: clientId
39
+ };
40
+ return _context.abrupt("return", participant);
41
+ case 7:
42
+ case "end":
43
+ return _context.stop();
44
+ }
45
+ }
46
+ }, _callee);
47
+ }));
48
+ return function createParticipantFromPayload(_x, _x2) {
49
+ return _ref.apply(this, arguments);
50
+ };
51
+ }();
52
+ exports.createParticipantFromPayload = createParticipantFromPayload;
@@ -0,0 +1,259 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.ParticipantsService = void 0;
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+ var _disconnectedReasonMapper = require("../disconnected-reason-mapper");
14
+ var _const = require("../helpers/const");
15
+ var _telepointersHelper = require("./telepointers-helper");
16
+ var _participantsHelper = require("./participants-helper");
17
+ var _participantsState = require("./participants-state");
18
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
19
+ 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
+ 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; }
21
+ var ParticipantsService = /*#__PURE__*/function () {
22
+ function ParticipantsService(analyticsHelper) {
23
+ var _this = this;
24
+ var participantsState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _participantsState.ParticipantsState();
25
+ (0, _classCallCheck2.default)(this, ParticipantsService);
26
+ (0, _defineProperty2.default)(this, "updateParticipant", /*#__PURE__*/function () {
27
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(payload, getUser, emit) {
28
+ var userId, participant, _this$analyticsHelper, isNewParticipant;
29
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
30
+ while (1) {
31
+ switch (_context.prev = _context.next) {
32
+ case 0:
33
+ userId = payload.userId; // If userId does not exist, does nothing here to prevent duplication.
34
+ if (userId) {
35
+ _context.next = 3;
36
+ break;
37
+ }
38
+ return _context.abrupt("return");
39
+ case 3:
40
+ _context.prev = 3;
41
+ _context.next = 6;
42
+ return (0, _participantsHelper.createParticipantFromPayload)( // userId _must_ be defined, this lets the compiler know
43
+ _objectSpread(_objectSpread({}, payload), {}, {
44
+ userId: userId
45
+ }), getUser);
46
+ case 6:
47
+ participant = _context.sent;
48
+ _context.next = 12;
49
+ break;
50
+ case 9:
51
+ _context.prev = 9;
52
+ _context.t0 = _context["catch"](3);
53
+ // We don't want to throw errors for Presence features as they tend to self-restore
54
+ (_this$analyticsHelper = _this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(_context.t0, 'enriching participant');
55
+ case 12:
56
+ if (participant) {
57
+ _context.next = 14;
58
+ break;
59
+ }
60
+ return _context.abrupt("return");
61
+ case 14:
62
+ isNewParticipant = _this.participantsState.doesntHave(participant.sessionId);
63
+ _this.participantsState.setBySessionId(participant.sessionId, participant);
64
+ if (isNewParticipant) {
65
+ _context.next = 18;
66
+ break;
67
+ }
68
+ return _context.abrupt("return");
69
+ case 18:
70
+ _this.emitPresence({
71
+ joined: [participant]
72
+ }, emit, 'handling participant updated event');
73
+ case 19:
74
+ case "end":
75
+ return _context.stop();
76
+ }
77
+ }
78
+ }, _callee, null, [[3, 9]]);
79
+ }));
80
+ return function (_x, _x2, _x3) {
81
+ return _ref.apply(this, arguments);
82
+ };
83
+ }());
84
+ (0, _defineProperty2.default)(this, "participantLeft", function (_ref2, emit) {
85
+ var sessionId = _ref2.sessionId;
86
+ _this.participantsState.removeBySessionId(sessionId);
87
+ _this.emitPresence({
88
+ left: [{
89
+ sessionId: sessionId
90
+ }]
91
+ }, emit, 'participant leaving');
92
+ });
93
+ (0, _defineProperty2.default)(this, "disconnect", function (reason, sessionId, emit) {
94
+ var left = _this.participantsState.getParticipants();
95
+ _this.participantsState.clear();
96
+ try {
97
+ emit('disconnected', {
98
+ reason: (0, _disconnectedReasonMapper.disconnectedReasonMapper)(reason),
99
+ sid: sessionId
100
+ });
101
+ } catch (error) {
102
+ var _this$analyticsHelper2;
103
+ // We don't want to throw errors for Presence features as they tend to self-restore
104
+ (_this$analyticsHelper2 = _this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendErrorEvent(error, 'emitting disconnected data');
105
+ }
106
+ if (left.length) {
107
+ _this.emitPresence({
108
+ left: left
109
+ }, emit, 'emitting presence update on disconnect');
110
+ }
111
+ });
112
+ (0, _defineProperty2.default)(this, "updateLastActive", function () {
113
+ var userIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
114
+ return _this.participantsState.updateLastActive(Date.now(), userIds);
115
+ });
116
+ (0, _defineProperty2.default)(this, "participantTelepointer", function (payload, thisSessionId, getUser, emit) {
117
+ var sessionId = payload.sessionId,
118
+ selection = payload.selection,
119
+ timestamp = payload.timestamp;
120
+ var participant = _this.participantsState.getBySessionId(sessionId);
121
+ if (sessionId === thisSessionId ||
122
+ // Ignore old telepointer events
123
+ participant && participant.lastActive > timestamp) {
124
+ return;
125
+ }
126
+ var userId = payload.userId ? [payload.userId] : undefined;
127
+
128
+ // Set last active
129
+ _this.updateLastActive(userId);
130
+ _this.emitTelepointer({
131
+ type: 'telepointer',
132
+ selection: selection,
133
+ sessionId: sessionId
134
+ }, emit, 'handling participant telepointer event');
135
+ });
136
+ (0, _defineProperty2.default)(this, "removeInactiveParticipants", function (sessionId, emit) {
137
+ clearTimeout(_this.participantUpdateTimeout);
138
+ try {
139
+ _this.filterInactive(sessionId, emit);
140
+ } catch (err) {
141
+ var _this$analyticsHelper3;
142
+ (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(err, 'Failed filtering inactive participants');
143
+ }
144
+ _this.participantUpdateTimeout = window.setTimeout(function () {
145
+ return _this.removeInactiveParticipants(sessionId, emit);
146
+ }, _participantsHelper.PARTICIPANT_UPDATE_INTERVAL);
147
+ });
148
+ (0, _defineProperty2.default)(this, "filterInactive", function (sessionId, emit) {
149
+ var now = Date.now();
150
+ var left = _this.participantsState.getParticipants().filter(function (p) {
151
+ return p.sessionId !== sessionId && now - p.lastActive > _participantsHelper.PARTICIPANT_UPDATE_INTERVAL;
152
+ });
153
+ left.forEach(function (p) {
154
+ return _this.participantsState.removeBySessionId(p.sessionId);
155
+ });
156
+ left.length && _this.emitPresence({
157
+ left: left
158
+ }, emit, 'filtering inactive participants');
159
+ });
160
+ (0, _defineProperty2.default)(this, "emitPresence", function (data, emit, errorMessage) {
161
+ try {
162
+ var _this$analyticsHelper4;
163
+ emit('presence', data);
164
+ (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendActionEvent(_const.EVENT_ACTION.UPDATE_PARTICIPANTS, _const.EVENT_STATUS.SUCCESS, {
165
+ participants: _this.participantsState.size()
166
+ });
167
+ } catch (error) {
168
+ var _this$analyticsHelper5;
169
+ // We don't want to throw errors for Presence features as they tend to self-restore
170
+ (_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(error, "Error while ".concat(errorMessage));
171
+ }
172
+ });
173
+ (0, _defineProperty2.default)(this, "emitTelepointer", function (data, emit, errorMessage) {
174
+ try {
175
+ emit('telepointer', data);
176
+ } catch (error) {
177
+ var _this$analyticsHelper6;
178
+ // We don't want to throw errors for Presence features as they tend to self-restore
179
+ (_this$analyticsHelper6 = _this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(error, "Error while ".concat(errorMessage));
180
+ }
181
+ });
182
+ (0, _defineProperty2.default)(this, "clearTimers", function () {
183
+ clearTimeout(_this.participantUpdateTimeout);
184
+ });
185
+ this.participantsState = participantsState;
186
+ this.analyticsHelper = analyticsHelper;
187
+ }
188
+
189
+ /**
190
+ * Carries out 3 things: 1) enriches the participant with user data, 2) updates the participantsState, 3) emits the presence event
191
+ * @param payload Payload from incoming socket event
192
+ * @param getUser Function to get user data from confluence
193
+ * @param emit Function to execute emit from provider socket
194
+ * @returns Awaitable Promise, due to getUser
195
+ */
196
+
197
+ /**
198
+ * Called when a participant leaves the session.
199
+ *
200
+ * We emit the `presence` event to update the active avatars in the editor.
201
+ */
202
+
203
+ /**
204
+ * Updates when users were last active
205
+ * @param userIds Users in most recent steps
206
+ */
207
+ (0, _createClass2.default)(ParticipantsService, [{
208
+ key: "emitTelepointersFromSteps",
209
+ value:
210
+ /**
211
+ * Called on receiving steps, emits each step's telepointer
212
+ * @param steps Steps to extract telepointers from
213
+ * @param emit Provider emit function
214
+ */
215
+ function emitTelepointersFromSteps(steps, emit) {
216
+ var _this2 = this;
217
+ steps.forEach(function (step) {
218
+ var event = (0, _telepointersHelper.telepointerFromStep)(_this2.participantsState.getParticipants(), step);
219
+ if (event) {
220
+ _this2.emitTelepointer(event, emit, 'emitting telepointers from steps');
221
+ }
222
+ });
223
+ }
224
+
225
+ /**
226
+ * Called when we receive a telepointer update from another
227
+ * participant.
228
+ */
229
+
230
+ /**
231
+ * Every 5 minutes (PARTICIPANT_UPDATE_INTERVAL), removes inactive participants and emits the update to other participants.
232
+ * Needs to be kicked off in the Provider.
233
+ * @param sessionId SessionId from provider's connection
234
+ * @param emit Function to execute emit from provider socket
235
+ */
236
+
237
+ /**
238
+ * Keep list of participants up to date. Filter out inactive users etc.
239
+ */
240
+
241
+ /**
242
+ * Wrapper function to emit with error handling and analytics
243
+ * @param data Data to emit
244
+ * @param emit Emit function from Provider
245
+ */
246
+
247
+ /**
248
+ * Wrapper function to emit with error handling and analytics
249
+ * @param data Data to emit
250
+ * @param emit Emit function from Provider
251
+ */
252
+
253
+ /**
254
+ * Used when the provider is disconnected or destroyed to prevent perpetual timers from continuously running
255
+ */
256
+ }]);
257
+ return ParticipantsService;
258
+ }();
259
+ exports.ParticipantsService = ParticipantsService;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ParticipantsState = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
+ 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; }
13
+ 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; }
14
+ var ParticipantsState = /*#__PURE__*/(0, _createClass2.default)(function ParticipantsState() {
15
+ var _this = this;
16
+ var baseParticipants = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Map();
17
+ (0, _classCallCheck2.default)(this, ParticipantsState);
18
+ (0, _defineProperty2.default)(this, "getBySessionId", function (sessionId) {
19
+ var participant = _this.participants.get(sessionId);
20
+ // Spread to ensure we get a deep copy
21
+ return participant ? _objectSpread({}, participant) : undefined;
22
+ });
23
+ (0, _defineProperty2.default)(this, "setBySessionId", function (sessionId, participant) {
24
+ _this.participants.set(sessionId, participant);
25
+ });
26
+ (0, _defineProperty2.default)(this, "getParticipants", function () {
27
+ return (
28
+ // Spread to get deep copy
29
+ (0, _toConsumableArray2.default)(_this.participants.values()).map(function (p) {
30
+ return _objectSpread({}, p);
31
+ })
32
+ );
33
+ });
34
+ (0, _defineProperty2.default)(this, "removeBySessionId", function (sessionId) {
35
+ return _this.participants.delete(sessionId);
36
+ });
37
+ (0, _defineProperty2.default)(this, "clear", function () {
38
+ return _this.participants.clear();
39
+ });
40
+ (0, _defineProperty2.default)(this, "doesntHave", function (sessionId) {
41
+ return !_this.participants.has(sessionId);
42
+ });
43
+ (0, _defineProperty2.default)(this, "size", function () {
44
+ return _this.participants.size;
45
+ });
46
+ (0, _defineProperty2.default)(this, "updateLastActive", function (now, userIds) {
47
+ return _this.participants.forEach(function (p) {
48
+ p.lastActive = userIds.includes(p.userId) ? now : p.lastActive;
49
+ });
50
+ });
51
+ this.participants = baseParticipants;
52
+ }
53
+
54
+ // If userId of participant in userIds, set lastActive to now
55
+ );
56
+ exports.ParticipantsState = ParticipantsState;
@@ -4,19 +4,19 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.telepointersFromStep = exports.telepointerCallback = void 0;
7
+ exports.telepointerFromStep = exports.telepointerCallback = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _utils = require("../helpers/utils");
11
11
  var _ufo = require("@atlaskit/ufo");
12
12
  var _types = require("../types");
13
13
  var logger = (0, _utils.createLogger)('Telepointer', 'green');
14
- var telepointersFromStep = function telepointersFromStep(participants, step) {
15
- var _Array$from$filter = Array.from(participants.values()).filter(function (p) {
14
+ var telepointerFromStep = function telepointerFromStep(participants, step) {
15
+ var _participants$filter = participants.filter(function (p) {
16
16
  return p.clientId === step.clientId;
17
17
  }),
18
- _Array$from$filter2 = (0, _slicedToArray2.default)(_Array$from$filter, 1),
19
- participant = _Array$from$filter2[0];
18
+ _participants$filter2 = (0, _slicedToArray2.default)(_participants$filter, 1),
19
+ participant = _participants$filter2[0];
20
20
  if (participant) {
21
21
  var _node$text;
22
22
  var stepType = step.stepType,
@@ -41,7 +41,7 @@ var telepointersFromStep = function telepointersFromStep(participants, step) {
41
41
  }
42
42
  }
43
43
  };
44
- exports.telepointersFromStep = telepointersFromStep;
44
+ exports.telepointerFromStep = telepointerFromStep;
45
45
  var telepointerCallback = function telepointerCallback(documentAri) {
46
46
  var telepointerExperience = new _ufo.UFOExperience('collab-provider.telepointer', {
47
47
  type: _ufo.ExperienceTypes.Operation,
@@ -4,15 +4,19 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.commitStep = void 0;
7
+ exports.throttledCommitStep = exports.commitStep = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _countBy = _interopRequireDefault(require("lodash/countBy"));
10
+ var _throttle = _interopRequireDefault(require("lodash/throttle"));
10
11
  var _const = require("../helpers/const");
11
12
  var _types = require("../types");
13
+ var _errorTypes = require("../errors/error-types");
12
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; }
13
15
  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; }
16
+ var SEND_STEPS_THROTTLE = 500; // 0.5 second
17
+
14
18
  var commitStep = function commitStep(_ref) {
15
- var channel = _ref.channel,
19
+ var broadcast = _ref.broadcast,
16
20
  steps = _ref.steps,
17
21
  version = _ref.version,
18
22
  userId = _ref.userId,
@@ -28,7 +32,7 @@ var commitStep = function commitStep(_ref) {
28
32
  });
29
33
  var start = new Date().getTime();
30
34
  try {
31
- channel.broadcast('steps:commit', {
35
+ broadcast('steps:commit', {
32
36
  steps: stepsWithClientAndUserId,
33
37
  version: version,
34
38
  userId: userId
@@ -47,13 +51,12 @@ var commitStep = function commitStep(_ref) {
47
51
  })
48
52
  });
49
53
  } else if (response.type === _types.AcknowledgementResponseTypes.ERROR) {
50
- var _response$error, _response$error$data, _response$error2, _response$error2$data;
51
54
  onErrorHandled(response.error);
52
55
  analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendActionEvent(_const.EVENT_ACTION.ADD_STEPS, _const.EVENT_STATUS.FAILURE, {
53
56
  // User tried committing steps but they were rejected because:
54
57
  // - HEAD_VERSION_UPDATE_FAILED: the collab service's latest stored step tail version didn't correspond to the head version of the first step submitted
55
58
  // - VERSION_NUMBER_ALREADY_EXISTS: while storing the steps there was a conflict meaning someone else wrote steps into the database more quickly
56
- type: ((_response$error = response.error) === null || _response$error === void 0 ? void 0 : (_response$error$data = _response$error.data) === null || _response$error$data === void 0 ? void 0 : _response$error$data.code) === 'HEAD_VERSION_UPDATE_FAILED' || ((_response$error2 = response.error) === null || _response$error2 === void 0 ? void 0 : (_response$error2$data = _response$error2.data) === null || _response$error2$data === void 0 ? void 0 : _response$error2$data.code) === 'VERSION_NUMBER_ALREADY_EXISTS' ? _const.ADD_STEPS_TYPE.REJECTED : _const.ADD_STEPS_TYPE.ERROR,
59
+ type: response.error.data.code === _errorTypes.NCS_ERROR_CODE.HEAD_VERSION_UPDATE_FAILED || response.error.data.code === _errorTypes.NCS_ERROR_CODE.VERSION_NUMBER_ALREADY_EXISTS ? _const.ADD_STEPS_TYPE.REJECTED : _const.ADD_STEPS_TYPE.ERROR,
57
60
  latency: latency
58
61
  });
59
62
  analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(response.error, 'Error while adding steps - Acknowledgement Error');
@@ -67,4 +70,9 @@ var commitStep = function commitStep(_ref) {
67
70
  analyticsHelper === null || analyticsHelper === void 0 ? void 0 : analyticsHelper.sendErrorEvent(error, 'Error while adding steps - Broadcast threw exception');
68
71
  }
69
72
  };
70
- exports.commitStep = commitStep;
73
+ exports.commitStep = commitStep;
74
+ var throttledCommitStep = (0, _throttle.default)(commitStep, SEND_STEPS_THROTTLE, {
75
+ leading: false,
76
+ trailing: true
77
+ });
78
+ exports.throttledCommitStep = throttledCommitStep;