@ipcom/asterisk-ari 0.0.142 → 0.0.144
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 +19 -77
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +19 -77
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/baseClient.d.ts.map +1 -1
- package/dist/types/ari-client/resources/channels.d.ts.map +1 -1
- package/dist/types/ari-client/resources/playbacks.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -618,7 +618,9 @@ var BaseClient = class {
|
|
|
618
618
|
this.username = username;
|
|
619
619
|
this.password = password;
|
|
620
620
|
if (!/^https?:\/\/.+/.test(baseUrl)) {
|
|
621
|
-
throw new Error(
|
|
621
|
+
throw new Error(
|
|
622
|
+
"Invalid base URL. It must start with http:// or https://"
|
|
623
|
+
);
|
|
622
624
|
}
|
|
623
625
|
this.client = import_axios.default.create({
|
|
624
626
|
baseURL: baseUrl,
|
|
@@ -629,7 +631,6 @@ var BaseClient = class {
|
|
|
629
631
|
}
|
|
630
632
|
});
|
|
631
633
|
this.addInterceptors();
|
|
632
|
-
console.log(`BaseClient initialized for ${baseUrl}`);
|
|
633
634
|
}
|
|
634
635
|
client;
|
|
635
636
|
/**
|
|
@@ -654,7 +655,6 @@ var BaseClient = class {
|
|
|
654
655
|
addInterceptors() {
|
|
655
656
|
this.client.interceptors.request.use(
|
|
656
657
|
(config) => {
|
|
657
|
-
console.log(`[Request] ${config.method?.toUpperCase()} ${config.url}`);
|
|
658
658
|
return config;
|
|
659
659
|
},
|
|
660
660
|
(error) => {
|
|
@@ -665,7 +665,6 @@ var BaseClient = class {
|
|
|
665
665
|
);
|
|
666
666
|
this.client.interceptors.response.use(
|
|
667
667
|
(response) => {
|
|
668
|
-
console.log(`[Response] ${response.status} ${response.config.url}`);
|
|
669
668
|
return response;
|
|
670
669
|
},
|
|
671
670
|
(error) => {
|
|
@@ -788,7 +787,6 @@ var BaseClient = class {
|
|
|
788
787
|
...this.client.defaults.headers.common,
|
|
789
788
|
...headers
|
|
790
789
|
};
|
|
791
|
-
console.log("Updated client headers");
|
|
792
790
|
}
|
|
793
791
|
/**
|
|
794
792
|
* Gets the current request timeout setting.
|
|
@@ -801,7 +799,6 @@ var BaseClient = class {
|
|
|
801
799
|
*/
|
|
802
800
|
setTimeout(timeout) {
|
|
803
801
|
this.client.defaults.timeout = timeout;
|
|
804
|
-
console.log(`Updated timeout to ${timeout}ms`);
|
|
805
802
|
}
|
|
806
803
|
};
|
|
807
804
|
|
|
@@ -1094,7 +1091,6 @@ var ChannelInstance = class {
|
|
|
1094
1091
|
this.client = client;
|
|
1095
1092
|
this.baseClient = baseClient;
|
|
1096
1093
|
this.id = channelId || `channel-${Date.now()}`;
|
|
1097
|
-
console.log(`Channel instance initialized with ID: ${this.id}`);
|
|
1098
1094
|
}
|
|
1099
1095
|
eventEmitter = new import_events.EventEmitter();
|
|
1100
1096
|
channelData = null;
|
|
@@ -1112,7 +1108,6 @@ var ChannelInstance = class {
|
|
|
1112
1108
|
}
|
|
1113
1109
|
};
|
|
1114
1110
|
this.eventEmitter.on(event, wrappedListener);
|
|
1115
|
-
console.log(`Event listener registered for ${event} on channel ${this.id}`);
|
|
1116
1111
|
}
|
|
1117
1112
|
/**
|
|
1118
1113
|
* Registers a one-time event listener
|
|
@@ -1127,9 +1122,6 @@ var ChannelInstance = class {
|
|
|
1127
1122
|
}
|
|
1128
1123
|
};
|
|
1129
1124
|
this.eventEmitter.once(event, wrappedListener);
|
|
1130
|
-
console.log(
|
|
1131
|
-
`One-time event listener registered for ${event} on channel ${this.id}`
|
|
1132
|
-
);
|
|
1133
1125
|
}
|
|
1134
1126
|
/**
|
|
1135
1127
|
* Removes event listener(s) for a specific WebSocket event type.
|
|
@@ -1146,12 +1138,8 @@ var ChannelInstance = class {
|
|
|
1146
1138
|
}
|
|
1147
1139
|
if (listener) {
|
|
1148
1140
|
this.eventEmitter.off(event, listener);
|
|
1149
|
-
console.log(
|
|
1150
|
-
`Specific listener removed for ${event} on channel ${this.id}`
|
|
1151
|
-
);
|
|
1152
1141
|
} else {
|
|
1153
1142
|
this.eventEmitter.removeAllListeners(event);
|
|
1154
|
-
console.log(`All listeners removed for ${event} on channel ${this.id}`);
|
|
1155
1143
|
}
|
|
1156
1144
|
}
|
|
1157
1145
|
/**
|
|
@@ -1164,7 +1152,6 @@ var ChannelInstance = class {
|
|
|
1164
1152
|
}
|
|
1165
1153
|
if ("channel" in event && event.channel?.id === this.id) {
|
|
1166
1154
|
this.eventEmitter.emit(event.type, event);
|
|
1167
|
-
console.log(`Event ${event.type} emitted for channel ${this.id}`);
|
|
1168
1155
|
}
|
|
1169
1156
|
}
|
|
1170
1157
|
/**
|
|
@@ -1174,7 +1161,6 @@ var ChannelInstance = class {
|
|
|
1174
1161
|
* @return {void} This method does not return a value.
|
|
1175
1162
|
*/
|
|
1176
1163
|
removeAllListeners() {
|
|
1177
|
-
console.log(`Removendo todos os listeners para o canal ${this.id}`);
|
|
1178
1164
|
this.eventEmitter.removeAllListeners();
|
|
1179
1165
|
}
|
|
1180
1166
|
/**
|
|
@@ -1183,7 +1169,6 @@ var ChannelInstance = class {
|
|
|
1183
1169
|
async answer() {
|
|
1184
1170
|
try {
|
|
1185
1171
|
await this.baseClient.post(`/channels/${this.id}/answer`);
|
|
1186
|
-
console.log(`Channel ${this.id} answered`);
|
|
1187
1172
|
} catch (error) {
|
|
1188
1173
|
const message = getErrorMessage(error);
|
|
1189
1174
|
console.error(`Error answering channel ${this.id}:`, message);
|
|
@@ -1206,9 +1191,6 @@ var ChannelInstance = class {
|
|
|
1206
1191
|
"/channels",
|
|
1207
1192
|
data
|
|
1208
1193
|
);
|
|
1209
|
-
console.log(
|
|
1210
|
-
`Channel originated successfully with ID: ${this.channelData.id}`
|
|
1211
|
-
);
|
|
1212
1194
|
return this.channelData;
|
|
1213
1195
|
} catch (error) {
|
|
1214
1196
|
const message = getErrorMessage(error);
|
|
@@ -1225,7 +1207,6 @@ var ChannelInstance = class {
|
|
|
1225
1207
|
}
|
|
1226
1208
|
try {
|
|
1227
1209
|
if (!this.channelData) {
|
|
1228
|
-
console.log("Initializing channel details...");
|
|
1229
1210
|
this.channelData = await this.getDetails();
|
|
1230
1211
|
}
|
|
1231
1212
|
const playback = this.client.Playback(playbackId || v4_default());
|
|
@@ -1233,7 +1214,6 @@ var ChannelInstance = class {
|
|
|
1233
1214
|
`/channels/${this.id}/play/${playback.id}`,
|
|
1234
1215
|
options
|
|
1235
1216
|
);
|
|
1236
|
-
console.log(`Media playback started on channel ${this.id}`);
|
|
1237
1217
|
return playback;
|
|
1238
1218
|
} catch (error) {
|
|
1239
1219
|
const message = getErrorMessage(error);
|
|
@@ -1256,7 +1236,6 @@ var ChannelInstance = class {
|
|
|
1256
1236
|
`/channels/${this.id}`
|
|
1257
1237
|
);
|
|
1258
1238
|
this.channelData = details;
|
|
1259
|
-
console.log(`Retrieved channel details for ${this.id}`);
|
|
1260
1239
|
return details;
|
|
1261
1240
|
} catch (error) {
|
|
1262
1241
|
const message = getErrorMessage(error);
|
|
@@ -1303,7 +1282,6 @@ var ChannelInstance = class {
|
|
|
1303
1282
|
*/
|
|
1304
1283
|
async hangup() {
|
|
1305
1284
|
if (!this.channelData) {
|
|
1306
|
-
console.log("Canal n\xE3o inicializado, buscando detalhes...");
|
|
1307
1285
|
this.channelData = await this.getDetails();
|
|
1308
1286
|
}
|
|
1309
1287
|
if (!this.channelData?.id) {
|
|
@@ -1492,16 +1470,13 @@ var Channels = class {
|
|
|
1492
1470
|
if (!id) {
|
|
1493
1471
|
const instance = new ChannelInstance(this.client, this.baseClient);
|
|
1494
1472
|
this.channelInstances.set(instance.id, instance);
|
|
1495
|
-
console.log(`New channel instance created with ID: ${instance.id}`);
|
|
1496
1473
|
return instance;
|
|
1497
1474
|
}
|
|
1498
1475
|
if (!this.channelInstances.has(id)) {
|
|
1499
1476
|
const instance = new ChannelInstance(this.client, this.baseClient, id);
|
|
1500
1477
|
this.channelInstances.set(id, instance);
|
|
1501
|
-
console.log(`New channel instance created with provided ID: ${id}`);
|
|
1502
1478
|
return instance;
|
|
1503
1479
|
}
|
|
1504
|
-
console.log(`Returning existing channel instance: ${id}`);
|
|
1505
1480
|
return this.channelInstances.get(id);
|
|
1506
1481
|
} catch (error) {
|
|
1507
1482
|
const message = getErrorMessage(error);
|
|
@@ -1518,12 +1493,10 @@ var Channels = class {
|
|
|
1518
1493
|
*/
|
|
1519
1494
|
async get(id) {
|
|
1520
1495
|
try {
|
|
1521
|
-
if (id) {
|
|
1496
|
+
if (!id) {
|
|
1522
1497
|
throw new Error("No channel ID associated with this instance");
|
|
1523
1498
|
}
|
|
1524
|
-
|
|
1525
|
-
console.log(`Retrieved channel details for ${id}`);
|
|
1526
|
-
return details;
|
|
1499
|
+
return await this.baseClient.get(`/channels/${id}`);
|
|
1527
1500
|
} catch (error) {
|
|
1528
1501
|
const message = getErrorMessage(error);
|
|
1529
1502
|
console.error(`Error retrieving channel details for ${id}:`, message);
|
|
@@ -1541,7 +1514,6 @@ var Channels = class {
|
|
|
1541
1514
|
const instance = this.channelInstances.get(channelId);
|
|
1542
1515
|
instance?.removeAllListeners();
|
|
1543
1516
|
this.channelInstances.delete(channelId);
|
|
1544
|
-
console.log(`Channel instance removed: ${channelId}`);
|
|
1545
1517
|
} else {
|
|
1546
1518
|
console.warn(`Attempt to remove non-existent instance: ${channelId}`);
|
|
1547
1519
|
}
|
|
@@ -1558,9 +1530,6 @@ var Channels = class {
|
|
|
1558
1530
|
const instance = this.channelInstances.get(event.channel.id);
|
|
1559
1531
|
if (instance) {
|
|
1560
1532
|
instance.emitEvent(event);
|
|
1561
|
-
console.log(
|
|
1562
|
-
`Event propagated to channel ${event.channel.id}: ${event.type}`
|
|
1563
|
-
);
|
|
1564
1533
|
} else {
|
|
1565
1534
|
console.warn(`No instance found for channel ${event.channel.id}`);
|
|
1566
1535
|
}
|
|
@@ -1574,9 +1543,7 @@ var Channels = class {
|
|
|
1574
1543
|
throw new Error("Endpoint is required for channel origination");
|
|
1575
1544
|
}
|
|
1576
1545
|
try {
|
|
1577
|
-
|
|
1578
|
-
console.log(`Channel originated successfully with ID: ${channel.id}`);
|
|
1579
|
-
return channel;
|
|
1546
|
+
return await this.baseClient.post("/channels", data);
|
|
1580
1547
|
} catch (error) {
|
|
1581
1548
|
const message = getErrorMessage(error);
|
|
1582
1549
|
console.error(`Error originating channel:`, message);
|
|
@@ -1592,7 +1559,6 @@ var Channels = class {
|
|
|
1592
1559
|
if (!Array.isArray(channels)) {
|
|
1593
1560
|
throw new Error("API response for /channels is not an array");
|
|
1594
1561
|
}
|
|
1595
|
-
console.log(`Retrieved ${channels.length} active channels`);
|
|
1596
1562
|
return channels;
|
|
1597
1563
|
} catch (error) {
|
|
1598
1564
|
const message = getErrorMessage(error);
|
|
@@ -2046,7 +2012,6 @@ var PlaybackInstance = class {
|
|
|
2046
2012
|
this.baseClient = baseClient;
|
|
2047
2013
|
this.playbackId = playbackId;
|
|
2048
2014
|
this.id = playbackId;
|
|
2049
|
-
console.log(`PlaybackInstance initialized with ID: ${this.id}`);
|
|
2050
2015
|
}
|
|
2051
2016
|
eventEmitter = new import_events2.EventEmitter();
|
|
2052
2017
|
playbackData = null;
|
|
@@ -2067,9 +2032,6 @@ var PlaybackInstance = class {
|
|
|
2067
2032
|
}
|
|
2068
2033
|
};
|
|
2069
2034
|
this.eventEmitter.on(event, wrappedListener);
|
|
2070
|
-
console.log(
|
|
2071
|
-
`Event listener registered for ${event} on playback ${this.id}`
|
|
2072
|
-
);
|
|
2073
2035
|
}
|
|
2074
2036
|
/**
|
|
2075
2037
|
* Registers a one-time event listener for a specific WebSocket event type.
|
|
@@ -2087,9 +2049,6 @@ var PlaybackInstance = class {
|
|
|
2087
2049
|
}
|
|
2088
2050
|
};
|
|
2089
2051
|
this.eventEmitter.once(event, wrappedListener);
|
|
2090
|
-
console.log(
|
|
2091
|
-
`One-time event listener registered for ${event} on playback ${this.id}`
|
|
2092
|
-
);
|
|
2093
2052
|
}
|
|
2094
2053
|
/**
|
|
2095
2054
|
* Removes event listener(s) for a specific WebSocket event type.
|
|
@@ -2103,12 +2062,8 @@ var PlaybackInstance = class {
|
|
|
2103
2062
|
}
|
|
2104
2063
|
if (listener) {
|
|
2105
2064
|
this.eventEmitter.off(event, listener);
|
|
2106
|
-
console.log(
|
|
2107
|
-
`Specific listener removed for ${event} on playback ${this.id}`
|
|
2108
|
-
);
|
|
2109
2065
|
} else {
|
|
2110
2066
|
this.eventEmitter.removeAllListeners(event);
|
|
2111
|
-
console.log(`All listeners removed for ${event} on playback ${this.id}`);
|
|
2112
2067
|
}
|
|
2113
2068
|
}
|
|
2114
2069
|
/**
|
|
@@ -2123,7 +2078,6 @@ var PlaybackInstance = class {
|
|
|
2123
2078
|
}
|
|
2124
2079
|
if ("playback" in event && event.playback?.id === this.id) {
|
|
2125
2080
|
this.eventEmitter.emit(event.type, event);
|
|
2126
|
-
console.log(`Event ${event.type} emitted for playback ${this.id}`);
|
|
2127
2081
|
}
|
|
2128
2082
|
}
|
|
2129
2083
|
/**
|
|
@@ -2140,7 +2094,6 @@ var PlaybackInstance = class {
|
|
|
2140
2094
|
this.playbackData = await this.baseClient.get(
|
|
2141
2095
|
`/playbacks/${this.id}`
|
|
2142
2096
|
);
|
|
2143
|
-
console.log(`Retrieved playback data for ${this.id}`);
|
|
2144
2097
|
return this.playbackData;
|
|
2145
2098
|
} catch (error) {
|
|
2146
2099
|
const message = getErrorMessage2(error);
|
|
@@ -2162,9 +2115,6 @@ var PlaybackInstance = class {
|
|
|
2162
2115
|
await this.baseClient.post(
|
|
2163
2116
|
`/playbacks/${this.id}/control?operation=${operation}`
|
|
2164
2117
|
);
|
|
2165
|
-
console.log(
|
|
2166
|
-
`Operation ${operation} executed successfully on playback ${this.id}`
|
|
2167
|
-
);
|
|
2168
2118
|
} catch (error) {
|
|
2169
2119
|
const message = getErrorMessage2(error);
|
|
2170
2120
|
console.error(`Error controlling playback ${this.id}:`, message);
|
|
@@ -2182,7 +2132,6 @@ var PlaybackInstance = class {
|
|
|
2182
2132
|
}
|
|
2183
2133
|
try {
|
|
2184
2134
|
await this.baseClient.delete(`/playbacks/${this.id}`);
|
|
2185
|
-
console.log(`Playback ${this.id} stopped successfully`);
|
|
2186
2135
|
} catch (error) {
|
|
2187
2136
|
const message = getErrorMessage2(error);
|
|
2188
2137
|
console.error(`Error stopping playback ${this.id}:`, message);
|
|
@@ -2194,7 +2143,6 @@ var PlaybackInstance = class {
|
|
|
2194
2143
|
*/
|
|
2195
2144
|
removeAllListeners() {
|
|
2196
2145
|
this.eventEmitter.removeAllListeners();
|
|
2197
|
-
console.log(`All listeners removed from playback ${this.id}`);
|
|
2198
2146
|
}
|
|
2199
2147
|
/**
|
|
2200
2148
|
* Checks if the playback instance has any listeners for a specific event.
|
|
@@ -2232,16 +2180,13 @@ var Playbacks = class {
|
|
|
2232
2180
|
if (!id) {
|
|
2233
2181
|
const instance = new PlaybackInstance(this.client, this.baseClient);
|
|
2234
2182
|
this.playbackInstances.set(instance.id, instance);
|
|
2235
|
-
console.log(`New playback instance created with ID: ${instance.id}`);
|
|
2236
2183
|
return instance;
|
|
2237
2184
|
}
|
|
2238
2185
|
if (!this.playbackInstances.has(id)) {
|
|
2239
2186
|
const instance = new PlaybackInstance(this.client, this.baseClient, id);
|
|
2240
2187
|
this.playbackInstances.set(id, instance);
|
|
2241
|
-
console.log(`New playback instance created with provided ID: ${id}`);
|
|
2242
2188
|
return instance;
|
|
2243
2189
|
}
|
|
2244
|
-
console.log(`Returning existing playback instance: ${id}`);
|
|
2245
2190
|
return this.playbackInstances.get(id);
|
|
2246
2191
|
} catch (error) {
|
|
2247
2192
|
const message = getErrorMessage2(error);
|
|
@@ -2262,7 +2207,6 @@ var Playbacks = class {
|
|
|
2262
2207
|
const instance = this.playbackInstances.get(playbackId);
|
|
2263
2208
|
instance?.removeAllListeners();
|
|
2264
2209
|
this.playbackInstances.delete(playbackId);
|
|
2265
|
-
console.log(`Playback instance removed: ${playbackId}`);
|
|
2266
2210
|
} else {
|
|
2267
2211
|
console.warn(`Attempt to remove non-existent instance: ${playbackId}`);
|
|
2268
2212
|
}
|
|
@@ -2273,16 +2217,12 @@ var Playbacks = class {
|
|
|
2273
2217
|
*/
|
|
2274
2218
|
propagateEventToPlayback(event) {
|
|
2275
2219
|
if (!event) {
|
|
2276
|
-
console.warn("Invalid WebSocket event received");
|
|
2277
2220
|
return;
|
|
2278
2221
|
}
|
|
2279
2222
|
if ("playback" in event && event.playback?.id) {
|
|
2280
2223
|
const instance = this.playbackInstances.get(event.playback.id);
|
|
2281
2224
|
if (instance) {
|
|
2282
2225
|
instance.emitEvent(event);
|
|
2283
|
-
console.log(
|
|
2284
|
-
`Event propagated to playback ${event.playback.id}: ${event.type}`
|
|
2285
|
-
);
|
|
2286
2226
|
} else {
|
|
2287
2227
|
console.warn(`No instance found for playback ${event.playback.id}`);
|
|
2288
2228
|
}
|
|
@@ -2319,7 +2259,6 @@ var Playbacks = class {
|
|
|
2319
2259
|
try {
|
|
2320
2260
|
const playback = this.Playback({ id: playbackId });
|
|
2321
2261
|
await playback.control(operation);
|
|
2322
|
-
console.log(`Operation ${operation} executed on playback ${playbackId}`);
|
|
2323
2262
|
} catch (error) {
|
|
2324
2263
|
const message = getErrorMessage2(error);
|
|
2325
2264
|
console.error(`Error controlling playback ${playbackId}:`, message);
|
|
@@ -2338,7 +2277,6 @@ var Playbacks = class {
|
|
|
2338
2277
|
try {
|
|
2339
2278
|
const playback = this.Playback({ id: playbackId });
|
|
2340
2279
|
await playback.stop();
|
|
2341
|
-
console.log(`Playback ${playbackId} stopped`);
|
|
2342
2280
|
} catch (error) {
|
|
2343
2281
|
const message = getErrorMessage2(error);
|
|
2344
2282
|
console.error(`Error stopping playback ${playbackId}:`, message);
|
|
@@ -2521,9 +2459,11 @@ var WebSocketClient = class extends import_events3.EventEmitter {
|
|
|
2521
2459
|
event.instancePlayback = instancePlayback;
|
|
2522
2460
|
}
|
|
2523
2461
|
this.emit(event.type, event);
|
|
2524
|
-
console.log(`Event processed: ${event.type}`);
|
|
2525
2462
|
} catch (error) {
|
|
2526
|
-
console.error(
|
|
2463
|
+
console.error(
|
|
2464
|
+
"Error processing WebSocket message:",
|
|
2465
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
2466
|
+
);
|
|
2527
2467
|
this.emit("error", new Error("Failed to decode WebSocket message"));
|
|
2528
2468
|
}
|
|
2529
2469
|
}
|
|
@@ -2536,13 +2476,15 @@ var WebSocketClient = class extends import_events3.EventEmitter {
|
|
|
2536
2476
|
this.isReconnecting = true;
|
|
2537
2477
|
console.log("Initiating reconnection attempt...");
|
|
2538
2478
|
this.removeAllListeners();
|
|
2539
|
-
(0, import_exponential_backoff.backOff)(() => this.initializeWebSocket(wsUrl), this.backOffOptions).catch(
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2479
|
+
(0, import_exponential_backoff.backOff)(() => this.initializeWebSocket(wsUrl), this.backOffOptions).catch(
|
|
2480
|
+
(error) => {
|
|
2481
|
+
console.error(
|
|
2482
|
+
"Failed to reconnect after multiple attempts:",
|
|
2483
|
+
error instanceof Error ? error.message : "Unknown error"
|
|
2484
|
+
);
|
|
2485
|
+
this.emit("reconnectFailed", error);
|
|
2486
|
+
}
|
|
2487
|
+
);
|
|
2546
2488
|
}
|
|
2547
2489
|
/**
|
|
2548
2490
|
* Manually closes the WebSocket connection.
|