@ipcom/asterisk-ari 0.0.105 → 0.0.106
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 +58 -64
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +58 -64
- 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/resources/playbacks.d.ts +3 -0
- package/dist/types/ari-client/resources/playbacks.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts +2 -6
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -955,54 +955,46 @@ var ChannelInstance = class extends EventEmitter2 {
|
|
|
955
955
|
* Adiciona um listener para eventos de canal.
|
|
956
956
|
*/
|
|
957
957
|
on(event, callback) {
|
|
958
|
-
|
|
958
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
959
|
+
if (!wsClient) {
|
|
960
|
+
throw new Error(
|
|
961
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
962
|
+
);
|
|
963
|
+
}
|
|
964
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
965
|
+
wsClient.on(scopedEvent, callback);
|
|
959
966
|
return this;
|
|
960
967
|
}
|
|
961
968
|
/**
|
|
962
969
|
* Adiciona um listener para ser chamado apenas uma vez.
|
|
963
970
|
*/
|
|
964
971
|
once(event, callback) {
|
|
965
|
-
|
|
966
|
-
type: "Adiciona um listener para ser chamado apenas uma vez",
|
|
967
|
-
event
|
|
968
|
-
});
|
|
969
|
-
const wsClients = this.client.getWebSocketClients();
|
|
970
|
-
const wsClient = Array.from(wsClients.values()).find(
|
|
971
|
-
(client) => client.isConnected()
|
|
972
|
-
);
|
|
972
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
973
973
|
if (!wsClient) {
|
|
974
974
|
throw new Error(
|
|
975
|
-
`Nenhum WebSocket conectado dispon\xEDvel para '${this.
|
|
975
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
976
976
|
);
|
|
977
977
|
}
|
|
978
|
-
const
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
callback(webSocketEvent);
|
|
983
|
-
wsClient.removeScopedMessageListeners(this.id, this.app);
|
|
984
|
-
console.log(
|
|
985
|
-
`Listeners escopados para canal '${this.id}' foram removidos.`
|
|
986
|
-
);
|
|
987
|
-
}
|
|
978
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
979
|
+
const listener = (data) => {
|
|
980
|
+
callback(data);
|
|
981
|
+
wsClient.off(scopedEvent, listener);
|
|
988
982
|
};
|
|
989
|
-
|
|
990
|
-
wsClient.addScopedMessageListener(this.id, this.app, globalListener);
|
|
991
|
-
} catch (error) {
|
|
992
|
-
console.error(
|
|
993
|
-
`Erro ao adicionar listener escopado em 'once' para canal '${this.id}':`,
|
|
994
|
-
error
|
|
995
|
-
);
|
|
996
|
-
throw error;
|
|
997
|
-
}
|
|
998
|
-
super.once(event, callback);
|
|
983
|
+
wsClient.on(scopedEvent, listener);
|
|
999
984
|
return this;
|
|
1000
985
|
}
|
|
1001
986
|
/**
|
|
1002
987
|
* Remove um listener específico.
|
|
1003
988
|
*/
|
|
1004
989
|
off(event, callback) {
|
|
1005
|
-
|
|
990
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
991
|
+
if (!wsClient) {
|
|
992
|
+
throw new Error(
|
|
993
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
994
|
+
);
|
|
995
|
+
}
|
|
996
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
997
|
+
wsClient.off(scopedEvent, callback);
|
|
1006
998
|
return this;
|
|
1007
999
|
}
|
|
1008
1000
|
async answer() {
|
|
@@ -1478,55 +1470,50 @@ var PlaybackInstance = class extends EventEmitter3 {
|
|
|
1478
1470
|
/**
|
|
1479
1471
|
* Adiciona um listener para eventos de playback.
|
|
1480
1472
|
*/
|
|
1473
|
+
/**
|
|
1474
|
+
* Adiciona um listener para eventos de playback.
|
|
1475
|
+
*/
|
|
1481
1476
|
on(event, callback) {
|
|
1482
|
-
|
|
1477
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
1478
|
+
if (!wsClient) {
|
|
1479
|
+
throw new Error(
|
|
1480
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
1481
|
+
);
|
|
1482
|
+
}
|
|
1483
|
+
const scopedEvent = `${this.app}:Playback:${this.id}:${event}`;
|
|
1484
|
+
wsClient.on(scopedEvent, callback);
|
|
1483
1485
|
return this;
|
|
1484
1486
|
}
|
|
1485
1487
|
/**
|
|
1486
1488
|
* Adiciona um listener para ser chamado apenas uma vez.
|
|
1487
1489
|
*/
|
|
1488
1490
|
once(event, callback) {
|
|
1489
|
-
|
|
1490
|
-
type: "Adiciona um listener para ser chamado apenas uma vez",
|
|
1491
|
-
event
|
|
1492
|
-
});
|
|
1493
|
-
const wsClients = this.client.getWebSocketClients();
|
|
1494
|
-
const wsClient = Array.from(wsClients.values()).find(
|
|
1495
|
-
(client) => client.isConnected()
|
|
1496
|
-
);
|
|
1491
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
1497
1492
|
if (!wsClient) {
|
|
1498
1493
|
throw new Error(
|
|
1499
|
-
`Nenhum WebSocket conectado dispon\xEDvel para '${this.
|
|
1494
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
1500
1495
|
);
|
|
1501
1496
|
}
|
|
1502
|
-
const
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
callback(webSocketEvent);
|
|
1507
|
-
wsClient.removeScopedMessageListeners(this.id, this.app);
|
|
1508
|
-
console.log(
|
|
1509
|
-
`Listeners escopados para playback '${this.id}' foram removidos.`
|
|
1510
|
-
);
|
|
1511
|
-
}
|
|
1497
|
+
const scopedEvent = `${this.app}:Playback:${this.id}:${event}`;
|
|
1498
|
+
const listener = (data) => {
|
|
1499
|
+
callback(data);
|
|
1500
|
+
wsClient.off(scopedEvent, listener);
|
|
1512
1501
|
};
|
|
1513
|
-
|
|
1514
|
-
wsClient.addScopedMessageListener(this.id, this.app, globalListener);
|
|
1515
|
-
} catch (error) {
|
|
1516
|
-
console.error(
|
|
1517
|
-
`Erro ao adicionar listener escopado em 'once' para playback '${this.id}':`,
|
|
1518
|
-
error
|
|
1519
|
-
);
|
|
1520
|
-
throw error;
|
|
1521
|
-
}
|
|
1522
|
-
super.once(event, callback);
|
|
1502
|
+
wsClient.on(scopedEvent, listener);
|
|
1523
1503
|
return this;
|
|
1524
1504
|
}
|
|
1525
1505
|
/**
|
|
1526
1506
|
* Remove um listener específico.
|
|
1527
1507
|
*/
|
|
1528
1508
|
off(event, callback) {
|
|
1529
|
-
|
|
1509
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
1510
|
+
if (!wsClient) {
|
|
1511
|
+
throw new Error(
|
|
1512
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
const scopedEvent = `${this.app}:Playback:${this.id}:${event}`;
|
|
1516
|
+
wsClient.off(scopedEvent, callback);
|
|
1530
1517
|
return this;
|
|
1531
1518
|
}
|
|
1532
1519
|
/**
|
|
@@ -1925,10 +1912,17 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1925
1912
|
try {
|
|
1926
1913
|
const decodedData = JSON.parse(rawData.toString());
|
|
1927
1914
|
if (decodedData?.type && decodedData?.application) {
|
|
1928
|
-
console.log({ handleMessage: decodedData });
|
|
1929
1915
|
const scopedEvent = `${decodedData.application}:${decodedData.type}`;
|
|
1916
|
+
if ("channel" in decodedData && decodedData.channel?.id) {
|
|
1917
|
+
const channelScopedEvent = `${decodedData.application}:Channel:${decodedData.channel.id}:${decodedData.type}`;
|
|
1918
|
+
console.log({ handleMessage: decodedData });
|
|
1919
|
+
this.emit(channelScopedEvent, decodedData);
|
|
1920
|
+
} else if ("playback" in decodedData && decodedData.playback?.id) {
|
|
1921
|
+
const playbackScopedEvent = `${decodedData.application}:Playback:${decodedData.playback.id}:${decodedData.type}`;
|
|
1922
|
+
console.log({ handleMessage: decodedData });
|
|
1923
|
+
this.emit(playbackScopedEvent, decodedData);
|
|
1924
|
+
}
|
|
1930
1925
|
this.emit(scopedEvent, decodedData);
|
|
1931
|
-
this.emit(decodedData.application, decodedData);
|
|
1932
1926
|
} else {
|
|
1933
1927
|
console.warn(
|
|
1934
1928
|
"Mensagem recebida sem tipo ou aplica\xE7\xE3o v\xE1lida:",
|