@ipcom/asterisk-ari 0.0.154 → 0.0.156
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/README.md +117 -32
- package/dist/cjs/index.cjs +639 -67
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/esm/index.js +638 -67
- package/dist/esm/index.js.map +4 -4
- package/dist/types/ari-client/ariClient.d.ts +13 -1
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/interfaces/events.types.d.ts +5 -0
- package/dist/types/ari-client/interfaces/events.types.d.ts.map +1 -1
- package/dist/types/ari-client/interfaces/index.d.ts +1 -1
- package/dist/types/ari-client/interfaces/index.d.ts.map +1 -1
- package/dist/types/ari-client/resources/bridges.d.ts +365 -14
- package/dist/types/ari-client/resources/bridges.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -789,7 +789,7 @@ var Applications = class {
|
|
|
789
789
|
}
|
|
790
790
|
/**
|
|
791
791
|
* Lists all applications.
|
|
792
|
-
*
|
|
792
|
+
*
|
|
793
793
|
* @returns A promise that resolves to an array of Application objects.
|
|
794
794
|
* @throws {Error} If the API response is not an array.
|
|
795
795
|
*/
|
|
@@ -802,7 +802,7 @@ var Applications = class {
|
|
|
802
802
|
}
|
|
803
803
|
/**
|
|
804
804
|
* Retrieves details of a specific application.
|
|
805
|
-
*
|
|
805
|
+
*
|
|
806
806
|
* @param appName - The name of the application to retrieve details for.
|
|
807
807
|
* @returns A promise that resolves to an ApplicationDetails object.
|
|
808
808
|
* @throws {Error} If there's an error fetching the application details.
|
|
@@ -819,7 +819,7 @@ var Applications = class {
|
|
|
819
819
|
}
|
|
820
820
|
/**
|
|
821
821
|
* Sends a message to a specific application.
|
|
822
|
-
*
|
|
822
|
+
*
|
|
823
823
|
* @param appName - The name of the application to send the message to.
|
|
824
824
|
* @param body - The message to be sent, containing an event and optional data.
|
|
825
825
|
* @returns A promise that resolves when the message is successfully sent.
|
|
@@ -912,97 +912,655 @@ var Asterisk = class {
|
|
|
912
912
|
};
|
|
913
913
|
|
|
914
914
|
// src/ari-client/resources/bridges.ts
|
|
915
|
+
import { EventEmitter } from "events";
|
|
916
|
+
import { isAxiosError as isAxiosError2 } from "axios";
|
|
917
|
+
|
|
918
|
+
// src/ari-client/interfaces/events.types.ts
|
|
919
|
+
var bridgeEvents = [
|
|
920
|
+
"BridgeCreated",
|
|
921
|
+
"BridgeDestroyed",
|
|
922
|
+
"BridgeMerged",
|
|
923
|
+
"BridgeBlindTransfer",
|
|
924
|
+
"BridgeAttendedTransfer",
|
|
925
|
+
"BridgeVideoSourceChanged"
|
|
926
|
+
];
|
|
927
|
+
|
|
928
|
+
// src/ari-client/utils.ts
|
|
929
|
+
function toQueryParams2(options) {
|
|
930
|
+
return new URLSearchParams(
|
|
931
|
+
Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
|
|
932
|
+
).toString();
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// src/ari-client/resources/bridges.ts
|
|
936
|
+
var getErrorMessage = (error) => {
|
|
937
|
+
if (isAxiosError2(error)) {
|
|
938
|
+
return error.response?.data?.message || error.message || "Um erro do axios ocorreu";
|
|
939
|
+
}
|
|
940
|
+
if (error instanceof Error) {
|
|
941
|
+
return error.message;
|
|
942
|
+
}
|
|
943
|
+
return "Um erro desconhecido ocorreu";
|
|
944
|
+
};
|
|
945
|
+
var BridgeInstance = class {
|
|
946
|
+
/**
|
|
947
|
+
* Creates a new BridgeInstance.
|
|
948
|
+
*
|
|
949
|
+
* @param client - The AriClient instance for making API calls.
|
|
950
|
+
* @param baseClient - The BaseClient instance for making HTTP requests.
|
|
951
|
+
* @param bridgeId - Optional. The ID of the bridge. If not provided, a new ID will be generated.
|
|
952
|
+
*/
|
|
953
|
+
constructor(client, baseClient, bridgeId) {
|
|
954
|
+
this.client = client;
|
|
955
|
+
this.baseClient = baseClient;
|
|
956
|
+
this.id = bridgeId || `bridge-${Date.now()}`;
|
|
957
|
+
}
|
|
958
|
+
eventEmitter = new EventEmitter();
|
|
959
|
+
bridgeData = null;
|
|
960
|
+
id;
|
|
961
|
+
/**
|
|
962
|
+
* Registers a listener for specific bridge events.
|
|
963
|
+
*
|
|
964
|
+
* @param event - The type of event to listen for.
|
|
965
|
+
* @param listener - The callback function to be called when the event occurs.
|
|
966
|
+
*/
|
|
967
|
+
/**
|
|
968
|
+
* Registers a listener for specific bridge events.
|
|
969
|
+
*
|
|
970
|
+
* This method allows you to attach an event listener to the bridge instance for a specific event type.
|
|
971
|
+
* When the specified event occurs, the provided listener function will be called with the event data.
|
|
972
|
+
*
|
|
973
|
+
* @template T - The specific type of WebSocketEvent to listen for.
|
|
974
|
+
* It receives the event data as its parameter.
|
|
975
|
+
* @returns {void}
|
|
976
|
+
*
|
|
977
|
+
* @example
|
|
978
|
+
* bridge.on('BridgeCreated', (event) => {
|
|
979
|
+
*
|
|
980
|
+
* });
|
|
981
|
+
* @param event
|
|
982
|
+
* @param listener
|
|
983
|
+
*/
|
|
984
|
+
on(event, listener) {
|
|
985
|
+
if (!event) {
|
|
986
|
+
throw new Error("Event type is required");
|
|
987
|
+
}
|
|
988
|
+
const wrappedListener = (data) => {
|
|
989
|
+
if ("bridge" in data && data.bridge?.id === this.id) {
|
|
990
|
+
listener(data);
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
this.eventEmitter.on(event, wrappedListener);
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Registers a one-time listener for specific bridge events.
|
|
997
|
+
*
|
|
998
|
+
* @param event - The type of event to listen for.
|
|
999
|
+
* @param listener - The callback function to be called when the event occurs.
|
|
1000
|
+
*/
|
|
1001
|
+
once(event, listener) {
|
|
1002
|
+
if (!event) {
|
|
1003
|
+
throw new Error("Event type is required");
|
|
1004
|
+
}
|
|
1005
|
+
const wrappedListener = (data) => {
|
|
1006
|
+
if ("bridge" in data && data.bridge?.id === this.id) {
|
|
1007
|
+
listener(data);
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
this.eventEmitter.once(event, wrappedListener);
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Removes event listener(s) from the bridge.
|
|
1014
|
+
*
|
|
1015
|
+
* @param event - The type of event to remove listeners for.
|
|
1016
|
+
* @param listener - Optional. The specific listener to remove. If not provided, all listeners for the event will be removed.
|
|
1017
|
+
*/
|
|
1018
|
+
off(event, listener) {
|
|
1019
|
+
if (!event) {
|
|
1020
|
+
throw new Error("Event type is required");
|
|
1021
|
+
}
|
|
1022
|
+
if (listener) {
|
|
1023
|
+
this.eventEmitter.off(event, listener);
|
|
1024
|
+
} else {
|
|
1025
|
+
this.eventEmitter.removeAllListeners(event);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Emits an event if it corresponds to the current bridge.
|
|
1030
|
+
*
|
|
1031
|
+
* @param event - The WebSocketEvent to emit.
|
|
1032
|
+
*/
|
|
1033
|
+
emitEvent(event) {
|
|
1034
|
+
if (!event) {
|
|
1035
|
+
console.warn("Invalid event received");
|
|
1036
|
+
return;
|
|
1037
|
+
}
|
|
1038
|
+
if ("bridge" in event && event.bridge?.id === this.id) {
|
|
1039
|
+
this.eventEmitter.emit(event.type, event);
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
/**
|
|
1043
|
+
* Removes all event listeners from this bridge instance.
|
|
1044
|
+
*/
|
|
1045
|
+
removeAllListeners() {
|
|
1046
|
+
this.eventEmitter.removeAllListeners();
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Retrieves the current details of the bridge.
|
|
1050
|
+
*
|
|
1051
|
+
* @returns A Promise that resolves to the Bridge object containing the current details.
|
|
1052
|
+
* @throws An error if the retrieval fails.
|
|
1053
|
+
*/
|
|
1054
|
+
async get() {
|
|
1055
|
+
try {
|
|
1056
|
+
if (!this.id) {
|
|
1057
|
+
throw new Error("No bridge associated with this instance");
|
|
1058
|
+
}
|
|
1059
|
+
this.bridgeData = await this.baseClient.get(
|
|
1060
|
+
`/bridges/${this.id}`
|
|
1061
|
+
);
|
|
1062
|
+
return this.bridgeData;
|
|
1063
|
+
} catch (error) {
|
|
1064
|
+
const message = getErrorMessage(error);
|
|
1065
|
+
console.error(`Error retrieving details for bridge ${this.id}:`, message);
|
|
1066
|
+
throw new Error(`Failed to get bridge details: ${message}`);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Adds channels to the bridge.
|
|
1071
|
+
*
|
|
1072
|
+
* @param request - The AddChannelRequest object containing the channels to add.
|
|
1073
|
+
* @throws An error if the operation fails.
|
|
1074
|
+
*/
|
|
1075
|
+
async add(request) {
|
|
1076
|
+
try {
|
|
1077
|
+
const queryParams = toQueryParams2({
|
|
1078
|
+
channel: Array.isArray(request.channel) ? request.channel.join(",") : request.channel,
|
|
1079
|
+
...request.role && { role: request.role }
|
|
1080
|
+
});
|
|
1081
|
+
await this.baseClient.post(
|
|
1082
|
+
`/bridges/${this.id}/addChannel?${queryParams}`
|
|
1083
|
+
);
|
|
1084
|
+
} catch (error) {
|
|
1085
|
+
const message = getErrorMessage(error);
|
|
1086
|
+
console.error(`Error adding channels to bridge ${this.id}:`, message);
|
|
1087
|
+
throw new Error(`Failed to add channels: ${message}`);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
/**
|
|
1091
|
+
* Removes channels from the bridge.
|
|
1092
|
+
*
|
|
1093
|
+
* @param request - The RemoveChannelRequest object containing the channels to remove.
|
|
1094
|
+
* @throws An error if the operation fails.
|
|
1095
|
+
*/
|
|
1096
|
+
async remove(request) {
|
|
1097
|
+
try {
|
|
1098
|
+
const queryParams = toQueryParams2({
|
|
1099
|
+
channel: Array.isArray(request.channel) ? request.channel.join(",") : request.channel
|
|
1100
|
+
});
|
|
1101
|
+
await this.baseClient.post(
|
|
1102
|
+
`/bridges/${this.id}/removeChannel?${queryParams}`
|
|
1103
|
+
);
|
|
1104
|
+
} catch (error) {
|
|
1105
|
+
const message = getErrorMessage(error);
|
|
1106
|
+
console.error(`Error removing channels from bridge ${this.id}:`, message);
|
|
1107
|
+
throw new Error(`Failed to remove channels: ${message}`);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Plays media on the bridge.
|
|
1112
|
+
*
|
|
1113
|
+
* @param request - The PlayMediaRequest object containing the media details to play.
|
|
1114
|
+
* @returns A Promise that resolves to a BridgePlayback object.
|
|
1115
|
+
* @throws An error if the operation fails.
|
|
1116
|
+
*/
|
|
1117
|
+
async playMedia(request) {
|
|
1118
|
+
try {
|
|
1119
|
+
const queryParams = new URLSearchParams({
|
|
1120
|
+
...request.lang && { lang: request.lang },
|
|
1121
|
+
...request.offsetms && { offsetms: request.offsetms.toString() },
|
|
1122
|
+
...request.skipms && { skipms: request.skipms.toString() },
|
|
1123
|
+
...request.playbackId && { playbackId: request.playbackId }
|
|
1124
|
+
}).toString();
|
|
1125
|
+
const result = await this.baseClient.post(
|
|
1126
|
+
`/bridges/${this.id}/play?${queryParams}`,
|
|
1127
|
+
{ media: request.media }
|
|
1128
|
+
);
|
|
1129
|
+
return result;
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
const message = getErrorMessage(error);
|
|
1132
|
+
console.error(`Error playing media on bridge ${this.id}:`, message);
|
|
1133
|
+
throw new Error(`Failed to play media: ${message}`);
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Stops media playback on the bridge.
|
|
1138
|
+
*
|
|
1139
|
+
* @param playbackId - The ID of the playback to stop.
|
|
1140
|
+
* @throws An error if the operation fails.
|
|
1141
|
+
*/
|
|
1142
|
+
async stopPlayback(playbackId) {
|
|
1143
|
+
try {
|
|
1144
|
+
await this.baseClient.delete(
|
|
1145
|
+
`/bridges/${this.id}/play/${playbackId}`
|
|
1146
|
+
);
|
|
1147
|
+
} catch (error) {
|
|
1148
|
+
const message = getErrorMessage(error);
|
|
1149
|
+
console.error(`Error stopping playback on bridge ${this.id}:`, message);
|
|
1150
|
+
throw new Error(`Failed to stop playback: ${message}`);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* Sets the video source for the bridge.
|
|
1155
|
+
*
|
|
1156
|
+
* @param channelId - The ID of the channel to set as the video source.
|
|
1157
|
+
* @throws An error if the operation fails.
|
|
1158
|
+
*/
|
|
1159
|
+
async setVideoSource(channelId) {
|
|
1160
|
+
try {
|
|
1161
|
+
await this.baseClient.post(
|
|
1162
|
+
`/bridges/${this.id}/videoSource/${channelId}`
|
|
1163
|
+
);
|
|
1164
|
+
} catch (error) {
|
|
1165
|
+
const message = getErrorMessage(error);
|
|
1166
|
+
console.error(
|
|
1167
|
+
`Error setting video source for bridge ${this.id}:`,
|
|
1168
|
+
message
|
|
1169
|
+
);
|
|
1170
|
+
throw new Error(`Failed to set video source: ${message}`);
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Removes the video source from the bridge.
|
|
1175
|
+
*
|
|
1176
|
+
* @throws An error if the operation fails.
|
|
1177
|
+
*/
|
|
1178
|
+
async clearVideoSource() {
|
|
1179
|
+
try {
|
|
1180
|
+
await this.baseClient.delete(`/bridges/${this.id}/videoSource`);
|
|
1181
|
+
} catch (error) {
|
|
1182
|
+
const message = getErrorMessage(error);
|
|
1183
|
+
console.error(
|
|
1184
|
+
`Error removing video source from bridge ${this.id}:`,
|
|
1185
|
+
message
|
|
1186
|
+
);
|
|
1187
|
+
throw new Error(`Failed to remove video source: ${message}`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Checks if the bridge has listeners for a specific event.
|
|
1192
|
+
*
|
|
1193
|
+
* @param event - The event type to check for listeners.
|
|
1194
|
+
* @returns A boolean indicating whether there are listeners for the event.
|
|
1195
|
+
*/
|
|
1196
|
+
hasListeners(event) {
|
|
1197
|
+
return this.eventEmitter.listenerCount(event) > 0;
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Retrieves the current bridge data without making an API call.
|
|
1201
|
+
*
|
|
1202
|
+
* @returns The current Bridge object or null if no data is available.
|
|
1203
|
+
*/
|
|
1204
|
+
getCurrentData() {
|
|
1205
|
+
return this.bridgeData;
|
|
1206
|
+
}
|
|
1207
|
+
};
|
|
915
1208
|
var Bridges = class {
|
|
916
|
-
constructor(client) {
|
|
1209
|
+
constructor(baseClient, client) {
|
|
1210
|
+
this.baseClient = baseClient;
|
|
917
1211
|
this.client = client;
|
|
918
1212
|
}
|
|
1213
|
+
bridgeInstances = /* @__PURE__ */ new Map();
|
|
919
1214
|
/**
|
|
920
|
-
*
|
|
1215
|
+
* Creates or retrieves a Bridge instance.
|
|
1216
|
+
*
|
|
1217
|
+
* This method manages the creation and retrieval of BridgeInstance objects.
|
|
1218
|
+
* If an ID is provided and an instance with that ID already exists, it returns the existing instance.
|
|
1219
|
+
* If an ID is provided but no instance exists, it creates a new instance with that ID.
|
|
1220
|
+
* If no ID is provided, it creates a new instance with a generated ID.
|
|
1221
|
+
*
|
|
1222
|
+
* @param {Object} params - The parameters for creating or retrieving a Bridge instance.
|
|
1223
|
+
* @param {string} [params.id] - Optional. The ID of the Bridge instance to create or retrieve.
|
|
1224
|
+
*
|
|
1225
|
+
* @returns {BridgeInstance} A BridgeInstance object, either newly created or retrieved from existing instances.
|
|
1226
|
+
*
|
|
1227
|
+
* @throws {Error} If there's an error in creating or retrieving the Bridge instance.
|
|
1228
|
+
*/
|
|
1229
|
+
Bridge({ id }) {
|
|
1230
|
+
try {
|
|
1231
|
+
if (!id) {
|
|
1232
|
+
const instance = new BridgeInstance(this.client, this.baseClient);
|
|
1233
|
+
this.bridgeInstances.set(instance.id, instance);
|
|
1234
|
+
return instance;
|
|
1235
|
+
}
|
|
1236
|
+
if (!this.bridgeInstances.has(id)) {
|
|
1237
|
+
const instance = new BridgeInstance(this.client, this.baseClient, id);
|
|
1238
|
+
this.bridgeInstances.set(id, instance);
|
|
1239
|
+
return instance;
|
|
1240
|
+
}
|
|
1241
|
+
return this.bridgeInstances.get(id);
|
|
1242
|
+
} catch (error) {
|
|
1243
|
+
const message = getErrorMessage(error);
|
|
1244
|
+
throw new Error(`Failed to manage bridge instance: ${message}`);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Removes a bridge instance from the collection of managed bridges.
|
|
1249
|
+
*
|
|
1250
|
+
* This function removes the specified bridge instance, cleans up its event listeners,
|
|
1251
|
+
* and logs the removal. If the bridge instance doesn't exist, it logs a warning.
|
|
1252
|
+
*
|
|
1253
|
+
* @param {string} bridgeId - The unique identifier of the bridge instance to be removed.
|
|
1254
|
+
* @throws {Error} Throws an error if the bridgeId is not provided.
|
|
1255
|
+
* @returns {void}
|
|
1256
|
+
*/
|
|
1257
|
+
removeBridgeInstance(bridgeId) {
|
|
1258
|
+
if (!bridgeId) {
|
|
1259
|
+
throw new Error("ID da bridge \xE9 obrigat\xF3rio");
|
|
1260
|
+
}
|
|
1261
|
+
if (this.bridgeInstances.has(bridgeId)) {
|
|
1262
|
+
const instance = this.bridgeInstances.get(bridgeId);
|
|
1263
|
+
instance?.removeAllListeners();
|
|
1264
|
+
this.bridgeInstances.delete(bridgeId);
|
|
1265
|
+
} else {
|
|
1266
|
+
console.warn(`Tentativa de remover inst\xE2ncia inexistente: ${bridgeId}`);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
/**
|
|
1270
|
+
* Propagates a WebSocket event to a specific bridge instance.
|
|
1271
|
+
*
|
|
1272
|
+
* This function checks if the received event is valid and related to a bridge,
|
|
1273
|
+
* then emits the event to the corresponding bridge instance if it exists.
|
|
1274
|
+
*
|
|
1275
|
+
* @param {WebSocketEvent} event - The WebSocket event to be propagated.
|
|
1276
|
+
* This should be an object containing information about the event,
|
|
1277
|
+
* including the bridge ID and event type.
|
|
1278
|
+
*
|
|
1279
|
+
* @returns {void}
|
|
1280
|
+
*
|
|
1281
|
+
* @remarks
|
|
1282
|
+
* - If the event is invalid (null or undefined), a warning is logged and the function returns early.
|
|
1283
|
+
* - The function checks if the event is bridge-related and if the event type is included in the predefined bridge events.
|
|
1284
|
+
* - If a matching bridge instance is found, the event is emitted to that instance.
|
|
1285
|
+
* - If no matching bridge instance is found, a warning is logged.
|
|
1286
|
+
*/
|
|
1287
|
+
propagateEventToBridge(event) {
|
|
1288
|
+
if (!event) {
|
|
1289
|
+
console.warn("Evento WebSocket inv\xE1lido recebido");
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
if ("bridge" in event && event.bridge?.id && bridgeEvents.includes(event.type)) {
|
|
1293
|
+
const instance = this.bridgeInstances.get(event.bridge.id);
|
|
1294
|
+
if (instance) {
|
|
1295
|
+
instance.emitEvent(event);
|
|
1296
|
+
} else {
|
|
1297
|
+
console.warn(
|
|
1298
|
+
`Nenhuma inst\xE2ncia encontrada para bridge ${event.bridge.id}`
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
/**
|
|
1304
|
+
* Lists all active bridges in the system.
|
|
1305
|
+
*
|
|
1306
|
+
* This asynchronous function retrieves a list of all currently active bridges
|
|
1307
|
+
* by making a GET request to the "/bridges" endpoint using the base client.
|
|
1308
|
+
*
|
|
1309
|
+
* @returns {Promise<Bridge[]>} A promise that resolves to an array of Bridge objects.
|
|
1310
|
+
* Each Bridge object represents an active bridge in the system.
|
|
1311
|
+
*
|
|
1312
|
+
* @throws {Error} If there's an error in fetching the bridges or if the request fails.
|
|
1313
|
+
*
|
|
1314
|
+
* @example
|
|
1315
|
+
* try {
|
|
1316
|
+
* const bridges = await bridgesInstance.list();
|
|
1317
|
+
*
|
|
1318
|
+
* } catch (error) {
|
|
1319
|
+
* console.error('Failed to fetch bridges:', error);
|
|
1320
|
+
* }
|
|
921
1321
|
*/
|
|
922
1322
|
async list() {
|
|
923
|
-
return this.
|
|
1323
|
+
return this.baseClient.get("/bridges");
|
|
924
1324
|
}
|
|
925
1325
|
/**
|
|
926
|
-
* Creates a new bridge.
|
|
1326
|
+
* Creates a new bridge in the system.
|
|
1327
|
+
*
|
|
1328
|
+
* This asynchronous function sends a POST request to create a new bridge
|
|
1329
|
+
* using the provided configuration details.
|
|
1330
|
+
*
|
|
1331
|
+
* @param request - The configuration details for creating the new bridge.
|
|
1332
|
+
* @param request.type - The type of bridge to create (e.g., 'mixing', 'holding').
|
|
1333
|
+
* @param request.name - Optional. A custom name for the bridge.
|
|
1334
|
+
* @param request.bridgeId - Optional. A specific ID for the bridge. If not provided, one will be generated.
|
|
1335
|
+
*
|
|
1336
|
+
* @returns A Promise that resolves to a Bridge object representing the newly created bridge.
|
|
1337
|
+
* The Bridge object contains details such as id, technology, bridge_type, bridge_class, channels, etc.
|
|
1338
|
+
*
|
|
1339
|
+
* @throws Will throw an error if the bridge creation fails or if there's a network issue.
|
|
927
1340
|
*/
|
|
928
1341
|
async createBridge(request) {
|
|
929
|
-
return this.
|
|
1342
|
+
return this.baseClient.post("/bridges", request);
|
|
930
1343
|
}
|
|
931
1344
|
/**
|
|
932
|
-
* Retrieves
|
|
1345
|
+
* Retrieves detailed information about a specific bridge.
|
|
1346
|
+
*
|
|
1347
|
+
* This asynchronous function fetches the complete details of a bridge
|
|
1348
|
+
* identified by its unique ID. It makes a GET request to the ARI endpoint
|
|
1349
|
+
* for the specified bridge.
|
|
1350
|
+
*
|
|
1351
|
+
* @param bridgeId - The unique identifier of the bridge to retrieve details for.
|
|
1352
|
+
* This should be a string that uniquely identifies the bridge in the system.
|
|
1353
|
+
*
|
|
1354
|
+
* @returns A Promise that resolves to a Bridge object containing all the details
|
|
1355
|
+
* of the specified bridge. This includes information such as the bridge's
|
|
1356
|
+
* ID, type, channels, and other relevant properties.
|
|
1357
|
+
*
|
|
1358
|
+
* @throws Will throw an error if the bridge cannot be found, if there's a network issue,
|
|
1359
|
+
* or if the server responds with an error.
|
|
933
1360
|
*/
|
|
934
|
-
async
|
|
935
|
-
return this.
|
|
1361
|
+
async get(bridgeId) {
|
|
1362
|
+
return this.baseClient.get(`/bridges/${bridgeId}`);
|
|
936
1363
|
}
|
|
937
1364
|
/**
|
|
938
|
-
* Destroys (deletes) a specific bridge.
|
|
1365
|
+
* Destroys (deletes) a specific bridge in the system.
|
|
1366
|
+
*
|
|
1367
|
+
* This asynchronous function sends a DELETE request to remove a bridge
|
|
1368
|
+
* identified by its unique ID. Once destroyed, the bridge and all its
|
|
1369
|
+
* associated resources are permanently removed from the system.
|
|
1370
|
+
*
|
|
1371
|
+
* @param bridgeId - The unique identifier of the bridge to be destroyed.
|
|
1372
|
+
* This should be a string that uniquely identifies the bridge in the system.
|
|
1373
|
+
*
|
|
1374
|
+
* @returns A Promise that resolves to void when the bridge is successfully destroyed.
|
|
1375
|
+
* If the operation is successful, the bridge no longer exists in the system.
|
|
1376
|
+
*
|
|
1377
|
+
* @throws Will throw an error if the bridge cannot be found, if there's a network issue,
|
|
1378
|
+
* or if the server responds with an error during the deletion process.
|
|
939
1379
|
*/
|
|
940
1380
|
async destroy(bridgeId) {
|
|
941
|
-
return this.
|
|
1381
|
+
return this.baseClient.delete(`/bridges/${bridgeId}`);
|
|
942
1382
|
}
|
|
943
1383
|
/**
|
|
944
|
-
* Adds
|
|
1384
|
+
* Adds one or more channels to a specified bridge.
|
|
1385
|
+
*
|
|
1386
|
+
* This asynchronous function sends a POST request to add channels to an existing bridge.
|
|
1387
|
+
* It can handle adding a single channel or multiple channels in one operation.
|
|
1388
|
+
*
|
|
1389
|
+
* @param bridgeId - The unique identifier of the bridge to which channels will be added.
|
|
1390
|
+
* @param request - An object containing the details of the channel(s) to be added.
|
|
1391
|
+
* @param request.channel - A single channel ID or an array of channel IDs to add to the bridge.
|
|
1392
|
+
* @param request.role - Optional. Specifies the role of the channel(s) in the bridge.
|
|
1393
|
+
*
|
|
1394
|
+
* @returns A Promise that resolves to void when the operation is successful.
|
|
1395
|
+
*
|
|
1396
|
+
* @throws Will throw an error if the request fails, such as if the bridge doesn't exist
|
|
1397
|
+
* or if there's a network issue.
|
|
945
1398
|
*/
|
|
946
1399
|
async addChannels(bridgeId, request) {
|
|
947
|
-
const queryParams =
|
|
1400
|
+
const queryParams = toQueryParams2({
|
|
948
1401
|
channel: Array.isArray(request.channel) ? request.channel.join(",") : request.channel,
|
|
949
1402
|
...request.role && { role: request.role }
|
|
950
|
-
})
|
|
951
|
-
await this.
|
|
1403
|
+
});
|
|
1404
|
+
await this.baseClient.post(
|
|
952
1405
|
`/bridges/${bridgeId}/addChannel?${queryParams}`
|
|
953
1406
|
);
|
|
954
1407
|
}
|
|
955
1408
|
/**
|
|
956
|
-
* Removes
|
|
1409
|
+
* Removes one or more channels from a specified bridge.
|
|
1410
|
+
*
|
|
1411
|
+
* This asynchronous function sends a POST request to remove channels from an existing bridge.
|
|
1412
|
+
* It can handle removing a single channel or multiple channels in one operation.
|
|
1413
|
+
*
|
|
1414
|
+
* @param bridgeId - The unique identifier of the bridge from which channels will be removed.
|
|
1415
|
+
* @param request - An object containing the details of the channel(s) to be removed.
|
|
1416
|
+
* @param request.channel - A single channel ID or an array of channel IDs to remove from the bridge.
|
|
1417
|
+
*
|
|
1418
|
+
* @returns A Promise that resolves to void when the operation is successful.
|
|
1419
|
+
*
|
|
1420
|
+
* @throws Will throw an error if the request fails, such as if the bridge doesn't exist,
|
|
1421
|
+
* if the channels are not in the bridge, or if there's a network issue.
|
|
957
1422
|
*/
|
|
958
1423
|
async removeChannels(bridgeId, request) {
|
|
959
|
-
const queryParams =
|
|
1424
|
+
const queryParams = toQueryParams2({
|
|
960
1425
|
channel: Array.isArray(request.channel) ? request.channel.join(",") : request.channel
|
|
961
|
-
})
|
|
962
|
-
await this.
|
|
1426
|
+
});
|
|
1427
|
+
await this.baseClient.post(
|
|
963
1428
|
`/bridges/${bridgeId}/removeChannel?${queryParams}`
|
|
964
1429
|
);
|
|
965
1430
|
}
|
|
966
1431
|
/**
|
|
967
|
-
* Plays media
|
|
1432
|
+
* Plays media on a specified bridge.
|
|
1433
|
+
*
|
|
1434
|
+
* This asynchronous function initiates media playback on a bridge identified by its ID.
|
|
1435
|
+
* It allows for customization of the playback through various options in the request.
|
|
1436
|
+
*
|
|
1437
|
+
* @param bridgeId - The unique identifier of the bridge on which to play the media.
|
|
1438
|
+
* @param request - An object containing the media playback request details.
|
|
1439
|
+
* @param request.media - The media to be played (e.g., sound file, URL).
|
|
1440
|
+
* @param request.lang - Optional. The language of the media content.
|
|
1441
|
+
* @param request.offsetms - Optional. The offset in milliseconds to start playing from.
|
|
1442
|
+
* @param request.skipms - Optional. The number of milliseconds to skip before playing.
|
|
1443
|
+
* @param request.playbackId - Optional. A custom ID for the playback session.
|
|
1444
|
+
*
|
|
1445
|
+
* @returns A Promise that resolves to a BridgePlayback object, containing details about the initiated playback.
|
|
1446
|
+
*
|
|
1447
|
+
* @throws Will throw an error if the playback request fails or if there's a network issue.
|
|
968
1448
|
*/
|
|
969
1449
|
async playMedia(bridgeId, request) {
|
|
970
|
-
const queryParams =
|
|
1450
|
+
const queryParams = toQueryParams2({
|
|
971
1451
|
...request.lang && { lang: request.lang },
|
|
972
1452
|
...request.offsetms && { offsetms: request.offsetms.toString() },
|
|
973
1453
|
...request.skipms && { skipms: request.skipms.toString() },
|
|
974
1454
|
...request.playbackId && { playbackId: request.playbackId }
|
|
975
|
-
})
|
|
976
|
-
return this.
|
|
1455
|
+
});
|
|
1456
|
+
return this.baseClient.post(
|
|
977
1457
|
`/bridges/${bridgeId}/play?${queryParams}`,
|
|
978
1458
|
{ media: request.media }
|
|
979
1459
|
);
|
|
980
1460
|
}
|
|
981
1461
|
/**
|
|
982
|
-
* Stops media playback on a bridge.
|
|
1462
|
+
* Stops media playback on a specified bridge.
|
|
1463
|
+
*
|
|
1464
|
+
* This asynchronous function sends a DELETE request to stop the playback of media
|
|
1465
|
+
* on a bridge identified by its ID and a specific playback session.
|
|
1466
|
+
*
|
|
1467
|
+
* @param bridgeId - The unique identifier of the bridge where the playback is to be stopped.
|
|
1468
|
+
* @param playbackId - The unique identifier of the playback session to be stopped.
|
|
1469
|
+
*
|
|
1470
|
+
* @returns A Promise that resolves to void when the playback is successfully stopped.
|
|
1471
|
+
*
|
|
1472
|
+
* @throws Will throw an error if the request fails, such as if the bridge or playback session
|
|
1473
|
+
* doesn't exist, or if there's a network issue.
|
|
983
1474
|
*/
|
|
984
1475
|
async stopPlayback(bridgeId, playbackId) {
|
|
985
|
-
await this.
|
|
1476
|
+
await this.baseClient.delete(
|
|
1477
|
+
`/bridges/${bridgeId}/play/${playbackId}`
|
|
1478
|
+
);
|
|
986
1479
|
}
|
|
987
1480
|
/**
|
|
988
|
-
* Sets the video source for a bridge.
|
|
1481
|
+
* Sets the video source for a specified bridge.
|
|
1482
|
+
*
|
|
1483
|
+
* This asynchronous function configures a channel as the video source for a given bridge.
|
|
1484
|
+
* It sends a POST request to the ARI endpoint to update the bridge's video source.
|
|
1485
|
+
*
|
|
1486
|
+
* @param bridgeId - The unique identifier of the bridge for which to set the video source.
|
|
1487
|
+
* @param channelId - The unique identifier of the channel to be set as the video source.
|
|
1488
|
+
*
|
|
1489
|
+
* @returns A Promise that resolves to void when the video source is successfully set.
|
|
1490
|
+
*
|
|
1491
|
+
* @throws Will throw an error if the request fails, such as if the bridge or channel
|
|
1492
|
+
* doesn't exist, or if there's a network issue.
|
|
989
1493
|
*/
|
|
990
1494
|
async setVideoSource(bridgeId, channelId) {
|
|
991
|
-
|
|
992
|
-
|
|
1495
|
+
const queryParams = toQueryParams2({ channelId });
|
|
1496
|
+
await this.baseClient.post(
|
|
1497
|
+
`/bridges/${bridgeId}/videoSource?${queryParams}`
|
|
993
1498
|
);
|
|
994
1499
|
}
|
|
995
1500
|
/**
|
|
996
|
-
* Clears the video source for a bridge.
|
|
1501
|
+
* Clears the video source for a specified bridge.
|
|
1502
|
+
*
|
|
1503
|
+
* This asynchronous function removes the currently set video source from a bridge.
|
|
1504
|
+
* It sends a DELETE request to the ARI endpoint to clear the video source configuration.
|
|
1505
|
+
*
|
|
1506
|
+
* @param bridgeId - The unique identifier of the bridge from which to clear the video source.
|
|
1507
|
+
* This should be a string that uniquely identifies the bridge in the system.
|
|
1508
|
+
*
|
|
1509
|
+
* @returns A Promise that resolves to void when the video source is successfully cleared.
|
|
1510
|
+
* If the operation is successful, the bridge will no longer have a designated video source.
|
|
1511
|
+
*
|
|
1512
|
+
* @throws Will throw an error if the request fails, such as if the bridge doesn't exist,
|
|
1513
|
+
* if there's no video source set, or if there's a network issue.
|
|
997
1514
|
*/
|
|
998
1515
|
async clearVideoSource(bridgeId) {
|
|
999
|
-
await this.
|
|
1516
|
+
await this.baseClient.delete(`/bridges/${bridgeId}/videoSource`);
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Retrieves the count of active bridge instances.
|
|
1520
|
+
*
|
|
1521
|
+
* This function returns the total number of bridge instances currently
|
|
1522
|
+
* managed by the Bridges class. It provides a quick way to check how many
|
|
1523
|
+
* active bridges are present in the system.
|
|
1524
|
+
*
|
|
1525
|
+
* @returns {number} The count of active bridge instances.
|
|
1526
|
+
*/
|
|
1527
|
+
getInstanceCount() {
|
|
1528
|
+
return this.bridgeInstances.size;
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Checks if a bridge instance exists in the collection of managed bridges.
|
|
1532
|
+
*
|
|
1533
|
+
* This function verifies whether a bridge instance with the specified ID
|
|
1534
|
+
* is currently being managed by the Bridges class.
|
|
1535
|
+
*
|
|
1536
|
+
* @param bridgeId - The unique identifier of the bridge instance to check.
|
|
1537
|
+
* This should be a string that uniquely identifies the bridge in the system.
|
|
1538
|
+
*
|
|
1539
|
+
* @returns A boolean value indicating whether the bridge instance exists.
|
|
1540
|
+
* Returns true if the bridge instance is found, false otherwise.
|
|
1541
|
+
*/
|
|
1542
|
+
hasInstance(bridgeId) {
|
|
1543
|
+
return this.bridgeInstances.has(bridgeId);
|
|
1544
|
+
}
|
|
1545
|
+
/**
|
|
1546
|
+
* Retrieves all active bridge instances currently managed by the Bridges class.
|
|
1547
|
+
*
|
|
1548
|
+
* This method provides a way to access all the BridgeInstance objects that are
|
|
1549
|
+
* currently active and being managed. It returns a new Map to prevent direct
|
|
1550
|
+
* modification of the internal bridgeInstances collection.
|
|
1551
|
+
*
|
|
1552
|
+
* @returns A new Map object containing all active bridge instances, where the keys
|
|
1553
|
+
* are the bridge IDs (strings) and the values are the corresponding
|
|
1554
|
+
* BridgeInstance objects. If no bridges are active, an empty Map is returned.
|
|
1555
|
+
*/
|
|
1556
|
+
getAllInstances() {
|
|
1557
|
+
return new Map(this.bridgeInstances);
|
|
1000
1558
|
}
|
|
1001
1559
|
};
|
|
1002
1560
|
|
|
1003
1561
|
// src/ari-client/resources/channels.ts
|
|
1004
|
-
import { EventEmitter } from "events";
|
|
1005
|
-
import { isAxiosError as
|
|
1562
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
1563
|
+
import { isAxiosError as isAxiosError3 } from "axios";
|
|
1006
1564
|
|
|
1007
1565
|
// node_modules/uuid/dist/esm/stringify.js
|
|
1008
1566
|
var byteToHex = [];
|
|
@@ -1049,16 +1607,9 @@ function v4(options, buf, offset) {
|
|
|
1049
1607
|
}
|
|
1050
1608
|
var v4_default = v4;
|
|
1051
1609
|
|
|
1052
|
-
// src/ari-client/utils.ts
|
|
1053
|
-
function toQueryParams2(options) {
|
|
1054
|
-
return new URLSearchParams(
|
|
1055
|
-
Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
|
|
1056
|
-
).toString();
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
1610
|
// src/ari-client/resources/channels.ts
|
|
1060
|
-
var
|
|
1061
|
-
if (
|
|
1611
|
+
var getErrorMessage2 = (error) => {
|
|
1612
|
+
if (isAxiosError3(error)) {
|
|
1062
1613
|
return error.response?.data?.message || error.message || "An axios error occurred";
|
|
1063
1614
|
}
|
|
1064
1615
|
if (error instanceof Error) {
|
|
@@ -1072,7 +1623,7 @@ var ChannelInstance = class {
|
|
|
1072
1623
|
this.baseClient = baseClient;
|
|
1073
1624
|
this.id = channelId || `channel-${Date.now()}`;
|
|
1074
1625
|
}
|
|
1075
|
-
eventEmitter = new
|
|
1626
|
+
eventEmitter = new EventEmitter2();
|
|
1076
1627
|
channelData = null;
|
|
1077
1628
|
id;
|
|
1078
1629
|
/**
|
|
@@ -1150,7 +1701,7 @@ var ChannelInstance = class {
|
|
|
1150
1701
|
try {
|
|
1151
1702
|
await this.baseClient.post(`/channels/${this.id}/answer`);
|
|
1152
1703
|
} catch (error) {
|
|
1153
|
-
const message =
|
|
1704
|
+
const message = getErrorMessage2(error);
|
|
1154
1705
|
console.error(`Error answering channel ${this.id}:`, message);
|
|
1155
1706
|
throw new Error(`Failed to answer channel: ${message}`);
|
|
1156
1707
|
}
|
|
@@ -1173,7 +1724,7 @@ var ChannelInstance = class {
|
|
|
1173
1724
|
);
|
|
1174
1725
|
return this.channelData;
|
|
1175
1726
|
} catch (error) {
|
|
1176
|
-
const message =
|
|
1727
|
+
const message = getErrorMessage2(error);
|
|
1177
1728
|
console.error(`Error originating channel:`, message);
|
|
1178
1729
|
throw new Error(`Failed to originate channel: ${message}`);
|
|
1179
1730
|
}
|
|
@@ -1196,7 +1747,7 @@ var ChannelInstance = class {
|
|
|
1196
1747
|
);
|
|
1197
1748
|
return playback;
|
|
1198
1749
|
} catch (error) {
|
|
1199
|
-
const message =
|
|
1750
|
+
const message = getErrorMessage2(error);
|
|
1200
1751
|
console.error(`Error playing media on channel ${this.id}:`, message);
|
|
1201
1752
|
throw new Error(`Failed to play media: ${message}`);
|
|
1202
1753
|
}
|
|
@@ -1218,7 +1769,7 @@ var ChannelInstance = class {
|
|
|
1218
1769
|
this.channelData = details;
|
|
1219
1770
|
return details;
|
|
1220
1771
|
} catch (error) {
|
|
1221
|
-
const message =
|
|
1772
|
+
const message = getErrorMessage2(error);
|
|
1222
1773
|
console.error(
|
|
1223
1774
|
`Error retrieving channel details for ${this.id}:`,
|
|
1224
1775
|
message
|
|
@@ -1459,7 +2010,7 @@ var Channels = class {
|
|
|
1459
2010
|
}
|
|
1460
2011
|
return this.channelInstances.get(id);
|
|
1461
2012
|
} catch (error) {
|
|
1462
|
-
const message =
|
|
2013
|
+
const message = getErrorMessage2(error);
|
|
1463
2014
|
console.error(`Error creating/retrieving channel instance:`, message);
|
|
1464
2015
|
throw new Error(`Failed to manage channel instance: ${message}`);
|
|
1465
2016
|
}
|
|
@@ -1478,7 +2029,7 @@ var Channels = class {
|
|
|
1478
2029
|
}
|
|
1479
2030
|
return await this.baseClient.get(`/channels/${id}`);
|
|
1480
2031
|
} catch (error) {
|
|
1481
|
-
const message =
|
|
2032
|
+
const message = getErrorMessage2(error);
|
|
1482
2033
|
console.error(`Error retrieving channel details for ${id}:`, message);
|
|
1483
2034
|
throw new Error(`Failed to get channel details: ${message}`);
|
|
1484
2035
|
}
|
|
@@ -1525,7 +2076,7 @@ var Channels = class {
|
|
|
1525
2076
|
try {
|
|
1526
2077
|
return await this.baseClient.post("/channels", data);
|
|
1527
2078
|
} catch (error) {
|
|
1528
|
-
const message =
|
|
2079
|
+
const message = getErrorMessage2(error);
|
|
1529
2080
|
console.error(`Error originating channel:`, message);
|
|
1530
2081
|
throw new Error(`Failed to originate channel: ${message}`);
|
|
1531
2082
|
}
|
|
@@ -1541,7 +2092,7 @@ var Channels = class {
|
|
|
1541
2092
|
}
|
|
1542
2093
|
return channels;
|
|
1543
2094
|
} catch (error) {
|
|
1544
|
-
const message =
|
|
2095
|
+
const message = getErrorMessage2(error);
|
|
1545
2096
|
console.error(`Error listing channels:`, message);
|
|
1546
2097
|
throw new Error(`Failed to list channels: ${message}`);
|
|
1547
2098
|
}
|
|
@@ -1968,10 +2519,10 @@ var Endpoints = class {
|
|
|
1968
2519
|
};
|
|
1969
2520
|
|
|
1970
2521
|
// src/ari-client/resources/playbacks.ts
|
|
1971
|
-
import { EventEmitter as
|
|
1972
|
-
import { isAxiosError as
|
|
1973
|
-
var
|
|
1974
|
-
if (
|
|
2522
|
+
import { EventEmitter as EventEmitter3 } from "events";
|
|
2523
|
+
import { isAxiosError as isAxiosError4 } from "axios";
|
|
2524
|
+
var getErrorMessage3 = (error) => {
|
|
2525
|
+
if (isAxiosError4(error)) {
|
|
1975
2526
|
return error.response?.data?.message || error.message || "An axios error occurred";
|
|
1976
2527
|
}
|
|
1977
2528
|
if (error instanceof Error) {
|
|
@@ -1993,7 +2544,7 @@ var PlaybackInstance = class {
|
|
|
1993
2544
|
this.playbackId = playbackId;
|
|
1994
2545
|
this.id = playbackId;
|
|
1995
2546
|
}
|
|
1996
|
-
eventEmitter = new
|
|
2547
|
+
eventEmitter = new EventEmitter3();
|
|
1997
2548
|
playbackData = null;
|
|
1998
2549
|
id;
|
|
1999
2550
|
/**
|
|
@@ -2076,7 +2627,7 @@ var PlaybackInstance = class {
|
|
|
2076
2627
|
);
|
|
2077
2628
|
return this.playbackData;
|
|
2078
2629
|
} catch (error) {
|
|
2079
|
-
const message =
|
|
2630
|
+
const message = getErrorMessage3(error);
|
|
2080
2631
|
console.warn(`Error retrieving playback data for ${this.id}:`, message);
|
|
2081
2632
|
throw new Error(`Failed to get playback data: ${message}`);
|
|
2082
2633
|
}
|
|
@@ -2096,7 +2647,7 @@ var PlaybackInstance = class {
|
|
|
2096
2647
|
`/playbacks/${this.id}/control?operation=${operation}`
|
|
2097
2648
|
);
|
|
2098
2649
|
} catch (error) {
|
|
2099
|
-
const message =
|
|
2650
|
+
const message = getErrorMessage3(error);
|
|
2100
2651
|
console.warn(`Error controlling playback ${this.id}:`, message);
|
|
2101
2652
|
throw new Error(`Failed to control playback: ${message}`);
|
|
2102
2653
|
}
|
|
@@ -2113,7 +2664,7 @@ var PlaybackInstance = class {
|
|
|
2113
2664
|
try {
|
|
2114
2665
|
await this.baseClient.delete(`/playbacks/${this.id}`);
|
|
2115
2666
|
} catch (error) {
|
|
2116
|
-
const message =
|
|
2667
|
+
const message = getErrorMessage3(error);
|
|
2117
2668
|
console.warn(`Error stopping playback ${this.id}:`, message);
|
|
2118
2669
|
throw new Error(`Failed to stop playback: ${message}`);
|
|
2119
2670
|
}
|
|
@@ -2169,7 +2720,7 @@ var Playbacks = class {
|
|
|
2169
2720
|
}
|
|
2170
2721
|
return this.playbackInstances.get(id);
|
|
2171
2722
|
} catch (error) {
|
|
2172
|
-
const message =
|
|
2723
|
+
const message = getErrorMessage3(error);
|
|
2173
2724
|
console.warn(`Error creating/retrieving playback instance:`, message);
|
|
2174
2725
|
throw new Error(`Failed to manage playback instance: ${message}`);
|
|
2175
2726
|
}
|
|
@@ -2221,7 +2772,7 @@ var Playbacks = class {
|
|
|
2221
2772
|
try {
|
|
2222
2773
|
return await this.baseClient.get(`/playbacks/${playbackId}`);
|
|
2223
2774
|
} catch (error) {
|
|
2224
|
-
const message =
|
|
2775
|
+
const message = getErrorMessage3(error);
|
|
2225
2776
|
console.warn(`Error getting playback details ${playbackId}:`, message);
|
|
2226
2777
|
throw new Error(`Failed to get playback details: ${message}`);
|
|
2227
2778
|
}
|
|
@@ -2240,7 +2791,7 @@ var Playbacks = class {
|
|
|
2240
2791
|
const playback = this.Playback({ id: playbackId });
|
|
2241
2792
|
await playback.control(operation);
|
|
2242
2793
|
} catch (error) {
|
|
2243
|
-
const message =
|
|
2794
|
+
const message = getErrorMessage3(error);
|
|
2244
2795
|
console.warn(`Error controlling playback ${playbackId}:`, message);
|
|
2245
2796
|
throw new Error(`Failed to control playback: ${message}`);
|
|
2246
2797
|
}
|
|
@@ -2258,7 +2809,7 @@ var Playbacks = class {
|
|
|
2258
2809
|
const playback = this.Playback({ id: playbackId });
|
|
2259
2810
|
await playback.stop();
|
|
2260
2811
|
} catch (error) {
|
|
2261
|
-
const message =
|
|
2812
|
+
const message = getErrorMessage3(error);
|
|
2262
2813
|
console.warn(`Error stopping playback ${playbackId}:`, message);
|
|
2263
2814
|
throw new Error(`Failed to stop playback: ${message}`);
|
|
2264
2815
|
}
|
|
@@ -2313,12 +2864,12 @@ var Sounds = class {
|
|
|
2313
2864
|
|
|
2314
2865
|
// src/ari-client/websocketClient.ts
|
|
2315
2866
|
var import_exponential_backoff = __toESM(require_backoff(), 1);
|
|
2316
|
-
import { EventEmitter as
|
|
2867
|
+
import { EventEmitter as EventEmitter4 } from "events";
|
|
2317
2868
|
import WebSocket from "ws";
|
|
2318
2869
|
var DEFAULT_MAX_RECONNECT_ATTEMPTS = 30;
|
|
2319
2870
|
var DEFAULT_STARTING_DELAY = 500;
|
|
2320
2871
|
var DEFAULT_MAX_DELAY = 1e4;
|
|
2321
|
-
var WebSocketClient = class extends
|
|
2872
|
+
var WebSocketClient = class extends EventEmitter4 {
|
|
2322
2873
|
/**
|
|
2323
2874
|
* Creates a new WebSocketClient instance.
|
|
2324
2875
|
*
|
|
@@ -2472,6 +3023,11 @@ var WebSocketClient = class extends EventEmitter3 {
|
|
|
2472
3023
|
instancePlayback.emitEvent(event);
|
|
2473
3024
|
event.instancePlayback = instancePlayback;
|
|
2474
3025
|
}
|
|
3026
|
+
if ("bridge" in event && event.bridge?.id && this.ariClient) {
|
|
3027
|
+
const instanceBridge = this.ariClient.Bridge(event.bridge.id);
|
|
3028
|
+
instanceBridge.emitEvent(event);
|
|
3029
|
+
event.instanceBridge = instanceBridge;
|
|
3030
|
+
}
|
|
2475
3031
|
this.emit(event.type, event);
|
|
2476
3032
|
} catch (error) {
|
|
2477
3033
|
console.error(
|
|
@@ -2582,11 +3138,11 @@ var AriClient = class {
|
|
|
2582
3138
|
this.baseClient = new BaseClient(baseUrl, config.username, config.password);
|
|
2583
3139
|
this.channels = new Channels(this.baseClient, this);
|
|
2584
3140
|
this.playbacks = new Playbacks(this.baseClient, this);
|
|
3141
|
+
this.bridges = new Bridges(this.baseClient, this);
|
|
2585
3142
|
this.endpoints = new Endpoints(this.baseClient);
|
|
2586
3143
|
this.applications = new Applications(this.baseClient);
|
|
2587
3144
|
this.sounds = new Sounds(this.baseClient);
|
|
2588
3145
|
this.asterisk = new Asterisk(this.baseClient);
|
|
2589
|
-
this.bridges = new Bridges(this.baseClient);
|
|
2590
3146
|
console.log(`ARI Client initialized with base URL: ${baseUrl}`);
|
|
2591
3147
|
}
|
|
2592
3148
|
baseClient;
|
|
@@ -2702,6 +3258,20 @@ var AriClient = class {
|
|
|
2702
3258
|
Playback(playbackId, _app) {
|
|
2703
3259
|
return this.playbacks.Playback({ id: playbackId });
|
|
2704
3260
|
}
|
|
3261
|
+
/**
|
|
3262
|
+
* Creates or retrieves a Bridge instance.
|
|
3263
|
+
*
|
|
3264
|
+
* This function allows you to create a new Bridge instance or retrieve an existing one
|
|
3265
|
+
* based on the provided bridge ID.
|
|
3266
|
+
*
|
|
3267
|
+
* @param {string} [bridgeId] - Optional ID of an existing bridge. If provided, retrieves the
|
|
3268
|
+
* existing bridge with this ID. If omitted, creates a new bridge.
|
|
3269
|
+
* @returns {BridgeInstance} A new or existing Bridge instance that can be used to interact
|
|
3270
|
+
* with the Asterisk bridge.
|
|
3271
|
+
*/
|
|
3272
|
+
Bridge(bridgeId) {
|
|
3273
|
+
return this.bridges.Bridge({ id: bridgeId });
|
|
3274
|
+
}
|
|
2705
3275
|
/**
|
|
2706
3276
|
* Gets the current WebSocket connection status.
|
|
2707
3277
|
*
|
|
@@ -2715,6 +3285,7 @@ export {
|
|
|
2715
3285
|
Applications,
|
|
2716
3286
|
AriClient,
|
|
2717
3287
|
Asterisk,
|
|
3288
|
+
BridgeInstance,
|
|
2718
3289
|
Bridges,
|
|
2719
3290
|
ChannelInstance,
|
|
2720
3291
|
Channels,
|