Last active
August 24, 2022 11:53
-
-
Save lfalke/bd7eba442eae4d50075ecdf89dc9edf6 to your computer and use it in GitHub Desktop.
Detect Chromecast Model / Generation in Javascript
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
/** | |
* 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'; | |
}; |
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
Hi @lfalke - have you figured out how to detect the newer Google TV with Chromecast (Gen4) device ?