Indie and Retro Gaming Reviews from the one and only IGC
document.getElementById('refreshBtn').addEventListener('click', () => if (pollInterval) clearInterval(pollInterval); fetchNewCode(); );
async function activateDevice(code) messageDiv.innerHTML = ''; try const res = await fetch('/api/activate', method: 'POST', headers: 'Content-Type': 'application/json' , body: JSON.stringify( code, deviceId: 'web-browser' ) ); const data = await res.json(); if (res.ok) messageDiv.innerHTML = '✅ Success! Your TV is now activated. Enjoy Viaplay!'; messageDiv.className = 'success'; codeInput.value = ''; else messageDiv.innerHTML = ❌ $data.error ; messageDiv.className = 'error';
// 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 ); activate viaplay
// API: Activate code (user submits from browser) app.post('/api/activate', (req, res) => 'unknown-device'; res.json( success: true, message: 'Device activated successfully' ); );
// Auto-expire after 10 minutes setTimeout(() => if (codes.get(code)?.status === 'pending') codes.delete(code); document
res.json( code ); );
// Store activation codes and their status let codes = new Map(); // code -> status, deviceId, createdAt if (pollInterval) clearInterval(pollInterval)
, 3000); // check every 3 seconds
You must be logged in to post a comment.