@bradmax/player-ng
Version:
Bradmax Player Angular module.
248 lines (240 loc) • 8.79 kB
JavaScript
/**
* @license
* _ _
* | | | |
* | |__ _ __ __ _ __| |_ __ ___ __ ___ __
* | '_ \| '__/ _` |/ _` | '_ ` _ \ / _` \ \/ /
* | |_) | | | (_| | (_| | | | | | | (_| |> <
* |_.__/|_| \__,_|\__,_|_| |_| |_|\__,_/_/\_\
*
* Bradmax Player
* bradmax.com
*/
/* @bradmax/player-ng v0.1.2 */
import { EventEmitter, Injectable, Input, Output, InjectionToken, Component, ElementRef, Inject, NgModule } from '@angular/core';
import { BRADMAX_PLAYER_VERSION } from '@bradmax/player/version';
import '@bradmax/player/mole';
import { CommonModule } from '@angular/common';
let EmbederServiceCounter = -1;
class EmbederService {
constructor() {
this.debug = false;
this.isInitialized = false;
this.name = null;
this.version = BRADMAX_PLAYER_VERSION;
this.nativeElement = null;
this.player = null;
this.api = null;
this.onPlaying = new EventEmitter();
this.onCurrentTimeChange = new EventEmitter();
this.onComplete = new EventEmitter();
this.globalConfig = null;
this.handleCurrentTimeChange = (e) => {
if (this.debug)
console.log(EmbederService.name + '.handleCurrentTimeChange(', e, ')');
this.onCurrentTimeChange.emit(e.data);
};
this.handlePlaying = (e) => {
if (this.debug)
console.log(EmbederService.name + '.handlePlaying(', e, ')');
this.onPlaying.emit(e.data);
};
this.handleComplete = (e) => {
if (this.debug)
console.log(EmbederService.name + '.handleComplete(', e, ')');
this.onComplete.emit(e.data);
};
EmbederServiceCounter++;
if (this.debug)
console.debug(EmbederService.name + '.new(counter:' + EmbederServiceCounter + ')');
this.isInitialized = false;
}
setup(element) {
this.nativeElement = element;
if (this.debug)
console.log(EmbederService.name + '.setup(', this.nativeElement, ')');
}
create(config) {
this.clean();
if (this.debug)
console.log(EmbederService.name + '.create()');
this.build(config);
this.isInitialized = true;
}
clean() {
if (this.debug)
console.log(EmbederService.name + '.clean()');
this.isInitialized = false;
this.deattachApiListeners();
if (this.player != null)
bradmax.player.destroy(this.player);
if (this.nativeElement != null)
while (this.nativeElement.firstChild != null)
this.nativeElement.removeChild(this.nativeElement.firstChild);
this.api = null;
this.player = null;
}
destroy() {
if (this.debug)
console.log(EmbederService.name + '.destroy()');
this.clean();
this.nativeElement = null;
}
get playerId() {
if (this.name == null || this.version == null)
return undefined;
return this.name + '_' + this.version;
}
build(config) {
if (this.debug)
console.log(EmbederService.name + '.build()');
if (config == null && this.globalConfig == null)
throw new Error(EmbederService.name + '.build() -> player has no configuration !');
if (this.nativeElement == null)
throw new Error(EmbederService.name + '.build() -> player nativeElement == null !');
try {
this.player = bradmax.player.create(this.nativeElement, config == null ? this.globalConfig : config, this.playerId);
}
catch (e) {
throw e;
}
try {
this.api = this.player.modules.JavascriptApi;
}
catch (e) {
throw e;
}
this.attachApiListeners();
}
attachApiListeners() {
if (this.api != null) {
this.api.add('VideoEvent.currentTimeChange', this.handleCurrentTimeChange);
this.api.add('VideoEvent.playing', this.handlePlaying);
this.api.add('VideoEvent.complete', this.handleComplete);
}
}
deattachApiListeners() {
if (this.api != null) {
this.api.remove('VideoEvent.currentTimeChange', this.handleCurrentTimeChange);
this.api.remove('VideoEvent.playing', this.handlePlaying);
this.api.remove('VideoEvent.complete', this.handleComplete);
}
}
}
EmbederService.decorators = [
{ type: Injectable },
];
EmbederService.ctorParameters = () => [];
class AbstractBradmaxPlayerComponent {
constructor(service, elementRef, debug) {
this.service = service;
this.elementRef = elementRef;
this.debug = debug;
this.config = null;
this.playing = new EventEmitter();
this.currentTimeChange = new EventEmitter();
this.complete = new EventEmitter();
if (this.debug)
console.debug(AbstractBradmaxPlayerComponent.name + '.new()');
try {
this.service.setup(this.elementRef.nativeElement);
}
catch (e) {
throw e;
}
}
ngOnInit() {
if (this.debug)
console.debug(AbstractBradmaxPlayerComponent.name + '.ngOnInit(', this.config, ')');
if (this.config == null || typeof this.config === undefined)
throw new Error(AbstractBradmaxPlayerComponent.name + '.ngOnInit.config == ' + this.config);
this.service.onPlaying.subscribe((e) => this.playing.emit(e));
this.service.onCurrentTimeChange.subscribe((e) => this.currentTimeChange.emit(e));
this.service.onComplete.subscribe((e) => this.complete.emit(e));
try {
this.service.create(this.config);
}
catch (e) {
throw e;
}
}
ngOnDestroy() {
if (this.debug)
console.debug(AbstractBradmaxPlayerComponent.name + '.ngOnDestroy()');
try {
this.service.destroy();
}
catch (e) {
throw e;
}
}
}
AbstractBradmaxPlayerComponent.propDecorators = {
config: [{ type: Input }],
playing: [{ type: Output }],
currentTimeChange: [{ type: Output }],
complete: [{ type: Output }]
};
const BRADMAX_PLAYER_CONFIGURATION = new InjectionToken('BRADMAX_PLAYER_CONFIGURATION');
const BRADMAX_PLAYER_DEBUG = new InjectionToken('BRADMAX_PLAYER_DEBUG');
const BRADMAX_PLAYER_SOURCE_PATH = new InjectionToken('BRADMAX_PLAYER_SOURCE_PATH');
class BradmaxPlayerMoleComponent extends AbstractBradmaxPlayerComponent {
constructor(service, elementRef, debug) {
super(service, elementRef, debug);
this.service = service;
this.elementRef = elementRef;
this.debug = debug;
service.debug = debug;
service.name = 'mole';
}
}
BradmaxPlayerMoleComponent.decorators = [
{ type: Component, args: [{
selector: 'bradmax-player-mole',
template: `<i>bradmax player loading...</i>`,
styles: [`:host {display: block;}`],
providers: [EmbederService]
},] },
];
BradmaxPlayerMoleComponent.ctorParameters = () => [
{ type: EmbederService },
{ type: ElementRef },
{ type: Boolean, decorators: [{ type: Inject, args: [BRADMAX_PLAYER_DEBUG,] }] }
];
class BradmaxPlayerMoleModule {
static forRoot(options) {
return {
ngModule: BradmaxPlayerMoleModule,
providers: [
{ provide: BRADMAX_PLAYER_DEBUG, useValue: options ? options.debug : false },
{ provide: BRADMAX_PLAYER_CONFIGURATION, useValue: options ? options.playerConfig : null }
]
};
}
static forChild(options) {
return {
ngModule: BradmaxPlayerMoleModule,
providers: [
{ provide: BRADMAX_PLAYER_DEBUG, useValue: options ? options.debug : false },
{ provide: BRADMAX_PLAYER_CONFIGURATION, useValue: options ? options.playerConfig : null }
]
};
}
}
BradmaxPlayerMoleModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule
],
declarations: [
BradmaxPlayerMoleComponent
],
entryComponents: [BradmaxPlayerMoleComponent],
exports: [
BradmaxPlayerMoleComponent
]
},] },
];
export { BradmaxPlayerMoleModule, AbstractBradmaxPlayerComponent as ɵb, BRADMAX_PLAYER_CONFIGURATION as ɵd, BRADMAX_PLAYER_DEBUG as ɵe, EmbederService as ɵc, BradmaxPlayerMoleComponent as ɵa };
/* bradmax.com */
//# sourceMappingURL=index.js.map