@ipcom/asterisk-ari 0.0.97 → 0.0.99
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/cjs/index.cjs +72 -26
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +72 -26
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/resources/channels.d.ts.map +1 -1
- package/dist/types/ari-client/resources/playbacks.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts +2 -1
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -925,12 +925,20 @@ var ChannelInstance = class extends EventEmitter2 {
|
|
|
925
925
|
`Nenhum WebSocket conectado dispon\xEDvel para o canal: ${this.id}`
|
|
926
926
|
);
|
|
927
927
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
928
|
+
try {
|
|
929
|
+
wsClient.addScopedMessageListener(this.id, (event) => {
|
|
930
|
+
if (isChannelEvent(event, this.id)) {
|
|
931
|
+
const channelEventType = event.type;
|
|
932
|
+
this.emit(channelEventType, event);
|
|
933
|
+
}
|
|
934
|
+
});
|
|
935
|
+
} catch (error) {
|
|
936
|
+
console.error(
|
|
937
|
+
`Erro ao adicionar listener escopado para canal '${this.id}':`,
|
|
938
|
+
error
|
|
939
|
+
);
|
|
940
|
+
throw error;
|
|
941
|
+
}
|
|
934
942
|
this.on("removeListener", (eventName) => {
|
|
935
943
|
if (this.eventNames().length === 0 || this.listenerCount(eventName) === 0) {
|
|
936
944
|
wsClient.removeScopedMessageListeners(this.id);
|
|
@@ -969,11 +977,21 @@ var ChannelInstance = class extends EventEmitter2 {
|
|
|
969
977
|
console.log(`Recebido evento '${event}' para canal '${this.id}'`);
|
|
970
978
|
this.emit(event, webSocketEvent);
|
|
971
979
|
callback(webSocketEvent);
|
|
972
|
-
wsClient.
|
|
973
|
-
console.log(
|
|
980
|
+
wsClient.removeScopedMessageListeners(this.id);
|
|
981
|
+
console.log(
|
|
982
|
+
`Listeners escopados para canal '${this.id}' foram removidos.`
|
|
983
|
+
);
|
|
974
984
|
}
|
|
975
985
|
};
|
|
976
|
-
|
|
986
|
+
try {
|
|
987
|
+
wsClient.addScopedMessageListener(this.id, globalListener);
|
|
988
|
+
} catch (error) {
|
|
989
|
+
console.error(
|
|
990
|
+
`Erro ao adicionar listener escopado em 'once' para canal '${this.id}':`,
|
|
991
|
+
error
|
|
992
|
+
);
|
|
993
|
+
throw error;
|
|
994
|
+
}
|
|
977
995
|
super.once(event, callback);
|
|
978
996
|
return this;
|
|
979
997
|
}
|
|
@@ -1416,12 +1434,20 @@ var PlaybackInstance = class extends EventEmitter3 {
|
|
|
1416
1434
|
`Nenhum WebSocket conectado dispon\xEDvel para o playback: ${this.id}`
|
|
1417
1435
|
);
|
|
1418
1436
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1437
|
+
try {
|
|
1438
|
+
wsClient.addScopedMessageListener(this.id, (event) => {
|
|
1439
|
+
if (isPlaybackEvent(event, this.id)) {
|
|
1440
|
+
const playbackEventType = event.type;
|
|
1441
|
+
this.emit(playbackEventType, event);
|
|
1442
|
+
}
|
|
1443
|
+
});
|
|
1444
|
+
} catch (error) {
|
|
1445
|
+
console.error(
|
|
1446
|
+
`Erro ao adicionar listener escopado para playback '${this.id}':`,
|
|
1447
|
+
error
|
|
1448
|
+
);
|
|
1449
|
+
throw error;
|
|
1450
|
+
}
|
|
1425
1451
|
this.on("removeListener", (eventName) => {
|
|
1426
1452
|
if (this.eventNames().length === 0 || this.listenerCount(eventName) === 0) {
|
|
1427
1453
|
wsClient.removeScopedMessageListeners(this.id);
|
|
@@ -1471,7 +1497,15 @@ var PlaybackInstance = class extends EventEmitter3 {
|
|
|
1471
1497
|
);
|
|
1472
1498
|
}
|
|
1473
1499
|
};
|
|
1474
|
-
|
|
1500
|
+
try {
|
|
1501
|
+
wsClient.addScopedMessageListener(this.id, globalListener);
|
|
1502
|
+
} catch (error) {
|
|
1503
|
+
console.error(
|
|
1504
|
+
`Erro ao adicionar listener escopado em 'once' para playback '${this.id}':`,
|
|
1505
|
+
error
|
|
1506
|
+
);
|
|
1507
|
+
throw error;
|
|
1508
|
+
}
|
|
1475
1509
|
super.once(event, callback);
|
|
1476
1510
|
return this;
|
|
1477
1511
|
}
|
|
@@ -1642,7 +1676,6 @@ var import_exponential_backoff = __toESM(require_backoff(), 1);
|
|
|
1642
1676
|
import { EventEmitter as EventEmitter4 } from "events";
|
|
1643
1677
|
import WebSocket from "ws";
|
|
1644
1678
|
var WebSocketClient = class extends EventEmitter4 {
|
|
1645
|
-
// Para gerenciar tentativas de reconexão
|
|
1646
1679
|
/**
|
|
1647
1680
|
* Creates a new WebSocketClient instance.
|
|
1648
1681
|
* @param url - The WebSocket server URL to connect to.
|
|
@@ -1657,6 +1690,8 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1657
1690
|
messageListeners = [];
|
|
1658
1691
|
maxReconnectAttempts = 30;
|
|
1659
1692
|
reconnectAttempts = 0;
|
|
1693
|
+
// Para gerenciar tentativas de reconexão
|
|
1694
|
+
scopedListeners = /* @__PURE__ */ new Map();
|
|
1660
1695
|
async reconnect() {
|
|
1661
1696
|
console.log("Iniciando processo de reconex\xE3o...");
|
|
1662
1697
|
const backoffOptions = {
|
|
@@ -1780,25 +1815,36 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1780
1815
|
*/
|
|
1781
1816
|
addScopedMessageListener(instanceId, callback) {
|
|
1782
1817
|
const scopedListener = (data) => {
|
|
1783
|
-
|
|
1818
|
+
const decodedData = JSON.parse(data.toString());
|
|
1819
|
+
console.log(decodedData);
|
|
1820
|
+
if (data.type.startsWith("Channel") && "channel" in data && data.channel?.id === instanceId || // Verifica se o evento é de playback e possui a propriedade `playbackId`
|
|
1821
|
+
data.type.startsWith("Playback") && "playbackId" in data && data.playbackId === instanceId) {
|
|
1822
|
+
console.log(
|
|
1823
|
+
`Listener escopado para a inst\xE2ncia '${instanceId}' ativado.`
|
|
1824
|
+
);
|
|
1784
1825
|
callback(data);
|
|
1785
1826
|
}
|
|
1786
1827
|
};
|
|
1828
|
+
this.scopedListeners.set(instanceId, scopedListener);
|
|
1787
1829
|
this.on("message", scopedListener);
|
|
1788
|
-
this.messageListeners.push(scopedListener);
|
|
1789
1830
|
}
|
|
1790
1831
|
/**
|
|
1791
1832
|
* Remove todos os listeners associados a uma instância específica.
|
|
1792
1833
|
* @param instanceId - Identificador da instância cujos listeners serão removidos.
|
|
1793
1834
|
*/
|
|
1794
1835
|
removeScopedMessageListeners(instanceId) {
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1836
|
+
if (!this.scopedListeners.has(instanceId)) {
|
|
1837
|
+
console.warn(
|
|
1838
|
+
`Nenhum listener encontrado para a inst\xE2ncia '${instanceId}'.`
|
|
1839
|
+
);
|
|
1840
|
+
return;
|
|
1841
|
+
}
|
|
1842
|
+
const scopedListener = this.scopedListeners.get(instanceId);
|
|
1843
|
+
if (scopedListener) {
|
|
1844
|
+
this.off("message", scopedListener);
|
|
1845
|
+
this.scopedListeners.delete(instanceId);
|
|
1846
|
+
console.log(`Listeners removidos para a inst\xE2ncia '${instanceId}'.`);
|
|
1847
|
+
}
|
|
1802
1848
|
}
|
|
1803
1849
|
/**
|
|
1804
1850
|
* Handles incoming WebSocket messages.
|