@atlaskit/collab-provider 7.0.1 → 7.1.3

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.
@@ -1,23 +1,18 @@
1
1
  export const createLogger = (prefix, color = 'blue') => (msg, data = null) => {
2
2
  if (window.COLLAB_PROVIDER_LOGGER) {
3
3
  // eslint-disable-next-line no-console
4
- console.log(`%cCollab-${prefix}: ${msg}`, `color: ${color}; font-weight: bold`);
5
-
6
- if (data) {
7
- // eslint-disable-next-line no-console
8
- console.log(data);
9
- }
4
+ console.log(`%cCollab-${prefix}: ${msg}`, `color: ${color}; font-weight: bold`, data);
10
5
  }
11
6
  };
7
+ const logger = createLogger('Helper:util', 'black');
12
8
  export const getParticipant = userId => {
13
- // eslint-disable-next-line no-bitwise
14
- const name = 'Demo User';
15
- return Promise.resolve({
16
- userId,
17
- name,
18
- avatar: `https://api.adorable.io/avatars/80/${name.replace(/\s/g, '')}.png`,
19
- email: `${name.replace(/\s/g, '').toLocaleLowerCase()}@atlassian.com`
20
- });
9
+ logger('getParticipant: ', userId);
10
+ return {
11
+ userId: userId,
12
+ name: userId,
13
+ avatar: '',
14
+ email: `${userId.replace(/\s/g, '').toLocaleLowerCase()}@atlassian.com`
15
+ };
21
16
  };
22
17
  export function sleep(ms) {
23
18
  return new Promise(resolve => {
@@ -1,6 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { getVersion, sendableSteps } from 'prosemirror-collab';
3
3
  import throttle from 'lodash/throttle';
4
+ import isequal from 'lodash/isEqual';
4
5
  import { Emitter } from '../emitter';
5
6
  import { Channel } from '../channel';
6
7
  import { createLogger, getParticipant, sleep } from '../helpers/utils';
@@ -8,6 +9,7 @@ import { ACK_MAX_TRY } from '../helpers/const';
8
9
  import { triggerAnalyticsForCatchupFailed, triggerAnalyticsForStepsRejected, triggerAnalyticsForStepsAddedSuccessfully } from '../analytics';
9
10
  import { catchup } from './catchup';
10
11
  import { errorCodeMapper } from '../error-code-mapper';
12
+ import { DisconnectReason, socketIOReasons } from '../disconnected-reason-mapper';
11
13
  const logger = createLogger('Provider', 'black');
12
14
  const PARTICIPANT_UPDATE_INTERVAL = 300 * 1000; // 300 seconds
13
15
 
@@ -195,7 +197,7 @@ export class Provider extends Emitter {
195
197
  this.presenceUpdateTimeout = window.setTimeout(() => this.sendPresence(), SEND_PRESENCE_INTERVAL);
196
198
  });
197
199
 
198
- _defineProperty(this, "onParticipantJoined", ({
200
+ _defineProperty(this, "onPresenceJoined", ({
199
201
  sessionId
200
202
  }) => {
201
203
  logger('Participant joined with session: ', sessionId); // This expose existing users to the newly joined user
@@ -203,25 +205,18 @@ export class Provider extends Emitter {
203
205
  this.sendPresence();
204
206
  });
205
207
 
206
- _defineProperty(this, "onTitleChanged", ({
207
- title
208
+ _defineProperty(this, "onPresence", ({
209
+ userId
208
210
  }) => {
209
- if (title !== undefined && this.metadata.title !== title) {
210
- this.metadata.title = title;
211
- this.emit('metadata:changed', {
212
- title
213
- });
214
- }
211
+ logger('onPresence userId: ', userId);
212
+ this.userId = userId;
213
+ this.sendPresence();
214
+ this.channel.sendPresenceJoined();
215
215
  });
216
216
 
217
- _defineProperty(this, "onWidthChanged", ({
218
- editorWidth
219
- }) => {
220
- if (editorWidth !== undefined && this.metadata.editorWidth !== editorWidth) {
221
- this.metadata.editorWidth = editorWidth;
222
- this.emit('metadata:changed', {
223
- editorWidth
224
- });
217
+ _defineProperty(this, "onMetadataChanged", metadata => {
218
+ if (metadata !== undefined && !isequal(this.metadata, metadata)) {
219
+ this.emit('metadata:changed', metadata);
225
220
  }
226
221
  });
227
222
 
@@ -288,6 +283,11 @@ export class Provider extends Emitter {
288
283
  userId,
289
284
  clientId
290
285
  }) => {
286
+ if (!userId) {
287
+ // If userId does not exsit, does nothing here to prevent duplication.
288
+ return;
289
+ }
290
+
291
291
  const {
292
292
  getUser
293
293
  } = this.config;
@@ -348,12 +348,38 @@ export class Provider extends Emitter {
348
348
  this.participantUpdateTimeout = window.setTimeout(() => this.updateParticipants(), PARTICIPANT_UPDATE_INTERVAL);
349
349
  });
350
350
 
351
+ _defineProperty(this, "disconnectedReasonMapper", reason => {
352
+ switch (reason) {
353
+ case socketIOReasons.IO_CLIENT_DISCONNECT:
354
+ return DisconnectReason.CLIENT_DISCONNECT;
355
+
356
+ case socketIOReasons.IO_SERVER_DISCONNECT:
357
+ return DisconnectReason.SERVER_DISCONNECT;
358
+
359
+ case socketIOReasons.TRANSPORT_CLOSED:
360
+ return DisconnectReason.SOCKET_CLOSED;
361
+
362
+ case socketIOReasons.TRANSPORT_ERROR:
363
+ return DisconnectReason.SOCKET_ERROR;
364
+
365
+ case socketIOReasons.PING_TIMEOUT:
366
+ return DisconnectReason.SOCKET_TIMEOUT;
367
+
368
+ default:
369
+ return DisconnectReason.UNKNOWN_DISCONNECT;
370
+ }
371
+ });
372
+
351
373
  _defineProperty(this, "onDisconnected", ({
352
374
  reason
353
375
  }) => {
354
376
  this.disconnectedAt = Date.now();
355
377
  const left = Array.from(this.participants.values());
356
378
  this.participants.clear();
379
+ this.emit('disconnected', {
380
+ reason: this.disconnectedReasonMapper(reason),
381
+ sid: this.sessionId
382
+ });
357
383
 
358
384
  if (left.length) {
359
385
  this.emit('presence', {
@@ -386,8 +412,7 @@ export class Provider extends Emitter {
386
412
  this.sessionId = sid;
387
413
  this.emit('connected', {
388
414
  sid
389
- });
390
- this.sendPresence(); // If already initialized, `connected` means reconnected
415
+ }); // If already initialized, `connected` means reconnected
391
416
 
392
417
  if (initialized && this.disconnectedAt && // Offline longer than `OUT_OF_SYNC_PERIOD`
393
418
  Date.now() - this.disconnectedAt >= OUT_OF_SYNC_PERIOD) {
@@ -398,18 +423,15 @@ export class Provider extends Emitter {
398
423
  }).on('init', ({
399
424
  doc,
400
425
  version,
401
- userId,
402
426
  metadata
403
427
  }) => {
404
- this.userId = userId;
405
- this.sendPresence(); // Initial document and version
406
-
428
+ // Initial document and version
407
429
  this.updateDocumentWithMetadata({
408
430
  doc,
409
431
  version,
410
432
  metadata
411
433
  });
412
- }).on('steps:added', this.onStepsAdded).on('participant:telepointer', this.onParticipantTelepointer).on('participant:joined', this.onParticipantJoined).on('participant:left', this.onParticipantLeft).on('participant:updated', this.onParticipantUpdated).on('title:changed', this.onTitleChanged).on('width:changed', this.onWidthChanged).on('disconnect', this.onDisconnected).on('error', this.onErrorHandled).connect();
434
+ }).on('steps:added', this.onStepsAdded).on('participant:telepointer', this.onParticipantTelepointer).on('presence:joined', this.onPresenceJoined).on('presence', this.onPresence).on('participant:left', this.onParticipantLeft).on('participant:updated', this.onParticipantUpdated).on('metadata:changed', this.onMetadataChanged).on('disconnect', this.onDisconnected).on('error', this.onErrorHandled).connect();
413
435
  return this;
414
436
  }
415
437
  /**
@@ -595,23 +617,32 @@ export class Provider extends Emitter {
595
617
  }
596
618
 
597
619
  setTitle(title, broadcast) {
598
- this.metadata.title = title;
599
-
600
620
  if (broadcast) {
601
- this.channel.broadcast('title:changed', {
621
+ this.channel.sendMetadata({
602
622
  title
603
623
  });
604
624
  }
625
+
626
+ Object.assign(this.metadata, {
627
+ title
628
+ });
605
629
  }
606
630
 
607
631
  setEditorWidth(editorWidth, broadcast) {
608
- this.metadata.editorWidth = editorWidth;
609
-
610
632
  if (broadcast) {
611
- this.channel.broadcast('width:changed', {
633
+ this.channel.sendMetadata({
612
634
  editorWidth
613
635
  });
614
636
  }
637
+
638
+ Object.assign(this.metadata, {
639
+ editorWidth
640
+ });
641
+ }
642
+
643
+ setMetadata(metadata) {
644
+ this.channel.sendMetadata(metadata);
645
+ Object.assign(this.metadata, metadata);
615
646
  }
616
647
  /**
617
648
  * Get latest state.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "7.0.1",
3
+ "version": "7.1.3",
4
4
  "sideEffects": false
5
5
  }
@@ -149,8 +149,11 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
149
149
  this.socket.on('participant:telepointer', function (payload) {
150
150
  _this2.emit('participant:telepointer', payload.data);
151
151
  });
152
- this.socket.on('participant:joined', function (data) {
153
- _this2.emit('participant:joined', data);
152
+ this.socket.on('presence:joined', function (data) {
153
+ _this2.emit('presence:joined', data);
154
+ });
155
+ this.socket.on('presence', function (data) {
156
+ _this2.emit('presence', data);
154
157
  });
155
158
  this.socket.on('participant:left', function (data) {
156
159
  _this2.emit('participant:left', data);
@@ -167,11 +170,8 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
167
170
  clientId: clientId
168
171
  }, data));
169
172
  });
170
- this.socket.on('title:changed', function (payload) {
171
- _this2.emit('title:changed', payload.data);
172
- });
173
- this.socket.on('width:changed', function (payload) {
174
- _this2.emit('width:changed', payload.data);
173
+ this.socket.on('metadata:changed', function (payload) {
174
+ _this2.emit('metadata:changed', payload);
175
175
  });
176
176
  this.socket.on('disconnect', /*#__PURE__*/function () {
177
177
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(reason) {
@@ -344,6 +344,24 @@ export var Channel = /*#__PURE__*/function (_Emitter) {
344
344
  type: type
345
345
  }, data));
346
346
  }
347
+ }, {
348
+ key: "sendMetadata",
349
+ value: function sendMetadata(metadata) {
350
+ if (!this.connected || !this.socket) {
351
+ return;
352
+ }
353
+
354
+ this.socket.emit('metadata', metadata);
355
+ }
356
+ }, {
357
+ key: "sendPresenceJoined",
358
+ value: function sendPresenceJoined() {
359
+ if (!this.connected || !this.socket) {
360
+ return;
361
+ }
362
+
363
+ this.socket.emit('presence:joined');
364
+ }
347
365
  }, {
348
366
  key: "disconnect",
349
367
  value: function disconnect() {
@@ -0,0 +1,23 @@
1
+ // See https://socket.io/docs/v3/client-socket-instance#disconnect for emitted reasons
2
+ export var socketIOReasons = {
3
+ IO_CLIENT_DISCONNECT: 'io client disconnect',
4
+ // The socket was manually disconnected using socket.disconnect()
5
+ IO_SERVER_DISCONNECT: 'io server disconnect',
6
+ // The server has forcefully disconnected the socket with socket.disconnect()
7
+ TRANSPORT_CLOSED: 'transport close',
8
+ // The server did not send a PING within the pingInterval + pingTimeout range
9
+ TRANSPORT_ERROR: 'transport error',
10
+ // The connection was closed (example: the user has lost connection, or the network was changed from WiFi to 4G)
11
+ PING_TIMEOUT: 'ping timeout' // The connection has encountered an error (example: the server was killed during a HTTP long-polling cycle)
12
+
13
+ };
14
+ export var DisconnectReason;
15
+
16
+ (function (DisconnectReason) {
17
+ DisconnectReason["CLIENT_DISCONNECT"] = "CLIENT_DISCONNECT";
18
+ DisconnectReason["SERVER_DISCONNECT"] = "SERVER_DISCONNECT";
19
+ DisconnectReason["SOCKET_CLOSED"] = "SOCKET_CLOSED";
20
+ DisconnectReason["SOCKET_ERROR"] = "SOCKET_ERROR";
21
+ DisconnectReason["SOCKET_TIMEOUT"] = "SOCKET_TIMEOUT";
22
+ DisconnectReason["UNKNOWN_DISCONNECT"] = "UNKNOWN_DISCONNECT";
23
+ })(DisconnectReason || (DisconnectReason = {}));
@@ -5,24 +5,19 @@ export var createLogger = function createLogger(prefix) {
5
5
 
6
6
  if (window.COLLAB_PROVIDER_LOGGER) {
7
7
  // eslint-disable-next-line no-console
8
- console.log("%cCollab-".concat(prefix, ": ").concat(msg), "color: ".concat(color, "; font-weight: bold"));
9
-
10
- if (data) {
11
- // eslint-disable-next-line no-console
12
- console.log(data);
13
- }
8
+ console.log("%cCollab-".concat(prefix, ": ").concat(msg), "color: ".concat(color, "; font-weight: bold"), data);
14
9
  }
15
10
  };
16
11
  };
12
+ var logger = createLogger('Helper:util', 'black');
17
13
  export var getParticipant = function getParticipant(userId) {
18
- // eslint-disable-next-line no-bitwise
19
- var name = 'Demo User';
20
- return Promise.resolve({
14
+ logger('getParticipant: ', userId);
15
+ return {
21
16
  userId: userId,
22
- name: name,
23
- avatar: "https://api.adorable.io/avatars/80/".concat(name.replace(/\s/g, ''), ".png"),
24
- email: "".concat(name.replace(/\s/g, '').toLocaleLowerCase(), "@atlassian.com")
25
- });
17
+ name: userId,
18
+ avatar: '',
19
+ email: "".concat(userId.replace(/\s/g, '').toLocaleLowerCase(), "@atlassian.com")
20
+ };
26
21
  };
27
22
  export function sleep(ms) {
28
23
  return new Promise(function (resolve) {
@@ -22,6 +22,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
22
22
 
23
23
  import { getVersion, sendableSteps } from 'prosemirror-collab';
24
24
  import throttle from 'lodash/throttle';
25
+ import isequal from 'lodash/isEqual';
25
26
  import { Emitter } from '../emitter';
26
27
  import { Channel } from '../channel';
27
28
  import { createLogger, getParticipant, sleep } from '../helpers/utils';
@@ -29,6 +30,7 @@ import { ACK_MAX_TRY } from '../helpers/const';
29
30
  import { triggerAnalyticsForCatchupFailed, triggerAnalyticsForStepsRejected, triggerAnalyticsForStepsAddedSuccessfully } from '../analytics';
30
31
  import { catchup } from './catchup';
31
32
  import { errorCodeMapper } from '../error-code-mapper';
33
+ import { DisconnectReason, socketIOReasons } from '../disconnected-reason-mapper';
32
34
  var logger = createLogger('Provider', 'black');
33
35
  var PARTICIPANT_UPDATE_INTERVAL = 300 * 1000; // 300 seconds
34
36
 
@@ -261,39 +263,31 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
261
263
  }, SEND_PRESENCE_INTERVAL);
262
264
  });
263
265
 
264
- _defineProperty(_assertThisInitialized(_this), "onParticipantJoined", function (_ref5) {
266
+ _defineProperty(_assertThisInitialized(_this), "onPresenceJoined", function (_ref5) {
265
267
  var sessionId = _ref5.sessionId;
266
268
  logger('Participant joined with session: ', sessionId); // This expose existing users to the newly joined user
267
269
 
268
270
  _this.sendPresence();
269
271
  });
270
272
 
271
- _defineProperty(_assertThisInitialized(_this), "onTitleChanged", function (_ref6) {
272
- var title = _ref6.title;
273
+ _defineProperty(_assertThisInitialized(_this), "onPresence", function (_ref6) {
274
+ var userId = _ref6.userId;
275
+ logger('onPresence userId: ', userId);
276
+ _this.userId = userId;
273
277
 
274
- if (title !== undefined && _this.metadata.title !== title) {
275
- _this.metadata.title = title;
278
+ _this.sendPresence();
276
279
 
277
- _this.emit('metadata:changed', {
278
- title: title
279
- });
280
- }
280
+ _this.channel.sendPresenceJoined();
281
281
  });
282
282
 
283
- _defineProperty(_assertThisInitialized(_this), "onWidthChanged", function (_ref7) {
284
- var editorWidth = _ref7.editorWidth;
285
-
286
- if (editorWidth !== undefined && _this.metadata.editorWidth !== editorWidth) {
287
- _this.metadata.editorWidth = editorWidth;
288
-
289
- _this.emit('metadata:changed', {
290
- editorWidth: editorWidth
291
- });
283
+ _defineProperty(_assertThisInitialized(_this), "onMetadataChanged", function (metadata) {
284
+ if (metadata !== undefined && !isequal(_this.metadata, metadata)) {
285
+ _this.emit('metadata:changed', metadata);
292
286
  }
293
287
  });
294
288
 
295
- _defineProperty(_assertThisInitialized(_this), "onParticipantLeft", function (_ref8) {
296
- var sessionId = _ref8.sessionId;
289
+ _defineProperty(_assertThisInitialized(_this), "onParticipantLeft", function (_ref7) {
290
+ var sessionId = _ref7.sessionId;
297
291
  logger("Participant left");
298
292
 
299
293
  _this.participants.delete(sessionId);
@@ -305,11 +299,11 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
305
299
  });
306
300
  });
307
301
 
308
- _defineProperty(_assertThisInitialized(_this), "onParticipantUpdated", function (_ref9) {
309
- var sessionId = _ref9.sessionId,
310
- timestamp = _ref9.timestamp,
311
- userId = _ref9.userId,
312
- clientId = _ref9.clientId;
302
+ _defineProperty(_assertThisInitialized(_this), "onParticipantUpdated", function (_ref8) {
303
+ var sessionId = _ref8.sessionId,
304
+ timestamp = _ref8.timestamp,
305
+ userId = _ref8.userId,
306
+ clientId = _ref8.clientId;
313
307
 
314
308
  _this.updateParticipant({
315
309
  sessionId: sessionId,
@@ -319,12 +313,12 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
319
313
  });
320
314
  });
321
315
 
322
- _defineProperty(_assertThisInitialized(_this), "onParticipantTelepointer", function (_ref10) {
323
- var sessionId = _ref10.sessionId,
324
- timestamp = _ref10.timestamp,
325
- selection = _ref10.selection,
326
- userId = _ref10.userId,
327
- clientId = _ref10.clientId;
316
+ _defineProperty(_assertThisInitialized(_this), "onParticipantTelepointer", function (_ref9) {
317
+ var sessionId = _ref9.sessionId,
318
+ timestamp = _ref9.timestamp,
319
+ selection = _ref9.selection,
320
+ userId = _ref9.userId,
321
+ clientId = _ref9.clientId;
328
322
 
329
323
  if (sessionId === _this.sessionId) {
330
324
  return;
@@ -353,19 +347,28 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
353
347
  });
354
348
 
355
349
  _defineProperty(_assertThisInitialized(_this), "updateParticipant", /*#__PURE__*/function () {
356
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref11) {
350
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref10) {
357
351
  var sessionId, timestamp, userId, clientId, getUser, _yield, _yield$name, name, _yield$email, email, _yield$avatar, avatar, isNewParticipant;
358
352
 
359
353
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
360
354
  while (1) {
361
355
  switch (_context2.prev = _context2.next) {
362
356
  case 0:
363
- sessionId = _ref11.sessionId, timestamp = _ref11.timestamp, userId = _ref11.userId, clientId = _ref11.clientId;
357
+ sessionId = _ref10.sessionId, timestamp = _ref10.timestamp, userId = _ref10.userId, clientId = _ref10.clientId;
358
+
359
+ if (userId) {
360
+ _context2.next = 3;
361
+ break;
362
+ }
363
+
364
+ return _context2.abrupt("return");
365
+
366
+ case 3:
364
367
  getUser = _this.config.getUser;
365
- _context2.next = 4;
368
+ _context2.next = 6;
366
369
  return getUser ? getUser(userId) : getParticipant(userId);
367
370
 
368
- case 4:
371
+ case 6:
369
372
  _yield = _context2.sent;
370
373
  _yield$name = _yield.name;
371
374
  name = _yield$name === void 0 ? '' : _yield$name;
@@ -395,7 +398,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
395
398
 
396
399
  _this.updateParticipants(isNewParticipant ? [_this.participants.get(sessionId)] : []);
397
400
 
398
- case 15:
401
+ case 17:
399
402
  case "end":
400
403
  return _context2.stop();
401
404
  }
@@ -404,7 +407,7 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
404
407
  }));
405
408
 
406
409
  return function (_x) {
407
- return _ref12.apply(this, arguments);
410
+ return _ref11.apply(this, arguments);
408
411
  };
409
412
  }());
410
413
 
@@ -445,13 +448,40 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
445
448
  }, PARTICIPANT_UPDATE_INTERVAL);
446
449
  });
447
450
 
448
- _defineProperty(_assertThisInitialized(_this), "onDisconnected", function (_ref13) {
449
- var reason = _ref13.reason;
451
+ _defineProperty(_assertThisInitialized(_this), "disconnectedReasonMapper", function (reason) {
452
+ switch (reason) {
453
+ case socketIOReasons.IO_CLIENT_DISCONNECT:
454
+ return DisconnectReason.CLIENT_DISCONNECT;
455
+
456
+ case socketIOReasons.IO_SERVER_DISCONNECT:
457
+ return DisconnectReason.SERVER_DISCONNECT;
458
+
459
+ case socketIOReasons.TRANSPORT_CLOSED:
460
+ return DisconnectReason.SOCKET_CLOSED;
461
+
462
+ case socketIOReasons.TRANSPORT_ERROR:
463
+ return DisconnectReason.SOCKET_ERROR;
464
+
465
+ case socketIOReasons.PING_TIMEOUT:
466
+ return DisconnectReason.SOCKET_TIMEOUT;
467
+
468
+ default:
469
+ return DisconnectReason.UNKNOWN_DISCONNECT;
470
+ }
471
+ });
472
+
473
+ _defineProperty(_assertThisInitialized(_this), "onDisconnected", function (_ref12) {
474
+ var reason = _ref12.reason;
450
475
  _this.disconnectedAt = Date.now();
451
476
  var left = Array.from(_this.participants.values());
452
477
 
453
478
  _this.participants.clear();
454
479
 
480
+ _this.emit('disconnected', {
481
+ reason: _this.disconnectedReasonMapper(reason),
482
+ sid: _this.sessionId
483
+ });
484
+
455
485
  if (left.length) {
456
486
  _this.emit('presence', {
457
487
  left: left
@@ -484,16 +514,14 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
484
514
  this.getState().plugins.find(function (p) {
485
515
  return p.key === 'collab$';
486
516
  }).spec.config.clientID : optionsOrGetState.clientId;
487
- this.channel.on('connected', function (_ref14) {
488
- var sid = _ref14.sid,
489
- initialized = _ref14.initialized;
517
+ this.channel.on('connected', function (_ref13) {
518
+ var sid = _ref13.sid,
519
+ initialized = _ref13.initialized;
490
520
  _this2.sessionId = sid;
491
521
 
492
522
  _this2.emit('connected', {
493
523
  sid: sid
494
- });
495
-
496
- _this2.sendPresence(); // If already initialized, `connected` means reconnected
524
+ }); // If already initialized, `connected` means reconnected
497
525
 
498
526
 
499
527
  if (initialized && _this2.disconnectedAt && // Offline longer than `OUT_OF_SYNC_PERIOD`
@@ -502,22 +530,18 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
502
530
  }
503
531
 
504
532
  _this2.disconnectedAt = undefined;
505
- }).on('init', function (_ref15) {
506
- var doc = _ref15.doc,
507
- version = _ref15.version,
508
- userId = _ref15.userId,
509
- metadata = _ref15.metadata;
510
- _this2.userId = userId;
511
-
512
- _this2.sendPresence(); // Initial document and version
513
-
533
+ }).on('init', function (_ref14) {
534
+ var doc = _ref14.doc,
535
+ version = _ref14.version,
536
+ metadata = _ref14.metadata;
514
537
 
538
+ // Initial document and version
515
539
  _this2.updateDocumentWithMetadata({
516
540
  doc: doc,
517
541
  version: version,
518
542
  metadata: metadata
519
543
  });
520
- }).on('steps:added', this.onStepsAdded).on('participant:telepointer', this.onParticipantTelepointer).on('participant:joined', this.onParticipantJoined).on('participant:left', this.onParticipantLeft).on('participant:updated', this.onParticipantUpdated).on('title:changed', this.onTitleChanged).on('width:changed', this.onWidthChanged).on('disconnect', this.onDisconnected).on('error', this.onErrorHandled).connect();
544
+ }).on('steps:added', this.onStepsAdded).on('participant:telepointer', this.onParticipantTelepointer).on('presence:joined', this.onPresenceJoined).on('presence', this.onPresence).on('participant:left', this.onParticipantLeft).on('participant:updated', this.onParticipantUpdated).on('metadata:changed', this.onMetadataChanged).on('disconnect', this.onDisconnected).on('error', this.onErrorHandled).connect();
521
545
  return this;
522
546
  }
523
547
  /**
@@ -616,8 +640,8 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
616
640
  logger("Processing data. Version \"".concat(version, "\"."));
617
641
 
618
642
  if (steps && steps.length) {
619
- var clientIds = steps.map(function (_ref16) {
620
- var clientId = _ref16.clientId;
643
+ var clientIds = steps.map(function (_ref15) {
644
+ var clientId = _ref15.clientId;
621
645
  return clientId;
622
646
  });
623
647
  this.emit('data', {
@@ -680,14 +704,14 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
680
704
  participant = _Array$from$filter2[0];
681
705
 
682
706
  if (participant) {
683
- var _ref17 = step,
684
- stepType = _ref17.stepType,
685
- to = _ref17.to,
686
- from = _ref17.from,
687
- _ref17$slice = _ref17.slice,
688
- slice = _ref17$slice === void 0 ? {
707
+ var _ref16 = step,
708
+ stepType = _ref16.stepType,
709
+ to = _ref16.to,
710
+ from = _ref16.from,
711
+ _ref16$slice = _ref16.slice,
712
+ slice = _ref16$slice === void 0 ? {
689
713
  content: []
690
- } : _ref17$slice;
714
+ } : _ref16$slice;
691
715
 
692
716
  var _slice$content = _slicedToArray(slice.content, 1),
693
717
  node = _slice$content[0];
@@ -719,24 +743,34 @@ export var Provider = /*#__PURE__*/function (_Emitter) {
719
743
  }, {
720
744
  key: "setTitle",
721
745
  value: function setTitle(title, broadcast) {
722
- this.metadata.title = title;
723
-
724
746
  if (broadcast) {
725
- this.channel.broadcast('title:changed', {
747
+ this.channel.sendMetadata({
726
748
  title: title
727
749
  });
728
750
  }
751
+
752
+ Object.assign(this.metadata, {
753
+ title: title
754
+ });
729
755
  }
730
756
  }, {
731
757
  key: "setEditorWidth",
732
758
  value: function setEditorWidth(editorWidth, broadcast) {
733
- this.metadata.editorWidth = editorWidth;
734
-
735
759
  if (broadcast) {
736
- this.channel.broadcast('width:changed', {
760
+ this.channel.sendMetadata({
737
761
  editorWidth: editorWidth
738
762
  });
739
763
  }
764
+
765
+ Object.assign(this.metadata, {
766
+ editorWidth: editorWidth
767
+ });
768
+ }
769
+ }, {
770
+ key: "setMetadata",
771
+ value: function setMetadata(metadata) {
772
+ this.channel.sendMetadata(metadata);
773
+ Object.assign(this.metadata, metadata);
740
774
  }
741
775
  /**
742
776
  * Get latest state.
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/collab-provider",
3
- "version": "7.0.1",
3
+ "version": "7.1.3",
4
4
  "sideEffects": false
5
5
  }