Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// ============================================================ //
// CAST
// ============================================================ //
window.chrome = {};
window.chrome.cast = {};
window.chrome.cast.isAvailable = true;
window.chrome.cast.initialize = function(a, b, c) { }
window.chrome.cast.ApiConfig = function(a, b, c) {
// This fakes that chromecast is available so the button appears
// call anything other than "available" to fake chromcast dissapearing
c("available");
}
window.chrome.cast.SessionRequest = function(a) { }
window.chrome.cast.sessionRequest = window.fakeSession;
window.chrome.cast.addReceiverActionListener = function(a) { };
window.chrome.cast.requestSession = function(a, b) {
window.triggerConnectingToCC = a;
// STEP 1. this sets flash into "connecting to" state
// Call this later if you like
window.triggerConnectingToCC(window.fakeSession);
}
window.chrome.cast.media = {};
window.chrome.cast.media.GenericMediaMetadata = function() { }
window.chrome.cast.media.MediaInfo = function(a, b) { }
window.chrome.cast.media.LoadRequest = function(a) { return {}; }
window.chrome.cast.Image = function(a) { return {}; }
window.chrome.cast.media.StopRequest = function() { }
window.chrome.cast.media.PauseRequest = function(a) { }
window.chrome.cast.media.PlayRequest = function(a) { }
window.chrome.cast.media.SeekRequest = function() { return {}; }
// ============================================================ //
// FAKE SESSION
// ============================================================ //
window.fakeSession = {};
window.fakeSession.media = [];
window.fakeSession.media[0] = window.fakeMedia;
window.fakeSession.loadMedia = function(a, b, c) {
window.pretendMediaDiscovered = b;
// STEP 2. triggers adding an update listener to the media
// so we can start actually playing,pausing it etc
setTimeout(function() {
window.pretendMediaDiscovered(window.fakeMedia);
}, 1000);
}
window.fakeSession.receiver = {friendlyName:"dave", volume:{level:0.7}};
window.fakeSession.addUpdateListener = function(a) {
window.killSession = a;
}
window.fakeSession.stop = function(a,b,c) { }
window.fakeSession.sendMessage = function(a,b,c) { }
window.fakeSession.setReceiverMuted = function(a,b,c) { }
window.fakeSession.setReceiverVolumeLevel = function(a,b,c) { }
// ============================================================ //
// FAKE MEDIA
// ============================================================ //
window.fakeMedia = {};
window.fakeMedia.stop = function(a,b,c) {
// Invoke the success parameter
b();
}
window.fakeMedia.pause = function(a,b,c) { }
window.fakeMedia.play = function(a,b,c) { }
window.fakeMedia.seek = function(a,b,c) { }
window.fakeMedia.addUpdateListener = function(a) {
window.updateCCmediaStatus = a;
// STEP 3. If steps 1 and 2 are done we can start telling the page what our pretend chromecast is doing
// Have to do an initial 'play' (or anything else) to trigger the isCasting flag
// Update properties of fakeMedia to change behaviour before each updateCCmediaStatus({}) call
window.fakeMedia.playerState = "PLAYING";
window.fakeMedia.currentTime = 1;
window.fakeMedia.id = "irrelevant";
window.fakeMedia.customData = {subtitlesEnabled: false};
window.fakeSession.receiver = {volume: {level: 0.7, muted: false}};
}

FranAguiar commented Jul 25, 2016

Is It this still working?
I execute this script but chromecast isn't available. What I'm missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment