@ipcom/asterisk-ari 0.0.121 → 0.0.123
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 -55
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/esm/index.js +45 -55
- package/dist/esm/index.js.map +2 -2
- package/dist/types/ari-client/ariClient.d.ts +0 -4
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts +1 -0
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1846,9 +1846,18 @@ var WebSocketClient = class extends import_events3.EventEmitter {
|
|
|
1846
1846
|
"message"
|
|
1847
1847
|
)} listener(s).`
|
|
1848
1848
|
);
|
|
1849
|
+
this.listListeners("message");
|
|
1849
1850
|
}
|
|
1850
1851
|
return this;
|
|
1851
1852
|
}
|
|
1853
|
+
listListeners(event) {
|
|
1854
|
+
const listeners = this.listeners(event);
|
|
1855
|
+
console.log(`=== Listagem de Listeners para '${event}' ===`);
|
|
1856
|
+
listeners.forEach((listener, index) => {
|
|
1857
|
+
console.log(`Listener #${index + 1}:`, listener.toString());
|
|
1858
|
+
});
|
|
1859
|
+
console.log(`Total de listeners para '${event}': ${listeners.length}`);
|
|
1860
|
+
}
|
|
1852
1861
|
/**
|
|
1853
1862
|
* Removes a specific listener from a WebSocket event.
|
|
1854
1863
|
* @param event - The event type to remove the listener from.
|
|
@@ -1928,6 +1937,7 @@ var WebSocketClient = class extends import_events3.EventEmitter {
|
|
|
1928
1937
|
"message"
|
|
1929
1938
|
)}`
|
|
1930
1939
|
);
|
|
1940
|
+
this.listListeners("message");
|
|
1931
1941
|
}
|
|
1932
1942
|
/**
|
|
1933
1943
|
* Remove todos os listeners associados a uma instância específica.
|
|
@@ -2032,7 +2042,6 @@ var AriClient = class {
|
|
|
2032
2042
|
this.asterisk = new Asterisk(this.baseClient);
|
|
2033
2043
|
this.bridges = new Bridges(this.baseClient);
|
|
2034
2044
|
}
|
|
2035
|
-
scopedListeners = /* @__PURE__ */ new Map();
|
|
2036
2045
|
eventListeners = /* @__PURE__ */ new Map();
|
|
2037
2046
|
wsClients = /* @__PURE__ */ new Map();
|
|
2038
2047
|
// Map para armazenar conexões por app
|
|
@@ -2062,16 +2071,6 @@ var AriClient = class {
|
|
|
2062
2071
|
}
|
|
2063
2072
|
}
|
|
2064
2073
|
}
|
|
2065
|
-
async reconnectWebSocket(app) {
|
|
2066
|
-
console.log(`Tentando reconectar o WebSocket para o app '${app}'...`);
|
|
2067
|
-
try {
|
|
2068
|
-
await this.connectSingleWebSocket(app);
|
|
2069
|
-
this.processPendingListeners();
|
|
2070
|
-
console.log(`Reconex\xE3o bem-sucedida para o app '${app}'.`);
|
|
2071
|
-
} catch (error) {
|
|
2072
|
-
console.error(`Erro ao reconectar o WebSocket para '${app}':`, error);
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
2074
|
channels;
|
|
2076
2075
|
endpoints;
|
|
2077
2076
|
applications;
|
|
@@ -2083,53 +2082,49 @@ var AriClient = class {
|
|
|
2083
2082
|
getWebSocketClients() {
|
|
2084
2083
|
return this.wsClients;
|
|
2085
2084
|
}
|
|
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
|
-
}
|
|
2112
2085
|
/**
|
|
2113
2086
|
* Registra listeners globais para eventos de WebSocket.
|
|
2114
2087
|
*/
|
|
2115
2088
|
on(eventType, callback, app) {
|
|
2116
2089
|
if (!app) {
|
|
2117
2090
|
throw new Error(
|
|
2118
|
-
"O nome do app \xE9 obrigat\xF3rio para registrar um listener."
|
|
2091
|
+
"O nome do app \xE9 obrigat\xF3rio para registrar um listener de evento."
|
|
2119
2092
|
);
|
|
2120
2093
|
}
|
|
2094
|
+
console.log(
|
|
2095
|
+
`Registrando listener para evento '${eventType}' no app '${app}'.`
|
|
2096
|
+
);
|
|
2121
2097
|
const callbackKey = `${app}:${eventType}`;
|
|
2122
2098
|
if (this.eventListeners.has(callbackKey)) {
|
|
2123
|
-
console.log(
|
|
2099
|
+
console.log(
|
|
2100
|
+
`Listener para evento '${eventType}' j\xE1 est\xE1 registrado no app '${app}'. Ignorando duplicata.`
|
|
2101
|
+
);
|
|
2124
2102
|
return;
|
|
2125
2103
|
}
|
|
2104
|
+
const wrappedCallback = (event) => {
|
|
2105
|
+
if (isChannelEvent(event)) {
|
|
2106
|
+
const channelId = event.channel.id;
|
|
2107
|
+
if (channelId) {
|
|
2108
|
+
if (!this.channelInstances.has(channelId)) {
|
|
2109
|
+
const channelInstance = this.createChannelInstance(channelId, app);
|
|
2110
|
+
this.channelInstances.set(channelId, channelInstance);
|
|
2111
|
+
}
|
|
2112
|
+
event.instanceChannel = this.channelInstances.get(channelId);
|
|
2113
|
+
event.instanceChannel?.emit(event.type, event);
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
callback(event);
|
|
2117
|
+
};
|
|
2126
2118
|
const wsClient = this.wsClients.get(app);
|
|
2127
2119
|
if (wsClient) {
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2120
|
+
const scopedEvent = `${app}:${eventType}`;
|
|
2121
|
+
wsClient.on(scopedEvent, wrappedCallback);
|
|
2122
|
+
this.eventListeners.set(callbackKey, wrappedCallback);
|
|
2123
|
+
console.log(
|
|
2124
|
+
`Listener para evento '${eventType}' registrado com sucesso no app '${app}'.`
|
|
2125
|
+
);
|
|
2131
2126
|
} else {
|
|
2132
|
-
console.warn(`WebSocket para '${app}' n\xE3o est\xE1 conectado.`);
|
|
2127
|
+
console.warn(`WebSocket para o app '${app}' n\xE3o est\xE1 conectado.`);
|
|
2133
2128
|
}
|
|
2134
2129
|
}
|
|
2135
2130
|
removeListener(eventType, app) {
|
|
@@ -2241,11 +2236,6 @@ var AriClient = class {
|
|
|
2241
2236
|
if (!app) {
|
|
2242
2237
|
throw new Error("O nome do aplicativo \xE9 obrigat\xF3rio.");
|
|
2243
2238
|
}
|
|
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
|
-
}
|
|
2249
2239
|
if (this.webSocketReady.get(app)) {
|
|
2250
2240
|
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1 est\xE1 ativa.`);
|
|
2251
2241
|
return this.webSocketReady.get(app);
|
|
@@ -2309,26 +2299,27 @@ var AriClient = class {
|
|
|
2309
2299
|
`WebSocket client para o app '${app}' n\xE3o est\xE1 conectado.`
|
|
2310
2300
|
);
|
|
2311
2301
|
}
|
|
2302
|
+
console.log(
|
|
2303
|
+
"**************** INTEGRANDO EVENTOS DE PLAYBACK **************"
|
|
2304
|
+
);
|
|
2305
|
+
console.log(wsClient.eventNames());
|
|
2306
|
+
console.log(
|
|
2307
|
+
"**************** INTEGRANDO EVENTOS DE PLAYBACK **************"
|
|
2308
|
+
);
|
|
2312
2309
|
if (wsClient.listenerCount("PlaybackStarted") > 0) {
|
|
2313
2310
|
return;
|
|
2314
2311
|
}
|
|
2315
2312
|
const eventHandlers = {
|
|
2316
|
-
StasisStart: (data) => {
|
|
2317
|
-
console.log(`[${app}] Evento 'StasisStart' recebido:`, data);
|
|
2318
|
-
},
|
|
2319
2313
|
PlaybackStarted: (data) => {
|
|
2320
2314
|
if ("playbackId" in data) {
|
|
2321
|
-
console.log(`[${app}] PlaybackStarted:`, data);
|
|
2322
2315
|
}
|
|
2323
2316
|
},
|
|
2324
2317
|
PlaybackFinished: (data) => {
|
|
2325
2318
|
if ("playbackId" in data) {
|
|
2326
|
-
console.log(`[${app}] PlaybackFinished:`, data);
|
|
2327
2319
|
}
|
|
2328
2320
|
},
|
|
2329
2321
|
ChannelDtmfReceived: (data) => {
|
|
2330
2322
|
if (data.type === "ChannelDtmfReceived" && "digit" in data) {
|
|
2331
|
-
console.log(`[${app}] DTMF recebido: ${data.digit}`);
|
|
2332
2323
|
} else {
|
|
2333
2324
|
console.warn(
|
|
2334
2325
|
`[${app}] Evento inesperado em ChannelDtmfReceived`,
|
|
@@ -2338,7 +2329,6 @@ var AriClient = class {
|
|
|
2338
2329
|
},
|
|
2339
2330
|
ChannelStateChange: (data) => {
|
|
2340
2331
|
if ("channel" in data) {
|
|
2341
|
-
console.log(`[${app}] Estado do canal alterado:`, data.channel);
|
|
2342
2332
|
}
|
|
2343
2333
|
}
|
|
2344
2334
|
};
|