@ipcom/asterisk-ari 0.0.33 → 0.0.34

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.
package/dist/esm/index.js CHANGED
@@ -1677,6 +1677,7 @@ var AriClient = class {
1677
1677
  isReconnecting = false;
1678
1678
  eventEmitter = new EventEmitter4();
1679
1679
  wsConnections = /* @__PURE__ */ new Map();
1680
+ isWebSocketConnectedFlag = false;
1680
1681
  channels;
1681
1682
  endpoints;
1682
1683
  applications;
@@ -1728,17 +1729,21 @@ var AriClient = class {
1728
1729
  };
1729
1730
  try {
1730
1731
  await (0, import_exponential_backoff.backOff)(async () => {
1731
- await wsClient.connect();
1732
- this.integrateWebSocketEvents(app, wsClient);
1732
+ if (!this.wsClient) {
1733
+ throw new Error("WebSocketClient instance is null.");
1734
+ }
1735
+ await this.wsClient.connect();
1736
+ this.isWebSocketConnectedFlag = true;
1737
+ this.integrateWebSocketEvents(app, this.wsClient);
1733
1738
  console.log(`WebSocket conectado para o app: ${app}`);
1734
1739
  await this.ensureAppRegistered(app);
1735
1740
  }, backoffOptions);
1736
1741
  } catch (err) {
1742
+ this.isWebSocketConnectedFlag = false;
1737
1743
  console.error(
1738
- `N\xE3o foi poss\xEDvel conectar ao WebSocket para o app ${app}:`,
1744
+ "N\xE3o foi poss\xEDvel conectar ao WebSocket ap\xF3s m\xFAltiplas tentativas:",
1739
1745
  err
1740
1746
  );
1741
- this.wsConnections.delete(app);
1742
1747
  throw err;
1743
1748
  }
1744
1749
  }
@@ -1899,9 +1904,12 @@ var AriClient = class {
1899
1904
  * @throws {Error} Throws an error if the WebSocket client is not connected when this method is called.
1900
1905
  * @returns {void} This function doesn't return a value.
1901
1906
  */
1902
- onWebSocketEvent(event, callback) {
1907
+ async onWebSocketEvent(event, callback) {
1908
+ if (!this.isWebSocketConnectedFlag) {
1909
+ throw new Error("WebSocket ainda n\xE3o est\xE1 conectado.");
1910
+ }
1903
1911
  if (!this.wsClient) {
1904
- throw new Error("WebSocket n\xE3o est\xE1 conectado.");
1912
+ throw new Error("WebSocket n\xE3o est\xE1 configurado.");
1905
1913
  }
1906
1914
  this.wsClient.on(event, callback);
1907
1915
  }