@ipcom/asterisk-ari 0.0.149 → 0.0.150
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
CHANGED
|
@@ -1202,42 +1202,45 @@ 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
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
const playback = this.client.Playback(playbackId || v4_default());
|
|
1220
|
-
return new Promise((resolve, reject) => {
|
|
1221
|
-
playback.once("PlaybackFinished", (event) => {
|
|
1222
|
-
console.log("Playback finished: ", event);
|
|
1205
|
+
return new Promise(async (resolve, reject) => {
|
|
1206
|
+
try {
|
|
1207
|
+
if (!options.media) {
|
|
1208
|
+
throw new Error("Media URL is required");
|
|
1209
|
+
}
|
|
1210
|
+
if (!this.channelData) {
|
|
1211
|
+
this.channelData = await this.getDetails();
|
|
1212
|
+
}
|
|
1213
|
+
const playback = this.client.Playback(playbackId || v4_default());
|
|
1214
|
+
playback.once("PlaybackStarted", (event) => {
|
|
1215
|
+
if ("playback" in event) {
|
|
1216
|
+
console.log("Playback realmente iniciado:", playback.id);
|
|
1217
|
+
resolve(playback);
|
|
1218
|
+
}
|
|
1223
1219
|
});
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1220
|
+
playback.once("PlaybackFinished", async (event) => {
|
|
1221
|
+
if ("playback" in event && event.playback) {
|
|
1222
|
+
const playbackState = event.playback.state;
|
|
1223
|
+
if (playbackState === "failed") {
|
|
1224
|
+
console.error("Playback falhou:", {
|
|
1225
|
+
playbackId: playback.id,
|
|
1226
|
+
channelId: this.id,
|
|
1227
|
+
state: playbackState
|
|
1228
|
+
});
|
|
1229
|
+
reject(new Error(`Playback failed: ${playbackState}`));
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1230
1232
|
});
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
})
|
|
1239
|
-
|
|
1240
|
-
|
|
1233
|
+
await this.baseClient.post(
|
|
1234
|
+
`/channels/${this.id}/play/${playback.id}`,
|
|
1235
|
+
options
|
|
1236
|
+
);
|
|
1237
|
+
setTimeout(() => {
|
|
1238
|
+
reject(new Error("Playback timeout - n\xE3o recebeu evento de in\xEDcio"));
|
|
1239
|
+
}, 5e3);
|
|
1240
|
+
} catch (error) {
|
|
1241
|
+
reject(error);
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1241
1244
|
}
|
|
1242
1245
|
/**
|
|
1243
1246
|
* Gets the current channel details
|