@atlaskit/collab-provider 8.8.1 → 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.
- package/CHANGELOG.md +21 -0
- package/dist/cjs/analytics/analytics-helper.js +21 -12
- package/dist/cjs/channel.js +5 -3
- package/dist/cjs/document/document-service.js +1 -1
- package/dist/cjs/errors/error-code-mapper.js +9 -2
- package/dist/cjs/namespace/namespace-service.js +77 -0
- package/dist/cjs/participants/participants-helper.js +2 -0
- package/dist/cjs/participants/participants-service.js +94 -30
- package/dist/cjs/provider/index.js +91 -173
- package/dist/cjs/version-wrapper.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/analytics/analytics-helper.js +21 -12
- package/dist/es2019/channel.js +5 -3
- package/dist/es2019/document/document-service.js +1 -1
- package/dist/es2019/errors/error-code-mapper.js +9 -2
- package/dist/es2019/namespace/namespace-service.js +48 -0
- package/dist/es2019/participants/participants-helper.js +2 -0
- package/dist/es2019/participants/participants-service.js +88 -30
- package/dist/es2019/provider/index.js +82 -145
- package/dist/es2019/version-wrapper.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/analytics/analytics-helper.js +21 -12
- package/dist/esm/channel.js +5 -3
- package/dist/esm/document/document-service.js +1 -1
- package/dist/esm/errors/error-code-mapper.js +9 -2
- package/dist/esm/namespace/namespace-service.js +69 -0
- package/dist/esm/participants/participants-helper.js +2 -0
- package/dist/esm/participants/participants-service.js +94 -30
- package/dist/esm/provider/index.js +91 -173
- package/dist/esm/version-wrapper.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/channel.d.ts +1 -1
- package/dist/types/errors/error-types.d.ts +37 -37
- package/dist/types/feature-flags/types.d.ts +4 -4
- package/dist/types/helpers/const.d.ts +19 -19
- package/dist/types/helpers/utils.d.ts +2 -2
- package/dist/types/metadata/metadata-service.d.ts +1 -1
- package/dist/types/namespace/namespace-service.d.ts +14 -0
- package/dist/types/participants/participants-helper.d.ts +5 -7
- package/dist/types/participants/participants-service.d.ts +40 -16
- package/dist/types/provider/commit-step.d.ts +2 -2
- package/dist/types/provider/index.d.ts +21 -37
- package/dist/types/types.d.ts +28 -28
- package/dist/{types-ts4.0 → types-ts4.5}/channel.d.ts +1 -1
- package/dist/{types-ts4.0 → types-ts4.5}/errors/error-types.d.ts +37 -37
- package/dist/types-ts4.5/feature-flags/types.d.ts +13 -0
- package/dist/{types-ts4.0 → types-ts4.5}/helpers/const.d.ts +19 -19
- package/dist/{types-ts4.0 → types-ts4.5}/helpers/utils.d.ts +2 -2
- package/dist/{types-ts4.0 → types-ts4.5}/metadata/metadata-service.d.ts +1 -1
- package/dist/types-ts4.5/namespace/namespace-service.d.ts +14 -0
- package/dist/types-ts4.5/participants/participants-helper.d.ts +12 -0
- package/dist/types-ts4.5/participants/participants-service.d.ts +94 -0
- package/dist/{types-ts4.0 → types-ts4.5}/provider/commit-step.d.ts +2 -2
- package/dist/{types-ts4.0 → types-ts4.5}/provider/index.d.ts +21 -37
- package/dist/{types-ts4.0 → types-ts4.5}/types.d.ts +28 -28
- package/package.json +13 -5
- package/report.api.md +4 -2
- package/socket-io-provider/package.json +2 -2
- package/types/package.json +2 -2
- package/version-wrapper/package.json +2 -2
- package/dist/types-ts4.0/feature-flags/types.d.ts +0 -13
- package/dist/types-ts4.0/participants/participants-helper.d.ts +0 -14
- package/dist/types-ts4.0/participants/participants-service.d.ts +0 -70
- /package/dist/{types-ts4.0 → types-ts4.5}/analytics/analytics-helper.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/analytics/performance.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/analytics/ufo.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/config.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/connectivity/network.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/connectivity/reconnect-helper.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/connectivity/singleton.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/disconnected-reason-mapper.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/document/catchup.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/document/document-service.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/document/step-queue-state.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/emitter.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/errors/error-code-mapper.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/feature-flags/__test__/index.unit.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/feature-flags/index.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/index.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/participants/participants-state.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/participants/telepointers-helper.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/socket-io-provider.d.ts +0 -0
- /package/dist/{types-ts4.0 → types-ts4.5}/version-wrapper.d.ts +0 -0
|
@@ -15,14 +15,13 @@ import { Channel } from '../channel';
|
|
|
15
15
|
import { createLogger } from '../helpers/utils';
|
|
16
16
|
import AnalyticsHelper from '../analytics/analytics-helper';
|
|
17
17
|
import { telepointerCallback } from '../participants/telepointers-helper';
|
|
18
|
-
import { ParticipantsService } from '../participants/participants-service';
|
|
19
18
|
import { DestroyError, GetCurrentStateError, GetFinalAcknowledgedStateError, ProviderInitialisationError, SendTransactionError, SetEditorWidthError, SetMetadataError, SetTitleError, NCS_ERROR_CODE } from '../errors/error-types';
|
|
20
19
|
import { MetadataService } from '../metadata/metadata-service';
|
|
21
20
|
import { DocumentService } from '../document/document-service';
|
|
21
|
+
import { NamespaceService } from '../namespace/namespace-service';
|
|
22
|
+
import { ParticipantsService } from '../participants/participants-service';
|
|
22
23
|
import { errorCodeMapper } from '../errors/error-code-mapper';
|
|
23
24
|
var logger = createLogger('Provider', 'black');
|
|
24
|
-
var SEND_PRESENCE_INTERVAL = 150 * 1000; // 150 seconds
|
|
25
|
-
|
|
26
25
|
var OUT_OF_SYNC_PERIOD = 3 * 1000; // 3 seconds
|
|
27
26
|
|
|
28
27
|
export var MAX_STEP_REJECTED_ERROR = 15;
|
|
@@ -35,10 +34,25 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
35
34
|
_this = _super.call(this);
|
|
36
35
|
_defineProperty(_assertThisInitialized(_this), "isChannelInitialized", false);
|
|
37
36
|
_defineProperty(_assertThisInitialized(_this), "isProviderInitialized", false);
|
|
38
|
-
//
|
|
39
|
-
|
|
37
|
+
// isPreinitializating acts as a feature flag to determine when the provider has been initialized early
|
|
38
|
+
// and also contains the initial draft
|
|
39
|
+
_defineProperty(_assertThisInitialized(_this), "isPreinitializing", false);
|
|
40
|
+
/**
|
|
41
|
+
* Wrapper for this.emit, it binds scope for callbacks and waits for initialising of the editor before emitting events.
|
|
42
|
+
* Waiting for the collab provider to become connected to the editor ensures the editor doesn't miss any events.
|
|
43
|
+
* @param evt - Event name to emit to subscribers
|
|
44
|
+
* @param data - Event data to emit to subscribers
|
|
45
|
+
*/
|
|
40
46
|
_defineProperty(_assertThisInitialized(_this), "emitCallback", function (evt, data) {
|
|
41
|
-
|
|
47
|
+
// When the provider is initialized early, we want the editor state promise to resolve before emitting events
|
|
48
|
+
// to ensure that it is ready to listen to the events fired by NCS
|
|
49
|
+
if (_this.isPreinitializing) {
|
|
50
|
+
_this.getStatePromise.then(function () {
|
|
51
|
+
return _this.emit(evt, data);
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
_this.emit(evt, data);
|
|
55
|
+
}
|
|
42
56
|
});
|
|
43
57
|
_defineProperty(_assertThisInitialized(_this), "initializeChannel", function () {
|
|
44
58
|
_this.emit('connecting', {
|
|
@@ -49,7 +63,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
49
63
|
var sid = _ref.sid,
|
|
50
64
|
initialized = _ref.initialized;
|
|
51
65
|
_this.sessionId = sid;
|
|
52
|
-
_this.
|
|
66
|
+
_this.emitCallback('connected', {
|
|
53
67
|
sid: sid,
|
|
54
68
|
initial: !initialized
|
|
55
69
|
});
|
|
@@ -75,7 +89,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
75
89
|
Date.now() - _this.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
|
|
76
90
|
_this.documentService.throttledCatchup();
|
|
77
91
|
}
|
|
78
|
-
_this.startInactiveRemover();
|
|
92
|
+
_this.participantsService.startInactiveRemover(_this.sessionId);
|
|
79
93
|
_this.disconnectedAt = undefined;
|
|
80
94
|
}).on('init', function (_ref2) {
|
|
81
95
|
var doc = _ref2.doc,
|
|
@@ -88,7 +102,10 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
88
102
|
metadata: metadata
|
|
89
103
|
});
|
|
90
104
|
_this.metadataService.updateMetadata(metadata);
|
|
91
|
-
|
|
105
|
+
_this.isProviderInitialized = true;
|
|
106
|
+
}).on('restore', _this.documentService.onRestore).on('steps:added', _this.documentService.onStepsAdded).on('metadata:changed', _this.metadataService.onMetadataChanged).on('participant:telepointer', function (payload) {
|
|
107
|
+
return _this.participantsService.onParticipantTelepointer(payload, _this.sessionId);
|
|
108
|
+
}).on('presence:joined', _this.participantsService.onPresenceJoined).on('presence', _this.participantsService.onPresence).on('participant:left', _this.participantsService.onParticipantLeft).on('participant:updated', _this.participantsService.onParticipantUpdated).on('disconnect', _this.onDisconnected.bind(_assertThisInitialized(_this))).on('error', _this.onErrorHandled).on('status', _this.namespaceService.onNamespaceStatusChanged).connect(shouldInitialize);
|
|
92
109
|
});
|
|
93
110
|
/**
|
|
94
111
|
* @param {InternalError} error The error to handle
|
|
@@ -108,90 +125,15 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
108
125
|
if (mappedError) {
|
|
109
126
|
var _this$analyticsHelper2;
|
|
110
127
|
(_this$analyticsHelper2 = _this.analyticsHelper) === null || _this$analyticsHelper2 === void 0 ? void 0 : _this$analyticsHelper2.sendErrorEvent(mappedError, 'Error emitted');
|
|
111
|
-
_this.
|
|
128
|
+
_this.emitCallback('error', mappedError);
|
|
112
129
|
}
|
|
113
130
|
}
|
|
114
131
|
});
|
|
115
|
-
_defineProperty(_assertThisInitialized(_this), "sendPresence", function () {
|
|
116
|
-
try {
|
|
117
|
-
if (_this.presenceUpdateTimeout) {
|
|
118
|
-
clearTimeout(_this.presenceUpdateTimeout);
|
|
119
|
-
}
|
|
120
|
-
_this.channel.broadcast('participant:updated', {
|
|
121
|
-
sessionId: _this.sessionId,
|
|
122
|
-
userId: _this.userId,
|
|
123
|
-
clientId: _this.clientId
|
|
124
|
-
});
|
|
125
|
-
_this.presenceUpdateTimeout = window.setTimeout(function () {
|
|
126
|
-
return _this.sendPresence();
|
|
127
|
-
}, SEND_PRESENCE_INTERVAL);
|
|
128
|
-
} catch (error) {
|
|
129
|
-
var _this$analyticsHelper3;
|
|
130
|
-
// We don't want to throw errors for Presence features as they tend to self-restore
|
|
131
|
-
(_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(error, 'Error while sending presence');
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
/**
|
|
135
|
-
* Called when a participant joins the session.
|
|
136
|
-
*
|
|
137
|
-
* We keep track of participants internally in this class, and emit the `presence` event to update
|
|
138
|
-
* the active avatars in the editor.
|
|
139
|
-
* This method will be triggered from backend to notify all participants to exchange presence
|
|
140
|
-
*/
|
|
141
|
-
_defineProperty(_assertThisInitialized(_this), "onPresenceJoined", function (_ref3) {
|
|
142
|
-
var sessionId = _ref3.sessionId;
|
|
143
|
-
try {
|
|
144
|
-
logger('Participant joined with session: ', sessionId);
|
|
145
|
-
// This expose existing users to the newly joined user
|
|
146
|
-
_this.sendPresence();
|
|
147
|
-
} catch (error) {
|
|
148
|
-
var _this$analyticsHelper4;
|
|
149
|
-
// We don't want to throw errors for Presence features as they tend to self-restore
|
|
150
|
-
(_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendErrorEvent(error, 'Error while joining presence');
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
_defineProperty(_assertThisInitialized(_this), "onPresence", function (_ref4) {
|
|
154
|
-
var userId = _ref4.userId;
|
|
155
|
-
try {
|
|
156
|
-
logger('onPresence userId: ', userId);
|
|
157
|
-
_this.userId = userId;
|
|
158
|
-
_this.sendPresence();
|
|
159
|
-
_this.channel.sendPresenceJoined();
|
|
160
|
-
} catch (error) {
|
|
161
|
-
var _this$analyticsHelper5;
|
|
162
|
-
// We don't want to throw errors for Presence features as they tend to self-restore
|
|
163
|
-
(_this$analyticsHelper5 = _this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(error, 'Error while receiving presence');
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
/**
|
|
167
|
-
* Called when a participant leaves the session.
|
|
168
|
-
*
|
|
169
|
-
* We emit the `presence` event to update the active avatars in the editor.
|
|
170
|
-
*/
|
|
171
|
-
_defineProperty(_assertThisInitialized(_this), "onParticipantLeft", function (data) {
|
|
172
|
-
return _this.participantsService.participantLeft(data, _this.emitCallback);
|
|
173
|
-
});
|
|
174
|
-
_defineProperty(_assertThisInitialized(_this), "startInactiveRemover", function () {
|
|
175
|
-
return _this.participantsService.removeInactiveParticipants(_this.sessionId, _this.emitCallback);
|
|
176
|
-
});
|
|
177
|
-
/**
|
|
178
|
-
* Called when we receive an update event from another participant.
|
|
179
|
-
*/
|
|
180
|
-
_defineProperty(_assertThisInitialized(_this), "onParticipantUpdated", function (data) {
|
|
181
|
-
return _this.participantsService.updateParticipant(data, _this.config.getUser, _this.emitCallback);
|
|
182
|
-
});
|
|
183
|
-
/**
|
|
184
|
-
* Called when we receive a telepointer update from another
|
|
185
|
-
* participant.
|
|
186
|
-
*/
|
|
187
|
-
_defineProperty(_assertThisInitialized(_this), "onParticipantTelepointer", function (data) {
|
|
188
|
-
return _this.participantsService.participantTelepointer(data, _this.sessionId, _this.config.getUser, _this.emitCallback);
|
|
189
|
-
});
|
|
190
132
|
// Note: this gets triggered on page reload for Firefox (not other browsers) because of closeOnBeforeunload: false
|
|
191
|
-
_defineProperty(_assertThisInitialized(_this), "onDisconnected", function (
|
|
192
|
-
var reason =
|
|
133
|
+
_defineProperty(_assertThisInitialized(_this), "onDisconnected", function (_ref3) {
|
|
134
|
+
var reason = _ref3.reason;
|
|
193
135
|
_this.disconnectedAt = Date.now();
|
|
194
|
-
_this.participantsService.disconnect(reason, _this.sessionId
|
|
136
|
+
_this.participantsService.disconnect(reason, _this.sessionId);
|
|
195
137
|
});
|
|
196
138
|
/**
|
|
197
139
|
* Returns the documents metadata
|
|
@@ -205,7 +147,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
205
147
|
* @throws {GetCurrentStateError} Something went wrong while returning the current state
|
|
206
148
|
*/
|
|
207
149
|
_defineProperty(_assertThisInitialized(_this), "getCurrentState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
208
|
-
var _this$
|
|
150
|
+
var _this$analyticsHelper3;
|
|
209
151
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
210
152
|
while (1) switch (_context.prev = _context.next) {
|
|
211
153
|
case 0:
|
|
@@ -214,7 +156,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
214
156
|
case 4:
|
|
215
157
|
_context.prev = 4;
|
|
216
158
|
_context.t0 = _context["catch"](0);
|
|
217
|
-
(_this$
|
|
159
|
+
(_this$analyticsHelper3 = _this.analyticsHelper) === null || _this$analyticsHelper3 === void 0 ? void 0 : _this$analyticsHelper3.sendErrorEvent(_context.t0, 'Error while returning ADF version of current draft document');
|
|
218
160
|
throw new GetCurrentStateError('Error while returning the current state of the draft document', _context.t0);
|
|
219
161
|
case 8:
|
|
220
162
|
case "end":
|
|
@@ -228,7 +170,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
228
170
|
* @throws {GetFinalAcknowledgedStateError} Something went wrong while returning the acknowledged state
|
|
229
171
|
*/
|
|
230
172
|
_defineProperty(_assertThisInitialized(_this), "getFinalAcknowledgedState", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
231
|
-
var _this$
|
|
173
|
+
var _this$analyticsHelper4;
|
|
232
174
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
233
175
|
while (1) switch (_context2.prev = _context2.next) {
|
|
234
176
|
case 0:
|
|
@@ -237,7 +179,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
237
179
|
case 4:
|
|
238
180
|
_context2.prev = 4;
|
|
239
181
|
_context2.t0 = _context2["catch"](0);
|
|
240
|
-
(_this$
|
|
182
|
+
(_this$analyticsHelper4 = _this.analyticsHelper) === null || _this$analyticsHelper4 === void 0 ? void 0 : _this$analyticsHelper4.sendErrorEvent(_context2.t0, 'Error while returning ADF version of the final draft document');
|
|
241
183
|
throw new GetFinalAcknowledgedStateError('Error while returning the final acknowledged state of the draft document', _context2.t0);
|
|
242
184
|
case 8:
|
|
243
185
|
case "end":
|
|
@@ -248,51 +190,6 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
248
190
|
_defineProperty(_assertThisInitialized(_this), "getUnconfirmedSteps", function () {
|
|
249
191
|
return _this.documentService.getUnconfirmedSteps();
|
|
250
192
|
});
|
|
251
|
-
/**
|
|
252
|
-
* ESS-2916 namespace status event- lock/unlock
|
|
253
|
-
*/
|
|
254
|
-
_defineProperty(_assertThisInitialized(_this), "onNamespaceStatusChanged", /*#__PURE__*/function () {
|
|
255
|
-
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(data) {
|
|
256
|
-
var isLocked, waitTimeInMs, timestamp, start;
|
|
257
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
258
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
259
|
-
case 0:
|
|
260
|
-
isLocked = data.isLocked, waitTimeInMs = data.waitTimeInMs, timestamp = data.timestamp;
|
|
261
|
-
start = Date.now();
|
|
262
|
-
logger("Received a namespace status changed event ", {
|
|
263
|
-
data: data
|
|
264
|
-
});
|
|
265
|
-
if (!(isLocked && waitTimeInMs)) {
|
|
266
|
-
_context3.next = 8;
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
_this.isNamespaceLocked = true;
|
|
270
|
-
logger("Received a namespace status change event ", {
|
|
271
|
-
isLocked: isLocked
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
// To protect the collab editing process from locked out due to BE
|
|
275
|
-
setTimeout(function () {
|
|
276
|
-
logger("The namespace lock has expired", {
|
|
277
|
-
waitTime: Date.now() - start,
|
|
278
|
-
timestamp: timestamp
|
|
279
|
-
});
|
|
280
|
-
_this.isNamespaceLocked = false;
|
|
281
|
-
}, waitTimeInMs);
|
|
282
|
-
return _context3.abrupt("return");
|
|
283
|
-
case 8:
|
|
284
|
-
_this.isNamespaceLocked = false;
|
|
285
|
-
logger("The page lock has expired");
|
|
286
|
-
case 10:
|
|
287
|
-
case "end":
|
|
288
|
-
return _context3.stop();
|
|
289
|
-
}
|
|
290
|
-
}, _callee3);
|
|
291
|
-
}));
|
|
292
|
-
return function (_x) {
|
|
293
|
-
return _ref8.apply(this, arguments);
|
|
294
|
-
};
|
|
295
|
-
}());
|
|
296
193
|
/**
|
|
297
194
|
* Used when the provider is disconnected or destroyed to prevent perpetual timers from continuously running
|
|
298
195
|
*/
|
|
@@ -306,11 +203,16 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
306
203
|
_this.isChannelInitialized = false;
|
|
307
204
|
_this.initialDraft = _this.config.initialDraft;
|
|
308
205
|
_this.isProviderInitialized = false;
|
|
309
|
-
_this.
|
|
206
|
+
_this.isPreinitializing = false;
|
|
207
|
+
_this.participantsService = new ParticipantsService(_this.analyticsHelper, undefined, _this.emitCallback, _this.config.getUser, _this.channel.broadcast, _this.channel.sendPresenceJoined);
|
|
310
208
|
_this.metadataService = new MetadataService(_this.emitCallback, _this.channel.sendMetadata);
|
|
311
209
|
_this.documentService = new DocumentService(_this.participantsService, _this.analyticsHelper, _this.channel.fetchCatchup, _this.emitCallback, _this.channel.broadcast, function () {
|
|
312
210
|
return _this.userId;
|
|
313
211
|
}, _this.onErrorHandled, _this.metadataService);
|
|
212
|
+
_this.getStatePromise = new Promise(function (resolve) {
|
|
213
|
+
_this.getStatePromiseResolve = resolve;
|
|
214
|
+
});
|
|
215
|
+
_this.namespaceService = new NamespaceService();
|
|
314
216
|
return _this;
|
|
315
217
|
}
|
|
316
218
|
_createClass(Provider, [{
|
|
@@ -329,38 +231,54 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
329
231
|
}
|
|
330
232
|
|
|
331
233
|
/**
|
|
332
|
-
* Initialisation logic, called by the editor in the collab-edit plugin
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
234
|
+
* Initialisation logic, called by the editor in the collab-edit plugin.
|
|
235
|
+
*
|
|
236
|
+
* When getState is nullish and a initialDraft is provided the collab provider is in a state of pre-initialization,
|
|
237
|
+
* the provider starts to enable the connection to NCS, but the provider will not emit any events until this function
|
|
238
|
+
* is called again with a getState function, indicating that the editor is loaded and ready to receive the emits.
|
|
239
|
+
*
|
|
240
|
+
* @param {Object} options ...
|
|
241
|
+
* @param {Function} options.getState Function that returns the editor state, used to retrieve collab-edit properties and to interact with prosemirror-collab
|
|
242
|
+
* @param {SyncUpErrorFunction} options.onSyncUpError (Optional) Function that gets called when the sync of steps fails after retrying 30 times, used by Editor to log to analytics
|
|
336
243
|
* @throws {ProviderInitialisationError} Something went wrong during provider initialisation
|
|
337
244
|
*/
|
|
338
245
|
}, {
|
|
339
246
|
key: "setup",
|
|
340
|
-
value: function setup(
|
|
341
|
-
var getState =
|
|
342
|
-
onSyncUpError =
|
|
247
|
+
value: function setup(_ref6) {
|
|
248
|
+
var getState = _ref6.getState,
|
|
249
|
+
onSyncUpError = _ref6.onSyncUpError;
|
|
343
250
|
this.checkForCookies();
|
|
344
251
|
try {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
252
|
+
// if setup is called with no state and the initial draft is already provided
|
|
253
|
+
// set a flag to mark early provider setup
|
|
254
|
+
if (!getState && this.initialDraft) {
|
|
255
|
+
this.isPreinitializing = true;
|
|
256
|
+
}
|
|
257
|
+
if (getState) {
|
|
258
|
+
// if provider has already been initialized earlier, resolve the state once it is available
|
|
259
|
+
if (this.isPreinitializing) {
|
|
260
|
+
this.getStatePromiseResolve();
|
|
261
|
+
}
|
|
262
|
+
var collabPlugin = getState().plugins.find(function (p) {
|
|
263
|
+
return p.key === 'collab$';
|
|
264
|
+
});
|
|
265
|
+
if (collabPlugin === undefined) {
|
|
266
|
+
throw new ProviderInitialisationError('Collab provider attempted to initialise, but Editor state is missing collab plugin');
|
|
267
|
+
}
|
|
268
|
+
this.clientId = collabPlugin.spec.config.clientID;
|
|
269
|
+
this.documentService.setup({
|
|
270
|
+
getState: getState,
|
|
271
|
+
onSyncUpError: onSyncUpError,
|
|
272
|
+
clientId: this.clientId
|
|
273
|
+
});
|
|
350
274
|
}
|
|
351
|
-
this.clientId = collabPlugin.spec.config.clientID;
|
|
352
|
-
this.documentService.setup({
|
|
353
|
-
getState: getState,
|
|
354
|
-
onSyncUpError: onSyncUpError,
|
|
355
|
-
clientId: this.clientId
|
|
356
|
-
});
|
|
357
275
|
if (!this.isChannelInitialized) {
|
|
358
276
|
this.initializeChannel();
|
|
359
277
|
this.isChannelInitialized = true;
|
|
360
278
|
}
|
|
361
279
|
} catch (initError) {
|
|
362
|
-
var _this$
|
|
363
|
-
(_this$
|
|
280
|
+
var _this$analyticsHelper5;
|
|
281
|
+
(_this$analyticsHelper5 = this.analyticsHelper) === null || _this$analyticsHelper5 === void 0 ? void 0 : _this$analyticsHelper5.sendErrorEvent(initError, 'Error while initialising the provider');
|
|
364
282
|
// Throw error so consumers are aware the initialisation failed when initialising themselves
|
|
365
283
|
throw new ProviderInitialisationError('Provider initialisation error', initError);
|
|
366
284
|
}
|
|
@@ -370,9 +288,9 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
370
288
|
key: "checkForCookies",
|
|
371
289
|
value: function checkForCookies() {
|
|
372
290
|
if (!global.navigator.cookieEnabled) {
|
|
373
|
-
var _this$
|
|
291
|
+
var _this$analyticsHelper6;
|
|
374
292
|
var initError = new ProviderInitialisationError('Cookies are not enabled. Please enable cookies to use collaborative editing.');
|
|
375
|
-
(_this$
|
|
293
|
+
(_this$analyticsHelper6 = this.analyticsHelper) === null || _this$analyticsHelper6 === void 0 ? void 0 : _this$analyticsHelper6.sendErrorEvent(initError, 'Error while initialising the provider - cookies disabled');
|
|
376
294
|
throw new ProviderInitialisationError('Provider initialisation error - cookies disabled', initError);
|
|
377
295
|
}
|
|
378
296
|
}
|
|
@@ -389,14 +307,14 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
389
307
|
value: function send(_tr, _oldState, newState) {
|
|
390
308
|
try {
|
|
391
309
|
// Don't send steps while the document is locked (eg. when restoring the document)
|
|
392
|
-
if (this.
|
|
310
|
+
if (this.namespaceService.getIsNamespaceLocked()) {
|
|
393
311
|
logger('The document is temporary locked');
|
|
394
312
|
return;
|
|
395
313
|
}
|
|
396
314
|
this.documentService.send(_tr, _oldState, newState);
|
|
397
315
|
} catch (error) {
|
|
398
|
-
var _this$
|
|
399
|
-
(_this$
|
|
316
|
+
var _this$analyticsHelper7;
|
|
317
|
+
(_this$analyticsHelper7 = this.analyticsHelper) === null || _this$analyticsHelper7 === void 0 ? void 0 : _this$analyticsHelper7.sendErrorEvent(error, 'Error while sending steps for a transaction');
|
|
400
318
|
throw new SendTransactionError('Error while sending steps for a transaction', error);
|
|
401
319
|
}
|
|
402
320
|
}
|
|
@@ -424,9 +342,9 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
424
342
|
this.channel.broadcast('participant:telepointer', payload, callback);
|
|
425
343
|
}
|
|
426
344
|
} catch (error) {
|
|
427
|
-
var _this$
|
|
345
|
+
var _this$analyticsHelper8;
|
|
428
346
|
// We don't want to throw errors for Presence features as they tend to self-restore
|
|
429
|
-
(_this$
|
|
347
|
+
(_this$analyticsHelper8 = this.analyticsHelper) === null || _this$analyticsHelper8 === void 0 ? void 0 : _this$analyticsHelper8.sendErrorEvent(error, 'Error while sending message - telepointer');
|
|
430
348
|
}
|
|
431
349
|
}
|
|
432
350
|
}, {
|
|
@@ -465,8 +383,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
465
383
|
_get(_getPrototypeOf(Provider.prototype), "unsubscribeAll", this).call(this);
|
|
466
384
|
this.channel.disconnect();
|
|
467
385
|
} catch (error) {
|
|
468
|
-
var _this$
|
|
469
|
-
(_this$
|
|
386
|
+
var _this$analyticsHelper9;
|
|
387
|
+
(_this$analyticsHelper9 = this.analyticsHelper) === null || _this$analyticsHelper9 === void 0 ? void 0 : _this$analyticsHelper9.sendErrorEvent(error, 'Error while shutting down the collab provider');
|
|
470
388
|
throw new DestroyError('Error while shutting down the collab provider', error);
|
|
471
389
|
}
|
|
472
390
|
this.clearTimers();
|
|
@@ -486,8 +404,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
486
404
|
try {
|
|
487
405
|
this.metadataService.setTitle(title, broadcast);
|
|
488
406
|
} catch (error) {
|
|
489
|
-
var _this$
|
|
490
|
-
(_this$
|
|
407
|
+
var _this$analyticsHelper10;
|
|
408
|
+
(_this$analyticsHelper10 = this.analyticsHelper) === null || _this$analyticsHelper10 === void 0 ? void 0 : _this$analyticsHelper10.sendErrorEvent(error, 'Error while setting title');
|
|
491
409
|
throw new SetTitleError('Error while setting title', error);
|
|
492
410
|
}
|
|
493
411
|
}
|
|
@@ -505,8 +423,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
505
423
|
try {
|
|
506
424
|
this.metadataService.setEditorWidth(editorWidth, broadcast);
|
|
507
425
|
} catch (error) {
|
|
508
|
-
var _this$
|
|
509
|
-
(_this$
|
|
426
|
+
var _this$analyticsHelper11;
|
|
427
|
+
(_this$analyticsHelper11 = this.analyticsHelper) === null || _this$analyticsHelper11 === void 0 ? void 0 : _this$analyticsHelper11.sendErrorEvent(error, 'Error while setting editor width');
|
|
510
428
|
throw new SetEditorWidthError('Error while setting editor width', error);
|
|
511
429
|
}
|
|
512
430
|
}
|
|
@@ -522,8 +440,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
|
|
|
522
440
|
try {
|
|
523
441
|
this.metadataService.setMetadata(metadata);
|
|
524
442
|
} catch (error) {
|
|
525
|
-
var _this$
|
|
526
|
-
(_this$
|
|
443
|
+
var _this$analyticsHelper12;
|
|
444
|
+
(_this$analyticsHelper12 = this.analyticsHelper) === null || _this$analyticsHelper12 === void 0 ? void 0 : _this$analyticsHelper12.sendErrorEvent(error, 'Error while setting metadata');
|
|
527
445
|
throw new SetMetadataError('Error while setting metadata', error);
|
|
528
446
|
}
|
|
529
447
|
}
|
package/dist/esm/version.json
CHANGED
package/dist/types/channel.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare class Channel extends Emitter<ChannelEvent> {
|
|
|
34
34
|
* @throws {NotInitializedError} Channel not initialized
|
|
35
35
|
* @throws {NotConnectedError} Channel not connected
|
|
36
36
|
*/
|
|
37
|
-
broadcast: <K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], "timestamp">, callback?: Function
|
|
37
|
+
broadcast: <K extends keyof ChannelEvent>(type: K, data: Omit<ChannelEvent[K], "timestamp">, callback?: Function) => void;
|
|
38
38
|
/**
|
|
39
39
|
* Send metadata to the back-end service over the channel
|
|
40
40
|
* @throws {NotInitializedError} Channel not initialized
|