@hocuspocus/provider 1.0.0-alpha.27 → 1.0.0-alpha.28

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.
@@ -2057,7 +2057,7 @@ class HocuspocusProvider extends EventEmitter {
2057
2057
  });
2058
2058
  this.document.on('update', this.documentUpdateHandler.bind(this));
2059
2059
  this.awareness.on('update', this.awarenessUpdateHandler.bind(this));
2060
- this.registerBeforeUnloadEventListener();
2060
+ this.registerEventListeners();
2061
2061
  this.intervals.connectionChecker = setInterval(this.checkConnection.bind(this), this.options.messageReconnectTimeout / 10);
2062
2062
  if (this.options.forceSyncInterval) {
2063
2063
  this.intervals.forceSync = setInterval(this.forceSync.bind(this), this.options.forceSyncInterval);
@@ -2167,10 +2167,11 @@ class HocuspocusProvider extends EventEmitter {
2167
2167
  }
2168
2168
  this.send(SyncStepOneMessage, { document: this.document });
2169
2169
  }
2170
- registerBeforeUnloadEventListener() {
2170
+ registerEventListeners() {
2171
2171
  if (typeof window === 'undefined') {
2172
2172
  return;
2173
2173
  }
2174
+ window.addEventListener('online', this.connect.bind(this));
2174
2175
  window.addEventListener('beforeunload', () => {
2175
2176
  removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload');
2176
2177
  });
@@ -2335,6 +2336,10 @@ class HocuspocusProvider extends EventEmitter {
2335
2336
  this.awareness.off('update', this.awarenessUpdateHandler);
2336
2337
  this.document.off('update', this.documentUpdateHandler);
2337
2338
  this.removeAllListeners();
2339
+ if (typeof window === 'undefined') {
2340
+ return;
2341
+ }
2342
+ window.removeEventListener('online', this.connect.bind(this));
2338
2343
  }
2339
2344
  get broadcastChannel() {
2340
2345
  return `${this.serverUrl}/${this.options.name}`;