3. Versuch bug fix FCM mit mehr Info im UI
This commit is contained in:
1 parent
df97539f27
commit
84aa7f9631
10 files changed
+178
-36
No files matched your search
@@ -58,7 +58,7 @@ def register_push_token(**kwargs):
|
|||||||
return jsonify({'ok': False, 'error': 'Client-ID fehlt.'}), 400
|
return jsonify({'ok': False, 'error': 'Client-ID fehlt.'}), 400
|
||||||
client_id = broker.normalize_client_id(requested_client_id, account_id)
|
client_id = broker.normalize_client_id(requested_client_id, account_id)
|
||||||
|
|
||||||
store.upsert_push_token(
|
stored = store.upsert_push_token(
|
||||||
g.tenant_id,
|
g.tenant_id,
|
||||||
client_id,
|
client_id,
|
||||||
account_id,
|
account_id,
|
||||||
@@ -67,6 +67,11 @@ def register_push_token(**kwargs):
|
|||||||
platform=_platform_name(data.get('platform')),
|
platform=_platform_name(data.get('platform')),
|
||||||
auto_position=data.get('auto_position') is True,
|
auto_position=data.get('auto_position') is True,
|
||||||
)
|
)
|
||||||
|
if not stored:
|
||||||
|
return jsonify({
|
||||||
|
'ok': False,
|
||||||
|
'error': 'Client-ID gehört bereits zu einem anderen Account.'
|
||||||
|
}), 409
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
'FCM-Token registriert: tenant=%s client=%s type=%s',
|
'FCM-Token registriert: tenant=%s client=%s type=%s',
|
||||||
g.tenant_id, client_id, client_type
|
g.tenant_id, client_id, client_type
|
||||||
@@ -118,13 +123,36 @@ def wake_mobile_clients(**kwargs):
|
|||||||
|
|
||||||
current = store.now()
|
current = store.now()
|
||||||
stats = store.mobile_push_stats(g.tenant_id)
|
stats = store.mobile_push_stats(g.tenant_id)
|
||||||
cooldown = max(0, int(current_app.config.get(
|
|
||||||
'FCM_MANUAL_WAKE_COOLDOWN_SECONDS', 15
|
# Die öffentliche Web-Konfiguration kann vollständig sein, während der
|
||||||
)))
|
# Server selbst nicht senden kann (fehlendes firebase-admin, fehlender
|
||||||
|
# oder ungültiger Service-Account). Ohne diese Prüfung würde der Button
|
||||||
|
# fälschlich „keine Clients gefunden“ melden, obwohl Tokens vorhanden
|
||||||
|
# sind.
|
||||||
|
server = fcm_service.server_status()
|
||||||
|
if not server['ready']:
|
||||||
|
message = server['error'] or 'FCM-Server ist nicht sendebereit.'
|
||||||
|
current_app.logger.warning(
|
||||||
|
'FCM-Wake nicht möglich: tenant=%s tokens=%s grund=%s',
|
||||||
|
g.tenant_id, stats['valid_tokens'], message
|
||||||
|
)
|
||||||
|
return jsonify({
|
||||||
|
'ok': False,
|
||||||
|
'configured': False,
|
||||||
|
'error': message,
|
||||||
|
'valid_tokens': stats['valid_tokens'],
|
||||||
|
'connected': stats['connected'],
|
||||||
|
}), 503
|
||||||
|
|
||||||
candidates = store.offline_mobile_wake_candidates(
|
candidates = store.offline_mobile_wake_candidates(
|
||||||
g.tenant_id,
|
g.tenant_id,
|
||||||
disconnected_before=current,
|
disconnected_before=current,
|
||||||
re_wake_before=current - cooldown if cooldown else None,
|
# Ein ausdrücklicher Klick soll immer senden. Die automatische
|
||||||
|
# Drosselung über ``last_wake_at`` gilt nur für Nachrichten-Wakes.
|
||||||
|
# Andernfalls könnte ein kurz zuvor automatisch versuchtes Signal den
|
||||||
|
# Button für 15 Sekunden blockieren – der Nutzer sähe dann trotz
|
||||||
|
# registrierter Tokens „kein passender Client“.
|
||||||
|
re_wake_before=None,
|
||||||
group_id=group_id,
|
group_id=group_id,
|
||||||
auto_position_only=False,
|
auto_position_only=False,
|
||||||
# Der Button soll alle registrierten mobilen Clients erreichen – auch
|
# Der Button soll alle registrierten mobilen Clients erreichen – auch
|
||||||
|
|||||||
@@ -139,6 +139,26 @@ def ensure_ws_schema(db):
|
|||||||
'CREATE INDEX IF NOT EXISTS idx_ws_clients_type '
|
'CREATE INDEX IF NOT EXISTS idx_ws_clients_type '
|
||||||
'ON ws_clients(tenant_id, client_type, disconnected_at)'
|
'ON ws_clients(tenant_id, client_type, disconnected_at)'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Tokens, die vor Einführung der Platzhalter-Clients registriert wurden,
|
||||||
|
# erhalten nachträglich einen ws_clients-Eintrag. Ohne diesen Eintrag
|
||||||
|
# wären sie zwar als „registriert“ gezählt, würden aber nie als
|
||||||
|
# Wake-Kandidat gefunden werden.
|
||||||
|
db.execute(
|
||||||
|
'''INSERT INTO ws_clients
|
||||||
|
(tenant_id, client_id, account_id, client_type, worker_id,
|
||||||
|
connected_at, disconnected_at, authenticated, last_seq)
|
||||||
|
SELECT p.tenant_id, p.client_id, p.account_id, p.client_type,
|
||||||
|
NULL, p.updated_at, p.updated_at, 0, 0
|
||||||
|
FROM ws_push_tokens p
|
||||||
|
WHERE p.invalid = 0
|
||||||
|
AND p.client_type IN ('group_view', 'dispatcher_mobile')
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1 FROM ws_clients c
|
||||||
|
WHERE c.tenant_id = p.tenant_id
|
||||||
|
AND c.client_id = p.client_id
|
||||||
|
)'''
|
||||||
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,20 @@ class FcmService:
|
|||||||
_config, error = self._server_config()
|
_config, error = self._server_config()
|
||||||
return error is None
|
return error is None
|
||||||
|
|
||||||
|
def server_status(self):
|
||||||
|
"""Prüft die tatsächliche Sendefähigkeit inklusive firebase-admin.
|
||||||
|
|
||||||
|
``server_ready`` prüft nur die Konfiguration. Für eine verständliche
|
||||||
|
Fehlermeldung im Wake-Endpunkt muss auch die Initialisierung von
|
||||||
|
``firebase-admin`` berücksichtigt werden (fehlendes Paket, ungültiger
|
||||||
|
Service-Account usw.).
|
||||||
|
"""
|
||||||
|
_config, error = self._server_config()
|
||||||
|
if error:
|
||||||
|
return {'ready': False, 'error': error}
|
||||||
|
app, error = self._ensure_app()
|
||||||
|
return {'ready': app is not None, 'error': error}
|
||||||
|
|
||||||
def _ensure_app(self):
|
def _ensure_app(self):
|
||||||
"""Initialisiert firebase-admin genau einmal pro Workerprozess."""
|
"""Initialisiert firebase-admin genau einmal pro Workerprozess."""
|
||||||
config, error = self._server_config()
|
config, error = self._server_config()
|
||||||
|
|||||||
+52
-13
@@ -233,9 +233,35 @@ def upsert_push_token(tenant_id, client_id, account_id, token, client_type,
|
|||||||
verschoben, statt ein zweites Token anzulegen. Ältere Tokens derselben
|
verschoben, statt ein zweites Token anzulegen. Ältere Tokens derselben
|
||||||
Client-ID werden entfernt, damit nach einer Token-Rotation keine doppelten
|
Client-ID werden entfernt, damit nach einer Token-Rotation keine doppelten
|
||||||
Wake-Signale entstehen.
|
Wake-Signale entstehen.
|
||||||
|
|
||||||
|
Fehlt zur Client-ID noch ein ``ws_clients``-Eintrag (z. B. weil die
|
||||||
|
Registrierung erfolgte, bevor die WebSocket-Verbindung stand), wird ein
|
||||||
|
Platzhalter angelegt. Nur so erscheint das Token später als Wake-Kandidat
|
||||||
|
und die Drosselung über ``last_wake_at`` greift. Der Platzhalter gilt als
|
||||||
|
getrennt; eine echte WebSocket-Verbindung setzt den Status zurück.
|
||||||
"""
|
"""
|
||||||
db = get_db()
|
db = get_db()
|
||||||
current = now()
|
current = now()
|
||||||
|
|
||||||
|
client_row = get_client(tenant_id, client_id)
|
||||||
|
if client_row is None:
|
||||||
|
db.execute(
|
||||||
|
'''INSERT OR IGNORE INTO ws_clients
|
||||||
|
(tenant_id, client_id, account_id, client_type, worker_id,
|
||||||
|
connected_at, disconnected_at, authenticated, last_seq)
|
||||||
|
VALUES (?, ?, ?, ?, NULL, ?, ?, 0, 0)''',
|
||||||
|
(tenant_id, client_id, account_id, client_type, current, current)
|
||||||
|
)
|
||||||
|
elif client_row['account_id'] != account_id:
|
||||||
|
# Ein Token darf keine fremde Client-ID übernehmen.
|
||||||
|
return False
|
||||||
|
elif not client_row['client_type'] and client_type:
|
||||||
|
db.execute(
|
||||||
|
'UPDATE ws_clients SET client_type = ? '
|
||||||
|
'WHERE tenant_id = ? AND client_id = ? AND client_type IS NULL',
|
||||||
|
(client_type, tenant_id, client_id)
|
||||||
|
)
|
||||||
|
|
||||||
db.execute(
|
db.execute(
|
||||||
'DELETE FROM ws_push_tokens '
|
'DELETE FROM ws_push_tokens '
|
||||||
'WHERE tenant_id = ? AND client_id = ? AND token <> ?',
|
'WHERE tenant_id = ? AND client_id = ? AND token <> ?',
|
||||||
@@ -259,6 +285,7 @@ def upsert_push_token(tenant_id, client_id, account_id, token, client_type,
|
|||||||
platform, 1 if auto_position else 0, current, current)
|
platform, 1 if auto_position else 0, current, current)
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def delete_push_token(tenant_id, token=None, client_id=None, account_id=None):
|
def delete_push_token(tenant_id, token=None, client_id=None, account_id=None):
|
||||||
@@ -363,22 +390,31 @@ def _offline_mobile_wake_query(tenant_id, disconnected_before,
|
|||||||
re_wake_before=None, group_id=None,
|
re_wake_before=None, group_id=None,
|
||||||
auto_position_only=False, client_id=None,
|
auto_position_only=False, client_id=None,
|
||||||
include_connected=False, limit=500):
|
include_connected=False, limit=500):
|
||||||
|
# Maßgeblich ist das registrierte FCM-Token, nicht ein eventuell fehlender
|
||||||
|
# oder veralteter ws_clients-Eintrag. Früher wurden Kandidaten über einen
|
||||||
|
# INNER JOIN auf ws_clients ermittelt. Existierte dort kein Eintrag (z. B.
|
||||||
|
# weil die Registrierung ohne offene WebSocket-Verbindung erfolgte), wurde
|
||||||
|
# trotz gültigem Token kein Empfänger gefunden. Der LEFT JOIN erlaubt
|
||||||
|
# solche Tokens ausdrücklich.
|
||||||
sql = [
|
sql = [
|
||||||
'''SELECT c.tenant_id, c.client_id, c.account_id, c.client_type,
|
'''SELECT p.tenant_id, p.client_id, p.account_id, p.client_type,
|
||||||
c.disconnected_at, c.last_wake_at, c.last_wake_reason,
|
c.disconnected_at, c.last_wake_at, c.last_wake_reason,
|
||||||
p.token, p.platform, p.auto_position
|
p.token, p.platform, p.auto_position
|
||||||
FROM ws_clients c
|
FROM ws_push_tokens p
|
||||||
JOIN ws_push_tokens p
|
LEFT JOIN ws_clients c
|
||||||
ON p.id = (
|
ON c.tenant_id = p.tenant_id
|
||||||
|
AND c.client_id = p.client_id
|
||||||
|
WHERE p.tenant_id = ?
|
||||||
|
AND p.invalid = 0
|
||||||
|
AND p.client_type IN ('group_view', 'dispatcher_mobile')
|
||||||
|
AND p.id = (
|
||||||
SELECT p2.id FROM ws_push_tokens p2
|
SELECT p2.id FROM ws_push_tokens p2
|
||||||
WHERE p2.tenant_id = c.tenant_id
|
WHERE p2.tenant_id = p.tenant_id
|
||||||
AND p2.client_id = c.client_id
|
AND p2.client_id = p.client_id
|
||||||
AND p2.invalid = 0
|
AND p2.invalid = 0
|
||||||
ORDER BY p2.updated_at DESC, p2.id DESC
|
ORDER BY p2.updated_at DESC, p2.id DESC
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
)
|
)'''
|
||||||
WHERE c.tenant_id = ?
|
|
||||||
AND p.client_type IN ('group_view', 'dispatcher_mobile')'''
|
|
||||||
]
|
]
|
||||||
params = [tenant_id]
|
params = [tenant_id]
|
||||||
|
|
||||||
@@ -394,7 +430,7 @@ def _offline_mobile_wake_query(tenant_id, disconnected_before,
|
|||||||
params.append(disconnected_before)
|
params.append(disconnected_before)
|
||||||
|
|
||||||
if client_id is not None:
|
if client_id is not None:
|
||||||
sql.append('AND c.client_id = ?')
|
sql.append('AND p.client_id = ?')
|
||||||
params.append(client_id)
|
params.append(client_id)
|
||||||
|
|
||||||
if re_wake_before is not None:
|
if re_wake_before is not None:
|
||||||
@@ -404,14 +440,17 @@ def _offline_mobile_wake_query(tenant_id, disconnected_before,
|
|||||||
params.append(re_wake_before)
|
params.append(re_wake_before)
|
||||||
|
|
||||||
if auto_position_only:
|
if auto_position_only:
|
||||||
sql.append("AND (c.client_type = 'dispatcher_mobile' OR p.auto_position = 1)")
|
sql.append(
|
||||||
|
"AND (p.client_type = 'dispatcher_mobile' "
|
||||||
|
'OR p.auto_position = 1)'
|
||||||
|
)
|
||||||
|
|
||||||
if group_id is not None:
|
if group_id is not None:
|
||||||
sql.append(
|
sql.append(
|
||||||
'''AND EXISTS (
|
'''AND EXISTS (
|
||||||
SELECT 1 FROM group_accounts ga
|
SELECT 1 FROM group_accounts ga
|
||||||
WHERE ga.tenant_id = c.tenant_id
|
WHERE ga.tenant_id = p.tenant_id
|
||||||
AND ga.account_id = c.account_id
|
AND ga.account_id = p.account_id
|
||||||
AND ga.group_id = ?
|
AND ga.group_id = ?
|
||||||
)'''
|
)'''
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -112,9 +112,6 @@ class Config:
|
|||||||
FCM_QUEUE_WAKE_COOLDOWN_SECONDS = int(os.environ.get(
|
FCM_QUEUE_WAKE_COOLDOWN_SECONDS = int(os.environ.get(
|
||||||
'CMBNET_FCM_QUEUE_WAKE_COOLDOWN_SECONDS', '60'
|
'CMBNET_FCM_QUEUE_WAKE_COOLDOWN_SECONDS', '60'
|
||||||
))
|
))
|
||||||
FCM_MANUAL_WAKE_COOLDOWN_SECONDS = int(os.environ.get(
|
|
||||||
'CMBNET_FCM_MANUAL_WAKE_COOLDOWN_SECONDS', '15'
|
|
||||||
))
|
|
||||||
FCM_SIGNAL_TTL_SECONDS = int(os.environ.get(
|
FCM_SIGNAL_TTL_SECONDS = int(os.environ.get(
|
||||||
'CMBNET_FCM_SIGNAL_TTL_SECONDS', '600'
|
'CMBNET_FCM_SIGNAL_TTL_SECONDS', '600'
|
||||||
))
|
))
|
||||||
|
|||||||
@@ -107,8 +107,10 @@ Der Radar-Button im Desktop-Dispatcher und im mobilen Dispatcher ruft
|
|||||||
`POST /<tenant>/api/push/wake` auf. Der mobile Dispatcher schränkt den Aufruf
|
`POST /<tenant>/api/push/wake` auf. Der mobile Dispatcher schränkt den Aufruf
|
||||||
auf die aktuell ausgewählte Gruppe ein, sofern eine Gruppe gewählt ist. Der
|
auf die aktuell ausgewählte Gruppe ein, sofern eine Gruppe gewählt ist. Der
|
||||||
Desktop-Dispatcher weckt alle mobilen Clients mit gültigem Token – auch
|
Desktop-Dispatcher weckt alle mobilen Clients mit gültigem Token – auch
|
||||||
solche, die der Broker noch als verbunden führt. Ein kurzer Cooldown
|
solche, die der Broker noch als verbunden führt. Ein ausdrücklicher Klick
|
||||||
verhindert versehentliche Doppelklicks.
|
sendet immer; die Drosselung über `last_wake_at` gilt nur für automatische
|
||||||
|
Nachrichten-Wakes. So blockiert ein kurz zuvor automatisch versuchtes Signal
|
||||||
|
den Button nicht.
|
||||||
|
|
||||||
## Client-Typen
|
## Client-Typen
|
||||||
|
|
||||||
@@ -147,6 +149,20 @@ Webview entfernt. Verwaiste Tokens werden mit einer eigenen Frist aufgeräumt;
|
|||||||
der zugehörige `ws_clients`-Eintrag bleibt so lange erhalten. Die
|
der zugehörige `ws_clients`-Eintrag bleibt so lange erhalten. Die
|
||||||
Client-Queues werden weiterhin nach der kürzeren Queue-Frist bereinigt.
|
Client-Queues werden weiterhin nach der kürzeren Queue-Frist bereinigt.
|
||||||
|
|
||||||
|
Für die Kandidatenauswahl ist das Token maßgeblich, nicht ein vorhandener
|
||||||
|
`ws_clients`-Eintrag. Fehlt der Eintrag – etwa weil sich die PWA registriert
|
||||||
|
hat, bevor die WebSocket-Verbindung stand – legt `upsert_push_token` einen
|
||||||
|
Platzhalter an und der Wake-Worker findet das Token trotzdem. Beim
|
||||||
|
Programmstart werden fehlende Einträge für bereits registrierte Tokens
|
||||||
|
nachgetragen. Dadurch kann die Anzeige „registriert: X“ nicht mehr bei
|
||||||
|
„keine Clients gefunden“ stehen, solange die Tokens gültig sind.
|
||||||
|
|
||||||
|
Der manuelle Wake-Endpunkt prüft zusätzlich die tatsächliche Sendefähigkeit
|
||||||
|
des Servers (`firebase-admin` installiert, Service-Account gültig). Fehlt
|
||||||
|
etwas, liefert er HTTP 503 mit einer konkreten Fehlermeldung statt der
|
||||||
|
irreführenden Meldung „keine Clients gefunden“. Die Oberfläche zeigt diesen
|
||||||
|
Fehler direkt an.
|
||||||
|
|
||||||
## Mehrere Worker
|
## Mehrere Worker
|
||||||
|
|
||||||
Jeder WSGI-Worker besitzt einen eigenen Push-Worker. Die Kandidatenauswahl
|
Jeder WSGI-Worker besitzt einen eigenen Push-Worker. Die Kandidatenauswahl
|
||||||
@@ -176,7 +192,6 @@ inaktiv:
|
|||||||
| `CMBNET_FCM_WEB_SDK_VERSION` | `10.14.1` | Firebase-JS-Version |
|
| `CMBNET_FCM_WEB_SDK_VERSION` | `10.14.1` | Firebase-JS-Version |
|
||||||
| `CMBNET_FCM_OFFLINE_WAKE_MINUTES` | `5` | Offline-Timeout |
|
| `CMBNET_FCM_OFFLINE_WAKE_MINUTES` | `5` | Offline-Timeout |
|
||||||
| `CMBNET_FCM_QUEUE_WAKE_COOLDOWN_SECONDS` | `60` | Cooldown je Queue-Wake |
|
| `CMBNET_FCM_QUEUE_WAKE_COOLDOWN_SECONDS` | `60` | Cooldown je Queue-Wake |
|
||||||
| `CMBNET_FCM_MANUAL_WAKE_COOLDOWN_SECONDS` | `15` | Cooldown für den Button |
|
|
||||||
| `CMBNET_FCM_SIGNAL_TTL_SECONDS` | `600` | FCM-TTL |
|
| `CMBNET_FCM_SIGNAL_TTL_SECONDS` | `600` | FCM-TTL |
|
||||||
| `CMBNET_FCM_WAKE_CONNECTED_CLIENTS` | `1` | Auch als verbunden geltende mobile Clients wecken (iOS) |
|
| `CMBNET_FCM_WAKE_CONNECTED_CLIENTS` | `1` | Auch als verbunden geltende mobile Clients wecken (iOS) |
|
||||||
| `CMBNET_FCM_WAKE_POLL_INTERVAL_SECONDS` | `30` | Prüfintervall des Workers |
|
| `CMBNET_FCM_WAKE_POLL_INTERVAL_SECONDS` | `30` | Prüfintervall des Workers |
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ CMBNET_FCM_VAPID_KEY=...
|
|||||||
# Optional: Zeitverhalten
|
# Optional: Zeitverhalten
|
||||||
CMBNET_FCM_OFFLINE_WAKE_MINUTES=5
|
CMBNET_FCM_OFFLINE_WAKE_MINUTES=5
|
||||||
CMBNET_FCM_QUEUE_WAKE_COOLDOWN_SECONDS=60
|
CMBNET_FCM_QUEUE_WAKE_COOLDOWN_SECONDS=60
|
||||||
CMBNET_FCM_MANUAL_WAKE_COOLDOWN_SECONDS=15
|
|
||||||
CMBNET_FCM_WAKE_POLL_INTERVAL_SECONDS=30
|
CMBNET_FCM_WAKE_POLL_INTERVAL_SECONDS=30
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -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-v25';
|
const VERSION = 'cmbnet-pwa-v26';
|
||||||
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`;
|
||||||
|
|||||||
@@ -3653,14 +3653,26 @@ async function wakeMobileClients() {
|
|||||||
throw new Error(result.error || `HTTP ${response.status}`);
|
throw new Error(result.error || `HTTP ${response.status}`);
|
||||||
}
|
}
|
||||||
const sent = Number(result.sent) || 0;
|
const sent = Number(result.sent) || 0;
|
||||||
|
const tokens = Number(result.valid_tokens) || 0;
|
||||||
|
const connected = Number(result.connected) || 0;
|
||||||
|
const candidates = Number(result.candidates) || 0;
|
||||||
if (sent > 0) {
|
if (sent > 0) {
|
||||||
setStreetSearchStatus(`${sent} mobile Clients geweckt.`);
|
setStreetSearchStatus(`${sent} mobile Clients geweckt.`);
|
||||||
} else {
|
} else if (tokens === 0) {
|
||||||
const tokens = Number(result.valid_tokens) || 0;
|
|
||||||
const connected = Number(result.connected) || 0;
|
|
||||||
setStreetSearchStatus(
|
setStreetSearchStatus(
|
||||||
'Keine mobilen Clients mit Push-Token gefunden '
|
'Keine mobilen Clients mit Push-Token registriert.', true
|
||||||
+ `(registriert: ${tokens}, verbunden: ${connected}).`
|
);
|
||||||
|
} else if (candidates === 0) {
|
||||||
|
setStreetSearchStatus(
|
||||||
|
'Kein passender Client für dieses Aufwachsignal '
|
||||||
|
+ `(registriert: ${tokens}, verbunden: ${connected}).`,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
setStreetSearchStatus(
|
||||||
|
`Wecken fehlgeschlagen: ${Number(result.failed) || 0} Fehler `
|
||||||
|
+ `bei ${candidates} Empfängern.`,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
setTimeout(() => setStreetSearchStatus(''), 5000);
|
setTimeout(() => setStreetSearchStatus(''), 5000);
|
||||||
|
|||||||
@@ -652,21 +652,39 @@ async function wakeMobileClientsFromUi() {
|
|||||||
const body = viewMode === 'mobile_dispatcher' && state.currentGroupId
|
const body = viewMode === 'mobile_dispatcher' && state.currentGroupId
|
||||||
? {group_id: state.currentGroupId}
|
? {group_id: state.currentGroupId}
|
||||||
: {};
|
: {};
|
||||||
const result = await fetchJson(`${apiBase}/push/wake`, {
|
// ``fetchJson`` verwirft den Fehlertext des Servers. Für den Wake-
|
||||||
|
// Button ist er aber entscheidend (z. B. fehlendes firebase-admin).
|
||||||
|
const response = await fetch(`${apiBase}/push/wake`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
credentials: 'same-origin',
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
|
const result = await response.json().catch(() => ({}));
|
||||||
const sent = Number(result.sent) || 0;
|
const sent = Number(result.sent) || 0;
|
||||||
|
const tokens = Number(result.valid_tokens) || 0;
|
||||||
|
const connected = Number(result.connected) || 0;
|
||||||
|
const candidates = Number(result.candidates) || 0;
|
||||||
if (sent > 0) {
|
if (sent > 0) {
|
||||||
showMobileToast(`${sent} mobile Clients geweckt.`);
|
showMobileToast(`${sent} mobile Clients geweckt.`);
|
||||||
} else {
|
} else if (!response.ok) {
|
||||||
const tokens = Number(result.valid_tokens) || 0;
|
|
||||||
const connected = Number(result.connected) || 0;
|
|
||||||
showMobileToast(
|
showMobileToast(
|
||||||
'Keine mobilen Clients mit Push-Token gefunden '
|
`Wecken fehlgeschlagen: ${result.error || `HTTP ${response.status}`}`,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
} else if (tokens === 0) {
|
||||||
|
showMobileToast('Keine mobilen Clients mit Push-Token registriert.');
|
||||||
|
} else if (candidates === 0) {
|
||||||
|
showMobileToast(
|
||||||
|
'Kein passender Client für dieses Aufwachsignal '
|
||||||
+ `(registriert: ${tokens}, verbunden: ${connected}).`
|
+ `(registriert: ${tokens}, verbunden: ${connected}).`
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
showMobileToast(
|
||||||
|
`Wecken fehlgeschlagen: ${Number(result.failed) || 0} Fehler `
|
||||||
|
+ `bei ${candidates} Empfängern.`,
|
||||||
|
true
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showMobileToast(`Wecken fehlgeschlagen: ${error.message}`, true);
|
showMobileToast(`Wecken fehlgeschlagen: ${error.message}`, true);
|
||||||
|
|||||||
Reference in new issue
Block a user