@ipcom/asterisk-ari 0.0.147 → 0.0.149

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,36 @@ var ChannelInstance = class {
1186
1186
  throw new Error("Media URL is required");
1187
1187
  }
1188
1188
  try {
1189
- try {
1190
- if (!this.channelData) {
1191
- this.channelData = await this.getDetails();
1192
- }
1193
- if (!this.channelData?.id) {
1194
- throw new Error("Channel ID is not available");
1195
- }
1196
- } catch (error) {
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();
1199
1194
  }
1200
- const playbackInstance = this.client.Playback(playbackId || v4_default());
1201
- console.log("Attempting to play media:", {
1202
- channelId: this.id,
1203
- playbackId: playbackInstance.id,
1204
- options
1205
- });
1206
- try {
1207
- await this.baseClient.post(
1208
- `/channels/${this.id}/play/${playbackInstance.id}`,
1209
- options
1210
- );
1211
- console.log("Successfully initiated playback:", {
1212
- channelId: this.id,
1213
- playbackId: playbackInstance.id
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
+ return new Promise((resolve, reject) => {
1201
+ playback.once("PlaybackFinished", (event) => {
1202
+ console.log("Playback finished: ", event);
1214
1203
  });
1215
- const playbackStatus = await playbackInstance.get().catch((err) => {
1216
- console.warn("Could not verify playback status:", err);
1217
- return null;
1204
+ this.baseClient.post(`/channels/${this.id}/play/${playback.id}`, options).then(() => {
1205
+ console.log("Playback request successful");
1206
+ resolve(playback);
1207
+ }).catch((error) => {
1208
+ console.error("Error starting playback:", error);
1209
+ reject(error);
1218
1210
  });
1219
- if (!playbackStatus) {
1220
- console.warn("Playback was created but status could not be verified");
1221
- } else {
1222
- console.log("Playback status:", playbackStatus);
1223
- }
1224
- return playbackInstance;
1225
- } catch (error) {
1226
- const message = getErrorMessage(error);
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}`);
1236
- }
1211
+ });
1237
1212
  } catch (error) {
1238
1213
  const message = getErrorMessage(error);
1239
- console.error(`Error playing media on channel ${this.id}:`, message);
1214
+ console.error(`Error playing media on channel ${this.id}:`, {
1215
+ error: message,
1216
+ options,
1217
+ channelState: this.channelData?.state
1218
+ });
1240
1219
  throw new Error(`Failed to play media: ${message}`);
1241
1220
  }
1242
1221
  }