-
-
Save arturparkhisenko/72b4a873a967dd42c06e95a928d40d74 to your computer and use it in GitHub Desktop.
Detect Chromecast Model / Generation in Javascript
This file contains 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'; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment