Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(example): loading media with drm #35

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

<body>
<demo-dialog>
<video-js id="player" class="pillarbox-js" controls crossorigin="anonymous"></video-js>
<video-js id="demo-player" class="pillarbox-js" controls crossorigin="anonymous"></video-js>
</demo-dialog>

<demo-header></demo-header>
Expand Down
19 changes: 12 additions & 7 deletions src/components/player/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import router from '../../router/router';
import Pillarbox from '@srgssr/pillarbox-web';
import { IL_DEFAULT_HOST } from '../../utils/il-provider.js';

const DEMO_PLAYER_ID = 'player';
const DEMO_PLAYER_ID = 'demo-player';
const DEFAULT_OPTIONS = {
restoreEl: true
};
Expand Down Expand Up @@ -63,7 +63,7 @@ const toParams = (keySystems) => {

return {
vendor,
...keySystems[vendor]
...(vendor === 'com.apple.fps.1_0' ? keySystems[vendor] : { licenseUri: keySystems[vendor] })
};
};

Expand All @@ -72,12 +72,13 @@ const toKeySystem = (params) => {
return undefined;
}

const keySystem = {};
const { certificateUrl, licenseUrl } = params;
const { certificateUri, licenseUri } = params;

keySystem[params.vendor] = { certificateUrl, licenseUrl };
if (params.vendor === 'com.apple.fps.1_0') {
return { [params.vendor]: { certificateUri, licenseUri } };
}

return keySystem;
return { [params.vendor]: licenseUri };
};

export const asQueryParams = ({ src, type, keySystems }) => {
Expand All @@ -86,10 +87,14 @@ export const asQueryParams = ({ src, type, keySystems }) => {

playerDialog.addEventListener('close', () => {
destroyPlayer();
router.updateState({}, ['src', 'type', 'vendor', 'certificateUrl', 'licenseUrl']);
router.updateState({}, ['src', 'type', 'vendor', 'certificateUri', 'licenseUri']);
});

const loadPlayerFromRouter = (e) => {
if (window.player) {
return;
}

const params = e.detail.queryParams;

if ('src' in params) {
Expand Down
28 changes: 14 additions & 14 deletions src/layout/content/examples/load-media-form-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { classMap } from 'lit/directives/class-map.js';
* @fires LoadMediaFormComponent#submit-media - Dispatched when the user submits media with the specified details.
*
* @prop {String} src - The URL or URN of the media content to be loaded.
* @prop {{vendor: String, certificateUrl: String, licenseUrl: String}} drmSettings - DRM settings for the loaded media.
* @prop {{vendor: String, certificateUri: String, licenseUri: String}} drmSettings - DRM settings for the loaded media.
*/
export class LoadMediaFormComponent extends LitElement {
static properties = {
Expand All @@ -32,8 +32,8 @@ export class LoadMediaFormComponent extends LitElement {
#initDrmSettings() {
this.drmSettings = {
vendor: '',
certificateUrl: '',
licenseUrl: ''
certificateUri: '',
licenseUri: ''
};
}

Expand All @@ -46,7 +46,7 @@ export class LoadMediaFormComponent extends LitElement {
}

#submitMedia() {
const src = this.#getSource();
const src = this.#getSource()?.trim();
const type = src.startsWith('urn:') ? 'srgssr/urn' : undefined;
const keySystems = this.#keySystems;

Expand Down Expand Up @@ -78,14 +78,14 @@ export class LoadMediaFormComponent extends LitElement {
return undefined;
}

const certificateUrl = this.drmSettings.certificateUrl;
const licenseUrl = this.drmSettings.licenseUrl;
const certificateUri = this.drmSettings.certificateUri?.trim();
const licenseUri = this.drmSettings.licenseUri?.trim();

if (this.drmSettings.vendor === 'com.apple.fps.1_0') {
return { [this.drmSettings.vendor]: { certificateUrl, licenseUrl } };
return { [this.drmSettings.vendor]: { certificateUri, licenseUri } };
}

return { [this.drmSettings.vendor]: { licenseUrl } };
return { [this.drmSettings.vendor]: licenseUri };
}

render() {
Expand Down Expand Up @@ -160,13 +160,13 @@ export class LoadMediaFormComponent extends LitElement {
<option value="com.microsoft.playready">PlayReady</option>
</select>
<input type="text"
placeholder="Enter the license url..."
.value="${this.drmSettings.licenseUrl}"
@input="${e => { this.drmSettings.licenseUrl = e.target.value; }}">
placeholder="Enter the license uri..."
.value="${this.drmSettings.licenseUri}"
@input="${e => { this.drmSettings.licenseUri = e.target.value; }}">
<input type="text"
placeholder="Enter the certificate url..."
.value="${this.drmSettings.certificateUrl}"
@input="${e => { this.drmSettings.certificateUrl = e.target.value; }}">
placeholder="Enter the certificate uri..."
.value="${this.drmSettings.certificateUri}"
@input="${e => { this.drmSettings.certificateUri = e.target.value; }}">
<button class="icon-btn warning-text" type="reset">
<i class="material-icons-outlined">delete</i>Clear Settings
</button>
Expand Down
6 changes: 5 additions & 1 deletion src/router/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ class Router extends EventTarget {
/**
* Updates the state by navigating to the current path with the provided query parameters.
*
* @param {Object} queryParams - The new query parameters to be merged with the current ones.
* @param {Object} queryParams The new query parameters to be merged with the current ones.
* @param {String[]} [keysToRemove=[]] (Optional) An array of keys to remove from
* the current query parameters before merging with the new parameters.
* This allows for selectively removing parameters that are
* no longer needed or should be excluded from the current state.
*/
updateState(queryParams, keysToRemove = []) {
const filteredParams = Object.fromEntries(
Expand Down
Loading