@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/cjs/index.cjs
CHANGED
|
@@ -591,7 +591,7 @@ __export(src_exports, {
|
|
|
591
591
|
module.exports = __toCommonJS(src_exports);
|
|
592
592
|
|
|
593
593
|
// src/ari-client/ariClient.ts
|
|
594
|
-
var
|
|
594
|
+
var import_events4 = require("events");
|
|
595
595
|
var import_exponential_backoff = __toESM(require_backoff(), 1);
|
|
596
596
|
|
|
597
597
|
// src/ari-client/baseClient.ts
|
|
@@ -856,55 +856,150 @@ var Bridges = class {
|
|
|
856
856
|
};
|
|
857
857
|
|
|
858
858
|
// src/ari-client/resources/channels.ts
|
|
859
|
+
var import_events = require("events");
|
|
859
860
|
function toQueryParams2(options) {
|
|
860
861
|
return new URLSearchParams(
|
|
861
862
|
Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
|
|
862
|
-
// Garante que value é string
|
|
863
863
|
).toString();
|
|
864
864
|
}
|
|
865
|
-
var
|
|
866
|
-
constructor(client) {
|
|
865
|
+
var ChannelInstance = class extends import_events.EventEmitter {
|
|
866
|
+
constructor(client, channelId) {
|
|
867
|
+
super();
|
|
867
868
|
this.client = client;
|
|
869
|
+
this.channelId = channelId;
|
|
868
870
|
}
|
|
871
|
+
channelData = null;
|
|
869
872
|
/**
|
|
870
|
-
*
|
|
873
|
+
* Origina um canal físico no Asterisk.
|
|
871
874
|
*/
|
|
872
|
-
async
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
throw new Error("Resposta da API /channels n\xE3o \xE9 um array.");
|
|
875
|
+
async originate(data) {
|
|
876
|
+
if (this.channelData) {
|
|
877
|
+
throw new Error("O canal j\xE1 foi criado.");
|
|
876
878
|
}
|
|
877
|
-
|
|
879
|
+
const channel = await this.client.post("/channels", data);
|
|
880
|
+
this.channelData = channel;
|
|
881
|
+
this.emit("ChannelCreated", channel, this);
|
|
882
|
+
return channel;
|
|
878
883
|
}
|
|
879
884
|
/**
|
|
880
|
-
*
|
|
885
|
+
* Obtém os detalhes do canal.
|
|
886
|
+
*/
|
|
887
|
+
async getDetails() {
|
|
888
|
+
if (!this.channelId && !this.channelData) {
|
|
889
|
+
throw new Error("Nenhum canal est\xE1 associado a esta inst\xE2ncia.");
|
|
890
|
+
}
|
|
891
|
+
const id = this.channelId || this.channelData?.id;
|
|
892
|
+
const details = await this.client.get(`/channels/${id}`);
|
|
893
|
+
this.channelData = details;
|
|
894
|
+
return details;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Encerra o canal, se ele já foi criado.
|
|
898
|
+
*/
|
|
899
|
+
async hangup() {
|
|
900
|
+
if (!this.channelData) {
|
|
901
|
+
throw new Error("O canal ainda n\xE3o foi criado.");
|
|
902
|
+
}
|
|
903
|
+
await this.client.delete(`/channels/${this.channelData.id}`);
|
|
904
|
+
this.emit("ChannelHungUp", this.channelData);
|
|
905
|
+
}
|
|
906
|
+
/**
|
|
907
|
+
* Adiciona um listener para eventos de canal.
|
|
908
|
+
*/
|
|
909
|
+
on(event, callback) {
|
|
910
|
+
super.on(event, callback);
|
|
911
|
+
return this;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Adiciona um listener para ser chamado apenas uma vez.
|
|
915
|
+
*/
|
|
916
|
+
once(event, callback) {
|
|
917
|
+
super.once(event, callback);
|
|
918
|
+
return this;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Remove um listener específico.
|
|
922
|
+
*/
|
|
923
|
+
off(event, callback) {
|
|
924
|
+
super.off(event, callback);
|
|
925
|
+
return this;
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
var Channels = class extends import_events.EventEmitter {
|
|
929
|
+
constructor(client) {
|
|
930
|
+
super();
|
|
931
|
+
this.client = client;
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Cria uma nova instância de `ChannelInstance` sem originar um canal físico.
|
|
935
|
+
*/
|
|
936
|
+
createChannelInstance(channelId) {
|
|
937
|
+
return new ChannelInstance(this.client, channelId);
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Origina um canal físico diretamente, sem uma instância de `ChannelInstance`.
|
|
881
941
|
*/
|
|
882
942
|
async originate(data) {
|
|
883
943
|
return this.client.post("/channels", data);
|
|
884
944
|
}
|
|
885
945
|
/**
|
|
886
|
-
*
|
|
946
|
+
* Lida com eventos relacionados ao canal e os emite para listeners registrados.
|
|
887
947
|
*/
|
|
888
|
-
|
|
889
|
-
|
|
948
|
+
emitChannelEvent(eventType, data) {
|
|
949
|
+
if ("channel" in data) {
|
|
950
|
+
const channelId = data.channel?.id;
|
|
951
|
+
if (channelId) {
|
|
952
|
+
this.emit(`${eventType}:${channelId}`, data);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
this.emit(eventType, data);
|
|
890
956
|
}
|
|
891
957
|
/**
|
|
892
|
-
*
|
|
958
|
+
* Registra um listener para eventos de canal específicos.
|
|
893
959
|
*/
|
|
894
|
-
|
|
895
|
-
|
|
960
|
+
registerChannelListener(eventType, channelId, callback) {
|
|
961
|
+
this.on(`${eventType}:${channelId}`, callback);
|
|
896
962
|
}
|
|
897
963
|
/**
|
|
898
|
-
*
|
|
964
|
+
* Remove um listener específico de eventos de canal.
|
|
899
965
|
*/
|
|
900
|
-
|
|
901
|
-
|
|
966
|
+
unregisterChannelListener(eventType, channelId, callback) {
|
|
967
|
+
this.off(`${eventType}:${channelId}`, callback);
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* Verifica se um listener já está registrado para um evento de canal.
|
|
971
|
+
*/
|
|
972
|
+
isChannelListenerRegistered(eventType, channelId) {
|
|
973
|
+
return this.listenerCount(`${eventType}:${channelId}`) > 0;
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Lista todos os canais ativos.
|
|
977
|
+
*/
|
|
978
|
+
async list() {
|
|
979
|
+
const channels = await this.client.get("/channels");
|
|
980
|
+
if (!Array.isArray(channels)) {
|
|
981
|
+
throw new Error("Resposta da API /channels n\xE3o \xE9 um array.");
|
|
982
|
+
}
|
|
983
|
+
return channels;
|
|
984
|
+
}
|
|
985
|
+
/**
|
|
986
|
+
* Obtém detalhes de um canal específico.
|
|
987
|
+
*/
|
|
988
|
+
async getDetails(channelId) {
|
|
989
|
+
return this.client.get(`/channels/${channelId}`);
|
|
902
990
|
}
|
|
903
991
|
/**
|
|
904
|
-
*
|
|
992
|
+
* Reproduz mídia em um canal.
|
|
905
993
|
*/
|
|
994
|
+
async playMedia(channelId, media, options) {
|
|
995
|
+
const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
|
|
996
|
+
return this.client.post(
|
|
997
|
+
`/channels/${channelId}/play${queryParams}`,
|
|
998
|
+
{ media }
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
906
1001
|
/**
|
|
907
|
-
*
|
|
1002
|
+
* Encerra um canal específico.
|
|
908
1003
|
*/
|
|
909
1004
|
async hangup(channelId, options) {
|
|
910
1005
|
const queryParams = new URLSearchParams({
|
|
@@ -916,15 +1011,82 @@ var Channels = class {
|
|
|
916
1011
|
);
|
|
917
1012
|
}
|
|
918
1013
|
/**
|
|
919
|
-
*
|
|
1014
|
+
* Inicia a escuta em um canal.
|
|
920
1015
|
*/
|
|
921
|
-
async
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1016
|
+
async snoopChannel(channelId, options) {
|
|
1017
|
+
const queryParams = toQueryParams2(options);
|
|
1018
|
+
return this.client.post(
|
|
1019
|
+
`/channels/${channelId}/snoop?${queryParams}`
|
|
1020
|
+
);
|
|
1021
|
+
}
|
|
1022
|
+
async startSilence(channelId) {
|
|
1023
|
+
return this.client.post(`/channels/${channelId}/silence`);
|
|
1024
|
+
}
|
|
1025
|
+
async stopSilence(channelId) {
|
|
1026
|
+
return this.client.delete(`/channels/${channelId}/silence`);
|
|
1027
|
+
}
|
|
1028
|
+
async getRTPStatistics(channelId) {
|
|
1029
|
+
return this.client.get(`/channels/${channelId}/rtp_statistics`);
|
|
1030
|
+
}
|
|
1031
|
+
async createExternalMedia(options) {
|
|
1032
|
+
const queryParams = new URLSearchParams(options);
|
|
1033
|
+
return this.client.post(
|
|
1034
|
+
`/channels/externalMedia?${queryParams.toString()}`
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
async playWithId(channelId, playbackId, media, options) {
|
|
1038
|
+
const queryParams = options ? `?${new URLSearchParams(options).toString()}` : "";
|
|
1039
|
+
return this.client.post(
|
|
1040
|
+
`/channels/${channelId}/play/${playbackId}${queryParams}`,
|
|
1041
|
+
{ media }
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
async snoopChannelWithId(channelId, snoopId, options) {
|
|
1045
|
+
const queryParams = new URLSearchParams(options);
|
|
1046
|
+
return this.client.post(
|
|
1047
|
+
`/channels/${channelId}/snoop/${snoopId}?${queryParams.toString()}`
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
async startMohWithClass(channelId, mohClass) {
|
|
1051
|
+
const queryParams = `mohClass=${encodeURIComponent(mohClass)}`;
|
|
1052
|
+
return this.client.post(`/channels/${channelId}/moh?${queryParams}`);
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Gets the value of a channel variable or function.
|
|
1056
|
+
*
|
|
1057
|
+
* @param channelId - The ID of the channel.
|
|
1058
|
+
* @param variable - The name of the channel variable or function to retrieve.
|
|
1059
|
+
* @returns A promise that resolves to the value of the variable.
|
|
1060
|
+
* @throws Will throw an error if the variable is missing or the channel is not found.
|
|
1061
|
+
*/
|
|
1062
|
+
async getChannelVariable(channelId, variable) {
|
|
1063
|
+
if (!variable) {
|
|
1064
|
+
throw new Error("The 'variable' parameter is required.");
|
|
1065
|
+
}
|
|
1066
|
+
return this.client.get(
|
|
1067
|
+
`/channels/${channelId}/variable?variable=${encodeURIComponent(variable)}`
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Sets the value of a channel variable or function.
|
|
1072
|
+
*
|
|
1073
|
+
* @param channelId - The ID of the channel.
|
|
1074
|
+
* @param variable - The name of the channel variable or function to set.
|
|
1075
|
+
* @param value - The value to set the variable to.
|
|
1076
|
+
* @returns A promise that resolves when the variable is successfully set.
|
|
1077
|
+
* @throws Will throw an error if the variable is missing or the channel is not found.
|
|
1078
|
+
*/
|
|
1079
|
+
async setChannelVariable(channelId, variable, value) {
|
|
1080
|
+
if (!variable) {
|
|
1081
|
+
throw new Error("The 'variable' parameter is required.");
|
|
1082
|
+
}
|
|
1083
|
+
const queryParams = new URLSearchParams({
|
|
1084
|
+
variable,
|
|
1085
|
+
...value && { value }
|
|
927
1086
|
});
|
|
1087
|
+
await this.client.post(
|
|
1088
|
+
`/channels/${channelId}/variable?${queryParams.toString()}`
|
|
1089
|
+
);
|
|
928
1090
|
}
|
|
929
1091
|
/**
|
|
930
1092
|
* Moves the channel to another Stasis application.
|
|
@@ -936,31 +1098,21 @@ var Channels = class {
|
|
|
936
1098
|
});
|
|
937
1099
|
}
|
|
938
1100
|
/**
|
|
939
|
-
*
|
|
1101
|
+
* Continues the dialplan for a specific channel.
|
|
940
1102
|
*/
|
|
941
|
-
async
|
|
942
|
-
return this.client.post(`/channels/${channelId}/
|
|
943
|
-
|
|
944
|
-
|
|
1103
|
+
async continueDialplan(channelId, context, extension, priority, label) {
|
|
1104
|
+
return this.client.post(`/channels/${channelId}/continue`, {
|
|
1105
|
+
context,
|
|
1106
|
+
extension,
|
|
1107
|
+
priority,
|
|
1108
|
+
label
|
|
945
1109
|
});
|
|
946
1110
|
}
|
|
947
1111
|
/**
|
|
948
|
-
*
|
|
949
|
-
*/
|
|
950
|
-
async getVariable(channelId, variable) {
|
|
951
|
-
return this.client.get(
|
|
952
|
-
`/channels/${channelId}/variable?variable=${encodeURIComponent(variable)}`
|
|
953
|
-
);
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Plays a media file to a channel.
|
|
1112
|
+
* Stops music on hold (MOH) for a channel.
|
|
957
1113
|
*/
|
|
958
|
-
async
|
|
959
|
-
|
|
960
|
-
return this.client.post(
|
|
961
|
-
`/channels/${channelId}/play${queryParams}`,
|
|
962
|
-
{ media }
|
|
963
|
-
);
|
|
1114
|
+
async stopMusicOnHold(channelId) {
|
|
1115
|
+
return this.client.delete(`/channels/${channelId}/moh`);
|
|
964
1116
|
}
|
|
965
1117
|
/**
|
|
966
1118
|
* Starts music on hold (MOH) for a channel.
|
|
@@ -969,11 +1121,8 @@ var Channels = class {
|
|
|
969
1121
|
return this.client.post(`/channels/${channelId}/moh`);
|
|
970
1122
|
}
|
|
971
1123
|
/**
|
|
972
|
-
*
|
|
1124
|
+
* Starts playback of a media file on a channel.
|
|
973
1125
|
*/
|
|
974
|
-
async stopMusicOnHold(channelId) {
|
|
975
|
-
return this.client.delete(`/channels/${channelId}/moh`);
|
|
976
|
-
}
|
|
977
1126
|
/**
|
|
978
1127
|
* Starts playback of a media file on a channel.
|
|
979
1128
|
*/
|
|
@@ -1039,24 +1188,6 @@ var Channels = class {
|
|
|
1039
1188
|
`/channels/${channelId}/record?${queryParams.toString()}`
|
|
1040
1189
|
);
|
|
1041
1190
|
}
|
|
1042
|
-
/**
|
|
1043
|
-
* Starts snooping on a channel.
|
|
1044
|
-
*/
|
|
1045
|
-
async snoopChannel(channelId, options) {
|
|
1046
|
-
const queryParams = toQueryParams2(options);
|
|
1047
|
-
return this.client.post(
|
|
1048
|
-
`/channels/${channelId}/snoop?${queryParams}`
|
|
1049
|
-
);
|
|
1050
|
-
}
|
|
1051
|
-
/**
|
|
1052
|
-
* Starts snooping on a channel with a specific snoop ID.
|
|
1053
|
-
*/
|
|
1054
|
-
async snoopChannelWithId(channelId, snoopId, options) {
|
|
1055
|
-
const queryParams = new URLSearchParams(options);
|
|
1056
|
-
return this.client.post(
|
|
1057
|
-
`/channels/${channelId}/snoop/${snoopId}?${queryParams.toString()}`
|
|
1058
|
-
);
|
|
1059
|
-
}
|
|
1060
1191
|
/**
|
|
1061
1192
|
* Dials a created channel.
|
|
1062
1193
|
*/
|
|
@@ -1069,21 +1200,6 @@ var Channels = class {
|
|
|
1069
1200
|
`/channels/${channelId}/dial?${queryParams.toString()}`
|
|
1070
1201
|
);
|
|
1071
1202
|
}
|
|
1072
|
-
/**
|
|
1073
|
-
* Retrieves RTP statistics for a channel.
|
|
1074
|
-
*/
|
|
1075
|
-
async getRTPStatistics(channelId) {
|
|
1076
|
-
return this.client.get(`/channels/${channelId}/rtp_statistics`);
|
|
1077
|
-
}
|
|
1078
|
-
/**
|
|
1079
|
-
* Creates a channel to an external media source/sink.
|
|
1080
|
-
*/
|
|
1081
|
-
async createExternalMedia(options) {
|
|
1082
|
-
const queryParams = new URLSearchParams(options);
|
|
1083
|
-
return this.client.post(
|
|
1084
|
-
`/channels/externalMedia?${queryParams.toString()}`
|
|
1085
|
-
);
|
|
1086
|
-
}
|
|
1087
1203
|
/**
|
|
1088
1204
|
* Redirects the channel to a different location.
|
|
1089
1205
|
*/
|
|
@@ -1153,6 +1269,18 @@ var Channels = class {
|
|
|
1153
1269
|
async unholdChannel(channelId) {
|
|
1154
1270
|
return this.client.delete(`/channels/${channelId}/hold`);
|
|
1155
1271
|
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Creates a channel and places it in a Stasis app without dialing it.
|
|
1274
|
+
*/
|
|
1275
|
+
async createChannel(data) {
|
|
1276
|
+
return this.client.post("/channels/create", data);
|
|
1277
|
+
}
|
|
1278
|
+
/**
|
|
1279
|
+
* Creates a new channel with a specific ID and originates a call.
|
|
1280
|
+
*/
|
|
1281
|
+
async originateWithId(channelId, data) {
|
|
1282
|
+
return this.client.post(`/channels/${channelId}`, data);
|
|
1283
|
+
}
|
|
1156
1284
|
};
|
|
1157
1285
|
|
|
1158
1286
|
// src/ari-client/resources/endpoints.ts
|
|
@@ -1202,12 +1330,93 @@ var Endpoints = class {
|
|
|
1202
1330
|
};
|
|
1203
1331
|
|
|
1204
1332
|
// src/ari-client/resources/playbacks.ts
|
|
1205
|
-
var
|
|
1206
|
-
var
|
|
1333
|
+
var import_events2 = require("events");
|
|
1334
|
+
var PlaybackInstance = class extends import_events2.EventEmitter {
|
|
1335
|
+
constructor(client, playbackId) {
|
|
1336
|
+
super();
|
|
1337
|
+
this.client = client;
|
|
1338
|
+
this.playbackId = playbackId;
|
|
1339
|
+
}
|
|
1340
|
+
playbackData = null;
|
|
1341
|
+
/**
|
|
1342
|
+
* Obtém os detalhes do playback.
|
|
1343
|
+
*/
|
|
1344
|
+
async getDetails() {
|
|
1345
|
+
if (!this.playbackId && !this.playbackData) {
|
|
1346
|
+
throw new Error("Nenhum playback associado a esta inst\xE2ncia.");
|
|
1347
|
+
}
|
|
1348
|
+
const id = this.playbackId || this.playbackData?.id;
|
|
1349
|
+
const details = await this.client.get(`/playbacks/${id}`);
|
|
1350
|
+
this.playbackData = details;
|
|
1351
|
+
return details;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Controla o playback.
|
|
1355
|
+
*/
|
|
1356
|
+
async control(operation) {
|
|
1357
|
+
if (!this.playbackId) {
|
|
1358
|
+
throw new Error("Nenhum playback associado para controlar.");
|
|
1359
|
+
}
|
|
1360
|
+
await this.client.post(`/playbacks/${this.playbackId}/control`, {
|
|
1361
|
+
operation
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Encerra o playback.
|
|
1366
|
+
*/
|
|
1367
|
+
async stop() {
|
|
1368
|
+
if (!this.playbackId) {
|
|
1369
|
+
throw new Error("Nenhum playback associado para encerrar.");
|
|
1370
|
+
}
|
|
1371
|
+
await this.client.post(`/playbacks/${this.playbackId}/stop`);
|
|
1372
|
+
this.emit("PlaybackStopped", this.playbackData);
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Adiciona um listener para eventos de playback.
|
|
1376
|
+
*/
|
|
1377
|
+
on(event, callback) {
|
|
1378
|
+
super.on(event, callback);
|
|
1379
|
+
return this;
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Adiciona um listener para ser chamado apenas uma vez.
|
|
1383
|
+
*/
|
|
1384
|
+
once(event, callback) {
|
|
1385
|
+
super.once(event, callback);
|
|
1386
|
+
return this;
|
|
1387
|
+
}
|
|
1388
|
+
/**
|
|
1389
|
+
* Remove um listener específico.
|
|
1390
|
+
*/
|
|
1391
|
+
off(event, callback) {
|
|
1392
|
+
super.off(event, callback);
|
|
1393
|
+
return this;
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
var Playbacks = class extends import_events2.EventEmitter {
|
|
1207
1397
|
constructor(client) {
|
|
1208
1398
|
super();
|
|
1209
1399
|
this.client = client;
|
|
1210
1400
|
}
|
|
1401
|
+
/**
|
|
1402
|
+
* Inicializa uma nova instância de `PlaybackInstance`.
|
|
1403
|
+
*/
|
|
1404
|
+
Playback(playbackId) {
|
|
1405
|
+
return new PlaybackInstance(this.client, playbackId);
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* Emite eventos de playback.
|
|
1409
|
+
* Atualizado para gerenciar eventos específicos para `PlaybackInstance`.
|
|
1410
|
+
*/
|
|
1411
|
+
emitPlaybackEvent(eventType, data) {
|
|
1412
|
+
if ("playbackId" in data) {
|
|
1413
|
+
const playbackId = data.playbackId;
|
|
1414
|
+
if (playbackId) {
|
|
1415
|
+
this.emit(`${eventType}:${playbackId}`, data);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
this.emit(eventType, data);
|
|
1419
|
+
}
|
|
1211
1420
|
/**
|
|
1212
1421
|
* Retrieves details of a specific playback.
|
|
1213
1422
|
*
|
|
@@ -1275,19 +1484,6 @@ var Playbacks = class extends import_events.EventEmitter {
|
|
|
1275
1484
|
isListenerRegistered(eventType, playbackId) {
|
|
1276
1485
|
return this.listenerCount(`${eventType}:${playbackId}`) > 0;
|
|
1277
1486
|
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Emits playback events received via WebSocket.
|
|
1280
|
-
* This method should be called by the WebSocket client when playback events occur.
|
|
1281
|
-
*
|
|
1282
|
-
* @param eventType - The type of the WebSocket event.
|
|
1283
|
-
* @param data - The data associated with the event.
|
|
1284
|
-
*/
|
|
1285
|
-
emitPlaybackEvent(eventType, data) {
|
|
1286
|
-
if ("playbackId" in data) {
|
|
1287
|
-
this.emit(`${eventType}:${data.playbackId}`, data);
|
|
1288
|
-
}
|
|
1289
|
-
this.emit(eventType, data);
|
|
1290
|
-
}
|
|
1291
1487
|
};
|
|
1292
1488
|
|
|
1293
1489
|
// src/ari-client/resources/sounds.ts
|
|
@@ -1322,9 +1518,9 @@ var Sounds = class {
|
|
|
1322
1518
|
};
|
|
1323
1519
|
|
|
1324
1520
|
// src/ari-client/websocketClient.ts
|
|
1325
|
-
var
|
|
1521
|
+
var import_events3 = require("events");
|
|
1326
1522
|
var import_ws = __toESM(require("ws"), 1);
|
|
1327
|
-
var WebSocketClient = class extends
|
|
1523
|
+
var WebSocketClient = class extends import_events3.EventEmitter {
|
|
1328
1524
|
/**
|
|
1329
1525
|
* Creates a new WebSocketClient instance.
|
|
1330
1526
|
* @param url - The WebSocket server URL to connect to.
|
|
@@ -1463,7 +1659,7 @@ var AriClient = class {
|
|
|
1463
1659
|
wsClient = null;
|
|
1464
1660
|
baseClient;
|
|
1465
1661
|
isReconnecting = false;
|
|
1466
|
-
eventEmitter = new
|
|
1662
|
+
eventEmitter = new import_events4.EventEmitter();
|
|
1467
1663
|
channels;
|
|
1468
1664
|
endpoints;
|
|
1469
1665
|
applications;
|
|
@@ -1565,6 +1761,7 @@ var AriClient = class {
|
|
|
1565
1761
|
ChannelDtmfReceived: (data) => {
|
|
1566
1762
|
if ("channel" in data) {
|
|
1567
1763
|
console.log("DTMF recebido no canal:", data.channel);
|
|
1764
|
+
this.channels.emitChannelEvent("ChannelDtmfReceived", data);
|
|
1568
1765
|
}
|
|
1569
1766
|
this.emitGlobalEvent(data);
|
|
1570
1767
|
}
|
|
@@ -1786,13 +1983,13 @@ var AriClient = class {
|
|
|
1786
1983
|
* Sets a channel variable.
|
|
1787
1984
|
*/
|
|
1788
1985
|
async setChannelVariable(channelId, variable, value) {
|
|
1789
|
-
return this.channels.
|
|
1986
|
+
return this.channels.setChannelVariable(channelId, variable, value);
|
|
1790
1987
|
}
|
|
1791
1988
|
/**
|
|
1792
1989
|
* Gets a channel variable.
|
|
1793
1990
|
*/
|
|
1794
1991
|
async getChannelVariable(channelId, variable) {
|
|
1795
|
-
return this.channels.
|
|
1992
|
+
return this.channels.getChannelVariable(channelId, variable);
|
|
1796
1993
|
}
|
|
1797
1994
|
/**
|
|
1798
1995
|
* Plays a media file to a channel.
|
|
@@ -2263,6 +2460,24 @@ var AriClient = class {
|
|
|
2263
2460
|
async setGlobalVariable(variableName, value) {
|
|
2264
2461
|
return this.asterisk.setGlobalVariable(variableName, value);
|
|
2265
2462
|
}
|
|
2463
|
+
/**
|
|
2464
|
+
* Inicializa uma nova instância de `ChannelInstance` para manipular canais localmente.
|
|
2465
|
+
*
|
|
2466
|
+
* @param channelId - O ID do canal, se disponível. Caso contrário, a instância será para um canal ainda não criado.
|
|
2467
|
+
* @returns Uma instância de `ChannelInstance` vinculada ao cliente atual.
|
|
2468
|
+
*/
|
|
2469
|
+
Channel(channelId) {
|
|
2470
|
+
return this.channels.createChannelInstance(channelId);
|
|
2471
|
+
}
|
|
2472
|
+
/**
|
|
2473
|
+
* Inicializa uma nova instância de `PlaybackInstance` para manipular playbacks.
|
|
2474
|
+
*
|
|
2475
|
+
* @param playbackId - O ID do playback, se disponível. Caso contrário, a instância será para um playback ainda não inicializado.
|
|
2476
|
+
* @returns Uma instância de `PlaybackInstance` vinculada ao cliente atual.
|
|
2477
|
+
*/
|
|
2478
|
+
Playback(playbackId) {
|
|
2479
|
+
return this.playbacks.Playback(playbackId);
|
|
2480
|
+
}
|
|
2266
2481
|
};
|
|
2267
2482
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2268
2483
|
0 && (module.exports = {
|