From 5f2ccfdbcc76d3f16964b93727bcdf201f819142 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Fri, 7 Jan 2022 19:34:05 -0800 Subject: [PATCH] fix: Avoid WebCrypto randomUUID when CMCD disabled 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 --- lib/util/cmcd_manager.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/util/cmcd_manager.js b/lib/util/cmcd_manager.js index c13a9bb292..6ea7287b96 100644 --- a/lib/util/cmcd_manager.js +++ b/lib/util/cmcd_manager.js @@ -31,7 +31,7 @@ shaka.util.CmcdManager = class { * * @private {string} */ - this.sid_ = config.sessionId || window.crypto.randomUUID(); + this.sid_ = ''; /** * Streaming format @@ -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, @@ -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_,