@ipcom/asterisk-ari 0.0.41 → 0.0.42

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.
@@ -1891,10 +1891,11 @@ var AriClient = class {
1891
1891
  }
1892
1892
  /**
1893
1893
  * Registra um listener para eventos globais.
1894
+ * @param eventType
1894
1895
  * @param callback - A função a ser executada quando um evento global for recebido.
1895
1896
  */
1896
- onGlobalEvent(callback) {
1897
- this.eventEmitter.on("globalEvent", callback);
1897
+ onGlobalEvent(eventType, callback) {
1898
+ this.eventEmitter.on(eventType, callback);
1898
1899
  }
1899
1900
  /**
1900
1901
  * Remove um listener para eventos globais.
@@ -2100,6 +2101,27 @@ var AriClient = class {
2100
2101
  }
2101
2102
  return this.channelEmitters.get(channel.id);
2102
2103
  }
2104
+ handleChannelEvent(event) {
2105
+ if ("channel" in event && event.channel) {
2106
+ const channelEmitter = this.channelEmitters.get(event.channel.id);
2107
+ if (channelEmitter) {
2108
+ channelEmitter.emit(event.type, event);
2109
+ } else {
2110
+ console.warn(
2111
+ `Nenhum listener registrado para o canal ${event.channel.id}`
2112
+ );
2113
+ }
2114
+ }
2115
+ }
2116
+ registerGlobalWebSocketListener() {
2117
+ this.wsClient?.on("message", (event) => {
2118
+ if ("channel" in event && event.channel) {
2119
+ this.handleChannelEvent(event);
2120
+ } else {
2121
+ this.eventEmitter.emit(event.type, event);
2122
+ }
2123
+ });
2124
+ }
2103
2125
  /**
2104
2126
  * Adiciona um listener para um evento específico de canal.
2105
2127
  */
@@ -2109,6 +2131,9 @@ var AriClient = class {
2109
2131
  throw new Error(`Canal com ID ${channelId} n\xE3o encontrado.`);
2110
2132
  }
2111
2133
  channelEmitter.on(eventType, callback);
2134
+ console.log(
2135
+ `Listener registrado para o canal ${channelId} e evento ${eventType}`
2136
+ );
2112
2137
  }
2113
2138
  removeChannel(channelId) {
2114
2139
  const channelEmitter = this.channelEmitters.get(channelId);