mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-21 21:47:15 +00:00
49 lines
932 B
TypeScript
49 lines
932 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
export function useIsTV() {
|
|
const [isTV, setIsTV] = useState(false);
|
|
|
|
useEffect(() => {
|
|
function detectTV() {
|
|
const userAgent = navigator.userAgent || "";
|
|
|
|
const tvKeywords = [
|
|
"Silk",
|
|
"SmartTV",
|
|
"Tizen",
|
|
"Web0S",
|
|
"SamsungBrowser",
|
|
"HbbTV",
|
|
"Viera",
|
|
"NetCast",
|
|
"AppleTV",
|
|
"Android TV",
|
|
"GoogleTV",
|
|
"Roku",
|
|
"PlayStation",
|
|
"Xbox",
|
|
"Opera TV",
|
|
"AquosBrowser",
|
|
"Hisense",
|
|
"SonyBrowser",
|
|
"SharpBrowser",
|
|
"AFT", // Amazon Fire TV
|
|
"Chromecast",
|
|
];
|
|
|
|
const isTVDetected = tvKeywords.some((keyword) =>
|
|
userAgent.toLowerCase().includes(keyword.toLowerCase()),
|
|
);
|
|
|
|
if (isTVDetected) {
|
|
setIsTV(true);
|
|
}
|
|
}
|
|
|
|
detectTV();
|
|
}, []);
|
|
|
|
return {
|
|
isTV,
|
|
};
|
|
}
|