From 8465a9931374036bc3c9d700c2a3b43dbec09d62 Mon Sep 17 00:00:00 2001 From: JulianDomingo Date: Wed, 23 Nov 2022 15:20:05 -0800 Subject: [PATCH] Re-instated deleted code from previous commit, which prevented cast lab failures. --- lib/polyfill/media_capabilities.js | 4 ++++ test/polyfill/media_capabilities_unit.js | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/polyfill/media_capabilities.js b/lib/polyfill/media_capabilities.js index f534cca8a8..fc25add80a 100644 --- a/lib/polyfill/media_capabilities.js +++ b/lib/polyfill/media_capabilities.js @@ -267,6 +267,10 @@ shaka.polyfill.MediaCapabilities = class { shaka.util.Error.Severity.CRITICAL, shaka.util.Error.Category.CAST, shaka.util.Error.Code.CAST_API_UNAVAILABLE); + } else if (!(cast.__platform__ && cast.__platform__.canDisplayType)) { + shaka.log.warning('Expected cast APIs to be available! Falling back to ' + + 'MediaSource.isTypeSupported() for type support.'); + return MediaSource.isTypeSupported(contentType); } let displayType = contentType; diff --git a/test/polyfill/media_capabilities_unit.js b/test/polyfill/media_capabilities_unit.js index ca659a69fb..4fe0c283bf 100644 --- a/test/polyfill/media_capabilities_unit.js +++ b/test/polyfill/media_capabilities_unit.js @@ -211,6 +211,28 @@ describe('MediaCapabilities', () => { expect(isChromecastSpy).toHaveBeenCalledTimes(2); }); + it('falls back to isTypeSupported() when canDisplayType() missing', + async () => { + // We only set the cast namespace, but not the canDisplayType() API. + window['cast'] = {}; + const isChromecastSpy = + spyOn(shaka['util']['Platform'], + 'isChromecast').and.returnValue(true); + const isTypeSupportedSpy = + spyOn(window['MediaSource'], 'isTypeSupported') + .and.returnValue(true); + + shaka.polyfill.MediaCapabilities.install(); + await navigator.mediaCapabilities.decodingInfo(mockDecodingConfig); + + expect(mockCanDisplayType).not.toHaveBeenCalled(); + // 1 (during install()) + 1 (for video config check). + expect(isChromecastSpy).toHaveBeenCalledTimes(2); + // 1 (fallback in canCastDisplayType()) + + // 1 (mockDecodingConfig.audio). + expect(isTypeSupportedSpy).toHaveBeenCalledTimes(2); + }); + it('should use cast.__platform__.canDisplayType for "supported" field ' + 'when platform is Cast', async () => { // We're using quotes to access window.cast because the compiler