Jagd auf WS Abbrüche
This commit is contained in:
1 parent
a95204b8d6
commit
1e2a58e563
9 files changed
+462
-51
No files matched your search
+58
-17
@@ -66,6 +66,15 @@ class WebSocketBroker:
|
|||||||
self.disconnected_clients = {}
|
self.disconnected_clients = {}
|
||||||
self.queue_lock = Lock()
|
self.queue_lock = Lock()
|
||||||
|
|
||||||
|
# Sequenznummern werden pro Client-ID vergeben und bleiben über einen
|
||||||
|
# WebSocket-Reconnect derselben Webview hinweg erhalten. Dadurch kann
|
||||||
|
# der Client nach einem Reconnect erkennen, ob ihm Frames fehlen.
|
||||||
|
# client_sequences[(tenant_id, client_id)] = zuletzt zugestellte Sequenz
|
||||||
|
self.client_sequences = {}
|
||||||
|
# Ein Lock pro Client-ID serialisiert Sequenzvergabe und Sendevorgang
|
||||||
|
# auch dann, wenn die Verbindung während eines Reconnects ersetzt wird.
|
||||||
|
self.client_sequence_locks = {}
|
||||||
|
|
||||||
# Zeitpunkt des letzten Code-2-Pongs je Gruppe (monotonic).
|
# Zeitpunkt des letzten Code-2-Pongs je Gruppe (monotonic).
|
||||||
self.group_last_pong = {}
|
self.group_last_pong = {}
|
||||||
self.group_online_since = {}
|
self.group_online_since = {}
|
||||||
@@ -138,6 +147,10 @@ class WebSocketBroker:
|
|||||||
'last_ping': datetime.now(),
|
'last_ping': datetime.now(),
|
||||||
'connected_at': time.monotonic(),
|
'connected_at': time.monotonic(),
|
||||||
'last_pong_at': None,
|
'last_pong_at': None,
|
||||||
|
# Zuletzt an diese Client-ID zugestellte Sequenznummer. Die
|
||||||
|
# maßgebliche Zählung liegt in self.client_sequences, damit sie
|
||||||
|
# einen Reconnect überlebt.
|
||||||
|
'seq': self.client_sequences.get((tenant_id, client_id), 0),
|
||||||
# Ob diese Client-ID bereits vor diesem Handshake bekannt war.
|
# Ob diese Client-ID bereits vor diesem Handshake bekannt war.
|
||||||
# Nur dann bleibt ihre Queue auch bei einem fehlgeschlagenen
|
# Nur dann bleibt ihre Queue auch bei einem fehlgeschlagenen
|
||||||
# erneuten Handshake erhalten.
|
# erneuten Handshake erhalten.
|
||||||
@@ -156,24 +169,48 @@ class WebSocketBroker:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def send_to_connection(self, tenant_id, client_id, data):
|
def send_to_connection(self, tenant_id, client_id, data):
|
||||||
"""Sendet einen Frame thread-sicher an eine registrierte Client-Verbindung."""
|
"""Sendet einen Frame mit Sequenznummer thread-sicher an einen Client.
|
||||||
conn = self._get_connection(tenant_id, client_id)
|
|
||||||
if not conn:
|
|
||||||
return False
|
|
||||||
|
|
||||||
try:
|
Die Sequenz wird pro Client-ID vergeben. Sie wird erst nach einem
|
||||||
lock = conn.get('send_lock')
|
erfolgreichen Socket-Send fortgeschrieben, damit ein fehlgeschlagener
|
||||||
if lock is None:
|
Versand beim erneuten Zustellen keine Lücke erzeugt. Die Zählung bleibt
|
||||||
lock = Lock()
|
über Reconnects derselben Webview erhalten.
|
||||||
conn['send_lock'] = lock
|
"""
|
||||||
with lock:
|
key = (tenant_id, client_id)
|
||||||
conn['ws'].send(data)
|
seq_lock = self.client_sequence_locks.setdefault(key, Lock())
|
||||||
return True
|
|
||||||
except Exception:
|
with seq_lock:
|
||||||
# Eine fehlerhafte Verbindung darf den Versand an andere Clients
|
conn = self._get_connection(tenant_id, client_id)
|
||||||
# nicht verhindern. Das Aufräumen übernimmt die Route beim
|
if not conn:
|
||||||
# Schließen der Verbindung.
|
return False
|
||||||
return False
|
|
||||||
|
try:
|
||||||
|
payload = json.loads(data)
|
||||||
|
if not isinstance(payload, dict):
|
||||||
|
return False
|
||||||
|
|
||||||
|
last_seq = self.client_sequences.get(key)
|
||||||
|
if last_seq is None:
|
||||||
|
last_seq = int(conn.get('seq') or 0)
|
||||||
|
next_seq = last_seq + 1
|
||||||
|
payload['seq'] = next_seq
|
||||||
|
framed = json.dumps(payload, ensure_ascii=False)
|
||||||
|
|
||||||
|
send_lock = conn.get('send_lock')
|
||||||
|
if send_lock is None:
|
||||||
|
send_lock = Lock()
|
||||||
|
conn['send_lock'] = send_lock
|
||||||
|
with send_lock:
|
||||||
|
conn['ws'].send(framed)
|
||||||
|
|
||||||
|
self.client_sequences[key] = next_seq
|
||||||
|
conn['seq'] = next_seq
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
# Eine fehlerhafte Verbindung darf den Versand an andere Clients
|
||||||
|
# nicht verhindern. Das Aufräumen übernimmt die Route beim
|
||||||
|
# Schließen der Verbindung.
|
||||||
|
return False
|
||||||
|
|
||||||
def is_authenticated(self, tenant_id, client_id):
|
def is_authenticated(self, tenant_id, client_id):
|
||||||
"""Prüft, ob ein Client den Code-0-Handshake erfolgreich absolviert hat."""
|
"""Prüft, ob ein Client den Code-0-Handshake erfolgreich absolviert hat."""
|
||||||
@@ -282,6 +319,8 @@ class WebSocketBroker:
|
|||||||
account_id = self.client_accounts.pop((tenant_id, client_id), None)
|
account_id = self.client_accounts.pop((tenant_id, client_id), None)
|
||||||
self.client_queues.pop((tenant_id, client_id), None)
|
self.client_queues.pop((tenant_id, client_id), None)
|
||||||
self.disconnected_clients.pop((tenant_id, client_id), None)
|
self.disconnected_clients.pop((tenant_id, client_id), None)
|
||||||
|
self.client_sequences.pop((tenant_id, client_id), None)
|
||||||
|
self.client_sequence_locks.pop((tenant_id, client_id), None)
|
||||||
if account_id is not None:
|
if account_id is not None:
|
||||||
clients = self.account_clients.get((tenant_id, account_id))
|
clients = self.account_clients.get((tenant_id, account_id))
|
||||||
if clients is not None:
|
if clients is not None:
|
||||||
@@ -496,6 +535,8 @@ class WebSocketBroker:
|
|||||||
account_id = self.client_accounts.pop(key, None)
|
account_id = self.client_accounts.pop(key, None)
|
||||||
self.client_queues.pop(key, None)
|
self.client_queues.pop(key, None)
|
||||||
self.disconnected_clients.pop(key, None)
|
self.disconnected_clients.pop(key, None)
|
||||||
|
self.client_sequences.pop(key, None)
|
||||||
|
self.client_sequence_locks.pop(key, None)
|
||||||
if account_id is not None:
|
if account_id is not None:
|
||||||
clients = self.account_clients.get((tenant_id, account_id))
|
clients = self.account_clients.get((tenant_id, account_id))
|
||||||
if clients is not None:
|
if clients is not None:
|
||||||
|
|||||||
@@ -80,6 +80,75 @@ body.mobile-page main.container {
|
|||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
padding: 0.4rem 0.2rem;
|
padding: 0.4rem 0.2rem;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-ws-status {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.3rem;
|
||||||
|
padding: 0.2rem 0.45rem;
|
||||||
|
border: 1px solid var(--mobile-border);
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--mobile-bg);
|
||||||
|
color: var(--mobile-subtext);
|
||||||
|
font-size: 0.7rem;
|
||||||
|
font-weight: 600;
|
||||||
|
line-height: 1.2;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-ws-status::before {
|
||||||
|
content: '';
|
||||||
|
width: 0.5rem;
|
||||||
|
height: 0.5rem;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: currentColor;
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-ws-status.is-connected {
|
||||||
|
color: #15803d;
|
||||||
|
border-color: #86efac;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-ws-status.is-connecting {
|
||||||
|
color: #b45309;
|
||||||
|
border-color: #fcd34d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-ws-status.is-disconnected {
|
||||||
|
color: var(--mobile-subtext);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mobile-ws-status.is-error {
|
||||||
|
color: #dc2626;
|
||||||
|
border-color: #fca5a5;
|
||||||
|
}
|
||||||
|
|
||||||
|
html[data-theme="dark"] .mobile-ws-status.is-connected {
|
||||||
|
color: #4ade80;
|
||||||
|
border-color: #166534;
|
||||||
|
}
|
||||||
|
|
||||||
|
html[data-theme="dark"] .mobile-ws-status.is-connecting {
|
||||||
|
color: #fbbf24;
|
||||||
|
border-color: #92400e;
|
||||||
|
}
|
||||||
|
|
||||||
|
html[data-theme="dark"] .mobile-ws-status.is-error {
|
||||||
|
color: #f87171;
|
||||||
|
border-color: #991b1b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 420px) {
|
||||||
|
.mobile-ws-status {
|
||||||
|
font-size: 0.62rem;
|
||||||
|
padding: 0.15rem 0.3rem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.mobile-icon-btn {
|
.mobile-icon-btn {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
let adminSocket = null;
|
let adminSocket = null;
|
||||||
let adminRetryTimer = null;
|
let adminRetryTimer = null;
|
||||||
let adminStopped = false;
|
let adminStopped = false;
|
||||||
|
let lastAdminWsSeq = null;
|
||||||
|
|
||||||
function ensureDialog() {
|
function ensureDialog() {
|
||||||
if (dialog) return dialog;
|
if (dialog) return dialog;
|
||||||
@@ -89,6 +90,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkAdminWsSequence(message) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(message, 'seq')) return;
|
||||||
|
|
||||||
|
const seq = Number(message.seq);
|
||||||
|
if (!Number.isFinite(seq) || seq <= 0) return;
|
||||||
|
|
||||||
|
if (lastAdminWsSeq !== null && seq !== lastAdminWsSeq + 1) {
|
||||||
|
showReloadNotice(
|
||||||
|
`Die WebSocket-Verbindung hat Nachrichten verloren `
|
||||||
|
+ `(erwartet: ${lastAdminWsSeq + 1}, empfangen: ${seq}). `
|
||||||
|
+ 'Bitte lade die Seite neu, damit alle Änderungen sichtbar werden.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
lastAdminWsSeq = lastAdminWsSeq === null
|
||||||
|
? seq
|
||||||
|
: Math.max(lastAdminWsSeq, seq);
|
||||||
|
}
|
||||||
|
|
||||||
function appUrl(path) {
|
function appUrl(path) {
|
||||||
if (typeof window.CMBNET_APP_URL === 'function') {
|
if (typeof window.CMBNET_APP_URL === 'function') {
|
||||||
return window.CMBNET_APP_URL(path);
|
return window.CMBNET_APP_URL(path);
|
||||||
@@ -141,6 +161,9 @@
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkAdminWsSequence(message);
|
||||||
|
|
||||||
if (Number(message.code) === 1) {
|
if (Number(message.code) === 1) {
|
||||||
if (ws.readyState === WebSocket.OPEN) {
|
if (ws.readyState === WebSocket.OPEN) {
|
||||||
ws.send(JSON.stringify({code: 2, msg: 'pong'}));
|
ws.send(JSON.stringify({code: 2, msg: 'pong'}));
|
||||||
@@ -154,13 +177,21 @@
|
|||||||
showReloadNotice(text);
|
showReloadNotice(text);
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.addEventListener('close', () => {
|
ws.addEventListener('close', event => {
|
||||||
if (adminSocket === ws) adminSocket = null;
|
if (adminSocket !== ws) return;
|
||||||
|
console.warn('[WS] Admin-Watcher geschlossen', {
|
||||||
|
code: event.code,
|
||||||
|
reason: event.reason,
|
||||||
|
wasClean: event.wasClean
|
||||||
|
});
|
||||||
|
adminSocket = null;
|
||||||
scheduleAdminReconnect();
|
scheduleAdminReconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.addEventListener('error', () => {
|
ws.addEventListener('error', event => {
|
||||||
if (adminSocket === ws) adminSocket = null;
|
if (adminSocket !== ws) return;
|
||||||
|
console.warn('[WS] Admin-Watcher-Fehler', event);
|
||||||
|
adminSocket = null;
|
||||||
scheduleAdminReconnect();
|
scheduleAdminReconnect();
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* damit er sowohl die mobilen Views als auch die statischen Assets
|
* damit er sowohl die mobilen Views als auch die statischen Assets
|
||||||
* kontrolliert. Der Cache-Name wird pro App-Wurzel gebildet.
|
* kontrolliert. Der Cache-Name wird pro App-Wurzel gebildet.
|
||||||
*/
|
*/
|
||||||
const VERSION = 'cmbnet-pwa-v9';
|
const VERSION = 'cmbnet-pwa-v11';
|
||||||
const BASE = new URL('./', self.location).href;
|
const BASE = new URL('./', self.location).href;
|
||||||
const SHELL_CACHE = `${VERSION}-shell`;
|
const SHELL_CACHE = `${VERSION}-shell`;
|
||||||
const TILE_CACHE = `${VERSION}-tiles`;
|
const TILE_CACHE = `${VERSION}-tiles`;
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ const dispatcherState = {
|
|||||||
ws: null,
|
ws: null,
|
||||||
authenticated: false,
|
authenticated: false,
|
||||||
reconnectTimer: null,
|
reconnectTimer: null,
|
||||||
|
lastWsSeq: null,
|
||||||
crosshairGroupId: null,
|
crosshairGroupId: null,
|
||||||
currentStreetId: null,
|
currentStreetId: null,
|
||||||
streetsDialogGroupId: null,
|
streetsDialogGroupId: null,
|
||||||
@@ -2717,13 +2718,21 @@ async function connectWebSocket() {
|
|||||||
|
|
||||||
ws.addEventListener('message', handleWsMessage);
|
ws.addEventListener('message', handleWsMessage);
|
||||||
|
|
||||||
ws.addEventListener('close', () => {
|
ws.addEventListener('close', event => {
|
||||||
|
if (dispatcherState.ws !== ws) return;
|
||||||
|
console.warn('[WS] Verbindung geschlossen', {
|
||||||
|
code: event.code,
|
||||||
|
reason: event.reason,
|
||||||
|
wasClean: event.wasClean
|
||||||
|
});
|
||||||
dispatcherState.authenticated = false;
|
dispatcherState.authenticated = false;
|
||||||
setConnectionStatus('Getrennt – neuer Versuch …', 'disconnected');
|
setConnectionStatus('Getrennt – neuer Versuch …', 'disconnected');
|
||||||
scheduleReconnect();
|
scheduleReconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.addEventListener('error', () => {
|
ws.addEventListener('error', event => {
|
||||||
|
if (dispatcherState.ws !== ws) return;
|
||||||
|
console.warn('[WS] Verbindungsfehler', event);
|
||||||
setConnectionStatus('Verbindungsfehler', 'disconnected');
|
setConnectionStatus('Verbindungsfehler', 'disconnected');
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -2762,6 +2771,27 @@ function sendWs(message) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkWsSequence(message) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(message, 'seq')) return;
|
||||||
|
|
||||||
|
const seq = Number(message.seq);
|
||||||
|
if (!Number.isFinite(seq) || seq <= 0) return;
|
||||||
|
|
||||||
|
const lastSeq = dispatcherState.lastWsSeq;
|
||||||
|
if (lastSeq !== null && seq !== lastSeq + 1) {
|
||||||
|
const text = `Die WebSocket-Verbindung hat Nachrichten verloren `
|
||||||
|
+ `(erwartet: ${lastSeq + 1}, empfangen: ${seq}). `
|
||||||
|
+ 'Bitte lade die Seite neu, damit alle Änderungen sichtbar werden.';
|
||||||
|
if (typeof window.showReloadNotice === 'function') {
|
||||||
|
window.showReloadNotice(text);
|
||||||
|
} else {
|
||||||
|
alert(`${text}\n\nBitte die Webseite neu laden.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatcherState.lastWsSeq = lastSeq === null ? seq : Math.max(lastSeq, seq);
|
||||||
|
}
|
||||||
|
|
||||||
function handleWsMessage(event) {
|
function handleWsMessage(event) {
|
||||||
let message;
|
let message;
|
||||||
try {
|
try {
|
||||||
@@ -2771,6 +2801,7 @@ function handleWsMessage(event) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkWsSequence(message);
|
||||||
console.debug('[WS RX]', message);
|
console.debug('[WS RX]', message);
|
||||||
console.log('[WS RX]', JSON.stringify(message));
|
console.log('[WS RX]', JSON.stringify(message));
|
||||||
|
|
||||||
@@ -2946,8 +2977,18 @@ function handleStreetUpdate(message) {
|
|||||||
|
|
||||||
recolorStreet(street);
|
recolorStreet(street);
|
||||||
|
|
||||||
|
// Ein offener Straßendialog muss den neuen Serverzustand anzeigen.
|
||||||
|
const streetModal = document.getElementById('streetModal');
|
||||||
|
if (streetModal && streetModal.open
|
||||||
|
&& dispatcherState.currentStreetId === Number(street.id)) {
|
||||||
|
const stateSelect = document.getElementById('streetStateSelect');
|
||||||
|
if (stateSelect) stateSelect.value = street.state || 'unbearbeitet';
|
||||||
|
fillStreetGroupOptions(street.group_id);
|
||||||
|
updateStreetGroupVisibility();
|
||||||
|
}
|
||||||
|
|
||||||
const streetsDialog = document.getElementById('groupStreetsModal');
|
const streetsDialog = document.getElementById('groupStreetsModal');
|
||||||
if (dispatcherState.streetsDialogGroupId && streetsDialog.open) {
|
if (dispatcherState.streetsDialogGroupId && streetsDialog && streetsDialog.open) {
|
||||||
renderGroupStreetsDialog(dispatcherState.streetsDialogGroupId);
|
renderGroupStreetsDialog(dispatcherState.streetsDialogGroupId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2964,6 +3005,7 @@ function handleGroupStateUpdate(message) {
|
|||||||
if (GROUP_STATES.includes(payload.state)) {
|
if (GROUP_STATES.includes(payload.state)) {
|
||||||
group.state = payload.state;
|
group.state = payload.state;
|
||||||
updateGroupSummary(group);
|
updateGroupSummary(group);
|
||||||
|
refreshGroupControls();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ const state = {
|
|||||||
authenticated: false,
|
authenticated: false,
|
||||||
outbox: [],
|
outbox: [],
|
||||||
reconnectTimer: null,
|
reconnectTimer: null,
|
||||||
|
lastWsSeq: null,
|
||||||
chatMessages: [],
|
chatMessages: [],
|
||||||
chatKeys: new Set(),
|
chatKeys: new Set(),
|
||||||
userMarker: null,
|
userMarker: null,
|
||||||
@@ -694,7 +695,7 @@ function buildGroupSelect() {
|
|||||||
state.groups.forEach(g => {
|
state.groups.forEach(g => {
|
||||||
const opt = document.createElement('option');
|
const opt = document.createElement('option');
|
||||||
opt.value = g.id;
|
opt.value = g.id;
|
||||||
opt.textContent = g.aliasname || g.id;
|
opt.textContent = `${g.aliasname || g.id} (${g.state || 'offen'})`;
|
||||||
sel.appendChild(opt);
|
sel.appendChild(opt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1141,8 +1142,51 @@ function openGroupNavigation() {
|
|||||||
window.location.href = buildNavigationUrl(coordinates.lat, coordinates.lon);
|
window.location.href = buildNavigationUrl(coordinates.lat, coordinates.lon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setMobileWsStatus(label, status) {
|
||||||
|
const element = document.getElementById('mobileWsStatus');
|
||||||
|
if (!element) return;
|
||||||
|
|
||||||
|
element.textContent = `WS: ${label}`;
|
||||||
|
element.title = `WebSocket: ${label}`;
|
||||||
|
element.classList.remove('is-connected', 'is-connecting', 'is-disconnected', 'is-error');
|
||||||
|
element.classList.add(`is-${status}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleMobileReconnect() {
|
||||||
|
if (state.reconnectTimer) return;
|
||||||
|
state.reconnectTimer = setTimeout(() => {
|
||||||
|
state.reconnectTimer = null;
|
||||||
|
connectWebSocket();
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkWsSequence(message) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(message, 'seq')) return;
|
||||||
|
|
||||||
|
const seq = Number(message.seq);
|
||||||
|
if (!Number.isFinite(seq) || seq <= 0) return;
|
||||||
|
|
||||||
|
const lastSeq = state.lastWsSeq;
|
||||||
|
if (lastSeq !== null && seq !== lastSeq + 1) {
|
||||||
|
const text = `Die WebSocket-Verbindung hat Nachrichten verloren `
|
||||||
|
+ `(erwartet: ${lastSeq + 1}, empfangen: ${seq}). `
|
||||||
|
+ 'Bitte lade die Seite neu, damit alle Änderungen sichtbar werden.';
|
||||||
|
if (typeof window.showReloadNotice === 'function') {
|
||||||
|
window.showReloadNotice(text);
|
||||||
|
} else {
|
||||||
|
alert(`${text}\n\nBitte die Webseite neu laden.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bei einer Dublette nicht rückwärts zählen; so löst nicht jede folgende
|
||||||
|
// Nachricht erneut einen vermeintlichen Sprung aus.
|
||||||
|
state.lastWsSeq = lastSeq === null ? seq : Math.max(lastSeq, seq);
|
||||||
|
}
|
||||||
|
|
||||||
function connectWebSocket() {
|
function connectWebSocket() {
|
||||||
if (state.ws && (state.ws.readyState === WebSocket.OPEN || state.ws.readyState === WebSocket.CONNECTING)) return;
|
if (state.ws && (state.ws.readyState === WebSocket.OPEN || state.ws.readyState === WebSocket.CONNECTING)) return;
|
||||||
|
|
||||||
|
setMobileWsStatus('verbinde …', 'connecting');
|
||||||
fetchJson(`${apiBase}/auth/ws-token`).then(res => {
|
fetchJson(`${apiBase}/auth/ws-token`).then(res => {
|
||||||
const token = res.token;
|
const token = res.token;
|
||||||
const ws = new WebSocket(wsUrl);
|
const ws = new WebSocket(wsUrl);
|
||||||
@@ -1151,6 +1195,7 @@ function connectWebSocket() {
|
|||||||
// Der Server bestätigt den Handshake mit Code 0. Bis dahin werden
|
// Der Server bestätigt den Handshake mit Code 0. Bis dahin werden
|
||||||
// fachliche Nachrichten im Outbox-Puffer gesammelt.
|
// fachliche Nachrichten im Outbox-Puffer gesammelt.
|
||||||
state.authenticated = false;
|
state.authenticated = false;
|
||||||
|
setMobileWsStatus('Anmeldung …', 'connecting');
|
||||||
ws.send(JSON.stringify({
|
ws.send(JSON.stringify({
|
||||||
code: 0,
|
code: 0,
|
||||||
msg: token,
|
msg: token,
|
||||||
@@ -1167,17 +1212,31 @@ function connectWebSocket() {
|
|||||||
&& ws.readyState === WebSocket.OPEN
|
&& ws.readyState === WebSocket.OPEN
|
||||||
&& !state.authenticated) {
|
&& !state.authenticated) {
|
||||||
state.authenticated = true;
|
state.authenticated = true;
|
||||||
|
setMobileWsStatus('verbunden', 'connected');
|
||||||
flushWsOutbox();
|
flushWsOutbox();
|
||||||
}
|
}
|
||||||
}, 1500);
|
}, 1500);
|
||||||
});
|
});
|
||||||
ws.addEventListener('message', handleWs);
|
ws.addEventListener('message', handleWs);
|
||||||
ws.addEventListener('close', () => {
|
ws.addEventListener('close', event => {
|
||||||
|
if (state.ws !== ws) return;
|
||||||
|
console.warn('[WS] Verbindung geschlossen', {
|
||||||
|
code: event.code,
|
||||||
|
reason: event.reason,
|
||||||
|
wasClean: event.wasClean
|
||||||
|
});
|
||||||
state.authenticated = false;
|
state.authenticated = false;
|
||||||
setTimeout(connectWebSocket, 3000);
|
setMobileWsStatus('getrennt', 'disconnected');
|
||||||
|
scheduleMobileReconnect();
|
||||||
|
});
|
||||||
|
ws.addEventListener('error', event => {
|
||||||
|
if (state.ws !== ws) return;
|
||||||
|
console.warn('[WS] Verbindungsfehler', event);
|
||||||
|
setMobileWsStatus('Fehler', 'error');
|
||||||
});
|
});
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
setTimeout(connectWebSocket, 3000);
|
setMobileWsStatus('Token-Fehler', 'error');
|
||||||
|
scheduleMobileReconnect();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1325,16 +1384,127 @@ function parseFlexibleTimestamp(value) {
|
|||||||
return Number.isNaN(parsed) ? null : parsed;
|
return Number.isNaN(parsed) ? null : parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyMobileStreetUpdate(payload) {
|
||||||
|
if (!payload) return;
|
||||||
|
|
||||||
|
const streetId = Number(payload.street_id);
|
||||||
|
const hasGroup = Object.prototype.hasOwnProperty.call(payload, 'group_id');
|
||||||
|
const newGroupId = hasGroup && payload.group_id !== null && payload.group_id !== ''
|
||||||
|
? Number(payload.group_id)
|
||||||
|
: null;
|
||||||
|
const ownGroupId = Number(state.currentGroupId) || null;
|
||||||
|
|
||||||
|
let street = Number.isFinite(streetId) ? state.streetById.get(streetId) : null;
|
||||||
|
if (!street && payload.name) {
|
||||||
|
street = state.streets.find(item => item.name === payload.name) || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!street) {
|
||||||
|
// Eine Straße kann durch eine Zuweisung neu in der Gruppe auftauchen.
|
||||||
|
// Der Broker liefert Name, ID, Status und Zielgruppe im Payload mit.
|
||||||
|
if (ownGroupId && newGroupId === ownGroupId
|
||||||
|
&& Number.isFinite(streetId) && payload.name) {
|
||||||
|
street = {
|
||||||
|
id: streetId,
|
||||||
|
name: payload.name,
|
||||||
|
state: payload.state || 'zugewiesen',
|
||||||
|
group_id: ownGroupId
|
||||||
|
};
|
||||||
|
state.streets.push(street);
|
||||||
|
state.streetById.set(street.id, street);
|
||||||
|
} else {
|
||||||
|
console.warn('[WS] Code 100: Straße nicht im lokalen Zustand', payload);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (payload.state) street.state = payload.state;
|
||||||
|
if (hasGroup) street.group_id = newGroupId;
|
||||||
|
|
||||||
|
const index = state.streets.indexOf(street);
|
||||||
|
if (ownGroupId && hasGroup && newGroupId !== ownGroupId && index >= 0) {
|
||||||
|
// Die Straße wurde einer anderen Gruppe zugewiesen und gehört
|
||||||
|
// nicht mehr zur ToDo-Liste dieser Webview.
|
||||||
|
state.streets.splice(index, 1);
|
||||||
|
state.streetById.delete(street.id);
|
||||||
|
} else if (ownGroupId && newGroupId === ownGroupId && index < 0) {
|
||||||
|
state.streets.push(street);
|
||||||
|
state.streetById.set(street.id, street);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isCurrent = state.currentStreetId == street.id;
|
||||||
|
if (isCurrent && state.streetById.has(street.id)) {
|
||||||
|
if (state.currentPolyline) {
|
||||||
|
state.currentPolyline.setStyle({
|
||||||
|
color: STREET_COLORS[street.state] || STREET_COLORS.unbearbeitet
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const dialog = document.getElementById('mobileStreetStateDialog');
|
||||||
|
if (dialog && dialog.open) {
|
||||||
|
document.getElementById('mobileStreetStateTitle').textContent =
|
||||||
|
`Straße: ${street.name}`;
|
||||||
|
document.getElementById('mobileStreetStateSelect').value =
|
||||||
|
street.state || 'unbearbeitet';
|
||||||
|
fillMobileStreetGroupSelect(street.group_id);
|
||||||
|
updateMobileStreetGroupVisibility();
|
||||||
|
}
|
||||||
|
} else if (isCurrent && !state.streetById.has(street.id)) {
|
||||||
|
if (state.currentPolyline) {
|
||||||
|
map.removeLayer(state.currentPolyline);
|
||||||
|
state.currentPolyline = null;
|
||||||
|
}
|
||||||
|
state.currentStreetId = null;
|
||||||
|
closeMobileStreetState();
|
||||||
|
if (state.streets.length) {
|
||||||
|
selectStreet(state.streets[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildStreetList();
|
||||||
|
updateWorkButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyMobileGroupStateUpdate(message) {
|
||||||
|
const payload = typeof message.msg === 'string'
|
||||||
|
? JSON.parse(message.msg)
|
||||||
|
: message.msg;
|
||||||
|
if (!payload) return;
|
||||||
|
|
||||||
|
const groupId = Number(payload.group_id ?? message.receiver_id);
|
||||||
|
const group = state.groupById.get(groupId);
|
||||||
|
if (!group) {
|
||||||
|
console.warn('[WS] Code 200: Gruppe nicht im lokalen Zustand', payload);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (payload.state) group.state = payload.state;
|
||||||
|
|
||||||
|
if (viewMode === 'mobile_dispatcher') {
|
||||||
|
const select = document.getElementById('mobileGroupSelect');
|
||||||
|
const option = select
|
||||||
|
? select.querySelector(`option[value="${group.id}"]`)
|
||||||
|
: null;
|
||||||
|
if (option) {
|
||||||
|
option.textContent = `${group.aliasname || group.id} (${group.state || 'offen'})`;
|
||||||
|
}
|
||||||
|
updateNavigationButton();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleWs(event) {
|
function handleWs(event) {
|
||||||
let message;
|
let message;
|
||||||
try { message = JSON.parse(event.data); } catch(e) { return; }
|
try { message = JSON.parse(event.data); } catch(e) { return; }
|
||||||
|
|
||||||
|
checkWsSequence(message);
|
||||||
console.debug('[WS RX]', message);
|
console.debug('[WS RX]', message);
|
||||||
|
|
||||||
if (message.code === 0) {
|
if (message.code === 0) {
|
||||||
state.authenticated = true;
|
state.authenticated = true;
|
||||||
|
setMobileWsStatus('verbunden', 'connected');
|
||||||
flushWsOutbox();
|
flushWsOutbox();
|
||||||
} else if (message.code === 1) {
|
} else if (message.code === 1) {
|
||||||
|
setMobileWsStatus('verbunden', 'connected');
|
||||||
if (state.ws && state.ws.readyState === WebSocket.OPEN) {
|
if (state.ws && state.ws.readyState === WebSocket.OPEN) {
|
||||||
state.ws.send(JSON.stringify({code: 2, msg: 'pong'}));
|
state.ws.send(JSON.stringify({code: 2, msg: 'pong'}));
|
||||||
}
|
}
|
||||||
@@ -1351,20 +1521,17 @@ function handleWs(event) {
|
|||||||
// Street update
|
// Street update
|
||||||
try {
|
try {
|
||||||
const p = typeof message.msg === 'string' ? JSON.parse(message.msg) : message.msg;
|
const p = typeof message.msg === 'string' ? JSON.parse(message.msg) : message.msg;
|
||||||
if (p && p.street_id) {
|
applyMobileStreetUpdate(p);
|
||||||
const street = state.streetById.get(Number(p.street_id));
|
} catch(e) {
|
||||||
if (street) {
|
console.warn('[WS] Code 100 konnte nicht verarbeitet werden', e, message.msg);
|
||||||
if (p.state) street.state = p.state;
|
}
|
||||||
if (p.group_id !== undefined) street.group_id = p.group_id;
|
} else if (message.code === 200) {
|
||||||
if (state.currentStreetId == street.id && state.currentPolyline) {
|
// Group state update
|
||||||
state.currentPolyline.setStyle({color: STREET_COLORS[street.state] || STREET_COLORS.unbearbeitet});
|
try {
|
||||||
}
|
applyMobileGroupStateUpdate(message);
|
||||||
buildStreetList();
|
} catch(e) {
|
||||||
} else {
|
console.warn('[WS] Code 200 konnte nicht verarbeitet werden', e, message.msg);
|
||||||
console.warn('[WS] Code 100: Straße nicht im lokalen Zustand', p);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch(e) {}
|
|
||||||
} else if (message.code === 300) {
|
} else if (message.code === 300) {
|
||||||
// Group position
|
// Group position
|
||||||
try {
|
try {
|
||||||
@@ -1410,10 +1577,6 @@ function handleWs(event) {
|
|||||||
if (Number(message.sender_id) !== currentAccountId) {
|
if (Number(message.sender_id) !== currentAccountId) {
|
||||||
playSound();
|
playSound();
|
||||||
showChatPopup(text, getSenderName(message, payload));
|
showChatPopup(text, getSenderName(message, payload));
|
||||||
// Switch to chat tab
|
|
||||||
document.querySelectorAll('.mobile-tab').forEach(b => {
|
|
||||||
if (b.dataset.tab === 'chat') b.click();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
<header class="mobile-header">
|
<header class="mobile-header">
|
||||||
<div class="mobile-header-row">
|
<div class="mobile-header-row">
|
||||||
<select id="mobileGroupSelect" class="mobile-group-select" aria-label="Gruppe auswählen"></select>
|
<select id="mobileGroupSelect" class="mobile-group-select" aria-label="Gruppe auswählen"></select>
|
||||||
|
<span id="mobileWsStatus" class="mobile-ws-status is-disconnected"
|
||||||
|
role="status" aria-live="polite" title="WebSocket: getrennt">WS: getrennt</span>
|
||||||
<button type="button" id="mobileInstallBtn" class="mobile-icon-btn" aria-label="App installieren" title="App installieren" hidden>📲</button>
|
<button type="button" id="mobileInstallBtn" class="mobile-icon-btn" aria-label="App installieren" title="App installieren" hidden>📲</button>
|
||||||
<button type="button" id="mobileLogout" class="mobile-icon-btn" aria-label="Abmelden" title="Abmelden">⏻</button>
|
<button type="button" id="mobileLogout" class="mobile-icon-btn" aria-label="Abmelden" title="Abmelden">⏻</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
<header class="mobile-header">
|
<header class="mobile-header">
|
||||||
<div class="mobile-header-row">
|
<div class="mobile-header-row">
|
||||||
<div class="mobile-group-name" id="groupNameDisplay">Gruppe</div>
|
<div class="mobile-group-name" id="groupNameDisplay">Gruppe</div>
|
||||||
|
<span id="mobileWsStatus" class="mobile-ws-status is-disconnected"
|
||||||
|
role="status" aria-live="polite" title="WebSocket: getrennt">WS: getrennt</span>
|
||||||
<button type="button" id="mobileInstallBtn" class="mobile-icon-btn" aria-label="App installieren" title="App installieren" hidden>📲</button>
|
<button type="button" id="mobileInstallBtn" class="mobile-icon-btn" aria-label="App installieren" title="App installieren" hidden>📲</button>
|
||||||
<button type="button" id="mobileLogout" class="mobile-icon-btn" aria-label="Abmelden" title="Abmelden">⏻</button>
|
<button type="button" id="mobileLogout" class="mobile-icon-btn" aria-label="Abmelden" title="Abmelden">⏻</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+65
-4
@@ -96,6 +96,7 @@ Nach erfolgreicher Prüfung antwortet der Server mit einer Code-0-Bestätigung:
|
|||||||
"sender_id": 0,
|
"sender_id": 0,
|
||||||
"receiver_id": null,
|
"receiver_id": null,
|
||||||
"ts": 1793449907241,
|
"ts": 1793449907241,
|
||||||
|
"seq": 1,
|
||||||
"msg": "authenticated"
|
"msg": "authenticated"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -115,6 +116,7 @@ Alle Nachrichten werden als JSON-Text übertragen:
|
|||||||
"receiver_id": 20,
|
"receiver_id": 20,
|
||||||
"code": 100,
|
"code": 100,
|
||||||
"ts": 1793449907246,
|
"ts": 1793449907246,
|
||||||
|
"seq": 42,
|
||||||
"msg": "{\"street_id\": 30, \"state\": \"erledigt\"}"
|
"msg": "{\"street_id\": 30, \"state\": \"erledigt\"}"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -124,8 +126,24 @@ Alle Nachrichten werden als JSON-Text übertragen:
|
|||||||
- `receiver_id`: Empfänger-ID, soweit sinnvoll; bei Broadcasts `null`.
|
- `receiver_id`: Empfänger-ID, soweit sinnvoll; bei Broadcasts `null`.
|
||||||
- `code`: primäres Steuerungsmerkmal.
|
- `code`: primäres Steuerungsmerkmal.
|
||||||
- `ts`: Zeitstempel in Millisekunden.
|
- `ts`: Zeitstempel in Millisekunden.
|
||||||
|
- `seq`: fortlaufende Sequenznummer für genau diese Client-ID.
|
||||||
- `msg`: Text oder JSON-String mit dem fachlichen Inhalt.
|
- `msg`: Text oder JSON-String mit dem fachlichen Inhalt.
|
||||||
|
|
||||||
|
Die Sequenznummer wird vom Broker erst beim tatsächlichen Versand an eine
|
||||||
|
Client-Verbindung ergänzt. Jede Client-ID besitzt eine eigene Zählung; mehrere
|
||||||
|
Clients desselben Accounts beeinflussen sich nicht. Die Zählung beginnt bei 1
|
||||||
|
und bleibt über einen WebSocket-Reconnect derselben Webview erhalten. Wird eine
|
||||||
|
Nachricht gepuffert, erhält sie ihre Sequenznummer erst bei der späteren
|
||||||
|
Zustellung. Ein fehlgeschlagener Sendevorgang verbraucht keine Sequenznummer.
|
||||||
|
Nach einem Neuladen der Seite entsteht eine neue Client-ID und damit eine neue
|
||||||
|
Zählung ab 1.
|
||||||
|
|
||||||
|
Clients merken sich die zuletzt empfangene Sequenznummer. Trifft nach einem
|
||||||
|
Reconnect eine andere Nummer als `zuletzt + 1` ein, zeigt der Client einen
|
||||||
|
Code-99-ähnlichen Neulade-Dialog an. Die Sequenzzählung liegt bewusst nur im
|
||||||
|
Broker-Prozess und nicht in der Datenbank; nach einem Broker-Neustart beginnt
|
||||||
|
sie neu und löst bei bereits geöffneten Clients den Neulade-Hinweis aus.
|
||||||
|
|
||||||
`sender_id` und `receiver_id` werden nicht in jedem Fall mit lesbaren Namen
|
`sender_id` und `receiver_id` werden nicht in jedem Fall mit lesbaren Namen
|
||||||
ergänzt. Chat-Nachrichten enthalten zusätzlich ein `sender`-Objekt mit
|
ergänzt. Chat-Nachrichten enthalten zusätzlich ein `sender`-Objekt mit
|
||||||
Accountname, Rolle und Gruppenalias. Bei Code 100/200/300 enthält das Payload
|
Accountname, Rolle und Gruppenalias. Bei Code 100/200/300 enthält das Payload
|
||||||
@@ -176,7 +194,7 @@ Der Broker sendet standardmäßig jede Minute eine Nachricht mit Code 1 an alle
|
|||||||
authentifizierten Verbindungen:
|
authentifizierten Verbindungen:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{"sender_id": 0, "receiver_id": null, "code": 1, "ts": 1793449907241, "msg": "ping"}
|
{"sender_id": 0, "receiver_id": null, "code": 1, "ts": 1793449907241, "seq": 17, "msg": "ping"}
|
||||||
```
|
```
|
||||||
|
|
||||||
Die Heartbeat-Routine läuft in einem Daemon-Timer. Sie räumt zusätzlich
|
Die Heartbeat-Routine läuft in einem Daemon-Timer. Sie räumt zusätzlich
|
||||||
@@ -282,6 +300,41 @@ Aktuelle Implementierung:
|
|||||||
aber keinen Historieneintrag und keinen Transaktionseintrag.
|
aber keinen Historieneintrag und keinen Transaktionseintrag.
|
||||||
- Das Payload enthält `group_id`, `lat`, `lon`, `ts` und `actor`.
|
- Das Payload enthält `group_id`, `lat`, `lon`, `ts` und `actor`.
|
||||||
|
|
||||||
|
### Anzeige in den Clients
|
||||||
|
|
||||||
|
Nach der Zustellung müssen die Clients ihren lokalen Zustand und ihre Oberfläche
|
||||||
|
aktualisieren. Der aktuelle Stand:
|
||||||
|
|
||||||
|
- **Mobile Clients**: Im Kopf der Gruppen- und Dispatcher-Mobil-Ansicht zeigt
|
||||||
|
ein Statusfeld den WebSocket-Zustand (`verbinde`, `verbunden`, `getrennt`,
|
||||||
|
`Fehler`). Die Anzeige wird bei Verbindungsaufbau, Code-0-Bestätigung,
|
||||||
|
Heartbeat, Trennung und Tokenfehler aktualisiert.
|
||||||
|
- **Dispatcher und Beobachter** (`dispatcher.js`): Code 100 aktualisiert den
|
||||||
|
Straßenzustand, färbt die Karte neu und synchronisiert ein offenes
|
||||||
|
Straßenfenster sowie die Straßenliste einer offenen Gruppe. Code 200
|
||||||
|
aktualisiert Status-Badge und Statusauswahl der Gruppe sowie die
|
||||||
|
Gruppensteuerung. Code 300 verschiebt den Gruppenmarker und aktualisiert
|
||||||
|
Positionsalter, Fortschrittsanzeige und Navigationsbutton.
|
||||||
|
- **Dispatcher Mobil** (`mobile.js`, `mobile_dispatcher`): Code 100
|
||||||
|
aktualisiert die Straßenliste, die aktuell gezeichnete Straße und ein
|
||||||
|
offenes Bearbeitungsfenster. Neu zugewiesene Straßen werden aufgenommen,
|
||||||
|
abgegebene Straßen entfernt. Code 200 aktualisiert den Gruppenstatus und den
|
||||||
|
Statustext im Gruppenauswahlfeld. Code 300 zeichnet alle Gruppenpositionen
|
||||||
|
neu und aktualisiert den Navigationsbutton.
|
||||||
|
- **Gruppen-View** (`mobile.js`, `mobile_group`): Code 100 aktualisiert die
|
||||||
|
ToDo-Liste und die Karte der eigenen Straßen. Code 200 aktualisiert den
|
||||||
|
Gruppenstatus im lokalen Zustand. Code 300 aktualisiert die Gruppendaten;
|
||||||
|
die eigene Position wird in dieser Ansicht weiterhin durch den lokalen
|
||||||
|
GPS-Marker dargestellt, deshalb wird kein zusätzlicher Gruppenmarker
|
||||||
|
gezeichnet.
|
||||||
|
- **Chat**: Eingehende Chat-Nachrichten werden im Chat-Verlauf ergänzt und
|
||||||
|
lösen Ton bzw. Benachrichtigung aus. Sie wechseln nicht mehr automatisch in
|
||||||
|
den Chat-Tab, damit die Kartenansicht während der Arbeit sichtbar bleibt.
|
||||||
|
- **Sequenzprüfung**: Mobile Clients, Dispatcher/Beobachter und der Admin-
|
||||||
|
Reload-Watcher vergleichen jede empfangene `seq` mit ihrer letzten Zählung.
|
||||||
|
Bei einer Lücke erscheint der Neulade-Dialog; die Nachricht wird trotzdem
|
||||||
|
verarbeitet.
|
||||||
|
|
||||||
## 6. Chat-Nachrichten ab Code 1000
|
## 6. Chat-Nachrichten ab Code 1000
|
||||||
|
|
||||||
Alle Nachrichten ab Code 1000 werden in `ws_messages_store` persistiert. Sie
|
Alle Nachrichten ab Code 1000 werden in `ws_messages_store` persistiert. Sie
|
||||||
@@ -336,13 +389,17 @@ Absenders sein; Nachrichten an eine fremde Gruppe werden abgewiesen.
|
|||||||
```text
|
```text
|
||||||
connections[tenant_id][client_id] = {
|
connections[tenant_id][client_id] = {
|
||||||
ws, account_id, client_id, role, group_id,
|
ws, account_id, client_id, role, group_id,
|
||||||
last_ping, connected_at, last_pong_at, send_lock
|
last_ping, connected_at, last_pong_at, send_lock, seq
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Eine Client-ID gehört genau zu einer Webview. Ein Account kann daher mehrere
|
Eine Client-ID gehört genau zu einer Webview. Ein Account kann daher mehrere
|
||||||
Clients parallel betreiben. Eine neue Verbindung mit derselben Client-ID ersetzt
|
Clients parallel betreiben. Eine neue Verbindung mit derselben Client-ID ersetzt
|
||||||
nur diese eine Verbindung; andere Clients desselben Accounts bleiben erhalten.
|
nur diese eine Verbindung; andere Clients desselben Accounts bleiben erhalten.
|
||||||
|
Die zuletzt zugestellte Sequenznummer wird zusätzlich in
|
||||||
|
`client_sequences[(tenant_id, client_id)]` geführt, damit sie einen Reconnect
|
||||||
|
überlebt. `client_sequence_locks[(tenant_id, client_id)]` serialisiert
|
||||||
|
Sequenzvergabe und Versand pro Client.
|
||||||
|
|
||||||
`authenticated[tenant_id][client_id]` speichert den Authentifizierungsstatus.
|
`authenticated[tenant_id][client_id]` speichert den Authentifizierungsstatus.
|
||||||
Ohne erfolgreichen Code-0-Handshake werden keine fachlichen Nachrichten
|
Ohne erfolgreichen Code-0-Handshake werden keine fachlichen Nachrichten
|
||||||
@@ -352,7 +409,8 @@ Zusätzlich hält der Broker:
|
|||||||
|
|
||||||
- `client_accounts[(tenant_id, client_id)] = account_id`,
|
- `client_accounts[(tenant_id, client_id)] = account_id`,
|
||||||
- `account_clients[(tenant_id, account_id)] = {client_id, ...}`,
|
- `account_clients[(tenant_id, account_id)] = {client_id, ...}`,
|
||||||
- `disconnected_clients[(tenant_id, client_id)] = Zeitpunkt`.
|
- `disconnected_clients[(tenant_id, client_id)] = Zeitpunkt`,
|
||||||
|
- `client_sequences[(tenant_id, client_id)] = letzte Sequenznummer`.
|
||||||
|
|
||||||
Diese Zuordnungen bleiben nach einem Verbindungsabbruch erhalten, damit
|
Diese Zuordnungen bleiben nach einem Verbindungsabbruch erhalten, damit
|
||||||
kurzfristige Reconnects ihre Queue wiederfinden. Dauerhaft verlassene Webviews
|
kurzfristige Reconnects ihre Queue wiederfinden. Dauerhaft verlassene Webviews
|
||||||
@@ -387,7 +445,10 @@ zuerst die Authentifizierung:
|
|||||||
|
|
||||||
Der direkte Versand erfolgt pro Verbindung über einen `send_lock`. Dadurch
|
Der direkte Versand erfolgt pro Verbindung über einen `send_lock`. Dadurch
|
||||||
werden Heartbeat, Route-Thread und HTTP-ausgelöste Broadcasts nicht gleichzeitig
|
werden Heartbeat, Route-Thread und HTTP-ausgelöste Broadcasts nicht gleichzeitig
|
||||||
in denselben Socket schreiben.
|
in denselben Socket schreiben. Zusätzlich serialisiert ein pro Client-ID
|
||||||
|
geführtes `sequence_lock` die Sequenzvergabe und den Sendevorgang. Erst nach
|
||||||
|
erfolgreichem `send()` wird die Sequenznummer fortgeschrieben; schlägt der
|
||||||
|
Versand fehl, bleibt sie unverändert und die Nachricht wird gepuffert.
|
||||||
|
|
||||||
### Client-Queues
|
### Client-Queues
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user