@ipcom/asterisk-ari 0.0.96 → 0.0.98
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 +100 -33
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +100 -33
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/resources/channels.d.ts +0 -3
- package/dist/types/ari-client/resources/channels.d.ts.map +1 -1
- package/dist/types/ari-client/resources/playbacks.d.ts +3 -7
- package/dist/types/ari-client/resources/playbacks.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts +12 -0
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -925,9 +925,24 @@ var ChannelInstance = class extends EventEmitter2 {
|
|
|
925
925
|
`Nenhum WebSocket conectado dispon\xEDvel para o canal: ${this.id}`
|
|
926
926
|
);
|
|
927
927
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
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
|
+
}
|
|
942
|
+
this.on("removeListener", (eventName) => {
|
|
943
|
+
if (this.eventNames().length === 0 || this.listenerCount(eventName) === 0) {
|
|
944
|
+
wsClient.removeScopedMessageListeners(this.id);
|
|
945
|
+
console.log(`Listeners escopados removidos para canal '${this.id}'.`);
|
|
931
946
|
}
|
|
932
947
|
});
|
|
933
948
|
}
|
|
@@ -940,9 +955,6 @@ var ChannelInstance = class extends EventEmitter2 {
|
|
|
940
955
|
super.on(event, callback);
|
|
941
956
|
return this;
|
|
942
957
|
}
|
|
943
|
-
/**
|
|
944
|
-
* Adiciona um listener para ser chamado apenas uma vez.
|
|
945
|
-
*/
|
|
946
958
|
/**
|
|
947
959
|
* Adiciona um listener para ser chamado apenas uma vez.
|
|
948
960
|
*/
|
|
@@ -965,11 +977,21 @@ var ChannelInstance = class extends EventEmitter2 {
|
|
|
965
977
|
console.log(`Recebido evento '${event}' para canal '${this.id}'`);
|
|
966
978
|
this.emit(event, webSocketEvent);
|
|
967
979
|
callback(webSocketEvent);
|
|
968
|
-
wsClient.
|
|
969
|
-
console.log(
|
|
980
|
+
wsClient.removeScopedMessageListeners(this.id);
|
|
981
|
+
console.log(
|
|
982
|
+
`Listeners escopados para canal '${this.id}' foram removidos.`
|
|
983
|
+
);
|
|
970
984
|
}
|
|
971
985
|
};
|
|
972
|
-
|
|
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
|
+
}
|
|
973
995
|
super.once(event, callback);
|
|
974
996
|
return this;
|
|
975
997
|
}
|
|
@@ -1412,19 +1434,34 @@ var PlaybackInstance = class extends EventEmitter3 {
|
|
|
1412
1434
|
`Nenhum WebSocket conectado dispon\xEDvel para o playback: ${this.id}`
|
|
1413
1435
|
);
|
|
1414
1436
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1437
|
+
try {
|
|
1438
|
+
wsClient.addScopedMessageListener(this.id, (event) => {
|
|
1439
|
+
if (isPlaybackEvent(event, this.id)) {
|
|
1440
|
+
const playbackEventType = event.type;
|
|
1419
1441
|
this.emit(playbackEventType, event);
|
|
1420
|
-
} else {
|
|
1421
|
-
console.log(`Listener para '${playbackEventType}' j\xE1 registrado.`);
|
|
1422
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
|
+
}
|
|
1451
|
+
this.on("removeListener", (eventName) => {
|
|
1452
|
+
if (this.eventNames().length === 0 || this.listenerCount(eventName) === 0) {
|
|
1453
|
+
wsClient.removeScopedMessageListeners(this.id);
|
|
1454
|
+
console.log(
|
|
1455
|
+
`Listeners escopados removidos para playback '${this.id}'.`
|
|
1456
|
+
);
|
|
1423
1457
|
}
|
|
1424
1458
|
});
|
|
1425
1459
|
}
|
|
1426
1460
|
playbackData = null;
|
|
1427
1461
|
id;
|
|
1462
|
+
/**
|
|
1463
|
+
* Adiciona um listener para eventos de playback.
|
|
1464
|
+
*/
|
|
1428
1465
|
/**
|
|
1429
1466
|
* Adiciona um listener para eventos de playback.
|
|
1430
1467
|
*/
|
|
@@ -1454,11 +1491,21 @@ var PlaybackInstance = class extends EventEmitter3 {
|
|
|
1454
1491
|
console.log(`Recebido evento '${event}' para playback '${this.id}'`);
|
|
1455
1492
|
this.emit(event, webSocketEvent);
|
|
1456
1493
|
callback(webSocketEvent);
|
|
1457
|
-
wsClient.
|
|
1458
|
-
console.log(
|
|
1494
|
+
wsClient.removeScopedMessageListeners(this.id);
|
|
1495
|
+
console.log(
|
|
1496
|
+
`Listeners escopados para playback '${this.id}' foram removidos.`
|
|
1497
|
+
);
|
|
1459
1498
|
}
|
|
1460
1499
|
};
|
|
1461
|
-
|
|
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
|
+
}
|
|
1462
1509
|
super.once(event, callback);
|
|
1463
1510
|
return this;
|
|
1464
1511
|
}
|
|
@@ -1503,7 +1550,6 @@ var PlaybackInstance = class extends EventEmitter3 {
|
|
|
1503
1550
|
throw new Error("Nenhum playback associado para encerrar.");
|
|
1504
1551
|
}
|
|
1505
1552
|
await this.baseClient.delete(`/playbacks/${this.id}`);
|
|
1506
|
-
this.emit("PlaybackStopped", this.playbackData);
|
|
1507
1553
|
}
|
|
1508
1554
|
};
|
|
1509
1555
|
var Playbacks = class extends EventEmitter3 {
|
|
@@ -1525,19 +1571,6 @@ var Playbacks = class extends EventEmitter3 {
|
|
|
1525
1571
|
getWebSocketClients() {
|
|
1526
1572
|
return this.client.getWebSocketClients();
|
|
1527
1573
|
}
|
|
1528
|
-
/**
|
|
1529
|
-
* Emite eventos de playback.
|
|
1530
|
-
* Atualizado para gerenciar eventos específicos para `PlaybackInstance`.
|
|
1531
|
-
*/
|
|
1532
|
-
emitPlaybackEvent(eventType, data) {
|
|
1533
|
-
if ("playbackId" in data) {
|
|
1534
|
-
const playbackId = data.playbackId;
|
|
1535
|
-
if (playbackId) {
|
|
1536
|
-
this.emit(`${eventType}:${playbackId}`, data);
|
|
1537
|
-
}
|
|
1538
|
-
}
|
|
1539
|
-
this.emit(eventType, data);
|
|
1540
|
-
}
|
|
1541
1574
|
/**
|
|
1542
1575
|
* Retrieves details of a specific playback.
|
|
1543
1576
|
*
|
|
@@ -1643,7 +1676,6 @@ var import_exponential_backoff = __toESM(require_backoff(), 1);
|
|
|
1643
1676
|
import { EventEmitter as EventEmitter4 } from "events";
|
|
1644
1677
|
import WebSocket from "ws";
|
|
1645
1678
|
var WebSocketClient = class extends EventEmitter4 {
|
|
1646
|
-
// Para gerenciar tentativas de reconexão
|
|
1647
1679
|
/**
|
|
1648
1680
|
* Creates a new WebSocketClient instance.
|
|
1649
1681
|
* @param url - The WebSocket server URL to connect to.
|
|
@@ -1658,6 +1690,8 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1658
1690
|
messageListeners = [];
|
|
1659
1691
|
maxReconnectAttempts = 30;
|
|
1660
1692
|
reconnectAttempts = 0;
|
|
1693
|
+
// Para gerenciar tentativas de reconexão
|
|
1694
|
+
scopedListeners = /* @__PURE__ */ new Map();
|
|
1661
1695
|
async reconnect() {
|
|
1662
1696
|
console.log("Iniciando processo de reconex\xE3o...");
|
|
1663
1697
|
const backoffOptions = {
|
|
@@ -1774,6 +1808,39 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1774
1808
|
super.removeAllListeners(event);
|
|
1775
1809
|
return this;
|
|
1776
1810
|
}
|
|
1811
|
+
/**
|
|
1812
|
+
* Adiciona um listener escopado ao evento "message".
|
|
1813
|
+
* @param instanceId - Identificador único da instância que está registrando o listener.
|
|
1814
|
+
* @param callback - Função de callback para o evento.
|
|
1815
|
+
*/
|
|
1816
|
+
addScopedMessageListener(instanceId, callback) {
|
|
1817
|
+
const scopedListener = (data) => {
|
|
1818
|
+
if (data.type.startsWith("Channel") && "channel" in data && data.channel?.id === instanceId || // Verifica se o evento é de playback e possui a propriedade `playbackId`
|
|
1819
|
+
data.type.startsWith("Playback") && "playbackId" in data && data.playbackId === instanceId) {
|
|
1820
|
+
callback(data);
|
|
1821
|
+
}
|
|
1822
|
+
};
|
|
1823
|
+
this.scopedListeners.set(instanceId, scopedListener);
|
|
1824
|
+
this.on("message", scopedListener);
|
|
1825
|
+
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Remove todos os listeners associados a uma instância específica.
|
|
1828
|
+
* @param instanceId - Identificador da instância cujos listeners serão removidos.
|
|
1829
|
+
*/
|
|
1830
|
+
removeScopedMessageListeners(instanceId) {
|
|
1831
|
+
if (!this.scopedListeners.has(instanceId)) {
|
|
1832
|
+
console.warn(
|
|
1833
|
+
`Nenhum listener encontrado para a inst\xE2ncia '${instanceId}'.`
|
|
1834
|
+
);
|
|
1835
|
+
return;
|
|
1836
|
+
}
|
|
1837
|
+
const scopedListener = this.scopedListeners.get(instanceId);
|
|
1838
|
+
if (scopedListener) {
|
|
1839
|
+
this.off("message", scopedListener);
|
|
1840
|
+
this.scopedListeners.delete(instanceId);
|
|
1841
|
+
console.log(`Listeners removidos para a inst\xE2ncia '${instanceId}'.`);
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1777
1844
|
/**
|
|
1778
1845
|
* Handles incoming WebSocket messages.
|
|
1779
1846
|
* @param rawData - The raw data received from the WebSocket.
|