Skip to content

Commit

Permalink
dash and common tests, rename
Browse files Browse the repository at this point in the history
  • Loading branch information
adrums86 committed Aug 30, 2023
1 parent e177d11 commit 23d6fc6
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 195 deletions.
77 changes: 34 additions & 43 deletions src/content-steering-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,40 @@ export default class ContentSteeringController extends videojs.EventTarget {
}

/**
* This function will extract the content steering data from both DASH and HLS manifest objects.
*/
handleContentSteeringTag(mainPlaylist) {
const steeringTag = mainPlaylist.contentSteering;
* Assigns the content steering tag properties to the steering controller
*
* @param {string} baseUrl the baseURL from the manifest for resolving the steering manifest url.
*/
assignTagProperties(baseUrl, steeringTag) {
this.manifestType_ = steeringTag.serverUri ? 'HLS' : 'DASH';
// serverUri is HLS serverURL is DASH
const steeringUri = steeringTag.serverUri || steeringTag.serverURL;

if (!steeringTag) {
// Content steering manifests can be encoded as a data URI. We can decode, parse and return early if that's the case.
if (steeringUri.startsWith('data:')) {
this.decodeDataUriManifest_(steeringUri.substring(steeringUri.indexOf(',') + 1));
return;
}
this.assignTagProperties_(mainPlaylist.uri, steeringTag);
this.steeringManifest.reloadUri = resolveUrl(baseUrl, steeringUri);
// pathwayId is HLS defaultServiceLocation is DASH
this.defaultPathway = steeringTag.pathwayId || steeringTag.defaultServiceLocation;
// currently only DASH supports the following properties on <ContentSteering> tags.
if (this.manifestType_ === 'DASH') {
this.queryBeforeStart = steeringTag.queryBeforeStart || false;
this.proxyServerUrl_ = steeringTag.proxyServerURL;
}

// trigger a steering event if we have a pathway from the content steering tag.
// this tells VHS which segment pathway to start with.
if (this.defaultPathway) {
this.trigger('content-steering');
}
}

/**
* Requests the steering manifest and parse response.
*/
requestContentSteeringManifest() {
requestSteeringManifest() {
if (!this.steeringManifest.reloadUri) {
this.logger_(`manifest URL is ${this.steeringManifest.reloadUri}, cannot request steering manifest.`);

Check warning on line 128 in src/content-steering-controller.js

View check run for this annotation

Codecov / codecov/patch

src/content-steering-controller.js#L128

Added line #L128 was not covered by tests
}
Expand All @@ -130,6 +149,8 @@ export default class ContentSteeringController extends videojs.EventTarget {
// it after waiting for the previously-specified TTL (or 5 minutes if
// none).
this.logger_(`manifest failed to load ${error}.`);
// TODO: we may want to expose the error object here.
this.trigger('error');
return;
}
const steeringManifestJson = JSON.parse(this.request_.responseText);
Expand All @@ -138,37 +159,6 @@ export default class ContentSteeringController extends videojs.EventTarget {
});
}

/**
* Assigns the content steering tag properties to
*
* @param {string} baseUrl the baseURL from the manifest for resolving the steering manifest url.
*/
assignTagProperties_(baseUrl, steeringTag) {
this.manifestType_ = steeringTag.serverUri ? 'HLS' : 'DASH';
// serverUri is HLS serverURL is DASH
const steeringUri = steeringTag.serverUri || steeringTag.serverURL;

// Content steering manifests can be encoded as a data URI. We can decode, parse and return early if that's the case.
if (steeringUri.startsWith('data:')) {
this.decodeDataUriManifest_(steeringUri.substring(steeringUri.indexOf(',') + 1));
return;
}
this.steeringManifest.reloadUri = resolveUrl(baseUrl, steeringUri);
// pathwayId is HLS defaultServiceLocation is DASH
this.defaultPathway = steeringTag.pathwayId || steeringTag.defaultServiceLocation;
// currently only DASH supports the following properties on <ContentSteering> tags.
if (this.manifestType_ === 'DASH') {
this.queryBeforeStart = steeringTag.queryBeforeStart || false;
this.proxyServerUrl_ = steeringTag.proxyServerUrl;
}

// trigger a steering event if we have a pathway from the content steering tag.
// this tells VHS which segment pathway to start with.
if (this.defaultPathway && !this.queryBeforeStart) {
this.trigger('content-steering');
}
}

/**
* Set the proxy server URL and add the steering manifest url as a URI encoded parameter.
*
Expand Down Expand Up @@ -229,7 +219,8 @@ export default class ContentSteeringController extends videojs.EventTarget {
assignSteeringProperties_(steeringJson) {
this.steeringManifest.version = steeringJson.VERSION;
if (!this.steeringManifest.version) {
this.logger_(`manifest version is ${this.steeringManifest.version}, which is not supported.`);
this.logger_(`manifest version is ${steeringJson.VERSION}, which is not supported.`);
this.trigger('error');
return;
}
this.steeringManifest.ttl = steeringJson.TTL;
Expand Down Expand Up @@ -274,17 +265,17 @@ export default class ContentSteeringController extends videojs.EventTarget {
}
const ttlMS = this.steeringManifest.ttl * 1000;

this.ttlTimeout = window.setTimeout(() => {
this.requestContentSteeringManifest();
this.ttlTimeout_ = window.setTimeout(() => {
this.requestSteeringManifest();

Check warning on line 269 in src/content-steering-controller.js

View check run for this annotation

Codecov / codecov/patch

src/content-steering-controller.js#L269

Added line #L269 was not covered by tests
}, ttlMS);
}

/**
* Clear the TTL timeout if necessary.
*/
clearTTLTimeout_() {
window.clearTimeout(this.ttlTimeout);
this.ttlTimeout = null;
window.clearTimeout(this.ttlTimeout_);
this.ttlTimeout_ = null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2070,15 +2070,15 @@ export class PlaylistController extends videojs.EventTarget {
if (!main.contentSteering) {
return;
}
this.contentSteeringController_.handleContentSteeringTag(main);
this.contentSteeringController_.assignTagProperties(main.uri, main.contentSteering);
for (const playlist of main.playlists) {
this.contentSteeringController_.availablePathways.add(this.pathwayAttribute_(playlist));

Check warning on line 2075 in src/playlist-controller.js

View check run for this annotation

Codecov / codecov/patch

src/playlist-controller.js#L2073-L2075

Added lines #L2073 - L2075 were not covered by tests
}
this.contentSteeringController_.on('content-steering', this.excludeThenChangePathway_.bind(this));

Check warning on line 2077 in src/playlist-controller.js

View check run for this annotation

Codecov / codecov/patch

src/playlist-controller.js#L2077

Added line #L2077 was not covered by tests
// Do this at startup only, after that the steering requests are managed by the Content Steering class.
this.tech_.one('canplay', () => {
if (main.contentSteering) {
this.contentSteeringController_.requestContentSteeringManifest();
this.contentSteeringController_.requestSteeringManifest();

Check warning on line 2081 in src/playlist-controller.js

View check run for this annotation

Codecov / codecov/patch

src/playlist-controller.js#L2079-L2081

Added lines #L2079 - L2081 were not covered by tests
}
});
}
Expand Down
Loading

0 comments on commit 23d6fc6

Please sign in to comment.