Skip to content

Instantly share code, notes, and snippets.

@lfalke
Last active August 24, 2022 11:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lfalke/bd7eba442eae4d50075ecdf89dc9edf6 to your computer and use it in GitHub Desktop.
Save lfalke/bd7eba442eae4d50075ecdf89dc9edf6 to your computer and use it in GitHub Desktop.
Detect Chromecast Model / Generation in Javascript
/**
* 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
*/
const getModelInfo = () => {
// https://developers.google.com/cast/docs/media#video_codecs
try {
const { hardwareConcurrency, userAgent } = window.navigator;
// 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';
};
@dilukd
Copy link

dilukd commented Jul 4, 2022

Hi @lfalke - have you figured out how to detect the newer Google TV with Chromecast (Gen4) device ?

@lfalke
Copy link
Author

lfalke commented Jul 5, 2022

Hey @dilukd, no, I did not. But the people from MUX have implemented my solution, and it seems that they have done it :)
Have a look here: https://github.com/muxinc/chromecast-mux/blob/master/src/index.js#L12

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