@ipcom/asterisk-ari 0.0.47 → 0.0.49
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
CHANGED
|
@@ -899,11 +899,15 @@ var ChannelInstance = class extends import_events.EventEmitter {
|
|
|
899
899
|
* Obtém os detalhes do canal.
|
|
900
900
|
*/
|
|
901
901
|
async getDetails() {
|
|
902
|
-
if (
|
|
903
|
-
|
|
902
|
+
if (this.channelData) {
|
|
903
|
+
return this.channelData;
|
|
904
|
+
}
|
|
905
|
+
if (!this.channelId) {
|
|
906
|
+
throw new Error("Nenhum ID de canal associado a esta inst\xE2ncia.");
|
|
904
907
|
}
|
|
905
|
-
const
|
|
906
|
-
|
|
908
|
+
const details = await this.baseClient.get(
|
|
909
|
+
`/channels/${this.channelId}`
|
|
910
|
+
);
|
|
907
911
|
this.channelData = details;
|
|
908
912
|
return details;
|
|
909
913
|
}
|
|
@@ -912,7 +916,11 @@ var ChannelInstance = class extends import_events.EventEmitter {
|
|
|
912
916
|
*/
|
|
913
917
|
async hangup() {
|
|
914
918
|
if (!this.channelData) {
|
|
915
|
-
|
|
919
|
+
console.log("Canal n\xE3o inicializado, buscando detalhes...");
|
|
920
|
+
this.channelData = await this.getDetails();
|
|
921
|
+
}
|
|
922
|
+
if (!this.channelData?.id) {
|
|
923
|
+
throw new Error("N\xE3o foi poss\xEDvel inicializar o canal. ID inv\xE1lido.");
|
|
916
924
|
}
|
|
917
925
|
await this.baseClient.delete(`/channels/${this.channelData.id}`);
|
|
918
926
|
}
|
|
@@ -920,11 +928,18 @@ var ChannelInstance = class extends import_events.EventEmitter {
|
|
|
920
928
|
* Reproduz mídia no canal.
|
|
921
929
|
*/
|
|
922
930
|
async play(options, playback) {
|
|
931
|
+
if (!this.channelData) {
|
|
932
|
+
console.log("Canal n\xE3o inicializado, buscando detalhes...");
|
|
933
|
+
this.channelData = await this.getDetails();
|
|
934
|
+
}
|
|
923
935
|
if (!playback) {
|
|
924
936
|
playback = this.client.Playback();
|
|
925
937
|
}
|
|
938
|
+
if (!this.channelData?.id) {
|
|
939
|
+
throw new Error("N\xE3o foi poss\xEDvel inicializar o canal. ID inv\xE1lido.");
|
|
940
|
+
}
|
|
926
941
|
await this.baseClient.post(
|
|
927
|
-
`/channels/${this.channelData
|
|
942
|
+
`/channels/${this.channelData.id}/play/${playback.id}`,
|
|
928
943
|
options
|
|
929
944
|
);
|
|
930
945
|
return playback;
|
|
@@ -1631,7 +1646,7 @@ var AriClient = class {
|
|
|
1631
1646
|
* O channel no evento será automaticamente transformado em uma instância de ChannelInstance.
|
|
1632
1647
|
*/
|
|
1633
1648
|
on(eventType, callback) {
|
|
1634
|
-
console.log(`Registrando listener para evento: ${eventType}`);
|
|
1649
|
+
console.log(`Registrando listener no AriClient para evento: ${eventType}`);
|
|
1635
1650
|
const wrappedCallback = (event) => {
|
|
1636
1651
|
if (isChannelEvent(event)) {
|
|
1637
1652
|
const channelId = event.channel.id;
|
|
@@ -1646,6 +1661,8 @@ var AriClient = class {
|
|
|
1646
1661
|
callback(event);
|
|
1647
1662
|
};
|
|
1648
1663
|
this.eventListeners.set(eventType, wrappedCallback);
|
|
1664
|
+
this.pendingListeners.push({ event: eventType, callback: wrappedCallback });
|
|
1665
|
+
this.processPendingListeners();
|
|
1649
1666
|
}
|
|
1650
1667
|
/**
|
|
1651
1668
|
* Type guard to check if the given data object contains a valid channel property.
|
|
@@ -1741,8 +1758,8 @@ var AriClient = class {
|
|
|
1741
1758
|
this.integrateWebSocketEvents(app, this.wsClient);
|
|
1742
1759
|
console.log(`WebSocket conectado para o app: ${app}`);
|
|
1743
1760
|
await this.ensureAppRegistered(app);
|
|
1744
|
-
this.processPendingListeners();
|
|
1745
1761
|
this.isWebSocketConnectedFlag = true;
|
|
1762
|
+
this.processPendingListeners();
|
|
1746
1763
|
}, backoffOptions);
|
|
1747
1764
|
resolve();
|
|
1748
1765
|
} catch (err) {
|