@ipcom/asterisk-ari 0.0.128 → 0.0.129

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
@@ -1061,26 +1061,26 @@ var ChannelInstance = class extends EventEmitter {
1061
1061
  `/channels/${this.channelData.id}/play/${playback.id}`,
1062
1062
  options
1063
1063
  );
1064
- playback.once("PlaybackFinished", async () => {
1065
- console.log(
1066
- `PlaybackFinished '${playback.id}' finalizado no canal '${this.id}'.`
1067
- );
1068
- console.log(this.client.getWebSocketClients().get(this.app));
1069
- this.client.getWebSocketClients().get(this.app)?.removeScopedMessageListeners(playback.id, this.app);
1064
+ const wsClient = this.client.getWebSocketClients().get(this.app);
1065
+ if (!wsClient) {
1066
+ throw new Error("WebSocketClient n\xE3o encontrado para o app.");
1067
+ }
1068
+ playback.once("PlaybackFinished", () => {
1069
+ console.log(`PlaybackFinished '${playback.id}' no canal '${this.id}'.`);
1070
+ wsClient.removeScopedPlaybackListeners(playback.id, this.app);
1070
1071
  });
1071
- playback.once("PlaybackStarted", async () => {
1072
- console.log(
1073
- `PlaybackStarted '${playback.id}' finalizado no canal '${this.id}'.`
1074
- );
1075
- console.log(this.client.getWebSocketClients().get(this.app));
1076
- this.client.getWebSocketClients().get(this.app)?.removeScopedMessageListeners(playback.id, this.app);
1072
+ playback.once("PlaybackStarted", () => {
1073
+ console.log(`PlaybackStarted '${playback.id}' no canal '${this.id}'.`);
1074
+ });
1075
+ playback.once("PlaybackContinuing", () => {
1076
+ console.log(`PlaybackContinuing '${playback.id}' no canal '${this.id}'.`);
1077
1077
  });
1078
- playback.once("PlaybackContinuing", async () => {
1078
+ this.once("ChannelDestroyed", () => {
1079
1079
  console.log(
1080
- `PlaybackContinuing '${playback.id}' finalizado no canal '${this.id}'.`
1080
+ `Canal '${this.id}' foi destru\xEDdo. Removendo listeners associados.`
1081
1081
  );
1082
- console.log(this.client.getWebSocketClients().get(this.app));
1083
- this.client.getWebSocketClients().get(this.app)?.removeScopedMessageListeners(playback.id, this.app);
1082
+ wsClient.removeScopedChannelListeners(this.id, this.app);
1083
+ wsClient.removeScopedPlaybackListeners(playback.id, this.app);
1084
1084
  });
1085
1085
  return playback;
1086
1086
  }
@@ -1999,6 +1999,24 @@ var WebSocketClient = class extends EventEmitter3 {
1999
1999
  );
2000
2000
  this.listListeners("message");
2001
2001
  }
2002
+ removeScopedChannelListeners(instanceId, app) {
2003
+ const key = `channel:${app}:${instanceId}`;
2004
+ const scopedListener = this.scopedListeners.get(key);
2005
+ if (scopedListener) {
2006
+ this.off("message", scopedListener);
2007
+ this.scopedListeners.delete(key);
2008
+ console.log(`Listener de canal removido para '${key}'.`);
2009
+ }
2010
+ }
2011
+ removeScopedPlaybackListeners(playbackId, app) {
2012
+ const key = `playback:${app}:${playbackId}`;
2013
+ const scopedListener = this.scopedListeners.get(key);
2014
+ if (scopedListener) {
2015
+ this.off("message", scopedListener);
2016
+ this.scopedListeners.delete(key);
2017
+ console.log(`Listener de playback removido para '${key}'.`);
2018
+ }
2019
+ }
2002
2020
  /**
2003
2021
  * Handles incoming WebSocket messages.
2004
2022
  * @param rawData - The raw data received from the WebSocket.