@ipcom/asterisk-ari 0.0.36 → 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.
@@ -1700,6 +1700,23 @@ var AriClient = class {
1700
1700
  eventEmitter = new import_events4.EventEmitter();
1701
1701
  wsConnections = /* @__PURE__ */ new Map();
1702
1702
  isWebSocketConnectedFlag = false;
1703
+ pendingListeners = [];
1704
+ processPendingListeners() {
1705
+ if (!this.wsClient || !this.isWebSocketConnectedFlag) {
1706
+ console.warn(
1707
+ "WebSocket ainda n\xE3o est\xE1 pronto. N\xE3o \xE9 poss\xEDvel processar a fila."
1708
+ );
1709
+ return;
1710
+ }
1711
+ console.log(
1712
+ `Processando ${this.pendingListeners.length} listeners pendentes...`
1713
+ );
1714
+ while (this.pendingListeners.length > 0) {
1715
+ const { event, callback } = this.pendingListeners.shift();
1716
+ console.log(`Registrando listener pendente para evento: ${event}`);
1717
+ this.wsClient.on(event, callback);
1718
+ }
1719
+ }
1703
1720
  channels;
1704
1721
  endpoints;
1705
1722
  applications;
@@ -1758,14 +1775,12 @@ var AriClient = class {
1758
1775
  if (!this.wsClient) {
1759
1776
  throw new Error("WebSocketClient instance is null.");
1760
1777
  }
1761
- if (!this.wsClient.isConnected()) {
1762
- console.log("Tentando conectar ao WebSocket...");
1763
- await this.wsClient.connect();
1764
- }
1778
+ await this.wsClient.connect();
1779
+ this.integrateWebSocketEvents(app, this.wsClient);
1780
+ console.log(`WebSocket conectado para o app: ${app}`);
1781
+ await this.ensureAppRegistered(app);
1782
+ this.processPendingListeners();
1765
1783
  }, backoffOptions);
1766
- this.integrateWebSocketEvents(app, this.wsClient);
1767
- console.log(`WebSocket conectado para o app: ${app}`);
1768
- await this.ensureAppRegistered(app);
1769
1784
  } catch (err) {
1770
1785
  console.error(
1771
1786
  "N\xE3o foi poss\xEDvel conectar ao WebSocket ap\xF3s m\xFAltiplas tentativas:",
@@ -1934,14 +1949,11 @@ var AriClient = class {
1934
1949
  * @returns {void} This function doesn't return a value.
1935
1950
  */
1936
1951
  onWebSocketEvent(event, callback) {
1937
- if (!this.wsClient) {
1938
- console.error("WebSocket n\xE3o est\xE1 configurado.");
1939
- return;
1940
- }
1941
- if (!this.isWebSocketConnectedFlag) {
1952
+ if (!this.wsClient || !this.isWebSocketConnectedFlag) {
1942
1953
  console.warn(
1943
- "WebSocket ainda n\xE3o est\xE1 conectado. Tentando reconectar..."
1954
+ `WebSocket ainda n\xE3o est\xE1 conectado. Colocando o listener na fila para: ${event}`
1944
1955
  );
1956
+ this.pendingListeners.push({ event, callback });
1945
1957
  return;
1946
1958
  }
1947
1959
  console.log(`Registrando listener para evento: ${event}`);