/* Human-readable device from the user agent ("iPhone · Safari"), shown to the teacher in "Acceso a la app". Best effort: never used for security. */ export function describeDevice(userAgent: string | null | undefined): string { const ua = userAgent ?? ''; const platform = detectPlatform(ua); const browser = detectBrowser(ua); if (platform && browser) return `${platform} · ${browser}`; return platform ?? browser ?? 'Dispositivo desconocido'; } function detectPlatform(ua: string): string | null { if (/iPhone/i.test(ua)) return 'iPhone'; if (/iPad/i.test(ua)) return 'iPad'; if (/Android/i.test(ua)) return /Mobile/i.test(ua) ? 'Android' : 'Tablet Android'; if (/CrOS/i.test(ua)) return 'Chromebook'; if (/Macintosh|Mac OS X/i.test(ua)) return 'Mac'; if (/Windows/i.test(ua)) return 'Windows'; if (/Linux/i.test(ua)) return 'Linux'; return null; } function detectBrowser(ua: string): string | null { // Order matters: Edge, Opera and Samsung also say "Chrome"; every iOS browser says "Safari". if (/EdgiOS|Edg\//i.test(ua)) return 'Edge'; if (/OPR\/|OPiOS/i.test(ua)) return 'Opera'; if (/SamsungBrowser/i.test(ua)) return 'Samsung Internet'; if (/FxiOS|Firefox\//i.test(ua)) return 'Firefox'; if (/CriOS|Chrome\//i.test(ua)) return 'Chrome'; if (/Safari\//i.test(ua)) return 'Safari'; return null; }