@ipcom/asterisk-ari 0.0.35 → 0.0.37

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
@@ -1678,6 +1678,23 @@ var AriClient = class {
1678
1678
  eventEmitter = new EventEmitter4();
1679
1679
  wsConnections = /* @__PURE__ */ new Map();
1680
1680
  isWebSocketConnectedFlag = false;
1681
+ pendingListeners = [];
1682
+ processPendingListeners() {
1683
+ if (!this.wsClient || !this.isWebSocketConnectedFlag) {
1684
+ console.warn(
1685
+ "WebSocket ainda n\xE3o est\xE1 pronto. N\xE3o \xE9 poss\xEDvel processar a fila."
1686
+ );
1687
+ return;
1688
+ }
1689
+ console.log(
1690
+ `Processando ${this.pendingListeners.length} listeners pendentes...`
1691
+ );
1692
+ while (this.pendingListeners.length > 0) {
1693
+ const { event, callback } = this.pendingListeners.shift();
1694
+ console.log(`Registrando listener pendente para evento: ${event}`);
1695
+ this.wsClient.on(event, callback);
1696
+ }
1697
+ }
1681
1698
  channels;
1682
1699
  endpoints;
1683
1700
  applications;
@@ -1736,14 +1753,12 @@ var AriClient = class {
1736
1753
  if (!this.wsClient) {
1737
1754
  throw new Error("WebSocketClient instance is null.");
1738
1755
  }
1739
- if (!this.wsClient.isConnected()) {
1740
- console.log("Tentando conectar ao WebSocket...");
1741
- await this.wsClient.connect();
1742
- }
1756
+ await this.wsClient.connect();
1757
+ this.integrateWebSocketEvents(app, this.wsClient);
1758
+ console.log(`WebSocket conectado para o app: ${app}`);
1759
+ await this.ensureAppRegistered(app);
1760
+ this.processPendingListeners();
1743
1761
  }, backoffOptions);
1744
- this.integrateWebSocketEvents(app, this.wsClient);
1745
- console.log(`WebSocket conectado para o app: ${app}`);
1746
- await this.ensureAppRegistered(app);
1747
1762
  } catch (err) {
1748
1763
  console.error(
1749
1764
  "N\xE3o foi poss\xEDvel conectar ao WebSocket ap\xF3s m\xFAltiplas tentativas:",
@@ -1911,13 +1926,15 @@ var AriClient = class {
1911
1926
  * @throws {Error} Throws an error if the WebSocket client is not connected when this method is called.
1912
1927
  * @returns {void} This function doesn't return a value.
1913
1928
  */
1914
- async onWebSocketEvent(event, callback) {
1915
- if (!this.isWebSocketConnectedFlag) {
1916
- throw new Error("WebSocket ainda n\xE3o est\xE1 conectado.");
1917
- }
1918
- if (!this.wsClient) {
1919
- throw new Error("WebSocket n\xE3o est\xE1 configurado.");
1929
+ onWebSocketEvent(event, callback) {
1930
+ if (!this.wsClient || !this.isWebSocketConnectedFlag) {
1931
+ console.warn(
1932
+ `WebSocket ainda n\xE3o est\xE1 conectado. Colocando o listener na fila para: ${event}`
1933
+ );
1934
+ this.pendingListeners.push({ event, callback });
1935
+ return;
1920
1936
  }
1937
+ console.log(`Registrando listener para evento: ${event}`);
1921
1938
  this.wsClient.on(event, callback);
1922
1939
  }
1923
1940
  /**