@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.
@@ -2081,7 +2081,7 @@ class HocuspocusProvider extends EventEmitter {
2081
2081
  });
2082
2082
  this.document.on('update', this.documentUpdateHandler.bind(this));
2083
2083
  this.awareness.on('update', this.awarenessUpdateHandler.bind(this));
2084
- this.registerBeforeUnloadEventListener();
2084
+ this.registerEventListeners();
2085
2085
  this.intervals.connectionChecker = setInterval(this.checkConnection.bind(this), this.options.messageReconnectTimeout / 10);
2086
2086
  if (this.options.forceSyncInterval) {
2087
2087
  this.intervals.forceSync = setInterval(this.forceSync.bind(this), this.options.forceSyncInterval);
@@ -2191,10 +2191,11 @@ class HocuspocusProvider extends EventEmitter {
2191
2191
  }
2192
2192
  this.send(SyncStepOneMessage, { document: this.document });
2193
2193
  }
2194
- registerBeforeUnloadEventListener() {
2194
+ registerEventListeners() {
2195
2195
  if (typeof window === 'undefined') {
2196
2196
  return;
2197
2197
  }
2198
+ window.addEventListener('online', this.connect.bind(this));
2198
2199
  window.addEventListener('beforeunload', () => {
2199
2200
  removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload');
2200
2201
  });
@@ -2359,6 +2360,10 @@ class HocuspocusProvider extends EventEmitter {
2359
2360
  this.awareness.off('update', this.awarenessUpdateHandler);
2360
2361
  this.document.off('update', this.documentUpdateHandler);
2361
2362
  this.removeAllListeners();
2363
+ if (typeof window === 'undefined') {
2364
+ return;
2365
+ }
2366
+ window.removeEventListener('online', this.connect.bind(this));
2362
2367
  }
2363
2368
  get broadcastChannel() {
2364
2369
  return `${this.serverUrl}/${this.options.name}`;