@ipcom/asterisk-ari 0.0.148 → 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,55 +1182,45 @@ var ChannelInstance = class {
|
|
|
1182
1182
|
* Plays media on the channel
|
|
1183
1183
|
*/
|
|
1184
1184
|
async play(options, playbackId) {
|
|
1185
|
-
|
|
1186
|
-
throw new Error("Media URL is required");
|
|
1187
|
-
}
|
|
1188
|
-
try {
|
|
1189
|
-
const mediaPath = options.media.replace("sound:", "");
|
|
1190
|
-
console.log("Formatted media path:", mediaPath);
|
|
1191
|
-
if (!this.channelData) {
|
|
1192
|
-
console.log("Fetching channel details...");
|
|
1193
|
-
this.channelData = await this.getDetails();
|
|
1194
|
-
}
|
|
1195
|
-
if (!this.channelData?.id) {
|
|
1196
|
-
throw new Error("Channel ID is not available");
|
|
1197
|
-
}
|
|
1198
|
-
console.log("Channel state:", this.channelData.state);
|
|
1199
|
-
const playback = this.client.Playback(playbackId || v4_default());
|
|
1200
|
-
const payload = {
|
|
1201
|
-
media: options.media,
|
|
1202
|
-
...options.lang && { lang: options.lang }
|
|
1203
|
-
};
|
|
1204
|
-
console.log("Sending playback request:", {
|
|
1205
|
-
channelId: this.id,
|
|
1206
|
-
playbackId: playback.id,
|
|
1207
|
-
payload
|
|
1208
|
-
});
|
|
1209
|
-
await this.baseClient.post(
|
|
1210
|
-
`/channels/${this.id}/play/${playback.id}`,
|
|
1211
|
-
payload
|
|
1212
|
-
);
|
|
1185
|
+
return new Promise(async (resolve, reject) => {
|
|
1213
1186
|
try {
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
console.warn("Playback not in playing state:", playbackStatus);
|
|
1187
|
+
if (!options.media) {
|
|
1188
|
+
throw new Error("Media URL is required");
|
|
1217
1189
|
}
|
|
1218
|
-
|
|
1219
|
-
|
|
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
|
+
}
|
|
1220
1199
|
});
|
|
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
|
+
}
|
|
1212
|
+
});
|
|
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);
|
|
1221
1220
|
} catch (error) {
|
|
1222
|
-
|
|
1221
|
+
reject(error);
|
|
1223
1222
|
}
|
|
1224
|
-
|
|
1225
|
-
} catch (error) {
|
|
1226
|
-
const message = getErrorMessage(error);
|
|
1227
|
-
console.error(`Error playing media on channel ${this.id}:`, {
|
|
1228
|
-
error: message,
|
|
1229
|
-
options,
|
|
1230
|
-
channelState: this.channelData?.state
|
|
1231
|
-
});
|
|
1232
|
-
throw new Error(`Failed to play media: ${message}`);
|
|
1233
|
-
}
|
|
1223
|
+
});
|
|
1234
1224
|
}
|
|
1235
1225
|
/**
|
|
1236
1226
|
* Gets the current channel details
|