@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.
@@ -2137,6 +2137,7 @@ class HocuspocusProviderWebsocket extends EventEmitter {
2137
2137
  }
2138
2138
  onMessage(event) {
2139
2139
  this.resolveConnectionAttempt();
2140
+ this.lastMessageReceived = getUnixTime();
2140
2141
  }
2141
2142
  resolveConnectionAttempt() {
2142
2143
  if (this.connectionAttempt) {
@@ -2342,8 +2343,17 @@ class HocuspocusProvider extends EventEmitter {
2342
2343
  forceSync: null,
2343
2344
  };
2344
2345
  this.isConnected = true;
2345
- this.boundBeforeUnload = this.beforeUnload.bind(this);
2346
2346
  this.boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this);
2347
+ this.boundBeforeUnload = this.beforeUnload.bind(this);
2348
+ this.boundOnOpen = this.onOpen.bind(this);
2349
+ this.boundOnMessage = this.onMessage.bind(this);
2350
+ this.boundOnClose = this.onClose.bind(this);
2351
+ this.boundOnStatus = this.onStatus.bind(this);
2352
+ this.forwardConnect = (e) => this.emit('connect', e);
2353
+ this.forwardOpen = (e) => this.emit('open', e);
2354
+ this.forwardClose = (e) => this.emit('close', e);
2355
+ this.forwardDisconnect = (e) => this.emit('disconnect', e);
2356
+ this.forwardDestroy = (e) => this.emit('destroy', e);
2347
2357
  this.setConfiguration(configuration);
2348
2358
  this.configuration.document = configuration.document ? configuration.document : new Y__namespace.Doc();
2349
2359
  this.configuration.awareness = configuration.awareness ? configuration.awareness : new Awareness(this.document);
@@ -2358,18 +2368,18 @@ class HocuspocusProvider extends EventEmitter {
2358
2368
  this.on('authenticated', this.configuration.onAuthenticated);
2359
2369
  this.on('authenticationFailed', this.configuration.onAuthenticationFailed);
2360
2370
  this.configuration.websocketProvider.on('connect', this.configuration.onConnect);
2361
- this.configuration.websocketProvider.on('connect', (e) => this.emit('connect', e));
2362
- this.configuration.websocketProvider.on('open', this.onOpen.bind(this));
2363
- this.configuration.websocketProvider.on('open', (e) => this.emit('open', e));
2364
- this.configuration.websocketProvider.on('message', this.onMessage.bind(this));
2365
- this.configuration.websocketProvider.on('close', this.onClose.bind(this));
2371
+ this.configuration.websocketProvider.on('connect', this.forwardConnect);
2372
+ this.configuration.websocketProvider.on('open', this.boundOnOpen);
2373
+ this.configuration.websocketProvider.on('open', this.forwardOpen);
2374
+ this.configuration.websocketProvider.on('message', this.boundOnMessage);
2375
+ this.configuration.websocketProvider.on('close', this.boundOnClose);
2366
2376
  this.configuration.websocketProvider.on('close', this.configuration.onClose);
2367
- this.configuration.websocketProvider.on('close', (e) => this.emit('close', e));
2368
- this.configuration.websocketProvider.on('status', this.onStatus.bind(this));
2377
+ this.configuration.websocketProvider.on('close', this.forwardClose);
2378
+ this.configuration.websocketProvider.on('status', this.boundOnStatus);
2369
2379
  this.configuration.websocketProvider.on('disconnect', this.configuration.onDisconnect);
2370
- this.configuration.websocketProvider.on('disconnect', (e) => this.emit('disconnect', e));
2380
+ this.configuration.websocketProvider.on('disconnect', this.forwardDisconnect);
2371
2381
  this.configuration.websocketProvider.on('destroy', this.configuration.onDestroy);
2372
- this.configuration.websocketProvider.on('destroy', (e) => this.emit('destroy', e));
2382
+ this.configuration.websocketProvider.on('destroy', this.forwardDestroy);
2373
2383
  this.awareness.on('update', () => {
2374
2384
  this.emit('awarenessUpdate', { states: common.awarenessStatesToArray(this.awareness.getStates()) });
2375
2385
  });
@@ -2534,6 +2544,19 @@ class HocuspocusProvider extends EventEmitter {
2534
2544
  this.awareness.off('update', this.awarenessUpdateHandler);
2535
2545
  this.document.off('update', this.documentUpdateHandler);
2536
2546
  this.removeAllListeners();
2547
+ this.configuration.websocketProvider.off('connect', this.configuration.onConnect);
2548
+ this.configuration.websocketProvider.off('connect', this.forwardConnect);
2549
+ this.configuration.websocketProvider.off('open', this.boundOnOpen);
2550
+ this.configuration.websocketProvider.off('open', this.forwardOpen);
2551
+ this.configuration.websocketProvider.off('message', this.boundOnMessage);
2552
+ this.configuration.websocketProvider.off('close', this.boundOnClose);
2553
+ this.configuration.websocketProvider.off('close', this.configuration.onClose);
2554
+ this.configuration.websocketProvider.off('close', this.forwardClose);
2555
+ this.configuration.websocketProvider.off('status', this.boundOnStatus);
2556
+ this.configuration.websocketProvider.off('disconnect', this.configuration.onDisconnect);
2557
+ this.configuration.websocketProvider.off('disconnect', this.forwardDisconnect);
2558
+ this.configuration.websocketProvider.off('destroy', this.configuration.onDestroy);
2559
+ this.configuration.websocketProvider.off('destroy', this.forwardDestroy);
2537
2560
  this.send(CloseMessage, { documentName: this.configuration.name });
2538
2561
  this.isConnected = false;
2539
2562
  if (typeof window === 'undefined') {