@ipcom/asterisk-ari 0.0.123 → 0.0.125

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.
@@ -1919,12 +1919,14 @@ var WebSocketClient = class extends import_events3.EventEmitter {
1919
1919
  */
1920
1920
  addScopedMessageListener(instanceId, app, callback) {
1921
1921
  const key = `${app}:${instanceId}`;
1922
- if (this.scopedListeners.has(key)) {
1923
- console.warn(
1924
- `Listener escopado para a inst\xE2ncia '${key}' j\xE1 existe. Ignorando duplicata.`
1925
- );
1922
+ if (key.includes("removeListener")) {
1923
+ console.warn(`Evento interno ignorado: '${key}'.`);
1926
1924
  return;
1927
1925
  }
1926
+ if (this.scopedListeners.has(key)) {
1927
+ console.warn(`Listener escopado j\xE1 existe para '${key}'. Substituindo.`);
1928
+ this.removeScopedMessageListeners(instanceId, app);
1929
+ }
1928
1930
  const scopedListener = (data) => {
1929
1931
  if (data.application === app && (data.type.startsWith("Channel") && "channel" in data && data.channel?.id === instanceId || data.type.startsWith("Playback") && "playbackId" in data && data.playbackId === instanceId)) {
1930
1932
  callback(data);
@@ -1933,7 +1935,7 @@ var WebSocketClient = class extends import_events3.EventEmitter {
1933
1935
  this.on("message", scopedListener);
1934
1936
  this.scopedListeners.set(key, scopedListener);
1935
1937
  console.log(
1936
- `Listener escopado adicionado para a inst\xE2ncia '${key}'. Total de listeners: ${this.listenerCount(
1938
+ `Listener escopado adicionado para '${key}'. Total de listeners: ${this.listenerCount(
1937
1939
  "message"
1938
1940
  )}`
1939
1941
  );
@@ -1952,10 +1954,11 @@ var WebSocketClient = class extends import_events3.EventEmitter {
1952
1954
  return;
1953
1955
  }
1954
1956
  if (this.listeners("message").includes(scopedListener)) {
1957
+ console.log(`Removendo listener escopado para '${key}'.`);
1955
1958
  this.off("message", scopedListener);
1956
- console.log(`Listener escopado removido para '${key}'.`);
1959
+ console.log(`Listener removido com sucesso para '${key}'.`);
1957
1960
  } else {
1958
- console.warn(`Listener j\xE1 foi removido para '${key}'.`);
1961
+ console.warn(`Listener j\xE1 foi removido ou n\xE3o encontrado para '${key}'.`);
1959
1962
  }
1960
1963
  this.scopedListeners.delete(key);
1961
1964
  console.log(
@@ -1963,6 +1966,17 @@ var WebSocketClient = class extends import_events3.EventEmitter {
1963
1966
  "message"
1964
1967
  )}`
1965
1968
  );
1969
+ const removeKey = `${key}:removeListener`;
1970
+ const removeListener = this.scopedListeners.get(removeKey);
1971
+ if (removeListener) {
1972
+ this.off("message", removeListener);
1973
+ this.scopedListeners.delete(removeKey);
1974
+ console.log(
1975
+ `Listener de 'removeListener' tamb\xE9m foi removido para '${key}'.`
1976
+ );
1977
+ }
1978
+ console.log("Depois de remover listeners:");
1979
+ this.listListeners("message");
1966
1980
  }
1967
1981
  /**
1968
1982
  * Handles incoming WebSocket messages.