@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/esm/index.js
CHANGED
|
@@ -1939,7 +1939,6 @@ var WebSocketClient = class extends EventEmitter3 {
|
|
|
1939
1939
|
handleMessage(rawData) {
|
|
1940
1940
|
try {
|
|
1941
1941
|
const decodedData = JSON.parse(rawData.toString());
|
|
1942
|
-
console.log({ tipo: decodedData?.type });
|
|
1943
1942
|
if (decodedData?.type && decodedData?.application) {
|
|
1944
1943
|
const scopedEvent = `${decodedData.application}:${decodedData.type}`;
|
|
1945
1944
|
if ("channel" in decodedData && decodedData.channel?.id) {
|
|
@@ -2011,6 +2010,7 @@ var AriClient = class {
|
|
|
2011
2010
|
this.asterisk = new Asterisk(this.baseClient);
|
|
2012
2011
|
this.bridges = new Bridges(this.baseClient);
|
|
2013
2012
|
}
|
|
2013
|
+
scopedListeners = /* @__PURE__ */ new Map();
|
|
2014
2014
|
eventListeners = /* @__PURE__ */ new Map();
|
|
2015
2015
|
wsClients = /* @__PURE__ */ new Map();
|
|
2016
2016
|
// Map para armazenar conexões por app
|
|
@@ -2061,49 +2061,53 @@ var AriClient = class {
|
|
|
2061
2061
|
getWebSocketClients() {
|
|
2062
2062
|
return this.wsClients;
|
|
2063
2063
|
}
|
|
2064
|
+
addScopedListener(app, eventType, instanceId, callback) {
|
|
2065
|
+
const key = `${app}:${instanceId}:${eventType}`;
|
|
2066
|
+
if (this.scopedListeners.has(key)) {
|
|
2067
|
+
console.warn(`Listener escopado j\xE1 registrado para '${key}'.`);
|
|
2068
|
+
return;
|
|
2069
|
+
}
|
|
2070
|
+
const scopedListener = (data) => {
|
|
2071
|
+
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)) {
|
|
2072
|
+
callback(data);
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
this.scopedListeners.set(key, scopedListener);
|
|
2076
|
+
const wsClient = this.wsClients.get(app);
|
|
2077
|
+
wsClient?.on(eventType, scopedListener);
|
|
2078
|
+
console.log(`Listener escopado adicionado para '${key}'.`);
|
|
2079
|
+
}
|
|
2080
|
+
removeScopedListener(app, eventType, instanceId) {
|
|
2081
|
+
const key = `${app}:${instanceId}:${eventType}`;
|
|
2082
|
+
const scopedListener = this.scopedListeners.get(key);
|
|
2083
|
+
if (scopedListener) {
|
|
2084
|
+
const wsClient = this.wsClients.get(app);
|
|
2085
|
+
wsClient?.off(eventType, scopedListener);
|
|
2086
|
+
this.scopedListeners.delete(key);
|
|
2087
|
+
console.log(`Listener escopado removido para '${key}'.`);
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2064
2090
|
/**
|
|
2065
2091
|
* Registra listeners globais para eventos de WebSocket.
|
|
2066
2092
|
*/
|
|
2067
2093
|
on(eventType, callback, app) {
|
|
2068
2094
|
if (!app) {
|
|
2069
2095
|
throw new Error(
|
|
2070
|
-
"O nome do app \xE9 obrigat\xF3rio para registrar um listener
|
|
2096
|
+
"O nome do app \xE9 obrigat\xF3rio para registrar um listener."
|
|
2071
2097
|
);
|
|
2072
2098
|
}
|
|
2073
|
-
console.log(
|
|
2074
|
-
`Registrando listener para evento '${eventType}' no app '${app}'.`
|
|
2075
|
-
);
|
|
2076
2099
|
const callbackKey = `${app}:${eventType}`;
|
|
2077
2100
|
if (this.eventListeners.has(callbackKey)) {
|
|
2078
|
-
console.log(
|
|
2079
|
-
`Listener para evento '${eventType}' j\xE1 est\xE1 registrado no app '${app}'. Ignorando duplicata.`
|
|
2080
|
-
);
|
|
2101
|
+
console.log(`Listener j\xE1 registrado para '${callbackKey}'. Ignorando.`);
|
|
2081
2102
|
return;
|
|
2082
2103
|
}
|
|
2083
|
-
const wrappedCallback = (event) => {
|
|
2084
|
-
if (isChannelEvent(event)) {
|
|
2085
|
-
const channelId = event.channel.id;
|
|
2086
|
-
if (channelId) {
|
|
2087
|
-
if (!this.channelInstances.has(channelId)) {
|
|
2088
|
-
const channelInstance = this.createChannelInstance(channelId, app);
|
|
2089
|
-
this.channelInstances.set(channelId, channelInstance);
|
|
2090
|
-
}
|
|
2091
|
-
event.instanceChannel = this.channelInstances.get(channelId);
|
|
2092
|
-
event.instanceChannel?.emit(event.type, event);
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
|
-
callback(event);
|
|
2096
|
-
};
|
|
2097
2104
|
const wsClient = this.wsClients.get(app);
|
|
2098
2105
|
if (wsClient) {
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
console.log(
|
|
2103
|
-
`Listener para evento '${eventType}' registrado com sucesso no app '${app}'.`
|
|
2104
|
-
);
|
|
2106
|
+
wsClient.on(eventType, callback);
|
|
2107
|
+
this.eventListeners.set(callbackKey, callback);
|
|
2108
|
+
console.log(`Listener registrado para '${callbackKey}'.`);
|
|
2105
2109
|
} else {
|
|
2106
|
-
console.warn(`WebSocket para
|
|
2110
|
+
console.warn(`WebSocket para '${app}' n\xE3o est\xE1 conectado.`);
|
|
2107
2111
|
}
|
|
2108
2112
|
}
|
|
2109
2113
|
removeListener(eventType, app) {
|
|
@@ -2215,6 +2219,11 @@ var AriClient = class {
|
|
|
2215
2219
|
if (!app) {
|
|
2216
2220
|
throw new Error("O nome do aplicativo \xE9 obrigat\xF3rio.");
|
|
2217
2221
|
}
|
|
2222
|
+
console.log(`Conectando WebSocket para o app '${app}'...`);
|
|
2223
|
+
if (this.wsClients.has(app)) {
|
|
2224
|
+
console.log(`WebSocket para '${app}' j\xE1 est\xE1 conectado.`);
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2218
2227
|
if (this.webSocketReady.get(app)) {
|
|
2219
2228
|
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1 est\xE1 ativa.`);
|
|
2220
2229
|
return this.webSocketReady.get(app);
|
|
@@ -2282,16 +2291,22 @@ var AriClient = class {
|
|
|
2282
2291
|
return;
|
|
2283
2292
|
}
|
|
2284
2293
|
const eventHandlers = {
|
|
2294
|
+
StasisStart: (data) => {
|
|
2295
|
+
console.log(`[${app}] Evento 'StasisStart' recebido:`, data);
|
|
2296
|
+
},
|
|
2285
2297
|
PlaybackStarted: (data) => {
|
|
2286
2298
|
if ("playbackId" in data) {
|
|
2299
|
+
console.log(`[${app}] PlaybackStarted:`, data);
|
|
2287
2300
|
}
|
|
2288
2301
|
},
|
|
2289
2302
|
PlaybackFinished: (data) => {
|
|
2290
2303
|
if ("playbackId" in data) {
|
|
2304
|
+
console.log(`[${app}] PlaybackFinished:`, data);
|
|
2291
2305
|
}
|
|
2292
2306
|
},
|
|
2293
2307
|
ChannelDtmfReceived: (data) => {
|
|
2294
2308
|
if (data.type === "ChannelDtmfReceived" && "digit" in data) {
|
|
2309
|
+
console.log(`[${app}] DTMF recebido: ${data.digit}`);
|
|
2295
2310
|
} else {
|
|
2296
2311
|
console.warn(
|
|
2297
2312
|
`[${app}] Evento inesperado em ChannelDtmfReceived`,
|
|
@@ -2301,6 +2316,7 @@ var AriClient = class {
|
|
|
2301
2316
|
},
|
|
2302
2317
|
ChannelStateChange: (data) => {
|
|
2303
2318
|
if ("channel" in data) {
|
|
2319
|
+
console.log(`[${app}] Estado do canal alterado:`, data.channel);
|
|
2304
2320
|
}
|
|
2305
2321
|
}
|
|
2306
2322
|
};
|