@ipcom/asterisk-ari 0.0.121 → 0.0.122
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/esm/index.js
CHANGED
|
@@ -2010,7 +2010,6 @@ var AriClient = class {
|
|
|
2010
2010
|
this.asterisk = new Asterisk(this.baseClient);
|
|
2011
2011
|
this.bridges = new Bridges(this.baseClient);
|
|
2012
2012
|
}
|
|
2013
|
-
scopedListeners = /* @__PURE__ */ new Map();
|
|
2014
2013
|
eventListeners = /* @__PURE__ */ new Map();
|
|
2015
2014
|
wsClients = /* @__PURE__ */ new Map();
|
|
2016
2015
|
// Map para armazenar conexões por app
|
|
@@ -2040,16 +2039,6 @@ var AriClient = class {
|
|
|
2040
2039
|
}
|
|
2041
2040
|
}
|
|
2042
2041
|
}
|
|
2043
|
-
async reconnectWebSocket(app) {
|
|
2044
|
-
console.log(`Tentando reconectar o WebSocket para o app '${app}'...`);
|
|
2045
|
-
try {
|
|
2046
|
-
await this.connectSingleWebSocket(app);
|
|
2047
|
-
this.processPendingListeners();
|
|
2048
|
-
console.log(`Reconex\xE3o bem-sucedida para o app '${app}'.`);
|
|
2049
|
-
} catch (error) {
|
|
2050
|
-
console.error(`Erro ao reconectar o WebSocket para '${app}':`, error);
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
2042
|
channels;
|
|
2054
2043
|
endpoints;
|
|
2055
2044
|
applications;
|
|
@@ -2061,53 +2050,49 @@ var AriClient = class {
|
|
|
2061
2050
|
getWebSocketClients() {
|
|
2062
2051
|
return this.wsClients;
|
|
2063
2052
|
}
|
|
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
|
-
}
|
|
2090
2053
|
/**
|
|
2091
2054
|
* Registra listeners globais para eventos de WebSocket.
|
|
2092
2055
|
*/
|
|
2093
2056
|
on(eventType, callback, app) {
|
|
2094
2057
|
if (!app) {
|
|
2095
2058
|
throw new Error(
|
|
2096
|
-
"O nome do app \xE9 obrigat\xF3rio para registrar um listener."
|
|
2059
|
+
"O nome do app \xE9 obrigat\xF3rio para registrar um listener de evento."
|
|
2097
2060
|
);
|
|
2098
2061
|
}
|
|
2062
|
+
console.log(
|
|
2063
|
+
`Registrando listener para evento '${eventType}' no app '${app}'.`
|
|
2064
|
+
);
|
|
2099
2065
|
const callbackKey = `${app}:${eventType}`;
|
|
2100
2066
|
if (this.eventListeners.has(callbackKey)) {
|
|
2101
|
-
console.log(
|
|
2067
|
+
console.log(
|
|
2068
|
+
`Listener para evento '${eventType}' j\xE1 est\xE1 registrado no app '${app}'. Ignorando duplicata.`
|
|
2069
|
+
);
|
|
2102
2070
|
return;
|
|
2103
2071
|
}
|
|
2072
|
+
const wrappedCallback = (event) => {
|
|
2073
|
+
if (isChannelEvent(event)) {
|
|
2074
|
+
const channelId = event.channel.id;
|
|
2075
|
+
if (channelId) {
|
|
2076
|
+
if (!this.channelInstances.has(channelId)) {
|
|
2077
|
+
const channelInstance = this.createChannelInstance(channelId, app);
|
|
2078
|
+
this.channelInstances.set(channelId, channelInstance);
|
|
2079
|
+
}
|
|
2080
|
+
event.instanceChannel = this.channelInstances.get(channelId);
|
|
2081
|
+
event.instanceChannel?.emit(event.type, event);
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
callback(event);
|
|
2085
|
+
};
|
|
2104
2086
|
const wsClient = this.wsClients.get(app);
|
|
2105
2087
|
if (wsClient) {
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2088
|
+
const scopedEvent = `${app}:${eventType}`;
|
|
2089
|
+
wsClient.on(scopedEvent, wrappedCallback);
|
|
2090
|
+
this.eventListeners.set(callbackKey, wrappedCallback);
|
|
2091
|
+
console.log(
|
|
2092
|
+
`Listener para evento '${eventType}' registrado com sucesso no app '${app}'.`
|
|
2093
|
+
);
|
|
2109
2094
|
} else {
|
|
2110
|
-
console.warn(`WebSocket para '${app}' n\xE3o est\xE1 conectado.`);
|
|
2095
|
+
console.warn(`WebSocket para o app '${app}' n\xE3o est\xE1 conectado.`);
|
|
2111
2096
|
}
|
|
2112
2097
|
}
|
|
2113
2098
|
removeListener(eventType, app) {
|
|
@@ -2219,11 +2204,6 @@ var AriClient = class {
|
|
|
2219
2204
|
if (!app) {
|
|
2220
2205
|
throw new Error("O nome do aplicativo \xE9 obrigat\xF3rio.");
|
|
2221
2206
|
}
|
|
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
|
-
}
|
|
2227
2207
|
if (this.webSocketReady.get(app)) {
|
|
2228
2208
|
console.log(`Conex\xE3o WebSocket para '${app}' j\xE1 est\xE1 ativa.`);
|
|
2229
2209
|
return this.webSocketReady.get(app);
|
|
@@ -2287,26 +2267,27 @@ var AriClient = class {
|
|
|
2287
2267
|
`WebSocket client para o app '${app}' n\xE3o est\xE1 conectado.`
|
|
2288
2268
|
);
|
|
2289
2269
|
}
|
|
2270
|
+
console.log(
|
|
2271
|
+
"**************** INTEGRANDO EVENTOS DE PLAYBACK **************"
|
|
2272
|
+
);
|
|
2273
|
+
console.log(wsClient.eventNames());
|
|
2274
|
+
console.log(
|
|
2275
|
+
"**************** INTEGRANDO EVENTOS DE PLAYBACK **************"
|
|
2276
|
+
);
|
|
2290
2277
|
if (wsClient.listenerCount("PlaybackStarted") > 0) {
|
|
2291
2278
|
return;
|
|
2292
2279
|
}
|
|
2293
2280
|
const eventHandlers = {
|
|
2294
|
-
StasisStart: (data) => {
|
|
2295
|
-
console.log(`[${app}] Evento 'StasisStart' recebido:`, data);
|
|
2296
|
-
},
|
|
2297
2281
|
PlaybackStarted: (data) => {
|
|
2298
2282
|
if ("playbackId" in data) {
|
|
2299
|
-
console.log(`[${app}] PlaybackStarted:`, data);
|
|
2300
2283
|
}
|
|
2301
2284
|
},
|
|
2302
2285
|
PlaybackFinished: (data) => {
|
|
2303
2286
|
if ("playbackId" in data) {
|
|
2304
|
-
console.log(`[${app}] PlaybackFinished:`, data);
|
|
2305
2287
|
}
|
|
2306
2288
|
},
|
|
2307
2289
|
ChannelDtmfReceived: (data) => {
|
|
2308
2290
|
if (data.type === "ChannelDtmfReceived" && "digit" in data) {
|
|
2309
|
-
console.log(`[${app}] DTMF recebido: ${data.digit}`);
|
|
2310
2291
|
} else {
|
|
2311
2292
|
console.warn(
|
|
2312
2293
|
`[${app}] Evento inesperado em ChannelDtmfReceived`,
|
|
@@ -2316,7 +2297,6 @@ var AriClient = class {
|
|
|
2316
2297
|
},
|
|
2317
2298
|
ChannelStateChange: (data) => {
|
|
2318
2299
|
if ("channel" in data) {
|
|
2319
|
-
console.log(`[${app}] Estado do canal alterado:`, data.channel);
|
|
2320
2300
|
}
|
|
2321
2301
|
}
|
|
2322
2302
|
};
|