@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.
- package/dist/cjs/index.cjs +17 -61
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +17 -61
- 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,45 +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
|
-
playback.once("PlaybackStarted", (event) => {
|
|
1195
|
-
if ("playback" in event) {
|
|
1196
|
-
console.log("Playback realmente iniciado:", playback.id);
|
|
1197
|
-
resolve(playback);
|
|
1198
|
-
}
|
|
1199
|
-
});
|
|
1200
|
-
playback.once("PlaybackFinished", async (event) => {
|
|
1201
|
-
if ("playback" in event && event.playback) {
|
|
1202
|
-
const playbackState = event.playback.state;
|
|
1203
|
-
if (playbackState === "failed") {
|
|
1204
|
-
console.error("Playback falhou:", {
|
|
1205
|
-
playbackId: playback.id,
|
|
1206
|
-
channelId: this.id,
|
|
1207
|
-
state: playbackState
|
|
1208
|
-
});
|
|
1209
|
-
reject(new Error(`Playback failed: ${playbackState}`));
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
});
|
|
1213
|
-
await this.baseClient.post(
|
|
1214
|
-
`/channels/${this.id}/play/${playback.id}`,
|
|
1215
|
-
options
|
|
1216
|
-
);
|
|
1217
|
-
setTimeout(() => {
|
|
1218
|
-
reject(new Error("Playback timeout - n\xE3o recebeu evento de in\xEDcio"));
|
|
1219
|
-
}, 5e3);
|
|
1220
|
-
} catch (error) {
|
|
1221
|
-
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();
|
|
1222
1191
|
}
|
|
1223
|
-
|
|
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
|
+
}
|
|
1224
1203
|
}
|
|
1225
1204
|
/**
|
|
1226
1205
|
* Gets the current channel details
|
|
@@ -2553,32 +2532,9 @@ var WebSocketClient = class extends EventEmitter3 {
|
|
|
2553
2532
|
);
|
|
2554
2533
|
}
|
|
2555
2534
|
}
|
|
2556
|
-
/**
|
|
2557
|
-
* Checks if the WebSocket connection is currently open and active.
|
|
2558
|
-
*
|
|
2559
|
-
* This method examines the readyState of the WebSocket instance to determine
|
|
2560
|
-
* if the connection is established and ready for communication.
|
|
2561
|
-
*
|
|
2562
|
-
* @returns {boolean} True if the WebSocket connection is open and ready,
|
|
2563
|
-
* false otherwise.
|
|
2564
|
-
*/
|
|
2565
2535
|
isConnected() {
|
|
2566
2536
|
return this.ws?.readyState === WebSocket.OPEN;
|
|
2567
2537
|
}
|
|
2568
|
-
/**
|
|
2569
|
-
* Retrieves the current state of the WebSocket connection.
|
|
2570
|
-
*
|
|
2571
|
-
* This method returns the readyState of the WebSocket instance, which
|
|
2572
|
-
* indicates the current state of the connection. If no WebSocket instance
|
|
2573
|
-
* exists, it returns the CLOSED state.
|
|
2574
|
-
*
|
|
2575
|
-
* @returns {number} The current state of the WebSocket connection.
|
|
2576
|
-
* Possible values are:
|
|
2577
|
-
* - WebSocket.CONNECTING (0): The connection is not yet open.
|
|
2578
|
-
* - WebSocket.OPEN (1): The connection is open and ready to communicate.
|
|
2579
|
-
* - WebSocket.CLOSING (2): The connection is in the process of closing.
|
|
2580
|
-
* - WebSocket.CLOSED (3): The connection is closed or couldn't be opened.
|
|
2581
|
-
*/
|
|
2582
2538
|
getState() {
|
|
2583
2539
|
return this.ws?.readyState ?? WebSocket.CLOSED;
|
|
2584
2540
|
}
|