@ipcom/asterisk-ari 0.0.119 → 0.0.121
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 +45 -29
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +45 -29
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/ariClient.d.ts +3 -0
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1961,7 +1961,6 @@ var WebSocketClient = class extends import_events3.EventEmitter {
|
|
|
1961
1961
|
handleMessage(rawData) {
|
|
1962
1962
|
try {
|
|
1963
1963
|
const decodedData = JSON.parse(rawData.toString());
|
|
1964
|
-
console.log({ tipo: decodedData?.type });
|
|
1965
1964
|
if (decodedData?.type && decodedData?.application) {
|
|
1966
1965
|
const scopedEvent = `${decodedData.application}:${decodedData.type}`;
|
|
1967
1966
|
if ("channel" in decodedData && decodedData.channel?.id) {
|
|
@@ -2033,6 +2032,7 @@ var AriClient = class {
|
|
|
2033
2032
|
this.asterisk = new Asterisk(this.baseClient);
|
|
2034
2033
|
this.bridges = new Bridges(this.baseClient);
|
|
2035
2034
|
}
|
|
2035
|
+
scopedListeners = /* @__PURE__ */ new Map();
|
|
2036
2036
|
eventListeners = /* @__PURE__ */ new Map();
|
|
2037
2037
|
wsClients = /* @__PURE__ */ new Map();
|
|
2038
2038
|
// Map para armazenar conexões por app
|
|
@@ -2083,49 +2083,53 @@ var AriClient = class {
|
|
|
2083
2083
|
getWebSocketClients() {
|
|
2084
2084
|
return this.wsClients;
|
|
2085
2085
|
}
|
|
2086
|
+
addScopedListener(app, eventType, instanceId, callback) {
|
|
2087
|
+
const key = `${app}:${instanceId}:${eventType}`;
|
|
2088
|
+
if (this.scopedListeners.has(key)) {
|
|
2089
|
+
console.warn(`Listener escopado j\xE1 registrado para '${key}'.`);
|
|
2090
|
+
return;
|
|
2091
|
+
}
|
|
2092
|
+
const scopedListener = (data) => {
|
|
2093
|
+
if (data.application === app && (data.type.startsWith("Channel") && "channel" in data && data.channel?.id === instanceId || data.type.startsWith("Playback") && "playbackId" in data && data.playbackId === instanceId)) {
|
|
2094
|
+
callback(data);
|
|
2095
|
+
}
|
|
2096
|
+
};
|
|
2097
|
+
this.scopedListeners.set(key, scopedListener);
|
|
2098
|
+
const wsClient = this.wsClients.get(app);
|
|
2099
|
+
wsClient?.on(eventType, scopedListener);
|
|
2100
|
+
console.log(`Listener escopado adicionado para '${key}'.`);
|
|
2101
|
+
}
|
|
2102
|
+
removeScopedListener(app, eventType, instanceId) {
|
|
2103
|
+
const key = `${app}:${instanceId}:${eventType}`;
|
|
2104
|
+
const scopedListener = this.scopedListeners.get(key);
|
|
2105
|
+
if (scopedListener) {
|
|
2106
|
+
const wsClient = this.wsClients.get(app);
|
|
2107
|
+
wsClient?.off(eventType, scopedListener);
|
|
2108
|
+
this.scopedListeners.delete(key);
|
|
2109
|
+
console.log(`Listener escopado removido para '${key}'.`);
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2086
2112
|
/**
|
|
2087
2113
|
* Registra listeners globais para eventos de WebSocket.
|
|
2088
2114
|
*/
|
|
2089
2115
|
on(eventType, callback, app) {
|
|
2090
2116
|
if (!app) {
|
|
2091
2117
|
throw new Error(
|
|
2092
|
-
"O nome do app \xE9 obrigat\xF3rio para registrar um listener
|
|
2118
|
+
"O nome do app \xE9 obrigat\xF3rio para registrar um listener."
|
|
2093
2119
|
);
|
|
2094
2120
|
}
|
|
2095
|
-
console.log(
|
|
2096
|
-
`Registrando listener para evento '${eventType}' no app '${app}'.`
|
|
2097
|
-
);
|
|
2098
2121
|
const callbackKey = `${app}:${eventType}`;
|
|
2099
2122
|
if (this.eventListeners.has(callbackKey)) {
|
|
2100
|
-
console.log(
|
|
2101
|
-
`Listener para evento '${eventType}' j\xE1 est\xE1 registrado no app '${app}'. Ignorando duplicata.`
|
|
2102
|
-
);
|
|
2123
|
+
console.log(`Listener j\xE1 registrado para '${callbackKey}'. Ignorando.`);
|
|
2103
2124
|
return;
|
|
2104
2125
|
}
|
|
2105
|
-
const wrappedCallback = (event) => {
|
|
2106
|
-
if (isChannelEvent(event)) {
|
|
2107
|
-
const channelId = event.channel.id;
|
|
2108
|
-
if (channelId) {
|
|
2109
|
-
if (!this.channelInstances.has(channelId)) {
|
|
2110
|
-
const channelInstance = this.createChannelInstance(channelId, app);
|
|
2111
|
-
this.channelInstances.set(channelId, channelInstance);
|
|
2112
|
-
}
|
|
2113
|
-
event.instanceChannel = this.channelInstances.get(channelId);
|
|
2114
|
-
event.instanceChannel?.emit(event.type, event);
|
|
2115
|
-
}
|
|
2116
|
-
}
|
|
2117
|
-
callback(event);
|
|
2118
|
-
};
|
|
2119
2126
|
const wsClient = this.wsClients.get(app);
|
|
2120
2127
|
if (wsClient) {
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
console.log(
|
|
2125
|
-
`Listener para evento '${eventType}' registrado com sucesso no app '${app}'.`
|
|
2126
|
-
);
|
|
2128
|
+
wsClient.on(eventType, callback);
|
|
2129
|
+
this.eventListeners.set(callbackKey, callback);
|
|
2130
|
+
console.log(`Listener registrado para '${callbackKey}'.`);
|
|
2127
2131
|
} else {
|
|
2128
|
-
console.warn(`WebSocket para
|
|
2132
|
+
console.warn(`WebSocket para '${app}' n\xE3o est\xE1 conectado.`);
|
|
2129
2133
|
}
|
|
2130
2134
|
}
|
|
2131
2135
|
removeListener(eventType, app) {
|
|
@@ -2237,6 +2241,11 @@ var AriClient = class {
|
|
|
2237
2241
|
if (!app) {
|
|
2238
2242
|
throw new Error("O nome do aplicativo \xE9 obrigat\xF3rio.");
|
|
2239
2243
|
}
|
|
2244
|
+
console.log(`Conectando WebSocket para o app '${app}'...`);
|
|
2245
|
+
if (this.wsClients.has(app)) {
|
|
2246
|
+
console.log(`WebSocket para '${app}' j\xE1 est\xE1 conectado.`);
|
|
2247
|
+
return;
|
|
2248
|
+
}
|
|
2240
2249
|
if (this.webSocketReady.get(app)) {
|
|
2241
2250
|
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1 est\xE1 ativa.`);
|
|
2242
2251
|
return this.webSocketReady.get(app);
|
|
@@ -2304,16 +2313,22 @@ var AriClient = class {
|
|
|
2304
2313
|
return;
|
|
2305
2314
|
}
|
|
2306
2315
|
const eventHandlers = {
|
|
2316
|
+
StasisStart: (data) => {
|
|
2317
|
+
console.log(`[${app}] Evento 'StasisStart' recebido:`, data);
|
|
2318
|
+
},
|
|
2307
2319
|
PlaybackStarted: (data) => {
|
|
2308
2320
|
if ("playbackId" in data) {
|
|
2321
|
+
console.log(`[${app}] PlaybackStarted:`, data);
|
|
2309
2322
|
}
|
|
2310
2323
|
},
|
|
2311
2324
|
PlaybackFinished: (data) => {
|
|
2312
2325
|
if ("playbackId" in data) {
|
|
2326
|
+
console.log(`[${app}] PlaybackFinished:`, data);
|
|
2313
2327
|
}
|
|
2314
2328
|
},
|
|
2315
2329
|
ChannelDtmfReceived: (data) => {
|
|
2316
2330
|
if (data.type === "ChannelDtmfReceived" && "digit" in data) {
|
|
2331
|
+
console.log(`[${app}] DTMF recebido: ${data.digit}`);
|
|
2317
2332
|
} else {
|
|
2318
2333
|
console.warn(
|
|
2319
2334
|
`[${app}] Evento inesperado em ChannelDtmfReceived`,
|
|
@@ -2323,6 +2338,7 @@ var AriClient = class {
|
|
|
2323
2338
|
},
|
|
2324
2339
|
ChannelStateChange: (data) => {
|
|
2325
2340
|
if ("channel" in data) {
|
|
2341
|
+
console.log(`[${app}] Estado do canal alterado:`, data.channel);
|
|
2326
2342
|
}
|
|
2327
2343
|
}
|
|
2328
2344
|
};
|