@ipcom/asterisk-ari 0.0.147 → 0.0.148
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
|
@@ -1186,57 +1186,49 @@ var ChannelInstance = class {
|
|
|
1186
1186
|
throw new Error("Media URL is required");
|
|
1187
1187
|
}
|
|
1188
1188
|
try {
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
console.error("Failed to get channel details:", error);
|
|
1198
|
-
throw new Error("Could not initialize channel data");
|
|
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");
|
|
1199
1197
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
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:", {
|
|
1202
1205
|
channelId: this.id,
|
|
1203
|
-
playbackId:
|
|
1204
|
-
|
|
1206
|
+
playbackId: playback.id,
|
|
1207
|
+
payload
|
|
1205
1208
|
});
|
|
1209
|
+
await this.baseClient.post(
|
|
1210
|
+
`/channels/${this.id}/play/${playback.id}`,
|
|
1211
|
+
payload
|
|
1212
|
+
);
|
|
1206
1213
|
try {
|
|
1207
|
-
await
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
);
|
|
1211
|
-
console.log("Successfully initiated playback:", {
|
|
1212
|
-
channelId: this.id,
|
|
1213
|
-
playbackId: playbackInstance.id
|
|
1214
|
-
});
|
|
1215
|
-
const playbackStatus = await playbackInstance.get().catch((err) => {
|
|
1216
|
-
console.warn("Could not verify playback status:", err);
|
|
1217
|
-
return null;
|
|
1218
|
-
});
|
|
1219
|
-
if (!playbackStatus) {
|
|
1220
|
-
console.warn("Playback was created but status could not be verified");
|
|
1221
|
-
} else {
|
|
1222
|
-
console.log("Playback status:", playbackStatus);
|
|
1214
|
+
const playbackStatus = await playback.get();
|
|
1215
|
+
if (playbackStatus.state !== "playing") {
|
|
1216
|
+
console.warn("Playback not in playing state:", playbackStatus);
|
|
1223
1217
|
}
|
|
1224
|
-
|
|
1218
|
+
playback.once("PlaybackFinished", (event) => {
|
|
1219
|
+
console.log("Playback finished", event);
|
|
1220
|
+
});
|
|
1225
1221
|
} catch (error) {
|
|
1226
|
-
|
|
1227
|
-
console.error(
|
|
1228
|
-
`Failed to start playback on channel ${this.id}:`,
|
|
1229
|
-
message
|
|
1230
|
-
);
|
|
1231
|
-
try {
|
|
1232
|
-
await playbackInstance.stop().catch();
|
|
1233
|
-
} catch {
|
|
1234
|
-
}
|
|
1235
|
-
throw new Error(`Failed to start playback: ${message}`);
|
|
1222
|
+
console.warn("Could not verify playback status:", error);
|
|
1236
1223
|
}
|
|
1224
|
+
return playback;
|
|
1237
1225
|
} catch (error) {
|
|
1238
1226
|
const message = getErrorMessage(error);
|
|
1239
|
-
console.error(`Error playing media on channel ${this.id}:`,
|
|
1227
|
+
console.error(`Error playing media on channel ${this.id}:`, {
|
|
1228
|
+
error: message,
|
|
1229
|
+
options,
|
|
1230
|
+
channelState: this.channelData?.state
|
|
1231
|
+
});
|
|
1240
1232
|
throw new Error(`Failed to play media: ${message}`);
|
|
1241
1233
|
}
|
|
1242
1234
|
}
|