@ipcom/asterisk-ari 0.0.150 → 0.0.152

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.
@@ -1202,45 +1202,24 @@ var ChannelInstance = class {
1202
1202
  * Plays media on the channel
1203
1203
  */
1204
1204
  async play(options, playbackId) {
1205
- return new Promise(async (resolve, reject) => {
1206
- try {
1207
- if (!options.media) {
1208
- throw new Error("Media URL is required");
1209
- }
1210
- if (!this.channelData) {
1211
- this.channelData = await this.getDetails();
1212
- }
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) => {
1221
- if ("playback" in event && event.playback) {
1222
- const playbackState = event.playback.state;
1223
- if (playbackState === "failed") {
1224
- console.error("Playback falhou:", {
1225
- playbackId: playback.id,
1226
- channelId: this.id,
1227
- state: playbackState
1228
- });
1229
- reject(new Error(`Playback failed: ${playbackState}`));
1230
- }
1231
- }
1232
- });
1233
- await this.baseClient.post(
1234
- `/channels/${this.id}/play/${playback.id}`,
1235
- options
1236
- );
1237
- setTimeout(() => {
1238
- reject(new Error("Playback timeout - n\xE3o recebeu evento de in\xEDcio"));
1239
- }, 5e3);
1240
- } catch (error) {
1241
- reject(error);
1205
+ if (!options.media) {
1206
+ throw new Error("Media URL is required");
1207
+ }
1208
+ try {
1209
+ if (!this.channelData) {
1210
+ this.channelData = await this.getDetails();
1242
1211
  }
1243
- });
1212
+ const playback = this.client.Playback(playbackId || v4_default());
1213
+ await this.baseClient.post(
1214
+ `/channels/${this.id}/play/${playback.id}`,
1215
+ options
1216
+ );
1217
+ return playback;
1218
+ } catch (error) {
1219
+ const message = getErrorMessage(error);
1220
+ console.error(`Error playing media on channel ${this.id}:`, message);
1221
+ throw new Error(`Failed to play media: ${message}`);
1222
+ }
1244
1223
  }
1245
1224
  /**
1246
1225
  * Gets the current channel details
@@ -2573,32 +2552,9 @@ var WebSocketClient = class extends import_events3.EventEmitter {
2573
2552
  );
2574
2553
  }
2575
2554
  }
2576
- /**
2577
- * Checks if the WebSocket connection is currently open and active.
2578
- *
2579
- * This method examines the readyState of the WebSocket instance to determine
2580
- * if the connection is established and ready for communication.
2581
- *
2582
- * @returns {boolean} True if the WebSocket connection is open and ready,
2583
- * false otherwise.
2584
- */
2585
2555
  isConnected() {
2586
2556
  return this.ws?.readyState === import_ws.default.OPEN;
2587
2557
  }
2588
- /**
2589
- * Retrieves the current state of the WebSocket connection.
2590
- *
2591
- * This method returns the readyState of the WebSocket instance, which
2592
- * indicates the current state of the connection. If no WebSocket instance
2593
- * exists, it returns the CLOSED state.
2594
- *
2595
- * @returns {number} The current state of the WebSocket connection.
2596
- * Possible values are:
2597
- * - WebSocket.CONNECTING (0): The connection is not yet open.
2598
- * - WebSocket.OPEN (1): The connection is open and ready to communicate.
2599
- * - WebSocket.CLOSING (2): The connection is in the process of closing.
2600
- * - WebSocket.CLOSED (3): The connection is closed or couldn't be opened.
2601
- */
2602
2558
  getState() {
2603
2559
  return this.ws?.readyState ?? import_ws.default.CLOSED;
2604
2560
  }