This repository has been archived by the owner on Dec 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
145 additions
and
24 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
projects/ngx-plyr/src/lib/plyr-driver/default-plyr-driver.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import Plyr from 'plyr'; | ||
import { DefaultPlyrDriver } from './default-plyr-driver'; | ||
|
||
describe('DefaultPlyrDriver', () => { | ||
beforeEach(() => TestBed.configureTestingModule({})); | ||
|
||
it('should be created', () => { | ||
const driver: DefaultPlyrDriver = TestBed.get(DefaultPlyrDriver); | ||
expect(driver).toBeTruthy(); | ||
}); | ||
|
||
function createVideo() { | ||
const video = document.createElement('video'); | ||
|
||
document.body.appendChild(video); | ||
|
||
return video; | ||
} | ||
|
||
describe('create', () => { | ||
it('should created Plyr by a given video tag', () => { | ||
const driver: DefaultPlyrDriver = TestBed.get(DefaultPlyrDriver); | ||
expect(driver.create({ videoElement: createVideo(), options: {} })).toBeTruthy(); | ||
expect(driver.create({ videoElement: createVideo(), options: {} }) instanceof Plyr).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('updateSource', () => { | ||
it('should assign Plyr source settings', () => { | ||
const driver: DefaultPlyrDriver = TestBed.get(DefaultPlyrDriver); | ||
const videoElement = createVideo(); | ||
const plyr = driver.create({ videoElement: createVideo(), options: {} }); | ||
|
||
expect(() => driver.updateSource({ | ||
videoElement, | ||
plyr, | ||
source: { | ||
title: 'test title', | ||
poster: '', | ||
sources: [], | ||
tracks: [], | ||
type: 'video' | ||
} | ||
})).not.toThrow(); | ||
}); | ||
}); | ||
|
||
describe('destroy', () => { | ||
it('should destroy Plyr instance', () => { | ||
const driver: DefaultPlyrDriver = TestBed.get(DefaultPlyrDriver); | ||
const plyr = driver.create({ videoElement: createVideo(), options: {} }); | ||
|
||
expect(() => driver.destroy({ plyr })).not.toThrow(); | ||
}); | ||
}); | ||
|
||
}); |
18 changes: 18 additions & 0 deletions
18
projects/ngx-plyr/src/lib/plyr-driver/default-plyr-driver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Plyr from 'plyr'; | ||
import { PlyrDriver, PlyrDriverCreateParams, PlyrDriverUpdateSourceParams, PlyrDriverDestroyParams } from './plyr-driver'; | ||
|
||
export class DefaultPlyrDriver implements PlyrDriver { | ||
|
||
create(params: PlyrDriverCreateParams) { | ||
return new Plyr(params.videoElement, params.options); | ||
} | ||
|
||
updateSource(params: PlyrDriverUpdateSourceParams) { | ||
params.plyr.source = params.source; | ||
} | ||
|
||
destroy(params: PlyrDriverDestroyParams) { | ||
params.plyr.destroy(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Plyr from 'plyr'; | ||
|
||
export interface PlyrDriverCreateParams { | ||
options: Plyr.Options; | ||
videoElement: HTMLVideoElement; | ||
} | ||
|
||
export interface PlyrDriverUpdateSourceParams { | ||
plyr: Plyr; | ||
source: Plyr.SourceInfo; | ||
videoElement: HTMLVideoElement; | ||
} | ||
|
||
export interface PlyrDriverDestroyParams { | ||
plyr: Plyr; | ||
} | ||
|
||
export interface PlyrDriver { | ||
create(params: PlyrDriverCreateParams): Plyr; | ||
updateSource(params: PlyrDriverUpdateSourceParams): void; | ||
destroy(params: PlyrDriverDestroyParams): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<video playsinline controls #v></video> | ||
<video controls crossorigin playsinline #v></video> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
/* | ||
* Public API Surface of ngx-plyr | ||
*/ | ||
|
||
export * from './lib/plyr-driver/plyr-driver'; | ||
export * from './lib/plyr-driver/default-plyr-driver'; | ||
export * from './lib/plyr/plyr.component'; | ||
export * from './lib/ngx-plyr.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters