@ipcom/asterisk-ari 0.0.40 → 0.0.41
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 +83 -0
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +83 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/ariClient.d.ts +18 -0
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/resources/channels.d.ts +27 -0
- package/dist/types/ari-client/resources/channels.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -842,6 +842,37 @@ function toQueryParams2(options) {
|
|
|
842
842
|
Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
|
|
843
843
|
).toString();
|
|
844
844
|
}
|
|
845
|
+
var ChannelEventEmitter = class {
|
|
846
|
+
eventEmitter = new EventEmitter();
|
|
847
|
+
channel;
|
|
848
|
+
constructor(channel) {
|
|
849
|
+
this.channel = channel;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Registra um listener para um evento no canal.
|
|
853
|
+
*/
|
|
854
|
+
on(eventType, callback) {
|
|
855
|
+
this.eventEmitter.on(eventType, callback);
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Emite um evento no canal.
|
|
859
|
+
*/
|
|
860
|
+
emit(eventType, data) {
|
|
861
|
+
this.eventEmitter.emit(eventType, data);
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Remove um listener de evento do canal.
|
|
865
|
+
*/
|
|
866
|
+
off(eventType, callback) {
|
|
867
|
+
this.eventEmitter.off(eventType, callback);
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Remove todos os listeners de um evento no canal.
|
|
871
|
+
*/
|
|
872
|
+
removeAllListeners(eventType) {
|
|
873
|
+
this.eventEmitter.removeAllListeners(eventType);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
845
876
|
var ChannelInstance = class extends EventEmitter {
|
|
846
877
|
constructor(client, baseClient, channelId = `channel-${Date.now()}`) {
|
|
847
878
|
super();
|
|
@@ -1673,6 +1704,7 @@ var AriClient = class {
|
|
|
1673
1704
|
this.bridges = new Bridges(this.baseClient);
|
|
1674
1705
|
}
|
|
1675
1706
|
wsClient = null;
|
|
1707
|
+
channelEmitters = /* @__PURE__ */ new Map();
|
|
1676
1708
|
baseClient;
|
|
1677
1709
|
isReconnecting = false;
|
|
1678
1710
|
eventEmitter = new EventEmitter4();
|
|
@@ -1789,6 +1821,18 @@ var AriClient = class {
|
|
|
1789
1821
|
`WebSocket client para o app '${app}' n\xE3o est\xE1 conectado.`
|
|
1790
1822
|
);
|
|
1791
1823
|
}
|
|
1824
|
+
wsClient.on("ChannelDestroyed", (data) => {
|
|
1825
|
+
if (data.type === "ChannelDestroyed" && "channel" in data) {
|
|
1826
|
+
console.log(`[${app}] Canal destru\xEDdo: ${data.channel.id}`);
|
|
1827
|
+
this.removeChannel(data.channel.id);
|
|
1828
|
+
}
|
|
1829
|
+
});
|
|
1830
|
+
wsClient.on("StasisEnd", (data) => {
|
|
1831
|
+
if (data.type === "StasisEnd" && "channel" in data) {
|
|
1832
|
+
console.log(`[${app}] StasisEnd para o canal: ${data.channel.id}`);
|
|
1833
|
+
this.removeChannel(data.channel.id);
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1792
1836
|
const eventHandlers = {
|
|
1793
1837
|
PlaybackStarted: (data) => {
|
|
1794
1838
|
if ("playbackId" in data) {
|
|
@@ -2025,6 +2069,45 @@ var AriClient = class {
|
|
|
2025
2069
|
this.wsClient = null;
|
|
2026
2070
|
}
|
|
2027
2071
|
}
|
|
2072
|
+
/**
|
|
2073
|
+
* Obtém ou cria um emissor de eventos para o canal especificado.
|
|
2074
|
+
*/
|
|
2075
|
+
getOrCreateChannelEmitter(channel) {
|
|
2076
|
+
if (!this.channelEmitters.has(channel.id)) {
|
|
2077
|
+
this.channelEmitters.set(channel.id, new ChannelEventEmitter(channel));
|
|
2078
|
+
}
|
|
2079
|
+
return this.channelEmitters.get(channel.id);
|
|
2080
|
+
}
|
|
2081
|
+
/**
|
|
2082
|
+
* Adiciona um listener para um evento específico de canal.
|
|
2083
|
+
*/
|
|
2084
|
+
onChannelEvent(channelId, eventType, callback) {
|
|
2085
|
+
const channelEmitter = this.channelEmitters.get(channelId);
|
|
2086
|
+
if (!channelEmitter) {
|
|
2087
|
+
throw new Error(`Canal com ID ${channelId} n\xE3o encontrado.`);
|
|
2088
|
+
}
|
|
2089
|
+
channelEmitter.on(eventType, callback);
|
|
2090
|
+
}
|
|
2091
|
+
removeChannel(channelId) {
|
|
2092
|
+
const channelEmitter = this.channelEmitters.get(channelId);
|
|
2093
|
+
if (channelEmitter) {
|
|
2094
|
+
channelEmitter.removeAllListeners();
|
|
2095
|
+
this.channelEmitters.delete(channelId);
|
|
2096
|
+
console.log(`Listeners para o canal ${channelId} foram removidos.`);
|
|
2097
|
+
} else {
|
|
2098
|
+
console.warn(`Nenhum listener encontrado para o canal ${channelId}.`);
|
|
2099
|
+
}
|
|
2100
|
+
}
|
|
2101
|
+
/**
|
|
2102
|
+
* Remove um listener para um evento específico de canal.
|
|
2103
|
+
*/
|
|
2104
|
+
offChannelEvent(channelId, eventType, callback) {
|
|
2105
|
+
const channelEmitter = this.channelEmitters.get(channelId);
|
|
2106
|
+
if (!channelEmitter) {
|
|
2107
|
+
throw new Error(`Canal com ID ${channelId} n\xE3o encontrado.`);
|
|
2108
|
+
}
|
|
2109
|
+
channelEmitter.off(eventType, callback);
|
|
2110
|
+
}
|
|
2028
2111
|
/**
|
|
2029
2112
|
* Retrieves a list of active channels from the Asterisk ARI.
|
|
2030
2113
|
*
|