@ipcom/asterisk-ari 0.0.151 → 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,73 +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
- let playbackStarted = false;
1215
- const failureListener = (event) => {
1216
- if ("playback" in event && event.playback) {
1217
- if (event.playback.state === "failed") {
1218
- console.error("Playback falhou:", {
1219
- playbackId: playback.id,
1220
- channelId: this.id,
1221
- state: event.playback.state
1222
- });
1223
- if (!playbackStarted) {
1224
- reject(
1225
- new Error(
1226
- `Playback failed to start: ${event.playback.state}`
1227
- )
1228
- );
1229
- }
1230
- }
1231
- }
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);
1259
- await this.baseClient.post(
1260
- `/channels/${this.id}/play/${playback.id}`,
1261
- options
1262
- );
1263
- setTimeout(() => {
1264
- if (!playbackStarted) {
1265
- reject(new Error("Playback timeout - n\xE3o iniciou"));
1266
- }
1267
- }, 5e3);
1268
- } catch (error) {
1269
- 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();
1270
1211
  }
1271
- });
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
+ }
1272
1223
  }
1273
1224
  /**
1274
1225
  * Gets the current channel details
@@ -2601,32 +2552,9 @@ var WebSocketClient = class extends import_events3.EventEmitter {
2601
2552
  );
2602
2553
  }
2603
2554
  }
2604
- /**
2605
- * Checks if the WebSocket connection is currently open and active.
2606
- *
2607
- * This method examines the readyState of the WebSocket instance to determine
2608
- * if the connection is established and ready for communication.
2609
- *
2610
- * @returns {boolean} True if the WebSocket connection is open and ready,
2611
- * false otherwise.
2612
- */
2613
2555
  isConnected() {
2614
2556
  return this.ws?.readyState === import_ws.default.OPEN;
2615
2557
  }
2616
- /**
2617
- * Retrieves the current state of the WebSocket connection.
2618
- *
2619
- * This method returns the readyState of the WebSocket instance, which
2620
- * indicates the current state of the connection. If no WebSocket instance
2621
- * exists, it returns the CLOSED state.
2622
- *
2623
- * @returns {number} The current state of the WebSocket connection.
2624
- * Possible values are:
2625
- * - WebSocket.CONNECTING (0): The connection is not yet open.
2626
- * - WebSocket.OPEN (1): The connection is open and ready to communicate.
2627
- * - WebSocket.CLOSING (2): The connection is in the process of closing.
2628
- * - WebSocket.CLOSED (3): The connection is closed or couldn't be opened.
2629
- */
2630
2558
  getState() {
2631
2559
  return this.ws?.readyState ?? import_ws.default.CLOSED;
2632
2560
  }