@hocuspocus/provider 2.2.0 → 2.2.2

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.
@@ -2113,6 +2113,7 @@ class HocuspocusProviderWebsocket extends EventEmitter {
2113
2113
  }
2114
2114
  onMessage(event) {
2115
2115
  this.resolveConnectionAttempt();
2116
+ this.lastMessageReceived = getUnixTime();
2116
2117
  }
2117
2118
  resolveConnectionAttempt() {
2118
2119
  if (this.connectionAttempt) {
@@ -2318,8 +2319,17 @@ class HocuspocusProvider extends EventEmitter {
2318
2319
  forceSync: null,
2319
2320
  };
2320
2321
  this.isConnected = true;
2321
- this.boundBeforeUnload = this.beforeUnload.bind(this);
2322
2322
  this.boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this);
2323
+ this.boundBeforeUnload = this.beforeUnload.bind(this);
2324
+ this.boundOnOpen = this.onOpen.bind(this);
2325
+ this.boundOnMessage = this.onMessage.bind(this);
2326
+ this.boundOnClose = this.onClose.bind(this);
2327
+ this.boundOnStatus = this.onStatus.bind(this);
2328
+ this.forwardConnect = (e) => this.emit('connect', e);
2329
+ this.forwardOpen = (e) => this.emit('open', e);
2330
+ this.forwardClose = (e) => this.emit('close', e);
2331
+ this.forwardDisconnect = (e) => this.emit('disconnect', e);
2332
+ this.forwardDestroy = (e) => this.emit('destroy', e);
2323
2333
  this.setConfiguration(configuration);
2324
2334
  this.configuration.document = configuration.document ? configuration.document : new Y.Doc();
2325
2335
  this.configuration.awareness = configuration.awareness ? configuration.awareness : new Awareness(this.document);
@@ -2334,18 +2344,18 @@ class HocuspocusProvider extends EventEmitter {
2334
2344
  this.on('authenticated', this.configuration.onAuthenticated);
2335
2345
  this.on('authenticationFailed', this.configuration.onAuthenticationFailed);
2336
2346
  this.configuration.websocketProvider.on('connect', this.configuration.onConnect);
2337
- this.configuration.websocketProvider.on('connect', (e) => this.emit('connect', e));
2338
- this.configuration.websocketProvider.on('open', this.onOpen.bind(this));
2339
- this.configuration.websocketProvider.on('open', (e) => this.emit('open', e));
2340
- this.configuration.websocketProvider.on('message', this.onMessage.bind(this));
2341
- this.configuration.websocketProvider.on('close', this.onClose.bind(this));
2347
+ this.configuration.websocketProvider.on('connect', this.forwardConnect);
2348
+ this.configuration.websocketProvider.on('open', this.boundOnOpen);
2349
+ this.configuration.websocketProvider.on('open', this.forwardOpen);
2350
+ this.configuration.websocketProvider.on('message', this.boundOnMessage);
2351
+ this.configuration.websocketProvider.on('close', this.boundOnClose);
2342
2352
  this.configuration.websocketProvider.on('close', this.configuration.onClose);
2343
- this.configuration.websocketProvider.on('close', (e) => this.emit('close', e));
2344
- this.configuration.websocketProvider.on('status', this.onStatus.bind(this));
2353
+ this.configuration.websocketProvider.on('close', this.forwardClose);
2354
+ this.configuration.websocketProvider.on('status', this.boundOnStatus);
2345
2355
  this.configuration.websocketProvider.on('disconnect', this.configuration.onDisconnect);
2346
- this.configuration.websocketProvider.on('disconnect', (e) => this.emit('disconnect', e));
2356
+ this.configuration.websocketProvider.on('disconnect', this.forwardDisconnect);
2347
2357
  this.configuration.websocketProvider.on('destroy', this.configuration.onDestroy);
2348
- this.configuration.websocketProvider.on('destroy', (e) => this.emit('destroy', e));
2358
+ this.configuration.websocketProvider.on('destroy', this.forwardDestroy);
2349
2359
  this.awareness.on('update', () => {
2350
2360
  this.emit('awarenessUpdate', { states: awarenessStatesToArray(this.awareness.getStates()) });
2351
2361
  });
@@ -2510,6 +2520,19 @@ class HocuspocusProvider extends EventEmitter {
2510
2520
  this.awareness.off('update', this.awarenessUpdateHandler);
2511
2521
  this.document.off('update', this.documentUpdateHandler);
2512
2522
  this.removeAllListeners();
2523
+ this.configuration.websocketProvider.off('connect', this.configuration.onConnect);
2524
+ this.configuration.websocketProvider.off('connect', this.forwardConnect);
2525
+ this.configuration.websocketProvider.off('open', this.boundOnOpen);
2526
+ this.configuration.websocketProvider.off('open', this.forwardOpen);
2527
+ this.configuration.websocketProvider.off('message', this.boundOnMessage);
2528
+ this.configuration.websocketProvider.off('close', this.boundOnClose);
2529
+ this.configuration.websocketProvider.off('close', this.configuration.onClose);
2530
+ this.configuration.websocketProvider.off('close', this.forwardClose);
2531
+ this.configuration.websocketProvider.off('status', this.boundOnStatus);
2532
+ this.configuration.websocketProvider.off('disconnect', this.configuration.onDisconnect);
2533
+ this.configuration.websocketProvider.off('disconnect', this.forwardDisconnect);
2534
+ this.configuration.websocketProvider.off('destroy', this.configuration.onDestroy);
2535
+ this.configuration.websocketProvider.off('destroy', this.forwardDestroy);
2513
2536
  this.send(CloseMessage, { documentName: this.configuration.name });
2514
2537
  this.isConnected = false;
2515
2538
  if (typeof window === 'undefined') {