@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/esm/index.js
CHANGED
|
@@ -925,17 +925,55 @@ var ChannelInstance = class extends EventEmitter {
|
|
|
925
925
|
}
|
|
926
926
|
}
|
|
927
927
|
);
|
|
928
|
-
this.
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
console.log(
|
|
932
|
-
`Listeners escopados removidos para canal '${this.id}' no app '${this.app}'.`
|
|
933
|
-
);
|
|
934
|
-
}
|
|
928
|
+
this.once("ChannelDestroyed", () => {
|
|
929
|
+
console.log(`Removendo listeners associados ao canal ${this.id}`);
|
|
930
|
+
this.removeAllScopedListeners();
|
|
935
931
|
});
|
|
936
932
|
}
|
|
933
|
+
scopedListeners = /* @__PURE__ */ new Map();
|
|
937
934
|
channelData = null;
|
|
938
935
|
id;
|
|
936
|
+
addScopedListener(event, callback) {
|
|
937
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
938
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
939
|
+
if (!wsClient) {
|
|
940
|
+
throw new Error(
|
|
941
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
942
|
+
);
|
|
943
|
+
}
|
|
944
|
+
if (!this.scopedListeners.has(scopedEvent)) {
|
|
945
|
+
this.scopedListeners.set(scopedEvent, callback);
|
|
946
|
+
wsClient.on(scopedEvent, callback);
|
|
947
|
+
} else {
|
|
948
|
+
console.warn(`Listener j\xE1 registrado para o evento '${scopedEvent}'.`);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
removeScopedListener(event) {
|
|
952
|
+
const scopedEvent = `${this.app}:Channel:${this.id}:${event}`;
|
|
953
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
954
|
+
if (!wsClient) {
|
|
955
|
+
throw new Error(
|
|
956
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
957
|
+
);
|
|
958
|
+
}
|
|
959
|
+
const callback = this.scopedListeners.get(scopedEvent);
|
|
960
|
+
if (callback) {
|
|
961
|
+
wsClient.off(scopedEvent, callback);
|
|
962
|
+
this.scopedListeners.delete(scopedEvent);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
removeAllScopedListeners() {
|
|
966
|
+
const wsClient = this.client.getWebSocketClients().get(this.app);
|
|
967
|
+
if (!wsClient) {
|
|
968
|
+
throw new Error(
|
|
969
|
+
`Nenhum WebSocket conectado dispon\xEDvel para '${this.app}'.`
|
|
970
|
+
);
|
|
971
|
+
}
|
|
972
|
+
for (const [scopedEvent, callback] of this.scopedListeners.entries()) {
|
|
973
|
+
wsClient.off(scopedEvent, callback);
|
|
974
|
+
}
|
|
975
|
+
this.scopedListeners.clear();
|
|
976
|
+
}
|
|
939
977
|
/**
|
|
940
978
|
* Adiciona um listener para eventos de canal.
|
|
941
979
|
*/
|