@atlaskit/collab-provider 9.45.0 → 10.0.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.
- package/CHANGELOG.md +77 -0
- package/afm-cc/tsconfig.json +3 -0
- package/afm-jira/tsconfig.json +3 -0
- package/dist/cjs/helpers/const.js +1 -0
- package/dist/cjs/helpers/utils.js +4 -1
- package/dist/cjs/participants/participants-service.js +51 -2
- package/dist/cjs/participants/participants-state.js +14 -1
- package/dist/cjs/provider/index.js +43 -31
- package/dist/cjs/types.js +0 -1
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/es2019/helpers/const.js +1 -0
- package/dist/es2019/helpers/utils.js +1 -0
- package/dist/es2019/index.js +3 -0
- package/dist/es2019/participants/participants-service.js +50 -4
- package/dist/es2019/participants/participants-state.js +7 -1
- package/dist/es2019/provider/index.js +46 -31
- package/dist/es2019/types.js +0 -2
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/esm/helpers/const.js +1 -0
- package/dist/esm/helpers/utils.js +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/participants/participants-service.js +52 -3
- package/dist/esm/participants/participants-state.js +14 -1
- package/dist/esm/provider/index.js +43 -31
- package/dist/esm/types.js +0 -2
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/types/helpers/const.d.ts +9 -1
- package/dist/types/helpers/utils.d.ts +1 -0
- package/dist/types/participants/participants-helper.d.ts +1 -0
- package/dist/types/participants/participants-service.d.ts +11 -2
- package/dist/types/participants/participants-state.d.ts +1 -0
- package/dist/types/provider/index.d.ts +7 -3
- package/dist/types/types.d.ts +2 -1
- package/dist/types-ts4.5/helpers/const.d.ts +9 -1
- package/dist/types-ts4.5/helpers/utils.d.ts +1 -0
- package/dist/types-ts4.5/participants/participants-helper.d.ts +1 -0
- package/dist/types-ts4.5/participants/participants-service.d.ts +11 -2
- package/dist/types-ts4.5/participants/participants-state.d.ts +1 -0
- package/dist/types-ts4.5/provider/index.d.ts +7 -3
- package/dist/types-ts4.5/types.d.ts +2 -1
- package/package.json +3 -2
|
@@ -113,6 +113,10 @@ export class Provider extends Emitter {
|
|
|
113
113
|
if (initialized && this.disconnectedAt &&
|
|
114
114
|
// Offline longer than `OUT_OF_SYNC_PERIOD`
|
|
115
115
|
Date.now() - this.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
|
|
116
|
+
var _this$analyticsHelper2;
|
|
117
|
+
(_this$analyticsHelper2 = this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendActionEvent(EVENT_ACTION.RECONNECTION, EVENT_STATUS.INFO, {
|
|
118
|
+
disconnectionPeriodSeconds: Math.floor((Date.now() - this.disconnectedAt) / 1000)
|
|
119
|
+
});
|
|
116
120
|
this.documentService.throttledCatchupv2(CatchupEventReason.RECONNECTED);
|
|
117
121
|
}
|
|
118
122
|
this.participantsService.startInactiveRemover(this.sessionId);
|
|
@@ -155,13 +159,13 @@ export class Provider extends Emitter {
|
|
|
155
159
|
if (((_error$data = error.data) === null || _error$data === void 0 ? void 0 : _error$data.code) === NCS_ERROR_CODE.HEAD_VERSION_UPDATE_FAILED || ((_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.code) === NCS_ERROR_CODE.VERSION_NUMBER_ALREADY_EXISTS) {
|
|
156
160
|
this.documentService.onStepRejectedError();
|
|
157
161
|
} else {
|
|
158
|
-
var _this$
|
|
159
|
-
(_this$
|
|
162
|
+
var _this$analyticsHelper3;
|
|
163
|
+
(_this$analyticsHelper3 = this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(error, 'Error handled');
|
|
160
164
|
const mappedError = errorCodeMapper(error);
|
|
161
165
|
// Only emit errors to Confluence very intentionally because they will disconnect the collab provider
|
|
162
166
|
if (mappedError) {
|
|
163
|
-
var _this$
|
|
164
|
-
(_this$
|
|
167
|
+
var _this$analyticsHelper4;
|
|
168
|
+
(_this$analyticsHelper4 = this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendProviderErrorEvent(mappedError);
|
|
165
169
|
this.emit('error', mappedError);
|
|
166
170
|
}
|
|
167
171
|
}
|
|
@@ -188,8 +192,8 @@ export class Provider extends Emitter {
|
|
|
188
192
|
try {
|
|
189
193
|
return await this.documentService.getCurrentState();
|
|
190
194
|
} catch (error) {
|
|
191
|
-
var _this$
|
|
192
|
-
(_this$
|
|
195
|
+
var _this$analyticsHelper5;
|
|
196
|
+
(_this$analyticsHelper5 = this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(error, 'Error while returning ADF version of current draft document');
|
|
193
197
|
throw new GetCurrentStateError('Error while returning the current state of the draft document', error); // Reject the promise so the consumer can react to it failing
|
|
194
198
|
}
|
|
195
199
|
});
|
|
@@ -202,8 +206,8 @@ export class Provider extends Emitter {
|
|
|
202
206
|
try {
|
|
203
207
|
return await this.documentService.getFinalAcknowledgedState();
|
|
204
208
|
} catch (error) {
|
|
205
|
-
var _this$
|
|
206
|
-
(_this$
|
|
209
|
+
var _this$analyticsHelper6;
|
|
210
|
+
(_this$analyticsHelper6 = this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(error, 'Error while returning ADF version of the final draft document');
|
|
207
211
|
throw new GetFinalAcknowledgedStateError('Error while returning the final acknowledged state of the draft document', error); // Reject the promise so the consumer can react to it failing
|
|
208
212
|
}
|
|
209
213
|
});
|
|
@@ -231,6 +235,9 @@ export class Provider extends Emitter {
|
|
|
231
235
|
_defineProperty(this, "getParticipants", () => {
|
|
232
236
|
return this.participantsService.getParticipants();
|
|
233
237
|
});
|
|
238
|
+
_defineProperty(this, "getAIProviderParticipants", () => {
|
|
239
|
+
return this.participantsService.getAIProviderParticipants();
|
|
240
|
+
});
|
|
234
241
|
_defineProperty(this, "getSessionId", () => {
|
|
235
242
|
return this.sessionId;
|
|
236
243
|
});
|
|
@@ -304,7 +311,7 @@ export class Provider extends Emitter {
|
|
|
304
311
|
clientId: this.clientId
|
|
305
312
|
});
|
|
306
313
|
if (this.isBufferingEnabled && this.initialDraft && !this.isProviderInitialized) {
|
|
307
|
-
var _this$
|
|
314
|
+
var _this$analyticsHelper7;
|
|
308
315
|
const {
|
|
309
316
|
document,
|
|
310
317
|
version,
|
|
@@ -315,7 +322,7 @@ export class Provider extends Emitter {
|
|
|
315
322
|
version,
|
|
316
323
|
metadata
|
|
317
324
|
});
|
|
318
|
-
(_this$
|
|
325
|
+
(_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendActionEvent(EVENT_ACTION.PROVIDER_INITIALIZED, EVENT_STATUS.INFO, {
|
|
319
326
|
isBuffered: true
|
|
320
327
|
});
|
|
321
328
|
}
|
|
@@ -324,8 +331,8 @@ export class Provider extends Emitter {
|
|
|
324
331
|
this.isChannelInitialized = true;
|
|
325
332
|
}
|
|
326
333
|
} catch (initError) {
|
|
327
|
-
var _this$
|
|
328
|
-
(_this$
|
|
334
|
+
var _this$analyticsHelper8;
|
|
335
|
+
(_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(initError, 'Error while initialising the provider');
|
|
329
336
|
// Throw error so consumers are aware the initialisation failed when initialising themselves
|
|
330
337
|
throw new ProviderInitialisationError('Provider initialisation error', initError);
|
|
331
338
|
}
|
|
@@ -342,8 +349,8 @@ export class Provider extends Emitter {
|
|
|
342
349
|
this.isChannelInitialized = true;
|
|
343
350
|
}
|
|
344
351
|
} catch (initError) {
|
|
345
|
-
var _this$
|
|
346
|
-
(_this$
|
|
352
|
+
var _this$analyticsHelper9;
|
|
353
|
+
(_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(initError, 'Error while initialising the provider');
|
|
347
354
|
// Throw error so consumers are aware the initialisation failed when initialising themselves
|
|
348
355
|
throw new ProviderInitialisationError('Provider initialisation error', initError);
|
|
349
356
|
}
|
|
@@ -351,9 +358,9 @@ export class Provider extends Emitter {
|
|
|
351
358
|
}
|
|
352
359
|
checkForCookies() {
|
|
353
360
|
if (!global.navigator.cookieEnabled) {
|
|
354
|
-
var _this$
|
|
361
|
+
var _this$analyticsHelper10;
|
|
355
362
|
const initError = new ProviderInitialisationError('Cookies are not enabled. Please enable cookies to use collaborative editing.');
|
|
356
|
-
(_this$
|
|
363
|
+
(_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(initError, 'Error while initialising the provider - cookies disabled');
|
|
357
364
|
throw new ProviderInitialisationError('Provider initialisation error - cookies disabled', initError);
|
|
358
365
|
}
|
|
359
366
|
}
|
|
@@ -368,14 +375,14 @@ export class Provider extends Emitter {
|
|
|
368
375
|
send(_tr, _oldState, newState) {
|
|
369
376
|
try {
|
|
370
377
|
if (this.isViewOnly()) {
|
|
371
|
-
var _this$
|
|
378
|
+
var _this$analyticsHelper11;
|
|
372
379
|
const error = {
|
|
373
380
|
message: 'Attempted to send steps in view only mode',
|
|
374
381
|
data: {
|
|
375
382
|
code: INTERNAL_ERROR_CODE.VIEW_ONLY_STEPS_ERROR
|
|
376
383
|
}
|
|
377
384
|
};
|
|
378
|
-
(_this$
|
|
385
|
+
(_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(error, error.message);
|
|
379
386
|
return;
|
|
380
387
|
}
|
|
381
388
|
// Don't send steps while the document is locked (eg. when restoring the document)
|
|
@@ -385,8 +392,8 @@ export class Provider extends Emitter {
|
|
|
385
392
|
}
|
|
386
393
|
this.documentService.send(_tr, _oldState, newState);
|
|
387
394
|
} catch (error) {
|
|
388
|
-
var _this$
|
|
389
|
-
(_this$
|
|
395
|
+
var _this$analyticsHelper12;
|
|
396
|
+
(_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, 'Error while sending steps for a transaction');
|
|
390
397
|
throw new SendTransactionError('Error while sending steps for a transaction', error);
|
|
391
398
|
}
|
|
392
399
|
}
|
|
@@ -397,8 +404,11 @@ export class Provider extends Emitter {
|
|
|
397
404
|
}
|
|
398
405
|
|
|
399
406
|
/**
|
|
400
|
-
* Send messages, such as telepointers, to NCS and other participants.
|
|
407
|
+
* Send messages, such as telepointers, and AI provider changes to NCS and other participants.
|
|
408
|
+
* Only used for telepointer data (text and node selections) in the editor and JWM.
|
|
409
|
+
* JWM does some weird serialisation stuff on the node selections.
|
|
401
410
|
* Silently fails if an error occurs, since Presence isn't a critical functionality and self-restores over time.
|
|
411
|
+
*
|
|
402
412
|
* @param {CollabTelepointerPayload} data Data you want to send to NCS / the other participants
|
|
403
413
|
* @param {string} data.type Can only be 'telepointer' for now, we don't support anything else yet
|
|
404
414
|
* @param {CollabSendableSelection} data.selection Object representing the selected element
|
|
@@ -422,11 +432,16 @@ export class Provider extends Emitter {
|
|
|
422
432
|
...basePayload,
|
|
423
433
|
activity: data.activity
|
|
424
434
|
}, activityCallback());
|
|
435
|
+
} else if ((data === null || data === void 0 ? void 0 : data.type) === 'ai-provider:change') {
|
|
436
|
+
this.participantsService.sendAIProviderChanged({
|
|
437
|
+
...basePayload,
|
|
438
|
+
...data
|
|
439
|
+
});
|
|
425
440
|
}
|
|
426
441
|
} catch (error) {
|
|
427
|
-
var _this$
|
|
442
|
+
var _this$analyticsHelper13;
|
|
428
443
|
// We don't want to throw errors for Presence features as they tend to self-restore
|
|
429
|
-
(_this$
|
|
444
|
+
(_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 ? void 0 : _this$analyticsHelper13.sendErrorEvent(error, 'Error while sending message - telepointer');
|
|
430
445
|
}
|
|
431
446
|
}
|
|
432
447
|
/**
|
|
@@ -462,8 +477,8 @@ export class Provider extends Emitter {
|
|
|
462
477
|
this.sendStepsTimer = undefined;
|
|
463
478
|
}
|
|
464
479
|
} catch (error) {
|
|
465
|
-
var _this$
|
|
466
|
-
(_this$
|
|
480
|
+
var _this$analyticsHelper14;
|
|
481
|
+
(_this$analyticsHelper14 = this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 ? void 0 : _this$analyticsHelper14.sendErrorEvent(error, 'Error while shutting down the collab provider');
|
|
467
482
|
throw new DestroyError('Error while shutting down the collab provider', error);
|
|
468
483
|
}
|
|
469
484
|
this.clearTimers();
|
|
@@ -484,8 +499,8 @@ export class Provider extends Emitter {
|
|
|
484
499
|
}
|
|
485
500
|
this.metadataService.setTitle(title, broadcast);
|
|
486
501
|
} catch (error) {
|
|
487
|
-
var _this$
|
|
488
|
-
(_this$
|
|
502
|
+
var _this$analyticsHelper15;
|
|
503
|
+
(_this$analyticsHelper15 = this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 ? void 0 : _this$analyticsHelper15.sendErrorEvent(error, 'Error while setting title');
|
|
489
504
|
throw new SetTitleError('Error while setting title', error);
|
|
490
505
|
}
|
|
491
506
|
}
|
|
@@ -501,8 +516,8 @@ export class Provider extends Emitter {
|
|
|
501
516
|
try {
|
|
502
517
|
this.metadataService.setEditorWidth(editorWidth, broadcast);
|
|
503
518
|
} catch (error) {
|
|
504
|
-
var _this$
|
|
505
|
-
(_this$
|
|
519
|
+
var _this$analyticsHelper16;
|
|
520
|
+
(_this$analyticsHelper16 = this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 ? void 0 : _this$analyticsHelper16.sendErrorEvent(error, 'Error while setting editor width');
|
|
506
521
|
throw new SetEditorWidthError('Error while setting editor width', error);
|
|
507
522
|
}
|
|
508
523
|
}
|
|
@@ -519,8 +534,8 @@ export class Provider extends Emitter {
|
|
|
519
534
|
}
|
|
520
535
|
this.metadataService.setMetadata(metadata);
|
|
521
536
|
} catch (error) {
|
|
522
|
-
var _this$
|
|
523
|
-
(_this$
|
|
537
|
+
var _this$analyticsHelper17;
|
|
538
|
+
(_this$analyticsHelper17 = this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 ? void 0 : _this$analyticsHelper17.sendErrorEvent(error, 'Error while setting metadata');
|
|
524
539
|
throw new SetMetadataError('Error while setting metadata', error);
|
|
525
540
|
}
|
|
526
541
|
}
|
package/dist/es2019/types.js
CHANGED
|
@@ -16,6 +16,7 @@ export var EVENT_ACTION = /*#__PURE__*/function (EVENT_ACTION) {
|
|
|
16
16
|
EVENT_ACTION["DROPPED_STEPS"] = "droppedStepInCatchup";
|
|
17
17
|
EVENT_ACTION["WEBSOCKET_MESSAGE_VOLUME_METRIC"] = "websocketMessageVolumeMetric";
|
|
18
18
|
EVENT_ACTION["PROVIDER_INITIALIZED"] = "providerInitialized";
|
|
19
|
+
EVENT_ACTION["RECONNECTION"] = "providerReconnection";
|
|
19
20
|
EVENT_ACTION["PROVIDER_SETUP"] = "providerSetup";
|
|
20
21
|
EVENT_ACTION["HAS_UNCONFIRMED_STEPS"] = "hasUnconfirmedSteps";
|
|
21
22
|
return EVENT_ACTION;
|
|
@@ -13,6 +13,9 @@ export function sleep(ms) {
|
|
|
13
13
|
setTimeout(resolve, ms);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
+
export var isAIProviderID = function isAIProviderID(id) {
|
|
17
|
+
return typeof id === 'string' && id.startsWith('agent:');
|
|
18
|
+
};
|
|
16
19
|
export var getProduct = function getProduct(productInfo) {
|
|
17
20
|
var _productInfo$product;
|
|
18
21
|
return (_productInfo$product = productInfo === null || productInfo === void 0 ? void 0 : productInfo.product) !== null && _productInfo$product !== void 0 ? _productInfo$product : 'unknown';
|
package/dist/esm/index.js
CHANGED
|
@@ -8,9 +8,10 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
8
8
|
import { disconnectedReasonMapper } from '../disconnected-reason-mapper';
|
|
9
9
|
import { EVENT_ACTION, EVENT_STATUS } from '../helpers/const';
|
|
10
10
|
import { telepointerFromStep } from './telepointers-helper';
|
|
11
|
+
import FeatureGates from '@atlaskit/feature-gate-js-client';
|
|
11
12
|
import { createParticipantFromPayload as enrichParticipant, PARTICIPANT_UPDATE_INTERVAL } from './participants-helper';
|
|
12
13
|
import { ParticipantsState } from './participants-state';
|
|
13
|
-
import { createLogger } from '../helpers/utils';
|
|
14
|
+
import { createLogger, isAIProviderID } from '../helpers/utils';
|
|
14
15
|
var logger = createLogger('PresenceService', 'pink');
|
|
15
16
|
var SEND_PRESENCE_INTERVAL = 150 * 1000; // 150 seconds
|
|
16
17
|
|
|
@@ -34,6 +35,28 @@ export var ParticipantsService = /*#__PURE__*/function () {
|
|
|
34
35
|
var getPresenceData = arguments.length > 6 ? arguments[6] : undefined;
|
|
35
36
|
var setUserId = arguments.length > 7 ? arguments[7] : undefined;
|
|
36
37
|
_classCallCheck(this, ParticipantsService);
|
|
38
|
+
_defineProperty(this, "sendAIProviderChanged", function (payload) {
|
|
39
|
+
var isFacepileExperimentEnabled = FeatureGates.getExperimentValue('platform_editor_ai_facepile', 'isEnabled', false);
|
|
40
|
+
if (isFacepileExperimentEnabled && payload.providerId) {
|
|
41
|
+
for (var propKey in payload.permit) {
|
|
42
|
+
if (payload.permit.hasOwnProperty(propKey)) {
|
|
43
|
+
payload.permit[propKey] = false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
var presencePayload = {
|
|
47
|
+
sessionId: "".concat(payload.providerId, "::").concat(payload.sessionId),
|
|
48
|
+
userId: payload.providerId,
|
|
49
|
+
clientId: "".concat(payload.providerId, "::").concat(payload.clientId),
|
|
50
|
+
permit: payload.permit,
|
|
51
|
+
timestamp: Date.now()
|
|
52
|
+
};
|
|
53
|
+
if (payload.action === 'add') {
|
|
54
|
+
_this.channelBroadcast('participant:updated', presencePayload);
|
|
55
|
+
} else if (payload.action === 'remove') {
|
|
56
|
+
_this.channelBroadcast('participant:left', presencePayload);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
37
60
|
/**
|
|
38
61
|
* Carries out 3 things: 1) enriches the participant with user data, 2) updates the participantsState, 3) emits the presence event
|
|
39
62
|
* @param payload Payload from incoming socket event
|
|
@@ -99,8 +122,31 @@ export var ParticipantsService = /*#__PURE__*/function () {
|
|
|
99
122
|
* Called when a participant leaves the session.
|
|
100
123
|
* We emit the `presence` event to update the active avatars in the editor.
|
|
101
124
|
*/
|
|
102
|
-
_defineProperty(this, "onParticipantLeft", function (
|
|
103
|
-
var sessionId =
|
|
125
|
+
_defineProperty(this, "onParticipantLeft", function (payload) {
|
|
126
|
+
var sessionId = payload.sessionId;
|
|
127
|
+
var isFacepileExperimentEnabled = FeatureGates.getExperimentValue('platform_editor_ai_facepile', 'isEnabled', false);
|
|
128
|
+
if (isFacepileExperimentEnabled) {
|
|
129
|
+
var _payload$data;
|
|
130
|
+
// When an agent leaves a session, the backend service returns the original user's
|
|
131
|
+
// session ID accompanied by a payload containing the agent's session ID.
|
|
132
|
+
// If the user session leaves, we also want to remove all agent sessions associated.
|
|
133
|
+
if (payload !== null && payload !== void 0 && (_payload$data = payload.data) !== null && _payload$data !== void 0 && _payload$data.sessionId && isAIProviderID(payload.data.sessionId)) {
|
|
134
|
+
sessionId = payload.data.sessionId;
|
|
135
|
+
} else {
|
|
136
|
+
var associatedAgents = _this.getAIProviderParticipants().filter(function (ap) {
|
|
137
|
+
return ap.sessionId.endsWith(sessionId);
|
|
138
|
+
});
|
|
139
|
+
associatedAgents.forEach(function (agent) {
|
|
140
|
+
_this.onParticipantLeft({
|
|
141
|
+
sessionId: sessionId,
|
|
142
|
+
timestamp: payload.timestamp,
|
|
143
|
+
data: agent,
|
|
144
|
+
userId: undefined,
|
|
145
|
+
clientId: ''
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
104
150
|
_this.participantsState.removeBySessionId(sessionId);
|
|
105
151
|
_this.emitPresence({
|
|
106
152
|
left: [{
|
|
@@ -311,6 +357,9 @@ export var ParticipantsService = /*#__PURE__*/function () {
|
|
|
311
357
|
_defineProperty(this, "getParticipants", function () {
|
|
312
358
|
return _this.participantsState.getParticipants();
|
|
313
359
|
});
|
|
360
|
+
_defineProperty(this, "getAIProviderParticipants", function () {
|
|
361
|
+
return _this.participantsState.getAIProviderParticipants();
|
|
362
|
+
});
|
|
314
363
|
this.analyticsHelper = analyticsHelper;
|
|
315
364
|
this.participantsState = participantsState;
|
|
316
365
|
this.emit = emit;
|
|
@@ -4,6 +4,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
|
4
4
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
import { isAIProviderID } from '../helpers/utils';
|
|
7
8
|
export var ParticipantsState = /*#__PURE__*/_createClass(function ParticipantsState() {
|
|
8
9
|
var _this = this;
|
|
9
10
|
var baseParticipants = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Map();
|
|
@@ -19,7 +20,19 @@ export var ParticipantsState = /*#__PURE__*/_createClass(function ParticipantsSt
|
|
|
19
20
|
_defineProperty(this, "getParticipants", function () {
|
|
20
21
|
return (
|
|
21
22
|
// Spread to get deep copy
|
|
22
|
-
_toConsumableArray(_this.participants.values()).
|
|
23
|
+
_toConsumableArray(_this.participants.values()).filter(function (p) {
|
|
24
|
+
return !isAIProviderID(p.userId);
|
|
25
|
+
}).map(function (p) {
|
|
26
|
+
return _objectSpread({}, p);
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
});
|
|
30
|
+
_defineProperty(this, "getAIProviderParticipants", function () {
|
|
31
|
+
return (
|
|
32
|
+
// Spread to get deep copy
|
|
33
|
+
_toConsumableArray(_this.participants.values()).filter(function (p) {
|
|
34
|
+
return isAIProviderID(p.userId);
|
|
35
|
+
}).map(function (p) {
|
|
23
36
|
return _objectSpread({}, p);
|
|
24
37
|
})
|
|
25
38
|
);
|
|
@@ -129,6 +129,10 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
129
129
|
if (initialized && _this.disconnectedAt &&
|
|
130
130
|
// Offline longer than `OUT_OF_SYNC_PERIOD`
|
|
131
131
|
Date.now() - _this.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
|
|
132
|
+
var _this$analyticsHelper2;
|
|
133
|
+
(_this$analyticsHelper2 = _this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 || _this$analyticsHelper2.sendActionEvent(EVENT_ACTION.RECONNECTION, EVENT_STATUS.INFO, {
|
|
134
|
+
disconnectionPeriodSeconds: Math.floor((Date.now() - _this.disconnectedAt) / 1000)
|
|
135
|
+
});
|
|
132
136
|
_this.documentService.throttledCatchupv2(CatchupEventReason.RECONNECTED);
|
|
133
137
|
}
|
|
134
138
|
_this.participantsService.startInactiveRemover(_this.sessionId);
|
|
@@ -172,13 +176,13 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
172
176
|
if (((_error$data = error.data) === null || _error$data === void 0 ? void 0 : _error$data.code) === NCS_ERROR_CODE.HEAD_VERSION_UPDATE_FAILED || ((_error$data2 = error.data) === null || _error$data2 === void 0 ? void 0 : _error$data2.code) === NCS_ERROR_CODE.VERSION_NUMBER_ALREADY_EXISTS) {
|
|
173
177
|
_this.documentService.onStepRejectedError();
|
|
174
178
|
} else {
|
|
175
|
-
var _this$
|
|
176
|
-
(_this$
|
|
179
|
+
var _this$analyticsHelper3;
|
|
180
|
+
(_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 || _this$analyticsHelper3.sendErrorEvent(error, 'Error handled');
|
|
177
181
|
var mappedError = errorCodeMapper(error);
|
|
178
182
|
// Only emit errors to Confluence very intentionally because they will disconnect the collab provider
|
|
179
183
|
if (mappedError) {
|
|
180
|
-
var _this$
|
|
181
|
-
(_this$
|
|
184
|
+
var _this$analyticsHelper4;
|
|
185
|
+
(_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 || _this$analyticsHelper4.sendProviderErrorEvent(mappedError);
|
|
182
186
|
_this.emit('error', mappedError);
|
|
183
187
|
}
|
|
184
188
|
}
|
|
@@ -201,7 +205,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
201
205
|
* @throws {GetCurrentStateError} Something went wrong while returning the current state
|
|
202
206
|
*/
|
|
203
207
|
_defineProperty(_assertThisInitialized(_this), "getCurrentState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
204
|
-
var _this$
|
|
208
|
+
var _this$analyticsHelper5;
|
|
205
209
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
206
210
|
while (1) switch (_context.prev = _context.next) {
|
|
207
211
|
case 0:
|
|
@@ -213,7 +217,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
213
217
|
case 6:
|
|
214
218
|
_context.prev = 6;
|
|
215
219
|
_context.t0 = _context["catch"](0);
|
|
216
|
-
(_this$
|
|
220
|
+
(_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 || _this$analyticsHelper5.sendErrorEvent(_context.t0, 'Error while returning ADF version of current draft document');
|
|
217
221
|
throw new GetCurrentStateError('Error while returning the current state of the draft document', _context.t0);
|
|
218
222
|
case 10:
|
|
219
223
|
case "end":
|
|
@@ -227,7 +231,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
227
231
|
* @throws {GetFinalAcknowledgedStateError} Something went wrong while returning the acknowledged state
|
|
228
232
|
*/
|
|
229
233
|
_defineProperty(_assertThisInitialized(_this), "getFinalAcknowledgedState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
230
|
-
var _this$
|
|
234
|
+
var _this$analyticsHelper6;
|
|
231
235
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
232
236
|
while (1) switch (_context2.prev = _context2.next) {
|
|
233
237
|
case 0:
|
|
@@ -239,7 +243,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
239
243
|
case 6:
|
|
240
244
|
_context2.prev = 6;
|
|
241
245
|
_context2.t0 = _context2["catch"](0);
|
|
242
|
-
(_this$
|
|
246
|
+
(_this$analyticsHelper6 = _this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 || _this$analyticsHelper6.sendErrorEvent(_context2.t0, 'Error while returning ADF version of the final draft document');
|
|
243
247
|
throw new GetFinalAcknowledgedStateError('Error while returning the final acknowledged state of the draft document', _context2.t0);
|
|
244
248
|
case 10:
|
|
245
249
|
case "end":
|
|
@@ -271,6 +275,9 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
271
275
|
_defineProperty(_assertThisInitialized(_this), "getParticipants", function () {
|
|
272
276
|
return _this.participantsService.getParticipants();
|
|
273
277
|
});
|
|
278
|
+
_defineProperty(_assertThisInitialized(_this), "getAIProviderParticipants", function () {
|
|
279
|
+
return _this.participantsService.getAIProviderParticipants();
|
|
280
|
+
});
|
|
274
281
|
_defineProperty(_assertThisInitialized(_this), "getSessionId", function () {
|
|
275
282
|
return _this.sessionId;
|
|
276
283
|
});
|
|
@@ -353,7 +360,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
353
360
|
clientId: this.clientId
|
|
354
361
|
});
|
|
355
362
|
if (this.isBufferingEnabled && this.initialDraft && !this.isProviderInitialized) {
|
|
356
|
-
var _this$
|
|
363
|
+
var _this$analyticsHelper7;
|
|
357
364
|
var _this$initialDraft2 = this.initialDraft,
|
|
358
365
|
document = _this$initialDraft2.document,
|
|
359
366
|
version = _this$initialDraft2.version,
|
|
@@ -363,7 +370,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
363
370
|
version: version,
|
|
364
371
|
metadata: metadata
|
|
365
372
|
});
|
|
366
|
-
(_this$
|
|
373
|
+
(_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 || _this$analyticsHelper7.sendActionEvent(EVENT_ACTION.PROVIDER_INITIALIZED, EVENT_STATUS.INFO, {
|
|
367
374
|
isBuffered: true
|
|
368
375
|
});
|
|
369
376
|
}
|
|
@@ -372,8 +379,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
372
379
|
this.isChannelInitialized = true;
|
|
373
380
|
}
|
|
374
381
|
} catch (initError) {
|
|
375
|
-
var _this$
|
|
376
|
-
(_this$
|
|
382
|
+
var _this$analyticsHelper8;
|
|
383
|
+
(_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 || _this$analyticsHelper8.sendErrorEvent(initError, 'Error while initialising the provider');
|
|
377
384
|
// Throw error so consumers are aware the initialisation failed when initialising themselves
|
|
378
385
|
throw new ProviderInitialisationError('Provider initialisation error', initError);
|
|
379
386
|
}
|
|
@@ -392,8 +399,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
392
399
|
this.isChannelInitialized = true;
|
|
393
400
|
}
|
|
394
401
|
} catch (initError) {
|
|
395
|
-
var _this$
|
|
396
|
-
(_this$
|
|
402
|
+
var _this$analyticsHelper9;
|
|
403
|
+
(_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 || _this$analyticsHelper9.sendErrorEvent(initError, 'Error while initialising the provider');
|
|
397
404
|
// Throw error so consumers are aware the initialisation failed when initialising themselves
|
|
398
405
|
throw new ProviderInitialisationError('Provider initialisation error', initError);
|
|
399
406
|
}
|
|
@@ -403,9 +410,9 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
403
410
|
key: "checkForCookies",
|
|
404
411
|
value: function checkForCookies() {
|
|
405
412
|
if (!global.navigator.cookieEnabled) {
|
|
406
|
-
var _this$
|
|
413
|
+
var _this$analyticsHelper10;
|
|
407
414
|
var initError = new ProviderInitialisationError('Cookies are not enabled. Please enable cookies to use collaborative editing.');
|
|
408
|
-
(_this$
|
|
415
|
+
(_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 || _this$analyticsHelper10.sendErrorEvent(initError, 'Error while initialising the provider - cookies disabled');
|
|
409
416
|
throw new ProviderInitialisationError('Provider initialisation error - cookies disabled', initError);
|
|
410
417
|
}
|
|
411
418
|
}
|
|
@@ -422,14 +429,14 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
422
429
|
value: function send(_tr, _oldState, newState) {
|
|
423
430
|
try {
|
|
424
431
|
if (this.isViewOnly()) {
|
|
425
|
-
var _this$
|
|
432
|
+
var _this$analyticsHelper11;
|
|
426
433
|
var error = {
|
|
427
434
|
message: 'Attempted to send steps in view only mode',
|
|
428
435
|
data: {
|
|
429
436
|
code: INTERNAL_ERROR_CODE.VIEW_ONLY_STEPS_ERROR
|
|
430
437
|
}
|
|
431
438
|
};
|
|
432
|
-
(_this$
|
|
439
|
+
(_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 || _this$analyticsHelper11.sendErrorEvent(error, error.message);
|
|
433
440
|
return;
|
|
434
441
|
}
|
|
435
442
|
// Don't send steps while the document is locked (eg. when restoring the document)
|
|
@@ -439,8 +446,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
439
446
|
}
|
|
440
447
|
this.documentService.send(_tr, _oldState, newState);
|
|
441
448
|
} catch (error) {
|
|
442
|
-
var _this$
|
|
443
|
-
(_this$
|
|
449
|
+
var _this$analyticsHelper12;
|
|
450
|
+
(_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 || _this$analyticsHelper12.sendErrorEvent(error, 'Error while sending steps for a transaction');
|
|
444
451
|
throw new SendTransactionError('Error while sending steps for a transaction', error);
|
|
445
452
|
}
|
|
446
453
|
}
|
|
@@ -453,8 +460,11 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
453
460
|
}
|
|
454
461
|
|
|
455
462
|
/**
|
|
456
|
-
* Send messages, such as telepointers, to NCS and other participants.
|
|
463
|
+
* Send messages, such as telepointers, and AI provider changes to NCS and other participants.
|
|
464
|
+
* Only used for telepointer data (text and node selections) in the editor and JWM.
|
|
465
|
+
* JWM does some weird serialisation stuff on the node selections.
|
|
457
466
|
* Silently fails if an error occurs, since Presence isn't a critical functionality and self-restores over time.
|
|
467
|
+
*
|
|
458
468
|
* @param {CollabTelepointerPayload} data Data you want to send to NCS / the other participants
|
|
459
469
|
* @param {string} data.type Can only be 'telepointer' for now, we don't support anything else yet
|
|
460
470
|
* @param {CollabSendableSelection} data.selection Object representing the selected element
|
|
@@ -478,11 +488,13 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
478
488
|
this.channel.broadcast((data === null || data === void 0 ? void 0 : data.type) === 'activity:join' ? 'participant:activity-join' : 'participant:activity-ack', _objectSpread(_objectSpread({}, basePayload), {}, {
|
|
479
489
|
activity: data.activity
|
|
480
490
|
}), activityCallback());
|
|
491
|
+
} else if ((data === null || data === void 0 ? void 0 : data.type) === 'ai-provider:change') {
|
|
492
|
+
this.participantsService.sendAIProviderChanged(_objectSpread(_objectSpread({}, basePayload), data));
|
|
481
493
|
}
|
|
482
494
|
} catch (error) {
|
|
483
|
-
var _this$
|
|
495
|
+
var _this$analyticsHelper13;
|
|
484
496
|
// We don't want to throw errors for Presence features as they tend to self-restore
|
|
485
|
-
(_this$
|
|
497
|
+
(_this$analyticsHelper13 = this.analyticsHelper) === null || _this$analyticsHelper13 === void 0 || _this$analyticsHelper13.sendErrorEvent(error, 'Error while sending message - telepointer');
|
|
486
498
|
}
|
|
487
499
|
}
|
|
488
500
|
}, {
|
|
@@ -525,8 +537,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
525
537
|
this.sendStepsTimer = undefined;
|
|
526
538
|
}
|
|
527
539
|
} catch (error) {
|
|
528
|
-
var _this$
|
|
529
|
-
(_this$
|
|
540
|
+
var _this$analyticsHelper14;
|
|
541
|
+
(_this$analyticsHelper14 = this.analyticsHelper) === null || _this$analyticsHelper14 === void 0 || _this$analyticsHelper14.sendErrorEvent(error, 'Error while shutting down the collab provider');
|
|
530
542
|
throw new DestroyError('Error while shutting down the collab provider', error);
|
|
531
543
|
}
|
|
532
544
|
this.clearTimers();
|
|
@@ -549,8 +561,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
549
561
|
}
|
|
550
562
|
this.metadataService.setTitle(title, broadcast);
|
|
551
563
|
} catch (error) {
|
|
552
|
-
var _this$
|
|
553
|
-
(_this$
|
|
564
|
+
var _this$analyticsHelper15;
|
|
565
|
+
(_this$analyticsHelper15 = this.analyticsHelper) === null || _this$analyticsHelper15 === void 0 || _this$analyticsHelper15.sendErrorEvent(error, 'Error while setting title');
|
|
554
566
|
throw new SetTitleError('Error while setting title', error);
|
|
555
567
|
}
|
|
556
568
|
}
|
|
@@ -568,8 +580,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
568
580
|
try {
|
|
569
581
|
this.metadataService.setEditorWidth(editorWidth, broadcast);
|
|
570
582
|
} catch (error) {
|
|
571
|
-
var _this$
|
|
572
|
-
(_this$
|
|
583
|
+
var _this$analyticsHelper16;
|
|
584
|
+
(_this$analyticsHelper16 = this.analyticsHelper) === null || _this$analyticsHelper16 === void 0 || _this$analyticsHelper16.sendErrorEvent(error, 'Error while setting editor width');
|
|
573
585
|
throw new SetEditorWidthError('Error while setting editor width', error);
|
|
574
586
|
}
|
|
575
587
|
}
|
|
@@ -588,8 +600,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
588
600
|
}
|
|
589
601
|
this.metadataService.setMetadata(metadata);
|
|
590
602
|
} catch (error) {
|
|
591
|
-
var _this$
|
|
592
|
-
(_this$
|
|
603
|
+
var _this$analyticsHelper17;
|
|
604
|
+
(_this$analyticsHelper17 = this.analyticsHelper) === null || _this$analyticsHelper17 === void 0 || _this$analyticsHelper17.sendErrorEvent(error, 'Error while setting metadata');
|
|
593
605
|
throw new SetMetadataError('Error while setting metadata', error);
|
|
594
606
|
}
|
|
595
607
|
}
|
package/dist/esm/types.js
CHANGED