@ipcom/asterisk-ari 0.0.117 → 0.0.119

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.
@@ -1912,29 +1912,19 @@ var WebSocketClient = class extends import_events3.EventEmitter {
1912
1912
  const key = `${app}:${instanceId}`;
1913
1913
  if (this.scopedListeners.has(key)) {
1914
1914
  console.warn(
1915
- `Listener escopado para a inst\xE2ncia '${key}' j\xE1 existe. Ignorando.`
1915
+ `Listener escopado para a inst\xE2ncia '${key}' j\xE1 existe. Ignorando duplicata.`
1916
1916
  );
1917
1917
  return;
1918
1918
  }
1919
1919
  const scopedListener = (data) => {
1920
- try {
1921
- 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)) {
1922
- console.log(
1923
- `Listener escopado ativado para inst\xE2ncia '${instanceId}' no app '${app}'.`
1924
- );
1925
- callback(data);
1926
- }
1927
- } catch (error) {
1928
- console.error(
1929
- `Erro no listener escopado para inst\xE2ncia '${instanceId}' no app '${app}':`,
1930
- error
1931
- );
1920
+ 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)) {
1921
+ callback(data);
1932
1922
  }
1933
1923
  };
1934
- this.scopedListeners.set(key, scopedListener);
1935
1924
  this.on("message", scopedListener);
1925
+ this.scopedListeners.set(key, scopedListener);
1936
1926
  console.log(
1937
- `Listener escopado adicionado para a inst\xE2ncia '${instanceId}' no app '${app}'. Total de listeners: ${this.listenerCount(
1927
+ `Listener escopado adicionado para a inst\xE2ncia '${key}'. Total de listeners: ${this.listenerCount(
1938
1928
  "message"
1939
1929
  )}`
1940
1930
  );
@@ -1946,29 +1936,23 @@ var WebSocketClient = class extends import_events3.EventEmitter {
1946
1936
  */
1947
1937
  removeScopedMessageListeners(instanceId, app) {
1948
1938
  const key = `${app}:${instanceId}`;
1949
- if (!this.scopedListeners.has(key)) {
1939
+ const scopedListener = this.scopedListeners.get(key);
1940
+ if (!scopedListener) {
1950
1941
  console.warn(`Nenhum listener encontrado para a inst\xE2ncia '${key}'.`);
1951
1942
  return;
1952
1943
  }
1953
- const scopedListener = this.scopedListeners.get(key);
1954
- if (scopedListener) {
1955
- if (this.listeners("message").includes(scopedListener)) {
1956
- this.off("message", scopedListener);
1957
- console.log(`Listener removido para '${key}'.`);
1958
- } else {
1959
- console.warn(
1960
- `Listener n\xE3o encontrado entre os registrados para '${key}'.`
1961
- );
1962
- }
1963
- this.scopedListeners.delete(key);
1964
- console.log(
1965
- `Listeners escopados removidos para a inst\xE2ncia '${key}'. Total de listeners restantes: ${this.listenerCount(
1966
- "message"
1967
- )}`
1968
- );
1944
+ if (this.listeners("message").includes(scopedListener)) {
1945
+ this.off("message", scopedListener);
1946
+ console.log(`Listener escopado removido para '${key}'.`);
1969
1947
  } else {
1970
- console.warn(`Listener j\xE1 foi removido para a inst\xE2ncia '${key}'.`);
1948
+ console.warn(`Listener j\xE1 foi removido para '${key}'.`);
1971
1949
  }
1950
+ this.scopedListeners.delete(key);
1951
+ console.log(
1952
+ `Listeners escopados removidos para a inst\xE2ncia '${key}'. Total de listeners restantes: ${this.listenerCount(
1953
+ "message"
1954
+ )}`
1955
+ );
1972
1956
  }
1973
1957
  /**
1974
1958
  * Handles incoming WebSocket messages.
@@ -1977,6 +1961,7 @@ var WebSocketClient = class extends import_events3.EventEmitter {
1977
1961
  handleMessage(rawData) {
1978
1962
  try {
1979
1963
  const decodedData = JSON.parse(rawData.toString());
1964
+ console.log({ tipo: decodedData?.type });
1980
1965
  if (decodedData?.type && decodedData?.application) {
1981
1966
  const scopedEvent = `${decodedData.application}:${decodedData.type}`;
1982
1967
  if ("channel" in decodedData && decodedData.channel?.id) {
@@ -2020,10 +2005,12 @@ var WebSocketClient = class extends import_events3.EventEmitter {
2020
2005
  this.isClosedManually = true;
2021
2006
  this.ws.close();
2022
2007
  this.ws = null;
2008
+ console.log(this.scopedListeners);
2023
2009
  this.scopedListeners.forEach((_listener, key) => {
2024
2010
  console.log(`Removendo listener escopado para '${key}' ao fechar.`);
2025
2011
  this.removeScopedMessageListeners(key.split(":")[1], key.split(":")[0]);
2026
2012
  });
2013
+ this.scopedListeners.clear();
2027
2014
  this.removeAllListeners("message");
2028
2015
  console.log("WebSocket fechado manualmente e todos os listeners limpos.");
2029
2016
  }