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

cxl jwplayer upgrades & tweaks #239

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5121b7c
feat(cxl-ui): rename jw player component
saas786 Dec 1, 2022
6bd1eb3
feat(cxl-ui): tweak jw player component
saas786 Dec 1, 2022
4ff8d22
feat(cxl-ui): rename caption mixin to transcript mixin
saas786 Dec 1, 2022
6b74e43
feat(cxl-ui): tweak transcript mixin
saas786 Dec 1, 2022
7391356
feat(cxl-ui): rename chapter mixin to chapter navigation mixin
saas786 Dec 1, 2022
67aba0d
feat(cxl-ui): tweak chapter navigation mixin
saas786 Dec 1, 2022
d6433d6
feat(cxl-ui): add cxl-jw-player-transcript element
saas786 Dec 1, 2022
5698fd1
feat: cleanup, refactor & improve the code for PHP `cxl/jw-player`
saas786 Dec 1, 2022
f296fbd
feat(cxl-ui): [cxl-jw-player] add styles directory
anoblet Feb 20, 2023
ec4b4c6
feat(cxl-ui): [cxl-jw-player] rename playerId, playerSource to librar…
anoblet Feb 20, 2023
744570a
feat(cxl-ui): [cxl-jw-player] add hidden property style
anoblet Feb 20, 2023
0468d8b
feat(cxl-ui): [cxl-jw-player] set container display and height
anoblet Feb 20, 2023
e6fdf45
feat(cxl-ui): [cxl-jw-player] fix playlist story
anoblet Feb 21, 2023
9bfba1e
feat(cxl-ui): [cxl-jw-player] fix playlist styles
anoblet Feb 21, 2023
45c8607
feat(cxl-ui): [cxl-jw-player] add next up CTA
anoblet Feb 23, 2023
ee00b4e
feat(cxl-ui): [cxl-jw-player] hide default next up overlay
anoblet Feb 24, 2023
6e8cc9f
feat(cxl-ui): [cxl-jw-player] add pointer events to the link not the …
anoblet Feb 24, 2023
7663379
feat(cxl-ui): [cxl-jw-player] move next up styles to the global direc…
anoblet Feb 24, 2023
0863474
feat(cxl-ui): [cxl-jw-player] refactor private methods and properties…
anoblet Feb 27, 2023
b137208
feat(cxl-ui): [cxl-jw-player] refactor for playlists
anoblet Feb 28, 2023
0d2aad0
feat(cxl-ui): [cxl-jw-player] move styles to global directory
anoblet Feb 28, 2023
a672227
feat(cxl-ui): [cxl-jw-player] remove save position endpoint request
anoblet Feb 28, 2023
c2f9f0f
feat(cxl-ui): [cxl-jw-player] add the ability to save the playback rate
anoblet Mar 1, 2023
a33acf6
feat(cxl-ui): [cxl-jw-player] add the ability to play protected content
anoblet Mar 3, 2023
bd7051a
feat(cxl-ui): [cxl-jw-player] fix media and playlist source url
anoblet Mar 3, 2023
0ec3397
feat(cxl-ui): [cxl-jw-player] fix and improve next up feature
anoblet Mar 3, 2023
ffa54c4
feat(cxl-ui): [cxl-jw-player] remove api secret default value
anoblet Mar 3, 2023
e4c8edb
feat(cxl-ui): [cxl-jw-player] fix save position when using a playlist
anoblet Mar 3, 2023
5fe476c
feat(cxl-ui): [cxl-jw-player] add ability to save playlist index
anoblet Mar 7, 2023
4f5889c
feat(cxl-ui): [cxl-jw-player] add nextupoffset attribute
anoblet Mar 7, 2023
71a4554
feat(cxl-ui): [cxl-jw-player] add separate mobile CTA
anoblet Mar 7, 2023
e9f39e2
feat(cxl-ui): [cxl-jw-player] fix chapter navigation when using playl…
anoblet Mar 7, 2023
3f024f4
feat(cxl-ui): [cxl-jw-player] fix CTA pointer events
anoblet Mar 7, 2023
6287638
feat(cxl-ui): [cxl-jw-player] fix saving position when using a playlist
anoblet Aug 26, 2024
b15f6d2
Merge branch 'master' into syed/feat/cxl-jw-player
anoblet Aug 26, 2024
8fcc612
feat(cxl-ui): cxl-jw-player update component references
anoblet Aug 26, 2024
3373bf1
feat(cxl-ui): [cxl-jw-player] fix poor refactoring
anoblet Sep 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
background: var(--lumo-shade);
gap: var(--lumo-space-s);

&[hidden] {
display: none;
}

.close {
font-size: var(--lumo-font-size-xs);
cursor: pointer;
Expand Down
3 changes: 3 additions & 0 deletions packages/cxl-ui/scss/cxl-jw-player/cxl-jw-player-next-up.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.jw-next-up-cta {
pointer-events: all;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
}
}

:host([captions]) #container {
grid-template-rows: 1fr max-content 1fr;
}

.captions {
h2,
span {
Expand Down Expand Up @@ -39,6 +35,11 @@
justify-content: center;
}

.cxl-jw-player-container {
display: grid;
height: 100%;
}

.flex {
display: flex;
height: 100%;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host(:not([hidden])) {
display: block;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:host(:not([hidden])) {
display: block;
}
25 changes: 25 additions & 0 deletions packages/cxl-ui/scss/cxl-jw-player/cxl-jw-player.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cxl-jw-player {
.jw-player-button {
width: 32px;
fill: rgba(255, 255, 255, 0.8);

&:hover {
fill: rgba(255, 255, 255, 1);
}
}

.jw-related-item {
height: 100% !important; /* stylelint-disable-line declaration-no-important */
}

.jwplayer:not(.jw-flag-small-player) .jw-related-item-next-up {
.jw-related-item-poster {
height: 100%;
}

.jw-related-item-title {
position: absolute;
bottom: 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# JW Player
# CXL JW Player

## Usage

```
<jw-player
<cxl-jw-player
is-public
captions
media-id="fZ0XiGdb"
minimum-search-length="3"
player-id="5CFJNXKb"
library-id="5CFJNXKb"
plugin-path="https://cxl.com/institute/wp-content/plugins/cxl-jwplayer/"
></jw-player>
></cxl-jw-player>
```

## Features:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { html, LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
import style from '../../../styles/cxl-jw-player/cxl-jw-player-transcript-css';
import shadowStyle from '../../../styles/cxl-jw-player/cxl-jw-player-transcript-shadow-css';

@customElement('cxl-jw-player-transcript')
export class CXLJWPlayerTranscriptElement extends LitElement {
static get styles() {
return [shadowStyle];
}

render() {
return html`<slot></slot>`;
}

async __setup() {
await super.__setup();

this.__addStyle(style);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import '@vaadin/text-field';
// eslint-disable-next-line func-names
export const template = function () {
return html`
<div class="grid height-100" id="container">
<div class="cxl-jw-player-container" id="cxl-jw-player-container">
<slot></slot>
${this.captions
? html`
Expand Down
48 changes: 48 additions & 0 deletions packages/cxl-ui/src/components/cxl-jw-player/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { LitElement } from 'lit';
import { customElement } from 'lit/decorators.js';
import style from '../../styles/cxl-jw-player/cxl-jw-player-css';
import shadowStyle from '../../styles/cxl-jw-player/cxl-jw-player-shadow-css';
import { template } from './index.html';
import {
BaseMixin,
ChapterNavigationMixin,
NextUpMixin,
SavePositionMixin,
TranscriptMixin,
} from './mixins';
import { mixin } from './utility';

@customElement('cxl-jw-player')
export class CXLJWPlayerElement extends mixin(LitElement, [
BaseMixin,
TranscriptMixin,
ChapterNavigationMixin,
NextUpMixin,
SavePositionMixin,
]) {
config = {
width: '100%',
playbackRateControls: [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2],
plugins: {
// 'http://192.168.0.101:8080/telemetry-8.20.0.js': {},
},
skin: {
name: 'cxl-institute',
},
stretching: 'uniform',
};

static get styles() {
return [shadowStyle];
}

render() {
return template.bind(this)();
}

async __setup() {
await super.__setup();

this.__addStyle(style);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { render } from 'lit';
import { property } from 'lit/decorators.js';
import { throttle } from 'lodash-es';
import { parseSync } from 'subtitle';
Expand All @@ -16,10 +17,18 @@ export function BaseMixin(BaseClass) {

@property({ attribute: 'media-id', type: String }) mediaId;

@property({ attribute: 'player-id', type: String }) playerId;
@property({ attribute: 'media-source', type: String }) mediaSource;

@property({ attribute: 'is-public', type: String }) isPublic;

@property({ attribute: 'library-id', type: String }) libraryId;

@property({ attribute: 'library-source', type: String }) librarySource;

@property({ attribute: 'playlist-id', type: String }) playlistId;

@property({ attribute: 'playlist-source', type: String }) playlistSource;

firstUpdated(_changedProperties) {
super.firstUpdated(_changedProperties);

Expand All @@ -34,33 +43,60 @@ export function BaseMixin(BaseClass) {
}

get __scriptUrl() {
return `https://content.jwplatform.com/libraries/${this.playerId}.js`;
let scriptUrl;

if (this.libraryId && this.isPublic) {
scriptUrl = `https://content.jwplatform.com/libraries/${this.libraryId}.js`;
} else if (this.librarySource) {
scriptUrl = this.librarySource;
} else {
return false;
}

return scriptUrl;
}

__addStyle(style) {
const el = document.createElement('style');
render(style, el);
this.appendChild(el);
}

async __getChapters() {
const playlistItem = this.__jwPlayer.getPlaylistItem();
const { file } = playlistItem.tracks.filter((track) => track.kind === 'chapters')[0];
const chapters = playlistItem.tracks.filter((track) => track.kind === 'chapters');
const { file } = chapters.length > 0 ? chapters[0] : '';
const response = await (await fetch(file)).text();

return parseSync(response);
}

async __getMedia() {
if (!this.mediaId) return false;

const response = await fetch(`https://cdn.jwplayer.com/v2/media/${this.mediaId}`);
const result = await response.json();
let response;

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

return result;
return response.json();
}

async __getPlaylist() {
if (!this.playlistId) return false;

const response = await fetch(`https://cdn.jwplayer.com/v2/playlists/${this.playlistId}`);
const result = await response.json();
let response;

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

return result;
return response.json();
}

async __loadScript() {
Expand Down Expand Up @@ -90,6 +126,15 @@ export function BaseMixin(BaseClass) {
* Each mixin has the ability to hook onto this method.
*/
async __setup() {

// Merge configs from `cxlJWPlayerData`.
if (typeof window.cxlJWPlayerData !== 'undefined') {
// eslint-disable-next-line camelcase
const { media_config } = window.cxlJWPlayerData[this.mediaId];
// eslint-disable-next-line camelcase
this.config = { ...this.config, ...media_config };
}

const jwPlayer = await this.__loadScript();

const el = document.createElement('div');
Expand Down
42 changes: 42 additions & 0 deletions packages/cxl-ui/src/components/cxl-jw-player/mixins/NextUpMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { html, render } from 'lit';
import style from '../../../styles/cxl-jw-player/cxl-jw-player-next-up-css';
export function NextUpMixin(BaseClass) {
class Mixin extends BaseClass {
__nextUpCTA;
pawelkmpt marked this conversation as resolved.
Show resolved Hide resolved

async __setup() {
await super.__setup();

this.__addStyle(style);

this.__nextUpCTA = document.createElement('div');
this.__nextUpCTA.classList.add('jw-next-up-cta');

const container = this.querySelector('.jw-nextup-container');
container.insertBefore(this.__nextUpCTA, container.firstChild);

this.__updateNextUp();
this.__jwPlayer.on('playlistItem', this.__updateNextUp.bind(this));
}

__updateNextUp() {
const index = this.__jwPlayer.getPlaylistIndex();
const playlistItem = this.__jwPlayer.getPlaylistItem(index + 1);

if (playlistItem && playlistItem.coursePage) {
render(this.__getTemplate(playlistItem), this.__nextUpCTA);
}
}

// eslint-disable-next-line class-methods-use-this
__getTemplate(playlistItem) {
return html`
<a href=${playlistItem.coursePage}>
<vaadin-button role="link" theme="primary">Go to the course page</vaadin-button>
</a>
`;
}
}

return Mixin;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function SavePositionMixin(BaseClass) {
class Mixin extends BaseClass {
__endpoint = '';
__endpoint;

__nonce;

Expand All @@ -9,6 +9,12 @@ export function SavePositionMixin(BaseClass) {
async __setup() {
await super.__setup();

this.__endpoint = `${window.ajaxurl}?action=jwplayer_save_position`;

if ( typeof window.cxl_pum_vars !== 'undefined' ) {
this.__nonce = window.cxl_pum_vars.nonce;
}

this.__loadPosition();
}

Expand Down
Loading