@atlaskit/collab-provider 8.8.2 → 8.9.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 (70) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/analytics/analytics-helper.js +21 -12
  3. package/dist/cjs/channel.js +5 -3
  4. package/dist/cjs/document/document-service.js +1 -1
  5. package/dist/cjs/errors/error-code-mapper.js +9 -2
  6. package/dist/cjs/namespace/namespace-service.js +77 -0
  7. package/dist/cjs/participants/participants-helper.js +2 -0
  8. package/dist/cjs/participants/participants-service.js +94 -30
  9. package/dist/cjs/provider/index.js +91 -173
  10. package/dist/cjs/version-wrapper.js +1 -1
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/analytics/analytics-helper.js +21 -12
  13. package/dist/es2019/channel.js +5 -3
  14. package/dist/es2019/document/document-service.js +1 -1
  15. package/dist/es2019/errors/error-code-mapper.js +9 -2
  16. package/dist/es2019/namespace/namespace-service.js +48 -0
  17. package/dist/es2019/participants/participants-helper.js +2 -0
  18. package/dist/es2019/participants/participants-service.js +88 -30
  19. package/dist/es2019/provider/index.js +82 -145
  20. package/dist/es2019/version-wrapper.js +1 -1
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/analytics/analytics-helper.js +21 -12
  23. package/dist/esm/channel.js +5 -3
  24. package/dist/esm/document/document-service.js +1 -1
  25. package/dist/esm/errors/error-code-mapper.js +9 -2
  26. package/dist/esm/namespace/namespace-service.js +69 -0
  27. package/dist/esm/participants/participants-helper.js +2 -0
  28. package/dist/esm/participants/participants-service.js +94 -30
  29. package/dist/esm/provider/index.js +91 -173
  30. package/dist/esm/version-wrapper.js +1 -1
  31. package/dist/esm/version.json +1 -1
  32. package/dist/types/namespace/namespace-service.d.ts +14 -0
  33. package/dist/types/participants/participants-helper.d.ts +2 -4
  34. package/dist/types/participants/participants-service.d.ts +40 -16
  35. package/dist/types/provider/index.d.ts +20 -36
  36. package/dist/types/types.d.ts +1 -1
  37. package/dist/types-ts4.5/analytics/analytics-helper.d.ts +11 -0
  38. package/dist/types-ts4.5/analytics/performance.d.ts +15 -0
  39. package/dist/types-ts4.5/analytics/ufo.d.ts +3 -0
  40. package/dist/types-ts4.5/channel.d.ts +47 -0
  41. package/dist/types-ts4.5/config.d.ts +5 -0
  42. package/dist/types-ts4.5/connectivity/network.d.ts +17 -0
  43. package/dist/types-ts4.5/connectivity/reconnect-helper.d.ts +8 -0
  44. package/dist/types-ts4.5/connectivity/singleton.d.ts +3 -0
  45. package/dist/types-ts4.5/disconnected-reason-mapper.d.ts +16 -0
  46. package/dist/types-ts4.5/document/catchup.d.ts +9 -0
  47. package/dist/types-ts4.5/document/document-service.d.ts +86 -0
  48. package/dist/types-ts4.5/document/step-queue-state.d.ts +16 -0
  49. package/dist/types-ts4.5/emitter.d.ts +19 -0
  50. package/dist/types-ts4.5/errors/error-code-mapper.d.ts +2 -0
  51. package/dist/types-ts4.5/errors/error-types.d.ts +443 -0
  52. package/dist/types-ts4.5/feature-flags/__test__/index.unit.d.ts +1 -0
  53. package/dist/types-ts4.5/feature-flags/index.d.ts +9 -0
  54. package/dist/types-ts4.5/feature-flags/types.d.ts +13 -0
  55. package/dist/types-ts4.5/helpers/const.d.ts +183 -0
  56. package/dist/types-ts4.5/helpers/utils.d.ts +5 -0
  57. package/dist/types-ts4.5/index.d.ts +4 -0
  58. package/dist/types-ts4.5/metadata/metadata-service.d.ts +25 -0
  59. package/dist/types-ts4.5/namespace/namespace-service.d.ts +14 -0
  60. package/dist/types-ts4.5/participants/participants-helper.d.ts +12 -0
  61. package/dist/types-ts4.5/participants/participants-service.d.ts +94 -0
  62. package/dist/types-ts4.5/participants/participants-state.d.ts +13 -0
  63. package/dist/types-ts4.5/participants/telepointers-helper.d.ts +4 -0
  64. package/dist/types-ts4.5/provider/commit-step.d.ts +25 -0
  65. package/dist/types-ts4.5/provider/index.d.ts +146 -0
  66. package/dist/types-ts4.5/socket-io-provider.d.ts +5 -0
  67. package/dist/types-ts4.5/types.d.ts +265 -0
  68. package/dist/types-ts4.5/version-wrapper.d.ts +3 -0
  69. package/package.json +3 -3
  70. package/report.api.md +4 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/collab-provider
2
2
 
3
+ ## 8.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`220cf63d92b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/220cf63d92b) - ESS-3525 change catchup failed to recoverable true
8
+ - [`a6bdc7cbd60`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a6bdc7cbd60) - adding functionality for early collab provider setup with initial draft
9
+
10
+ ### Patch Changes
11
+
12
+ - [`a41f38996bd`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a41f38996bd) - Add namespace service, refactor presence into participants service. No external API changes.
13
+ - [`5e005df7946`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5e005df7946) - Refactor presence, no API changes
14
+ - [`02c8dd052d5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/02c8dd052d5) - ESS-3553 Fix tokens not being unset when permissionTokenRefresh returns null. Fix error handler not emitting errors
15
+ - [`a142ba1aa28`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a142ba1aa28) - [ED17172] Bump prosemirror-model to 1.16.0 and prosemirror-view to 1.23.7 and removed work-arounds for fixed issues
16
+ - Updated dependencies
17
+
3
18
  ## 8.8.2
4
19
 
5
20
  ### Patch Changes
@@ -42,18 +42,27 @@ var triggerAnalyticsEvent = function triggerAnalyticsEvent(analyticsEvent, analy
42
42
 
43
43
  if (analyticsEvent.eventAction === _const.EVENT_ACTION.ERROR) {
44
44
  payload.nonPrivacySafeAttributes = analyticsEvent.nonPrivacySafeAttributes;
45
- }
46
-
47
- // Let the browser figure out
48
- // when it should send those events
49
- try {
50
- var requestIdleCallbackFunction = window.requestIdleCallback;
51
- var runItLater = typeof requestIdleCallbackFunction === 'function' ? requestIdleCallbackFunction : window.requestAnimationFrame;
52
- runItLater(function () {
53
- analyticsClient.sendOperationalEvent(payload);
54
- });
55
- } catch (error) {
56
- // silently fail for now https://product-fabric.atlassian.net/browse/ESS-3112
45
+ try {
46
+ var requestIdleCallbackFunction = window.requestIdleCallback;
47
+ var runItLater = typeof requestIdleCallbackFunction === 'function' ? requestIdleCallbackFunction : window.requestAnimationFrame;
48
+ runItLater(function () {
49
+ analyticsClient.sendTrackEvent(payload);
50
+ });
51
+ } catch (error) {
52
+ // silently fail for now https://product-fabric.atlassian.net/browse/ESS-3112
53
+ }
54
+ } else {
55
+ // Let the browser figure out
56
+ // when it should send those events
57
+ try {
58
+ var _requestIdleCallbackFunction = window.requestIdleCallback;
59
+ var _runItLater = typeof _requestIdleCallbackFunction === 'function' ? _requestIdleCallbackFunction : window.requestAnimationFrame;
60
+ _runItLater(function () {
61
+ analyticsClient.sendOperationalEvent(payload);
62
+ });
63
+ } catch (error) {
64
+ // silently fail for now https://product-fabric.atlassian.net/browse/ESS-3112
65
+ }
57
66
  }
58
67
  };
59
68
  var AnalyticsHelper = /*#__PURE__*/function () {
@@ -400,7 +400,7 @@ var Channel = /*#__PURE__*/function (_Emitter) {
400
400
  if (permissionTokenRefresh) {
401
401
  auth = /*#__PURE__*/function () {
402
402
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(cb) {
403
- var token, _err, _err$data, _err$data$meta, authenticationError;
403
+ var token, _data, _data$meta, authenticationError;
404
404
  return _regenerator.default.wrap(function _callee2$(_context2) {
405
405
  while (1) switch (_context2.prev = _context2.next) {
406
406
  case 0:
@@ -422,6 +422,9 @@ var Channel = /*#__PURE__*/function (_Emitter) {
422
422
  // save token locally
423
423
  _this2.setToken(token);
424
424
  authData.token = token;
425
+ } else {
426
+ _this2.unsetToken();
427
+ authData.token = undefined;
425
428
  }
426
429
  cb(authData);
427
430
  _context2.next = 17;
@@ -437,8 +440,7 @@ var Channel = /*#__PURE__*/function (_Emitter) {
437
440
  code: _errorTypes.INTERNAL_ERROR_CODE.TOKEN_PERMISSION_ERROR,
438
441
  meta: {
439
442
  originalError: _context2.t0,
440
- // @ts-expect-error we know the error structure passed in this hack
441
- reason: (_err = err) === null || _err === void 0 ? void 0 : (_err$data = _err.data) === null || _err$data === void 0 ? void 0 : (_err$data$meta = _err$data.meta) === null || _err$data$meta === void 0 ? void 0 : _err$data$meta.reason // Should always be 'RESOURCE_DELETED' Temporary, until Confluence Cloud removes their hack
443
+ reason: _context2.t0 === null || _context2.t0 === void 0 ? void 0 : (_data = _context2.t0.data) === null || _data === void 0 ? void 0 : (_data$meta = _data.meta) === null || _data$meta === void 0 ? void 0 : _data$meta.reason // Should always be 'RESOURCE_DELETED' Temporary, until Confluence Cloud removes their hack
442
444
  // https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/browse/next/packages/native-collab/src/fetchCollabPermissionToken.ts#37
443
445
  }
444
446
  }
@@ -473,7 +473,7 @@ var DocumentService = /*#__PURE__*/function () {
473
473
  });
474
474
  // If steps can apply to local editor successfully, no need to accumulate the error counter.
475
475
  this.stepRejectCounter = 0;
476
- this.participantsService.emitTelepointersFromSteps(steps, this.providerEmitCallback);
476
+ this.participantsService.emitTelepointersFromSteps(steps);
477
477
 
478
478
  // Resend local steps if none of the received steps originated with us!
479
479
  if (clientIds.indexOf(this.clientId) === -1) {
@@ -9,7 +9,7 @@ var _errorTypes = require("./error-types");
9
9
  * Maps internal collab provider errors to an emitted error format
10
10
  */
11
11
  var errorCodeMapper = function errorCodeMapper(error) {
12
- var _error$data, _error$data2, _error$data3;
12
+ var _error$data, _error$data2, _error$data3, _error$data4;
13
13
  switch ((_error$data = error.data) === null || _error$data === void 0 ? void 0 : _error$data.code) {
14
14
  case _errorTypes.NCS_ERROR_CODE.HEAD_VERSION_UPDATE_FAILED:
15
15
  case _errorTypes.NCS_ERROR_CODE.VERSION_NUMBER_ALREADY_EXISTS:
@@ -92,7 +92,6 @@ var errorCodeMapper = function errorCodeMapper(error) {
92
92
  case _errorTypes.NCS_ERROR_CODE.NAMESPACE_NOT_FOUND:
93
93
  case _errorTypes.NCS_ERROR_CODE.ERROR_MAPPING_ERROR:
94
94
  case _errorTypes.NCS_ERROR_CODE.EMPTY_BROADCAST:
95
- case _errorTypes.INTERNAL_ERROR_CODE.CATCHUP_FAILED:
96
95
  return {
97
96
  code: _errorTypes.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
98
97
  message: 'Collab Provider experienced an unrecoverable error',
@@ -100,6 +99,14 @@ var errorCodeMapper = function errorCodeMapper(error) {
100
99
  reason: (_error$data3 = error.data) === null || _error$data3 === void 0 ? void 0 : _error$data3.code,
101
100
  status: 500
102
101
  };
102
+ case _errorTypes.INTERNAL_ERROR_CODE.CATCHUP_FAILED:
103
+ return {
104
+ code: _errorTypes.PROVIDER_ERROR_CODE.INTERNAL_SERVICE_ERROR,
105
+ message: 'Collab Provider experienced an unrecoverable error',
106
+ recoverable: true,
107
+ reason: (_error$data4 = error.data) === null || _error$data4 === void 0 ? void 0 : _error$data4.code,
108
+ status: 500
109
+ };
103
110
  default:
104
111
  return;
105
112
  }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.NamespaceService = void 0;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+ var _utils = require("../helpers/utils");
14
+ var logger = (0, _utils.createLogger)('Provider', 'orange');
15
+
16
+ /**
17
+ * Allows us to keep track of any namespace changes from the server.
18
+ * @param isNamespaceLocked - whether the namespace is locked or not, defaults to false
19
+ */
20
+ var NamespaceService = /*#__PURE__*/(0, _createClass2.default)(function NamespaceService() {
21
+ var _this = this;
22
+ var isNamespaceLocked = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
23
+ (0, _classCallCheck2.default)(this, NamespaceService);
24
+ // Primitive values are always copied
25
+ (0, _defineProperty2.default)(this, "getIsNamespaceLocked", function () {
26
+ return _this.isNamespaceLocked;
27
+ });
28
+ /**
29
+ * ESS-2916 namespace status event- lock/unlock
30
+ */
31
+ (0, _defineProperty2.default)(this, "onNamespaceStatusChanged", /*#__PURE__*/function () {
32
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
33
+ var isLocked, waitTimeInMs, timestamp, start;
34
+ return _regenerator.default.wrap(function _callee$(_context) {
35
+ while (1) switch (_context.prev = _context.next) {
36
+ case 0:
37
+ isLocked = _ref.isLocked, waitTimeInMs = _ref.waitTimeInMs, timestamp = _ref.timestamp;
38
+ start = Date.now();
39
+ logger("Received a namespace status changed event ", {
40
+ isLocked: isLocked,
41
+ waitTimeInMs: waitTimeInMs,
42
+ timestamp: timestamp
43
+ });
44
+ if (!(isLocked && waitTimeInMs)) {
45
+ _context.next = 8;
46
+ break;
47
+ }
48
+ _this.isNamespaceLocked = true;
49
+ logger("Received a namespace status change event ", {
50
+ isLocked: isLocked
51
+ });
52
+
53
+ // To protect the collab editing process from locked out due to BE
54
+ setTimeout(function () {
55
+ logger("The namespace lock has expired", {
56
+ waitTime: Date.now() - start,
57
+ timestamp: timestamp
58
+ });
59
+ _this.isNamespaceLocked = false;
60
+ }, waitTimeInMs);
61
+ return _context.abrupt("return");
62
+ case 8:
63
+ _this.isNamespaceLocked = false;
64
+ logger("The page lock has expired");
65
+ case 10:
66
+ case "end":
67
+ return _context.stop();
68
+ }
69
+ }, _callee);
70
+ }));
71
+ return function (_x) {
72
+ return _ref2.apply(this, arguments);
73
+ };
74
+ }());
75
+ this.isNamespaceLocked = isNamespaceLocked;
76
+ });
77
+ exports.NamespaceService = NamespaceService;
@@ -8,6 +8,8 @@ exports.createParticipantFromPayload = exports.PARTICIPANT_UPDATE_INTERVAL = voi
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var PARTICIPANT_UPDATE_INTERVAL = 300 * 1000; // 300 seconds
11
+
12
+ // Names are hard
11
13
  exports.PARTICIPANT_UPDATE_INTERVAL = PARTICIPANT_UPDATE_INTERVAL;
12
14
  var createParticipantFromPayload = /*#__PURE__*/function () {
13
15
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(payload, getUser) {
@@ -15,22 +15,37 @@ var _const = require("../helpers/const");
15
15
  var _telepointersHelper = require("./telepointers-helper");
16
16
  var _participantsHelper = require("./participants-helper");
17
17
  var _participantsState = require("./participants-state");
18
+ var _utils = require("../helpers/utils");
18
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; }
19
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 logger = (0, _utils.createLogger)('PresenceService', 'pink');
22
+ var SEND_PRESENCE_INTERVAL = 150 * 1000; // 150 seconds
23
+
24
+ /**
25
+ * This service is responsible for handling presence and participant events, as well as sending them on to the editor or NCS.
26
+ * @param analyticsHelper Analytics helper instance
27
+ * @param participantsState Starts with no participants, only add this when testing
28
+ * @param emit Emit from the Provider class (to the editor)
29
+ * @param getUser Callback to get user data from the editor
30
+ * @param channelBroadcast Broadcast from the Channel class (to NCS)
31
+ * @param sendPresenceJoined Callback to Channel class
32
+ */
20
33
  var ParticipantsService = /*#__PURE__*/function () {
21
34
  function ParticipantsService(analyticsHelper) {
22
35
  var _this = this;
23
36
  var participantsState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _participantsState.ParticipantsState();
37
+ var emit = arguments.length > 2 ? arguments[2] : undefined;
38
+ var getUser = arguments.length > 3 ? arguments[3] : undefined;
39
+ var channelBroadcast = arguments.length > 4 ? arguments[4] : undefined;
40
+ var sendPresenceJoined = arguments.length > 5 ? arguments[5] : undefined;
24
41
  (0, _classCallCheck2.default)(this, ParticipantsService);
25
42
  /**
26
43
  * Carries out 3 things: 1) enriches the participant with user data, 2) updates the participantsState, 3) emits the presence event
27
44
  * @param payload Payload from incoming socket event
28
- * @param getUser Function to get user data from confluence
29
- * @param emit Function to execute emit from provider socket
30
45
  * @returns Awaitable Promise, due to getUser
31
46
  */
32
- (0, _defineProperty2.default)(this, "updateParticipant", /*#__PURE__*/function () {
33
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(payload, getUser, emit) {
47
+ (0, _defineProperty2.default)(this, "onParticipantUpdated", /*#__PURE__*/function () {
48
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(payload) {
34
49
  var userId, participant, _this$analyticsHelper, isNewParticipant;
35
50
  return _regenerator.default.wrap(function _callee$(_context) {
36
51
  while (1) switch (_context.prev = _context.next) {
@@ -47,7 +62,7 @@ var ParticipantsService = /*#__PURE__*/function () {
47
62
  return (0, _participantsHelper.createParticipantFromPayload)( // userId _must_ be defined, this lets the compiler know
48
63
  _objectSpread(_objectSpread({}, payload), {}, {
49
64
  userId: userId
50
- }), getUser);
65
+ }), _this.getUser);
51
66
  case 6:
52
67
  participant = _context.sent;
53
68
  _context.next = 12;
@@ -56,7 +71,7 @@ var ParticipantsService = /*#__PURE__*/function () {
56
71
  _context.prev = 9;
57
72
  _context.t0 = _context["catch"](3);
58
73
  // We don't want to throw errors for Presence features as they tend to self-restore
59
- (_this$analyticsHelper = _this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(_context.t0, 'enriching participant');
74
+ (_this$analyticsHelper = _this.analyticsHelper) === null || _this$analyticsHelper === void 0 ? void 0 : _this$analyticsHelper.sendErrorEvent(_context.t0, 'Error while enriching participant');
60
75
  case 12:
61
76
  if (participant) {
62
77
  _context.next = 14;
@@ -74,36 +89,35 @@ var ParticipantsService = /*#__PURE__*/function () {
74
89
  case 18:
75
90
  _this.emitPresence({
76
91
  joined: [participant]
77
- }, emit, 'handling participant updated event');
92
+ }, 'handling participant updated event');
78
93
  case 19:
79
94
  case "end":
80
95
  return _context.stop();
81
96
  }
82
97
  }, _callee, null, [[3, 9]]);
83
98
  }));
84
- return function (_x, _x2, _x3) {
99
+ return function (_x) {
85
100
  return _ref.apply(this, arguments);
86
101
  };
87
102
  }());
88
103
  /**
89
104
  * Called when a participant leaves the session.
90
- *
91
105
  * We emit the `presence` event to update the active avatars in the editor.
92
106
  */
93
- (0, _defineProperty2.default)(this, "participantLeft", function (_ref2, emit) {
107
+ (0, _defineProperty2.default)(this, "onParticipantLeft", function (_ref2) {
94
108
  var sessionId = _ref2.sessionId;
95
109
  _this.participantsState.removeBySessionId(sessionId);
96
110
  _this.emitPresence({
97
111
  left: [{
98
112
  sessionId: sessionId
99
113
  }]
100
- }, emit, 'participant leaving');
114
+ }, 'participant leaving');
101
115
  });
102
- (0, _defineProperty2.default)(this, "disconnect", function (reason, sessionId, emit) {
116
+ (0, _defineProperty2.default)(this, "disconnect", function (reason, sessionId) {
103
117
  var left = _this.participantsState.getParticipants();
104
118
  _this.participantsState.clear();
105
119
  try {
106
- emit('disconnected', {
120
+ _this.emit('disconnected', {
107
121
  reason: (0, _disconnectedReasonMapper.disconnectedReasonMapper)(reason),
108
122
  sid: sessionId
109
123
  });
@@ -115,7 +129,7 @@ var ParticipantsService = /*#__PURE__*/function () {
115
129
  if (left.length) {
116
130
  _this.emitPresence({
117
131
  left: left
118
- }, emit, 'emitting presence update on disconnect');
132
+ }, 'emitting presence update on disconnect');
119
133
  }
120
134
  });
121
135
  /**
@@ -130,7 +144,7 @@ var ParticipantsService = /*#__PURE__*/function () {
130
144
  * Called when we receive a telepointer update from another
131
145
  * participant.
132
146
  */
133
- (0, _defineProperty2.default)(this, "participantTelepointer", function (payload, thisSessionId, getUser, emit) {
147
+ (0, _defineProperty2.default)(this, "onParticipantTelepointer", function (payload, thisSessionId) {
134
148
  var sessionId = payload.sessionId,
135
149
  selection = payload.selection,
136
150
  timestamp = payload.timestamp;
@@ -148,30 +162,29 @@ var ParticipantsService = /*#__PURE__*/function () {
148
162
  type: 'telepointer',
149
163
  selection: selection,
150
164
  sessionId: sessionId
151
- }, emit, 'handling participant telepointer event');
165
+ }, 'handling participant telepointer event');
152
166
  });
153
167
  /**
154
168
  * Every 5 minutes (PARTICIPANT_UPDATE_INTERVAL), removes inactive participants and emits the update to other participants.
155
169
  * Needs to be kicked off in the Provider.
156
170
  * @param sessionId SessionId from provider's connection
157
- * @param emit Function to execute emit from provider socket
158
171
  */
159
- (0, _defineProperty2.default)(this, "removeInactiveParticipants", function (sessionId, emit) {
172
+ (0, _defineProperty2.default)(this, "startInactiveRemover", function (sessionId) {
160
173
  clearTimeout(_this.participantUpdateTimeout);
161
174
  try {
162
- _this.filterInactive(sessionId, emit);
175
+ _this.filterInactive(sessionId);
163
176
  } catch (err) {
164
177
  var _this$analyticsHelper3;
165
178
  (_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(err, 'Failed filtering inactive participants');
166
179
  }
167
180
  _this.participantUpdateTimeout = window.setTimeout(function () {
168
- return _this.removeInactiveParticipants(sessionId, emit);
181
+ return _this.startInactiveRemover(sessionId);
169
182
  }, _participantsHelper.PARTICIPANT_UPDATE_INTERVAL);
170
183
  });
171
184
  /**
172
185
  * Keep list of participants up to date. Filter out inactive users etc.
173
186
  */
174
- (0, _defineProperty2.default)(this, "filterInactive", function (sessionId, emit) {
187
+ (0, _defineProperty2.default)(this, "filterInactive", function (sessionId) {
175
188
  var now = Date.now();
176
189
  var left = _this.participantsState.getParticipants().filter(function (p) {
177
190
  return p.sessionId !== sessionId && now - p.lastActive > _participantsHelper.PARTICIPANT_UPDATE_INTERVAL;
@@ -181,17 +194,17 @@ var ParticipantsService = /*#__PURE__*/function () {
181
194
  });
182
195
  left.length && _this.emitPresence({
183
196
  left: left
184
- }, emit, 'filtering inactive participants');
197
+ }, 'filtering inactive participants');
185
198
  });
186
199
  /**
187
200
  * Wrapper function to emit with error handling and analytics
188
201
  * @param data Data to emit
189
202
  * @param emit Emit function from Provider
190
203
  */
191
- (0, _defineProperty2.default)(this, "emitPresence", function (data, emit, errorMessage) {
204
+ (0, _defineProperty2.default)(this, "emitPresence", function (data, errorMessage) {
192
205
  try {
193
206
  var _this$analyticsHelper4;
194
- emit('presence', data);
207
+ _this.emit('presence', data);
195
208
  (_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendActionEvent(_const.EVENT_ACTION.UPDATE_PARTICIPANTS, _const.EVENT_STATUS.SUCCESS, {
196
209
  participants: _this.participantsState.size()
197
210
  });
@@ -206,9 +219,9 @@ var ParticipantsService = /*#__PURE__*/function () {
206
219
  * @param data Data to emit
207
220
  * @param emit Emit function from Provider
208
221
  */
209
- (0, _defineProperty2.default)(this, "emitTelepointer", function (data, emit, errorMessage) {
222
+ (0, _defineProperty2.default)(this, "emitTelepointer", function (data, errorMessage) {
210
223
  try {
211
- emit('telepointer', data);
224
+ _this.emit('telepointer', data);
212
225
  } catch (error) {
213
226
  var _this$analyticsHelper6;
214
227
  // We don't want to throw errors for Presence features as they tend to self-restore
@@ -221,8 +234,60 @@ var ParticipantsService = /*#__PURE__*/function () {
221
234
  (0, _defineProperty2.default)(this, "clearTimers", function () {
222
235
  clearTimeout(_this.participantUpdateTimeout);
223
236
  });
224
- this.participantsState = participantsState;
237
+ (0, _defineProperty2.default)(this, "sendPresence", function (payload) {
238
+ try {
239
+ clearTimeout(_this.presenceUpdateTimeout);
240
+ _this.channelBroadcast('participant:updated', payload);
241
+ _this.presenceUpdateTimeout = window.setTimeout(function () {
242
+ return _this.sendPresence(payload);
243
+ }, SEND_PRESENCE_INTERVAL);
244
+ } catch (error) {
245
+ var _this$analyticsHelper7;
246
+ // We don't want to throw errors for Presence features as they tend to self-restore
247
+ (_this$analyticsHelper7 = _this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(error, 'Error while sending presence');
248
+ }
249
+ });
250
+ /**
251
+ * Called when a participant joins the session.
252
+ *
253
+ * We keep track of participants internally, and emit the `presence` event to update
254
+ * the active avatars in the editor.
255
+ * This method will be triggered from backend to notify all participants to exchange presence
256
+ */
257
+ (0, _defineProperty2.default)(this, "onPresenceJoined", function (payload) {
258
+ try {
259
+ logger('Participant joined with session: ', payload.sessionId);
260
+ // This expose existing users to the newly joined user
261
+ _this.sendPresence(payload);
262
+ } catch (error) {
263
+ var _this$analyticsHelper8;
264
+ // We don't want to throw errors for Presence features as they tend to self-restore
265
+ (_this$analyticsHelper8 = _this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(error, 'Error while joining presence');
266
+ }
267
+ });
268
+ /**
269
+ * Called when the current user joins the session.
270
+ *
271
+ * This will send both a 'presence' event and a 'participant:updated' event.
272
+ * This updates both the avatars and the participants list.
273
+ */
274
+ (0, _defineProperty2.default)(this, "onPresence", function (payload) {
275
+ try {
276
+ logger('onPresence userId: ', payload.userId);
277
+ _this.sendPresence(payload);
278
+ _this.sendPresenceJoined();
279
+ } catch (error) {
280
+ var _this$analyticsHelper9;
281
+ // We don't want to throw errors for Presence features as they tend to self-restore
282
+ (_this$analyticsHelper9 = _this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(error, 'Error while receiving presence');
283
+ }
284
+ });
225
285
  this.analyticsHelper = analyticsHelper;
286
+ this.participantsState = participantsState;
287
+ this.emit = emit;
288
+ this.getUser = getUser;
289
+ this.channelBroadcast = channelBroadcast;
290
+ this.sendPresenceJoined = sendPresenceJoined;
226
291
  }
227
292
  (0, _createClass2.default)(ParticipantsService, [{
228
293
  key: "emitTelepointersFromSteps",
@@ -230,14 +295,13 @@ var ParticipantsService = /*#__PURE__*/function () {
230
295
  /**
231
296
  * Called on receiving steps, emits each step's telepointer
232
297
  * @param steps Steps to extract telepointers from
233
- * @param emit Provider emit function
234
298
  */
235
- function emitTelepointersFromSteps(steps, emit) {
299
+ function emitTelepointersFromSteps(steps) {
236
300
  var _this2 = this;
237
301
  steps.forEach(function (step) {
238
302
  var event = (0, _telepointersHelper.telepointerFromStep)(_this2.participantsState.getParticipants(), step);
239
303
  if (event) {
240
- _this2.emitTelepointer(event, emit, 'emitting telepointers from steps');
304
+ _this2.emitTelepointer(event, 'emitting telepointers from steps');
241
305
  }
242
306
  });
243
307
  }