remove the flag waiting to ensure the reconnexion from the iframe
This commit is contained in:
parent
08bc930675
commit
6137b99d56
@ -512,32 +512,12 @@ export async function registerAllListeners() {
|
||||
|
||||
const handleGetPairingId = async (event: MessageEvent) => {
|
||||
console.log(`[Router:API] 📨 Message ${MessageType.GET_PAIRING_ID} reçu`);
|
||||
console.log('[Router:API] GET_PAIRING_ID: Vérification du drapeau __PAIRING_READY...');
|
||||
const maxWait = 10000; // 10 sec (doit être > au timeout de handleRequestLink)
|
||||
let waited = 0;
|
||||
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
while (!(window as any).__PAIRING_READY && waited < maxWait) {
|
||||
await delay(100);
|
||||
waited += 100;
|
||||
}
|
||||
|
||||
if ((window as any).__PAIRING_READY === 'error') {
|
||||
console.error('[Router:API] GET_PAIRING_ID: Auto-pairing (home.ts) a échoué.');
|
||||
throw new Error('Auto-pairing failed');
|
||||
}
|
||||
if (!(window as any).__PAIRING_READY) {
|
||||
console.error('[Router:API] GET_PAIRING_ID: Timeout en attente de __PAIRING_READY.');
|
||||
throw new Error('Auto-pairing timed out');
|
||||
}
|
||||
|
||||
console.log('[Router:API] GET_PAIRING_ID: Feu vert de home.ts reçu. Polling de la BDD...');
|
||||
|
||||
const maxRetries = 10;
|
||||
const retryDelay = 300;
|
||||
let pairingId: string | null = null;
|
||||
|
||||
// Boucle de polling (maintenant sécurisée après l'attente)
|
||||
// Boucle de polling
|
||||
for (let i = 0; i < maxRetries; i++) {
|
||||
// On lit DIRECTEMENT la BDD (la "source de vérité")
|
||||
const device = await services.getDeviceFromDatabase();
|
||||
@ -558,10 +538,7 @@ export async function registerAllListeners() {
|
||||
// Si la boucle se termine sans succès
|
||||
if (!pairingId) {
|
||||
console.error(`[Router:API] GET_PAIRING_ID: Échec final, non trouvé en BDD après ${maxRetries} tentatives.`);
|
||||
// On vérifie si l'appareil existe (debug)
|
||||
const finalDevice = await services.getDeviceFromDatabase();
|
||||
console.log("[Router:API] GET_PAIRING_ID: État final de l'appareil:", finalDevice);
|
||||
throw new Error('Device not paired (post-wait)');
|
||||
throw new Error('Device not paired');
|
||||
}
|
||||
|
||||
const { accessToken } = event.data;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user