Skip to content

Commit

Permalink
fix: patch setServerCertificate() on older Tizens & webOS (#6696)
Browse files Browse the repository at this point in the history
We've tried to enable setting server certificates to optimize playback
start, but turned out that with our widevine certificate shaka was
throwing 6004 error. The issue is not reproducible starting from Tizen
5.5. The same certificate was working properly also on Chrome.
  • Loading branch information
tykus160 authored and joeyparrish committed May 31, 2024
1 parent 737fac7 commit 0c76912
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/types/polyfill
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
+../../lib/polyfill/mediasource.js
+../../lib/polyfill/media_capabilities.js
+../../lib/polyfill/orientation.js
+../../lib/polyfill/patchedmediakeys_cert.js
+../../lib/polyfill/patchedmediakeys_nop.js
+../../lib/polyfill/patchedmediakeys_webkit.js
+../../lib/polyfill/pip_webkit.js
Expand Down
62 changes: 62 additions & 0 deletions lib/polyfill/patchedmediakeys_cert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

goog.provide('shaka.polyfill.PatchedMediaKeysCert');

goog.require('shaka.log');
goog.require('shaka.polyfill');
goog.require('shaka.util.Platform');


/**
* @summary A polyfill to fix setServerCertificate implementation on
* older platforms which claim to support modern EME.
* @export
*/
shaka.polyfill.PatchedMediaKeysCert = class {
/**
* Installs the polyfill if needed.
* @export
*/
static install() {
if (!window.MediaKeys) {
// No MediaKeys available
return;
}
// eslint-disable-next-line no-restricted-syntax
if (MediaKeys.prototype.setServerCertificate &&
!shaka.polyfill.PatchedMediaKeysCert.hasInvalidImplementation_()) {
// setServerCertificate is there and userAgent seems to be valid.
return;
}

shaka.log.info('Patching MediaKeys.setServerCertificate');
// eslint-disable-next-line no-restricted-syntax
MediaKeys.prototype.setServerCertificate =
shaka.polyfill.PatchedMediaKeysCert.setServerCertificate_;
}

/**
* @param {!BufferSource} certificate
* @return {!Promise<boolean>}
* @private
*/
static setServerCertificate_(certificate) {
shaka.log.debug('PatchedMediaKeysCert.setServerCertificate');
return Promise.resolve(false);
}

/**
* @return {boolean}
* @private
*/
static hasInvalidImplementation_() {
return shaka.util.Platform.isTizen3() || shaka.util.Platform.isTizen4() ||
shaka.util.Platform.isTizen5_0() || shaka.util.Platform.isWebOS3();
}
};

shaka.polyfill.register(shaka.polyfill.PatchedMediaKeysCert.install);
9 changes: 9 additions & 0 deletions lib/util/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ shaka.util.Platform = class {
return shaka.util.Platform.userAgentContains_('Tizen 6');
}

/**
* Check if the current platform is a Tizen 5.0 TV.
*
* @return {boolean}
*/
static isTizen5_0() {
return shaka.util.Platform.userAgentContains_('Tizen 5.0');
}

/**
* Check if the current platform is a Tizen 5 TV.
*
Expand Down
15 changes: 15 additions & 0 deletions test/util/platform_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ describe('Platform', () => {
expect(shaka.util.Platform.isTizen5()).toBe(false);
});

it('checks is Tizen 5.0', () => {
setUserAgent(webOs3);
expect(shaka.util.Platform.isTizen5_0()).toBe(false);
setUserAgent(tizen50);
expect(shaka.util.Platform.isTizen5_0()).toBe(true);
setUserAgent(tizen55);
expect(shaka.util.Platform.isTizen5_0()).toBe(false);
setUserAgent(tizen60);
expect(shaka.util.Platform.isTizen5_0()).toBe(false);
setUserAgent(tizen65);
expect(shaka.util.Platform.isTizen5_0()).toBe(false);
setUserAgent(tizen70);
expect(shaka.util.Platform.isTizen5_0()).toBe(false);
});

it('checks is Tizen 6', () => {
setUserAgent(webOs3);
expect(shaka.util.Platform.isTizen6()).toBe(false);
Expand Down

0 comments on commit 0c76912

Please sign in to comment.