@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/esm/index.js
CHANGED
|
@@ -1182,42 +1182,45 @@ var ChannelInstance = class {
|
|
|
1182
1182
|
* Plays media on the channel
|
|
1183
1183
|
*/
|
|
1184
1184
|
async play(options, playbackId) {
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
const playback = this.client.Playback(playbackId || v4_default());
|
|
1200
|
-
return new Promise((resolve, reject) => {
|
|
1201
|
-
playback.once("PlaybackFinished", (event) => {
|
|
1202
|
-
console.log("Playback finished: ", event);
|
|
1185
|
+
return new Promise(async (resolve, reject) => {
|
|
1186
|
+
try {
|
|
1187
|
+
if (!options.media) {
|
|
1188
|
+
throw new Error("Media URL is required");
|
|
1189
|
+
}
|
|
1190
|
+
if (!this.channelData) {
|
|
1191
|
+
this.channelData = await this.getDetails();
|
|
1192
|
+
}
|
|
1193
|
+
const playback = this.client.Playback(playbackId || v4_default());
|
|
1194
|
+
playback.once("PlaybackStarted", (event) => {
|
|
1195
|
+
if ("playback" in event) {
|
|
1196
|
+
console.log("Playback realmente iniciado:", playback.id);
|
|
1197
|
+
resolve(playback);
|
|
1198
|
+
}
|
|
1203
1199
|
});
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1200
|
+
playback.once("PlaybackFinished", async (event) => {
|
|
1201
|
+
if ("playback" in event && event.playback) {
|
|
1202
|
+
const playbackState = event.playback.state;
|
|
1203
|
+
if (playbackState === "failed") {
|
|
1204
|
+
console.error("Playback falhou:", {
|
|
1205
|
+
playbackId: playback.id,
|
|
1206
|
+
channelId: this.id,
|
|
1207
|
+
state: playbackState
|
|
1208
|
+
});
|
|
1209
|
+
reject(new Error(`Playback failed: ${playbackState}`));
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1210
1212
|
});
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
})
|
|
1219
|
-
|
|
1220
|
-
|
|
1213
|
+
await this.baseClient.post(
|
|
1214
|
+
`/channels/${this.id}/play/${playback.id}`,
|
|
1215
|
+
options
|
|
1216
|
+
);
|
|
1217
|
+
setTimeout(() => {
|
|
1218
|
+
reject(new Error("Playback timeout - n\xE3o recebeu evento de in\xEDcio"));
|
|
1219
|
+
}, 5e3);
|
|
1220
|
+
} catch (error) {
|
|
1221
|
+
reject(error);
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1221
1224
|
}
|
|
1222
1225
|
/**
|
|
1223
1226
|
* Gets the current channel details
|