@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.
@@ -1909,25 +1909,26 @@ class HocuspocusProvider extends EventEmitter {
1909
1909
  },
1910
1910
  });
1911
1911
  }
1912
- catch (err) {
1913
- // If we aborted the connection attempt then don't throw an error
1912
+ catch (error) {
1913
+ // If we aborted the connection attempt then dont throw an error
1914
1914
  // ref: https://github.com/lifeomic/attempt/blob/master/src/index.ts#L136
1915
- if (err.code !== 'ATTEMPT_ABORTED') {
1916
- throw err;
1915
+ if (error && error.code !== 'ATTEMPT_ABORTED') {
1916
+ throw error;
1917
1917
  }
1918
1918
  }
1919
1919
  }
1920
1920
  createWebSocketConnection() {
1921
1921
  return new Promise((resolve, reject) => {
1922
1922
  // Init the WebSocket connection
1923
- this.webSocket = new this.options.WebSocketPolyfill(this.url);
1924
- this.webSocket.binaryType = 'arraybuffer';
1925
- this.webSocket.onmessage = this.onMessage.bind(this);
1926
- this.webSocket.onclose = this.onClose.bind(this);
1927
- this.webSocket.onopen = this.onOpen.bind(this);
1928
- this.webSocket.onerror = () => {
1923
+ const ws = new this.options.WebSocketPolyfill(this.url);
1924
+ ws.binaryType = 'arraybuffer';
1925
+ ws.onmessage = this.onMessage.bind(this);
1926
+ ws.onclose = this.onClose.bind(this);
1927
+ ws.onopen = this.onOpen.bind(this);
1928
+ ws.onerror = () => {
1929
1929
  reject();
1930
1930
  };
1931
+ this.webSocket = ws;
1931
1932
  // Reset the status
1932
1933
  this.synced = false;
1933
1934
  this.status = exports.WebSocketStatus.Connecting;
@@ -1956,6 +1957,7 @@ class HocuspocusProvider extends EventEmitter {
1956
1957
  return this.options.awareness;
1957
1958
  }
1958
1959
  checkConnection() {
1960
+ var _a;
1959
1961
  // Don’t check the connection when it’s not even established
1960
1962
  if (this.status !== exports.WebSocketStatus.Connected) {
1961
1963
  return;
@@ -1970,7 +1972,7 @@ class HocuspocusProvider extends EventEmitter {
1970
1972
  }
1971
1973
  // No message received in a long time, not even your own
1972
1974
  // Awareness updates, which are updated every 15 seconds.
1973
- this.webSocket.close();
1975
+ (_a = this.webSocket) === null || _a === void 0 ? void 0 : _a.close();
1974
1976
  }
1975
1977
  forceSync() {
1976
1978
  if (!this.webSocket) {
@@ -2071,7 +2073,6 @@ class HocuspocusProvider extends EventEmitter {
2071
2073
  return;
2072
2074
  }
2073
2075
  this.startSync();
2074
- this.resolveConnectionAttempt();
2075
2076
  }
2076
2077
  startSync() {
2077
2078
  this.send(SyncStepOneMessage, { document: this.document });
@@ -2093,6 +2094,7 @@ class HocuspocusProvider extends EventEmitter {
2093
2094
  }
2094
2095
  }
2095
2096
  onMessage(event) {
2097
+ this.resolveConnectionAttempt();
2096
2098
  this.lastMessageReceived = getUnixTime();
2097
2099
  const message = new IncomingMessage(event.data);
2098
2100
  this.emit('message', { event, message });