@atlaskit/collab-provider 8.6.0 → 8.8.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 (67) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/cjs/analytics/analytics-helper.js +25 -28
  3. package/dist/cjs/analytics/performance.js +4 -4
  4. package/dist/cjs/channel.js +218 -224
  5. package/dist/cjs/connectivity/network.js +4 -4
  6. package/dist/cjs/disconnected-reason-mapper.js +4 -4
  7. package/dist/cjs/document/catchup.js +84 -87
  8. package/dist/cjs/document/document-service.js +205 -234
  9. package/dist/cjs/document/step-queue-state.js +4 -5
  10. package/dist/cjs/errors/error-types.js +25 -24
  11. package/dist/cjs/helpers/const.js +12 -12
  12. package/dist/cjs/metadata/metadata-service.js +15 -20
  13. package/dist/cjs/participants/participants-helper.js +22 -32
  14. package/dist/cjs/participants/participants-service.js +89 -101
  15. package/dist/cjs/participants/participants-state.js +2 -4
  16. package/dist/cjs/provider/index.js +130 -136
  17. package/dist/cjs/types.js +11 -5
  18. package/dist/cjs/version-wrapper.js +1 -1
  19. package/dist/cjs/version.json +1 -1
  20. package/dist/es2019/analytics/analytics-helper.js +3 -3
  21. package/dist/es2019/analytics/performance.js +3 -3
  22. package/dist/es2019/channel.js +21 -20
  23. package/dist/es2019/connectivity/network.js +3 -3
  24. package/dist/es2019/disconnected-reason-mapper.js +3 -3
  25. package/dist/es2019/document/document-service.js +17 -25
  26. package/dist/es2019/document/step-queue-state.js +4 -5
  27. package/dist/es2019/errors/error-types.js +26 -25
  28. package/dist/es2019/helpers/const.js +9 -9
  29. package/dist/es2019/metadata/metadata-service.js +15 -19
  30. package/dist/es2019/participants/participants-helper.js +3 -8
  31. package/dist/es2019/participants/participants-service.js +42 -52
  32. package/dist/es2019/participants/participants-state.js +1 -2
  33. package/dist/es2019/provider/index.js +68 -71
  34. package/dist/es2019/types.js +13 -3
  35. package/dist/es2019/version-wrapper.js +1 -1
  36. package/dist/es2019/version.json +1 -1
  37. package/dist/esm/analytics/analytics-helper.js +25 -28
  38. package/dist/esm/analytics/performance.js +3 -3
  39. package/dist/esm/channel.js +218 -224
  40. package/dist/esm/connectivity/network.js +3 -3
  41. package/dist/esm/disconnected-reason-mapper.js +3 -3
  42. package/dist/esm/document/catchup.js +84 -87
  43. package/dist/esm/document/document-service.js +205 -234
  44. package/dist/esm/document/step-queue-state.js +4 -5
  45. package/dist/esm/errors/error-types.js +26 -25
  46. package/dist/esm/helpers/const.js +9 -9
  47. package/dist/esm/metadata/metadata-service.js +15 -20
  48. package/dist/esm/participants/participants-helper.js +22 -32
  49. package/dist/esm/participants/participants-service.js +89 -101
  50. package/dist/esm/participants/participants-state.js +2 -4
  51. package/dist/esm/provider/index.js +130 -136
  52. package/dist/esm/types.js +13 -3
  53. package/dist/esm/version-wrapper.js +1 -1
  54. package/dist/esm/version.json +1 -1
  55. package/dist/types/channel.d.ts +1 -1
  56. package/dist/types/feature-flags/types.d.ts +1 -1
  57. package/dist/types/metadata/metadata-service.d.ts +1 -1
  58. package/dist/types/participants/participants-helper.d.ts +2 -3
  59. package/dist/types/participants/participants-service.d.ts +4 -8
  60. package/dist/types/provider/index.d.ts +6 -0
  61. package/dist/types/types.d.ts +15 -9
  62. package/package.json +16 -11
  63. package/report.api.md +11 -5
  64. package/channel/package.json +0 -15
  65. package/config/package.json +0 -15
  66. package/disconnected-reason-mapper/package.json +0 -15
  67. package/emitter/package.json +0 -15
@@ -11,15 +11,15 @@ export const socketIOReasons = {
11
11
  PING_TIMEOUT: 'ping timeout' // The connection has encountered an error (example: the server was killed during a HTTP long-polling cycle)
12
12
  };
13
13
 
14
- export let DisconnectReason;
15
- (function (DisconnectReason) {
14
+ export let DisconnectReason = /*#__PURE__*/function (DisconnectReason) {
16
15
  DisconnectReason["CLIENT_DISCONNECT"] = "CLIENT_DISCONNECT";
17
16
  DisconnectReason["SERVER_DISCONNECT"] = "SERVER_DISCONNECT";
18
17
  DisconnectReason["SOCKET_CLOSED"] = "SOCKET_CLOSED";
19
18
  DisconnectReason["SOCKET_ERROR"] = "SOCKET_ERROR";
20
19
  DisconnectReason["SOCKET_TIMEOUT"] = "SOCKET_TIMEOUT";
21
20
  DisconnectReason["UNKNOWN_DISCONNECT"] = "UNKNOWN_DISCONNECT";
22
- })(DisconnectReason || (DisconnectReason = {}));
21
+ return DisconnectReason;
22
+ }({});
23
23
  export const disconnectedReasonMapper = reason => {
24
24
  switch (reason) {
25
25
  case socketIOReasons.IO_CLIENT_DISCONNECT:
@@ -15,8 +15,6 @@ const CATCHUP_THROTTLE = 1 * 1000; // 1 second
15
15
  const noop = () => {};
16
16
  const logger = createLogger('documentService', 'black');
17
17
  export class DocumentService {
18
- // Fires analytics to editor when collab editor cannot sync up
19
-
20
18
  // ClientID is the unique ID for a prosemirror client. Used for step-rebasing.
21
19
 
22
20
  /**
@@ -32,12 +30,21 @@ export class DocumentService {
32
30
  * @param onErrorHandled - Callback to handle
33
31
  */
34
32
  constructor(participantsService, analyticsHelper, fetchCatchup, providerEmitCallback, broadcast, getUserId, onErrorHandled, metadataService) {
33
+ // Fires analytics to editor when collab editor cannot sync up
35
34
  _defineProperty(this, "stepRejectCounter", 0);
35
+ /**
36
+ * To prevent calling catchup to often, use lodash throttle to reduce the frequency
37
+ */
36
38
  _defineProperty(this, "throttledCatchup", throttle(() => this.catchup(), CATCHUP_THROTTLE, {
37
39
  leading: false,
38
40
  // TODO: why shouldn't this be leading?
39
41
  trailing: true
40
42
  }));
43
+ /**
44
+ * Called when:
45
+ * * session established(offline -> online)
46
+ * * try to accept steps but version is behind.
47
+ */
41
48
  _defineProperty(this, "catchup", async () => {
42
49
  const start = new Date().getTime();
43
50
  // if the queue is already paused, we are busy with something else, so don't proceed.
@@ -140,6 +147,9 @@ export class DocumentService {
140
147
  steps
141
148
  });
142
149
  });
150
+ /**
151
+ * Called when we receive steps from the service
152
+ */
143
153
  _defineProperty(this, "onStepsAdded", data => {
144
154
  logger(`Received steps`, {
145
155
  steps: data.steps,
@@ -177,6 +187,7 @@ export class DocumentService {
177
187
  });
178
188
  }
179
189
  });
190
+ // Triggered when page recovery has emitted an 'init' event on a page client is currently connected to.
180
191
  _defineProperty(this, "onRestore", ({
181
192
  doc,
182
193
  version,
@@ -259,6 +270,10 @@ export class DocumentService {
259
270
  } : {})
260
271
  });
261
272
  });
273
+ /**
274
+ * Commit the unconfirmed local steps to the back-end service
275
+ * @throws {Error} Couldn't sync the steps after retrying 30 times
276
+ */
262
277
  _defineProperty(this, "commitUnconfirmedSteps", async () => {
263
278
  const unconfirmedSteps = this.getUnconfirmedSteps();
264
279
  try {
@@ -339,17 +354,6 @@ export class DocumentService {
339
354
  this.metadataService = metadataService;
340
355
  this.stepQueue = new StepQueueState();
341
356
  }
342
-
343
- /**
344
- * To prevent calling catchup to often, use lodash throttle to reduce the frequency
345
- */
346
-
347
- /**
348
- * Called when:
349
- * * session established(offline -> online)
350
- * * try to accept steps but version is behind.
351
- */
352
-
353
357
  processQueue() {
354
358
  if (this.stepQueue.isPaused()) {
355
359
  logger(`Queue is paused. Aborting.`);
@@ -400,18 +404,6 @@ export class DocumentService {
400
404
  }
401
405
  }
402
406
  }
403
-
404
- /**
405
- * Called when we receive steps from the service
406
- */
407
-
408
- // Triggered when page recovery has emitted an 'init' event on a page client is currently connected to.
409
-
410
- /**
411
- * Commit the unconfirmed local steps to the back-end service
412
- * @throws {Error} Couldn't sync the steps after retrying 30 times
413
- */
414
-
415
407
  setup({
416
408
  getState,
417
409
  onSyncUpError,
@@ -11,6 +11,10 @@ export class StepQueueState {
11
11
  _defineProperty(this, "filterQueue", condition => {
12
12
  this.queue = this.queue.filter(condition);
13
13
  });
14
+ /**
15
+ * Get whether the document service has stopped processing new steps whilst it carries out processes such as catchup.
16
+ * Exposed for testing
17
+ */
14
18
  _defineProperty(this, "isPaused", () => this.queuePaused);
15
19
  _defineProperty(this, "pauseQueue", () => {
16
20
  this.queuePaused = true;
@@ -27,9 +31,4 @@ export class StepQueueState {
27
31
  const orderedQueue = [...this.queue, data].sort((a, b) => a.version > b.version ? 1 : -1);
28
32
  this.queue = orderedQueue;
29
33
  }
30
-
31
- /**
32
- * Get whether the document service has stopped processing new steps whilst it carries out processes such as catchup.
33
- * Exposed for testing
34
- */
35
34
  }
@@ -1,8 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  // Internal error codes (generated by collab provider)
3
- export let INTERNAL_ERROR_CODE;
4
- // NCS error coded (generated by NCS)
5
- (function (INTERNAL_ERROR_CODE) {
3
+ export let INTERNAL_ERROR_CODE = /*#__PURE__*/function (INTERNAL_ERROR_CODE) {
6
4
  INTERNAL_ERROR_CODE["TOKEN_PERMISSION_ERROR"] = "TOKEN_PERMISSION_ERROR";
7
5
  INTERNAL_ERROR_CODE["RECONNECTION_NETWORK_ISSUE"] = "RECONNECTION_NETWORK_ISSUE";
8
6
  INTERNAL_ERROR_CODE["CONNECTION_ERROR"] = "CONNECTION_ERROR";
@@ -11,14 +9,10 @@ export let INTERNAL_ERROR_CODE;
11
9
  INTERNAL_ERROR_CODE["CATCHUP_FAILED"] = "CATCHUP_FAILED";
12
10
  INTERNAL_ERROR_CODE["DOCUMENT_RESTORE_ERROR"] = "DOCUMENT_RESTORE_ERROR";
13
11
  INTERNAL_ERROR_CODE["ADD_STEPS_ERROR"] = "ADD_STEPS_ERROR";
14
- })(INTERNAL_ERROR_CODE || (INTERNAL_ERROR_CODE = {}));
15
- export let NCS_ERROR_CODE;
16
-
17
- // TODO: Import emitted error codes from NCS
18
-
19
- // NCS Errors
20
- // - Step rejection errors
21
- (function (NCS_ERROR_CODE) {
12
+ return INTERNAL_ERROR_CODE;
13
+ }({});
14
+ // NCS error coded (generated by NCS)
15
+ export let NCS_ERROR_CODE = /*#__PURE__*/function (NCS_ERROR_CODE) {
22
16
  NCS_ERROR_CODE["HEAD_VERSION_UPDATE_FAILED"] = "HEAD_VERSION_UPDATE_FAILED";
23
17
  NCS_ERROR_CODE["VERSION_NUMBER_ALREADY_EXISTS"] = "VERSION_NUMBER_ALREADY_EXISTS";
24
18
  NCS_ERROR_CODE["INSUFFICIENT_EDITING_PERMISSION"] = "INSUFFICIENT_EDITING_PERMISSION";
@@ -35,7 +29,14 @@ export let NCS_ERROR_CODE;
35
29
  NCS_ERROR_CODE["INVALID_ACTIVATION_ID"] = "INVALID_ACTIVATION_ID";
36
30
  NCS_ERROR_CODE["INVALID_DOCUMENT_ARI"] = "INVALID_DOCUMENT_ARI";
37
31
  NCS_ERROR_CODE["INVALID_CLOUD_ID"] = "INVALID_CLOUD_ID";
38
- })(NCS_ERROR_CODE || (NCS_ERROR_CODE = {})); // - Permission errors
32
+ return NCS_ERROR_CODE;
33
+ }({});
34
+
35
+ // TODO: Import emitted error codes from NCS
36
+
37
+ // NCS Errors
38
+ // - Step rejection errors
39
+ // - Permission errors
39
40
  // - Page missing / TTL errors
40
41
  // - Server errors
41
42
  // - Less common back-end errors
@@ -45,7 +46,19 @@ export let NCS_ERROR_CODE;
45
46
  * A union of all possible internal errors, that are mapped to another error if being emitted to the editor.
46
47
  */
47
48
  // Emitted errors
48
- export let PROVIDER_ERROR_CODE;
49
+ export let PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) {
50
+ PROVIDER_ERROR_CODE["NO_PERMISSION_ERROR"] = "NO_PERMISSION_ERROR";
51
+ PROVIDER_ERROR_CODE["INVALID_USER_TOKEN"] = "INVALID_USER_TOKEN";
52
+ PROVIDER_ERROR_CODE["DOCUMENT_NOT_FOUND"] = "DOCUMENT_NOT_FOUND";
53
+ PROVIDER_ERROR_CODE["LOCKED"] = "LOCKED";
54
+ PROVIDER_ERROR_CODE["FAIL_TO_SAVE"] = "FAIL_TO_SAVE";
55
+ PROVIDER_ERROR_CODE["DOCUMENT_RESTORE_ERROR"] = "DOCUMENT_RESTORE_ERROR";
56
+ PROVIDER_ERROR_CODE["INITIALISATION_ERROR"] = "INITIALISATION_ERROR";
57
+ PROVIDER_ERROR_CODE["NETWORK_ISSUE"] = "NETWORK_ISSUE";
58
+ PROVIDER_ERROR_CODE["INVALID_PROVIDER_CONFIGURATION"] = "INVALID_PROVIDER_CONFIGURATION";
59
+ PROVIDER_ERROR_CODE["INTERNAL_SERVICE_ERROR"] = "INTERNAL_SERVICE_ERROR";
60
+ return PROVIDER_ERROR_CODE;
61
+ }({});
49
62
 
50
63
  /*
51
64
  * This is what a generic ProviderError type would look like:
@@ -70,18 +83,6 @@ export let PROVIDER_ERROR_CODE;
70
83
  * @message Message returned to editor, i.e User does not have permissions to access this document or document is not found
71
84
  * @recoverable It is recoverable, as we will try to refresh the token.
72
85
  */
73
- (function (PROVIDER_ERROR_CODE) {
74
- PROVIDER_ERROR_CODE["NO_PERMISSION_ERROR"] = "NO_PERMISSION_ERROR";
75
- PROVIDER_ERROR_CODE["INVALID_USER_TOKEN"] = "INVALID_USER_TOKEN";
76
- PROVIDER_ERROR_CODE["DOCUMENT_NOT_FOUND"] = "DOCUMENT_NOT_FOUND";
77
- PROVIDER_ERROR_CODE["LOCKED"] = "LOCKED";
78
- PROVIDER_ERROR_CODE["FAIL_TO_SAVE"] = "FAIL_TO_SAVE";
79
- PROVIDER_ERROR_CODE["DOCUMENT_RESTORE_ERROR"] = "DOCUMENT_RESTORE_ERROR";
80
- PROVIDER_ERROR_CODE["INITIALISATION_ERROR"] = "INITIALISATION_ERROR";
81
- PROVIDER_ERROR_CODE["NETWORK_ISSUE"] = "NETWORK_ISSUE";
82
- PROVIDER_ERROR_CODE["INVALID_PROVIDER_CONFIGURATION"] = "INVALID_PROVIDER_CONFIGURATION";
83
- PROVIDER_ERROR_CODE["INTERNAL_SERVICE_ERROR"] = "INTERNAL_SERVICE_ERROR";
84
- })(PROVIDER_ERROR_CODE || (PROVIDER_ERROR_CODE = {}));
85
86
  /**
86
87
  * Similiar to InsufficientEditingPermission, but the user token is invalid because it has expired or been revoked.
87
88
  * It may also be an invalid token format.
@@ -1,5 +1,4 @@
1
- export let EVENT_ACTION;
2
- (function (EVENT_ACTION) {
1
+ export let EVENT_ACTION = /*#__PURE__*/function (EVENT_ACTION) {
3
2
  EVENT_ACTION["CONNECTION"] = "connection";
4
3
  EVENT_ACTION["CATCHUP"] = "catchup";
5
4
  EVENT_ACTION["DOCUMENT_INIT"] = "documentInit";
@@ -11,17 +10,18 @@ export let EVENT_ACTION;
11
10
  EVENT_ACTION["PUBLISH_PAGE"] = "publishPage";
12
11
  EVENT_ACTION["GET_CURRENT_STATE"] = "getCurrentState";
13
12
  EVENT_ACTION["INVALIDATE_TOKEN"] = "invalidateToken";
14
- })(EVENT_ACTION || (EVENT_ACTION = {}));
15
- export let EVENT_STATUS;
16
- (function (EVENT_STATUS) {
13
+ return EVENT_ACTION;
14
+ }({});
15
+ export let EVENT_STATUS = /*#__PURE__*/function (EVENT_STATUS) {
17
16
  EVENT_STATUS["SUCCESS"] = "SUCCESS";
18
17
  EVENT_STATUS["FAILURE"] = "FAILURE";
19
- })(EVENT_STATUS || (EVENT_STATUS = {}));
20
- export let ADD_STEPS_TYPE;
21
- (function (ADD_STEPS_TYPE) {
18
+ return EVENT_STATUS;
19
+ }({});
20
+ export let ADD_STEPS_TYPE = /*#__PURE__*/function (ADD_STEPS_TYPE) {
22
21
  ADD_STEPS_TYPE["ACCEPTED"] = "ACCEPTED";
23
22
  ADD_STEPS_TYPE["REJECTED"] = "REJECTED";
24
23
  ADD_STEPS_TYPE["ERROR"] = "ERROR";
25
- })(ADD_STEPS_TYPE || (ADD_STEPS_TYPE = {}));
24
+ return ADD_STEPS_TYPE;
25
+ }({});
26
26
  export const ACK_MAX_TRY = 30;
27
27
  export const CONFLUENCE = 'confluence';
@@ -8,12 +8,27 @@ export class MetadataService {
8
8
  var _this$metadata$title;
9
9
  return (_this$metadata$title = this.metadata.title) === null || _this$metadata$title === void 0 ? void 0 : _this$metadata$title.toString();
10
10
  });
11
+ /**
12
+ * Called when a metadata is changed externally from other clients/backend.
13
+ */
11
14
  _defineProperty(this, "onMetadataChanged", metadata => {
12
15
  if (metadata !== undefined && !isEqual(this.metadata, metadata) && Object.keys(metadata).length > 0) {
13
16
  this.metadata = metadata;
14
17
  this.providerEmitCallback('metadata:changed', metadata);
15
18
  }
16
19
  });
20
+ /**
21
+ * Updates the local metadata and broadcasts the metadata to other clients/backend.
22
+ * @param metadata
23
+ */
24
+ _defineProperty(this, "setMetadata", metadata => {
25
+ this.broadcastMetadata(metadata);
26
+ this.metadata = metadata;
27
+ });
28
+ /**
29
+ * Emits a change in document's metadata
30
+ * @param metadata
31
+ */
17
32
  _defineProperty(this, "updateMetadata", metadata => {
18
33
  if (metadata && Object.keys(metadata).length > 0) {
19
34
  this.metadata = metadata;
@@ -23,11 +38,6 @@ export class MetadataService {
23
38
  this.providerEmitCallback = providerEmitCallback;
24
39
  this.broadcastMetadata = broadcastMetadata;
25
40
  }
26
-
27
- /**
28
- * Called when a metadata is changed externally from other clients/backend.
29
- */
30
-
31
41
  setTitle(title, broadcast) {
32
42
  if (broadcast) {
33
43
  this.broadcastMetadata({
@@ -44,18 +54,4 @@ export class MetadataService {
44
54
  }
45
55
  this.metadata.editorWidth = editorWidth;
46
56
  }
47
-
48
- /**
49
- * Updates the local metadata and broadcasts the metadata to other clients/backend.
50
- * @param metadata
51
- */
52
- setMetadata(metadata) {
53
- this.broadcastMetadata(metadata);
54
- this.metadata = metadata;
55
- }
56
-
57
- /**
58
- * Emits a change in document's metadata
59
- * @param metadata
60
- */
61
57
  }
@@ -1,21 +1,16 @@
1
1
  export const PARTICIPANT_UPDATE_INTERVAL = 300 * 1000; // 300 seconds
2
2
 
3
3
  export const createParticipantFromPayload = async (payload, getUser) => {
4
- var _user, _user2, _user3;
5
4
  const {
6
5
  sessionId,
7
6
  timestamp,
8
7
  clientId,
9
8
  userId
10
9
  } = payload;
11
- let user;
12
- if (getUser) {
13
- user = await getUser(userId);
14
- }
10
+ const user = await (getUser === null || getUser === void 0 ? void 0 : getUser(userId));
15
11
  const participant = {
16
- name: ((_user = user) === null || _user === void 0 ? void 0 : _user.name) || '',
17
- email: ((_user2 = user) === null || _user2 === void 0 ? void 0 : _user2.email) || '',
18
- avatar: ((_user3 = user) === null || _user3 === void 0 ? void 0 : _user3.avatar) || '',
12
+ name: (user === null || user === void 0 ? void 0 : user.name) || '',
13
+ avatar: (user === null || user === void 0 ? void 0 : user.avatar) || '',
19
14
  sessionId,
20
15
  lastActive: timestamp,
21
16
  userId,
@@ -6,6 +6,13 @@ import { createParticipantFromPayload as enrichParticipant, PARTICIPANT_UPDATE_I
6
6
  import { ParticipantsState } from './participants-state';
7
7
  export class ParticipantsService {
8
8
  constructor(analyticsHelper, participantsState = new ParticipantsState()) {
9
+ /**
10
+ * Carries out 3 things: 1) enriches the participant with user data, 2) updates the participantsState, 3) emits the presence event
11
+ * @param payload Payload from incoming socket event
12
+ * @param getUser Function to get user data from confluence
13
+ * @param emit Function to execute emit from provider socket
14
+ * @returns Awaitable Promise, due to getUser
15
+ */
9
16
  _defineProperty(this, "updateParticipant", async (payload, getUser, emit) => {
10
17
  const {
11
18
  userId
@@ -41,6 +48,11 @@ export class ParticipantsService {
41
48
  joined: [participant]
42
49
  }, emit, 'handling participant updated event');
43
50
  });
51
+ /**
52
+ * Called when a participant leaves the session.
53
+ *
54
+ * We emit the `presence` event to update the active avatars in the editor.
55
+ */
44
56
  _defineProperty(this, "participantLeft", ({
45
57
  sessionId
46
58
  }, emit) => {
@@ -70,7 +82,15 @@ export class ParticipantsService {
70
82
  }, emit, 'emitting presence update on disconnect');
71
83
  }
72
84
  });
85
+ /**
86
+ * Updates when users were last active
87
+ * @param userIds Users in most recent steps
88
+ */
73
89
  _defineProperty(this, "updateLastActive", (userIds = []) => this.participantsState.updateLastActive(Date.now(), userIds));
90
+ /**
91
+ * Called when we receive a telepointer update from another
92
+ * participant.
93
+ */
74
94
  _defineProperty(this, "participantTelepointer", (payload, thisSessionId, getUser, emit) => {
75
95
  const {
76
96
  sessionId,
@@ -93,6 +113,12 @@ export class ParticipantsService {
93
113
  sessionId
94
114
  }, emit, 'handling participant telepointer event');
95
115
  });
116
+ /**
117
+ * Every 5 minutes (PARTICIPANT_UPDATE_INTERVAL), removes inactive participants and emits the update to other participants.
118
+ * Needs to be kicked off in the Provider.
119
+ * @param sessionId SessionId from provider's connection
120
+ * @param emit Function to execute emit from provider socket
121
+ */
96
122
  _defineProperty(this, "removeInactiveParticipants", (sessionId, emit) => {
97
123
  clearTimeout(this.participantUpdateTimeout);
98
124
  try {
@@ -103,6 +129,9 @@ export class ParticipantsService {
103
129
  }
104
130
  this.participantUpdateTimeout = window.setTimeout(() => this.removeInactiveParticipants(sessionId, emit), PARTICIPANT_UPDATE_INTERVAL);
105
131
  });
132
+ /**
133
+ * Keep list of participants up to date. Filter out inactive users etc.
134
+ */
106
135
  _defineProperty(this, "filterInactive", (sessionId, emit) => {
107
136
  const now = Date.now();
108
137
  const left = this.participantsState.getParticipants().filter(p => p.sessionId !== sessionId && now - p.lastActive > PARTICIPANT_UPDATE_INTERVAL);
@@ -111,6 +140,11 @@ export class ParticipantsService {
111
140
  left
112
141
  }, emit, 'filtering inactive participants');
113
142
  });
143
+ /**
144
+ * Wrapper function to emit with error handling and analytics
145
+ * @param data Data to emit
146
+ * @param emit Emit function from Provider
147
+ */
114
148
  _defineProperty(this, "emitPresence", (data, emit, errorMessage) => {
115
149
  try {
116
150
  var _this$analyticsHelper4;
@@ -124,6 +158,11 @@ export class ParticipantsService {
124
158
  (_this$analyticsHelper5 = this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(error, `Error while ${errorMessage}`);
125
159
  }
126
160
  });
161
+ /**
162
+ * Wrapper function to emit with error handling and analytics
163
+ * @param data Data to emit
164
+ * @param emit Emit function from Provider
165
+ */
127
166
  _defineProperty(this, "emitTelepointer", (data, emit, errorMessage) => {
128
167
  try {
129
168
  emit('telepointer', data);
@@ -133,32 +172,15 @@ export class ParticipantsService {
133
172
  (_this$analyticsHelper6 = this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(error, `Error while ${errorMessage}`);
134
173
  }
135
174
  });
175
+ /**
176
+ * Used when the provider is disconnected or destroyed to prevent perpetual timers from continuously running
177
+ */
136
178
  _defineProperty(this, "clearTimers", () => {
137
179
  clearTimeout(this.participantUpdateTimeout);
138
180
  });
139
181
  this.participantsState = participantsState;
140
182
  this.analyticsHelper = analyticsHelper;
141
183
  }
142
-
143
- /**
144
- * Carries out 3 things: 1) enriches the participant with user data, 2) updates the participantsState, 3) emits the presence event
145
- * @param payload Payload from incoming socket event
146
- * @param getUser Function to get user data from confluence
147
- * @param emit Function to execute emit from provider socket
148
- * @returns Awaitable Promise, due to getUser
149
- */
150
-
151
- /**
152
- * Called when a participant leaves the session.
153
- *
154
- * We emit the `presence` event to update the active avatars in the editor.
155
- */
156
-
157
- /**
158
- * Updates when users were last active
159
- * @param userIds Users in most recent steps
160
- */
161
-
162
184
  /**
163
185
  * Called on receiving steps, emits each step's telepointer
164
186
  * @param steps Steps to extract telepointers from
@@ -172,36 +194,4 @@ export class ParticipantsService {
172
194
  }
173
195
  });
174
196
  }
175
-
176
- /**
177
- * Called when we receive a telepointer update from another
178
- * participant.
179
- */
180
-
181
- /**
182
- * Every 5 minutes (PARTICIPANT_UPDATE_INTERVAL), removes inactive participants and emits the update to other participants.
183
- * Needs to be kicked off in the Provider.
184
- * @param sessionId SessionId from provider's connection
185
- * @param emit Function to execute emit from provider socket
186
- */
187
-
188
- /**
189
- * Keep list of participants up to date. Filter out inactive users etc.
190
- */
191
-
192
- /**
193
- * Wrapper function to emit with error handling and analytics
194
- * @param data Data to emit
195
- * @param emit Emit function from Provider
196
- */
197
-
198
- /**
199
- * Wrapper function to emit with error handling and analytics
200
- * @param data Data to emit
201
- * @param emit Emit function from Provider
202
- */
203
-
204
- /**
205
- * Used when the provider is disconnected or destroyed to prevent perpetual timers from continuously running
206
- */
207
197
  }
@@ -20,11 +20,10 @@ export class ParticipantsState {
20
20
  _defineProperty(this, "clear", () => this.participants.clear());
21
21
  _defineProperty(this, "doesntHave", sessionId => !this.participants.has(sessionId));
22
22
  _defineProperty(this, "size", () => this.participants.size);
23
+ // If userId of participant in userIds, set lastActive to now
23
24
  _defineProperty(this, "updateLastActive", (now, userIds) => this.participants.forEach(p => {
24
25
  p.lastActive = userIds.includes(p.userId) ? now : p.lastActive;
25
26
  }));
26
27
  this.participants = baseParticipants;
27
28
  }
28
-
29
- // If userId of participant in userIds, set lastActive to now
30
29
  }