@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/esm/index.js
CHANGED
|
@@ -877,11 +877,15 @@ var ChannelInstance = class extends EventEmitter {
|
|
|
877
877
|
* Obtém os detalhes do canal.
|
|
878
878
|
*/
|
|
879
879
|
async getDetails() {
|
|
880
|
-
if (
|
|
881
|
-
|
|
880
|
+
if (this.channelData) {
|
|
881
|
+
return this.channelData;
|
|
882
|
+
}
|
|
883
|
+
if (!this.channelId) {
|
|
884
|
+
throw new Error("Nenhum ID de canal associado a esta inst\xE2ncia.");
|
|
882
885
|
}
|
|
883
|
-
const
|
|
884
|
-
|
|
886
|
+
const details = await this.baseClient.get(
|
|
887
|
+
`/channels/${this.channelId}`
|
|
888
|
+
);
|
|
885
889
|
this.channelData = details;
|
|
886
890
|
return details;
|
|
887
891
|
}
|
|
@@ -890,7 +894,11 @@ var ChannelInstance = class extends EventEmitter {
|
|
|
890
894
|
*/
|
|
891
895
|
async hangup() {
|
|
892
896
|
if (!this.channelData) {
|
|
893
|
-
|
|
897
|
+
console.log("Canal n\xE3o inicializado, buscando detalhes...");
|
|
898
|
+
this.channelData = await this.getDetails();
|
|
899
|
+
}
|
|
900
|
+
if (!this.channelData?.id) {
|
|
901
|
+
throw new Error("N\xE3o foi poss\xEDvel inicializar o canal. ID inv\xE1lido.");
|
|
894
902
|
}
|
|
895
903
|
await this.baseClient.delete(`/channels/${this.channelData.id}`);
|
|
896
904
|
}
|
|
@@ -898,11 +906,18 @@ var ChannelInstance = class extends EventEmitter {
|
|
|
898
906
|
* Reproduz mídia no canal.
|
|
899
907
|
*/
|
|
900
908
|
async play(options, playback) {
|
|
909
|
+
if (!this.channelData) {
|
|
910
|
+
console.log("Canal n\xE3o inicializado, buscando detalhes...");
|
|
911
|
+
this.channelData = await this.getDetails();
|
|
912
|
+
}
|
|
901
913
|
if (!playback) {
|
|
902
914
|
playback = this.client.Playback();
|
|
903
915
|
}
|
|
916
|
+
if (!this.channelData?.id) {
|
|
917
|
+
throw new Error("N\xE3o foi poss\xEDvel inicializar o canal. ID inv\xE1lido.");
|
|
918
|
+
}
|
|
904
919
|
await this.baseClient.post(
|
|
905
|
-
`/channels/${this.channelData
|
|
920
|
+
`/channels/${this.channelData.id}/play/${playback.id}`,
|
|
906
921
|
options
|
|
907
922
|
);
|
|
908
923
|
return playback;
|
|
@@ -1609,7 +1624,7 @@ var AriClient = class {
|
|
|
1609
1624
|
* O channel no evento será automaticamente transformado em uma instância de ChannelInstance.
|
|
1610
1625
|
*/
|
|
1611
1626
|
on(eventType, callback) {
|
|
1612
|
-
console.log(`Registrando listener para evento: ${eventType}`);
|
|
1627
|
+
console.log(`Registrando listener no AriClient para evento: ${eventType}`);
|
|
1613
1628
|
const wrappedCallback = (event) => {
|
|
1614
1629
|
if (isChannelEvent(event)) {
|
|
1615
1630
|
const channelId = event.channel.id;
|
|
@@ -1624,6 +1639,8 @@ var AriClient = class {
|
|
|
1624
1639
|
callback(event);
|
|
1625
1640
|
};
|
|
1626
1641
|
this.eventListeners.set(eventType, wrappedCallback);
|
|
1642
|
+
this.pendingListeners.push({ event: eventType, callback: wrappedCallback });
|
|
1643
|
+
this.processPendingListeners();
|
|
1627
1644
|
}
|
|
1628
1645
|
/**
|
|
1629
1646
|
* Type guard to check if the given data object contains a valid channel property.
|
|
@@ -1719,8 +1736,8 @@ var AriClient = class {
|
|
|
1719
1736
|
this.integrateWebSocketEvents(app, this.wsClient);
|
|
1720
1737
|
console.log(`WebSocket conectado para o app: ${app}`);
|
|
1721
1738
|
await this.ensureAppRegistered(app);
|
|
1722
|
-
this.processPendingListeners();
|
|
1723
1739
|
this.isWebSocketConnectedFlag = true;
|
|
1740
|
+
this.processPendingListeners();
|
|
1724
1741
|
}, backoffOptions);
|
|
1725
1742
|
resolve();
|
|
1726
1743
|
} catch (err) {
|