@ipcom/asterisk-ari 0.0.100 → 0.0.102

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.
@@ -1571,7 +1571,22 @@ var PlaybackInstance = class extends import_events3.EventEmitter {
1571
1571
  if (!this.id) {
1572
1572
  throw new Error("Nenhum playback associado para encerrar.");
1573
1573
  }
1574
- await this.baseClient.delete(`/playbacks/${this.id}`);
1574
+ try {
1575
+ await this.baseClient.delete(`/playbacks/${this.id}`);
1576
+ console.log(`Playback '${this.id}' parado com sucesso.`);
1577
+ } catch (error) {
1578
+ if (error.response?.status === 404) {
1579
+ console.warn(
1580
+ `Playback '${this.id}' n\xE3o encontrado para encerrar (404).`
1581
+ );
1582
+ return;
1583
+ }
1584
+ console.error(
1585
+ `Erro ao encerrar o playback '${this.id}':`,
1586
+ error.message || error
1587
+ );
1588
+ throw error;
1589
+ }
1575
1590
  }
1576
1591
  };
1577
1592
  var Playbacks = class extends import_events3.EventEmitter {
@@ -1627,7 +1642,22 @@ var Playbacks = class extends import_events3.EventEmitter {
1627
1642
  * @returns A promise that resolves when the playback is successfully stopped.
1628
1643
  */
1629
1644
  async stop(playbackId) {
1630
- await this.baseClient.delete(`/playbacks/${playbackId}`);
1645
+ try {
1646
+ await this.baseClient.delete(`/playbacks/${playbackId}`);
1647
+ console.log(`Playback '${playbackId}' parado com sucesso.`);
1648
+ } catch (error) {
1649
+ if (error.response?.status === 404) {
1650
+ console.warn(
1651
+ `Playback '${playbackId}' n\xE3o encontrado para encerrar (404).`
1652
+ );
1653
+ return;
1654
+ }
1655
+ console.error(
1656
+ `Erro ao encerrar o playback '${playbackId}':`,
1657
+ error.message || error
1658
+ );
1659
+ throw error;
1660
+ }
1631
1661
  }
1632
1662
  /**
1633
1663
  * Registers a listener for playback events.
@@ -1836,10 +1866,15 @@ var WebSocketClient = class extends import_events4.EventEmitter {
1836
1866
  * @param callback - Função de callback para o evento.
1837
1867
  */
1838
1868
  addScopedMessageListener(instanceId, callback) {
1869
+ if (this.scopedListeners.has(instanceId)) {
1870
+ console.warn(
1871
+ `Listener escopado para a inst\xE2ncia '${instanceId}' j\xE1 existe. Ignorando duplica\xE7\xE3o.`
1872
+ );
1873
+ return;
1874
+ }
1839
1875
  const scopedListener = (data) => {
1840
- console.log(data);
1841
- if (data.type.startsWith("Channel") && "channel" in data && data.channel?.id === instanceId || // Verifica se o evento é de playback e possui a propriedade `playbackId`
1842
- data.type.startsWith("Playback") && "playbackId" in data && data.playbackId === instanceId) {
1876
+ if (data.type.startsWith("Channel") && "channel" in data && data.channel?.id === instanceId || data.type.startsWith("Playback") && "playbackId" in data && data.playbackId === instanceId) {
1877
+ console.log(data);
1843
1878
  console.log(
1844
1879
  `Listener escopado para a inst\xE2ncia '${instanceId}' ativado.`
1845
1880
  );
@@ -1848,6 +1883,11 @@ var WebSocketClient = class extends import_events4.EventEmitter {
1848
1883
  };
1849
1884
  this.scopedListeners.set(instanceId, scopedListener);
1850
1885
  this.on("message", scopedListener);
1886
+ console.log(
1887
+ `Listener escopado adicionado para a inst\xE2ncia '${instanceId}'. Total de listeners: ${this.listenerCount(
1888
+ "message"
1889
+ )}`
1890
+ );
1851
1891
  }
1852
1892
  /**
1853
1893
  * Remove todos os listeners associados a uma instância específica.
@@ -1864,7 +1904,11 @@ var WebSocketClient = class extends import_events4.EventEmitter {
1864
1904
  if (scopedListener) {
1865
1905
  this.off("message", scopedListener);
1866
1906
  this.scopedListeners.delete(instanceId);
1867
- console.log(`Listeners removidos para a inst\xE2ncia '${instanceId}'.`);
1907
+ console.log(
1908
+ `Listeners removidos para a inst\xE2ncia '${instanceId}'. Total de listeners restantes: ${this.listenerCount(
1909
+ "message"
1910
+ )}`
1911
+ );
1868
1912
  }
1869
1913
  }
1870
1914
  /**