feat(waiter): native app finds the venue server again after its IP changes
When the saved server address stops answering, the native app re-checks it once and then probes every address in the same /24 (same scheme and port, nearest first, 48 in parallel, 1.5s timeout) for /api/system/identity, switching only to the server that reports THIS venue's site_id - never to "any Xenia server". A found address is saved on the venue and the app reloads onto the same screen (/offline → start page) after a short "Ο server άλλαξε διεύθυνση" notice; the offline queue syncs after reload. - src/native/rediscovery.js: subnet candidates + scan (pure, injectable) - src/native/autoRediscover.js: re-check first, one scan at a time, automatic attempts at most once a minute; skipped for dev / site-less venues - ServerRediscovery: triggers when the connection is confirmed offline (retry every 2 min) or any request fails with a network error - Offline page: manual "Αναζήτηση server στο δίκτυο" with progress and "not found → scan the QR" guidance Tests: 11 unit checks (ordering, port kept, non-IP hosts, other venue never chosen, early stop, progress). Emulator E2E with a real address change (.99 → .2): logged in → found in ~3.5s, back on /tables with live WS; logged out → found in ~6.5s, waiter list loads; server really down → address untouched, manual search reports not found. Web modes unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import client from '../api/client'
|
||||
import { deliveryMode } from '../config/server'
|
||||
import { canRediscover, rediscover } from '../native/autoRediscover'
|
||||
import { useState } from 'react'
|
||||
|
||||
export default function OfflinePage() {
|
||||
const [checking, setChecking] = useState(false)
|
||||
const [search, setSearch] = useState(null) // null | { done, total } | 'not-found'
|
||||
|
||||
async function retry() {
|
||||
setChecking(true)
|
||||
@@ -15,6 +17,19 @@ export default function OfflinePage() {
|
||||
}
|
||||
}
|
||||
|
||||
// Native app: look for this venue's server at a new address on the same network
|
||||
async function searchNetwork() {
|
||||
setSearch({ done: 0, total: 253 })
|
||||
const result = await rediscover({ force: true, onProgress: (done, total) => setSearch({ done, total }) })
|
||||
if (result.status === 'moved' || result.status === 'reachable') {
|
||||
window.location.href = '/'
|
||||
} else {
|
||||
setSearch('not-found')
|
||||
}
|
||||
}
|
||||
|
||||
const searching = search && search !== 'not-found'
|
||||
|
||||
return (
|
||||
<div className="page page--centered">
|
||||
<div style={{ textAlign: 'center', maxWidth: 300 }}>
|
||||
@@ -23,14 +38,30 @@ export default function OfflinePage() {
|
||||
<p style={{ color: '#64748b', marginBottom: 32 }}>
|
||||
Δεν είναι δυνατή η επικοινωνία με το σύστημα. Ελέγξτε τη σύνδεση WiFi.
|
||||
</p>
|
||||
<button className="btn btn--primary btn--lg" onClick={retry} disabled={checking}>
|
||||
<button className="btn btn--primary btn--lg" onClick={retry} disabled={checking || searching}>
|
||||
{checking ? 'Έλεγχος…' : 'Επανάληψη'}
|
||||
</button>
|
||||
{canRediscover() && (
|
||||
<button
|
||||
className="btn btn--secondary btn--lg"
|
||||
style={{ marginTop: 12 }}
|
||||
onClick={searchNetwork}
|
||||
disabled={searching}
|
||||
>
|
||||
{searching ? `Αναζήτηση… ${search.done}/${search.total}` : 'Αναζήτηση server στο δίκτυο'}
|
||||
</button>
|
||||
)}
|
||||
{search === 'not-found' && (
|
||||
<p style={{ color: '#94a3b8', fontSize: 13, marginTop: 12, lineHeight: 1.45 }}>
|
||||
Ο server δεν βρέθηκε στο δίκτυο. Ελέγξτε ότι είναι αναμμένος, ή σαρώστε ξανά το QR από τον διαχειριστή.
|
||||
</p>
|
||||
)}
|
||||
{deliveryMode() === 'native' && (
|
||||
<button
|
||||
className="btn btn--secondary btn--lg"
|
||||
style={{ marginTop: 12 }}
|
||||
onClick={() => { window.location.href = '/venues' }}
|
||||
disabled={searching}
|
||||
>
|
||||
Αλλαγή καταστήματος
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user