@ipcom/asterisk-ari 0.0.74 → 0.0.76
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 +15 -16
- package/dist/cjs/index.cjs.map +3 -3
- package/dist/esm/index.js +15 -16
- package/dist/esm/index.js.map +3 -3
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/resources/channels.d.ts +0 -5
- package/dist/types/ari-client/resources/channels.d.ts.map +1 -1
- package/dist/types/ari-client/utils.d.ts +7 -1
- package/dist/types/ari-client/utils.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
|
@@ -287,12 +287,21 @@ function toQueryParams2(options) {
|
|
|
287
287
|
Object.entries(options).filter(([, value]) => value !== void 0).map(([key, value]) => [key, value])
|
|
288
288
|
).toString();
|
|
289
289
|
}
|
|
290
|
-
function isChannelEvent(event) {
|
|
291
|
-
|
|
290
|
+
function isChannelEvent(event, channelId) {
|
|
291
|
+
const hasChannel = "channel" in event && event.channel?.id !== void 0;
|
|
292
|
+
const matchesChannelId = hasChannel && (!channelId || event.channel?.id === channelId);
|
|
293
|
+
if (!hasChannel || channelId && !matchesChannelId) {
|
|
294
|
+
console.log(
|
|
295
|
+
`Evento ignorado no isChannelEvent: tipo=${event.type}, canal esperado=${channelId}, evento recebido=`,
|
|
296
|
+
event
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
return matchesChannelId;
|
|
292
300
|
}
|
|
293
301
|
|
|
294
302
|
// src/ari-client/resources/channels.ts
|
|
295
303
|
var ChannelInstance = class extends EventEmitter2 {
|
|
304
|
+
// ID do canal
|
|
296
305
|
constructor(client, baseClient, channelId = `channel-${Date.now()}`) {
|
|
297
306
|
super();
|
|
298
307
|
this.client = client;
|
|
@@ -305,11 +314,11 @@ var ChannelInstance = class extends EventEmitter2 {
|
|
|
305
314
|
);
|
|
306
315
|
if (!wsClient) {
|
|
307
316
|
throw new Error(
|
|
308
|
-
`Nenhum WebSocket conectado dispon\xEDvel para o canal: ${this.
|
|
317
|
+
`Nenhum WebSocket conectado dispon\xEDvel para o canal: ${this.id}`
|
|
309
318
|
);
|
|
310
319
|
}
|
|
311
320
|
wsClient.on("message", (event) => {
|
|
312
|
-
if (
|
|
321
|
+
if (isChannelEvent(event, this.id)) {
|
|
313
322
|
console.log(`Evento recebido no ChannelInstance: ${event.type}`, event);
|
|
314
323
|
this.emit(event.type, event);
|
|
315
324
|
}
|
|
@@ -317,18 +326,6 @@ var ChannelInstance = class extends EventEmitter2 {
|
|
|
317
326
|
}
|
|
318
327
|
channelData = null;
|
|
319
328
|
id;
|
|
320
|
-
// ID do canal
|
|
321
|
-
/**
|
|
322
|
-
* Verifica se o evento possui a propriedade `channel`.
|
|
323
|
-
* @param event Evento recebido.
|
|
324
|
-
*/
|
|
325
|
-
isChannelEvent(event) {
|
|
326
|
-
const isChannelEvent2 = event && typeof event === "object" && "channel" in event && event.channel?.id === this.channelId;
|
|
327
|
-
if (!isChannelEvent2) {
|
|
328
|
-
console.log(`Evento ignorado no ChannelInstance: ${event.type}`, event);
|
|
329
|
-
}
|
|
330
|
-
return isChannelEvent2;
|
|
331
|
-
}
|
|
332
329
|
/**
|
|
333
330
|
* Adiciona um listener para eventos de canal.
|
|
334
331
|
*/
|
|
@@ -1073,6 +1070,7 @@ var WebSocketClient = class extends EventEmitter4 {
|
|
|
1073
1070
|
const decodedData = JSON.parse(rawData.toString());
|
|
1074
1071
|
if (decodedData?.type) {
|
|
1075
1072
|
this.emit(decodedData.type, decodedData);
|
|
1073
|
+
this.emit("message", decodedData);
|
|
1076
1074
|
} else {
|
|
1077
1075
|
console.warn("Mensagem recebida sem tipo:", decodedData);
|
|
1078
1076
|
}
|
|
@@ -1190,6 +1188,7 @@ var AriClient = class {
|
|
|
1190
1188
|
this.channelInstances.set(channelId, channelInstance);
|
|
1191
1189
|
}
|
|
1192
1190
|
event.instanceChannel = this.channelInstances.get(channelId);
|
|
1191
|
+
event.instanceChannel?.emit(event.type, event);
|
|
1193
1192
|
}
|
|
1194
1193
|
}
|
|
1195
1194
|
callback(event);
|