Skip to content

Commit

Permalink
feat(cxl-ui): cxl-jw-player refactor base url
Browse files Browse the repository at this point in the history
  • Loading branch information
anoblet committed Sep 23, 2024
1 parent 702065a commit 2a873b4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/cxl-ui/src/components/cxl-jw-player/mixins/BaseMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { MediaQueryController } from '@vaadin/component-base/src/media-query-con

export function BaseMixin(BaseClass) {
class Mixin extends BaseClass {
_baseUrl = 'https://cdn.jwplayer.com/';

_boundOnTimeListener;

_chapters;
Expand Down Expand Up @@ -70,7 +72,7 @@ export function BaseMixin(BaseClass) {

if (this.libraryId) {
if (this.isPublic) {
scriptUrl = `https://content.jwplatform.com/libraries/${this.libraryId}.js`;
scriptUrl = `${this._baseUrl}libraries/${this.libraryId}.js`;
} else {
scriptUrl = this.__signedURL(`libraries/${this.libraryId}.js`);
}
Expand Down Expand Up @@ -113,9 +115,9 @@ export function BaseMixin(BaseClass) {

if (this.mediaId) {
if (this.isPublic) {
response = await fetch(`https://cdn.jwplayer.com/v2/media/${this.mediaId}`);
response = await fetch(`${this._baseUrl}v2/media/${this.mediaId}`);
} else {
response = await fetch(await this._signedJWTURL(`/v2/media/${this.mediaId}`));
response = await fetch(await this._signedJWTURL(`v2/media/${this.mediaId}`));
}
}

Expand All @@ -133,9 +135,9 @@ export function BaseMixin(BaseClass) {

if (this.playlistId) {
if (this.isPublic) {
response = await fetch(`https://cdn.jwplayer.com/v2/playlists/${this.playlistId}`);
response = await fetch(`${this._baseUrl}v2/playlists/${this.playlistId}`);
} else {
response = await fetch(await this._signedJWTURL(`/v2/playlists/${this.playlistId}`));
response = await fetch(await this._signedJWTURL(`v2/playlists/${this.playlistId}`));
}
}

Expand Down Expand Up @@ -220,14 +222,14 @@ export function BaseMixin(BaseClass) {
.setExpirationTime('2h')
.sign(secret);

return `https://cdn.jwplayer.com${path}?token=${token}`;
return `${this._baseUrl}${path}?token=${token}`;
}

__signedURL(path) {
const expires = Math.ceil((new Date().getTime() + 3600) / 300) * 300;
const signature = MD5(`${path}:${expires}:${this.apiSecret}`);

return `https://cdn.jwplayer.com/${path}?exp=${expires}&sig=${signature}`;
return `${this._baseUrl}${path}?exp=${expires}&sig=${signature}`;
}
}

Expand Down

0 comments on commit 2a873b4

Please sign in to comment.