@ipcom/asterisk-ari 0.0.26 → 0.0.28
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 +321 -106
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/esm/index.js +321 -106
- package/dist/esm/index.js.map +3 -3
- package/dist/types/ari-client/ariClient.d.ts +16 -2
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/resources/channels.d.ts +110 -41
- package/dist/types/ari-client/resources/channels.d.ts.map +1 -1
- package/dist/types/ari-client/resources/playbacks.d.ts +47 -10
- package/dist/types/ari-client/resources/playbacks.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -572,7 +572,7 @@ var require_backoff = __commonJS({
|
|
|
572
572
|
|
|
573
573
|
// src/ari-client/ariClient.ts
|
|
574
574
|
var import_exponential_backoff = __toESM(require_backoff(), 1);
|
|
575
|
-
import { EventEmitter as
|
|
575
|
+
import { EventEmitter as EventEmitter4 } from "events";
|
|
576
576
|
|
|
577
577
|
// src/ari-client/baseClient.ts
|
|
578
578
|
import axios from "axios";
|
|
@@ -836,55 +836,150 @@ var Bridges = class {
|
|
|
836
836
|
};
|
|
837
837
|
|
|
838
838
|
// src/ari-client/resources/channels.ts
|
|
839
|
+
import { EventEmitter } from "events";
|
|
839
840
|
function toQueryParams2(options) {
|
|
840
841
|
return new URLSearchParams(
|
|
841
842
|
Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
|
|
842
|
-
// Garante que value é string
|
|
843
843
|
).toString();
|
|
844
844
|
}
|
|
845
|
-
var
|
|
846
|
-
constructor(client) {
|
|
845
|
+
var ChannelInstance = class extends EventEmitter {
|
|
846
|
+
constructor(client, channelId) {
|
|
847
|
+
super();
|
|
847
848
|
this.client = client;
|
|
849
|
+
this.channelId = channelId;
|
|
848
850
|
}
|
|
851
|
+
channelData = null;
|
|
849
852
|
/**
|
|
850
|
-
*
|
|
853
|
+
* Origina um canal físico no Asterisk.
|
|
851
854
|
*/
|
|
852
|
-
async
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
throw new Error("Resposta da API /channels n\xE3o \xE9 um array.");
|
|
855
|
+
async originate(data) {
|
|
856
|
+
if (this.channelData) {
|
|
857
|
+
throw new Error("O canal j\xE1 foi criado.");
|
|
856
858
|
}
|
|
857
|
-
|
|
859
|
+
const channel = await this.client.post("/channels", data);
|
|
860
|
+
this.channelData = channel;
|
|
861
|
+
this.emit("ChannelCreated", channel, this);
|
|
862
|
+
return channel;
|
|
858
863
|
}
|
|
859
864
|
/**
|
|
860
|
-
*
|
|
865
|
+
* Obtém os detalhes do canal.
|
|
866
|
+
*/
|
|
867
|
+
async getDetails() {
|
|
868
|
+
if (!this.channelId && !this.channelData) {
|
|
869
|
+
throw new Error("Nenhum canal est\xE1 associado a esta inst\xE2ncia.");
|
|
870
|
+
}
|
|
871
|
+
const id = this.channelId || this.channelData?.id;
|
|
872
|
+
const details = await this.client.get(`/channels/${id}`);
|
|
873
|
+
this.channelData = details;
|
|
874
|
+
return details;
|
|
875
|
+
}
|
|
876
|
+
/**
|
|
877
|
+
* Encerra o canal, se ele já foi criado.
|
|
878
|
+
*/
|
|
879
|
+
async hangup() {
|
|
880
|
+
if (!this.channelData) {
|
|
881
|
+
throw new Error("O canal ainda n\xE3o foi criado.");
|
|
882
|
+
}
|
|
883
|
+
await this.client.delete(`/channels/${this.channelData.id}`);
|
|
884
|
+
this.emit("ChannelHungUp", this.channelData);
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Adiciona um listener para eventos de canal.
|
|
888
|
+
*/
|
|
889
|
+
on(event, callback) {
|
|
890
|
+
super.on(event, callback);
|
|
891
|
+
return this;
|
|
892
|
+
}
|
|
893
|
+
/**
|
|
894
|
+
* Adiciona um listener para ser chamado apenas uma vez.
|
|
895
|
+
*/
|
|
896
|
+
once(event, callback) {
|
|
897
|
+
super.once(event, callback);
|
|
898
|
+
return this;
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Remove um listener específico.
|
|
902
|
+
*/
|
|
903
|
+
off(event, callback) {
|
|
904
|
+
super.off(event, callback);
|
|
905
|
+
return this;
|
|
906
|
+
}
|
|
907
|
+
};
|
|
908
|
+
var Channels = class extends EventEmitter {
|
|
909
|
+
constructor(client) {
|
|
910
|
+
super();
|
|
911
|
+
this.client = client;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Cria uma nova instância de `ChannelInstance` sem originar um canal físico.
|
|
915
|
+
*/
|
|
916
|
+
createChannelInstance(channelId) {
|
|
917
|
+
return new ChannelInstance(this.client, channelId);
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Origina um canal físico diretamente, sem uma instância de `ChannelInstance`.
|
|
861
921
|
*/
|
|
862
922
|
async originate(data) {
|
|
863
923
|
return this.client.post("/channels", data);
|
|
864
924
|
}
|
|
865
925
|
/**
|
|
866
|
-
*
|
|
926
|
+
* Lida com eventos relacionados ao canal e os emite para listeners registrados.
|
|
867
927
|
*/
|
|
868
|
-
|
|
869
|
-
|
|
928
|
+
emitChannelEvent(eventType, data) {
|
|
929
|
+
if ("channel" in data) {
|
|
930
|
+
const channelId = data.channel?.id;
|
|
931
|
+
if (channelId) {
|
|
932
|
+
this.emit(`${eventType}:${channelId}`, data);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
this.emit(eventType, data);
|
|
870
936
|
}
|
|
871
937
|
/**
|
|
872
|
-
*
|
|
938
|
+
* Registra um listener para eventos de canal específicos.
|
|
873
939
|
*/
|
|
874
|
-
|
|
875
|
-
|
|
940
|
+
registerChannelListener(eventType, channelId, callback) {
|
|
941
|
+
this.on(`${eventType}:${channelId}`, callback);
|
|
876
942
|
}
|
|
877
943
|
/**
|
|
878
|
-
*
|
|
944
|
+
* Remove um listener específico de eventos de canal.
|
|
879
945
|
*/
|
|
880
|
-
|
|
881
|
-
|
|
946
|
+
unregisterChannelListener(eventType, channelId, callback) {
|
|
947
|
+
this.off(`${eventType}:${channelId}`, callback);
|
|
948
|
+
}
|
|
949
|
+
/**
|
|
950
|
+
* Verifica se um listener já está registrado para um evento de canal.
|
|
951
|
+
*/
|
|
952
|
+
isChannelListenerRegistered(eventType, channelId) {
|
|
953
|
+
return this.listenerCount(`${eventType}:${channelId}`) > 0;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Lista todos os canais ativos.
|
|
957
|
+
*/
|
|
958
|
+
async list() {
|
|
959
|
+
const channels = await this.client.get("/channels");
|
|
960
|
+
if (!Array.isArray(channels)) {
|
|
961
|
+
throw new Error("Resposta da API /channels n\xE3o \xE9 um array.");
|
|
962
|
+
}
|
|
963
|
+
return channels;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Obtém detalhes de um canal específico.
|
|
967
|
+
*/
|
|
968
|
+
async getDetails(channelId) {
|
|
969
|
+
return this.client.get(`/channels/${channelId}`);
|
|
882
970
|
}
|
|
883
971
|
/**
|
|
884
|
-
*
|
|
972
|
+
* Reproduz mídia em um canal.
|
|
885
973
|
*/
|
|
974
|
+
async playMedia(channelId, media, options) {
|
|
975
|
+
const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
|
|
976
|
+
return this.client.post(
|
|
977
|
+
`/channels/${channelId}/play${queryParams}`,
|
|
978
|
+
{ media }
|
|
979
|
+
);
|
|
980
|
+
}
|
|
886
981
|
/**
|
|
887
|
-
*
|
|
982
|
+
* Encerra um canal específico.
|
|
888
983
|
*/
|
|
889
984
|
async hangup(channelId, options) {
|
|
890
985
|
const queryParams = new URLSearchParams({
|
|
@@ -896,15 +991,82 @@ var Channels = class {
|
|
|
896
991
|
);
|
|
897
992
|
}
|
|
898
993
|
/**
|
|
899
|
-
*
|
|
994
|
+
* Inicia a escuta em um canal.
|
|
900
995
|
*/
|
|
901
|
-
async
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
996
|
+
async snoopChannel(channelId, options) {
|
|
997
|
+
const queryParams = toQueryParams2(options);
|
|
998
|
+
return this.client.post(
|
|
999
|
+
`/channels/${channelId}/snoop?${queryParams}`
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
1002
|
+
async startSilence(channelId) {
|
|
1003
|
+
return this.client.post(`/channels/${channelId}/silence`);
|
|
1004
|
+
}
|
|
1005
|
+
async stopSilence(channelId) {
|
|
1006
|
+
return this.client.delete(`/channels/${channelId}/silence`);
|
|
1007
|
+
}
|
|
1008
|
+
async getRTPStatistics(channelId) {
|
|
1009
|
+
return this.client.get(`/channels/${channelId}/rtp_statistics`);
|
|
1010
|
+
}
|
|
1011
|
+
async createExternalMedia(options) {
|
|
1012
|
+
const queryParams = new URLSearchParams(options);
|
|
1013
|
+
return this.client.post(
|
|
1014
|
+
`/channels/externalMedia?${queryParams.toString()}`
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
async playWithId(channelId, playbackId, media, options) {
|
|
1018
|
+
const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
|
|
1019
|
+
return this.client.post(
|
|
1020
|
+
`/channels/${channelId}/play/${playbackId}${queryParams}`,
|
|
1021
|
+
{ media }
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
async snoopChannelWithId(channelId, snoopId, options) {
|
|
1025
|
+
const queryParams = new URLSearchParams(options);
|
|
1026
|
+
return this.client.post(
|
|
1027
|
+
`/channels/${channelId}/snoop/${snoopId}?${queryParams.toString()}`
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
async startMohWithClass(channelId, mohClass) {
|
|
1031
|
+
const queryParams = `mohClass=${encodeURIComponent(mohClass)}`;
|
|
1032
|
+
return this.client.post(`/channels/${channelId}/moh?${queryParams}`);
|
|
1033
|
+
}
|
|
1034
|
+
/**
|
|
1035
|
+
* Gets the value of a channel variable or function.
|
|
1036
|
+
*
|
|
1037
|
+
* @param channelId - The ID of the channel.
|
|
1038
|
+
* @param variable - The name of the channel variable or function to retrieve.
|
|
1039
|
+
* @returns A promise that resolves to the value of the variable.
|
|
1040
|
+
* @throws Will throw an error if the variable is missing or the channel is not found.
|
|
1041
|
+
*/
|
|
1042
|
+
async getChannelVariable(channelId, variable) {
|
|
1043
|
+
if (!variable) {
|
|
1044
|
+
throw new Error("The 'variable' parameter is required.");
|
|
1045
|
+
}
|
|
1046
|
+
return this.client.get(
|
|
1047
|
+
`/channels/${channelId}/variable?variable=${encodeURIComponent(variable)}`
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Sets the value of a channel variable or function.
|
|
1052
|
+
*
|
|
1053
|
+
* @param channelId - The ID of the channel.
|
|
1054
|
+
* @param variable - The name of the channel variable or function to set.
|
|
1055
|
+
* @param value - The value to set the variable to.
|
|
1056
|
+
* @returns A promise that resolves when the variable is successfully set.
|
|
1057
|
+
* @throws Will throw an error if the variable is missing or the channel is not found.
|
|
1058
|
+
*/
|
|
1059
|
+
async setChannelVariable(channelId, variable, value) {
|
|
1060
|
+
if (!variable) {
|
|
1061
|
+
throw new Error("The 'variable' parameter is required.");
|
|
1062
|
+
}
|
|
1063
|
+
const queryParams = new URLSearchParams({
|
|
1064
|
+
variable,
|
|
1065
|
+
...value && { value }
|
|
907
1066
|
});
|
|
1067
|
+
await this.client.post(
|
|
1068
|
+
`/channels/${channelId}/variable?${queryParams.toString()}`
|
|
1069
|
+
);
|
|
908
1070
|
}
|
|
909
1071
|
/**
|
|
910
1072
|
* Moves the channel to another Stasis application.
|
|
@@ -916,31 +1078,21 @@ var Channels = class {
|
|
|
916
1078
|
});
|
|
917
1079
|
}
|
|
918
1080
|
/**
|
|
919
|
-
*
|
|
1081
|
+
* Continues the dialplan for a specific channel.
|
|
920
1082
|
*/
|
|
921
|
-
async
|
|
922
|
-
return this.client.post(`/channels/${channelId}/
|
|
923
|
-
|
|
924
|
-
|
|
1083
|
+
async continueDialplan(channelId, context, extension, priority, label) {
|
|
1084
|
+
return this.client.post(`/channels/${channelId}/continue`, {
|
|
1085
|
+
context,
|
|
1086
|
+
extension,
|
|
1087
|
+
priority,
|
|
1088
|
+
label
|
|
925
1089
|
});
|
|
926
1090
|
}
|
|
927
1091
|
/**
|
|
928
|
-
*
|
|
929
|
-
*/
|
|
930
|
-
async getVariable(channelId, variable) {
|
|
931
|
-
return this.client.get(
|
|
932
|
-
`/channels/${channelId}/variable?variable=${encodeURIComponent(variable)}`
|
|
933
|
-
);
|
|
934
|
-
}
|
|
935
|
-
/**
|
|
936
|
-
* Plays a media file to a channel.
|
|
1092
|
+
* Stops music on hold (MOH) for a channel.
|
|
937
1093
|
*/
|
|
938
|
-
async
|
|
939
|
-
|
|
940
|
-
return this.client.post(
|
|
941
|
-
`/channels/${channelId}/play${queryParams}`,
|
|
942
|
-
{ media }
|
|
943
|
-
);
|
|
1094
|
+
async stopMusicOnHold(channelId) {
|
|
1095
|
+
return this.client.delete(`/channels/${channelId}/moh`);
|
|
944
1096
|
}
|
|
945
1097
|
/**
|
|
946
1098
|
* Starts music on hold (MOH) for a channel.
|
|
@@ -949,11 +1101,8 @@ var Channels = class {
|
|
|
949
1101
|
return this.client.post(`/channels/${channelId}/moh`);
|
|
950
1102
|
}
|
|
951
1103
|
/**
|
|
952
|
-
*
|
|
1104
|
+
* Starts playback of a media file on a channel.
|
|
953
1105
|
*/
|
|
954
|
-
async stopMusicOnHold(channelId) {
|
|
955
|
-
return this.client.delete(`/channels/${channelId}/moh`);
|
|
956
|
-
}
|
|
957
1106
|
/**
|
|
958
1107
|
* Starts playback of a media file on a channel.
|
|
959
1108
|
*/
|
|
@@ -1019,24 +1168,6 @@ var Channels = class {
|
|
|
1019
1168
|
`/channels/${channelId}/record?${queryParams.toString()}`
|
|
1020
1169
|
);
|
|
1021
1170
|
}
|
|
1022
|
-
/**
|
|
1023
|
-
* Starts snooping on a channel.
|
|
1024
|
-
*/
|
|
1025
|
-
async snoopChannel(channelId, options) {
|
|
1026
|
-
const queryParams = toQueryParams2(options);
|
|
1027
|
-
return this.client.post(
|
|
1028
|
-
`/channels/${channelId}/snoop?${queryParams}`
|
|
1029
|
-
);
|
|
1030
|
-
}
|
|
1031
|
-
/**
|
|
1032
|
-
* Starts snooping on a channel with a specific snoop ID.
|
|
1033
|
-
*/
|
|
1034
|
-
async snoopChannelWithId(channelId, snoopId, options) {
|
|
1035
|
-
const queryParams = new URLSearchParams(options);
|
|
1036
|
-
return this.client.post(
|
|
1037
|
-
`/channels/${channelId}/snoop/${snoopId}?${queryParams.toString()}`
|
|
1038
|
-
);
|
|
1039
|
-
}
|
|
1040
1171
|
/**
|
|
1041
1172
|
* Dials a created channel.
|
|
1042
1173
|
*/
|
|
@@ -1049,21 +1180,6 @@ var Channels = class {
|
|
|
1049
1180
|
`/channels/${channelId}/dial?${queryParams.toString()}`
|
|
1050
1181
|
);
|
|
1051
1182
|
}
|
|
1052
|
-
/**
|
|
1053
|
-
* Retrieves RTP statistics for a channel.
|
|
1054
|
-
*/
|
|
1055
|
-
async getRTPStatistics(channelId) {
|
|
1056
|
-
return this.client.get(`/channels/${channelId}/rtp_statistics`);
|
|
1057
|
-
}
|
|
1058
|
-
/**
|
|
1059
|
-
* Creates a channel to an external media source/sink.
|
|
1060
|
-
*/
|
|
1061
|
-
async createExternalMedia(options) {
|
|
1062
|
-
const queryParams = new URLSearchParams(options);
|
|
1063
|
-
return this.client.post(
|
|
1064
|
-
`/channels/externalMedia?${queryParams.toString()}`
|
|
1065
|
-
);
|
|
1066
|
-
}
|
|
1067
1183
|
/**
|
|
1068
1184
|
* Redirects the channel to a different location.
|
|
1069
1185
|
*/
|
|
@@ -1133,6 +1249,18 @@ var Channels = class {
|
|
|
1133
1249
|
async unholdChannel(channelId) {
|
|
1134
1250
|
return this.client.delete(`/channels/${channelId}/hold`);
|
|
1135
1251
|
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Creates a channel and places it in a Stasis app without dialing it.
|
|
1254
|
+
*/
|
|
1255
|
+
async createChannel(data) {
|
|
1256
|
+
return this.client.post("/channels/create", data);
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Creates a new channel with a specific ID and originates a call.
|
|
1260
|
+
*/
|
|
1261
|
+
async originateWithId(channelId, data) {
|
|
1262
|
+
return this.client.post(`/channels/${channelId}`, data);
|
|
1263
|
+
}
|
|
1136
1264
|
};
|
|
1137
1265
|
|
|
1138
1266
|
// src/ari-client/resources/endpoints.ts
|
|
@@ -1182,12 +1310,93 @@ var Endpoints = class {
|
|
|
1182
1310
|
};
|
|
1183
1311
|
|
|
1184
1312
|
// src/ari-client/resources/playbacks.ts
|
|
1185
|
-
import { EventEmitter } from "events";
|
|
1186
|
-
var
|
|
1313
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
1314
|
+
var PlaybackInstance = class extends EventEmitter2 {
|
|
1315
|
+
constructor(client, playbackId) {
|
|
1316
|
+
super();
|
|
1317
|
+
this.client = client;
|
|
1318
|
+
this.playbackId = playbackId;
|
|
1319
|
+
}
|
|
1320
|
+
playbackData = null;
|
|
1321
|
+
/**
|
|
1322
|
+
* Obtém os detalhes do playback.
|
|
1323
|
+
*/
|
|
1324
|
+
async getDetails() {
|
|
1325
|
+
if (!this.playbackId && !this.playbackData) {
|
|
1326
|
+
throw new Error("Nenhum playback associado a esta inst\xE2ncia.");
|
|
1327
|
+
}
|
|
1328
|
+
const id = this.playbackId || this.playbackData?.id;
|
|
1329
|
+
const details = await this.client.get(`/playbacks/${id}`);
|
|
1330
|
+
this.playbackData = details;
|
|
1331
|
+
return details;
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Controla o playback.
|
|
1335
|
+
*/
|
|
1336
|
+
async control(operation) {
|
|
1337
|
+
if (!this.playbackId) {
|
|
1338
|
+
throw new Error("Nenhum playback associado para controlar.");
|
|
1339
|
+
}
|
|
1340
|
+
await this.client.post(`/playbacks/${this.playbackId}/control`, {
|
|
1341
|
+
operation
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Encerra o playback.
|
|
1346
|
+
*/
|
|
1347
|
+
async stop() {
|
|
1348
|
+
if (!this.playbackId) {
|
|
1349
|
+
throw new Error("Nenhum playback associado para encerrar.");
|
|
1350
|
+
}
|
|
1351
|
+
await this.client.post(`/playbacks/${this.playbackId}/stop`);
|
|
1352
|
+
this.emit("PlaybackStopped", this.playbackData);
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Adiciona um listener para eventos de playback.
|
|
1356
|
+
*/
|
|
1357
|
+
on(event, callback) {
|
|
1358
|
+
super.on(event, callback);
|
|
1359
|
+
return this;
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Adiciona um listener para ser chamado apenas uma vez.
|
|
1363
|
+
*/
|
|
1364
|
+
once(event, callback) {
|
|
1365
|
+
super.once(event, callback);
|
|
1366
|
+
return this;
|
|
1367
|
+
}
|
|
1368
|
+
/**
|
|
1369
|
+
* Remove um listener específico.
|
|
1370
|
+
*/
|
|
1371
|
+
off(event, callback) {
|
|
1372
|
+
super.off(event, callback);
|
|
1373
|
+
return this;
|
|
1374
|
+
}
|
|
1375
|
+
};
|
|
1376
|
+
var Playbacks = class extends EventEmitter2 {
|
|
1187
1377
|
constructor(client) {
|
|
1188
1378
|
super();
|
|
1189
1379
|
this.client = client;
|
|
1190
1380
|
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Inicializa uma nova instância de `PlaybackInstance`.
|
|
1383
|
+
*/
|
|
1384
|
+
Playback(playbackId) {
|
|
1385
|
+
return new PlaybackInstance(this.client, playbackId);
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Emite eventos de playback.
|
|
1389
|
+
* Atualizado para gerenciar eventos específicos para `PlaybackInstance`.
|
|
1390
|
+
*/
|
|
1391
|
+
emitPlaybackEvent(eventType, data) {
|
|
1392
|
+
if ("playbackId" in data) {
|
|
1393
|
+
const playbackId = data.playbackId;
|
|
1394
|
+
if (playbackId) {
|
|
1395
|
+
this.emit(`${eventType}:${playbackId}`, data);
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
this.emit(eventType, data);
|
|
1399
|
+
}
|
|
1191
1400
|
/**
|
|
1192
1401
|
* Retrieves details of a specific playback.
|
|
1193
1402
|
*
|
|
@@ -1255,19 +1464,6 @@ var Playbacks = class extends EventEmitter {
|
|
|
1255
1464
|
isListenerRegistered(eventType, playbackId) {
|
|
1256
1465
|
return this.listenerCount(`${eventType}:${playbackId}`) > 0;
|
|
1257
1466
|
}
|
|
1258
|
-
/**
|
|
1259
|
-
* Emits playback events received via WebSocket.
|
|
1260
|
-
* This method should be called by the WebSocket client when playback events occur.
|
|
1261
|
-
*
|
|
1262
|
-
* @param eventType - The type of the WebSocket event.
|
|
1263
|
-
* @param data - The data associated with the event.
|
|
1264
|
-
*/
|
|
1265
|
-
emitPlaybackEvent(eventType, data) {
|
|
1266
|
-
if ("playbackId" in data) {
|
|
1267
|
-
this.emit(`${eventType}:${data.playbackId}`, data);
|
|
1268
|
-
}
|
|
1269
|
-
this.emit(eventType, data);
|
|
1270
|
-
}
|
|
1271
1467
|
};
|
|
1272
1468
|
|
|
1273
1469
|
// src/ari-client/resources/sounds.ts
|
|
@@ -1302,9 +1498,9 @@ var Sounds = class {
|
|
|
1302
1498
|
};
|
|
1303
1499
|
|
|
1304
1500
|
// src/ari-client/websocketClient.ts
|
|
1305
|
-
import { EventEmitter as
|
|
1501
|
+
import { EventEmitter as EventEmitter3 } from "events";
|
|
1306
1502
|
import WebSocket from "ws";
|
|
1307
|
-
var WebSocketClient = class extends
|
|
1503
|
+
var WebSocketClient = class extends EventEmitter3 {
|
|
1308
1504
|
/**
|
|
1309
1505
|
* Creates a new WebSocketClient instance.
|
|
1310
1506
|
* @param url - The WebSocket server URL to connect to.
|
|
@@ -1443,7 +1639,7 @@ var AriClient = class {
|
|
|
1443
1639
|
wsClient = null;
|
|
1444
1640
|
baseClient;
|
|
1445
1641
|
isReconnecting = false;
|
|
1446
|
-
eventEmitter = new
|
|
1642
|
+
eventEmitter = new EventEmitter4();
|
|
1447
1643
|
channels;
|
|
1448
1644
|
endpoints;
|
|
1449
1645
|
applications;
|
|
@@ -1545,6 +1741,7 @@ var AriClient = class {
|
|
|
1545
1741
|
ChannelDtmfReceived: (data) => {
|
|
1546
1742
|
if ("channel" in data) {
|
|
1547
1743
|
console.log("DTMF recebido no canal:", data.channel);
|
|
1744
|
+
this.channels.emitChannelEvent("ChannelDtmfReceived", data);
|
|
1548
1745
|
}
|
|
1549
1746
|
this.emitGlobalEvent(data);
|
|
1550
1747
|
}
|
|
@@ -1766,13 +1963,13 @@ var AriClient = class {
|
|
|
1766
1963
|
* Sets a channel variable.
|
|
1767
1964
|
*/
|
|
1768
1965
|
async setChannelVariable(channelId, variable, value) {
|
|
1769
|
-
return this.channels.
|
|
1966
|
+
return this.channels.setChannelVariable(channelId, variable, value);
|
|
1770
1967
|
}
|
|
1771
1968
|
/**
|
|
1772
1969
|
* Gets a channel variable.
|
|
1773
1970
|
*/
|
|
1774
1971
|
async getChannelVariable(channelId, variable) {
|
|
1775
|
-
return this.channels.
|
|
1972
|
+
return this.channels.getChannelVariable(channelId, variable);
|
|
1776
1973
|
}
|
|
1777
1974
|
/**
|
|
1778
1975
|
* Plays a media file to a channel.
|
|
@@ -2243,6 +2440,24 @@ var AriClient = class {
|
|
|
2243
2440
|
async setGlobalVariable(variableName, value) {
|
|
2244
2441
|
return this.asterisk.setGlobalVariable(variableName, value);
|
|
2245
2442
|
}
|
|
2443
|
+
/**
|
|
2444
|
+
* Inicializa uma nova instância de `ChannelInstance` para manipular canais localmente.
|
|
2445
|
+
*
|
|
2446
|
+
* @param channelId - O ID do canal, se disponível. Caso contrário, a instância será para um canal ainda não criado.
|
|
2447
|
+
* @returns Uma instância de `ChannelInstance` vinculada ao cliente atual.
|
|
2448
|
+
*/
|
|
2449
|
+
Channel(channelId) {
|
|
2450
|
+
return this.channels.createChannelInstance(channelId);
|
|
2451
|
+
}
|
|
2452
|
+
/**
|
|
2453
|
+
* Inicializa uma nova instância de `PlaybackInstance` para manipular playbacks.
|
|
2454
|
+
*
|
|
2455
|
+
* @param playbackId - O ID do playback, se disponível. Caso contrário, a instância será para um playback ainda não inicializado.
|
|
2456
|
+
* @returns Uma instância de `PlaybackInstance` vinculada ao cliente atual.
|
|
2457
|
+
*/
|
|
2458
|
+
Playback(playbackId) {
|
|
2459
|
+
return this.playbacks.Playback(playbackId);
|
|
2460
|
+
}
|
|
2246
2461
|
};
|
|
2247
2462
|
export {
|
|
2248
2463
|
Applications,
|