diff --git a/demo/common/message_ids.js b/demo/common/message_ids.js index 85f127cd51..0087cbb980 100644 --- a/demo/common/message_ids.js +++ b/demo/common/message_ids.js @@ -157,6 +157,7 @@ shakaDemo.MessageIds = { DRM_SECTION_HEADER: 'DEMO_DRM_SECTION_HEADER', DURATION_BACKOFF: 'DEMO_DURATION_BACKOFF', ENABLED: 'DEMO_ENABLED', + FORCE_HTTPS: 'DEMO_FORCE_HTTPS', FORCE_TRANSMUX_TS: 'DEMO_FORCE_TRANSMUX_TS', FUZZ_FACTOR: 'DEMO_FUZZ_FACTOR', IGNORE_DASH_EMPTY_ADAPTATION_SET: 'DEMO_IGNORE_DASH_EMPTY_ADAPTATION_SET', diff --git a/demo/config.js b/demo/config.js index 9d67261f53..dc885cceff 100644 --- a/demo/config.js +++ b/demo/config.js @@ -321,7 +321,9 @@ shakaDemo.Config = class { .addBoolInput_(MessageIds.LOW_LATENCY, 'streaming.lowLatencyMode') .addBoolInput_(MessageIds.AUTO_LOW_LATENCY, - 'streaming.autoLowLatencyMode'); + 'streaming.autoLowLatencyMode') + .addBoolInput_(MessageIds.FORCE_HTTPS, + 'streaming.forceHTTPS'); if (!shakaDemoMain.getNativeControlsEnabled()) { this.addBoolInput_(MessageIds.ALWAYS_STREAM_TEXT, diff --git a/demo/locales/en.json b/demo/locales/en.json index eae1235c5b..42c1527f28 100644 --- a/demo/locales/en.json +++ b/demo/locales/en.json @@ -62,6 +62,7 @@ "DEMO_EDIT_CUSTOM": "Edit", "DEMO_ENABLED": "Enabled", "DEMO_FAIRPLAY": "Fairplay DRM", + "DEMO_FORCE_HTTPS": "Force HTTPS", "DEMO_FORCE_TRANSMUX_TS": "Force Transmux TS", "DEMO_FRONT_INTRO_DISMISS": "Dismiss", "DEMO_FRONT_INTRO_ONE": "This is a demo of Google's Shaka Player, a JavaScript library for adaptive video streaming.", diff --git a/demo/locales/source.json b/demo/locales/source.json index 16025bcfce..7ea9f3369f 100644 --- a/demo/locales/source.json +++ b/demo/locales/source.json @@ -251,6 +251,10 @@ "description": "Text that describes an asset that is protected with the Fairplay Digital Rights Management system.", "message": "[PROPER_NAME:Fairplay] [JARGON:DRM]" }, + "DEMO_FORCE_HTTPS": { + "description": "The name of a configuration value.", + "message": "Force [JARGON:HTTPS]" + }, "DEMO_FORCE_TRANSMUX_TS": { "description": "The name of a configuration value.", "message": "Force Transmux [JARGON:MPEG-2 TS]" diff --git a/externs/shaka/player.js b/externs/shaka/player.js index 9b8a561caa..2188d3f671 100644 --- a/externs/shaka/player.js +++ b/externs/shaka/player.js @@ -729,7 +729,8 @@ shaka.extern.ManifestConfiguration; * useNativeHlsOnSafari: boolean, * inaccurateManifestTolerance: number, * lowLatencyMode: boolean, - * autoLowLatencyMode: boolean + * autoLowLatencyMode: boolean, + * forceHTTPS: boolean * }} * * @description @@ -828,6 +829,8 @@ shaka.extern.ManifestConfiguration; * lowLatencyMode, but if it has been configured to activate the * lowLatencyMode if a stream of this type is detected, we automatically * activate the lowLatencyMode. Defaults to false. + * @property {boolean} forceHTTPS + * If true, if the protocol is HTTP change it to HTTPs. * * @exportDoc */ diff --git a/lib/net/networking_engine.js b/lib/net/networking_engine.js index eb455697a7..18b8e68e21 100644 --- a/lib/net/networking_engine.js +++ b/lib/net/networking_engine.js @@ -65,6 +65,17 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget { /** @private {?function(number, number)} */ this.onProgressUpdated_ = onProgressUpdated || null; + + /** @private {boolean} */ + this.forceHTTPS_ = false; + } + + /** + * @param {boolean} forceHTTPS + * @export + */ + setForceHTTPS(forceHTTPS) { + this.forceHTTPS_ = forceHTTPS; } /** @@ -380,6 +391,10 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget { * @private */ send_(type, request, backoff, index, lastError, numBytesRemainingObj) { + if (this.forceHTTPS_) { + request.uris[index] = request.uris[index].replace('http://', 'https://'); + } + const uri = new goog.Uri(request.uris[index]); let scheme = uri.getScheme(); // Whether it got a progress event. diff --git a/lib/player.js b/lib/player.js index 067b08fc42..30876b8224 100644 --- a/lib/player.js +++ b/lib/player.js @@ -503,6 +503,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget { } this.networkingEngine_ = this.createNetworkingEngine(); + this.networkingEngine_.setForceHTTPS(this.config_.streaming.forceHTTPS); /** @private {shaka.extern.IAdManager} */ this.adManager_ = null; @@ -2716,6 +2717,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget { } } } + if (this.networkingEngine_) { + this.networkingEngine_.setForceHTTPS(this.config_.streaming.forceHTTPS); + } if (this.mediaSourceEngine_) { const textDisplayerFactory = this.config_.textDisplayFactory; diff --git a/lib/util/player_configuration.js b/lib/util/player_configuration.js index ebfbdd4ca1..b45edfc2c6 100644 --- a/lib/util/player_configuration.js +++ b/lib/util/player_configuration.js @@ -136,6 +136,7 @@ shaka.util.PlayerConfiguration = class { inaccurateManifestTolerance: 2, lowLatencyMode: false, autoLowLatencyMode: false, + forceHTTPS: false, }; // WebOS, Tizen, and Chromecast have long hardware pipelines that respond diff --git a/test/test/util/fake_networking_engine.js b/test/test/util/fake_networking_engine.js index b89dd84d64..fc209ad4ba 100644 --- a/test/test/util/fake_networking_engine.js +++ b/test/test/util/fake_networking_engine.js @@ -51,6 +51,9 @@ shaka.test.FakeNetworkingEngine = class { /** @private {?shaka.extern.ResponseFilter} */ this.responseFilter_ = null; + /** @type {!jasmine.Spy} */ + this.setForceHTTPS = jasmine.createSpy('setForceHTTPS').and.stub(); + // The prototype has already been applied; create spies for the // methods but still call it by default. spyOn(this, 'destroy').and.callThrough();