A small web app for watching movies and shows easily
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

30 lines
910 B

const CHROMECAST_SENDER_SDK =
"https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1";
const callbacks: ((available: boolean) => void)[] = [];
let _available: boolean | null = null;
function init(available: boolean) {
_available = available;
callbacks.forEach((cb) => cb(available));
}
export function isChromecastAvailable(cb: (available: boolean) => void) {
if (_available !== null) return cb(_available);
callbacks.push(cb);
}
export function initializeChromecast() {
window.__onGCastApiAvailable = (isAvailable) => {
init(isAvailable);
};
// add script if doesnt exist yet
const exists = !!document.getElementById("chromecast-script");
if (!exists) {
const script = document.createElement("script");
script.setAttribute("src", CHROMECAST_SENDER_SDK);
script.setAttribute("id", "chromecast-script");
document.body.appendChild(script);
}
}