-
-
Save brent-hoover/8888251 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Chromecast init</title> | |
<script src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js"></script> | |
</head> | |
<body> | |
<div id="message"></div> | |
<script type="text/javascript"> | |
(function (window) { | |
function showMessage(html) { | |
window.document.getElementById("message").innerHTML = html; | |
} | |
if (!window.chrome) { | |
// Not running in Chrome... inform users about it (or hide Chromecast functionality for non-Chrome users) | |
showMessage("Only works in <a href=\"https://www.google.com/chrome\">Chrome</a>."); | |
return; | |
} | |
if (!window.chrome.cast) { | |
// shouldn't happen since we load cast_sender.js synchronously | |
showMessage("Cast API not found, this shouldn't happen..."); | |
return; | |
} | |
/* | |
* Check for Chromecast extension. | |
* Unfortunately no nice way to know whether the Extension is missing in the API so far | |
* Open feature request: https://code.google.com/p/google-cast-sdk/issues/detail?id=124 | |
*/ | |
if (window.chrome.cast.extensionId) { | |
waitForApi(); | |
} else { | |
// Internal API call so might break, but best way for now without relying on a maximum timeout... | |
window.chrome.cast.ApiBootstrap_.findInstalledExtension_(function (extensionId) { | |
if (!extensionId) { | |
// Extension not installed, prompt user to install it | |
showMessage("Please install the <a href=\"https://chrome.google.com/webstore/detail/google-cast/boadgeojelhgndaghljhdicfkmllpafd\">Google Cast extension</a>."); | |
} else { | |
waitForApi(); | |
} | |
}); | |
} | |
function waitForApi() { | |
showMessage("Waiting for API to become ready..."); | |
if (!window.chrome.cast.isAvailable) { | |
window.setTimeout(waitForApi, 100); | |
} else { | |
initializeCastApi(); | |
} | |
} | |
function initializeCastApi() { | |
// we can start using the Cast API now | |
showMessage("Everything ready!"); | |
} | |
}(this)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment