@ipcom/asterisk-ari 0.0.104 → 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 +66 -66
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +66 -66
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- 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/cjs/index.cjs
CHANGED
|
@@ -977,54 +977,46 @@ var ChannelInstance = class extends import_events2.EventEmitter {
|
|
|
977
977
|
* Adiciona um listener para eventos de canal.
|
|
978
978
|
*/
|
|
979
979
|
on(event, callback) {
|
|
980
|
-
|
|
980
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
981
|
+
if (!wsClient) {
|
|
982
|
+
throw new Error(
|
|
983
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
987
|
+
wsClient.on(scopedEvent, callback);
|
|
981
988
|
return this;
|
|
982
989
|
}
|
|
983
990
|
/**
|
|
984
991
|
* Adiciona um listener para ser chamado apenas uma vez.
|
|
985
992
|
*/
|
|
986
993
|
once(event, callback) {
|
|
987
|
-
|
|
988
|
-
type: "Adiciona um listener para ser chamado apenas uma vez",
|
|
989
|
-
event
|
|
990
|
-
});
|
|
991
|
-
const wsClients = this.client.getWebSocketClients();
|
|
992
|
-
const wsClient = Array.from(wsClients.values()).find(
|
|
993
|
-
(client) => client.isConnected()
|
|
994
|
-
);
|
|
994
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
995
995
|
if (!wsClient) {
|
|
996
996
|
throw new Error(
|
|
997
|
-
`Nenhum WebSocket conectado dispon\xEDvel para '${this.
|
|
997
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
998
998
|
);
|
|
999
999
|
}
|
|
1000
|
-
const
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
callback(webSocketEvent);
|
|
1005
|
-
wsClient.removeScopedMessageListeners(this.id, this.app);
|
|
1006
|
-
console.log(
|
|
1007
|
-
`Listeners escopados para canal '${this.id}' foram removidos.`
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1000
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
1001
|
+
const listener = (data) => {
|
|
1002
|
+
callback(data);
|
|
1003
|
+
wsClient.off(scopedEvent, listener);
|
|
1010
1004
|
};
|
|
1011
|
-
|
|
1012
|
-
wsClient.addScopedMessageListener(this.id, this.app, globalListener);
|
|
1013
|
-
} catch (error) {
|
|
1014
|
-
console.error(
|
|
1015
|
-
`Erro ao adicionar listener escopado em 'once' para canal '${this.id}':`,
|
|
1016
|
-
error
|
|
1017
|
-
);
|
|
1018
|
-
throw error;
|
|
1019
|
-
}
|
|
1020
|
-
super.once(event, callback);
|
|
1005
|
+
wsClient.on(scopedEvent, listener);
|
|
1021
1006
|
return this;
|
|
1022
1007
|
}
|
|
1023
1008
|
/**
|
|
1024
1009
|
* Remove um listener específico.
|
|
1025
1010
|
*/
|
|
1026
1011
|
off(event, callback) {
|
|
1027
|
-
|
|
1012
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
1013
|
+
if (!wsClient) {
|
|
1014
|
+
throw new Error(
|
|
1015
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
1018
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
1019
|
+
wsClient.off(scopedEvent, callback);
|
|
1028
1020
|
return this;
|
|
1029
1021
|
}
|
|
1030
1022
|
async answer() {
|
|
@@ -1500,55 +1492,50 @@ var PlaybackInstance = class extends import_events3.EventEmitter {
|
|
|
1500
1492
|
/**
|
|
1501
1493
|
* Adiciona um listener para eventos de playback.
|
|
1502
1494
|
*/
|
|
1495
|
+
/**
|
|
1496
|
+
* Adiciona um listener para eventos de playback.
|
|
1497
|
+
*/
|
|
1503
1498
|
on(event, callback) {
|
|
1504
|
-
|
|
1499
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
1500
|
+
if (!wsClient) {
|
|
1501
|
+
throw new Error(
|
|
1502
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
const scopedEvent = `${this.app}:Playback:${this.id}:${event}`;
|
|
1506
|
+
wsClient.on(scopedEvent, callback);
|
|
1505
1507
|
return this;
|
|
1506
1508
|
}
|
|
1507
1509
|
/**
|
|
1508
1510
|
* Adiciona um listener para ser chamado apenas uma vez.
|
|
1509
1511
|
*/
|
|
1510
1512
|
once(event, callback) {
|
|
1511
|
-
|
|
1512
|
-
type: "Adiciona um listener para ser chamado apenas uma vez",
|
|
1513
|
-
event
|
|
1514
|
-
});
|
|
1515
|
-
const wsClients = this.client.getWebSocketClients();
|
|
1516
|
-
const wsClient = Array.from(wsClients.values()).find(
|
|
1517
|
-
(client) => client.isConnected()
|
|
1518
|
-
);
|
|
1513
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
1519
1514
|
if (!wsClient) {
|
|
1520
1515
|
throw new Error(
|
|
1521
|
-
`Nenhum WebSocket conectado dispon\xEDvel para '${this.
|
|
1516
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
1522
1517
|
);
|
|
1523
1518
|
}
|
|
1524
|
-
const
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
callback(webSocketEvent);
|
|
1529
|
-
wsClient.removeScopedMessageListeners(this.id, this.app);
|
|
1530
|
-
console.log(
|
|
1531
|
-
`Listeners escopados para playback '${this.id}' foram removidos.`
|
|
1532
|
-
);
|
|
1533
|
-
}
|
|
1519
|
+
const scopedEvent = `${this.app}:Playback:${this.id}:${event}`;
|
|
1520
|
+
const listener = (data) => {
|
|
1521
|
+
callback(data);
|
|
1522
|
+
wsClient.off(scopedEvent, listener);
|
|
1534
1523
|
};
|
|
1535
|
-
|
|
1536
|
-
wsClient.addScopedMessageListener(this.id, this.app, globalListener);
|
|
1537
|
-
} catch (error) {
|
|
1538
|
-
console.error(
|
|
1539
|
-
`Erro ao adicionar listener escopado em 'once' para playback '${this.id}':`,
|
|
1540
|
-
error
|
|
1541
|
-
);
|
|
1542
|
-
throw error;
|
|
1543
|
-
}
|
|
1544
|
-
super.once(event, callback);
|
|
1524
|
+
wsClient.on(scopedEvent, listener);
|
|
1545
1525
|
return this;
|
|
1546
1526
|
}
|
|
1547
1527
|
/**
|
|
1548
1528
|
* Remove um listener específico.
|
|
1549
1529
|
*/
|
|
1550
1530
|
off(event, callback) {
|
|
1551
|
-
|
|
1531
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
1532
|
+
if (!wsClient) {
|
|
1533
|
+
throw new Error(
|
|
1534
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1537
|
+
const scopedEvent = `${this.app}:Playback:${this.id}:${event}`;
|
|
1538
|
+
wsClient.off(scopedEvent, callback);
|
|
1552
1539
|
return this;
|
|
1553
1540
|
}
|
|
1554
1541
|
/**
|
|
@@ -1947,8 +1934,17 @@ var WebSocketClient = class extends import_events4.EventEmitter {
|
|
|
1947
1934
|
try {
|
|
1948
1935
|
const decodedData = JSON.parse(rawData.toString());
|
|
1949
1936
|
if (decodedData?.type && decodedData?.application) {
|
|
1950
|
-
|
|
1951
|
-
|
|
1937
|
+
const scopedEvent = `${decodedData.application}:${decodedData.type}`;
|
|
1938
|
+
if ("channel" in decodedData && decodedData.channel?.id) {
|
|
1939
|
+
const channelScopedEvent = `${decodedData.application}:Channel:${decodedData.channel.id}:${decodedData.type}`;
|
|
1940
|
+
console.log({ handleMessage: decodedData });
|
|
1941
|
+
this.emit(channelScopedEvent, decodedData);
|
|
1942
|
+
} else if ("playback" in decodedData && decodedData.playback?.id) {
|
|
1943
|
+
const playbackScopedEvent = `${decodedData.application}:Playback:${decodedData.playback.id}:${decodedData.type}`;
|
|
1944
|
+
console.log({ handleMessage: decodedData });
|
|
1945
|
+
this.emit(playbackScopedEvent, decodedData);
|
|
1946
|
+
}
|
|
1947
|
+
this.emit(scopedEvent, decodedData);
|
|
1952
1948
|
} else {
|
|
1953
1949
|
console.warn(
|
|
1954
1950
|
"Mensagem recebida sem tipo ou aplica\xE7\xE3o v\xE1lida:",
|
|
@@ -2071,7 +2067,7 @@ var AriClient = class {
|
|
|
2071
2067
|
console.log(
|
|
2072
2068
|
`Registrando listener para evento '${eventType}' no app '${app}'.`
|
|
2073
2069
|
);
|
|
2074
|
-
const callbackKey = `${
|
|
2070
|
+
const callbackKey = `${app}:${eventType}`;
|
|
2075
2071
|
if (this.eventListeners.has(callbackKey)) {
|
|
2076
2072
|
console.log(
|
|
2077
2073
|
`Listener para evento '${eventType}' j\xE1 est\xE1 registrado no app '${app}'. Ignorando duplicata.`
|
|
@@ -2094,8 +2090,12 @@ var AriClient = class {
|
|
|
2094
2090
|
};
|
|
2095
2091
|
const wsClient = this.wsClients.get(app);
|
|
2096
2092
|
if (wsClient) {
|
|
2097
|
-
|
|
2093
|
+
const scopedEvent = `${app}:${eventType}`;
|
|
2094
|
+
wsClient.on(scopedEvent, wrappedCallback);
|
|
2098
2095
|
this.eventListeners.set(callbackKey, wrappedCallback);
|
|
2096
|
+
console.log(
|
|
2097
|
+
`Listener para evento '${eventType}' registrado com sucesso no app '${app}'.`
|
|
2098
|
+
);
|
|
2099
2099
|
} else {
|
|
2100
2100
|
console.warn(`WebSocket para o app '${app}' n\xE3o est\xE1 conectado.`);
|
|
2101
2101
|
}
|