@hocuspocus/provider 1.0.0-alpha.19 → 1.0.0-alpha.23

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.
@@ -1885,25 +1885,26 @@ class HocuspocusProvider extends EventEmitter {
1885
1885
  },
1886
1886
  });
1887
1887
  }
1888
- catch (err) {
1889
- // If we aborted the connection attempt then don't throw an error
1888
+ catch (error) {
1889
+ // If we aborted the connection attempt then dont throw an error
1890
1890
  // ref: https://github.com/lifeomic/attempt/blob/master/src/index.ts#L136
1891
- if (err.code !== 'ATTEMPT_ABORTED') {
1892
- throw err;
1891
+ if (error && error.code !== 'ATTEMPT_ABORTED') {
1892
+ throw error;
1893
1893
  }
1894
1894
  }
1895
1895
  }
1896
1896
  createWebSocketConnection() {
1897
1897
  return new Promise((resolve, reject) => {
1898
1898
  // Init the WebSocket connection
1899
- this.webSocket = new this.options.WebSocketPolyfill(this.url);
1900
- this.webSocket.binaryType = 'arraybuffer';
1901
- this.webSocket.onmessage = this.onMessage.bind(this);
1902
- this.webSocket.onclose = this.onClose.bind(this);
1903
- this.webSocket.onopen = this.onOpen.bind(this);
1904
- this.webSocket.onerror = () => {
1899
+ const ws = new this.options.WebSocketPolyfill(this.url);
1900
+ ws.binaryType = 'arraybuffer';
1901
+ ws.onmessage = this.onMessage.bind(this);
1902
+ ws.onclose = this.onClose.bind(this);
1903
+ ws.onopen = this.onOpen.bind(this);
1904
+ ws.onerror = () => {
1905
1905
  reject();
1906
1906
  };
1907
+ this.webSocket = ws;
1907
1908
  // Reset the status
1908
1909
  this.synced = false;
1909
1910
  this.status = WebSocketStatus.Connecting;
@@ -1932,6 +1933,7 @@ class HocuspocusProvider extends EventEmitter {
1932
1933
  return this.options.awareness;
1933
1934
  }
1934
1935
  checkConnection() {
1936
+ var _a;
1935
1937
  // Don’t check the connection when it’s not even established
1936
1938
  if (this.status !== WebSocketStatus.Connected) {
1937
1939
  return;
@@ -1946,7 +1948,7 @@ class HocuspocusProvider extends EventEmitter {
1946
1948
  }
1947
1949
  // No message received in a long time, not even your own
1948
1950
  // Awareness updates, which are updated every 15 seconds.
1949
- this.webSocket.close();
1951
+ (_a = this.webSocket) === null || _a === void 0 ? void 0 : _a.close();
1950
1952
  }
1951
1953
  forceSync() {
1952
1954
  if (!this.webSocket) {
@@ -2047,7 +2049,6 @@ class HocuspocusProvider extends EventEmitter {
2047
2049
  return;
2048
2050
  }
2049
2051
  this.startSync();
2050
- this.resolveConnectionAttempt();
2051
2052
  }
2052
2053
  startSync() {
2053
2054
  this.send(SyncStepOneMessage, { document: this.document });
@@ -2069,6 +2070,7 @@ class HocuspocusProvider extends EventEmitter {
2069
2070
  }
2070
2071
  }
2071
2072
  onMessage(event) {
2073
+ this.resolveConnectionAttempt();
2072
2074
  this.lastMessageReceived = getUnixTime();
2073
2075
  const message = new IncomingMessage(event.data);
2074
2076
  this.emit('message', { event, message });