@ipcom/asterisk-ari 0.0.150 → 0.0.151

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.
@@ -1211,31 +1211,59 @@ var ChannelInstance = class {
1211
1211
  this.channelData = await this.getDetails();
1212
1212
  }
1213
1213
  const playback = this.client.Playback(playbackId || v4_default());
1214
- playback.once("PlaybackStarted", (event) => {
1215
- if ("playback" in event) {
1216
- console.log("Playback realmente iniciado:", playback.id);
1217
- resolve(playback);
1218
- }
1219
- });
1220
- playback.once("PlaybackFinished", async (event) => {
1214
+ let playbackStarted = false;
1215
+ const failureListener = (event) => {
1221
1216
  if ("playback" in event && event.playback) {
1222
- const playbackState = event.playback.state;
1223
- if (playbackState === "failed") {
1217
+ if (event.playback.state === "failed") {
1224
1218
  console.error("Playback falhou:", {
1225
1219
  playbackId: playback.id,
1226
1220
  channelId: this.id,
1227
- state: playbackState
1221
+ state: event.playback.state
1228
1222
  });
1229
- reject(new Error(`Playback failed: ${playbackState}`));
1223
+ if (!playbackStarted) {
1224
+ reject(
1225
+ new Error(
1226
+ `Playback failed to start: ${event.playback.state}`
1227
+ )
1228
+ );
1229
+ }
1230
1230
  }
1231
1231
  }
1232
- });
1232
+ };
1233
+ const startListener = (event) => {
1234
+ if ("playback" in event && event.playback) {
1235
+ console.log("Playback come\xE7ou:", {
1236
+ playbackId: playback.id,
1237
+ channelId: this.id,
1238
+ state: event.playback.state
1239
+ });
1240
+ playbackStarted = true;
1241
+ setTimeout(async () => {
1242
+ try {
1243
+ const status = await playback.get();
1244
+ if (status.state === "playing") {
1245
+ resolve(playback);
1246
+ } else {
1247
+ reject(
1248
+ new Error(`Playback started but state is ${status.state}`)
1249
+ );
1250
+ }
1251
+ } catch (_err) {
1252
+ reject(new Error("Failed to verify playback status"));
1253
+ }
1254
+ }, 500);
1255
+ }
1256
+ };
1257
+ playback.once("PlaybackStarted", startListener);
1258
+ playback.once("PlaybackFinished", failureListener);
1233
1259
  await this.baseClient.post(
1234
1260
  `/channels/${this.id}/play/${playback.id}`,
1235
1261
  options
1236
1262
  );
1237
1263
  setTimeout(() => {
1238
- reject(new Error("Playback timeout - n\xE3o recebeu evento de in\xEDcio"));
1264
+ if (!playbackStarted) {
1265
+ reject(new Error("Playback timeout - n\xE3o iniciou"));
1266
+ }
1239
1267
  }, 5e3);
1240
1268
  } catch (error) {
1241
1269
  reject(error);