diff --git a/.eslintrc.json b/.eslintrc.json index 9c4a78e02e..62ed614b63 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,6 +3,35 @@ "sourceType": "module", "ecmaVersion": 2015 }, + "env": { + "browser": true, + "jquery": true, + "node": true, + "es6": true + }, + "globals": { + "it": "readonly", + "describe": "readonly", + "beforeEach": "readonly", + "before": "readonly", + "afterEach": "readonly", + "after": "readonly", + "kendo": "readonly", + "utils": "readonly", + "MediaPlayer": "readonly", + "Dash": "readonly", + "WebKitMediaSource": "readonly", + "MediaSource": "readonly", + "WebKitMediaKeys": "readonly", + "MSMediaKeys": "readonly", + "MediaKeys": "readonly", + "Caster": "readonly", + "TextTrackCue": "readonly", + "HTMLMediaElement": "readonly", + "MediaError": "readonly", + "cea608parser": "readonly", + "dashjs": "readonly" + }, "rules": { "indent": [ 2, @@ -53,6 +82,17 @@ { "allowEmptyCatch": true } - ] + ], + "no-caller": 2, + "no-use-before-define": [ + 2, + { + "functions": false + } + ], + "no-undef": 2, + "no-unused-vars": 2, + "strict": 0, + "no-loop-func": 2 } } diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 4753bb722b..0000000000 --- a/.jshintrc +++ /dev/null @@ -1,34 +0,0 @@ -{ - "esnext": true, - "noarg": true, - "latedef": "nofunc", - "undef": true, - "unused": true, - "strict": false, - "node": true, - "jquery" : true, - "devel" : true, - "browser": true, - "loopfunc" : true, - "predef" : [ - "it", - "describe", - "beforeEach", - "before", - "afterEach", - "after", - "kendo", - "utils", - "MediaPlayer", - "Dash", - "WebKitMediaSource", - "MediaSource", - "WebKitMediaKeys", - "MSMediaKeys", - "MediaKeys", - "Caster", - "TextTrackCue", - "HTMLMediaElement", - "MediaError", - "cea608parser"] -} diff --git a/Gruntfile.js b/Gruntfile.js index 8b11386380..eeb7562e67 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -15,15 +15,6 @@ module.exports = function (grunt) { build: ['build/temp'], dist: ['dist/*'] }, - jshint: { - src: { - src: ['src/**/*.js', 'test/unit/mocks/*.js', 'test/unit/*.js', 'Gruntfile.js'], - options: { - jshintrc: '.jshintrc' - } - } - }, - uglify: { options: { banner: '/*! v<%= pkg.version %>-<%= githash.dist.short %>, <%= grunt.template.today("isoUtcDateTime") %> */', @@ -433,14 +424,14 @@ module.exports = function (grunt) { require('load-grunt-tasks')(grunt); grunt.loadNpmTasks('grunt-string-replace'); grunt.registerTask('default', ['dist', 'test']); - grunt.registerTask('dist', ['clean', 'jshint', 'eslint', 'browserify:mediaplayer', 'browserify:protection', 'browserify:reporting', 'browserify:mss', 'browserify:offline', 'browserify:all', 'babel:es5', 'minimize', 'copy:dist']); + grunt.registerTask('dist', ['clean', 'eslint', 'browserify:mediaplayer', 'browserify:protection', 'browserify:reporting', 'browserify:mss', 'browserify:offline', 'browserify:all', 'babel:es5', 'minimize', 'copy:dist']); grunt.registerTask('minimize', ['exorcise', 'githash', 'uglify']); grunt.registerTask('test', ['nyc:test']); grunt.registerTask('watch', ['browserify:watch']); grunt.registerTask('watch-dev', ['browserify:watch_dev']); grunt.registerTask('release', ['default', 'jsdoc']); grunt.registerTask('debug', ['clean', 'browserify:all', 'exorcise:all', 'copy:dist']); - grunt.registerTask('lint', ['jshint', 'eslint']); + grunt.registerTask('lint', ['eslint']); grunt.registerTask('dev', ['browserSync', 'watch-dev']); grunt.registerTask('deploy', ['string-replace', 'ftp_push']); }; diff --git a/package-lock.json b/package-lock.json index d7059d4448..60e1595b0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3155,38 +3155,6 @@ "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", "dev": true }, - "cli": { - "version": "0.6.6", - "resolved": "https://registry.npmjs.org/cli/-/cli-0.6.6.tgz", - "integrity": "sha1-Aq1Eo4Cr8nraxebwzdewQ9dMU+M=", - "dev": true, - "requires": { - "exit": "0.1.2", - "glob": "~ 3.2.1" - }, - "dependencies": { - "glob": { - "version": "3.2.11", - "resolved": "https://registry.npmjs.org/glob/-/glob-3.2.11.tgz", - "integrity": "sha1-Spc/Y1uRkPcV0QmH1cAP0oFevj0=", - "dev": true, - "requires": { - "inherits": "2", - "minimatch": "0.3" - } - }, - "minimatch": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-0.3.0.tgz", - "integrity": "sha1-J12O2qxPG7MyZHIInnlJyDlGmd0=", - "dev": true, - "requires": { - "lru-cache": "2", - "sigmund": "~1.0.0" - } - } - } - }, "cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -3623,12 +3591,6 @@ "whatwg-url": "^7.0.0" } }, - "date-now": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/date-now/-/date-now-0.1.4.tgz", - "integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs=", - "dev": true - }, "date-time": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/date-time/-/date-time-1.1.0.tgz", @@ -6143,16 +6105,6 @@ "file-sync-cmp": "^0.1.0" } }, - "grunt-contrib-jshint": { - "version": "0.11.3", - "resolved": "https://registry.npmjs.org/grunt-contrib-jshint/-/grunt-contrib-jshint-0.11.3.tgz", - "integrity": "sha1-gDaBgdzNVRGG5bg4XAEc7iTWQKA=", - "dev": true, - "requires": { - "hooker": "^0.2.3", - "jshint": "~2.8.0" - } - }, "grunt-contrib-uglify": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/grunt-contrib-uglify/-/grunt-contrib-uglify-4.0.1.tgz", @@ -9126,110 +9078,6 @@ } } }, - "jshint": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/jshint/-/jshint-2.8.0.tgz", - "integrity": "sha1-HQmjvZE8TK36gb8Y1YK9hb/+DUQ=", - "dev": true, - "requires": { - "cli": "0.6.x", - "console-browserify": "1.1.x", - "exit": "0.1.x", - "htmlparser2": "3.8.x", - "lodash": "3.7.x", - "minimatch": "2.0.x", - "shelljs": "0.3.x", - "strip-json-comments": "1.0.x" - }, - "dependencies": { - "console-browserify": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-browserify/-/console-browserify-1.1.0.tgz", - "integrity": "sha1-8CQcRXMKn8YyOyBtvzjtx0HQuxA=", - "dev": true, - "requires": { - "date-now": "^0.1.4" - } - }, - "domhandler": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.3.0.tgz", - "integrity": "sha1-LeWaCCLVAn+r/28DLCsloqir5zg=", - "dev": true, - "requires": { - "domelementtype": "1" - } - }, - "domutils": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", - "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", - "dev": true, - "requires": { - "dom-serializer": "0", - "domelementtype": "1" - } - }, - "entities": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-1.0.0.tgz", - "integrity": "sha1-sph6o4ITR/zeZCsk/fyeT7cSvyY=", - "dev": true - }, - "htmlparser2": { - "version": "3.8.3", - "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.8.3.tgz", - "integrity": "sha1-mWwosZFRaovoZQGn15dX5ccMEGg=", - "dev": true, - "requires": { - "domelementtype": "1", - "domhandler": "2.3", - "domutils": "1.5", - "entities": "1.0", - "readable-stream": "1.1" - } - }, - "isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", - "dev": true - }, - "lodash": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-3.7.0.tgz", - "integrity": "sha1-Nni9irmVBXwHreg27S7wh9qBHUU=", - "dev": true - }, - "minimatch": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-2.0.10.tgz", - "integrity": "sha1-jQh8OcazjAAbl/ynzm0OHoCvusc=", - "dev": true, - "requires": { - "brace-expansion": "^1.0.0" - } - }, - "readable-stream": { - "version": "1.1.14", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", - "integrity": "sha1-fPTFTvZI44EwhMY23SB54WbAgdk=", - "dev": true, - "requires": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.1", - "isarray": "0.0.1", - "string_decoder": "~0.10.x" - } - }, - "string_decoder": { - "version": "0.10.31", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz", - "integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=", - "dev": true - } - } - }, "json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", @@ -10014,12 +9862,6 @@ "signal-exit": "^3.0.0" } }, - "lru-cache": { - "version": "2.7.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.7.3.tgz", - "integrity": "sha1-bUUk6LlV+V1PW1iFHOId1y+06VI=", - "dev": true - }, "make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -13630,18 +13472,6 @@ "integrity": "sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==", "dev": true }, - "shelljs": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.3.0.tgz", - "integrity": "sha1-NZbmMHp4FUT1kfN9phg2DzHbV7E=", - "dev": true - }, - "sigmund": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/sigmund/-/sigmund-1.0.1.tgz", - "integrity": "sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA=", - "dev": true - }, "signal-exit": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", @@ -14470,12 +14300,6 @@ "get-stdin": "^4.0.1" } }, - "strip-json-comments": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-1.0.4.tgz", - "integrity": "sha1-HhX7ysl9Pumb8tc7TGVrCCu6+5E=", - "dev": true - }, "subarg": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/subarg/-/subarg-1.0.0.tgz", diff --git a/package.json b/package.json index 7f62d01b2c..30abee6573 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "grunt-contrib-clean": "^2.0.0", "grunt-contrib-connect": "^2.0.0", "grunt-contrib-copy": "^1.0.0", - "grunt-contrib-jshint": "^0.11.2", "grunt-contrib-uglify": "^4.0.1", "grunt-contrib-watch": "^1.1.0", "grunt-eslint": "^22.0.0", diff --git a/src/mss/parser/MssParser.js b/src/mss/parser/MssParser.js index 5891fda42b..0dac001ee2 100644 --- a/src/mss/parser/MssParser.js +++ b/src/mss/parser/MssParser.js @@ -114,7 +114,6 @@ function MssParser(config) { let segmentTemplate, qualityLevels, representation, - segments, i; const name = streamIndex.getAttribute('Name'); @@ -184,8 +183,6 @@ function MssParser(config) { // Set SegmentTemplate adaptationSet.SegmentTemplate = segmentTemplate; - segments = segmentTemplate.SegmentTimeline.S_asArray; - return adaptationSet; } @@ -460,8 +457,8 @@ function MssParser(config) { } function getWRMHeaderFromPRHeader(prHeader) { - let length, - recordCount, + let // length, + // recordCount, recordType, recordLength, recordValue; @@ -470,11 +467,11 @@ function MssParser(config) { // Parse PlayReady header // Length - 32 bits (LE format) - length = (prHeader[i + 3] << 24) + (prHeader[i + 2] << 16) + (prHeader[i + 1] << 8) + prHeader[i]; + // length = (prHeader[i + 3] << 24) + (prHeader[i + 2] << 16) + (prHeader[i + 1] << 8) + prHeader[i]; i += 4; // Record count - 16 bits (LE format) - recordCount = (prHeader[i + 1] << 8) + prHeader[i]; + // recordCount = (prHeader[i + 1] << 8) + prHeader[i]; i += 2; // Parse records diff --git a/src/streaming/metrics/MetricsReporting.js b/src/streaming/metrics/MetricsReporting.js index 5f02ce2f46..9859dc21f3 100644 --- a/src/streaming/metrics/MetricsReporting.js +++ b/src/streaming/metrics/MetricsReporting.js @@ -38,8 +38,7 @@ import ReportingFactory from './reporting/ReportingFactory'; function MetricsReporting() { let context = this.context; - let instance, - dvbErrorsTranslator; + let instance; /** * Create a MetricsCollectionController, and a DVBErrorsTranslator @@ -47,7 +46,7 @@ function MetricsReporting() { * @return {MetricsCollectionController} Metrics Collection Controller */ function createMetricsReporting(config) { - dvbErrorsTranslator = DVBErrorsTranslator(context).getInstance({ + DVBErrorsTranslator(context).getInstance({ eventBus: config.eventBus, dashMetrics: config.dashMetrics, metricsConstants: config.metricsConstants, diff --git a/src/streaming/metrics/utils/MetricSerialiser.js b/src/streaming/metrics/utils/MetricSerialiser.js index db25f40503..f6fafa97f6 100644 --- a/src/streaming/metrics/utils/MetricSerialiser.js +++ b/src/streaming/metrics/utils/MetricSerialiser.js @@ -43,6 +43,14 @@ function MetricSerialiser() { let key, value; + // internal helper to remove function declaration in following loop + // TODO: the actual implementation here could be improved + const elementIterator = function (obj, v) { + let isBuiltIn = Object.prototype.toString.call(v).slice(8, -1) !== 'Object'; + + obj.push(isBuiltIn ? v : serialise(v)); + }; + // Take each (key, value) pair from the metric entry and create a // string consisting of the name of the key, followed by an equals // ('=') character, followed by the string representation of the @@ -67,11 +75,7 @@ function MetricSerialiser() { obj = []; - value.forEach(function (v) { - let isBuiltIn = Object.prototype.toString.call(v).slice(8, -1) !== 'Object'; - - obj.push(isBuiltIn ? v : serialise(v)); - }); + value.forEach(elementIterator.bind(null, obj)); value = obj.map(encodeURIComponent).join(','); } else if (typeof value === 'string') { diff --git a/src/streaming/models/CmcdModel.js b/src/streaming/models/CmcdModel.js index 432b95abde..85082ab496 100644 --- a/src/streaming/models/CmcdModel.js +++ b/src/streaming/models/CmcdModel.js @@ -31,7 +31,6 @@ import EventBus from '../../core/EventBus'; import MediaPlayerEvents from '../MediaPlayerEvents'; import FactoryMaker from '../../core/FactoryMaker'; -import Debug from '../../core/Debug'; import Settings from '../../core/Settings'; import {HTTPRequest} from '../vo/metrics/HTTPRequest'; import DashManifestModel from '../../dash/models/DashManifestModel'; @@ -66,8 +65,7 @@ const STREAM_TYPES = { function CmcdModel() { - let logger, - dashManifestModel, + let dashManifestModel, instance, internalData, abrController, @@ -79,7 +77,6 @@ function CmcdModel() { let settings = Settings(context).getInstance(); function setup() { - logger = Debug(context).getInstance().getLogger(instance); dashManifestModel = DashManifestModel(context).getInstance(); _resetInitialSettings(); diff --git a/src/streaming/protection/CommonEncryption.js b/src/streaming/protection/CommonEncryption.js index 0887cf898f..f676111b04 100644 --- a/src/streaming/protection/CommonEncryption.js +++ b/src/streaming/protection/CommonEncryption.js @@ -135,7 +135,7 @@ class CommonEncryption { nextBox, version, systemID, - psshDataSize, + // psshDataSize, i, val; let boxStart = byteCursor; @@ -200,7 +200,7 @@ class CommonEncryption { systemID = systemID.toLowerCase(); /* PSSH Data Size */ - psshDataSize = dv.getUint32(byteCursor); + // psshDataSize = dv.getUint32(byteCursor); byteCursor += 4; /* PSSH Data */ diff --git a/src/streaming/protection/controllers/ProtectionController.js b/src/streaming/protection/controllers/ProtectionController.js index 1dd715de7e..5fb84e41d2 100644 --- a/src/streaming/protection/controllers/ProtectionController.js +++ b/src/streaming/protection/controllers/ProtectionController.js @@ -414,35 +414,36 @@ function ProtectionController(config) { return indexA - indexB; }); - let ksIdx; if (keySystem) { // We have a key system - for (ksIdx = 0; ksIdx < supportedKS.length; ksIdx++) { + + // Ensure that we would be granted key system access using the key + // system and codec information + const onKeySystemAccessComplete = function (ksIdx, event) { + eventBus.off(events.KEY_SYSTEM_ACCESS_COMPLETE, onKeySystemAccessComplete, self); + if (event.error) { + if (!fromManifest) { + eventBus.trigger(events.KEY_SYSTEM_SELECTED, { error: new DashJSError(ProtectionErrors.KEY_SYSTEM_ACCESS_DENIED_ERROR_CODE, ProtectionErrors.KEY_SYSTEM_ACCESS_DENIED_ERROR_MESSAGE + event.error) }); + } + } else { + logger.info('DRM: KeySystem Access Granted'); + eventBus.trigger(events.KEY_SYSTEM_SELECTED, { data: event.data }); + if (supportedKS[ksIdx].sessionId) { + // Load MediaKeySession with sessionId + loadKeySession(supportedKS[ksIdx].sessionId, supportedKS[ksIdx].initData); + } else if (supportedKS[ksIdx].initData) { + // Create new MediaKeySession with initData + createKeySession(supportedKS[ksIdx].initData, supportedKS[ksIdx].cdmData); + } + } + }; + for (let ksIdx = 0; ksIdx < supportedKS.length; ksIdx++) { if (keySystem === supportedKS[ksIdx].ks) { requestedKeySystems.push({ks: supportedKS[ksIdx].ks, configs: [getKeySystemConfiguration(keySystem)]}); - // Ensure that we would be granted key system access using the key - // system and codec information - const onKeySystemAccessComplete = function (event) { - eventBus.off(events.KEY_SYSTEM_ACCESS_COMPLETE, onKeySystemAccessComplete, self); - if (event.error) { - if (!fromManifest) { - eventBus.trigger(events.KEY_SYSTEM_SELECTED, {error: new DashJSError(ProtectionErrors.KEY_SYSTEM_ACCESS_DENIED_ERROR_CODE, ProtectionErrors.KEY_SYSTEM_ACCESS_DENIED_ERROR_MESSAGE + event.error)}); - } - } else { - logger.info('DRM: KeySystem Access Granted'); - eventBus.trigger(events.KEY_SYSTEM_SELECTED, {data: event.data}); - if (supportedKS[ksIdx].sessionId) { - // Load MediaKeySession with sessionId - loadKeySession(supportedKS[ksIdx].sessionId, supportedKS[ksIdx].initData); - } else if (supportedKS[ksIdx].initData) { - // Create new MediaKeySession with initData - createKeySession(supportedKS[ksIdx].initData, supportedKS[ksIdx].cdmData); - } - } - }; - eventBus.on(events.KEY_SYSTEM_ACCESS_COMPLETE, onKeySystemAccessComplete, self); + + eventBus.on(events.KEY_SYSTEM_ACCESS_COMPLETE, onKeySystemAccessComplete.bind(null, ksIdx), self); protectionModel.requestKeySystemAccess(requestedKeySystems); break; } @@ -463,6 +464,8 @@ function ProtectionController(config) { eventBus.off(events.KEY_SYSTEM_ACCESS_COMPLETE, onKeySystemAccessComplete, self); if (event.error) { keySystem = undefined; + // TODO: check if this use before define is legitimate + // eslint-disable-next-line no-use-before-define eventBus.off(events.INTERNAL_KEY_SYSTEM_SELECTED, onKeySystemSelected, self); if (!fromManifest) { eventBus.trigger(events.KEY_SYSTEM_SELECTED, {data: null, error: new DashJSError(ProtectionErrors.KEY_SYSTEM_ACCESS_DENIED_ERROR_CODE, ProtectionErrors.KEY_SYSTEM_ACCESS_DENIED_ERROR_MESSAGE + event.error)}); @@ -488,7 +491,7 @@ function ProtectionController(config) { protectionModel.setServerCertificate(BASE64.decodeArray(protData.serverCertificate).buffer); } for (let i = 0; i < pendingNeedKeyData.length; i++) { - for (ksIdx = 0; ksIdx < pendingNeedKeyData[i].length; ksIdx++) { + for (let ksIdx = 0; ksIdx < pendingNeedKeyData[i].length; ksIdx++) { if (keySystem === pendingNeedKeyData[i][ksIdx].ks) { // For Clearkey: if parameters for generating init data was provided by the user, use them for generating // initData and overwrite possible initData indicated in encrypted event (EME) diff --git a/src/streaming/protection/models/ProtectionModel_21Jan2015.js b/src/streaming/protection/models/ProtectionModel_21Jan2015.js index 595322cf3b..4c99695e54 100644 --- a/src/streaming/protection/models/ProtectionModel_21Jan2015.js +++ b/src/streaming/protection/models/ProtectionModel_21Jan2015.js @@ -74,7 +74,6 @@ function ProtectionModel_21Jan2015(config) { function reset() { const numSessions = sessions.length; - let session; if (numSessions !== 0) { // Called when we are done closing a session. Success or fail @@ -91,20 +90,19 @@ function ProtectionModel_21Jan2015(config) { } } }; + const processSession = function (session) { + // Override closed promise resolver + session.session.closed.then(function () { + done(session); + }); + // Close the session and handle errors, otherwise promise + // resolver above will be called + closeKeySessionInternal(session).catch(function () { + done(session); + }); + }; for (let i = 0; i < numSessions; i++) { - session = sessions[i]; - (function (s) { - // Override closed promise resolver - session.session.closed.then(function () { - done(s); - }); - // Close the session and handle errors, otherwise promise - // resolver above will be called - closeKeySessionInternal(session).catch(function () { - done(s); - }); - - })(session); + processSession(sessions[i]); } } else { eventBus.trigger(events.TEARDOWN_COMPLETE); @@ -117,9 +115,7 @@ function ProtectionModel_21Jan2015(config) { for (let i = 0; i < sessions.length; i++) { session = sessions[i]; if (!session.getUsable()) { - closeKeySessionInternal(session).catch(function () { - removeSession(session); - }); + closeKeySessionInternal(session).catch(removeSession.bind(null, session)); } } } diff --git a/src/streaming/rules/scheduling/NextFragmentRequestRule.js b/src/streaming/rules/scheduling/NextFragmentRequestRule.js index d768dae921..f1167873bb 100644 --- a/src/streaming/rules/scheduling/NextFragmentRequestRule.js +++ b/src/streaming/rules/scheduling/NextFragmentRequestRule.js @@ -29,23 +29,18 @@ * POSSIBILITY OF SUCH DAMAGE. */ import Constants from '../../constants/Constants'; -import Debug from '../../../core/Debug'; import FactoryMaker from '../../../core/FactoryMaker'; import FragmentRequest from '../../../streaming/vo/FragmentRequest'; function NextFragmentRequestRule(config) { config = config || {}; - const context = this.context; const textController = config.textController; const playbackController = config.playbackController; - let instance, - logger; + let instance; - function setup() { - logger = Debug(context).getInstance().getLogger(instance); - } + function setup() {} function execute(streamProcessor, seekTarget, requestToReplace) { if (!streamProcessor) { diff --git a/src/streaming/text/TextSourceBuffer.js b/src/streaming/text/TextSourceBuffer.js index d89dffdf28..adeb838832 100644 --- a/src/streaming/text/TextSourceBuffer.js +++ b/src/streaming/text/TextSourceBuffer.js @@ -453,13 +453,11 @@ function TextSourceBuffer() { if (!embeddedCea608FieldParsers[0] && !embeddedCea608FieldParsers[1]) { // Time to setup the CEA-608 parsing - let field, handler, trackIdx; + let handler, trackIdx; for (i = 0; i < embeddedTracks.length; i++) { if (embeddedTracks[i].id === Constants.CC1) { - field = 0; trackIdx = textTracks.getTrackIdxForId(Constants.CC1); } else if (embeddedTracks[i].id === Constants.CC3) { - field = 1; trackIdx = textTracks.getTrackIdxForId(Constants.CC3); } if (trackIdx === -1) { diff --git a/src/streaming/text/TextTracks.js b/src/streaming/text/TextTracks.js index 85fc6a572f..ec970ccab1 100644 --- a/src/streaming/text/TextTracks.js +++ b/src/streaming/text/TextTracks.js @@ -410,6 +410,38 @@ function TextTracks() { return; } + const onenterHandlerHtml = function () { + if (track.mode === Constants.TEXT_SHOWING) { + if (this.isd) { + renderCaption(this); + logger.debug('Cue enter id:' + this.cueID); + } else { + captionContainer.appendChild(this.cueHTMLElement); + scaleCue.call(self, this); + eventBus.trigger(Events.CAPTION_RENDERED, { captionDiv: this.cueHTMLElement, currentTrackIdx }); + } + } + }; + + const onexitHandlerHtml = function () { + if (captionContainer) { + const divs = captionContainer.childNodes; + for (let i = 0; i < divs.length; ++i) { + if (divs[i].id === this.cueID) { + logger.debug('Cue exit id:' + divs[i].id); + captionContainer.removeChild(divs[i]); + --i; + } + } + } + }; + + const onenterHandler = function () { + if (track.mode === Constants.TEXT_SHOWING) { + eventBus.trigger(Events.CAPTION_RENDERED, { currentTrackIdx }); + } + }; + for (let item = 0; item < captionData.length; item++) { let cue; const currentItem = captionData[item]; @@ -436,31 +468,8 @@ function TextTracks() { captionContainer.style.width = actualVideoWidth + 'px'; captionContainer.style.height = actualVideoHeight + 'px'; - cue.onenter = function () { - if (track.mode === Constants.TEXT_SHOWING) { - if (this.isd) { - renderCaption(this); - logger.debug('Cue enter id:' + this.cueID); - } else { - captionContainer.appendChild(this.cueHTMLElement); - scaleCue.call(self, this); - eventBus.trigger(Events.CAPTION_RENDERED, {captionDiv: this.cueHTMLElement, currentTrackIdx}); - } - } - }; - - cue.onexit = function () { - if (captionContainer) { - const divs = captionContainer.childNodes; - for (let i = 0; i < divs.length; ++i) { - if (divs[i].id === this.cueID) { - logger.debug('Cue exit id:' + divs[i].id); - captionContainer.removeChild(divs[i]); - --i; - } - } - } - }; + cue.onenter = onenterHandlerHtml(); + cue.onexit = onexitHandlerHtml(); } else { if (currentItem.data) { cue = new Cue(currentItem.start - timeOffset, currentItem.end - timeOffset, currentItem.data); @@ -478,11 +487,7 @@ function TextTracks() { cue.size = currentItem.styles.size; } } - cue.onenter = function () { - if (track.mode === Constants.TEXT_SHOWING) { - eventBus.trigger(Events.CAPTION_RENDERED, {currentTrackIdx}); - } - }; + cue.onenter = onenterHandler; } } try { diff --git a/src/streaming/utils/DefaultURLUtils.js b/src/streaming/utils/DefaultURLUtils.js index d32359f23a..906ea0b7fa 100644 --- a/src/streaming/utils/DefaultURLUtils.js +++ b/src/streaming/utils/DefaultURLUtils.js @@ -109,7 +109,7 @@ function DefaultURLUtils() { function setup() { try { - const u = new window.URL('x', 'http://y'); //jshint ignore:line + new window.URL('x', 'http://y'); resolveFunction = nativeURLResolver; } catch (e) { // must be IE11/Node etc diff --git a/src/streaming/utils/TTMLParser.js b/src/streaming/utils/TTMLParser.js index 764aeccb3d..7867c100db 100644 --- a/src/streaming/utils/TTMLParser.js +++ b/src/streaming/utils/TTMLParser.js @@ -121,11 +121,12 @@ function TTMLParser() { eventBus.trigger(Events.TTML_PARSED, {ttmlString: content.data, ttmlDoc: imsc1doc}); const mediaTimeEvents = imsc1doc.getMediaTimeEvents(); + const errorHandler = function (error) { + errorMsg = error; + }; for (i = 0; i < mediaTimeEvents.length; i++) { - let isd = generateISD(imsc1doc, mediaTimeEvents[i], function (error) { - errorMsg = error; - }); + let isd = generateISD(imsc1doc, mediaTimeEvents[i], errorHandler); if (isd.contents.some(topLevelContents => topLevelContents.contents.length)) { //be sure that mediaTimeEvents values are in the mp4 segment time ranges. diff --git a/test/unit/dash.utils.TimelineConverter.js b/test/unit/dash.utils.TimelineConverter.js index c3e5cc7397..0761d5e105 100644 --- a/test/unit/dash.utils.TimelineConverter.js +++ b/test/unit/dash.utils.TimelineConverter.js @@ -57,13 +57,9 @@ describe('TimelineConverter', function () { }); describe('when time sync is complete', function () { - let updateCompleted; - beforeEach(function (done) { - updateCompleted = false; setTimeout(() => { eventBus.trigger(Events.TIME_SYNCHRONIZATION_COMPLETED, {offset: 0}); - updateCompleted = true; done(); }, specHelper.getExecutionDelay()); });