Skip to content

Instantly share code, notes, and snippets.

@bittu
Forked from lfalke/detect-chromecast.js
Last active August 24, 2022 12:04
Show Gist options
  • Save bittu/282df7c97f078e707998b80cfee03fe8 to your computer and use it in GitHub Desktop.
Save bittu/282df7c97f078e707998b80cfee03fe8 to your computer and use it in GitHub Desktop.
Detect Chromecast Model / Generation in Javascript - Updated for Google TV with Chromecast
/**
* We use this workaround to detect the Chromecast device generation.
* Unfortunately the Cast Application Framework (CAF) does not have an API for that.
*
* cc-1: Chromecast 1st Gen.
* cc-2: Chromecast 2nd Gen.
* cc-3: Chromecast 3rd Gen.
* cc-ultra: Chromecast Ultra
* cc-builtin: Android TV with Chromecast built-in
* cc-googletv: Google TV with Chromecast
*
*/
const getModelInfo = () => {
// https://developers.google.com/cast/docs/media#video_codecs
try {
const { hardwareConcurrency, userAgent } = window.navigator;
const context = cast.framework.CastReceiverContext.getInstance();
// Google TV with Chromecast supports 'H.264 High Profile, level 5.1'
if (context.canDisplayType('video/mp4; codecs="avc1.640033')) { return 'cc-googletv'; }
// Android TV with Chromecast built-in
if (userAgent.includes('Android')) { return 'cc-builtin'; }
// Chromecast Ultra supports 'HEVC main profile, level 3.1'
if (MediaSource.isTypeSupported('video/mp4; codecs=hev1.1.6.L93.B0')) { return 'cc-ultra'; }
// 3rd generation Chromecast supports 'H.264 high profile, level 4.2'
if (MediaSource.isTypeSupported('video/mp4; codecs=avc1.64002A')) { return 'cc-3'; }
// 2nd and 1st generation Chromecast can be differentiated by hardwareConcurrency
if (hardwareConcurrency === 2) { return 'cc-2'; }
if (hardwareConcurrency === 1) { return 'cc-1'; }
} catch (e) {
// do nothing
}
return 'cc-unknown';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment