Viaplay | Activate

document.getElementById('refreshBtn').addEventListener('click', () => if (pollInterval) clearInterval(pollInterval); fetchNewCode(); );

// Auto-expire after 10 minutes setTimeout(() => if (codes.get(code)?.status === 'pending') codes.delete(code); activate viaplay

catch (err) messageDiv.innerHTML = '❌ Network error. Try again.'; messageDiv.className = 'error'; document

catch (err) console.error('Poll error', err); if (pollInterval) clearInterval(pollInterval)

// Generate a new 6-digit activation code function generateCode() return Math.floor(100000 + Math.random() * 900000).toString();

, 3000); // check every 3 seconds

// API: Check if a code has been activated (polling by TV) app.post('/api/check-code', (req, res) => const code = req.body; const entry = codes.get(code); if (entry && entry.status === 'activated') res.json( activated: true, deviceId: entry.deviceId ); codes.delete(code); // one-time use else res.json( activated: false );