SHA256
Добавлен временный debug API для автотеста WebRTC и runbook
This commit is contained in:
+111
-1
@@ -2,7 +2,13 @@ import { navigate, getRoute, PRE_AUTH_PAGES } from './router.js';
|
||||
import { renderToolbar } from './components/toolbar.js';
|
||||
import { captureClientError, setClientErrorTransport } from './services/client-error-reporter.js';
|
||||
import { initPwaPush } from './services/pwa-push-service.js';
|
||||
import { handleIncomingCallInvite, handleIncomingCallSignal } from './services/call-service.js';
|
||||
import {
|
||||
handleIncomingCallInvite,
|
||||
handleIncomingCallSignal,
|
||||
setCallDebugReporter,
|
||||
startDebugConnectionAsInitiator,
|
||||
startDebugConnectionAsResponder,
|
||||
} from './services/call-service.js';
|
||||
import {
|
||||
authService,
|
||||
addAppLogEntry,
|
||||
@@ -91,9 +97,21 @@ const toolbarEl = document.getElementById('toolbar-slot');
|
||||
|
||||
let currentCleanup = null;
|
||||
let pingIntervalId = null;
|
||||
let reconnectIntervalId = null;
|
||||
let sessionRuntimeStarted = false;
|
||||
|
||||
setClientErrorTransport((payload) => authService.reportClientError(payload));
|
||||
setCallDebugReporter((payload) => authService.reportClientDebug(payload));
|
||||
|
||||
function isReconnectAllowedNow() {
|
||||
const pageId = getRoute().pageId || '';
|
||||
return !PRE_AUTH_PAGES.includes(pageId);
|
||||
}
|
||||
|
||||
function wsIsOpen() {
|
||||
const ws = authService?.ws?.ws;
|
||||
return !!(ws && ws.readyState === WebSocket.OPEN);
|
||||
}
|
||||
|
||||
function showGlobalErrorAlert(title, details = {}) {
|
||||
const lines = [title];
|
||||
@@ -298,6 +316,32 @@ async function ensureSessionRuntimeStarted() {
|
||||
// silent keep-alive
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
if (reconnectIntervalId) {
|
||||
window.clearInterval(reconnectIntervalId);
|
||||
reconnectIntervalId = null;
|
||||
}
|
||||
reconnectIntervalId = window.setInterval(async () => {
|
||||
if (!state.session.isAuthorized) return;
|
||||
if (!isReconnectAllowedNow()) return;
|
||||
if (wsIsOpen()) return;
|
||||
|
||||
try {
|
||||
await authService.ws.open();
|
||||
addAppLogEntry({
|
||||
level: 'info',
|
||||
source: 'ws-reconnect',
|
||||
message: 'WS переподключен автоматически',
|
||||
});
|
||||
} catch (error) {
|
||||
addAppLogEntry({
|
||||
level: 'warn',
|
||||
source: 'ws-reconnect',
|
||||
message: 'Попытка автопереподключения не удалась',
|
||||
details: { error: error?.message || 'unknown' },
|
||||
});
|
||||
}
|
||||
}, 15_000);
|
||||
}
|
||||
|
||||
async function init() {
|
||||
@@ -313,6 +357,10 @@ async function init() {
|
||||
window.clearInterval(pingIntervalId);
|
||||
pingIntervalId = null;
|
||||
}
|
||||
if (reconnectIntervalId) {
|
||||
window.clearInterval(reconnectIntervalId);
|
||||
reconnectIntervalId = null;
|
||||
}
|
||||
navigate('start-view');
|
||||
});
|
||||
|
||||
@@ -391,6 +439,68 @@ async function init() {
|
||||
try { await handleIncomingCallSignal(evt); } catch {}
|
||||
});
|
||||
|
||||
authService.onEvent('DebugConnectPrepareResponder', async (evt) => {
|
||||
try {
|
||||
const p = evt?.payload || {};
|
||||
await startDebugConnectionAsResponder({
|
||||
runId: p.runId,
|
||||
callId: p.callId,
|
||||
peerLogin: p.peerLogin,
|
||||
peerSessionId: p.peerSessionId,
|
||||
});
|
||||
addAppLogEntry({
|
||||
level: 'info',
|
||||
source: 'debug-connect',
|
||||
message: 'Получена команда debug responder',
|
||||
details: p,
|
||||
});
|
||||
} catch (error) {
|
||||
addAppLogEntry({
|
||||
level: 'error',
|
||||
source: 'debug-connect',
|
||||
message: 'Ошибка запуска debug responder',
|
||||
details: { error: error?.message || 'unknown' },
|
||||
});
|
||||
await authService.reportClientDebug({
|
||||
runId: evt?.payload?.runId || '',
|
||||
level: 'error',
|
||||
message: 'debug_responder_failed',
|
||||
details: error?.message || 'unknown',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
authService.onEvent('DebugConnectStartInitiator', async (evt) => {
|
||||
try {
|
||||
const p = evt?.payload || {};
|
||||
await startDebugConnectionAsInitiator({
|
||||
runId: p.runId,
|
||||
callId: p.callId,
|
||||
peerLogin: p.peerLogin,
|
||||
peerSessionId: p.peerSessionId,
|
||||
});
|
||||
addAppLogEntry({
|
||||
level: 'info',
|
||||
source: 'debug-connect',
|
||||
message: 'Получена команда debug initiator',
|
||||
details: p,
|
||||
});
|
||||
} catch (error) {
|
||||
addAppLogEntry({
|
||||
level: 'error',
|
||||
source: 'debug-connect',
|
||||
message: 'Ошибка запуска debug initiator',
|
||||
details: { error: error?.message || 'unknown' },
|
||||
});
|
||||
await authService.reportClientDebug({
|
||||
runId: evt?.payload?.runId || '',
|
||||
level: 'error',
|
||||
message: 'debug_initiator_failed',
|
||||
details: error?.message || 'unknown',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
await tryAutoLogin();
|
||||
await ensureSessionRuntimeStarted();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user