@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.
@@ -221,7 +221,7 @@ let usePolyfill = true;
221
221
  /* c8 ignore start */
222
222
  try {
223
223
  // if the same-origin rule is violated, accessing localStorage might thrown an error
224
- if (typeof localStorage !== 'undefined') {
224
+ if (typeof localStorage !== 'undefined' && localStorage) {
225
225
  _localStorage = localStorage;
226
226
  usePolyfill = false;
227
227
  }
@@ -406,10 +406,10 @@ const isOneOf = (value, options) => options.includes(value);
406
406
  * @module map
407
407
  */
408
408
 
409
- /* c8 ignore next */
409
+ /* c8 ignore next 2 */
410
410
  // @ts-ignore
411
- const isNode = typeof process !== 'undefined' && process.release &&
412
- /node|io\.js/.test(process.release.name);
411
+ 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]';
412
+
413
413
  /* c8 ignore next */
414
414
  const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && !isNode;
415
415
  /* c8 ignore next 3 */
@@ -621,7 +621,7 @@ const toUint8Array = encoder => {
621
621
  uint8arr.set(d, curPos);
622
622
  curPos += d.length;
623
623
  }
624
- uint8arr.set(createUint8ArrayViewFromArrayBuffer(encoder.cbuf.buffer, 0, encoder.cpos), curPos);
624
+ uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos);
625
625
  return uint8arr
626
626
  };
627
627
 
@@ -834,7 +834,7 @@ const createDecoder = uint8Array => new Decoder(uint8Array);
834
834
  * @return {Uint8Array}
835
835
  */
836
836
  const readUint8Array = (decoder, len) => {
837
- const view = createUint8ArrayViewFromArrayBuffer(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
837
+ const view = new Uint8Array(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
838
838
  decoder.pos += len;
839
839
  return view
840
840
  };
@@ -1071,7 +1071,7 @@ const fromBase64Browser = s => {
1071
1071
  */
1072
1072
  const fromBase64Node = s => {
1073
1073
  const buf = Buffer.from(s, 'base64');
1074
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength)
1074
+ return createUint8ArrayViewFromArrayBuffer(buf.buffer, buf.byteOffset, buf.byteLength)
1075
1075
  };
1076
1076
 
1077
1077
  /* c8 ignore next */
@@ -1252,9 +1252,11 @@ const getUnixTime = Date.now;
1252
1252
  * @module observable
1253
1253
  */
1254
1254
 
1255
+ /* c8 ignore start */
1255
1256
  /**
1256
1257
  * Handles named events.
1257
1258
  *
1259
+ * @deprecated
1258
1260
  * @template N
1259
1261
  */
1260
1262
  class Observable {
@@ -1321,6 +1323,7 @@ class Observable {
1321
1323
  this._observers = create$2();
1322
1324
  }
1323
1325
  }
1326
+ /* c8 ignore end */
1324
1327
 
1325
1328
  /**
1326
1329
  * @module awareness-protocol
@@ -1724,14 +1727,12 @@ class HocuspocusProviderWebsocket extends EventEmitter {
1724
1727
  quiet: false,
1725
1728
  providerMap: new Map(),
1726
1729
  };
1727
- this.subscribedToBroadcastChannel = false;
1728
1730
  this.webSocket = null;
1729
1731
  this.webSocketHandlers = {};
1730
1732
  this.shouldConnect = true;
1731
1733
  this.status = exports.WebSocketStatus.Disconnected;
1732
1734
  this.lastMessageReceived = 0;
1733
1735
  this.identifier = 0;
1734
- this.mux = createMutex();
1735
1736
  this.intervals = {
1736
1737
  forceSync: null,
1737
1738
  connectionChecker: null,
@@ -1739,7 +1740,6 @@ class HocuspocusProviderWebsocket extends EventEmitter {
1739
1740
  this.connectionAttempt = null;
1740
1741
  this.receivedOnOpenPayload = undefined;
1741
1742
  this.receivedOnStatusPayload = undefined;
1742
- this.boundConnect = this.connect.bind(this);
1743
1743
  this.closeTries = 0;
1744
1744
  this.setConfiguration(configuration);
1745
1745
  this.configuration.WebSocketPolyfill = configuration.WebSocketPolyfill
@@ -2075,8 +2075,8 @@ class HocuspocusProviderWebsocket extends EventEmitter {
2075
2075
  * When the server receives SyncStep1, it should reply with SyncStep2 immediately followed by SyncStep1. The client replies
2076
2076
  * with SyncStep2 when it receives SyncStep1. Optionally the server may send a SyncDone after it received SyncStep2, so the
2077
2077
  * client knows that the sync is finished. There are two reasons for this more elaborated sync model: 1. This protocol can
2078
- * easily be implemented on top of http and websockets. 2. The server shoul only reply to requests, and not initiate them.
2079
- * Therefore it is necesarry that the client initiates the sync.
2078
+ * easily be implemented on top of http and websockets. 2. The server should only reply to requests, and not initiate them.
2079
+ * Therefore it is necessary that the client initiates the sync.
2080
2080
  *
2081
2081
  * Construction of a message:
2082
2082
  * [messageType : varUint, message definition..]
@@ -2158,7 +2158,7 @@ const readUpdate = readSyncStep2;
2158
2158
 
2159
2159
  /**
2160
2160
  * @param {decoding.Decoder} decoder A message received from another client
2161
- * @param {encoding.Encoder} encoder The reply message. Will not be sent if empty.
2161
+ * @param {encoding.Encoder} encoder The reply message. Does not need to be sent if empty.
2162
2162
  * @param {Y.Doc} doc
2163
2163
  * @param {any} transactionOrigin
2164
2164
  */
@@ -2623,12 +2623,14 @@ class HocuspocusProvider extends EventEmitter {
2623
2623
  disconnect() {
2624
2624
  this.disconnectBroadcastChannel();
2625
2625
  this.configuration.websocketProvider.detach(this);
2626
+ this.isConnected = false;
2626
2627
  if (!this.configuration.preserveConnection) {
2627
2628
  this.configuration.websocketProvider.disconnect();
2628
2629
  }
2629
2630
  }
2630
2631
  async onOpen(event) {
2631
2632
  this.isAuthenticated = false;
2633
+ this.isConnected = true;
2632
2634
  this.emit('open', { event });
2633
2635
  let token;
2634
2636
  try {
@@ -2699,7 +2701,6 @@ class HocuspocusProvider extends EventEmitter {
2699
2701
  if (this.awareness) {
2700
2702
  removeAwarenessStates(this.awareness, [this.document.clientID], 'provider destroy');
2701
2703
  }
2702
- this.disconnect();
2703
2704
  (_a = this.awareness) === null || _a === void 0 ? void 0 : _a.off('update', this.awarenessUpdateHandler);
2704
2705
  this.document.off('update', this.documentUpdateHandler);
2705
2706
  this.removeAllListeners();
@@ -2716,7 +2717,7 @@ class HocuspocusProvider extends EventEmitter {
2716
2717
  this.configuration.websocketProvider.off('destroy', this.configuration.onDestroy);
2717
2718
  this.configuration.websocketProvider.off('destroy', this.forwardDestroy);
2718
2719
  this.send(CloseMessage, { documentName: this.configuration.name });
2719
- this.isConnected = false;
2720
+ this.disconnect();
2720
2721
  if (typeof window === 'undefined') {
2721
2722
  return;
2722
2723
  }