diff --git a/.eslintrc.js b/.eslintrc.js index 02efbc49f8..06cf1d416e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -128,12 +128,14 @@ module.exports = { "block-spacing": ["error", "always"], "brace-style": ["error", "1tbs", { "allowSingleLine": true }], "lines-between-class-members": "error", + "max-statements-per-line": ["error", {"max": 1}], "new-parens": "error", "no-mixed-operators": ["error", { "groups": [["&", "|", "^", "~", "<<", ">>", ">>>", "&&", "||"]], "allowSamePrecedence": false, }], "no-whitespace-before-property": "error", + "nonblock-statement-body-position": ["error", "below"], "operator-assignment": "error", // }}} diff --git a/demo/cast_receiver/receiver_app.js b/demo/cast_receiver/receiver_app.js index aa0b0e4446..05baa6bf2d 100644 --- a/demo/cast_receiver/receiver_app.js +++ b/demo/cast_receiver/receiver_app.js @@ -113,7 +113,9 @@ ShakaReceiver.prototype.init = function() { */ ShakaReceiver.prototype.appDataCallback_ = function(appData) { // appData is null if we start the app without any media loaded. - if (!appData) return; + if (!appData) { + return; + } const asset = ShakaDemoAssetInfo.fromJSON(appData['asset']); asset.applyFilters(this.player_.getNetworkingEngine()); diff --git a/demo/common/asset.js b/demo/common/asset.js index bcf503ce59..ec5eb70c39 100644 --- a/demo/common/asset.js +++ b/demo/common/asset.js @@ -331,7 +331,9 @@ const ShakaDemoAssetInfo = class { * @private */ addLicenseRequestHeaders_(headers, requestType, request) { - if (requestType != shaka.net.NetworkingEngine.RequestType.LICENSE) return; + if (requestType != shaka.net.NetworkingEngine.RequestType.LICENSE) { + return; + } // Add these to the existing headers. Do not clobber them! // For PlayReady, there will already be headers in the request. diff --git a/demo/config.js b/demo/config.js index 7aedac2ca4..35217ffda3 100644 --- a/demo/config.js +++ b/demo/config.js @@ -340,7 +340,9 @@ class ShakaDemoConfig { // shaka.log is not set if logging isn't enabled. // I.E. if using the release version of shaka. - if (!shaka['log']) return; + if (!shaka['log']) { + return; + } // Access shaka.log using bracket syntax because shaka.log is not exported. // Exporting the logging methods proved to be a bad solution, both in terms @@ -373,10 +375,18 @@ class ShakaDemoConfig { this.addSelectInput_('Log Level', logLevels, onChange); const input = this.latestInput_.input(); switch (shaka['log']['currentLevel']) { - case Level['DEBUG']: input.value = 'debug'; break; - case Level['V2']: input.value = 'vv'; break; - case Level['V1']: input.value = 'v'; break; - default: input.value = 'info'; break; + case Level['DEBUG']: + input.value = 'debug'; + break; + case Level['V2']: + input.value = 'vv'; + break; + case Level['V1']: + input.value = 'v'; + break; + default: + input.value = 'info'; + break; } } diff --git a/demo/demo_utils.js b/demo/demo_utils.js index da70fe59b4..877ac9825c 100644 --- a/demo/demo_utils.js +++ b/demo/demo_utils.js @@ -86,7 +86,9 @@ ShakaDemoUtils.runThroughHashParams = (callback, config) => { for (const key in object) { let hashName = key; const configName = accumulated + key; - if (overridden.includes(configName)) continue; + if (overridden.includes(configName)) { + continue; + } if (collisions.includes(key)) { hashName = configName; } diff --git a/demo/input.js b/demo/input.js index 82e8e7a599..fd184132f0 100644 --- a/demo/input.js +++ b/demo/input.js @@ -35,7 +35,9 @@ class ShakaDemoInput { /** @private {!Element} */ this.input_ = document.createElement(inputType); - this.input_.onchange = () => { onChange(this.input_); }; + this.input_.onchange = () => { + onChange(this.input_); + }; this.input_.id = ShakaDemoInput.generateNewId_('input'); this.container_.appendChild(this.input_); diff --git a/demo/main.js b/demo/main.js index b7e73d5afd..c84cb83af2 100644 --- a/demo/main.js +++ b/demo/main.js @@ -67,7 +67,9 @@ class ShakaDemoMain { // Exception to the exceptions we catch: ChromeVox (screenreader) always // throws an error as of Chrome 73. Screen these out since they are // unrelated to our application and we can't control them. - if (event.message.includes('cvox.ApiImplementation')) return; + if (event.message.includes('cvox.ApiImplementation')) { + return; + } this.onError_(/** @type {!shaka.util.Error} */ (event.error)); }); @@ -976,10 +978,18 @@ class ShakaDemoMain { // if it's different from this default. if (shaka.log && shaka.log.currentLevel != shaka.log.MAX_LOG_LEVEL) { switch (shaka.log.currentLevel) { - case shaka.log.Level.INFO: params.push('info'); break; - case shaka.log.Level.DEBUG: params.push('debug'); break; - case shaka.log.Level.V2: params.push('vv'); break; - case shaka.log.Level.V1: params.push('v'); break; + case shaka.log.Level.INFO: + params.push('info'); + break; + case shaka.log.Level.DEBUG: + params.push('debug'); + break; + case shaka.log.Level.V2: + params.push('vv'); + break; + case shaka.log.Level.V1: + params.push('v'); + break; } } diff --git a/lib/cast/cast_proxy.js b/lib/cast/cast_proxy.js index a07542a399..dbe3c6ec56 100644 --- a/lib/cast/cast_proxy.js +++ b/lib/cast/cast_proxy.js @@ -517,7 +517,7 @@ shaka.cast.CastProxy.prototype.playerProxyGet_ = function(name) { } if (name == 'getMediaElement') { - return function() { return this.videoProxy_; }.bind(this); + return () => this.videoProxy_; } if (name == 'getSharedConfiguration') { diff --git a/lib/cast/cast_receiver.js b/lib/cast/cast_receiver.js index 6eb9f2b535..6c5a4ed7af 100644 --- a/lib/cast/cast_receiver.js +++ b/lib/cast/cast_receiver.js @@ -760,7 +760,9 @@ shaka.cast.CastReceiver.prototype.sendAsyncComplete_ = shaka.cast.CastReceiver.prototype.sendMessage_ = function(message, bus, senderId) { // Cuts log spam when debugging the receiver UI in Chrome. - if (!this.isConnected_) return; + if (!this.isConnected_) { + return; + } const serialized = shaka.cast.CastUtils.serialize(message); if (senderId) { diff --git a/lib/cast/cast_sender.js b/lib/cast/cast_sender.js index d94e4059fc..1629d6ad82 100644 --- a/lib/cast/cast_sender.js +++ b/lib/cast/cast_sender.js @@ -625,7 +625,9 @@ shaka.cast.CastSender.prototype.onMessageReceived_ = delete this.asyncCallPromises_[id]; goog.asserts.assert(p, 'Unexpected async id'); - if (!p) break; + if (!p) { + break; + } if (error) { // This is a hacky way to reconstruct the serialized error. diff --git a/lib/cast/cast_utils.js b/lib/cast/cast_utils.js index 5d8b1fb7e8..964ed81512 100644 --- a/lib/cast/cast_utils.js +++ b/lib/cast/cast_utils.js @@ -300,9 +300,15 @@ shaka.cast.CastUtils.serialize = function(thing) { if (typeof value == 'number') { // NaN and infinity cannot be represented directly in JSON. - if (isNaN(value)) return 'NaN'; - if (isFinite(value)) return value; - if (value < 0) return '-Infinity'; + if (isNaN(value)) { + return 'NaN'; + } + if (isFinite(value)) { + return value; + } + if (value < 0) { + return '-Infinity'; + } return 'Infinity'; } diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index b654ac7c74..6cd7533ef4 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -380,7 +380,9 @@ shaka.dash.DashParser.prototype.stop = function() { */ shaka.dash.DashParser.prototype.update = function() { this.requestManifest_().catch((error) => { - if (!this.playerInterface_ || !error) return; + if (!this.playerInterface_ || !error) { + return; + } goog.asserts.assert(error instanceof shaka.util.Error, 'Bad error type'); this.playerInterface_.onError(error); }); @@ -593,7 +595,9 @@ shaka.dash.DashParser.prototype.processManifest_ = // Use @maxSegmentDuration to override smaller, derived values. presentationTimeline.notifyMaxSegmentDuration(maxSegmentDuration || 1); - if (goog.DEBUG) presentationTimeline.assertIsValid(); + if (goog.DEBUG) { + presentationTimeline.assertIsValid(); + } // These steps are not done on manifest update. if (!this.manifest_) { @@ -1462,10 +1466,14 @@ shaka.dash.DashParser.prototype.parseAudioChannels_ = const elem = audioChannelConfigs[i]; const scheme = elem.getAttribute('schemeIdUri'); - if (!scheme) continue; + if (!scheme) { + continue; + } const value = elem.getAttribute('value'); - if (!value) continue; + if (!value) { + continue; + } switch (scheme) { case 'urn:mpeg:dash:outputChannelPositionList:2012': @@ -1497,7 +1505,9 @@ shaka.dash.DashParser.prototype.parseAudioChannels_ = // Count the 1-bits in hexValue. let numBits = 0; while (hexValue) { - if (hexValue & 1) ++numBits; + if (hexValue & 1) { + ++numBits; + } hexValue >>= 1; } return numBits; diff --git a/lib/dash/segment_base.js b/lib/dash/segment_base.js index e9b212b9e0..193e74c2e2 100644 --- a/lib/dash/segment_base.js +++ b/lib/dash/segment_base.js @@ -69,7 +69,7 @@ shaka.dash.SegmentBase.createInitSegment = function(context, callback) { endByte = range.end; } - const getUris = function() { return resolvedUris; }; + const getUris = () => resolvedUris; return new shaka.media.InitSegmentReference(getUris, startByte, endByte); }; diff --git a/lib/dash/segment_list.js b/lib/dash/segment_list.js index db93d7ca83..bea4307aaf 100644 --- a/lib/dash/segment_list.js +++ b/lib/dash/segment_list.js @@ -288,7 +288,7 @@ shaka.dash.SegmentList.createSegmentReferences_ = function( endTime = startTime + periodDuration; } - const getUris = (function(uris) { return uris; }.bind(null, mediaUri)); + const getUris = () => mediaUri; references.push( new shaka.media.SegmentReference( i + startNumber, startTime, endTime, getUris, segment.start, diff --git a/lib/dash/segment_template.js b/lib/dash/segment_template.js index 65d9f072cc..d0f57f6b1b 100644 --- a/lib/dash/segment_template.js +++ b/lib/dash/segment_template.js @@ -349,7 +349,9 @@ shaka.dash.SegmentTemplate.createFromDuration_ = function(context, info) { // Cap the segment end at the period end, to avoid period transition issues // in StreamingEngine. let segmentEnd = segmentStart + segmentDuration; - if (periodDuration) segmentEnd = Math.min(segmentEnd, periodDuration); + if (periodDuration) { + segmentEnd = Math.min(segmentEnd, periodDuration); + } // Do not construct segments references that should not exist. if (segmentEnd < 0) { diff --git a/lib/hls/hls_parser.js b/lib/hls/hls_parser.js index 42a7b2546e..0ace029ede 100644 --- a/lib/hls/hls_parser.js +++ b/lib/hls/hls_parser.js @@ -993,7 +993,9 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromMediaTag_ = // Shaka recognizes the content types 'audio', 'video' and 'text'. // The HLS 'subtitles' type needs to be mapped to 'text'. const ContentType = shaka.util.ManifestParserUtils.ContentType; - if (type == 'subtitles') type = ContentType.TEXT; + if (type == 'subtitles') { + type = ContentType.TEXT; + } const LanguageUtils = shaka.util.LanguageUtils; const language = LanguageUtils.normalize(/** @type {string} */( @@ -1012,7 +1014,9 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromMediaTag_ = const streamInfo = await this.createStreamInfo_( verbatimMediaPlaylistUri, allCodecs, type, language, primary, name, channelsCount, /* closedCaptions */ null); - if (streamInfo == null) return null; + if (streamInfo == null) { + return null; + } // TODO: This check is necessary because of the possibility of multiple // calls to createStreamInfoFromMediaTag_ before either has resolved. if (this.uriToStreamInfosMap_.has(verbatimMediaPlaylistUri)) { @@ -1037,7 +1041,9 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromMediaTag_ = * @private */ shaka.hls.HlsParser.prototype.getChannelCount_ = function(channels) { - if (!channels) return null; + if (!channels) { + return null; + } const channelcountstring = channels.split('/')[0]; const count = parseInt(channelcountstring, 10); return count; @@ -1083,7 +1089,9 @@ shaka.hls.HlsParser.prototype.createStreamInfoFromVariantTag_ = const streamInfo = await this.createStreamInfo_(verbatimMediaPlaylistUri, allCodecs, type, /* language */ 'und', /* primary */ false, /* name */ null, /* channelcount */ null, closedCaptions); - if (streamInfo == null) return null; + if (streamInfo == null) { + return null; + } // TODO: This check is necessary because of the possibility of multiple // calls to createStreamInfoFromVariantTag_ before either has resolved. if (this.uriToStreamInfosMap_.has(verbatimMediaPlaylistUri)) { @@ -1806,11 +1814,15 @@ shaka.hls.HlsParser.prototype.getStartTimeFromTsSegment_ = function(data) { packetStart = reader.getPosition(); syncByte = reader.readUint8(); - if (syncByte != 0x47) fail(); + if (syncByte != 0x47) { + fail(); + } const flagsAndPacketId = reader.readUint16(); const hasPesPacket = flagsAndPacketId & 0x4000; - if (!hasPesPacket) fail(); + if (!hasPesPacket) { + fail(); + } const flags = reader.readUint8(); const adaptationFieldControl = (flags & 0x30) >> 4; diff --git a/lib/hls/hls_utils.js b/lib/hls/hls_utils.js index dc1393b805..be67a3f59f 100644 --- a/lib/hls/hls_utils.js +++ b/lib/hls/hls_utils.js @@ -41,7 +41,9 @@ shaka.hls.Utils.filterTagsByName = function(tags, name) { */ shaka.hls.Utils.getFirstTagWithName = function(tags, name) { const tagsWithName = shaka.hls.Utils.filterTagsByName(tags, name); - if (!tagsWithName.length) return null; + if (!tagsWithName.length) { + return null; + } return tagsWithName[0]; }; diff --git a/lib/media/adaptation_set.js b/lib/media/adaptation_set.js index 6d93ed4ab1..8d1b75a562 100644 --- a/lib/media/adaptation_set.js +++ b/lib/media/adaptation_set.js @@ -220,7 +220,9 @@ shaka.media.AdaptationSet = class { codecsB.sort(); for (let i = 0; i < codecsA.length; i++) { - if (codecsA[i] != codecsB[i]) { return false; } + if (codecsA[i] != codecsB[i]) { + return false; + } } return true; @@ -247,12 +249,16 @@ shaka.media.AdaptationSet = class { // Make sure that we have the same number roles in each list. Make sure to // do it after correcting for 'main'. - if (aSet.size != bSet.size) { return false; } + if (aSet.size != bSet.size) { + return false; + } // Because we know the two sets are the same size, if any item is missing // if means that they are not the same. for (const x of aSet) { - if (!bSet.has(x)) { return false; } + if (!bSet.has(x)) { + return false; + } } return true; diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index 0c8115727d..e07c3800b9 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -491,7 +491,9 @@ shaka.media.DrmEngine.prototype.attach = function(video) { const setServerCertificate = this.setServerCertificate(); return Promise.all([setMediaKeys, setServerCertificate]).then(() => { - if (this.isDestroying_) { return; } + if (this.isDestroying_) { + return; + } this.createOrLoad(); if (!this.currentDrmInfo_.initData.length && @@ -503,7 +505,9 @@ shaka.media.DrmEngine.prototype.attach = function(video) { this.eventManager_.listen(this.video_, 'encrypted', cb); } }).catch((error) => { - if (this.isDestroying_) { return; } + if (this.isDestroying_) { + return; + } throw error; }); }; @@ -870,10 +874,14 @@ shaka.media.DrmEngine.prototype.queryMediaKeys_ = function(configsByKeySystem) { const hasLicenseServer = config.drmInfos.some((info) => { return !!info.licenseServerUri; }); - if (hasLicenseServer != shouldHaveLicenseServer) return; + if (hasLicenseServer != shouldHaveLicenseServer) { + return; + } p = p.catch(() => { - if (this.isDestroying_) { return null; } + if (this.isDestroying_) { + return null; + } return navigator.requestMediaKeySystemAccess(keySystem, [config]); }); }); @@ -887,7 +895,9 @@ shaka.media.DrmEngine.prototype.queryMediaKeys_ = function(configsByKeySystem) { }); p = p.then((mediaKeySystemAccess) => { - if (this.isDestroying_) { return null; } + if (this.isDestroying_) { + return null; + } // Get the set of supported content types from the audio and video // capabilities. Avoid duplicates so that it is easier to read what is @@ -924,14 +934,18 @@ shaka.media.DrmEngine.prototype.queryMediaKeys_ = function(configsByKeySystem) { return mediaKeySystemAccess.createMediaKeys(); }).then((mediaKeys) => { - if (this.isDestroying_) { return; } + if (this.isDestroying_) { + return; + } shaka.log.info('Created MediaKeys object for key system', this.currentDrmInfo_.keySystem); this.mediaKeys_ = mediaKeys; this.initialized_ = true; }).catch((exception) => { - if (this.isDestroying_) { return; } + if (this.isDestroying_) { + return; + } // Don't rewrap a shaka.util.Error from earlier in the chain: this.currentDrmInfo_ = null; @@ -962,7 +976,9 @@ shaka.media.DrmEngine.prototype.queryMediaKeys_ = function(configsByKeySystem) { */ shaka.media.DrmEngine.prototype.configureClearKey_ = function() { const clearKeys = shaka.util.MapUtils.asMap(this.config_.clearKeys); - if (clearKeys.size == 0) { return null; } + if (clearKeys.size == 0) { + return null; + } const StringUtils = shaka.util.StringUtils; const Uint8ArrayUtils = shaka.util.Uint8ArrayUtils; @@ -1041,7 +1057,9 @@ shaka.media.DrmEngine.prototype.loadOfflineSession_ = function(sessionId) { this.activeSessions_.set(session, metadata); return session.load(sessionId).then((present) => { - if (this.isDestroying_) { return null; } + if (this.isDestroying_) { + return null; + } shaka.log.v2('Loaded offline session', sessionId, present); if (!present) { @@ -1063,7 +1081,9 @@ shaka.media.DrmEngine.prototype.loadOfflineSession_ = function(sessionId) { return session; }, (error) => { - if (this.isDestroying_) { return; } + if (this.isDestroying_) { + return; + } this.activeSessions_.delete(session); @@ -1116,7 +1136,9 @@ shaka.media.DrmEngine.prototype.createTemporarySession_ = this.activeSessions_.set(session, metadata); session.generateRequest(initDataType, initData.buffer).catch((error) => { - if (this.isDestroying_) { return; } + if (this.isDestroying_) { + return; + } this.activeSessions_.delete(session); @@ -1198,7 +1220,9 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) { this.playerInterface_.netEngine.request(requestType, request).promise .then((response) => { - if (this.isDestroying_) { return Promise.reject(); } + if (this.isDestroying_) { + return Promise.reject(); + } if (this.currentDrmInfo_.keySystem.startsWith('com.apple.fps')) { this.parseFairPlayResponse_(response); @@ -1229,7 +1253,9 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) { }); }, (error) => { // Ignore destruction errors - if (this.isDestroying_) { return; } + if (this.isDestroying_) { + return; + } // Request failed! goog.asserts.assert(error instanceof shaka.util.Error, @@ -1245,7 +1271,9 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) { } }).catch((error) => { // Ignore destruction errors - if (this.isDestroying_) { return; } + if (this.isDestroying_) { + return; + } // Session update failed! const shakaErr = new shaka.util.Error( @@ -1652,14 +1680,18 @@ shaka.media.DrmEngine.prototype.supportsVariant = function(variant) { const audioContentType = shaka.util.MimeUtils.getFullType( audio.mimeType, audio.codecs); - if (!this.willSupport(audioContentType)) { return false; } + if (!this.willSupport(audioContentType)) { + return false; + } } if (video && video.encrypted) { const videoContentType = shaka.util.MimeUtils.getFullType( video.mimeType, video.codecs); - if (!this.willSupport(videoContentType)) { return false; } + if (!this.willSupport(videoContentType)) { + return false; + } } const keySystem = this.keySystem(); @@ -1677,7 +1709,9 @@ shaka.media.DrmEngine.prototype.supportsVariant = function(variant) { * @return {boolean} */ shaka.media.DrmEngine.areDrmCompatible = function(drms1, drms2) { - if (!drms1.length || !drms2.length) return true; + if (!drms1.length || !drms2.length) { + return true; + } return shaka.media.DrmEngine.getCommonDrmInfos( drms1, drms2).length > 0; @@ -1694,8 +1728,12 @@ shaka.media.DrmEngine.areDrmCompatible = function(drms1, drms2) { * @return {!Array.} */ shaka.media.DrmEngine.getCommonDrmInfos = function(drms1, drms2) { - if (!drms1.length) return drms2; - if (!drms2.length) return drms1; + if (!drms1.length) { + return drms2; + } + if (!drms2.length) { + return drms1; + } const commonDrms = []; diff --git a/lib/media/gap_jumping_controller.js b/lib/media/gap_jumping_controller.js index 36bc8255f3..074572378f 100644 --- a/lib/media/gap_jumping_controller.js +++ b/lib/media/gap_jumping_controller.js @@ -158,7 +158,9 @@ shaka.media.GapJumpingController.prototype.onSeeking = function() { */ shaka.media.GapJumpingController.prototype.onPollGapJump_ = function() { // Don't gap jump before the video is ready to play. - if (this.video_.readyState == 0) return; + if (this.video_.readyState == 0) { + return; + } // Do not gap jump if seeking has begun, but the seeking event has not // yet fired for this particular seek. if (this.video_.seeking) { @@ -170,7 +172,9 @@ shaka.media.GapJumpingController.prototype.onPollGapJump_ = function() { } // Don't gap jump while paused, so that you don't constantly jump ahead while // paused on a livestream. - if (this.video_.paused) return; + if (this.video_.paused) { + return; + } // When the ready state changes, we have moved on, so we should fire the large diff --git a/lib/media/media_source_engine.js b/lib/media/media_source_engine.js index 178b43c33d..230f037f81 100644 --- a/lib/media/media_source_engine.js +++ b/lib/media/media_source_engine.js @@ -904,7 +904,9 @@ shaka.media.MediaSourceEngine.prototype.onError_ = shaka.media.MediaSourceEngine.prototype.onUpdateEnd_ = function(contentType) { const operation = this.queues_[contentType][0]; goog.asserts.assert(operation, 'Spurious updateend event!'); - if (!operation) return; + if (!operation) { + return; + } goog.asserts.assert(!this.sourceBuffers_[contentType].updating, 'SourceBuffer should not be updating on updateend!'); operation.p.resolve(); @@ -922,7 +924,9 @@ shaka.media.MediaSourceEngine.prototype.onUpdateEnd_ = function(contentType) { */ shaka.media.MediaSourceEngine.prototype.enqueueOperation_ = function(contentType, start) { - if (this.destroyed_) return Promise.reject(); + if (this.destroyed_) { + return Promise.reject(); + } const operation = { start: start, @@ -964,7 +968,9 @@ shaka.media.MediaSourceEngine.prototype.enqueueOperation_ = */ shaka.media.MediaSourceEngine.prototype.enqueueBlockingOperation_ = function(run) { - if (this.destroyed_) return Promise.reject(); + if (this.destroyed_) { + return Promise.reject(); + } const allWaiters = []; diff --git a/lib/media/playhead.js b/lib/media/playhead.js index 0b47595ebf..9de5365fc7 100644 --- a/lib/media/playhead.js +++ b/lib/media/playhead.js @@ -458,10 +458,14 @@ shaka.media.MediaSourcePlayhead = class { */ clampTime_(time) { const start = this.timeline_.getSeekRangeStart(); - if (time < start) return start; + if (time < start) { + return start; + } const end = this.timeline_.getSeekRangeEnd(); - if (time > end) return end; + if (time > end) { + return end; + } return time; } diff --git a/lib/media/segment_index.js b/lib/media/segment_index.js index f6fff1ed16..1dba44a67a 100644 --- a/lib/media/segment_index.js +++ b/lib/media/segment_index.js @@ -302,9 +302,13 @@ if (goog.DEBUG) { */ shaka.media.SegmentIndex.assertCorrectReferences_ = function(references) { goog.asserts.assert(references.every((r2, i) => { - if (i == 0) return true; + if (i == 0) { + return true; + } const r1 = references[i - 1]; - if (r2.position != r1.position + 1) return false; + if (r2.position != r1.position + 1) { + return false; + } if (r1.startTime < r2.startTime) { return true; } else if (r1.startTime > r2.startTime) { diff --git a/lib/media/stall_detector.js b/lib/media/stall_detector.js index 58967b3984..1d3f696d2d 100644 --- a/lib/media/stall_detector.js +++ b/lib/media/stall_detector.js @@ -151,12 +151,18 @@ shaka.media.StallDetector.MediaElementImplementation = class { shouldBeMakingProgress() { // If we are not trying to play, the lack of change could be misidentified // as a stall. - if (this.mediaElement_.paused) { return false; } - if (this.mediaElement_.playbackRate == 0) { return false; } + if (this.mediaElement_.paused) { + return false; + } + if (this.mediaElement_.playbackRate == 0) { + return false; + } // If we have don't have enough content, we are not stalled, we are // buffering. - if (this.mediaElement_.buffered == null) { return false; } + if (this.mediaElement_.buffered == null) { + return false; + } return shaka.media.StallDetector.MediaElementImplementation.hasContentFor_( this.mediaElement_.buffered, @@ -188,8 +194,12 @@ shaka.media.StallDetector.MediaElementImplementation = class { const bufferedStart = buffered.start(i); const bufferedEnd = buffered.end(i); - if (timeInSeconds < bufferedStart) { continue; } - if (timeInSeconds > bufferedEnd - 0.5) { continue; } + if (timeInSeconds < bufferedStart) { + continue; + } + if (timeInSeconds > bufferedEnd - 0.5) { + continue; + } return true; } diff --git a/lib/media/streaming_engine.js b/lib/media/streaming_engine.js index 3a747dca35..3911a16478 100644 --- a/lib/media/streaming_engine.js +++ b/lib/media/streaming_engine.js @@ -472,10 +472,14 @@ shaka.media.StreamingEngine.prototype.getBufferingPeriod = function() { const ContentType = shaka.util.ManifestParserUtils.ContentType; const video = this.mediaStates_.get(ContentType.VIDEO); - if (video) { return this.manifest_.periods[video.needPeriodIndex]; } + if (video) { + return this.manifest_.periods[video.needPeriodIndex]; + } const audio = this.mediaStates_.get(ContentType.AUDIO); - if (audio) { return this.manifest_.periods[audio.needPeriodIndex]; } + if (audio) { + return this.manifest_.periods[audio.needPeriodIndex]; + } return null; }; @@ -567,10 +571,14 @@ shaka.media.StreamingEngine.prototype.loadNewTextStream = async function( streamSet.add(stream); await mediaSourceEngine.init(streamMap, /** forceTansmuxTS */ false); - if (this.destroyed_) { return; } + if (this.destroyed_) { + return; + } await this.setupStreams_(streamSet); - if (this.destroyed_) { return; } + if (this.destroyed_) { + return; + } if ((this.textStreamSequenceId_ == currentSequenceId) && !this.mediaStates_.has(ContentType.TEXT) && @@ -612,25 +620,35 @@ shaka.media.StreamingEngine.prototype.setTrickPlay = function(on) { const ContentType = shaka.util.ManifestParserUtils.ContentType; const mediaState = this.mediaStates_.get(ContentType.VIDEO); - if (!mediaState) return; + if (!mediaState) { + return; + } const stream = mediaState.stream; - if (!stream) return; + if (!stream) { + return; + } shaka.log.debug('setTrickPlay', on); if (on) { const trickModeVideo = stream.trickModeVideo; - if (!trickModeVideo) return; // Can't engage trick play. + if (!trickModeVideo) { + return; // Can't engage trick play. + } const normalVideo = mediaState.restoreStreamAfterTrickPlay; - if (normalVideo) return; // Already in trick play. + if (normalVideo) { + return; // Already in trick play. + } shaka.log.debug('Engaging trick mode stream', trickModeVideo); this.switchInternal_(trickModeVideo, false, 0); mediaState.restoreStreamAfterTrickPlay = stream; } else { const normalVideo = mediaState.restoreStreamAfterTrickPlay; - if (!normalVideo) return; + if (!normalVideo) { + return; + } shaka.log.debug('Restoring non-trick-mode stream', normalVideo); mediaState.restoreStreamAfterTrickPlay = null; @@ -686,7 +704,9 @@ shaka.media.StreamingEngine.prototype.switchInternal_ = function( return; } goog.asserts.assert(mediaState, 'switch: expected mediaState to exist'); - if (!mediaState) return; + if (!mediaState) { + return; + } // If we are selecting a stream from a different Period, then we need to // handle a Period transition. Simply ignore the given stream, assuming that @@ -724,13 +744,17 @@ shaka.media.StreamingEngine.prototype.switchInternal_ = function( goog.asserts.assert( canSwitchRecord && canSwitchRecord.resolved, 'switch: expected Period ' + periodIndex + ' to be ready'); - if (!canSwitchRecord || !canSwitchRecord.resolved) return; + if (!canSwitchRecord || !canSwitchRecord.resolved) { + return; + } // Sanity check. If the Period is ready then the Stream should be ready too. canSwitchRecord = this.canSwitchStream_.get(stream.id); goog.asserts.assert(canSwitchRecord && canSwitchRecord.resolved, 'switch: expected Stream ' + stream.id + ' to be ready'); - if (!canSwitchRecord || !canSwitchRecord.resolved) return; + if (!canSwitchRecord || !canSwitchRecord.resolved) { + return; + } if (mediaState.stream == stream) { const streamTag = shaka.media.StreamingEngine.logPrefix_(mediaState); @@ -984,14 +1008,18 @@ shaka.media.StreamingEngine.prototype.initStreams_ = async function( const forceTransmuxTS = this.config_.forceTransmuxTS; await mediaSourceEngine.init(streamsByType, forceTransmuxTS); - if (this.destroyed_) { return; } + if (this.destroyed_) { + return; + } this.setDuration_(); // Setup the initial set of Streams and then begin each update cycle. After // startup completes onUpdate_() will set up the remaining Periods. await this.setupStreams_(streams); - if (this.destroyed_) { return; } + if (this.destroyed_) { + return; + } streamsByType.forEach((stream, type) => { if (!this.mediaStates_.has(type)) { @@ -1082,15 +1110,21 @@ shaka.media.StreamingEngine.prototype.setupPeriod_ = function(periodIndex) { // Serialize Period set up. this.setupPeriodPromise_ = this.setupPeriodPromise_.then(() => { - if (this.destroyed_) return null; + if (this.destroyed_) { + return null; + } return this.setupStreams_(streams); }).then(() => { - if (this.destroyed_) return; + if (this.destroyed_) { + return; + } this.canSwitchPeriod_[periodIndex].promise.resolve(); this.canSwitchPeriod_[periodIndex].resolved = true; shaka.log.v1('(all) setup Period ' + periodIndex); }).catch((error) => { - if (this.destroyed_) return; + if (this.destroyed_) { + return; + } this.canSwitchPeriod_[periodIndex].promise.catch(() => {}); this.canSwitchPeriod_[periodIndex].promise.reject(); delete this.canSwitchPeriod_[periodIndex]; @@ -1137,9 +1171,13 @@ shaka.media.StreamingEngine.prototype.setupStreams_ = async function(streams) { try { await Promise.all(parallelWork); - if (this.destroyed_) return; + if (this.destroyed_) { + return; + } } catch (error) { - if (this.destroyed_) return; + if (this.destroyed_) { + return; + } for (const stream of streams) { this.canSwitchStream_.get(stream.id).promise.catch(() => {}); @@ -1184,7 +1222,9 @@ shaka.media.StreamingEngine.prototype.setDuration_ = function() { * @private */ shaka.media.StreamingEngine.prototype.onUpdate_ = function(mediaState) { - if (this.destroyed_) return; + if (this.destroyed_) { + return; + } const logPrefix = shaka.media.StreamingEngine.logPrefix_(mediaState); @@ -1192,12 +1232,16 @@ shaka.media.StreamingEngine.prototype.onUpdate_ = function(mediaState) { goog.asserts.assert( !mediaState.performingUpdate && (mediaState.updateTimer != null), logPrefix + ' unexpected call to onUpdate_()'); - if (mediaState.performingUpdate || (mediaState.updateTimer == null)) return; + if (mediaState.performingUpdate || (mediaState.updateTimer == null)) { + return; + } goog.asserts.assert( !mediaState.clearingBuffer, logPrefix + ' onUpdate_() should not be called when clearing the buffer'); - if (mediaState.clearingBuffer) return; + if (mediaState.clearingBuffer) { + return; + } mediaState.updateTimer = null; @@ -1377,7 +1421,9 @@ shaka.media.StreamingEngine.prototype.update_ = function(mediaState) { mediaStates.forEach((otherState) => { // Do not consider embedded captions in this calculation. It could lead // to hangs in streaming. - if (isCaptionState(otherState)) return; + if (isCaptionState(otherState)) { + return; + } const timeNeeded = this.getTimeNeeded_(otherState, presentationTime); minTimeNeeded = Math.min(minTimeNeeded, timeNeeded); @@ -1644,7 +1690,9 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function( Promise.all([initSourceBuffer, fetchSegment]).then((results) => { - if (this.destroyed_ || this.fatalError_) return null; + if (this.destroyed_ || this.fatalError_) { + return null; + } return this.append_(mediaState, presentationTime, currentPeriod, @@ -1652,7 +1700,9 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function( reference, results[1]); }).then(() => { - if (this.destroyed_ || this.fatalError_) return; + if (this.destroyed_ || this.fatalError_) { + return; + } mediaState.performingUpdate = false; mediaState.recovering = false; @@ -1671,7 +1721,9 @@ shaka.media.StreamingEngine.prototype.fetchAndAppend_ = function( shaka.log.v1(logPrefix, 'finished fetch and append'); }).catch((error) => { - if (this.destroyed_ || this.fatalError_) return; + if (this.destroyed_ || this.fatalError_) { + return; + } goog.asserts.assert(error instanceof shaka.util.Error, 'Should only receive a Shaka error'); @@ -1848,7 +1900,9 @@ shaka.media.StreamingEngine.prototype.initSourceBuffer_ = function( const fetchInit = this.fetch_(mediaState, mediaState.stream.initSegmentReference); const appendInit = fetchInit.then((initSegment) => { - if (this.destroyed_) return null; + if (this.destroyed_) { + return null; + } shaka.log.v1(logPrefix, 'appending init segment'); const hasClosedCaptions = mediaState.stream.closedCaptions && mediaState.stream.closedCaptions.size > 0; @@ -1892,7 +1946,9 @@ shaka.media.StreamingEngine.prototype.append_ = function( } return this.evict_(mediaState, presentationTime).then(() => { - if (this.destroyed_) return null; + if (this.destroyed_) { + return null; + } shaka.log.v1(logPrefix, 'appending media segment'); // MediaSourceEngine expects times relative to the start of the @@ -1903,7 +1959,9 @@ shaka.media.StreamingEngine.prototype.append_ = function( return this.playerInterface_.mediaSourceEngine.appendBuffer( mediaState.type, segment, startTime, endTime, hasClosedCaptions); }).then(() => { - if (this.destroyed_) return; + if (this.destroyed_) { + return; + } shaka.log.v2(logPrefix, 'appended media segment'); // We must use |stream| because switch() may have been called. @@ -2018,7 +2076,9 @@ shaka.media.StreamingEngine.prototype.evict_ = function( return this.playerInterface_.mediaSourceEngine.remove( mediaState.type, startTime, startTime + overflow).then(() => { - if (this.destroyed_) return; + if (this.destroyed_) { + return; + } shaka.log.v1(logPrefix, 'evicted ' + overflow + ' seconds'); }); }; @@ -2050,7 +2110,9 @@ shaka.media.StreamingEngine.prototype.handleStartup_ = function( this.startupComplete_ = mediaStates.every((ms) => { // Startup completes once we have buffered at least one segment from each // MediaState, not counting text. - if (ms.type == ContentType.TEXT) return true; + if (ms.type == ContentType.TEXT) { + return true; + } return !ms.waitingToClearBuffer && !ms.clearingBuffer && ms.lastSegmentReference; @@ -2160,7 +2222,9 @@ shaka.media.StreamingEngine.prototype.handlePeriodTransition_ = function( // Ensure the Period which we need to buffer is set up and then call // onChooseStreams(). this.setupPeriod_(needPeriodIndex).then(() => { - if (this.destroyed_) return; + if (this.destroyed_) { + return; + } // If we seek during a Period transition, we can start another transition. // So we need to verify that: @@ -2200,7 +2264,9 @@ shaka.media.StreamingEngine.prototype.handlePeriodTransition_ = function( // Vet |streamsByType| before switching. for (const type of this.mediaStates_.keys()) { - if (streamsByType.has(type) || type == ContentType.TEXT) continue; + if (streamsByType.has(type) || type == ContentType.TEXT) { + continue; + } shaka.log.error(logPrefix, 'invalid Streams chosen: missing ' + type + ' Stream'); @@ -2214,7 +2280,9 @@ shaka.media.StreamingEngine.prototype.handlePeriodTransition_ = function( // Because we are going to modify the map, we need to create a copy of the // keys, so copy the iterable to an array first. for (const type of Array.from(streamsByType.keys())) { - if (this.mediaStates_.has(type)) continue; + if (this.mediaStates_.has(type)) { + continue; + } if (type == ContentType.TEXT) { // initStreams_ will switch streams and schedule an update. @@ -2415,7 +2483,9 @@ shaka.media.StreamingEngine.prototype.clearBuffer_ = } await p; - if (this.destroyed_) return; + if (this.destroyed_) { + return; + } shaka.log.debug(logPrefix, 'cleared buffer'); mediaState.lastStream = null; diff --git a/lib/media/time_ranges_utils.js b/lib/media/time_ranges_utils.js index 61d4e3e972..3f6c9ad495 100644 --- a/lib/media/time_ranges_utils.js +++ b/lib/media/time_ranges_utils.js @@ -34,11 +34,17 @@ goog.require('shaka.util.Platform'); * is non-empty; otherwise, return null. */ shaka.media.TimeRangesUtils.bufferStart = function(b) { - if (!b) return null; + if (!b) { + return null; + } // Workaround Safari bug: https://bit.ly/2trx6O8 - if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) return null; + if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) { + return null; + } // Workaround Edge bug: https://bit.ly/2JYLPeB - if (b.length == 1 && b.start(0) < 0) return 0; + if (b.length == 1 && b.start(0) < 0) { + return 0; + } return b.length ? b.start(0) : null; }; @@ -51,9 +57,13 @@ shaka.media.TimeRangesUtils.bufferStart = function(b) { * is non-empty; otherwise, return null. */ shaka.media.TimeRangesUtils.bufferEnd = function(b) { - if (!b) return null; + if (!b) { + return null; + } // Workaround Safari bug: https://bit.ly/2trx6O8 - if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) return null; + if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) { + return null; + } return b.length ? b.end(b.length - 1) : null; }; @@ -70,9 +80,13 @@ shaka.media.TimeRangesUtils.bufferEnd = function(b) { * @return {boolean} */ shaka.media.TimeRangesUtils.isBuffered = function(b, time, smallGapLimit = 0) { - if (!b || !b.length) return false; + if (!b || !b.length) { + return false; + } // Workaround Safari bug: https://bit.ly/2trx6O8 - if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) return false; + if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) { + return false; + } if (time > b.end(b.length - 1)) { return false; @@ -94,9 +108,13 @@ shaka.media.TimeRangesUtils.isBuffered = function(b, time, smallGapLimit = 0) { * given time. */ shaka.media.TimeRangesUtils.bufferedAheadOf = function(b, time) { - if (!b || !b.length) return 0; + if (!b || !b.length) { + return 0; + } // Workaround Safari bug: https://bit.ly/2trx6O8 - if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) return 0; + if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) { + return 0; + } // NOTE: On IE11, buffered ranges may show appended data before the associated // append operation is complete. @@ -126,9 +144,13 @@ shaka.media.TimeRangesUtils.bufferedAheadOf = function(b, time) { shaka.media.TimeRangesUtils.getGapIndex = function(b, time) { const Platform = shaka.util.Platform; - if (!b || !b.length) return null; + if (!b || !b.length) { + return null; + } // Workaround Safari bug: https://bit.ly/2trx6O8 - if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) return null; + if (b.length == 1 && b.end(0) - b.start(0) < 1e-6) { + return null; + } // Some browsers will stop earlier than others before a gap (e.g. IE/Edge // stops 0.5 seconds before a gap). So for some browsers we need to use a @@ -155,7 +177,9 @@ shaka.media.TimeRangesUtils.getGapIndex = function(b, time) { * @return {!Array.} */ shaka.media.TimeRangesUtils.getBufferedInfo = function(b) { - if (!b) return []; + if (!b) { + return []; + } const ret = []; for (let i = 0; i < b.length; i++) { ret.push({start: b.start(i), end: b.end(i)}); diff --git a/lib/media/webm_segment_index_parser.js b/lib/media/webm_segment_index_parser.js index 7a5958dc9e..1dc2c3459c 100644 --- a/lib/media/webm_segment_index_parser.js +++ b/lib/media/webm_segment_index_parser.js @@ -250,7 +250,7 @@ shaka.media.WebmSegmentIndexParser.prototype.parseCues_ = function( cuesElement, segmentOffset, timecodeScale, duration, uris, scaledPresentationTimeOffset) { const references = []; - const getUris = function() { return uris; }; + const getUris = () => uris; const parser = cuesElement.createParser(); diff --git a/lib/offline/indexeddb/storage_mechanism.js b/lib/offline/indexeddb/storage_mechanism.js index 8de681bfb2..8b276de171 100644 --- a/lib/offline/indexeddb/storage_mechanism.js +++ b/lib/offline/indexeddb/storage_mechanism.js @@ -94,13 +94,23 @@ shaka.offline.indexeddb.StorageMechanism = class { * @override */ async destroy() { - if (this.v1_) { await this.v1_.destroy(); } - if (this.v2_) { await this.v2_.destroy(); } - if (this.v3_) { await this.v3_.destroy(); } - if (this.sessions_) { await this.sessions_.destroy(); } + if (this.v1_) { + await this.v1_.destroy(); + } + if (this.v2_) { + await this.v2_.destroy(); + } + if (this.v3_) { + await this.v3_.destroy(); + } + if (this.sessions_) { + await this.sessions_.destroy(); + } // If we were never initialized, then |db_| will still be null. - if (this.db_) { this.db_.close(); } + if (this.db_) { + this.db_.close(); + } } /** @@ -109,9 +119,15 @@ shaka.offline.indexeddb.StorageMechanism = class { getCells() { const map = new Map(); - if (this.v1_) { map.set('v1', this.v1_); } - if (this.v2_) { map.set('v2', this.v2_); } - if (this.v3_) { map.set('v3', this.v3_); } + if (this.v1_) { + map.set('v1', this.v1_); + } + if (this.v2_) { + map.set('v2', this.v2_); + } + if (this.v3_) { + map.set('v3', this.v3_); + } return map; } @@ -130,14 +146,22 @@ shaka.offline.indexeddb.StorageMechanism = class { async erase() { // Not all cells may have been created, so only destroy the ones that // were created. - if (this.v1_) { await this.v1_.destroy(); } - if (this.v2_) { await this.v2_.destroy(); } - if (this.v3_) { await this.v3_.destroy(); } + if (this.v1_) { + await this.v1_.destroy(); + } + if (this.v2_) { + await this.v2_.destroy(); + } + if (this.v3_) { + await this.v3_.destroy(); + } // |db_| will only be null if the muxer was not initialized. We need to // close the connection in order delete the database without it being // blocked. - if (this.db_) { this.db_.close(); } + if (this.db_) { + this.db_.close(); + } await shaka.offline.indexeddb.StorageMechanism.deleteAll_(); diff --git a/lib/offline/indexeddb/v1_storage_cell.js b/lib/offline/indexeddb/v1_storage_cell.js index ffdc5e424f..ef95b2d423 100644 --- a/lib/offline/indexeddb/v1_storage_cell.js +++ b/lib/offline/indexeddb/v1_storage_cell.js @@ -543,8 +543,12 @@ shaka.offline.indexeddb.V1StorageCell = class { // Case 1 - Populate all the variant ids (putting us back to case 2). // Since all the variant ids are null, we need to first make them into // valid arrays. - audio.forEach((s) => { s.variantIds = []; }); - video.forEach((s) => { s.variantIds = []; }); + audio.forEach((s) => { + s.variantIds = []; + }); + video.forEach((s) => { + s.variantIds = []; + }); let nextId = 0; @@ -557,7 +561,9 @@ shaka.offline.indexeddb.V1StorageCell = class { if (video.length && !audio.length) { shaka.log.debug('Found video-only content. Creating variants for video.'); const variantId = nextId++; - video.forEach((s) => { s.variantIds.push(variantId); }); + video.forEach((s) => { + s.variantIds.push(variantId); + }); } // Everything is audio-only content - so each audio stream gets to be its @@ -565,7 +571,9 @@ shaka.offline.indexeddb.V1StorageCell = class { if (!video.length && audio.length) { shaka.log.debug('Found audio-only content. Creating variants for audio.'); const variantId = nextId++; - audio.forEach((s) => { s.variantIds.push(variantId); }); + audio.forEach((s) => { + s.variantIds.push(variantId); + }); } // Everything is audio-video content. diff --git a/lib/offline/manifest_converter.js b/lib/offline/manifest_converter.js index 2756357720..aa6154acb5 100644 --- a/lib/offline/manifest_converter.js +++ b/lib/offline/manifest_converter.js @@ -63,7 +63,9 @@ shaka.offline.ManifestConverter = class { const drmInfos = manifestDB.drmInfo ? [manifestDB.drmInfo] : []; if (manifestDB.drmInfo) { periods.forEach((period) => { - period.variants.forEach((variant) => { variant.drmInfos = drmInfos; }); + period.variants.forEach((variant) => { + variant.drmInfos = drmInfos; + }); }); } @@ -126,10 +128,14 @@ shaka.offline.ManifestConverter = class { /** @type {!Set.} */ const variantIds = new Set(); for (const stream of audios) { - for (const id of stream.variantIds) { variantIds.add(id); } + for (const id of stream.variantIds) { + variantIds.add(id); + } } for (const stream of videos) { - for (const id of stream.variantIds) { variantIds.add(id); } + for (const id of stream.variantIds) { + variantIds.add(id); + } } /** @type {!Map.} */ diff --git a/lib/offline/offline_uri.js b/lib/offline/offline_uri.js index 83fb2b4fe3..ef1b764b29 100644 --- a/lib/offline/offline_uri.js +++ b/lib/offline/offline_uri.js @@ -90,19 +90,29 @@ shaka.offline.OfflineUri = class { */ static parse(uri) { const parts = /^offline:([a-z]+)\/([^/]+)\/([^/]+)\/([0-9]+)$/.exec(uri); - if (parts == null) { return null; } + if (parts == null) { + return null; + } const type = parts[1]; - if (type != 'manifest' && type != 'segment') { return null; } + if (type != 'manifest' && type != 'segment') { + return null; + } const mechanism = parts[2]; - if (!mechanism) { return null; } + if (!mechanism) { + return null; + } const cell = parts[3]; - if (!cell) { return null; } + if (!cell) { + return null; + } const key = Number(parts[4]); - if (type == null) { return null; } + if (type == null) { + return null; + } return new shaka.offline.OfflineUri(type, mechanism, cell, key); } diff --git a/lib/offline/storage.js b/lib/offline/storage.js index 09aa69111b..9e7b70a11b 100644 --- a/lib/offline/storage.js +++ b/lib/offline/storage.js @@ -160,7 +160,9 @@ shaka.offline.Storage.support = function() { // Our Storage system is useless without MediaSource. MediaSource allows us // to pull data from anywhere (including our Storage system) and feed it to // the video element. - if (!shaka.util.Platform.supportsMediaSource()) return false; + if (!shaka.util.Platform.supportsMediaSource()) { + return false; + } return shaka.offline.StorageMuxer.support(); }; @@ -368,7 +370,9 @@ shaka.offline.Storage.prototype.store_ = async function( // We could have been asked to destroy ourselves while we were "away" // creating the drm engine. this.checkDestroyed_(); - if (drmError) { throw drmError; } + if (drmError) { + throw drmError; + } this.filterManifest_(manifest, drmEngine); @@ -386,7 +390,9 @@ shaka.offline.Storage.prototype.store_ = async function( const manifestDB = await this.downloadManifest_( activeHandle.cell, drmEngine, manifest, uri, appMetadata); this.checkDestroyed_(); - if (drmError) { throw drmError; } + if (drmError) { + throw drmError; + } const ids = await activeHandle.cell.addManifests([manifestDB]); this.checkDestroyed_(); @@ -474,8 +480,12 @@ shaka.offline.Storage.prototype.filterManifest_ = function( const textIds = new Set(); for (const track of chosenTracks) { - if (track.type == 'variant') { variantIds.add(track.id); } - if (track.type == 'text') { textIds.add(track.id); } + if (track.type == 'variant') { + variantIds.add(track.id); + } + if (track.type == 'text') { + textIds.add(track.id); + } } period.variants = @@ -957,8 +967,12 @@ shaka.offline.Storage.prototype.createPeriod_ = function( // Pass all variants and text streams to the estimator so that we can // get the best estimate for each stream later. manifest.periods.forEach((period) => { - period.variants.forEach((variant) => { estimator.addVariant(variant); }); - period.textStreams.forEach((text) => { estimator.addText(text); }); + period.variants.forEach((variant) => { + estimator.addVariant(variant); + }); + period.textStreams.forEach((text) => { + estimator.addText(text); + }); }); // Find the streams we want to download and create a stream db instance @@ -1262,8 +1276,12 @@ shaka.offline.Storage.getStreamSet_ = function(manifest) { } for (const variant of period.variants) { - if (variant.audio) { set.add(variant.audio); } - if (variant.video) { set.add(variant.video); } + if (variant.audio) { + set.add(variant.audio); + } + if (variant.video) { + set.add(variant.video); + } } } diff --git a/lib/offline/storage_muxer.js b/lib/offline/storage_muxer.js index a6426275e1..86f20c4226 100644 --- a/lib/offline/storage_muxer.js +++ b/lib/offline/storage_muxer.js @@ -139,7 +139,9 @@ shaka.offline.StorageMuxer = class { mechanism.getCells().forEach((cell, cellName) => { // If this cell is not useful to us or we already have a handle, then // we don't need to make a new handle. - if (cell.hasFixedKeySpace() || handle) { return; } + if (cell.hasFixedKeySpace() || handle) { + return; + } const path = { mechanism: mechanismName, @@ -251,7 +253,9 @@ shaka.offline.StorageMuxer = class { resolvePath(path) { const mechanism = this.mechanisms_.get(path.mechanism); - if (!mechanism) { return null; } + if (!mechanism) { + return null; + } return mechanism.getCells().get(path.cell); } diff --git a/lib/player.js b/lib/player.js index 0656ffbab4..9f127b3044 100644 --- a/lib/player.js +++ b/lib/player.js @@ -705,16 +705,22 @@ shaka.Player.isBrowserSupported = function() { // Basic features needed for the library to be usable. const basicSupport = !!window.Promise && !!window.Uint8Array && !!Array.prototype.forEach; - if (!basicSupport) return false; + if (!basicSupport) { + return false; + } // DRM support is not strictly necessary, but the APIs at least need to be // there. Our no-op DRM polyfill should handle that. // TODO(#1017): Consider making even DrmEngine optional. const drmSupport = shaka.media.DrmEngine.isBrowserSupported(); - if (!drmSupport) return false; + if (!drmSupport) { + return false; + } // If we have MediaSource (MSE) support, we should be able to use Shaka. - if (shaka.util.Platform.supportsMediaSource()) return true; + if (shaka.util.Platform.supportsMediaSource()) { + return true; + } // If we don't have MSE, we _may_ be able to use Shaka. Look for native HLS // support, and call this platform usable if we have it. @@ -2060,7 +2066,9 @@ shaka.Player.prototype.chooseCodecsAndFilterManifest_ = function() { this.manifest_.periods.forEach((period) => { period.variants = period.variants.filter((variant) => { const codecs = variantCodecs(variant); - if (codecs == bestCodecs) return true; + if (codecs == bestCodecs) { + return true; + } shaka.log.debug('Dropping Variant (better codec available)', variant); return false; @@ -2552,10 +2560,14 @@ shaka.Player.prototype.isInProgress = function() { shaka.Player.prototype.isAudioOnly = function() { if (this.manifest_) { const periods = this.manifest_.periods; - if (!periods.length) { return false; } + if (!periods.length) { + return false; + } const variants = this.manifest_.periods[0].variants; - if (!variants.length) { return false; } + if (!variants.length) { + return false; + } // Note that if there are some audio-only variants and some audio-video // variants, the audio-only variants are removed during filtering. @@ -3808,7 +3820,9 @@ shaka.Player.prototype.switchTextStream_ = function(textStream) { * @private */ shaka.Player.prototype.assertCorrectActiveStreams_ = function() { - if (!this.streamingEngine_ || !this.manifest_ || !goog.DEBUG) return; + if (!this.streamingEngine_ || !this.manifest_ || !goog.DEBUG) { + return; + } const activePeriod = this.streamingEngine_.getBufferingPeriod(); /** @type {shaka.extern.Period} */ @@ -3868,11 +3882,17 @@ shaka.Player.prototype.adjustStartTime_ = function(time) { // This method is called after StreamingEngine.init resolves, which means that // all the active streams have had createSegmentIndex called. function getAdjustedTime(stream, time) { - if (!stream) return null; + if (!stream) { + return null; + } const idx = stream.findSegmentPosition(time - period.startTime); - if (idx == null) return null; + if (idx == null) { + return null; + } const ref = stream.getSegmentReference(idx); - if (!ref) return null; + if (!ref) { + return null; + } const refTime = ref.startTime + period.startTime; goog.asserts.assert(refTime <= time, 'Segment should start before time'); return refTime; @@ -3969,8 +3989,12 @@ shaka.Player.prototype.onRateChange_ = function() { */ shaka.Player.prototype.updateStateHistory_ = function() { // If we have not finish initializing, this will be a no-op. - if (!this.stats_) { return; } - if (!this.bufferObserver_) { return; } + if (!this.stats_) { + return; + } + if (!this.bufferObserver_) { + return; + } const State = shaka.media.BufferingObserver.State; @@ -4401,7 +4425,9 @@ shaka.Player.prototype.onError_ = function(error) { // Errors dispatched after |destroy| is called are not meaningful and should // be safe to ignore. - if (this.loadMode_ == shaka.Player.LoadMode.DESTROYED) { return; } + if (this.loadMode_ == shaka.Player.LoadMode.DESTROYED) { + return; + } const event = new shaka.util.FakeEvent('error', {'detail': error}); this.dispatchEvent(event); @@ -4653,8 +4679,12 @@ shaka.Player.prototype.checkRestrictedVariants_ = function(variants) { for (const variant of variants) { // TODO: Combine with onKeyStatus_. const streams = []; - if (variant.audio) streams.push(variant.audio); - if (variant.video) streams.push(variant.video); + if (variant.audio) { + streams.push(variant.audio); + } + if (variant.video) { + streams.push(variant.video); + } for (const stream of streams) { if (stream.keyId) { @@ -4802,7 +4832,9 @@ shaka.Player.prototype.getSelectableVariants_ = function() { // If we have been called before we load content or after we have unloaded // content, then we should return no variants. - if (currentPeriod == null) { return []; } + if (currentPeriod == null) { + return []; + } this.assertCorrectActiveStreams_(); @@ -4827,7 +4859,9 @@ shaka.Player.prototype.getSelectableText_ = function() { // If we have been called before we load content or after we have unloaded // content, then we should return no streams. - if (currentPeriod == null) { return []; } + if (currentPeriod == null) { + return []; + } this.assertCorrectActiveStreams_(); @@ -4893,7 +4927,9 @@ shaka.Player.prototype.getPresentationText_ = function() { const currentPeriod = this.getPresentationPeriod_(); // Can't have a text stream when there is no period. - if (currentPeriod == null) { return null; } + if (currentPeriod == null) { + return null; + } // This is a workaround for the demo page to be able to display the list of // text tracks. If no text track is currently active, pick the one that's\ @@ -5158,16 +5194,22 @@ shaka.Player.prototype.getNextStep_ = function( shaka.Player.prototype.getNextAfterAttach_ = function(goingTo, has, wants) { // Attach and detach are the only two nodes that we can directly go // back-and-forth between. - if (goingTo == this.detachNode_) { return this.detachNode_; } + if (goingTo == this.detachNode_) { + return this.detachNode_; + } // If we are going anywhere other than detach, then we need the media element // to match, if they don't match, we need to go through detach first. - if (has.mediaElement != wants.mediaElement) { return this.detachNode_; } + if (has.mediaElement != wants.mediaElement) { + return this.detachNode_; + } // If we are already in attached, and someone calls |attach| again (to the // same video element), we can handle the redundant request by re-entering // our current state. - if (goingTo == this.attachNode_) { return this.attachNode_; } + if (goingTo == this.attachNode_) { + return this.attachNode_; + } // The next step from attached to loaded is through media source. if (goingTo == this.mediaSourceNode_ || goingTo == this.loadNode_) { diff --git a/lib/polyfill/mediasource.js b/lib/polyfill/mediasource.js index 7911c4ff90..46a74bf0b0 100644 --- a/lib/polyfill/mediasource.js +++ b/lib/polyfill/mediasource.js @@ -355,7 +355,9 @@ shaka.polyfill.MediaSource.patchCastIsTypeSupported_ = function() { // If the content uses Dolby Vision, we take this as a sign that the content // is not HDR after all. - if (isDolbyVision) isHDR = false; + if (isDolbyVision) { + isHDR = false; + } // Reconstruct the "codecs" parameter from the results of the filter. parameters['codecs'] = codecList.join(','); diff --git a/lib/polyfill/patchedmediakeys_webkit.js b/lib/polyfill/patchedmediakeys_webkit.js index da2e8930db..d325e0a979 100644 --- a/lib/polyfill/patchedmediakeys_webkit.js +++ b/lib/polyfill/patchedmediakeys_webkit.js @@ -421,7 +421,9 @@ shaka.polyfill.PatchedMediaKeysWebkit.MediaKeys.prototype.createSession = // Prefixed EME requires both a valid HTMLMediaElement and a src. const media = this.media_ || /** @type {!HTMLMediaElement} */( document.createElement('video')); - if (!media.src) media.src = 'about:blank'; + if (!media.src) { + media.src = 'about:blank'; + } const session = new PatchedMediaKeysWebkit.MediaKeySession( media, this.keySystem_, sessionType); diff --git a/lib/text/mp4_vtt_parser.js b/lib/text/mp4_vtt_parser.js index d50e8d58b5..819857b171 100644 --- a/lib/text/mp4_vtt_parser.js +++ b/lib/text/mp4_vtt_parser.js @@ -280,13 +280,19 @@ shaka.text.Mp4VttParser.parseTFHD_ = function(flags, reader) { reader.skip(4); // Skip "base_data_offset" if present. - if (flags & 0x000001) { reader.skip(8); } + if (flags & 0x000001) { + reader.skip(8); + } // Skip "sample_description_index" if present. - if (flags & 0x000002) { reader.skip(4); } + if (flags & 0x000002) { + reader.skip(4); + } // Read and return "default_sample_duration" if present. - if (flags & 0x000008) { return reader.readUint32(); } + if (flags & 0x000008) { + return reader.readUint32(); + } // There is no "default_sample_duration". return null; @@ -304,10 +310,14 @@ shaka.text.Mp4VttParser.parseTRUN_ = function(version, flags, reader) { const sampleCount = reader.readUint32(); // Skip "data_offset" if present. - if (flags & 0x000001) { reader.skip(4); } + if (flags & 0x000001) { + reader.skip(4); + } // Skip "first_sample_flags" if present. - if (flags & 0x000004) { reader.skip(4); } + if (flags & 0x000004) { + reader.skip(4); + } const samples = []; @@ -320,13 +330,19 @@ shaka.text.Mp4VttParser.parseTRUN_ = function(version, flags, reader) { }; // Read "sample duration" if present. - if (flags & 0x000100) { sample.duration = reader.readUint32(); } + if (flags & 0x000100) { + sample.duration = reader.readUint32(); + } // Read "sample_size" if present. - if (flags & 0x000200) { sample.sampleSize = reader.readUint32(); } + if (flags & 0x000200) { + sample.sampleSize = reader.readUint32(); + } // Skip "sample_flags" if present. - if (flags & 0x000400) { reader.skip(4); } + if (flags & 0x000400) { + reader.skip(4); + } // Read "sample_time_offset" if present. if (flags & 0x000800) { diff --git a/lib/text/simple_text_displayer.js b/lib/text/simple_text_displayer.js index 4a609e03d8..606989a349 100644 --- a/lib/text/simple_text_displayer.js +++ b/lib/text/simple_text_displayer.js @@ -74,7 +74,9 @@ shaka.text.SimpleTextDisplayer = function(video) { */ shaka.text.SimpleTextDisplayer.prototype.remove = function(start, end) { // Check that the displayer hasn't been destroyed. - if (!this.textTrack_) return false; + if (!this.textTrack_) { + return false; + } const removeInRange = (cue) => { const inside = cue.startTime < end && cue.endTime > start; diff --git a/lib/text/text_engine.js b/lib/text/text_engine.js index eccf085da7..cf33c2cf28 100644 --- a/lib/text/text_engine.js +++ b/lib/text/text_engine.js @@ -189,7 +189,9 @@ shaka.text.TextEngine.prototype.appendBuffer = // Start the operation asynchronously to avoid blocking the caller. return Promise.resolve().then(() => { // Check that TextEngine hasn't been destroyed. - if (!this.parser_ || !this.displayer_) return; + if (!this.parser_ || !this.displayer_) { + return; + } if (startTime == null || endTime == null) { this.parser_.parseInit(new Uint8Array(buffer)); @@ -326,7 +328,9 @@ shaka.text.TextEngine.prototype.isBuffered = function(t) { * @return {number} Number of seconds ahead of 't' we have buffered */ shaka.text.TextEngine.prototype.bufferedAheadOf = function(t) { - if (this.bufferEnd_ == null || this.bufferEnd_ < t) return 0; + if (this.bufferEnd_ == null || this.bufferEnd_ < t) { + return 0; + } goog.asserts.assert( this.bufferStart_ != null, 'start should not be null if end is not null'); diff --git a/lib/util/data_view_reader.js b/lib/util/data_view_reader.js index 64f0cd8d74..6046ce8f29 100644 --- a/lib/util/data_view_reader.js +++ b/lib/util/data_view_reader.js @@ -269,7 +269,9 @@ shaka.util.DataViewReader.prototype.readTerminatedString = function() { const start = this.position_; while (this.hasMoreData()) { const value = this.dataView_.getUint8(this.position_); - if (value == 0) break; + if (value == 0) { + break; + } this.position_ += 1; } diff --git a/lib/util/event_manager.js b/lib/util/event_manager.js index 92c62179e2..e14cd812f3 100644 --- a/lib/util/event_manager.js +++ b/lib/util/event_manager.js @@ -62,7 +62,9 @@ shaka.util.EventManager.prototype.release = function() { * @param {shaka.util.EventManager.ListenerType} listener The event listener. */ shaka.util.EventManager.prototype.listen = function(target, type, listener) { - if (!this.bindingMap_) return; + if (!this.bindingMap_) { + return; + } const binding = new shaka.util.EventManager.Binding_(target, type, listener); this.bindingMap_.push(type, binding); @@ -96,7 +98,9 @@ shaka.util.EventManager.prototype.listenOnce = * @param {shaka.util.EventManager.ListenerType=} listener The event listener. */ shaka.util.EventManager.prototype.unlisten = function(target, type, listener) { - if (!this.bindingMap_) return; + if (!this.bindingMap_) { + return; + } const list = this.bindingMap_.get(type) || []; @@ -117,7 +121,9 @@ shaka.util.EventManager.prototype.unlisten = function(target, type, listener) { * Detaches all event listeners from all targets. */ shaka.util.EventManager.prototype.removeAll = function() { - if (!this.bindingMap_) return; + if (!this.bindingMap_) { + return; + } const list = this.bindingMap_.getAll(); diff --git a/lib/util/iterables.js b/lib/util/iterables.js index 3d842c0e63..c33dcb1c8c 100644 --- a/lib/util/iterables.js +++ b/lib/util/iterables.js @@ -32,7 +32,9 @@ shaka.util.Iterables = class { */ static map(iterable, mapping) { const array = []; - for (const x of iterable) { array.push(mapping(x)); } + for (const x of iterable) { + array.push(mapping(x)); + } return array; } @@ -44,7 +46,9 @@ shaka.util.Iterables = class { */ static every(iterable, test) { for (const x of iterable) { - if (!test(x)) { return false; } + if (!test(x)) { + return false; + } } return true; } @@ -57,7 +61,9 @@ shaka.util.Iterables = class { */ static some(iterable, test) { for (const x of iterable) { - if (test(x)) { return true; } + if (test(x)) { + return true; + } } return false; } @@ -74,7 +80,9 @@ shaka.util.Iterables = class { static filter(iterable, filter) { const out = []; for (const x of iterable) { - if (filter(x)) { out.push(x); } + if (filter(x)) { + out.push(x); + } } return out; } diff --git a/lib/util/manifest_parser_utils.js b/lib/util/manifest_parser_utils.js index d57762d1fb..3008cde650 100644 --- a/lib/util/manifest_parser_utils.js +++ b/lib/util/manifest_parser_utils.js @@ -41,14 +41,13 @@ shaka.util.ManifestParserUtils.resolveUris = function(baseUris, relativeUris) { return baseUris; } - const relativeAsGoog = - relativeUris.map((uri) => { return new goog.Uri(uri); }); + const relativeAsGoog = relativeUris.map((uri) => new goog.Uri(uri)); // Resolve each URI relative to each base URI, creating an Array of Arrays. // Then flatten the Arrays into a single Array. - return baseUris.map((uri) => { return new goog.Uri(uri); }) - .map((base) => { return relativeAsGoog.map(base.resolve.bind(base)); }) + return baseUris.map((uri) => new goog.Uri(uri)) + .map((base) => relativeAsGoog.map(base.resolve.bind(base))) .reduce(Functional.collapseArrays, []) - .map((uri) => { return uri.toString(); }); + .map((uri) => uri.toString()); }; diff --git a/lib/util/multi_map.js b/lib/util/multi_map.js index 4be21dc68d..9a3f8d3785 100644 --- a/lib/util/multi_map.js +++ b/lib/util/multi_map.js @@ -77,7 +77,9 @@ shaka.util.MultiMap.prototype.getAll = function() { */ shaka.util.MultiMap.prototype.remove = function(key, value) { const list = this.map_[key]; - if (!list) return; + if (!list) { + return; + } for (let i = 0; i < list.length; ++i) { if (list[i] == value) { list.splice(i, 1); diff --git a/lib/util/object_utils.js b/lib/util/object_utils.js index 957d27c6e2..db1fbaf89d 100644 --- a/lib/util/object_utils.js +++ b/lib/util/object_utils.js @@ -45,7 +45,9 @@ shaka.util.ObjectUtils = class { case 'object': default: { // typeof null === 'object' - if (!val) return val; + if (!val) { + return val; + } // This covers Uint8Array and friends, even without a TypedArray // base-class constructor. diff --git a/lib/util/player_configuration.js b/lib/util/player_configuration.js index 0cc3386e8c..3cf323a6b8 100644 --- a/lib/util/player_configuration.js +++ b/lib/util/player_configuration.js @@ -335,7 +335,9 @@ shaka.util.PlayerConfiguration = class { // better demo for us, and does not rely on user preferences for the // unconfigured app. for (const track of tracks) { - if (track.type == ContentType.TEXT) { selectedTracks.push(track); } + if (track.type == ContentType.TEXT) { + selectedTracks.push(track); + } } return selectedTracks; diff --git a/lib/util/stream_utils.js b/lib/util/stream_utils.js index 0fca23296a..14308d8de3 100644 --- a/lib/util/stream_utils.js +++ b/lib/util/stream_utils.js @@ -238,27 +238,43 @@ shaka.util.StreamUtils.variantToTrack = function(variant) { /** @type {!Array.} */ const codecs = []; - if (videoCodec) codecs.push(videoCodec); - if (audioCodec) codecs.push(audioCodec); + if (videoCodec) { + codecs.push(videoCodec); + } + if (audioCodec) { + codecs.push(audioCodec); + } /** @type {!Array.} */ const mimeTypes = []; - if (video) mimeTypes.push(video.mimeType); - if (audio) mimeTypes.push(audio.mimeType); + if (video) { + mimeTypes.push(video.mimeType); + } + if (audio) { + mimeTypes.push(audio.mimeType); + } /** @type {?string} */ const mimeType = mimeTypes[0] || null; /** @type {!Array.} */ const kinds = []; - if (audio) kinds.push(audio.kind); - if (video) kinds.push(video.kind); + if (audio) { + kinds.push(audio.kind); + } + if (video) { + kinds.push(video.kind); + } /** @type {?string} */ const kind = kinds[0] || null; /** @type {!Set.} */ const roles = new Set(); - if (audio) audio.roles.forEach((role) => roles.add(role)); - if (video) video.roles.forEach((role) => roles.add(role)); + if (audio) { + audio.roles.forEach((role) => roles.add(role)); + } + if (video) { + video.roles.forEach((role) => roles.add(role)); + } /** @type {shaka.extern.Track} */ const track = { @@ -690,8 +706,12 @@ shaka.util.StreamUtils.isVideo = function(stream) { shaka.util.StreamUtils.getVariantStreams = function(variant) { const streams = []; - if (variant.audio) { streams.push(variant.audio); } - if (variant.video) { streams.push(variant.video); } + if (variant.audio) { + streams.push(variant.audio); + } + if (variant.video) { + streams.push(variant.video); + } return streams; }; diff --git a/lib/util/string_utils.js b/lib/util/string_utils.js index 187f47e9b2..cf3837f760 100644 --- a/lib/util/string_utils.js +++ b/lib/util/string_utils.js @@ -37,7 +37,9 @@ goog.require('shaka.util.Error'); * @export */ shaka.util.StringUtils.fromUTF8 = function(data) { - if (!data) return ''; + if (!data) { + return ''; + } let uint8 = new Uint8Array(data); // If present, strip off the UTF-8 BOM. @@ -78,7 +80,9 @@ shaka.util.StringUtils.fromUTF8 = function(data) { * @export */ shaka.util.StringUtils.fromUTF16 = function(data, littleEndian, noThrow) { - if (!data) return ''; + if (!data) { + return ''; + } if (!noThrow && data.byteLength % 2 != 0) { shaka.log.error('Data has an incorrect length, must be even.'); diff --git a/lib/util/switch_history.js b/lib/util/switch_history.js index 846e5233e4..352d7d2a4c 100644 --- a/lib/util/switch_history.js +++ b/lib/util/switch_history.js @@ -44,7 +44,9 @@ shaka.util.SwitchHistory = class { * @param {boolean} fromAdaptation */ updateCurrentVariant(newVariant, fromAdaptation) { - if (this.currentVariant_ == newVariant) { return; } + if (this.currentVariant_ == newVariant) { + return; + } this.currentVariant_ = newVariant; this.history_.push({ @@ -64,7 +66,9 @@ shaka.util.SwitchHistory = class { * @param {boolean} fromAdaptation */ updateCurrentText(newText, fromAdaptation) { - if (this.currentText_ == newText) { return; } + if (this.currentText_ == newText) { + return; + } this.currentText_ = newText; this.history_.push({ diff --git a/lib/util/uint8array_utils.js b/lib/util/uint8array_utils.js index 5acf039557..b59107aea8 100644 --- a/lib/util/uint8array_utils.js +++ b/lib/util/uint8array_utils.js @@ -98,7 +98,9 @@ shaka.util.Uint8ArrayUtils.toHex = function(arr) { let hex = ''; for (let i = 0; i < arr.length; ++i) { let value = arr[i].toString(16); - if (value.length == 1) value = '0' + value; + if (value.length == 1) { + value = '0' + value; + } hex += value; } return hex; @@ -113,11 +115,19 @@ shaka.util.Uint8ArrayUtils.toHex = function(arr) { * @export */ shaka.util.Uint8ArrayUtils.equal = function(arr1, arr2) { - if (!arr1 && !arr2) return true; - if (!arr1 || !arr2) return false; - if (arr1.length != arr2.length) return false; + if (!arr1 && !arr2) { + return true; + } + if (!arr1 || !arr2) { + return false; + } + if (arr1.length != arr2.length) { + return false; + } for (let i = 0; i < arr1.length; ++i) { - if (arr1[i] != arr2[i]) return false; + if (arr1[i] != arr2[i]) { + return false; + } } return true; }; diff --git a/test/cast/cast_proxy_unit.js b/test/cast/cast_proxy_unit.js index c7a90d5ef0..02ae93a5d7 100644 --- a/test/cast/cast_proxy_unit.js +++ b/test/cast/cast_proxy_unit.js @@ -382,10 +382,13 @@ describe('CastProxy', () => { mockSender.get.and.callFake((targetName, property) => { expect(targetName).toEqual('player'); const value = cache.player[property]; - // methods: - if (typeof value == 'function') return value; - // getters: - else return function() { return value; }; + if (typeof value == 'function') { + // methods: + return value; + } else { + // getters: + return () => value; + } }); expect(proxy.getPlayer().getConfiguration()).toEqual(fakeConfig2); @@ -543,7 +546,7 @@ describe('CastProxy', () => { }; mockSender.get.and.callFake((targetName, property) => { if (targetName == 'player') { - return function() { return cache[targetName][property]; }; + return () => cache[targetName][property]; } else { return cache[targetName][property]; } diff --git a/test/cast/cast_receiver_unit.js b/test/cast/cast_receiver_unit.js index 1bb4b21e90..db37ce18e1 100644 --- a/test/cast/cast_receiver_unit.js +++ b/test/cast/cast_receiver_unit.js @@ -76,7 +76,9 @@ describe('CastReceiver', () => { isChrome = navigator.userAgent.includes('Chrome/') && !isEdge; // Don't do any more work here if the tests will not end up running. - if (!isChromecast && !isChrome) return; + if (!isChromecast && !isChrome) { + return; + } // In uncompiled mode, there is a UA check for Chromecast in order to make // manual testing easier. For these automated tests, we want to act as if @@ -143,7 +145,9 @@ describe('CastReceiver', () => { mockCanDisplayType.and.callFake((type) => { const matches = /height=(\d+)/.exec(type); const height = matches[1]; - if (height && height > 1080) return false; + if (height && height > 1080) { + return false; + } return true; }); receiver = new CastReceiver( @@ -158,7 +162,9 @@ describe('CastReceiver', () => { mockCanDisplayType.and.callFake((type) => { const matches = /height=(\d+)/.exec(type); const height = matches[1]; - if (height && height > 2160) return false; + if (height && height > 2160) { + return false; + } return true; }); receiver = new CastReceiver( diff --git a/test/dash/dash_parser_live_unit.js b/test/dash/dash_parser_live_unit.js index ffe9ffa70f..1d954acd9a 100644 --- a/test/dash/dash_parser_live_unit.js +++ b/test/dash/dash_parser_live_unit.js @@ -190,7 +190,7 @@ describe('DashParser Live', () => { template, {updateTime: updateTime, contents: basicLines.join('\n')}); fakeNetEngine.setResponseText('dummy://foo', text); - Date.now = function() { return 0; }; + Date.now = () => 0; parser.start('dummy://foo', playerInterface) .then((manifest) => { expect(manifest).toBeTruthy(); @@ -206,7 +206,7 @@ describe('DashParser Live', () => { // seconds long in all of these cases. So 11 seconds after the // manifest was parsed, the first segment should have fallen out of // the availability window. - Date.now = function() { return 11 * 1000; }; + Date.now = () => 11 * 1000; delayForUpdatePeriod(); // The first reference should have been evicted. expect(stream.findSegmentPosition(0)).toBe(2); @@ -244,7 +244,7 @@ describe('DashParser Live', () => { const durs = basicRefs.map((r) => { return r.endTime - r.startTime; }); - const pStart = durs.reduce((p, d) => { return p + d; }, 0); + const pStart = durs.reduce((p, d) => p + d, 0); const args = { updateTime: updateTime, pStart: pStart, @@ -253,7 +253,7 @@ describe('DashParser Live', () => { const text = sprintf(template, args); fakeNetEngine.setResponseText('dummy://foo', text); - Date.now = function() { return 0; }; + Date.now = () => 0; parser.start('dummy://foo', playerInterface) .then((manifest) => { const stream1 = manifest.periods[0].variants[0].video; @@ -266,14 +266,14 @@ describe('DashParser Live', () => { // seconds long in all of these cases. So 11 seconds after the // manifest was parsed, the first segment should have fallen out of // the availability window. - Date.now = function() { return 11 * 1000; }; + Date.now = () => 11 * 1000; delayForUpdatePeriod(); // The first reference should have been evicted. ManifestParser.verifySegmentIndex(stream1, basicRefs.slice(1)); ManifestParser.verifySegmentIndex(stream2, basicRefs); // Same as above, but 1 period length later - Date.now = function() { return (11 + pStart) * 1000; }; + Date.now = () => (11 + pStart) * 1000; delayForUpdatePeriod(); ManifestParser.verifySegmentIndex(stream1, []); ManifestParser.verifySegmentIndex(stream2, basicRefs.slice(1)); @@ -301,7 +301,7 @@ describe('DashParser Live', () => { template, {updateTime: updateTime, contents: basicLines.join('\n')}); fakeNetEngine.setResponseText('dummy://foo', text); - Date.now = function() { return 0; }; + Date.now = () => 0; parser.start('dummy://foo', playerInterface) .then((manifest) => { expect(manifest.periods.length).toBe(1); @@ -339,7 +339,7 @@ describe('DashParser Live', () => { template, {updateTime: updateTime, contents: basicLines.join('\n')}); fakeNetEngine.setResponseText('dummy://foo', text); - Date.now = function() { return 0; }; + Date.now = () => 0; parser.start('dummy://foo', playerInterface) .then((manifest) => { expect(manifest.periods.length).toBe(2); @@ -662,7 +662,7 @@ describe('DashParser Live', () => { ].join('\n'); fakeNetEngine.setResponseText('dummy://foo', manifest); - Date.now = function() { return 600000; /* 10 minutes */ }; + Date.now = () => 600000; /* 10 minutes */ parser.start('dummy://foo', playerInterface) .then((manifest) => { expect(manifest).toBeTruthy(); @@ -705,7 +705,7 @@ describe('DashParser Live', () => { config.availabilityWindowOverride = 4 * 60; parser.configure(config); - Date.now = function() { return 600000; /* 10 minutes */ }; + Date.now = () => 600000; /* 10 minutes */ parser.start('dummy://foo', playerInterface) .then((manifest) => { expect(manifest).toBeTruthy(); @@ -742,7 +742,7 @@ describe('DashParser Live', () => { ].join('\n'); fakeNetEngine.setResponseText('dummy://foo', manifest); - Date.now = function() { return 600000; /* 10 minutes */ }; + Date.now = () => 600000; /* 10 minutes */ parser.start('dummy://foo', playerInterface) .then((manifest) => { expect(manifest).toBeTruthy(); @@ -817,7 +817,7 @@ describe('DashParser Live', () => { const manifest = sprintf(template, {contents: lines.join('\n')}); fakeNetEngine.setResponseText('dummy://foo', manifest); - Date.now = function() { return 600000; /* 10 minutes */ }; + Date.now = () => 600000; /* 10 minutes */ parser.start('dummy://foo', playerInterface) .then((manifest) => { expect(manifest).toBeTruthy(); diff --git a/test/dash/dash_parser_manifest_unit.js b/test/dash/dash_parser_manifest_unit.js index 68dc29b3b3..4b6f95ec49 100644 --- a/test/dash/dash_parser_manifest_unit.js +++ b/test/dash/dash_parser_manifest_unit.js @@ -438,7 +438,7 @@ describe('DashParser Manifest', () => { const originalNow = Date.now; beforeAll(() => { - Date.now = function() { return 10 * 1000; }; + Date.now = () => 10 * 1000; }); afterAll(() => { diff --git a/test/media/drm_engine_integration.js b/test/media/drm_engine_integration.js index d4a8d631f5..2c138e0073 100644 --- a/test/media/drm_engine_integration.js +++ b/test/media/drm_engine_integration.js @@ -89,7 +89,9 @@ describe('DrmEngine', () => { networkingEngine = new shaka.net.NetworkingEngine(); networkingEngine.registerRequestFilter((type, request) => { - if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) return; + if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) { + return; + } request.headers['X-AxDRM-Message'] = [ 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lk', diff --git a/test/media/media_source_engine_integration.js b/test/media/media_source_engine_integration.js index 096cc02141..6d3da06222 100644 --- a/test/media/media_source_engine_integration.js +++ b/test/media/media_source_engine_integration.js @@ -200,7 +200,9 @@ describe('MediaSourceEngine', () => { function checkOrder(p) { const nextIndex = requests.length; requests.push(p); - p.then(() => { resolutionOrder.push(nextIndex); }); + p.then(() => { + resolutionOrder.push(nextIndex); + }); } const initObject = new Map(); diff --git a/test/media/media_source_engine_unit.js b/test/media/media_source_engine_unit.js index ed925aafea..2af69d7064 100644 --- a/test/media/media_source_engine_unit.js +++ b/test/media/media_source_engine_unit.js @@ -1179,7 +1179,7 @@ describe('MediaSourceEngine', () => { function createMockTextEngineCtor() { const ctor = jasmine.createSpy('TextEngine'); - ctor.isTypeSupported = function() { return true; }; + ctor.isTypeSupported = () => true; ctor.and.callFake(() => { expect(mockTextEngine).toBeFalsy(); mockTextEngine = jasmine.createSpyObj('TextEngine', [ diff --git a/test/media/play_rate_controller_unit.js b/test/media/play_rate_controller_unit.js index 99991d28e7..4e3541628c 100644 --- a/test/media/play_rate_controller_unit.js +++ b/test/media/play_rate_controller_unit.js @@ -38,7 +38,9 @@ describe('PlayRateController', () => { playRate = 1; getPlayRateSpy.and.callFake(() => playRate); - setPlayRateSpy.and.callFake((rate) => { playRate = rate; }); + setPlayRateSpy.and.callFake((rate) => { + playRate = rate; + }); const harness = { getRate: shaka.test.Util.spyFunc(getPlayRateSpy), diff --git a/test/media/presentation_timeline_unit.js b/test/media/presentation_timeline_unit.js index 6f4b01fa79..e50febcb6a 100644 --- a/test/media/presentation_timeline_unit.js +++ b/test/media/presentation_timeline_unit.js @@ -23,7 +23,7 @@ describe('PresentationTimeline', () => { beforeEach(() => { baseTime = new Date(2015, 11, 30); - Date.now = function() { return baseTime.getTime(); }; + Date.now = () => baseTime.getTime(); }); afterEach(() => { @@ -31,9 +31,7 @@ describe('PresentationTimeline', () => { }); function setElapsed(secondsSinceBaseTime) { - Date.now = function() { - return baseTime.getTime() + (secondsSinceBaseTime * 1000); - }; + Date.now = () => baseTime.getTime() + (secondsSinceBaseTime * 1000); } /** diff --git a/test/media/streaming_engine_integration.js b/test/media/streaming_engine_integration.js index bf2e82a127..fe545dc47b 100644 --- a/test/media/streaming_engine_integration.js +++ b/test/media/streaming_engine_integration.js @@ -243,7 +243,9 @@ describe('StreamingEngine', () => { function setupPlayhead() { onBuffering = jasmine.createSpy('onBuffering'); - const onSeek = () => { streamingEngine.seeked(); }; + const onSeek = () => { + streamingEngine.seeked(); + }; playhead = new shaka.media.MediaSourcePlayhead( /** @type {!HTMLVideoElement} */(video), manifest, @@ -265,7 +267,9 @@ describe('StreamingEngine', () => { manifest.minBufferTime = 2; // Create InitSegmentReferences. - function makeUris(uri) { return () => { return [uri]; }; } + function makeUris(uri) { + return () => [uri]; + } manifest.periods[0].variants[0].audio.initSegmentReference = new shaka.media.InitSegmentReference(makeUris('1_audio_init'), 0, null); manifest.periods[0].variants[0].video.initSegmentReference = @@ -434,7 +438,9 @@ describe('StreamingEngine', () => { }); let seekCount = 0; - eventManager.listen(video, 'seeking', () => { seekCount++; }); + eventManager.listen(video, 'seeking', () => { + seekCount++; + }); // Let's go! onChooseStreams.and.callFake(defaultOnChooseStreams); @@ -614,7 +620,9 @@ describe('StreamingEngine', () => { const getUris = (function(i) { // The times in the media are based on the URL; so to drop a // segment, we change the URL. - if (i >= 2 && dropSegment) i++; + if (i >= 2 && dropSegment) { + i++; + } return ['1_' + type + '_' + i]; }.bind(null, i)); refs.push( diff --git a/test/media/streaming_engine_unit.js b/test/media/streaming_engine_unit.js index 589baac584..ea5fade402 100644 --- a/test/media/streaming_engine_unit.js +++ b/test/media/streaming_engine_unit.js @@ -89,7 +89,9 @@ describe('StreamingEngine', () => { */ function runTest(callback) { function onTick(currentTime) { - if (callback) callback(); + if (callback) { + callback(); + } if (playing) { presentationTimeInSeconds++; } @@ -123,7 +125,7 @@ describe('StreamingEngine', () => { const initSegmentSizeVideo = initSegmentRanges[ContentType.VIDEO][1] - initSegmentRanges[ContentType.VIDEO][0] + 1; - function makeBuffer(size) { return new ArrayBuffer(size); } + const makeBuffer = (size) => new ArrayBuffer(size); segmentData = { audio: { initSegments: [ @@ -224,7 +226,7 @@ describe('StreamingEngine', () => { const initSegmentSizeVideo = initSegmentRanges[ContentType.VIDEO][1] - initSegmentRanges[ContentType.VIDEO][0] + 1; - function makeBuffer(size) { return new ArrayBuffer(size); } + const makeBuffer = (size) => new ArrayBuffer(size); segmentData = { audio: { initSegments: @@ -608,7 +610,9 @@ describe('StreamingEngine', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); - onStartupComplete.and.callFake(() => { setupFakeGetTime(0); }); + onStartupComplete.and.callFake(() => { + setupFakeGetTime(0); + }); onChooseStreams.and.callFake(onChooseStreamsWithUnloadedText); streamingEngine.start(); @@ -635,7 +639,9 @@ describe('StreamingEngine', () => { setupVod(); mediaSourceEngine = new shaka.test.FakeMediaSourceEngine(segmentData); createStreamingEngine(); - onStartupComplete.and.callFake(() => { setupFakeGetTime(0); }); + onStartupComplete.and.callFake(() => { + setupFakeGetTime(0); + }); onChooseStreams.and.callFake(onChooseStreamsWithUnloadedText); streamingEngine.start(); @@ -2088,7 +2094,9 @@ describe('StreamingEngine', () => { // Configure with a failure callback that records the callback time. let callbackTime = null; const failureCallback = jasmine.createSpy('failureCallback'); - failureCallback.and.callFake(() => { callbackTime = Date.now(); }); + failureCallback.and.callFake(() => { + callbackTime = Date.now(); + }); const config = shaka.util.PlayerConfiguration.createDefault().streaming; config.failureCallback = shaka.test.Util.spyFunc(failureCallback); @@ -2454,7 +2462,9 @@ describe('StreamingEngine', () => { // Stop the playhead after 10 seconds since will not append any // segments after this time. - const stopPlayhead = () => { playing = presentationTimeInSeconds < 10; }; + const stopPlayhead = () => { + playing = presentationTimeInSeconds < 10; + }; runTest(stopPlayhead); expect(onError).toHaveBeenCalled(); @@ -2995,9 +3005,15 @@ describe('StreamingEngine', () => { expect(Util.invokeSpy(mediaSourceEngine.bufferEnd, 'video')).toBe(30); const expected = ['video-10-0.mp4']; - if (!didAbort) { expected.push('video-10-1.mp4'); } - if (hasInit) { expected.push('init-11.mp4'); } - if (didAbort) { expected.push('video-11-1.mp4'); } + if (!didAbort) { + expected.push('video-10-1.mp4'); + } + if (hasInit) { + expected.push('init-11.mp4'); + } + if (didAbort) { + expected.push('video-11-1.mp4'); + } expected.push('video-11-2.mp4'); expect(requestUris).toEqual(expected); } diff --git a/test/net/networking_engine_unit.js b/test/net/networking_engine_unit.js index fad2a3ee18..1847bc45d9 100644 --- a/test/net/networking_engine_unit.js +++ b/test/net/networking_engine_unit.js @@ -757,7 +757,9 @@ describe('NetworkingEngine', /** @suppress {accessControls} */ () => { }); it('if throws will stop requests', (done) => { - filter.and.callFake(() => { throw error; }); + filter.and.callFake(() => { + throw error; + }); networkingEngine.request(requestType, createRequest('resolve://foo')) .promise .then(fail) diff --git a/test/offline/storage_unit.js b/test/offline/storage_unit.js index f03136b594..8f28772389 100644 --- a/test/offline/storage_unit.js +++ b/test/offline/storage_unit.js @@ -1339,8 +1339,12 @@ describe('Storage', () => { manifest.periods.forEach((period) => { period.variants.forEach((variant) => { - if (variant.audio) { streams.push(variant.audio); } - if (variant.video) { streams.push(variant.video); } + if (variant.audio) { + streams.push(variant.audio); + } + if (variant.video) { + streams.push(variant.video); + } }); period.textStreams.forEach((stream) => { streams.push(stream); diff --git a/test/player_external.js b/test/player_external.js index 4e53ab253d..29c16244ef 100644 --- a/test/player_external.js +++ b/test/player_external.js @@ -82,7 +82,9 @@ describe('Player', () => { describe('plays', () => { /** @param {!ShakaDemoAssetInfo} asset */ function createAssetTest(asset) { - if (asset.disabled) return; + if (asset.disabled) { + return; + } const testName = asset.source + ' / ' + asset.name + ' : ' + asset.manifestUri; @@ -256,7 +258,9 @@ describe('Player', () => { */ function addLicenseRequestHeaders(headers, requestType, request) { const RequestType = compiledShaka.net.NetworkingEngine.RequestType; - if (requestType != RequestType.LICENSE) return; + if (requestType != RequestType.LICENSE) { + return; + } // Add these to the existing headers. Do not clobber them! // For PlayReady, there will already be headers in the request. diff --git a/test/player_integration.js b/test/player_integration.js index 679dd3a910..82bbcdcf7b 100644 --- a/test/player_integration.js +++ b/test/player_integration.js @@ -46,7 +46,9 @@ describe('Player', () => { eventManager = new shaka.util.EventManager(); onErrorSpy = jasmine.createSpy('onError'); - onErrorSpy.and.callFake((event) => { fail(event.detail); }); + onErrorSpy.and.callFake((event) => { + fail(event.detail); + }); eventManager.listen(player, 'error', Util.spyFunc(onErrorSpy)); }); @@ -237,7 +239,9 @@ describe('Player', () => { displayer.appendSpy.and.callFake((added) => { cues = cues.concat(added); }); - displayer.removeSpy.and.callFake(() => { cues = []; }); + displayer.removeSpy.and.callFake(() => { + cues = []; + }); player.configure({textDisplayFactory: () => displayer}); const preferredTextLanguage = 'fa'; // The same as in the content itself @@ -1462,7 +1466,9 @@ describe('Player Load Path', () => { whenEnteringState(state, () => { // Make sure we don't execute more than once per promise. - if (called) { return; } + if (called) { + return; + } called = true; // We need to call doThis in-sync with entering the state so that it diff --git a/test/player_unit.js b/test/player_unit.js index 440769e4a3..45dcca3275 100644 --- a/test/player_unit.js +++ b/test/player_unit.js @@ -101,10 +101,10 @@ describe('Player', () => { periodIndex = 0; abrManager = new shaka.test.FakeAbrManager(); - abrFactory = function() { return abrManager; }; + abrFactory = () => abrManager; textDisplayer = createTextDisplayer(); - textDisplayFactory = function() { return textDisplayer; }; + textDisplayFactory = () => textDisplayer; function dependencyInjector(player) { // Create a networking engine that always returns an empty buffer. @@ -126,11 +126,11 @@ describe('Player', () => { ended: jasmine.createSpy('ended').and.returnValue(false), }; - player.createDrmEngine = function() { return drmEngine; }; - player.createNetworkingEngine = function() { return networkingEngine; }; - player.createPlayhead = function() { return playhead; }; - player.createMediaSourceEngine = function() { return mediaSourceEngine; }; - player.createStreamingEngine = function() { return streamingEngine; }; + player.createDrmEngine = () => drmEngine; + player.createNetworkingEngine = () => networkingEngine; + player.createPlayhead = () => playhead; + player.createMediaSourceEngine = () => mediaSourceEngine; + player.createStreamingEngine = () => streamingEngine; } video = new shaka.test.FakeVideo(20); @@ -164,7 +164,7 @@ describe('Player', () => { it('cleans up all dependencies', async () => { goog.asserts.assert(manifest, 'Manifest should be non-null'); const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; await player.load(fakeManifestUri, 0, factory); await player.destroy(); @@ -180,7 +180,7 @@ describe('Player', () => { it('destroys mediaSourceEngine before drmEngine', async () => { goog.asserts.assert(manifest, 'Manifest should be non-null'); const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; mediaSourceEngine.destroy.and.callFake(() => { expect(drmEngine.destroy).not.toHaveBeenCalled(); @@ -206,7 +206,7 @@ describe('Player', () => { expect(abrManager.stop).not.toHaveBeenCalled(); expect(networkingEngine.destroy).not.toHaveBeenCalled(); }); - const factory = function() { return parser; }; + const factory = () => parser; player.load(fakeManifestUri, 0, factory).then(fail).catch(() => {}); shaka.test.Util.delay(0.1).then(() => { @@ -230,7 +230,7 @@ describe('Player', () => { beforeEach(() => { goog.asserts.assert(manifest, 'manifest must be non-null'); parser1 = new shaka.test.FakeManifestParser(manifest); - factory1 = function() { return parser1; }; + factory1 = () => parser1; checkError = jasmine.createSpy('checkError'); checkError.and.callFake((error) => { @@ -646,7 +646,7 @@ describe('Player', () => { /* eslint-enable indent */ goog.asserts.assert(manifest, 'manifest must be non-null'); const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; await player.load(fakeManifestUri, 0, factory); const seekRange = player.seekRange(); expect(seekRange.start).toBe(5); @@ -655,7 +655,7 @@ describe('Player', () => { it('does not switch for plain configuration changes', async () => { const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; const switchVariantSpy = spyOn(player, 'switchVariant_'); @@ -782,7 +782,7 @@ describe('Player', () => { beforeEach(() => { goog.asserts.assert(manifest, 'manifest must be non-null'); parser = new shaka.test.FakeManifestParser(manifest); - parserFactory = function() { return parser; }; + parserFactory = () => parser; }); it('sets through load', async () => { @@ -906,7 +906,7 @@ describe('Player', () => { ]; const parser = new shaka.test.FakeManifestParser(manifest); - const parserFactory = function() { return parser; }; + const parserFactory = () => parser; player.load(fakeManifestUri, 0, parserFactory).catch(fail).then(() => { // Check the first period's variant tracks. const actualVariantTracks1 = player.getVariantTracks(); @@ -1319,7 +1319,7 @@ describe('Player', () => { goog.asserts.assert(manifest, 'manifest must be non-null'); const parser = new shaka.test.FakeManifestParser(manifest); - const parserFactory = function() { return parser; }; + const parserFactory = () => parser; // Language/channel prefs must be set before load. Used in // select*Language() tests. @@ -1341,7 +1341,7 @@ describe('Player', () => { it('returns empty arrays before tracks can be determined', async () => { const parser = new shaka.test.FakeManifestParser(manifest); - const parserFactory = function() { return parser; }; + const parserFactory = () => parser; parser.start.and.callFake((manifestUri, playerInterface) => { // The player does not yet have a manifest. expect(player.getVariantTracks()).toEqual([]); @@ -1712,7 +1712,7 @@ describe('Player', () => { expect(player.isTextTrackVisible()).toBe(false); const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; await player.load(fakeManifestUri, 0, factory); // Text was turned on during startup. @@ -1745,7 +1745,7 @@ describe('Player', () => { }); const parser = new shaka.test.FakeManifestParser(manifest); - const parserFactory = function() { return parser; }; + const parserFactory = () => parser; await player.load(fakeManifestUri, 0, parserFactory); expect(abrManager.setVariants).toHaveBeenCalled(); @@ -1786,7 +1786,7 @@ describe('Player', () => { }); const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; return player.load(fakeManifestUri, 0, factory).then(() => { expect(getActiveVariantTrack().id).toBe(expectedIndex); }); @@ -1828,7 +1828,7 @@ describe('Player', () => { /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const parserFactory = function() { return parser; }; + const parserFactory = () => parser; await player.load(fakeManifestUri, 0, parserFactory); // Initialize the fake streams. @@ -2123,7 +2123,7 @@ describe('Player', () => { .build(); /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; await player.load(fakeManifestUri, 0, factory); }); @@ -2139,7 +2139,7 @@ describe('Player', () => { .build(); /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; await player.load(fakeManifestUri, 0, factory); }); @@ -2155,7 +2155,7 @@ describe('Player', () => { .build(); /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; try { await player.load(fakeManifestUri, 0, factory); fail(); @@ -2177,7 +2177,7 @@ describe('Player', () => { .addVideo(0).mime('video/mp4', 'bad') .build(); const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; try { await player.load(fakeManifestUri, 0, factory); fail(); @@ -2207,7 +2207,7 @@ describe('Player', () => { /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; try { await player.load(fakeManifestUri, 0, factory); fail(); @@ -2232,7 +2232,7 @@ describe('Player', () => { .build(); /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; player.load(fakeManifestUri, 0, factory).catch(fail).then(() => { /* eslint-disable indent */ const manifest2 = new shaka.test.ManifestGenerator() @@ -2765,7 +2765,7 @@ describe('Player', () => { /* eslint-enable indent */ const abrManager = new shaka.test.FakeAbrManager(); - player.configure({abrFactory: function() { return abrManager; }}); + player.configure({abrFactory: () => abrManager}); setupPlayer().then(() => { expect(player.getVariantTracks().length).toBe(2); @@ -2811,7 +2811,7 @@ describe('Player', () => { */ function setupPlayer() { const parser = new shaka.test.FakeManifestParser(manifest); - const parserFactory = function() { return parser; }; + const parserFactory = () => parser; return player.load(fakeManifestUri, 0, parserFactory).then(() => { // Initialize the fake streams. streamingEngine.onCanSwitch(); @@ -2833,7 +2833,7 @@ describe('Player', () => { /* eslint-enable indent */ goog.asserts.assert(manifest, 'manifest must be non-null'); const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; await player.load(fakeManifestUri, 0, factory); }); @@ -2846,7 +2846,7 @@ describe('Player', () => { it('rejects empty manifests', (done) => { manifest = new shaka.test.ManifestGenerator().build(); const emptyParser = new shaka.test.FakeManifestParser(manifest); - const emptyFactory = function() { return emptyParser; }; + const emptyFactory = () => emptyParser; player.load(fakeManifestUri, 0, emptyFactory).then(fail).catch((error) => { shaka.test.Util.expectToEqualError( @@ -2880,7 +2880,7 @@ describe('Player', () => { /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const parserFactory = function() { return parser; }; + const parserFactory = () => parser; await player.load(fakeManifestUri, 0, parserFactory); streamingEngine.onCanSwitch(); @@ -2969,7 +2969,7 @@ describe('Player', () => { /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const parserFactory = function() { return parser; }; + const parserFactory = () => parser; // Before the fix, load() would fail assertions and throw errors. await player.load(fakeManifestUri, 0, parserFactory); @@ -2995,7 +2995,7 @@ describe('Player', () => { /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const parserFactory = function() { return parser; }; + const parserFactory = () => parser; // To ensure that Playhead is correctly created, we must use the original // playhead injector. To inspect the real Playhead instance, though, we @@ -3188,7 +3188,9 @@ describe('Player', () => { } /** @suppress {accessControls} */ - function onCanSwitch() { player.canSwitch_(); } + function onCanSwitch() { + player.canSwitch_(); + } /** * A Jasmine asymmetric matcher for substring matches. diff --git a/test/routing/walker_unit.js b/test/routing/walker_unit.js index d471faa551..d8d1cd1c84 100644 --- a/test/routing/walker_unit.js +++ b/test/routing/walker_unit.js @@ -263,13 +263,19 @@ describe('Walker', () => { }); const route1 = startNewRoute(nodeD, /* interruptible= */ false); - route1.onStart = () => { currentRoute = 1; }; + route1.onStart = () => { + currentRoute = 1; + }; const route2 = startNewRoute(nodeC, /* interruptible= */ true); - route2.onStart = () => { currentRoute = 2; }; + route2.onStart = () => { + currentRoute = 2; + }; const route3 = startNewRoute(nodeE, /* interruptible= */ true); - route3.onStart = () => { currentRoute = 3; }; + route3.onStart = () => { + currentRoute = 3; + }; // Wait until we get to the end of route 3, that should be the end. await completesRoute(route3); diff --git a/test/test/util/fake_media_source_engine.js b/test/test/util/fake_media_source_engine.js index 2844dc0a86..ab41b2b318 100644 --- a/test/test/util/fake_media_source_engine.js +++ b/test/test/util/fake_media_source_engine.js @@ -167,7 +167,9 @@ shaka.test.FakeMediaSourceEngine.SegmentData; * @private */ shaka.test.FakeMediaSourceEngine.prototype.bufferStartImpl_ = function(type) { - if (this.segments[type] === undefined) throw new Error('unexpected type'); + if (this.segments[type] === undefined) { + throw new Error('unexpected type'); + } const first = this.segments[type].indexOf(true); if (first < 0) { @@ -184,7 +186,9 @@ shaka.test.FakeMediaSourceEngine.prototype.bufferStartImpl_ = function(type) { * @private */ shaka.test.FakeMediaSourceEngine.prototype.bufferEndImpl_ = function(type) { - if (this.segments[type] === undefined) throw new Error('unexpected type'); + if (this.segments[type] === undefined) { + throw new Error('unexpected type'); + } const last = this.segments[type].lastIndexOf(true); if (last < 0) { @@ -203,7 +207,9 @@ shaka.test.FakeMediaSourceEngine.prototype.bufferEndImpl_ = function(type) { */ shaka.test.FakeMediaSourceEngine.prototype.isBufferedImpl_ = function(type, time) { - if (this.segments[type] === undefined) throw new Error('unexpected type'); + if (this.segments[type] === undefined) { + throw new Error('unexpected type'); + } const first = this.segments[type].indexOf(true); const last = this.segments[type].lastIndexOf(true); @@ -222,7 +228,9 @@ shaka.test.FakeMediaSourceEngine.prototype.isBufferedImpl_ = */ shaka.test.FakeMediaSourceEngine.prototype.bufferedAheadOfImpl = function( type, start) { - if (this.segments[type] === undefined) throw new Error('unexpected type'); + if (this.segments[type] === undefined) { + throw new Error('unexpected type'); + } const ContentType = shaka.util.ManifestParserUtils.ContentType; const hasSegment = (function(i) { @@ -257,7 +265,9 @@ shaka.test.FakeMediaSourceEngine.prototype.bufferedAheadOfImpl = function( */ shaka.test.FakeMediaSourceEngine.prototype.appendBufferImpl = function( type, data, startTime, endTime) { - if (this.segments[type] === undefined) throw new Error('unexpected type'); + if (this.segments[type] === undefined) { + throw new Error('unexpected type'); + } // Remains 'video' even when we detect a 'trickvideo' segment. const originalType = type; @@ -329,7 +339,9 @@ shaka.test.FakeMediaSourceEngine.prototype.appendBufferImpl = function( */ shaka.test.FakeMediaSourceEngine.prototype.removeImpl = function(type, start, end) { - if (this.segments[type] === undefined) throw new Error('unexpected type'); + if (this.segments[type] === undefined) { + throw new Error('unexpected type'); + } const first = this.toIndex_(type, start); if (first < 0 || first >= this.segments[type].length) { @@ -360,7 +372,9 @@ shaka.test.FakeMediaSourceEngine.prototype.removeImpl = * @private */ shaka.test.FakeMediaSourceEngine.prototype.clearImpl_ = function(type) { - if (this.segments[type] === undefined) throw new Error('unexpected type'); + if (this.segments[type] === undefined) { + throw new Error('unexpected type'); + } for (let i = 0; i < this.segments[type].length; ++i) { this.segments[type][i] = false; @@ -390,7 +404,9 @@ shaka.test.FakeMediaSourceEngine.prototype.clearImpl_ = function(type) { */ shaka.test.FakeMediaSourceEngine.prototype.setStreamPropertiesImpl_ = function( type, offset, appendWindowEnd) { - if (this.segments[type] === undefined) throw new Error('unexpected type'); + if (this.segments[type] === undefined) { + throw new Error('unexpected type'); + } this.timestampOffsets_[type] = offset; // Don't use |appendWindowEnd|. return Promise.resolve(); diff --git a/test/test/util/fake_networking_engine.js b/test/test/util/fake_networking_engine.js index 58c3368e16..bedda196f0 100644 --- a/test/test/util/fake_networking_engine.js +++ b/test/test/util/fake_networking_engine.js @@ -319,7 +319,9 @@ shaka.test.FakeNetworkingEngine = class { // No header required. } else { let range = 'bytes=' + startByte + '-'; - if (endByte != null) range += endByte; + if (endByte != null) { + range += endByte; + } headers['Range'] = range; } diff --git a/test/test/util/indexeddb_utils.js b/test/test/util/indexeddb_utils.js index 062c150eb0..4ba4dec4c5 100644 --- a/test/test/util/indexeddb_utils.js +++ b/test/test/util/indexeddb_utils.js @@ -66,8 +66,12 @@ shaka.test.IndexedDBUtils.deleteDB = function(name) { const p = new shaka.util.PublicPromise(); const goaway = window.indexedDB.deleteDatabase(name); - goaway.onsuccess = (e) => { p.resolve(); }; - goaway.onerror = (e) => { p.reject(); }; + goaway.onsuccess = (e) => { + p.resolve(); + }; + goaway.onerror = (e) => { + p.reject(); + }; return p; }; @@ -88,7 +92,9 @@ shaka.test.IndexedDBUtils.dbOpenNew_ = function(name, version, upgrade) { const p = new shaka.util.PublicPromise(); const open = window.indexedDB.open(name, version); - open.onerror = (e) => { p.reject(); }; + open.onerror = (e) => { + p.reject(); + }; open.onsuccess = (e) => { // Make sure that the database actually upgraded when connecting or else // we will have an old copy. @@ -121,8 +127,12 @@ shaka.test.IndexedDBUtils.open = function(name) { const p = new shaka.util.PublicPromise(); const open = window.indexedDB.open(name); - open.onerror = (e) => { p.reject(); }; - open.onsuccess = (e) => { p.resolve(open.result); }; + open.onerror = (e) => { + p.reject(); + }; + open.onsuccess = (e) => { + p.resolve(open.result); + }; return p; }; diff --git a/test/test/util/jasmine_fetch.js b/test/test/util/jasmine_fetch.js index bce6c28790..2440436557 100644 --- a/test/test/util/jasmine_fetch.js +++ b/test/test/util/jasmine_fetch.js @@ -204,7 +204,7 @@ jasmine.Fetch.AbortController = function() { // TODO: I don't know if this implementation of AbortController is correct, // but it works for our tests this.aborted_ = false; - this.signal = (function() { return this.aborted_; }).bind(this); + this.signal = () => this.aborted_; }; diff --git a/test/test/util/manifest_generator.js b/test/test/util/manifest_generator.js index 917728cca9..03312adea2 100644 --- a/test/test/util/manifest_generator.js +++ b/test/test/util/manifest_generator.js @@ -580,15 +580,13 @@ shaka.test.ManifestGenerator.prototype.useSegmentTemplate = function( const stream = this.currentStream_(); const totalDuration = this.manifest_.presentationTimeline.getDuration(); const segmentCount = totalDuration / segmentDuration; - stream.createSegmentIndex = function() { return Promise.resolve(); }; - stream.findSegmentPosition = function(time) { - return Math.floor(time / segmentDuration); - }; + stream.createSegmentIndex = () => Promise.resolve(); + stream.findSegmentPosition = (time) => Math.floor(time / segmentDuration); stream.getSegmentReference = (function(index) { if (index < 0 || index >= segmentCount) { return null; } - const getUris = function() { return [sprintf(template, index)]; }; + const getUris = () => [sprintf(template, index)]; const start = index * segmentDuration; const end = Math.min(totalDuration, (index + 1) * segmentDuration); return new this.shaka_.media.SegmentReference( @@ -608,18 +606,19 @@ shaka.test.ManifestGenerator.prototype.useSegmentTemplate = function( shaka.test.ManifestGenerator.prototype.textStream = function(uri) { const stream = this.currentStream_(); const duration = this.manifest_.presentationTimeline.getDuration(); - const getUris = function() { return [uri]; }; + const getUris = () => [uri]; - stream.createSegmentIndex = function() { return Promise.resolve(); }; - stream.findSegmentPosition = function(time) { - return (time >= 0 && time < duration ? 1 : null); - }; - stream.getSegmentReference = (function(position) { - if (position != 1) return null; + stream.createSegmentIndex = () => Promise.resolve(); + stream.findSegmentPosition = (time) => + (time >= 0 && time < duration ? 1 : null); + stream.getSegmentReference = (position) => { + if (position != 1) { + return null; + } const startTime = 0; return new this.shaka_.media.SegmentReference( position, startTime, duration, getUris, 0, null); - }.bind(this)); + }; return this; }; @@ -674,7 +673,7 @@ shaka.test.ManifestGenerator.prototype.nullInitSegment = function() { shaka.test.ManifestGenerator.prototype.initSegmentReference = function( uris, startByte, endByte) { const stream = this.currentStream_(); - const getUris = function() { return uris; }; + const getUris = () => uris; stream.initSegmentReference = new this.shaka_.media.InitSegmentReference(getUris, startByte, endByte); return this; diff --git a/test/test/util/manifest_parser_util.js b/test/test/util/manifest_parser_util.js index dc7fdaad5e..70821559a5 100644 --- a/test/test/util/manifest_parser_util.js +++ b/test/test/util/manifest_parser_util.js @@ -77,7 +77,7 @@ shaka.test.ManifestParser.verifySegmentIndex = function(stream, references) { shaka.test.ManifestParser.makeReference = function(uri, position, start, end, baseUri = '', startByte = 0, endByte = null) { - const getUris = function() { return [baseUri + uri]; }; + const getUris = () => [baseUri + uri]; return new shaka.media.SegmentReference( position, start, end, getUris, startByte, endByte); }; diff --git a/test/test/util/simple_fakes.js b/test/test/util/simple_fakes.js index 054b1e7d86..bc72b16142 100644 --- a/test/test/util/simple_fakes.js +++ b/test/test/util/simple_fakes.js @@ -55,7 +55,9 @@ shaka.test.FakeAbrManager = function() { ret.init.and.callFake((switchCallback) => { ret.switchCallback = switchCallback; }); - ret.setVariants.and.callFake((arg) => { ret.variants = arg; }); + ret.setVariants.and.callFake((arg) => { + ret.variants = arg; + }); ret.chooseVariant.and.callFake(() => { return ret.variants[ret.chooseIndex]; }); @@ -137,9 +139,15 @@ shaka.test.FakeStreamingEngine = function(onChooseStreams, onCanSwitch) { ]); ret.destroy.and.callFake(resolve); ret.getBufferingPeriod.and.returnValue(null); - ret.getBufferingAudio.and.callFake(() => { return activeAudio; }); - ret.getBufferingVideo.and.callFake(() => { return activeVideo; }); - ret.getBufferingText.and.callFake(() => { return activeText; }); + ret.getBufferingAudio.and.callFake(() => { + return activeAudio; + }); + ret.getBufferingVideo.and.callFake(() => { + return activeVideo; + }); + ret.getBufferingText.and.callFake(() => { + return activeText; + }); ret.loadNewTextStream.and.callFake((stream) => { activeText = stream; return Promise.resolve(); @@ -312,14 +320,18 @@ shaka.test.FakeVideo.prototype.setMediaKeys; * @return {!TimeRanges} */ function createFakeBuffered(ranges) { - return /** @type {!TimeRanges} */({ + return /** @type {!TimeRanges} */ ({ length: ranges.length, start: function(i) { - if (i >= 0 && i < ranges.length) return ranges[i].start; + if (i >= 0 && i < ranges.length) { + return ranges[i].start; + } throw new Error('Unexpected index'); }, end: function(i) { - if (i >= 0 && i < ranges.length) return ranges[i].end; + if (i >= 0 && i < ranges.length) { + return ranges[i].end; + } throw new Error('Unexpected index'); }, }); diff --git a/test/test/util/stream_generator.js b/test/test/util/stream_generator.js index 887495e6ac..27e6295297 100644 --- a/test/test/util/stream_generator.js +++ b/test/test/util/stream_generator.js @@ -212,7 +212,9 @@ shaka.test.Mp4VodStreamGenerator.prototype.getSegment = function( goog.asserts.assert( this.segmentTemplate_, 'init() must be called before getSegment().'); - if (!this.segmentTemplate_) return null; + if (!this.segmentTemplate_) { + return null; + } // |position| must be an integer and >= 1. goog.asserts.assert((position % 1 === 0) && (position >= 1), @@ -350,7 +352,9 @@ shaka.test.Mp4LiveStreamGenerator.prototype.getSegment = function( goog.asserts.assert( this.initSegment_, 'init() must be called before getSegment().'); - if (!this.initSegment_) return null; + if (!this.initSegment_) { + return null; + } // |position| must be an integer and >= 1. goog.asserts.assert((position % 1 === 0) && (position >= 1), diff --git a/test/test/util/streaming_engine_util.js b/test/test/util/streaming_engine_util.js index 0cafcf5d3a..837e355778 100644 --- a/test/test/util/streaming_engine_util.js +++ b/test/test/util/streaming_engine_util.js @@ -259,10 +259,15 @@ shaka.test.StreamingEngineUtil.createManifest = function( stream.getSegmentReference.and.callFake(get.bind(null, type, i + 1)); const ContentType = shaka.util.ManifestParserUtils.ContentType; - if (type == ContentType.TEXT) period.textStreams.push(stream); - else if (type == ContentType.AUDIO) variant.audio = stream; - else if (type == 'trickvideo') trickModeVideo = stream; - else variant.video = stream; + if (type == ContentType.TEXT) { + period.textStreams.push(stream); + } else if (type == ContentType.AUDIO) { + variant.audio = stream; + } else if (type == 'trickvideo') { + trickModeVideo = stream; + } else { + variant.video = stream; + } } variant.video.trickModeVideo = trickModeVideo; diff --git a/test/test/util/test_scheme.js b/test/test/util/test_scheme.js index 15ef36d61b..b0b1d35595 100644 --- a/test/test/util/test_scheme.js +++ b/test/test/util/test_scheme.js @@ -363,17 +363,20 @@ shaka.test.TestScheme.DATA = { shaka.test.TestScheme.setupPlayer = function(player, name) { const asset = shaka.test.TestScheme.DATA[name]; goog.asserts.assert(asset, 'Unknown asset'); - if (!asset) return; + if (!asset) { + return; + } if (asset.licenseRequestHeaders) { const netEngine = player.getNetworkingEngine(); - netEngine.registerRequestFilter( - (type, request) => { - if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) return; - - for (const header in asset.licenseRequestHeaders) { - request.headers[header] = asset.licenseRequestHeaders[header]; - } - }); + netEngine.registerRequestFilter((type, request) => { + if (type != shaka.net.NetworkingEngine.RequestType.LICENSE) { + return; + } + + for (const header in asset.licenseRequestHeaders) { + request.headers[header] = asset.licenseRequestHeaders[header]; + } + }); } if (asset.licenseServers) { const config = {drm: {servers: asset.licenseServers}}; @@ -602,7 +605,9 @@ shaka.test.TestScheme.ManifestParser.prototype.start = const manifest = shaka.test.TestScheme.MANIFESTS[manifestParts[1]]; expect(manifest).toBeTruthy(); - if (!manifest) return Promise.reject(); + if (!manifest) { + return Promise.reject(); + } // Invoke filtering interfaces similar to how a real parser would. // This makes sure the filtering functions are covered implicitly by tests. diff --git a/test/text/simple_text_displayer_unit.js b/test/text/simple_text_displayer_unit.js index f4511c172b..a295e0cd93 100644 --- a/test/text/simple_text_displayer_unit.js +++ b/test/text/simple_text_displayer_unit.js @@ -244,9 +244,13 @@ describe('SimpleTextDisplayer', () => { function FakeVTTCueWithoutAlignCenter(start, end, text) { let align = 'middle'; Object.defineProperty(this, 'align', { - get: function() { return align; }, + get: function() { + return align; + }, set: function(newValue) { - if (newValue != 'center') align = newValue; + if (newValue != 'center') { + align = newValue; + } }, }); this.startTime = start; diff --git a/test/ui/ui_integration.js b/test/ui/ui_integration.js index 2934268146..8fa74b761b 100644 --- a/test/ui/ui_integration.js +++ b/test/ui/ui_integration.js @@ -86,7 +86,9 @@ describe('UI', () => { controls = ui.getControls(); onErrorSpy = jasmine.createSpy('onError'); - onErrorSpy.and.callFake((event) => { fail(event.detail); }); + onErrorSpy.and.callFake((event) => { + fail(event.detail); + }); eventManager.listen(player, 'error', Util.spyFunc(onErrorSpy)); eventManager.listen(controls, 'error', Util.spyFunc(onErrorSpy)); diff --git a/test/ui/ui_unit.js b/test/ui/ui_unit.js index e037acfc26..879b7edff1 100644 --- a/test/ui/ui_unit.js +++ b/test/ui/ui_unit.js @@ -259,7 +259,7 @@ describe('UI', () => { .build(); const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; await player.load(/* uri= */ 'fake', /* startTime= */ 0, factory); const pipButtons = @@ -388,7 +388,7 @@ describe('UI', () => { /* eslint-enable indent */ const parser = new shaka.test.FakeManifestParser(manifest); - const factory = function() { return parser; }; + const factory = () => parser; await player.load(/* uri */ 'fake', /* startTime */ 0, factory); diff --git a/test/util/data_view_reader_unit.js b/test/util/data_view_reader_unit.js index d8b6d45406..29991aeaec 100644 --- a/test/util/data_view_reader_unit.js +++ b/test/util/data_view_reader_unit.js @@ -201,37 +201,51 @@ describe('DataViewReader', () => { it('detects when reading a uint8', () => { bigEndianReader.skip(7); bigEndianReader.readUint8(); - runTest(() => { bigEndianReader.readUint8(); }); + runTest(() => { + bigEndianReader.readUint8(); + }); }); it('detects when reading a uint16', () => { bigEndianReader.skip(7); - runTest(() => { bigEndianReader.readUint16(); }); + runTest(() => { + bigEndianReader.readUint16(); + }); }); it('detects when reading a uint32', () => { bigEndianReader.skip(5); - runTest(() => { bigEndianReader.readUint32(); }); + runTest(() => { + bigEndianReader.readUint32(); + }); }); it('detects when reading a int32', () => { bigEndianReader.skip(5); - runTest(() => { bigEndianReader.readInt32(); }); + runTest(() => { + bigEndianReader.readInt32(); + }); }); it('detects when reading a uint64', () => { bigEndianReader.skip(3); - runTest(() => { bigEndianReader.readUint64(); }); + runTest(() => { + bigEndianReader.readUint64(); + }); }); it('detects when skipping bytes', () => { bigEndianReader.skip(8); - runTest(() => { bigEndianReader.skip(1); }); + runTest(() => { + bigEndianReader.skip(1); + }); }); it('detects when reading bytes', () => { bigEndianReader.skip(8); - runTest(() => { bigEndianReader.readBytes(1); }); + runTest(() => { + bigEndianReader.readBytes(1); + }); }); function runTest(test) { diff --git a/ui/controls.js b/ui/controls.js index 6081bc7b45..e72e718b8e 100644 --- a/ui/controls.js +++ b/ui/controls.js @@ -110,7 +110,7 @@ shaka.ui.Controls = function(player, videoContainer, video, config) { * @private {shaka.util.Timer} */ this.hideSettingsMenusTimer_ = new shaka.util.Timer(() => { - /** type {function(!HTMLElement)} */ + /** @type {function(!HTMLElement)} */ const hide = (control) => { shaka.ui.Utils.setDisplay(control, /* visible= */ false); }; @@ -864,7 +864,9 @@ shaka.ui.Controls.prototype.onMouseMove_ = function(event) { shaka.ui.Controls.prototype.onMouseLeave_ = function() { // We sometimes get 'mouseout' events with touches. Since we can never leave // the video element when touching, ignore. - if (this.lastTouchEventTime_) return; + if (this.lastTouchEventTime_) { + return; + } // Stop the timer and invoke the callback now to hide the controls. If we // don't, the opacity style we set in onMouseMove_ will continue to override @@ -924,7 +926,9 @@ shaka.ui.Controls.prototype.onContainerTouch_ = function(event) { * @private */ shaka.ui.Controls.prototype.onContainerClick_ = function(event) { - if (!this.enabled_) return; + if (!this.enabled_) { + return; + } if (this.anySettingsMenusAreOpen()) { this.hideSettingsMenusTimer_.tickNow(); @@ -936,7 +940,9 @@ shaka.ui.Controls.prototype.onContainerClick_ = function(event) { /** @private */ shaka.ui.Controls.prototype.onPlayPauseClick_ = function() { - if (!this.enabled_) return; + if (!this.enabled_) { + return; + } if (!this.video_.duration) { // Can't play yet. Ignore. @@ -995,7 +1001,9 @@ shaka.ui.Controls.prototype.onPlayStateChange_ = function() { /** @private */ shaka.ui.Controls.prototype.onSeekStart_ = function() { - if (!this.enabled_) return; + if (!this.enabled_) { + return; + } this.isSeeking_ = true; this.video_.pause(); @@ -1004,7 +1012,9 @@ shaka.ui.Controls.prototype.onSeekStart_ = function() { /** @private */ shaka.ui.Controls.prototype.onSeekInput_ = function() { - if (!this.enabled_) return; + if (!this.enabled_) { + return; + } if (!this.video_.duration) { // Can't seek yet. Ignore. @@ -1028,7 +1038,9 @@ shaka.ui.Controls.prototype.onSeekInput_ = function() { /** @private */ shaka.ui.Controls.prototype.onSeekEnd_ = function() { - if (!this.enabled_) return; + if (!this.enabled_) { + return; + } // They just let go of the seek bar, so cancel the timer and manually // call the event so that we can respond immediately. @@ -1117,11 +1129,15 @@ shaka.ui.Controls.prototype.onBufferingStateChange_ = function() { * @private */ shaka.ui.Controls.prototype.isOpaque_ = function() { - if (!this.enabled_) return false; + if (!this.enabled_) { + return false; + } // TODO: refactor into a single property // While you are casting, the UI is always opaque. - if (this.castProxy_ && this.castProxy_.isCasting()) return true; + if (this.castProxy_ && this.castProxy_.isCasting()) { + return true; + } return this.controlsContainer_.getAttribute('shown') != null; }; diff --git a/ui/fullscreen_button.js b/ui/fullscreen_button.js index 49fed86065..6c3fb9deaa 100644 --- a/ui/fullscreen_button.js +++ b/ui/fullscreen_button.js @@ -132,7 +132,7 @@ shaka.ui.FullscreenButton = class extends shaka.ui.Element { onScreenRotation_() { if (!this.video || this.video.readyState == 0 || - this.controls.getCastProxy().isCasting()) return; + this.controls.getCastProxy().isCasting()) { return; } if (screen.orientation.type.includes('landscape') && !document.fullscreenElement) { diff --git a/ui/language_utils.js b/ui/language_utils.js index 7819d4c709..375dbb342b 100644 --- a/ui/language_utils.js +++ b/ui/language_utils.js @@ -57,7 +57,9 @@ shaka.ui.LanguageUtils = class { // 4. Add new buttons languages.forEach((language) => { const button = shaka.util.Dom.createHTMLElement('button'); - button.addEventListener('click', () => { onLanguageSelected(language); }); + button.addEventListener('click', () => { + onLanguageSelected(language); + }); const span = shaka.util.Dom.createHTMLElement('span'); span.textContent = diff --git a/ui/localization.js b/ui/localization.js index b4568ce891..caade14431 100644 --- a/ui/localization.js +++ b/ui/localization.js @@ -320,7 +320,9 @@ shaka.ui.Localization = class { // Sort the siblings so that they will always appear in the same order // regardless of the order of |localizations|. siblings.sort(); - for (const locale of siblings) { localeOrder.add(locale); } + for (const locale of siblings) { + localeOrder.add(locale); + } const children = shaka.util.Iterables.filter( localizations.keys(), @@ -329,7 +331,9 @@ shaka.ui.Localization = class { // Sort the children so that they will always appear in the same order // regardless of the order of |localizations|. children.sort(); - for (const locale of children) { localeOrder.add(locale); } + for (const locale of children) { + localeOrder.add(locale); + } } // Finally we add our fallback (something that should have all expected @@ -340,7 +344,9 @@ shaka.ui.Localization = class { const mergeOrder = []; for (const locale of localeOrder) { const map = localizations.get(locale); - if (map) { mergeOrder.push(map); } + if (map) { + mergeOrder.push(map); + } } // We need to reverse the merge order. We build the order based on most diff --git a/ui/presentation_time.js b/ui/presentation_time.js index 75177003d5..6d124cab93 100644 --- a/ui/presentation_time.js +++ b/ui/presentation_time.js @@ -115,10 +115,14 @@ shaka.ui.PresentationTimeTracker = class extends shaka.ui.Element { const h = Math.floor(displayTime / 3600); const m = Math.floor((displayTime / 60) % 60); let s = Math.floor(displayTime % 60); - if (s < 10) s = '0' + s; + if (s < 10) { + s = '0' + s; + } let text = m + ':' + s; if (showHour) { - if (m < 10) text = '0' + text; + if (m < 10) { + text = '0' + text; + } text = h + ':' + text; } return text; diff --git a/ui/ui_utils.js b/ui/ui_utils.js index d6f72bf00c..223fd28a16 100644 --- a/ui/ui_utils.js +++ b/ui/ui_utils.js @@ -58,7 +58,9 @@ shaka.ui.Utils.getDescendantIfExists = function(element, className) { * @param {HTMLElement} menu */ shaka.ui.Utils.focusOnTheChosenItem = function(menu) { - if (!menu) return; + if (!menu) { + return; + } const chosenItem = shaka.ui.Utils.getDescendantIfExists( menu, 'shaka-chosen-item'); if (chosenItem) { @@ -90,7 +92,9 @@ shaka.ui.Utils.checkmarkIcon = function() { * @export */ shaka.ui.Utils.setDisplay = function(element, display) { - if (!element) return; + if (!element) { + return; + } // You can't use setDisplay with SVG on IE, because classList isn't on SVG // elements on that browser. It's better to find out on Chrome through an