@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.
- package/dist/cjs/index.cjs +17 -89
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +17 -89
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/resources/channels.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts +0 -23
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1182,73 +1182,24 @@ var ChannelInstance = class {
|
|
|
1182
1182
|
* Plays media on the channel
|
|
1183
1183
|
*/
|
|
1184
1184
|
async play(options, playbackId) {
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
this.channelData = await this.getDetails();
|
|
1192
|
-
}
|
|
1193
|
-
const playback = this.client.Playback(playbackId || v4_default());
|
|
1194
|
-
let playbackStarted = false;
|
|
1195
|
-
const failureListener = (event) => {
|
|
1196
|
-
if ("playback" in event && event.playback) {
|
|
1197
|
-
if (event.playback.state === "failed") {
|
|
1198
|
-
console.error("Playback falhou:", {
|
|
1199
|
-
playbackId: playback.id,
|
|
1200
|
-
channelId: this.id,
|
|
1201
|
-
state: event.playback.state
|
|
1202
|
-
});
|
|
1203
|
-
if (!playbackStarted) {
|
|
1204
|
-
reject(
|
|
1205
|
-
new Error(
|
|
1206
|
-
`Playback failed to start: ${event.playback.state}`
|
|
1207
|
-
)
|
|
1208
|
-
);
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
};
|
|
1213
|
-
const startListener = (event) => {
|
|
1214
|
-
if ("playback" in event && event.playback) {
|
|
1215
|
-
console.log("Playback come\xE7ou:", {
|
|
1216
|
-
playbackId: playback.id,
|
|
1217
|
-
channelId: this.id,
|
|
1218
|
-
state: event.playback.state
|
|
1219
|
-
});
|
|
1220
|
-
playbackStarted = true;
|
|
1221
|
-
setTimeout(async () => {
|
|
1222
|
-
try {
|
|
1223
|
-
const status = await playback.get();
|
|
1224
|
-
if (status.state === "playing") {
|
|
1225
|
-
resolve(playback);
|
|
1226
|
-
} else {
|
|
1227
|
-
reject(
|
|
1228
|
-
new Error(`Playback started but state is ${status.state}`)
|
|
1229
|
-
);
|
|
1230
|
-
}
|
|
1231
|
-
} catch (_err) {
|
|
1232
|
-
reject(new Error("Failed to verify playback status"));
|
|
1233
|
-
}
|
|
1234
|
-
}, 500);
|
|
1235
|
-
}
|
|
1236
|
-
};
|
|
1237
|
-
playback.once("PlaybackStarted", startListener);
|
|
1238
|
-
playback.once("PlaybackFinished", failureListener);
|
|
1239
|
-
await this.baseClient.post(
|
|
1240
|
-
`/channels/${this.id}/play/${playback.id}`,
|
|
1241
|
-
options
|
|
1242
|
-
);
|
|
1243
|
-
setTimeout(() => {
|
|
1244
|
-
if (!playbackStarted) {
|
|
1245
|
-
reject(new Error("Playback timeout - n\xE3o iniciou"));
|
|
1246
|
-
}
|
|
1247
|
-
}, 5e3);
|
|
1248
|
-
} catch (error) {
|
|
1249
|
-
reject(error);
|
|
1185
|
+
if (!options.media) {
|
|
1186
|
+
throw new Error("Media URL is required");
|
|
1187
|
+
}
|
|
1188
|
+
try {
|
|
1189
|
+
if (!this.channelData) {
|
|
1190
|
+
this.channelData = await this.getDetails();
|
|
1250
1191
|
}
|
|
1251
|
-
|
|
1192
|
+
const playback = this.client.Playback(playbackId || v4_default());
|
|
1193
|
+
await this.baseClient.post(
|
|
1194
|
+
`/channels/${this.id}/play/${playback.id}`,
|
|
1195
|
+
options
|
|
1196
|
+
);
|
|
1197
|
+
return playback;
|
|
1198
|
+
} catch (error) {
|
|
1199
|
+
const message = getErrorMessage(error);
|
|
1200
|
+
console.error(`Error playing media on channel ${this.id}:`, message);
|
|
1201
|
+
throw new Error(`Failed to play media: ${message}`);
|
|
1202
|
+
}
|
|
1252
1203
|
}
|
|
1253
1204
|
/**
|
|
1254
1205
|
* Gets the current channel details
|
|
@@ -2581,32 +2532,9 @@ var WebSocketClient = class extends EventEmitter3 {
|
|
|
2581
2532
|
);
|
|
2582
2533
|
}
|
|
2583
2534
|
}
|
|
2584
|
-
/**
|
|
2585
|
-
* Checks if the WebSocket connection is currently open and active.
|
|
2586
|
-
*
|
|
2587
|
-
* This method examines the readyState of the WebSocket instance to determine
|
|
2588
|
-
* if the connection is established and ready for communication.
|
|
2589
|
-
*
|
|
2590
|
-
* @returns {boolean} True if the WebSocket connection is open and ready,
|
|
2591
|
-
* false otherwise.
|
|
2592
|
-
*/
|
|
2593
2535
|
isConnected() {
|
|
2594
2536
|
return this.ws?.readyState === WebSocket.OPEN;
|
|
2595
2537
|
}
|
|
2596
|
-
/**
|
|
2597
|
-
* Retrieves the current state of the WebSocket connection.
|
|
2598
|
-
*
|
|
2599
|
-
* This method returns the readyState of the WebSocket instance, which
|
|
2600
|
-
* indicates the current state of the connection. If no WebSocket instance
|
|
2601
|
-
* exists, it returns the CLOSED state.
|
|
2602
|
-
*
|
|
2603
|
-
* @returns {number} The current state of the WebSocket connection.
|
|
2604
|
-
* Possible values are:
|
|
2605
|
-
* - WebSocket.CONNECTING (0): The connection is not yet open.
|
|
2606
|
-
* - WebSocket.OPEN (1): The connection is open and ready to communicate.
|
|
2607
|
-
* - WebSocket.CLOSING (2): The connection is in the process of closing.
|
|
2608
|
-
* - WebSocket.CLOSED (3): The connection is closed or couldn't be opened.
|
|
2609
|
-
*/
|
|
2610
2538
|
getState() {
|
|
2611
2539
|
return this.ws?.readyState ?? WebSocket.CLOSED;
|
|
2612
2540
|
}
|