@bradmax/player-ng
Version:
Bradmax Player Angular module.
263 lines (255 loc) • 10.2 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 { __extends } from 'tslib';
import '@bradmax/player/gorilla';
import { CommonModule } from '@angular/common';
var EmbederServiceCounter = -1;
var EmbederService = (function () {
function EmbederService() {
var _this = this;
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 = function (e) {
if (_this.debug)
console.log(EmbederService.name + '.handleCurrentTimeChange(', e, ')');
_this.onCurrentTimeChange.emit(e.data);
};
this.handlePlaying = function (e) {
if (_this.debug)
console.log(EmbederService.name + '.handlePlaying(', e, ')');
_this.onPlaying.emit(e.data);
};
this.handleComplete = function (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;
}
EmbederService.prototype.setup = function (element) {
this.nativeElement = element;
if (this.debug)
console.log(EmbederService.name + '.setup(', this.nativeElement, ')');
};
EmbederService.prototype.create = function (config) {
this.clean();
if (this.debug)
console.log(EmbederService.name + '.create()');
this.build(config);
this.isInitialized = true;
};
EmbederService.prototype.clean = function () {
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;
};
EmbederService.prototype.destroy = function () {
if (this.debug)
console.log(EmbederService.name + '.destroy()');
this.clean();
this.nativeElement = null;
};
Object.defineProperty(EmbederService.prototype, "playerId", {
get: function () {
if (this.name == null || this.version == null)
return undefined;
return this.name + '_' + this.version;
},
enumerable: true,
configurable: true
});
EmbederService.prototype.build = function (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();
};
EmbederService.prototype.attachApiListeners = function () {
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);
}
};
EmbederService.prototype.deattachApiListeners = function () {
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 = function () { return []; };
return EmbederService;
}());
var AbstractBradmaxPlayerComponent = (function () {
function AbstractBradmaxPlayerComponent(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;
}
}
AbstractBradmaxPlayerComponent.prototype.ngOnInit = function () {
var _this = this;
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(function (e) { return _this.playing.emit(e); });
this.service.onCurrentTimeChange.subscribe(function (e) { return _this.currentTimeChange.emit(e); });
this.service.onComplete.subscribe(function (e) { return _this.complete.emit(e); });
try {
this.service.create(this.config);
}
catch (e) {
throw e;
}
};
AbstractBradmaxPlayerComponent.prototype.ngOnDestroy = function () {
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 }]
};
return AbstractBradmaxPlayerComponent;
}());
var BRADMAX_PLAYER_CONFIGURATION = new InjectionToken('BRADMAX_PLAYER_CONFIGURATION');
var BRADMAX_PLAYER_DEBUG = new InjectionToken('BRADMAX_PLAYER_DEBUG');
var BRADMAX_PLAYER_SOURCE_PATH = new InjectionToken('BRADMAX_PLAYER_SOURCE_PATH');
var BradmaxPlayerGorillaComponent = (function (_super) {
__extends(BradmaxPlayerGorillaComponent, _super);
function BradmaxPlayerGorillaComponent(service, elementRef, debug) {
var _this = _super.call(this, service, elementRef, debug) || this;
_this.service = service;
_this.elementRef = elementRef;
_this.debug = debug;
service.debug = debug;
service.name = 'gorilla';
return _this;
}
BradmaxPlayerGorillaComponent.decorators = [
{ type: Component, args: [{
selector: 'bradmax-player-gorilla',
template: "<i>bradmax player loading...</i>",
styles: [":host {display: block;}"],
providers: [EmbederService]
},] },
];
BradmaxPlayerGorillaComponent.ctorParameters = function () { return [
{ type: EmbederService },
{ type: ElementRef },
{ type: Boolean, decorators: [{ type: Inject, args: [BRADMAX_PLAYER_DEBUG,] }] }
]; };
return BradmaxPlayerGorillaComponent;
}(AbstractBradmaxPlayerComponent));
var BradmaxPlayerGorillaModule = (function () {
function BradmaxPlayerGorillaModule() {
}
BradmaxPlayerGorillaModule.forRoot = function (options) {
return {
ngModule: BradmaxPlayerGorillaModule,
providers: [
{ provide: BRADMAX_PLAYER_DEBUG, useValue: options ? options.debug : false },
{ provide: BRADMAX_PLAYER_CONFIGURATION, useValue: options ? options.playerConfig : null }
]
};
};
BradmaxPlayerGorillaModule.forChild = function (options) {
return {
ngModule: BradmaxPlayerGorillaModule,
providers: [
{ provide: BRADMAX_PLAYER_DEBUG, useValue: options ? options.debug : false },
{ provide: BRADMAX_PLAYER_CONFIGURATION, useValue: options ? options.playerConfig : null }
]
};
};
BradmaxPlayerGorillaModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule
],
declarations: [
BradmaxPlayerGorillaComponent
],
entryComponents: [BradmaxPlayerGorillaComponent],
exports: [
BradmaxPlayerGorillaComponent
]
},] },
];
return BradmaxPlayerGorillaModule;
}());
export { BradmaxPlayerGorillaModule, AbstractBradmaxPlayerComponent as ɵb, BRADMAX_PLAYER_CONFIGURATION as ɵd, BRADMAX_PLAYER_DEBUG as ɵe, EmbederService as ɵc, BradmaxPlayerGorillaComponent as ɵa };
/* bradmax.com */
//# sourceMappingURL=index.js.map