@hocuspocus/provider 2.7.1 → 2.8.1

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
@@ -1700,14 +1703,12 @@ class HocuspocusProviderWebsocket extends EventEmitter {
1700
1703
  quiet: false,
1701
1704
  providerMap: new Map(),
1702
1705
  };
1703
- this.subscribedToBroadcastChannel = false;
1704
1706
  this.webSocket = null;
1705
1707
  this.webSocketHandlers = {};
1706
1708
  this.shouldConnect = true;
1707
1709
  this.status = WebSocketStatus.Disconnected;
1708
1710
  this.lastMessageReceived = 0;
1709
1711
  this.identifier = 0;
1710
- this.mux = createMutex();
1711
1712
  this.intervals = {
1712
1713
  forceSync: null,
1713
1714
  connectionChecker: null,
@@ -1715,7 +1716,6 @@ class HocuspocusProviderWebsocket extends EventEmitter {
1715
1716
  this.connectionAttempt = null;
1716
1717
  this.receivedOnOpenPayload = undefined;
1717
1718
  this.receivedOnStatusPayload = undefined;
1718
- this.boundConnect = this.connect.bind(this);
1719
1719
  this.closeTries = 0;
1720
1720
  this.setConfiguration(configuration);
1721
1721
  this.configuration.WebSocketPolyfill = configuration.WebSocketPolyfill
@@ -2051,8 +2051,8 @@ class HocuspocusProviderWebsocket extends EventEmitter {
2051
2051
  * When the server receives SyncStep1, it should reply with SyncStep2 immediately followed by SyncStep1. The client replies
2052
2052
  * with SyncStep2 when it receives SyncStep1. Optionally the server may send a SyncDone after it received SyncStep2, so the
2053
2053
  * client knows that the sync is finished. There are two reasons for this more elaborated sync model: 1. This protocol can
2054
- * easily be implemented on top of http and websockets. 2. The server shoul only reply to requests, and not initiate them.
2055
- * 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.
2056
2056
  *
2057
2057
  * Construction of a message:
2058
2058
  * [messageType : varUint, message definition..]
@@ -2134,7 +2134,7 @@ const readUpdate = readSyncStep2;
2134
2134
 
2135
2135
  /**
2136
2136
  * @param {decoding.Decoder} decoder A message received from another client
2137
- * @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.
2138
2138
  * @param {Y.Doc} doc
2139
2139
  * @param {any} transactionOrigin
2140
2140
  */
@@ -2599,12 +2599,14 @@ class HocuspocusProvider extends EventEmitter {
2599
2599
  disconnect() {
2600
2600
  this.disconnectBroadcastChannel();
2601
2601
  this.configuration.websocketProvider.detach(this);
2602
+ this.isConnected = false;
2602
2603
  if (!this.configuration.preserveConnection) {
2603
2604
  this.configuration.websocketProvider.disconnect();
2604
2605
  }
2605
2606
  }
2606
2607
  async onOpen(event) {
2607
2608
  this.isAuthenticated = false;
2609
+ this.isConnected = true;
2608
2610
  this.emit('open', { event });
2609
2611
  let token;
2610
2612
  try {
@@ -2675,7 +2677,6 @@ class HocuspocusProvider extends EventEmitter {
2675
2677
  if (this.awareness) {
2676
2678
  removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy');
2677
2679
  }
2678
- this.disconnect();
2679
2680
  (_a = this.awareness) === null || _a === void 0 ? void 0 : _a.off('update', this.awarenessUpdateHandler);
2680
2681
  this.document.off('update', this.documentUpdateHandler);
2681
2682
  this.removeAllListeners();
@@ -2692,7 +2693,7 @@ class HocuspocusProvider extends EventEmitter {
2692
2693
  this.configuration.websocketProvider.off('destroy', this.configuration.onDestroy);
2693
2694
  this.configuration.websocketProvider.off('destroy', this.forwardDestroy);
2694
2695
  this.send(CloseMessage, { documentName: this.configuration.name });
2695
- this.isConnected = false;
2696
+ this.disconnect();
2696
2697
  if (typeof window === 'undefined') {
2697
2698
  return;
2698
2699
  }