@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.
@@ -1083,11 +1083,26 @@ var ChannelInstance = class extends import_events.EventEmitter {
1083
1083
  `/channels/${this.channelData.id}/play/${playback.id}`,
1084
1084
  options
1085
1085
  );
1086
- playback.once("PlaybackFinished", async () => {
1086
+ const wsClient = this.client.getWebSocketClients().get(this.app);
1087
+ if (!wsClient) {
1088
+ throw new Error("WebSocketClient n\xE3o encontrado para o app.");
1089
+ }
1090
+ playback.once("PlaybackFinished", () => {
1091
+ console.log(`PlaybackFinished '${playback.id}' no canal '${this.id}'.`);
1092
+ wsClient.removeScopedPlaybackListeners(playback.id, this.app);
1093
+ });
1094
+ playback.once("PlaybackStarted", () => {
1095
+ console.log(`PlaybackStarted '${playback.id}' no canal '${this.id}'.`);
1096
+ });
1097
+ playback.once("PlaybackContinuing", () => {
1098
+ console.log(`PlaybackContinuing '${playback.id}' no canal '${this.id}'.`);
1099
+ });
1100
+ this.once("ChannelDestroyed", () => {
1087
1101
  console.log(
1088
- `Playback '${playback.id}' finalizado no canal '${this.id}'.`
1102
+ `Canal '${this.id}' foi destru\xEDdo. Removendo listeners associados.`
1089
1103
  );
1090
- this.client.getWebSocketClients().get(this.app)?.removeScopedMessageListeners(playback.id, this.app);
1104
+ wsClient.removeScopedChannelListeners(this.id, this.app);
1105
+ wsClient.removeScopedPlaybackListeners(playback.id, this.app);
1091
1106
  });
1092
1107
  return playback;
1093
1108
  }
@@ -2006,6 +2021,24 @@ var WebSocketClient = class extends import_events3.EventEmitter {
2006
2021
  );
2007
2022
  this.listListeners("message");
2008
2023
  }
2024
+ removeScopedChannelListeners(instanceId, app) {
2025
+ const key = `channel:${app}:${instanceId}`;
2026
+ const scopedListener = this.scopedListeners.get(key);
2027
+ if (scopedListener) {
2028
+ this.off("message", scopedListener);
2029
+ this.scopedListeners.delete(key);
2030
+ console.log(`Listener de canal removido para '${key}'.`);
2031
+ }
2032
+ }
2033
+ removeScopedPlaybackListeners(playbackId, app) {
2034
+ const key = `playback:${app}:${playbackId}`;
2035
+ const scopedListener = this.scopedListeners.get(key);
2036
+ if (scopedListener) {
2037
+ this.off("message", scopedListener);
2038
+ this.scopedListeners.delete(key);
2039
+ console.log(`Listener de playback removido para '${key}'.`);
2040
+ }
2041
+ }
2009
2042
  /**
2010
2043
  * Handles incoming WebSocket messages.
2011
2044
  * @param rawData - The raw data received from the WebSocket.