/** * 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'; };