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
  • Select an option

  • Save bittu/282df7c97f078e707998b80cfee03fe8 to your computer and use it in GitHub Desktop.

Select an option

Save bittu/282df7c97f078e707998b80cfee03fe8 to your computer and use it in GitHub Desktop.

Revisions

  1. bittu revised this gist Aug 24, 2022. 1 changed file with 10 additions and 10 deletions.
    20 changes: 10 additions & 10 deletions detect-chromecast.js
    Original file line number Diff line number Diff line change
    @@ -17,20 +17,20 @@ const getModelInfo = () => {
    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';
    if (context.canDisplayType('video/mp4; codecs="avc1.640033')) { return 'cc-googletv'; }

    // Android TV with Chromecast built-in
    if (userAgent.includes('Android')) return 'cc-builtin';
    // 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';
    // 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';
    // 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';
    // 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
    }
  2. bittu revised this gist Aug 24, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions detect-chromecast.js
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,8 @@
    * 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
  3. bittu revised this gist Aug 24, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions detect-chromecast.js
    Original file line number Diff line number Diff line change
    @@ -12,6 +12,10 @@ 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';
  4. @lfalke lfalke revised this gist Mar 25, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions detect-chromecast.js
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,7 @@
    * 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
  5. @lfalke lfalke revised this gist Mar 25, 2020. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion detect-chromecast.js
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,10 @@
    const getModelInfo = () => {
    // https://developers.google.com/cast/docs/media#video_codecs
    try {
    const { hardwareConcurrency } = window.navigator;
    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';
  6. @lfalke lfalke revised this gist Mar 24, 2020. 1 changed file with 12 additions and 7 deletions.
    19 changes: 12 additions & 7 deletions detect-chromecast.js
    Original file line number Diff line number Diff line change
    @@ -8,14 +8,19 @@
    * cc-ultra: Chromecast Ultra
    */
    const getModelInfo = () => {
    // https://developers.google.com/cast/docs/media#video_codecs
    try {
    if (MediaSource.isTypeSupported('video/mp4; codecs=hev1.1.6.L90.B0')) return 'cc-ultra';
    if (window.navigator.hardwareConcurrency === 1) return 'cc-1';
    if (window.navigator.hardwareConcurrency === 2) {
    // if H.264 level 4.2 is supported, it's a 3rd generation chromecast
    // https://developers.google.com/cast/docs/media#video_codecs
    return MediaSource.isTypeSupported('video/mp4; codecs=avc1.64002A') ? 'cc-3' : 'cc-2';
    }
    const { hardwareConcurrency } = window.navigator;

    // 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
    }
  7. @lfalke lfalke revised this gist Mar 17, 2020. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion detect-chromecast.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,12 @@
    /**
    * 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
    */
    const getModelInfo = () => {
    try {
    if (MediaSource.isTypeSupported('video/mp4; codecs=hev1.1.6.L90.B0')) return 'cc-ultra';
    @@ -8,7 +17,7 @@ const getModelInfo = () => {
    return MediaSource.isTypeSupported('video/mp4; codecs=avc1.64002A') ? 'cc-3' : 'cc-2';
    }
    } catch (e) {
    // error handling
    // do nothing
    }

    return 'cc-unknown';
  8. @lfalke lfalke renamed this gist Mar 17, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. @lfalke lfalke created this gist Mar 17, 2020.
    15 changes: 15 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    const getModelInfo = () => {
    try {
    if (MediaSource.isTypeSupported('video/mp4; codecs=hev1.1.6.L90.B0')) return 'cc-ultra';
    if (window.navigator.hardwareConcurrency === 1) return 'cc-1';
    if (window.navigator.hardwareConcurrency === 2) {
    // if H.264 level 4.2 is supported, it's a 3rd generation chromecast
    // https://developers.google.com/cast/docs/media#video_codecs
    return MediaSource.isTypeSupported('video/mp4; codecs=avc1.64002A') ? 'cc-3' : 'cc-2';
    }
    } catch (e) {
    // error handling
    }

    return 'cc-unknown';
    };