@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.
@@ -1083,26 +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 () => {
1087
- console.log(
1088
- `PlaybackFinished '${playback.id}' finalizado no canal '${this.id}'.`
1089
- );
1090
- console.log(this.client.getWebSocketClients().get(this.app));
1091
- this.client.getWebSocketClients().get(this.app)?.removeScopedMessageListeners(playback.id, this.app);
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);
1092
1093
  });
1093
- playback.once("PlaybackStarted", async () => {
1094
- console.log(
1095
- `PlaybackStarted '${playback.id}' finalizado no canal '${this.id}'.`
1096
- );
1097
- console.log(this.client.getWebSocketClients().get(this.app));
1098
- this.client.getWebSocketClients().get(this.app)?.removeScopedMessageListeners(playback.id, this.app);
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
1099
  });
1100
- playback.once("PlaybackContinuing", async () => {
1100
+ this.once("ChannelDestroyed", () => {
1101
1101
  console.log(
1102
- `PlaybackContinuing '${playback.id}' finalizado no canal '${this.id}'.`
1102
+ `Canal '${this.id}' foi destru\xEDdo. Removendo listeners associados.`
1103
1103
  );
1104
- console.log(this.client.getWebSocketClients().get(this.app));
1105
- 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);
1106
1106
  });
1107
1107
  return playback;
1108
1108
  }
@@ -2021,6 +2021,24 @@ var WebSocketClient = class extends import_events3.EventEmitter {
2021
2021
  );
2022
2022
  this.listListeners("message");
2023
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
+ }
2024
2042
  /**
2025
2043
  * Handles incoming WebSocket messages.
2026
2044
  * @param rawData - The raw data received from the WebSocket.