Skip to content

Commit

Permalink
fix: Avoid WebCrypto randomUUID when CMCD disabled
Browse files Browse the repository at this point in the history
If CMCD is disabled, there is no reason to use randomUUID.  And if
tests or applications are running in plain HTTP URLs (what the web
platform calls an "insecure context"), then WebCrypto APIs like
randomUUID don't exist.

If a site or test is running in plain HTTP, and CMCD is disabled
(which is the default), there shouldn't be any need to install the
randomUUID polyfill (which should be optional).

This changes the CMCD utility to skip generating a session ID if CMCD
is disabled.

Change-Id: Iaf9c3fe94bc03c0f5ce46a082d18513ad05fb341
  • Loading branch information
joeyparrish committed Jan 11, 2022
1 parent 11560cc commit 5f2ccfd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/util/cmcd_manager.js
Expand Up @@ -31,7 +31,7 @@ shaka.util.CmcdManager = class {
*
* @private {string}
*/
this.sid_ = config.sessionId || window.crypto.randomUUID();
this.sid_ = '';

/**
* Streaming format
Expand Down Expand Up @@ -147,6 +147,10 @@ shaka.util.CmcdManager = class {
*/
applyTextData(request) {
try {
if (!this.config_.enabled) {
return;
}

this.apply_(request, {
ot: shaka.util.CmcdManager.ObjectType.CAPTION,
su: true,
Expand Down Expand Up @@ -217,6 +221,9 @@ shaka.util.CmcdManager = class {
* @private
*/
createData_() {
if (!this.sid_) {
this.sid_ = this.config_.sessionId || window.crypto.randomUUID();
}
return {
v: shaka.util.CmcdManager.Version,
sf: this.sf_,
Expand Down

0 comments on commit 5f2ccfd

Please sign in to comment.