Skip to content

Commit

Permalink
feat: Optionally force HTTP content URIs (#6649)
Browse files Browse the repository at this point in the history
This may be necessary on older devices where not all certificates are
present.
  • Loading branch information
avelad committed May 23, 2024
1 parent c48e435 commit dda713a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions demo/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ shakaDemo.Config = class {
/* canBeDecimal= */ true)
.addBoolInput_('Low Latency Mode', 'streaming.lowLatencyMode')
.addBoolInput_('Auto Low Latency Mode', 'streaming.autoLowLatencyMode')
.addBoolInput_('Force HTTP', 'streaming.forceHTTP')
.addBoolInput_('Force HTTPS', 'streaming.forceHTTPS')
.addBoolInput_('Prefer native HLS playback when available',
'streaming.preferNativeHls')
Expand Down
5 changes: 5 additions & 0 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,7 @@ shaka.extern.ManifestConfiguration;
* inaccurateManifestTolerance: number,
* lowLatencyMode: boolean,
* autoLowLatencyMode: boolean,
* forceHTTP: boolean,
* forceHTTPS: boolean,
* preferNativeHls: boolean,
* updateIntervalSeconds: number,
Expand Down Expand Up @@ -1352,8 +1353,12 @@ 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} forceHTTP
* If true, if the protocol is HTTPs change it to HTTP.
* If both forceHTTP and forceHTTPS are set, forceHTTPS wins.
* @property {boolean} forceHTTPS
* If true, if the protocol is HTTP change it to HTTPs.
* If both forceHTTP and forceHTTPS are set, forceHTTPS wins.
* @property {boolean} preferNativeHls
* If true, prefer native HLS playback when possible, regardless of platform.
* @property {number} updateIntervalSeconds
Expand Down
14 changes: 14 additions & 0 deletions lib/net/networking_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,21 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget {
/** @private {?shaka.net.NetworkingEngine.OnResponse} */
this.onResponse_ = onResponse || null;

/** @private {boolean} */
this.forceHTTP_ = false;

/** @private {boolean} */
this.forceHTTPS_ = false;
}

/**
* @param {boolean} forceHTTP
* @export
*/
setForceHTTP(forceHTTP) {
this.forceHTTP_ = forceHTTP;
}

/**
* @param {boolean} forceHTTPS
* @export
Expand Down Expand Up @@ -450,6 +461,9 @@ shaka.net.NetworkingEngine = class extends shaka.util.FakeEventTarget {
*/
send_(type, request, context, backoff, index, lastError,
numBytesRemainingObj) {
if (this.forceHTTP_) {
request.uris[index] = request.uris[index].replace('https://', 'http://');
}
if (this.forceHTTPS_) {
request.uris[index] = request.uris[index].replace('http://', 'https://');
}
Expand Down
2 changes: 2 additions & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
this.cmsdManager_ = this.createCmsd_();

this.networkingEngine_ = this.createNetworkingEngine();
this.networkingEngine_.setForceHTTP(this.config_.streaming.forceHTTP);
this.networkingEngine_.setForceHTTPS(this.config_.streaming.forceHTTPS);

/** @private {shaka.extern.IAdManager} */
Expand Down Expand Up @@ -3573,6 +3574,7 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
}
}
if (this.networkingEngine_) {
this.networkingEngine_.setForceHTTP(this.config_.streaming.forceHTTP);
this.networkingEngine_.setForceHTTPS(this.config_.streaming.forceHTTPS);
}

Expand Down
1 change: 1 addition & 0 deletions lib/util/player_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ shaka.util.PlayerConfiguration = class {
inaccurateManifestTolerance: 2,
lowLatencyMode: false,
autoLowLatencyMode: false,
forceHTTP: false,
forceHTTPS: false,
preferNativeHls: false,
updateIntervalSeconds: 1,
Expand Down
3 changes: 3 additions & 0 deletions test/test/util/fake_networking_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ shaka.test.FakeNetworkingEngine = class {
/** @private {?shaka.extern.ResponseFilter} */
this.responseFilter_ = null;

/** @type {!jasmine.Spy} */
this.setForceHTTP = jasmine.createSpy('setForceHTTP').and.stub();

/** @type {!jasmine.Spy} */
this.setForceHTTPS = jasmine.createSpy('setForceHTTPS').and.stub();

Expand Down

0 comments on commit dda713a

Please sign in to comment.