@ipcom/asterisk-ari 0.0.25 → 0.0.26
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 +303 -64
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/esm/index.js +303 -64
- package/dist/esm/index.js.map +3 -3
- package/dist/types/ari-client/ariClient.d.ts +123 -26
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/interfaces/playbacks.types.d.ts +9 -2
- package/dist/types/ari-client/interfaces/playbacks.types.d.ts.map +1 -1
- package/dist/types/ari-client/resources/playbacks.d.ts +42 -2
- package/dist/types/ari-client/resources/playbacks.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts +55 -4
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -572,6 +572,7 @@ var require_backoff = __commonJS({
|
|
|
572
572
|
|
|
573
573
|
// src/ari-client/ariClient.ts
|
|
574
574
|
var import_exponential_backoff = __toESM(require_backoff(), 1);
|
|
575
|
+
import { EventEmitter as EventEmitter3 } from "events";
|
|
575
576
|
|
|
576
577
|
// src/ari-client/baseClient.ts
|
|
577
578
|
import axios from "axios";
|
|
@@ -1181,8 +1182,10 @@ var Endpoints = class {
|
|
|
1181
1182
|
};
|
|
1182
1183
|
|
|
1183
1184
|
// src/ari-client/resources/playbacks.ts
|
|
1184
|
-
|
|
1185
|
+
import { EventEmitter } from "events";
|
|
1186
|
+
var Playbacks = class extends EventEmitter {
|
|
1185
1187
|
constructor(client) {
|
|
1188
|
+
super();
|
|
1186
1189
|
this.client = client;
|
|
1187
1190
|
}
|
|
1188
1191
|
/**
|
|
@@ -1221,6 +1224,50 @@ var Playbacks = class {
|
|
|
1221
1224
|
async stop(playbackId) {
|
|
1222
1225
|
await this.client.post(`/playbacks/${playbackId}/stop`);
|
|
1223
1226
|
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Registers a listener for playback events.
|
|
1229
|
+
* The listener is triggered for events such as "PlaybackFinished".
|
|
1230
|
+
*
|
|
1231
|
+
* @param eventType - The type of event to listen for.
|
|
1232
|
+
* @param playbackId - The ID of the playback to associate with this listener.
|
|
1233
|
+
* @param callback - The callback function to execute when the event occurs.
|
|
1234
|
+
*/
|
|
1235
|
+
registerListener(eventType, playbackId, callback) {
|
|
1236
|
+
this.on(`${eventType}:${playbackId}`, callback);
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Unregisters a listener for playback events.
|
|
1240
|
+
*
|
|
1241
|
+
* @param eventType - The type of event to stop listening for.
|
|
1242
|
+
* @param playbackId - The ID of the playback associated with the listener.
|
|
1243
|
+
* @param callback - The callback function to remove.
|
|
1244
|
+
*/
|
|
1245
|
+
unregisterListener(eventType, playbackId, callback) {
|
|
1246
|
+
this.off(`${eventType}:${playbackId}`, callback);
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Checks if a listener is already registered for a specific event and playback.
|
|
1250
|
+
*
|
|
1251
|
+
* @param eventType - The type of event to check.
|
|
1252
|
+
* @param playbackId - The playback ID associated with the listener.
|
|
1253
|
+
* @returns True if a listener is already registered, false otherwise.
|
|
1254
|
+
*/
|
|
1255
|
+
isListenerRegistered(eventType, playbackId) {
|
|
1256
|
+
return this.listenerCount(`${eventType}:${playbackId}`) > 0;
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Emits playback events received via WebSocket.
|
|
1260
|
+
* This method should be called by the WebSocket client when playback events occur.
|
|
1261
|
+
*
|
|
1262
|
+
* @param eventType - The type of the WebSocket event.
|
|
1263
|
+
* @param data - The data associated with the event.
|
|
1264
|
+
*/
|
|
1265
|
+
emitPlaybackEvent(eventType, data) {
|
|
1266
|
+
if ("playbackId" in data) {
|
|
1267
|
+
this.emit(`${eventType}:${data.playbackId}`, data);
|
|
1268
|
+
}
|
|
1269
|
+
this.emit(eventType, data);
|
|
1270
|
+
}
|
|
1224
1271
|
};
|
|
1225
1272
|
|
|
1226
1273
|
// src/ari-client/resources/sounds.ts
|
|
@@ -1255,16 +1302,25 @@ var Sounds = class {
|
|
|
1255
1302
|
};
|
|
1256
1303
|
|
|
1257
1304
|
// src/ari-client/websocketClient.ts
|
|
1305
|
+
import { EventEmitter as EventEmitter2 } from "events";
|
|
1258
1306
|
import WebSocket from "ws";
|
|
1259
|
-
var WebSocketClient = class {
|
|
1260
|
-
|
|
1307
|
+
var WebSocketClient = class extends EventEmitter2 {
|
|
1308
|
+
/**
|
|
1309
|
+
* Creates a new WebSocketClient instance.
|
|
1310
|
+
* @param url - The WebSocket server URL to connect to.
|
|
1311
|
+
*/
|
|
1261
1312
|
constructor(url) {
|
|
1313
|
+
super();
|
|
1262
1314
|
this.url = url;
|
|
1263
1315
|
}
|
|
1264
1316
|
ws = null;
|
|
1265
1317
|
isClosedManually = false;
|
|
1266
|
-
// Para evitar reconexões automáticas quando fechado manualmente
|
|
1267
1318
|
isReconnecting = false;
|
|
1319
|
+
/**
|
|
1320
|
+
* Establishes a connection to the WebSocket server.
|
|
1321
|
+
* @returns A Promise that resolves when the connection is established, or rejects if an error occurs.
|
|
1322
|
+
* @throws Will throw an error if the connection fails.
|
|
1323
|
+
*/
|
|
1268
1324
|
async connect() {
|
|
1269
1325
|
if (this.isReconnecting) return;
|
|
1270
1326
|
return new Promise((resolve, reject) => {
|
|
@@ -1282,47 +1338,70 @@ var WebSocketClient = class {
|
|
|
1282
1338
|
this.ws.on("close", (code, reason) => {
|
|
1283
1339
|
console.warn(`WebSocket desconectado: ${code} - ${reason}`);
|
|
1284
1340
|
this.isReconnecting = false;
|
|
1341
|
+
this.emit("close", { code, reason });
|
|
1342
|
+
});
|
|
1343
|
+
this.ws.on("message", (rawData) => {
|
|
1344
|
+
this.handleMessage(rawData);
|
|
1285
1345
|
});
|
|
1286
1346
|
});
|
|
1287
1347
|
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
try {
|
|
1293
|
-
await this.connect();
|
|
1294
|
-
console.log("Reconex\xE3o bem-sucedida.");
|
|
1295
|
-
} catch (err) {
|
|
1296
|
-
console.error("Erro ao tentar reconectar:", err);
|
|
1297
|
-
} finally {
|
|
1298
|
-
this.isReconnecting = false;
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Checks if the WebSocket connection is currently open.
|
|
1350
|
+
* @returns True if the connection is open, false otherwise.
|
|
1351
|
+
*/
|
|
1301
1352
|
isConnected() {
|
|
1302
1353
|
return this.ws?.readyState === WebSocket.OPEN;
|
|
1303
1354
|
}
|
|
1355
|
+
/**
|
|
1356
|
+
* Adds a listener for WebSocket events.
|
|
1357
|
+
* @param event - The event type to listen for.
|
|
1358
|
+
* @param callback - The function to call when the event occurs.
|
|
1359
|
+
* @returns The WebSocketClient instance for chaining.
|
|
1360
|
+
*/
|
|
1304
1361
|
on(event, callback) {
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1362
|
+
super.on(event, callback);
|
|
1363
|
+
return this;
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Removes a specific listener from a WebSocket event.
|
|
1367
|
+
* @param event - The event type to remove the listener from.
|
|
1368
|
+
* @param callback - The function to remove from the event listeners.
|
|
1369
|
+
* @returns The WebSocketClient instance for chaining.
|
|
1370
|
+
*/
|
|
1371
|
+
off(event, callback) {
|
|
1372
|
+
super.off(event, callback);
|
|
1373
|
+
return this;
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Removes all listeners for a specific event, or all events if no event is specified.
|
|
1377
|
+
* @param event - Optional. The event to remove all listeners from.
|
|
1378
|
+
* @returns The WebSocketClient instance for chaining.
|
|
1379
|
+
*/
|
|
1380
|
+
removeAllListeners(event) {
|
|
1381
|
+
super.removeAllListeners(event);
|
|
1382
|
+
return this;
|
|
1383
|
+
}
|
|
1384
|
+
/**
|
|
1385
|
+
* Handles incoming WebSocket messages.
|
|
1386
|
+
* @param rawData - The raw data received from the WebSocket.
|
|
1387
|
+
*/
|
|
1388
|
+
handleMessage(rawData) {
|
|
1389
|
+
try {
|
|
1390
|
+
const decodedData = JSON.parse(rawData.toString());
|
|
1391
|
+
if (decodedData?.type) {
|
|
1392
|
+
this.emit(decodedData.type, decodedData);
|
|
1393
|
+
} else {
|
|
1394
|
+
console.warn("Mensagem recebida sem tipo:", decodedData);
|
|
1395
|
+
}
|
|
1396
|
+
} catch (err) {
|
|
1397
|
+
console.error("Erro ao decodificar mensagem do WebSocket:", err);
|
|
1324
1398
|
}
|
|
1325
1399
|
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Sends data through the WebSocket connection.
|
|
1402
|
+
* @param data - The data to send.
|
|
1403
|
+
* @throws Will throw an error if the WebSocket is not connected.
|
|
1404
|
+
*/
|
|
1326
1405
|
send(data) {
|
|
1327
1406
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
1328
1407
|
throw new Error("WebSocket n\xE3o est\xE1 conectado.");
|
|
@@ -1333,6 +1412,9 @@ var WebSocketClient = class {
|
|
|
1333
1412
|
}
|
|
1334
1413
|
});
|
|
1335
1414
|
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Closes the WebSocket connection manually.
|
|
1417
|
+
*/
|
|
1336
1418
|
close() {
|
|
1337
1419
|
if (this.ws) {
|
|
1338
1420
|
this.isClosedManually = true;
|
|
@@ -1361,6 +1443,7 @@ var AriClient = class {
|
|
|
1361
1443
|
wsClient = null;
|
|
1362
1444
|
baseClient;
|
|
1363
1445
|
isReconnecting = false;
|
|
1446
|
+
eventEmitter = new EventEmitter3();
|
|
1364
1447
|
channels;
|
|
1365
1448
|
endpoints;
|
|
1366
1449
|
applications;
|
|
@@ -1370,10 +1453,14 @@ var AriClient = class {
|
|
|
1370
1453
|
bridges;
|
|
1371
1454
|
/**
|
|
1372
1455
|
* Connects to the ARI WebSocket for a specific application.
|
|
1456
|
+
* This function establishes a WebSocket connection to the Asterisk ARI, sets up event listeners,
|
|
1457
|
+
* and ensures the application is registered. It uses an exponential backoff strategy for connection attempts.
|
|
1373
1458
|
*
|
|
1374
|
-
* @param app - The application
|
|
1375
|
-
* @param subscribedEvents
|
|
1376
|
-
*
|
|
1459
|
+
* @param app - The name of the application to connect to. This is required and used to identify the application in ARI.
|
|
1460
|
+
* @param subscribedEvents - Optional array of WebSocketEventType to subscribe to specific events.
|
|
1461
|
+
* If not provided or empty, it subscribes to all events.
|
|
1462
|
+
* @returns A Promise that resolves when the WebSocket connection is successfully established and the application is registered.
|
|
1463
|
+
* @throws Error if the 'app' parameter is not provided, or if connection attempts fail after multiple retries.
|
|
1377
1464
|
*/
|
|
1378
1465
|
async connectWebSocket(app, subscribedEvents) {
|
|
1379
1466
|
if (!app) {
|
|
@@ -1401,6 +1488,11 @@ var AriClient = class {
|
|
|
1401
1488
|
return !this.wsClient?.isConnected();
|
|
1402
1489
|
}
|
|
1403
1490
|
};
|
|
1491
|
+
if (this.wsClient?.isConnected()) {
|
|
1492
|
+
console.log("WebSocket j\xE1 conectado. Removendo listeners antigos...");
|
|
1493
|
+
this.wsClient.removeAllListeners();
|
|
1494
|
+
this.wsClient.close();
|
|
1495
|
+
}
|
|
1404
1496
|
this.wsClient = new WebSocketClient(wsUrl);
|
|
1405
1497
|
try {
|
|
1406
1498
|
await (0, import_exponential_backoff.backOff)(async () => {
|
|
@@ -1408,6 +1500,7 @@ var AriClient = class {
|
|
|
1408
1500
|
throw new Error("WebSocketClient instance is null.");
|
|
1409
1501
|
}
|
|
1410
1502
|
await this.wsClient.connect();
|
|
1503
|
+
this.integrateWebSocketEvents();
|
|
1411
1504
|
console.log(`WebSocket conectado para o app: ${app}`);
|
|
1412
1505
|
await this.ensureAppRegistered(app);
|
|
1413
1506
|
}, backoffOptions);
|
|
@@ -1421,6 +1514,103 @@ var AriClient = class {
|
|
|
1421
1514
|
this.isReconnecting = false;
|
|
1422
1515
|
}
|
|
1423
1516
|
}
|
|
1517
|
+
/**
|
|
1518
|
+
* Integrates WebSocket events with playback listeners.
|
|
1519
|
+
*/
|
|
1520
|
+
integrateWebSocketEvents() {
|
|
1521
|
+
if (!this.wsClient) {
|
|
1522
|
+
throw new Error("WebSocket client n\xE3o est\xE1 conectado.");
|
|
1523
|
+
}
|
|
1524
|
+
const eventHandlers = {
|
|
1525
|
+
PlaybackFinished: (data) => {
|
|
1526
|
+
if ("playbackId" in data) {
|
|
1527
|
+
this.playbacks.emitPlaybackEvent("PlaybackFinished", data);
|
|
1528
|
+
}
|
|
1529
|
+
this.emitGlobalEvent(data);
|
|
1530
|
+
},
|
|
1531
|
+
ChannelStateChange: (data) => {
|
|
1532
|
+
if ("channel" in data) {
|
|
1533
|
+
console.log("Estado do canal alterado:", data.channel);
|
|
1534
|
+
}
|
|
1535
|
+
this.emitGlobalEvent(data);
|
|
1536
|
+
},
|
|
1537
|
+
BridgeDestroyed: (data) => {
|
|
1538
|
+
if ("bridge" in data) {
|
|
1539
|
+
console.log("Bridge destru\xEDda:", data.bridge);
|
|
1540
|
+
}
|
|
1541
|
+
this.emitGlobalEvent(data);
|
|
1542
|
+
},
|
|
1543
|
+
// Adicione mais eventos conforme necessário
|
|
1544
|
+
// Exemplo:
|
|
1545
|
+
ChannelDtmfReceived: (data) => {
|
|
1546
|
+
if ("channel" in data) {
|
|
1547
|
+
console.log("DTMF recebido no canal:", data.channel);
|
|
1548
|
+
}
|
|
1549
|
+
this.emitGlobalEvent(data);
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
for (const [eventType, handler] of Object.entries(eventHandlers)) {
|
|
1553
|
+
if (handler) {
|
|
1554
|
+
this.wsClient.on(eventType, handler);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
console.log("Todos os eventos do WebSocket foram registrados.");
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* Registra um listener para eventos globais.
|
|
1561
|
+
* @param callback - A função a ser executada quando um evento global for recebido.
|
|
1562
|
+
*/
|
|
1563
|
+
onGlobalEvent(callback) {
|
|
1564
|
+
this.eventEmitter.on("globalEvent", callback);
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* Remove um listener para eventos globais.
|
|
1568
|
+
* @param callback - A função a ser removida dos eventos globais.
|
|
1569
|
+
*/
|
|
1570
|
+
offGlobalEvent(callback) {
|
|
1571
|
+
this.eventEmitter.off("globalEvent", callback);
|
|
1572
|
+
}
|
|
1573
|
+
/**
|
|
1574
|
+
* Emite um evento global.
|
|
1575
|
+
* @param data - Os dados do evento a serem emitidos.
|
|
1576
|
+
*/
|
|
1577
|
+
emitGlobalEvent(data) {
|
|
1578
|
+
this.eventEmitter.emit("globalEvent", data);
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Unregisters a listener for playback events.
|
|
1582
|
+
*
|
|
1583
|
+
* This method removes a specific listener registered for a playback event type,
|
|
1584
|
+
* ensuring that no further notifications are sent to the callback function.
|
|
1585
|
+
*
|
|
1586
|
+
* @param eventType - The type of event to stop listening for.
|
|
1587
|
+
* @param playbackId - The unique ID of the playback associated with the listener.
|
|
1588
|
+
* @param callback - The callback function to remove from the listener.
|
|
1589
|
+
*/
|
|
1590
|
+
unregisterPlaybackListener(eventType, playbackId, callback) {
|
|
1591
|
+
this.playbacks.unregisterListener(eventType, playbackId, callback);
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* Registers a listener for playback events.
|
|
1595
|
+
* The listener is triggered for events such as "PlaybackFinished".
|
|
1596
|
+
*
|
|
1597
|
+
* @param eventType - The type of event to listen for.
|
|
1598
|
+
* @param playbackId - The ID of the playback to associate with this listener.
|
|
1599
|
+
* @param callback - The callback function to execute when the event occurs.
|
|
1600
|
+
*/
|
|
1601
|
+
registerPlaybackListener(eventType, playbackId, callback) {
|
|
1602
|
+
this.playbacks.registerListener(eventType, playbackId, callback);
|
|
1603
|
+
}
|
|
1604
|
+
/**
|
|
1605
|
+
* Checks if a listener is already registered for a specific event and playback.
|
|
1606
|
+
*
|
|
1607
|
+
* @param eventType - The type of event to check.
|
|
1608
|
+
* @param playbackId - The playback ID associated with the listener.
|
|
1609
|
+
* @returns True if a listener is already registered, false otherwise.
|
|
1610
|
+
*/
|
|
1611
|
+
isPlaybackListenerRegistered(eventType, playbackId) {
|
|
1612
|
+
return this.playbacks.isListenerRegistered(eventType, playbackId);
|
|
1613
|
+
}
|
|
1424
1614
|
/**
|
|
1425
1615
|
* Ensures the ARI application is registered.
|
|
1426
1616
|
*
|
|
@@ -1452,23 +1642,72 @@ var AriClient = class {
|
|
|
1452
1642
|
return this.wsClient ? this.wsClient.isConnected() : false;
|
|
1453
1643
|
}
|
|
1454
1644
|
/**
|
|
1455
|
-
* Registers a
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1645
|
+
* Registers a listener for WebSocket events.
|
|
1646
|
+
*
|
|
1647
|
+
* This function allows you to attach a callback function to a specific WebSocket event type.
|
|
1648
|
+
* The callback will be executed whenever an event of the specified type is received.
|
|
1649
|
+
*
|
|
1650
|
+
* @template T - The type of WebSocket event, extending WebSocketEvent["type"].
|
|
1651
|
+
* @param {T} event - The type of WebSocket event to listen for.
|
|
1652
|
+
* @param {(data: Extract<WebSocketEvent, { type: T }>) => void} callback - The function to be called when the event is received.
|
|
1653
|
+
* The callback receives the event data as its parameter.
|
|
1654
|
+
* @throws {Error} Throws an error if the WebSocket client is not connected when this method is called.
|
|
1655
|
+
* @returns {void} This function doesn't return a value.
|
|
1656
|
+
*/
|
|
1657
|
+
onWebSocketEvent(event, callback) {
|
|
1658
|
+
if (!this.wsClient) {
|
|
1659
|
+
throw new Error("WebSocket n\xE3o est\xE1 conectado.");
|
|
1660
|
+
}
|
|
1661
|
+
this.wsClient.on(event, callback);
|
|
1662
|
+
}
|
|
1663
|
+
/**
|
|
1664
|
+
* Removes a specific listener for WebSocket events.
|
|
1665
|
+
*
|
|
1666
|
+
* This function unregisters a previously registered callback function for a specific WebSocket event type.
|
|
1667
|
+
* It's useful for removing event handlers when they are no longer needed or for cleaning up resources.
|
|
1668
|
+
*
|
|
1669
|
+
* @template T - The type of WebSocket event, extending WebSocketEvent["type"].
|
|
1670
|
+
* @param {T} event - The type of WebSocket event to remove the listener from.
|
|
1671
|
+
* @param {(data: Extract<WebSocketEvent, { type: T }>) => void} callback - The callback function to be removed.
|
|
1672
|
+
* This should be the same function reference that was used when adding the event listener.
|
|
1673
|
+
* @throws {Error} Throws an error if the WebSocket client is not connected when this method is called.
|
|
1674
|
+
* @returns {void} This function doesn't return a value.
|
|
1675
|
+
*/
|
|
1676
|
+
offWebSocketEvent(event, callback) {
|
|
1677
|
+
if (!this.wsClient) {
|
|
1678
|
+
throw new Error("WebSocket n\xE3o est\xE1 conectado.");
|
|
1679
|
+
}
|
|
1680
|
+
this.wsClient.off(event, callback);
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Removes all listeners for a specific WebSocket event type.
|
|
1458
1684
|
*
|
|
1459
|
-
*
|
|
1460
|
-
*
|
|
1461
|
-
*
|
|
1462
|
-
*
|
|
1685
|
+
* This function removes all event listeners that have been registered for a particular
|
|
1686
|
+
* WebSocket event type. It's useful for cleaning up event listeners when they are no
|
|
1687
|
+
* longer needed or before re-registering new listeners.
|
|
1688
|
+
*
|
|
1689
|
+
* @param event - The type of WebSocket event for which all listeners should be removed.
|
|
1690
|
+
* This should be a string identifying the event type (e.g., 'message', 'close', etc.).
|
|
1691
|
+
*
|
|
1692
|
+
* @throws {Error} Throws an error if the WebSocket client is not connected when this method is called.
|
|
1693
|
+
*
|
|
1694
|
+
* @returns {void} This function doesn't return a value.
|
|
1463
1695
|
*/
|
|
1464
|
-
|
|
1696
|
+
removeAllWebSocketListeners(event) {
|
|
1465
1697
|
if (!this.wsClient) {
|
|
1466
|
-
throw new Error("WebSocket
|
|
1698
|
+
throw new Error("WebSocket n\xE3o est\xE1 conectado.");
|
|
1467
1699
|
}
|
|
1468
|
-
this.wsClient.
|
|
1700
|
+
this.wsClient.removeAllListeners(event);
|
|
1469
1701
|
}
|
|
1470
1702
|
/**
|
|
1471
|
-
* Closes the WebSocket connection.
|
|
1703
|
+
* Closes the WebSocket connection and removes all associated listeners.
|
|
1704
|
+
*
|
|
1705
|
+
* This function terminates the active WebSocket connection if one exists,
|
|
1706
|
+
* and cleans up by removing all event listeners attached to it. After calling
|
|
1707
|
+
* this function, the WebSocket client will be set to null, effectively
|
|
1708
|
+
* ending the connection and preparing for potential future connections.
|
|
1709
|
+
*
|
|
1710
|
+
* @returns {void} This function doesn't return a value.
|
|
1472
1711
|
*/
|
|
1473
1712
|
closeWebSocket() {
|
|
1474
1713
|
if (this.wsClient) {
|
|
@@ -1879,20 +2118,20 @@ var AriClient = class {
|
|
|
1879
2118
|
return this.playbacks.getDetails(playbackId);
|
|
1880
2119
|
}
|
|
1881
2120
|
/**
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
2121
|
+
* Controls a specific playback in the Asterisk server.
|
|
2122
|
+
* This function allows manipulation of an ongoing playback, such as pausing, resuming, or skipping.
|
|
2123
|
+
*
|
|
2124
|
+
* @param playbackId - The unique identifier of the playback to control.
|
|
2125
|
+
* This should be a string that uniquely identifies the playback in the Asterisk system.
|
|
2126
|
+
* @param controlRequest - An object containing the control operation details.
|
|
2127
|
+
* This object should conform to the PlaybackControlRequest interface,
|
|
2128
|
+
* which includes an 'operation' property specifying the control action to perform.
|
|
2129
|
+
* @returns A Promise that resolves when the control operation is successfully executed.
|
|
2130
|
+
* The promise resolves to void, indicating no specific return value.
|
|
2131
|
+
* If an error occurs during the operation, the promise will be rejected with an error object.
|
|
2132
|
+
* @throws Will throw an error if the playback control operation fails, e.g., if the playback doesn't exist
|
|
2133
|
+
* or the requested operation is invalid.
|
|
2134
|
+
*/
|
|
1896
2135
|
async controlPlayback(playbackId, controlRequest) {
|
|
1897
2136
|
const { operation } = controlRequest;
|
|
1898
2137
|
return this.playbacks.control(playbackId, operation);
|