@ipcom/asterisk-ari 0.0.127 → 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,11 +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 () => {
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);
1071
+ });
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
+ });
1078
+ this.once("ChannelDestroyed", () => {
1065
1079
  console.log(
1066
- `Playback '${playback.id}' finalizado no canal '${this.id}'.`
1080
+ `Canal '${this.id}' foi destru\xEDdo. Removendo listeners associados.`
1067
1081
  );
1068
- 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);
1069
1084
  });
1070
1085
  return playback;
1071
1086
  }
@@ -1984,6 +1999,24 @@ var WebSocketClient = class extends EventEmitter3 {
1984
1999
  );
1985
2000
  this.listListeners("message");
1986
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
+ }
1987
2020
  /**
1988
2021
  * Handles incoming WebSocket messages.
1989
2022
  * @param rawData - The raw data received from the WebSocket.