From 6137b99d563fbb7c4c4c96f8cee1b1e1784d0e31 Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Fri, 14 Nov 2025 10:33:38 +0100 Subject: [PATCH] remove the flag waiting to ensure the reconnexion from the iframe --- src/router.ts | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/src/router.ts b/src/router.ts index 8bc9e18..ab94907 100755 --- a/src/router.ts +++ b/src/router.ts @@ -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;