@ipcom/asterisk-ari 0.0.130 → 0.0.132
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
CHANGED
|
@@ -947,17 +947,55 @@ var ChannelInstance = class extends import_events.EventEmitter {
|
|
|
947
947
|
}
|
|
948
948
|
}
|
|
949
949
|
);
|
|
950
|
-
this.
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
console.log(
|
|
954
|
-
`Listeners escopados removidos para canal '${this.id}' no app '${this.app}'.`
|
|
955
|
-
);
|
|
956
|
-
}
|
|
950
|
+
this.once("ChannelDestroyed", () => {
|
|
951
|
+
console.log(`Removendo listeners associados ao canal ${this.id}`);
|
|
952
|
+
this.removeAllScopedListeners();
|
|
957
953
|
});
|
|
958
954
|
}
|
|
955
|
+
scopedListeners = /* @__PURE__ */ new Map();
|
|
959
956
|
channelData = null;
|
|
960
957
|
id;
|
|
958
|
+
addScopedListener(event, callback) {
|
|
959
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
960
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
961
|
+
if (!wsClient) {
|
|
962
|
+
throw new Error(
|
|
963
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
964
|
+
);
|
|
965
|
+
}
|
|
966
|
+
if (!this.scopedListeners.has(scopedEvent)) {
|
|
967
|
+
this.scopedListeners.set(scopedEvent, callback);
|
|
968
|
+
wsClient.on(scopedEvent, callback);
|
|
969
|
+
} else {
|
|
970
|
+
console.warn(`Listener j\xE1 registrado para o evento '${scopedEvent}'.`);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
removeScopedListener(event) {
|
|
974
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
975
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
976
|
+
if (!wsClient) {
|
|
977
|
+
throw new Error(
|
|
978
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
979
|
+
);
|
|
980
|
+
}
|
|
981
|
+
const callback = this.scopedListeners.get(scopedEvent);
|
|
982
|
+
if (callback) {
|
|
983
|
+
wsClient.off(scopedEvent, callback);
|
|
984
|
+
this.scopedListeners.delete(scopedEvent);
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
removeAllScopedListeners() {
|
|
988
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
989
|
+
if (!wsClient) {
|
|
990
|
+
throw new Error(
|
|
991
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
992
|
+
);
|
|
993
|
+
}
|
|
994
|
+
for (const [scopedEvent, callback] of this.scopedListeners.entries()) {
|
|
995
|
+
wsClient.off(scopedEvent, callback);
|
|
996
|
+
}
|
|
997
|
+
this.scopedListeners.clear();
|
|
998
|
+
}
|
|
961
999
|
/**
|
|
962
1000
|
* Adiciona um listener para eventos de canal.
|
|
963
1001
|
*/
|