@hocuspocus/provider 2.8.0 → 2.9.0-rc.0

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.
@@ -197,7 +197,7 @@ let usePolyfill = true;
197
197
  /* c8 ignore start */
198
198
  try {
199
199
  // if the same-origin rule is violated, accessing localStorage might thrown an error
200
- if (typeof localStorage !== 'undefined') {
200
+ if (typeof localStorage !== 'undefined' && localStorage) {
201
201
  _localStorage = localStorage;
202
202
  usePolyfill = false;
203
203
  }
@@ -382,10 +382,10 @@ const isOneOf = (value, options) => options.includes(value);
382
382
  * @module map
383
383
  */
384
384
 
385
- /* c8 ignore next */
385
+ /* c8 ignore next 2 */
386
386
  // @ts-ignore
387
- const isNode = typeof process !== 'undefined' && process.release &&
388
- /node|io\.js/.test(process.release.name);
387
+ const isNode = typeof process !== 'undefined' && process.release && /node|io\.js/.test(process.release.name) && Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
388
+
389
389
  /* c8 ignore next */
390
390
  const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && !isNode;
391
391
  /* c8 ignore next 3 */
@@ -597,7 +597,7 @@ const toUint8Array = encoder => {
597
597
  uint8arr.set(d, curPos);
598
598
  curPos += d.length;
599
599
  }
600
- uint8arr.set(createUint8ArrayViewFromArrayBuffer(encoder.cbuf.buffer, 0, encoder.cpos), curPos);
600
+ uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos);
601
601
  return uint8arr
602
602
  };
603
603
 
@@ -810,7 +810,7 @@ const createDecoder = uint8Array => new Decoder(uint8Array);
810
810
  * @return {Uint8Array}
811
811
  */
812
812
  const readUint8Array = (decoder, len) => {
813
- const view = createUint8ArrayViewFromArrayBuffer(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
813
+ const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
814
814
  decoder.pos += len;
815
815
  return view
816
816
  };
@@ -1047,7 +1047,7 @@ const fromBase64Browser = s => {
1047
1047
  */
1048
1048
  const fromBase64Node = s => {
1049
1049
  const buf = Buffer.from(s, 'base64');
1050
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength)
1050
+ return createUint8ArrayViewFromArrayBuffer(buf.buffer, buf.byteOffset, buf.byteLength)
1051
1051
  };
1052
1052
 
1053
1053
  /* c8 ignore next */
@@ -1228,9 +1228,11 @@ const getUnixTime = Date.now;
1228
1228
  * @module observable
1229
1229
  */
1230
1230
 
1231
+ /* c8 ignore start */
1231
1232
  /**
1232
1233
  * Handles named events.
1233
1234
  *
1235
+ * @deprecated
1234
1236
  * @template N
1235
1237
  */
1236
1238
  class Observable {
@@ -1297,6 +1299,7 @@ class Observable {
1297
1299
  this._observers = create$2();
1298
1300
  }
1299
1301
  }
1302
+ /* c8 ignore end */
1300
1303
 
1301
1304
  /**
1302
1305
  * @module awareness-protocol
@@ -2048,8 +2051,8 @@ class HocuspocusProviderWebsocket extends EventEmitter {
2048
2051
  * When the server receives SyncStep1, it should reply with SyncStep2 immediately followed by SyncStep1. The client replies
2049
2052
  * with SyncStep2 when it receives SyncStep1. Optionally the server may send a SyncDone after it received SyncStep2, so the
2050
2053
  * client knows that the sync is finished. There are two reasons for this more elaborated sync model: 1. This protocol can
2051
- * easily be implemented on top of http and websockets. 2. The server shoul only reply to requests, and not initiate them.
2052
- * Therefore it is necesarry that the client initiates the sync.
2054
+ * easily be implemented on top of http and websockets. 2. The server should only reply to requests, and not initiate them.
2055
+ * Therefore it is necessary that the client initiates the sync.
2053
2056
  *
2054
2057
  * Construction of a message:
2055
2058
  * [messageType : varUint, message definition..]
@@ -2131,7 +2134,7 @@ const readUpdate = readSyncStep2;
2131
2134
 
2132
2135
  /**
2133
2136
  * @param {decoding.Decoder} decoder A message received from another client
2134
- * @param {encoding.Encoder} encoder The reply message. Will not be sent if empty.
2137
+ * @param {encoding.Encoder} encoder The reply message. Does not need to be sent if empty.
2135
2138
  * @param {Y.Doc} doc
2136
2139
  * @param {any} transactionOrigin
2137
2140
  */
@@ -2666,15 +2669,15 @@ class HocuspocusProvider extends EventEmitter {
2666
2669
  }
2667
2670
  }
2668
2671
  destroy() {
2669
- var _a;
2670
2672
  this.emit('destroy');
2671
2673
  if (this.intervals.forceSync) {
2672
2674
  clearInterval(this.intervals.forceSync);
2673
2675
  }
2674
2676
  if (this.awareness) {
2675
2677
  removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy');
2678
+ this.awareness.off('update', this.awarenessUpdateHandler);
2679
+ this.awareness.destroy();
2676
2680
  }
2677
- (_a = this.awareness) === null || _a === void 0 ? void 0 : _a.off('update', this.awarenessUpdateHandler);
2678
2681
  this.document.off('update', this.documentUpdateHandler);
2679
2682
  this.removeAllListeners();
2680
2683
  this.configuration.websocketProvider.off('connect', this.configuration.onConnect);
@@ -2706,7 +2709,6 @@ class HocuspocusProvider extends EventEmitter {
2706
2709
  this.isAuthenticated = true;
2707
2710
  this.authorizedScope = scope;
2708
2711
  this.emit('authenticated');
2709
- this.startSync();
2710
2712
  }
2711
2713
  get broadcastChannel() {
2712
2714
  return `${this.configuration.name}`;