Добавить смену профилей, пока не работает

This commit is contained in:
AidarKC
2026-09-03 12:51:46 +04:00
parent ebc9143593
commit e0295eebde
8 changed files with 227 additions and 43 deletions
+52 -4
View File
@@ -999,6 +999,8 @@ export class AuthService {
constructor(serverUrl) {
this.serverUrl = normalizeServerUrl(serverUrl);
this.ws = new WsJsonClient(this.serverUrl);
this.eventListeners = new Map();
this.wsEventUnsubscribers = new Map();
this.headerHashCache = new Map();
this.writeLocks = new Map();
this.passwordKeyBundleCache = new Map();
@@ -1008,14 +1010,39 @@ export class AuthService {
this.remoteAddBlockSessionId = '';
}
async reconnect(serverUrl) {
bindRegisteredEventsToCurrentWs() {
this.wsEventUnsubscribers.forEach((unsubscribe) => {
try { unsubscribe?.(); } catch {}
});
this.wsEventUnsubscribers.clear();
this.eventListeners.forEach((_handlers, op) => {
const unsubscribe = this.ws.onEvent(op, (data) => {
const handlers = this.eventListeners.get(op);
if (!handlers) return;
handlers.forEach((handler) => {
try { handler(data); } catch {}
});
});
this.wsEventUnsubscribers.set(op, unsubscribe);
});
}
resetConnection(serverUrl = this.serverUrl, { clearSessionContext = true } = {}) {
const normalized = normalizeServerUrl(serverUrl);
if (normalized === this.serverUrl) return;
this.ws.close();
try { this.ws?.close(); } catch {}
this.serverUrl = normalized;
this.ws = new WsJsonClient(this.serverUrl);
this.headerHashCache = new Map();
this.writeLocks.clear();
this.bindRegisteredEventsToCurrentWs();
if (clearSessionContext) this.clearActiveSessionContext();
}
async reconnect(serverUrl) {
const normalized = normalizeServerUrl(serverUrl);
if (normalized === this.serverUrl) return;
this.resetConnection(normalized, { clearSessionContext: false });
}
setActiveSessionContext({ login = '', sessionId = '' } = {}) {
@@ -2514,7 +2541,28 @@ export class AuthService {
onEvent(op, handler) {
return this.ws.onEvent(op, handler);
if (!op || typeof handler !== 'function') return () => {};
if (!this.eventListeners.has(op)) {
this.eventListeners.set(op, new Set());
const unsubscribe = this.ws.onEvent(op, (data) => {
const handlers = this.eventListeners.get(op);
if (!handlers) return;
handlers.forEach((callback) => {
try { callback(data); } catch {}
});
});
this.wsEventUnsubscribers.set(op, unsubscribe);
}
const handlers = this.eventListeners.get(op);
handlers.add(handler);
return () => {
handlers.delete(handler);
if (handlers.size) return;
this.eventListeners.delete(op);
const unsubscribe = this.wsEventUnsubscribers.get(op);
try { unsubscribe?.(); } catch {}
this.wsEventUnsubscribers.delete(op);
};
}
async upsertPushToken({ endpoint, p256dhKey, authKey, sessionId, platform = 'web', userAgent = navigator.userAgent || '' }) {