websocket fix
test-org/trust-module-frontend/pipeline/pr-rc This commit looks good
Details
test-org/trust-module-frontend/pipeline/pr-rc This commit looks good
Details
parent
cb7c22929a
commit
09a6082917
|
|
@ -6,6 +6,8 @@ class MetricsService {
|
|||
this.socket = null;
|
||||
this.subscriptions = new Map();
|
||||
this.pendingRequests = new Map();
|
||||
window.addEventListener('beforeunload', this.cleanupAll.bind(this));
|
||||
window.addEventListener('pagehide', this.cleanupAll.bind(this));
|
||||
|
||||
window.addEventListener('beforeunload', () => {
|
||||
this.cleanupAll();
|
||||
|
|
@ -89,14 +91,9 @@ class MetricsService {
|
|||
|
||||
subscribeToMetric(metricKey, callback, interval = 5000, filters = {}) {
|
||||
this.connectWebSocket();
|
||||
|
||||
const alreadySubscribed = this.subscriptions.has(metricKey);
|
||||
const callbacks = this.subscriptions.get(metricKey) || [];
|
||||
callbacks.push(callback);
|
||||
this.subscriptions.set(metricKey, callbacks);
|
||||
|
||||
if (!alreadySubscribed) {
|
||||
// Разделяем metricKey на метрику и фильтры
|
||||
|
||||
if (!this.subscriptions.has(metricKey)) {
|
||||
this.subscriptions.set(metricKey, []);
|
||||
const [metric] = metricKey.split('?');
|
||||
this.socket.emit('subscribe-metric', {
|
||||
metric,
|
||||
|
|
@ -104,8 +101,13 @@ class MetricsService {
|
|||
filters
|
||||
});
|
||||
}
|
||||
|
||||
return () => this.unsubscribeFromMetric(metricKey, callback);
|
||||
|
||||
const callbacks = this.subscriptions.get(metricKey);
|
||||
callbacks.push(callback);
|
||||
|
||||
return () => {
|
||||
this.unsubscribeFromMetric(metricKey, callback);
|
||||
};
|
||||
}
|
||||
|
||||
unsubscribeFromMetric(metricKey, callback) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue