@ipcom/asterisk-ari 0.0.151 → 0.0.152
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 +17 -89
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +17 -89
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/resources/channels.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts +0 -23
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1202,73 +1202,24 @@ var ChannelInstance = class {
|
|
|
1202
1202
|
* Plays media on the channel
|
|
1203
1203
|
*/
|
|
1204
1204
|
async play(options, playbackId) {
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
this.channelData = await this.getDetails();
|
|
1212
|
-
}
|
|
1213
|
-
const playback = this.client.Playback(playbackId || v4_default());
|
|
1214
|
-
let playbackStarted = false;
|
|
1215
|
-
const failureListener = (event) => {
|
|
1216
|
-
if ("playback" in event && event.playback) {
|
|
1217
|
-
if (event.playback.state === "failed") {
|
|
1218
|
-
console.error("Playback falhou:", {
|
|
1219
|
-
playbackId: playback.id,
|
|
1220
|
-
channelId: this.id,
|
|
1221
|
-
state: event.playback.state
|
|
1222
|
-
});
|
|
1223
|
-
if (!playbackStarted) {
|
|
1224
|
-
reject(
|
|
1225
|
-
new Error(
|
|
1226
|
-
`Playback failed to start: ${event.playback.state}`
|
|
1227
|
-
)
|
|
1228
|
-
);
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
};
|
|
1233
|
-
const startListener = (event) => {
|
|
1234
|
-
if ("playback" in event && event.playback) {
|
|
1235
|
-
console.log("Playback come\xE7ou:", {
|
|
1236
|
-
playbackId: playback.id,
|
|
1237
|
-
channelId: this.id,
|
|
1238
|
-
state: event.playback.state
|
|
1239
|
-
});
|
|
1240
|
-
playbackStarted = true;
|
|
1241
|
-
setTimeout(async () => {
|
|
1242
|
-
try {
|
|
1243
|
-
const status = await playback.get();
|
|
1244
|
-
if (status.state === "playing") {
|
|
1245
|
-
resolve(playback);
|
|
1246
|
-
} else {
|
|
1247
|
-
reject(
|
|
1248
|
-
new Error(`Playback started but state is ${status.state}`)
|
|
1249
|
-
);
|
|
1250
|
-
}
|
|
1251
|
-
} catch (_err) {
|
|
1252
|
-
reject(new Error("Failed to verify playback status"));
|
|
1253
|
-
}
|
|
1254
|
-
}, 500);
|
|
1255
|
-
}
|
|
1256
|
-
};
|
|
1257
|
-
playback.once("PlaybackStarted", startListener);
|
|
1258
|
-
playback.once("PlaybackFinished", failureListener);
|
|
1259
|
-
await this.baseClient.post(
|
|
1260
|
-
`/channels/${this.id}/play/${playback.id}`,
|
|
1261
|
-
options
|
|
1262
|
-
);
|
|
1263
|
-
setTimeout(() => {
|
|
1264
|
-
if (!playbackStarted) {
|
|
1265
|
-
reject(new Error("Playback timeout - n\xE3o iniciou"));
|
|
1266
|
-
}
|
|
1267
|
-
}, 5e3);
|
|
1268
|
-
} catch (error) {
|
|
1269
|
-
reject(error);
|
|
1205
|
+
if (!options.media) {
|
|
1206
|
+
throw new Error("Media URL is required");
|
|
1207
|
+
}
|
|
1208
|
+
try {
|
|
1209
|
+
if (!this.channelData) {
|
|
1210
|
+
this.channelData = await this.getDetails();
|
|
1270
1211
|
}
|
|
1271
|
-
|
|
1212
|
+
const playback = this.client.Playback(playbackId || v4_default());
|
|
1213
|
+
await this.baseClient.post(
|
|
1214
|
+
`/channels/${this.id}/play/${playback.id}`,
|
|
1215
|
+
options
|
|
1216
|
+
);
|
|
1217
|
+
return playback;
|
|
1218
|
+
} catch (error) {
|
|
1219
|
+
const message = getErrorMessage(error);
|
|
1220
|
+
console.error(`Error playing media on channel ${this.id}:`, message);
|
|
1221
|
+
throw new Error(`Failed to play media: ${message}`);
|
|
1222
|
+
}
|
|
1272
1223
|
}
|
|
1273
1224
|
/**
|
|
1274
1225
|
* Gets the current channel details
|
|
@@ -2601,32 +2552,9 @@ var WebSocketClient = class extends import_events3.EventEmitter {
|
|
|
2601
2552
|
);
|
|
2602
2553
|
}
|
|
2603
2554
|
}
|
|
2604
|
-
/**
|
|
2605
|
-
* Checks if the WebSocket connection is currently open and active.
|
|
2606
|
-
*
|
|
2607
|
-
* This method examines the readyState of the WebSocket instance to determine
|
|
2608
|
-
* if the connection is established and ready for communication.
|
|
2609
|
-
*
|
|
2610
|
-
* @returns {boolean} True if the WebSocket connection is open and ready,
|
|
2611
|
-
* false otherwise.
|
|
2612
|
-
*/
|
|
2613
2555
|
isConnected() {
|
|
2614
2556
|
return this.ws?.readyState === import_ws.default.OPEN;
|
|
2615
2557
|
}
|
|
2616
|
-
/**
|
|
2617
|
-
* Retrieves the current state of the WebSocket connection.
|
|
2618
|
-
*
|
|
2619
|
-
* This method returns the readyState of the WebSocket instance, which
|
|
2620
|
-
* indicates the current state of the connection. If no WebSocket instance
|
|
2621
|
-
* exists, it returns the CLOSED state.
|
|
2622
|
-
*
|
|
2623
|
-
* @returns {number} The current state of the WebSocket connection.
|
|
2624
|
-
* Possible values are:
|
|
2625
|
-
* - WebSocket.CONNECTING (0): The connection is not yet open.
|
|
2626
|
-
* - WebSocket.OPEN (1): The connection is open and ready to communicate.
|
|
2627
|
-
* - WebSocket.CLOSING (2): The connection is in the process of closing.
|
|
2628
|
-
* - WebSocket.CLOSED (3): The connection is closed or couldn't be opened.
|
|
2629
|
-
*/
|
|
2630
2558
|
getState() {
|
|
2631
2559
|
return this.ws?.readyState ?? import_ws.default.CLOSED;
|
|
2632
2560
|
}
|