@ipcom/asterisk-ari 0.0.146 → 0.0.147

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.
@@ -1206,15 +1206,54 @@ var ChannelInstance = class {
1206
1206
  throw new Error("Media URL is required");
1207
1207
  }
1208
1208
  try {
1209
- if (!this.channelData) {
1210
- this.channelData = await this.getDetails();
1209
+ try {
1210
+ if (!this.channelData) {
1211
+ this.channelData = await this.getDetails();
1212
+ }
1213
+ if (!this.channelData?.id) {
1214
+ throw new Error("Channel ID is not available");
1215
+ }
1216
+ } catch (error) {
1217
+ console.error("Failed to get channel details:", error);
1218
+ throw new Error("Could not initialize channel data");
1211
1219
  }
1212
- const playback = this.client.Playback(playbackId || v4_default());
1213
- await this.baseClient.post(
1214
- `/channels/${this.id}/play/${playback.id}`,
1220
+ const playbackInstance = this.client.Playback(playbackId || v4_default());
1221
+ console.log("Attempting to play media:", {
1222
+ channelId: this.id,
1223
+ playbackId: playbackInstance.id,
1215
1224
  options
1216
- );
1217
- return playback;
1225
+ });
1226
+ try {
1227
+ await this.baseClient.post(
1228
+ `/channels/${this.id}/play/${playbackInstance.id}`,
1229
+ options
1230
+ );
1231
+ console.log("Successfully initiated playback:", {
1232
+ channelId: this.id,
1233
+ playbackId: playbackInstance.id
1234
+ });
1235
+ const playbackStatus = await playbackInstance.get().catch((err) => {
1236
+ console.warn("Could not verify playback status:", err);
1237
+ return null;
1238
+ });
1239
+ if (!playbackStatus) {
1240
+ console.warn("Playback was created but status could not be verified");
1241
+ } else {
1242
+ console.log("Playback status:", playbackStatus);
1243
+ }
1244
+ return playbackInstance;
1245
+ } catch (error) {
1246
+ const message = getErrorMessage(error);
1247
+ console.error(
1248
+ `Failed to start playback on channel ${this.id}:`,
1249
+ message
1250
+ );
1251
+ try {
1252
+ await playbackInstance.stop().catch();
1253
+ } catch {
1254
+ }
1255
+ throw new Error(`Failed to start playback: ${message}`);
1256
+ }
1218
1257
  } catch (error) {
1219
1258
  const message = getErrorMessage(error);
1220
1259
  console.error(`Error playing media on channel ${this.id}:`, message);