@ngx-telly/player
Version:
Telly - Angular frame-accurate HTML player
177 lines (168 loc) • 7.2 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, inject, Optional, Inject, signal, makeEnvironmentProviders } from '@angular/core';
import { Subject, takeUntil, merge } from 'rxjs';
import { eventType, VideoEvent, tellyConfigToken, tellyPluginToken, tellyPluginConfigToken } from '@ngx-telly/player/core';
class TellyEventsService {
constructor() {
this.destroy$ = new Subject();
this.reconfigure$ = new Subject();
this.hide$ = new Subject();
this.click$ = new Subject();
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyEventsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyEventsService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyEventsService, decorators: [{
type: Injectable
}] });
class TellyMediaService {
constructor() {
this.staticFactories = [];
this.dynamicFactories = new Map();
this.medias = new Map();
}
register(media) {
if (this.exists(media.id))
throw new Error(`TellyMedia ${media.id} already exist!`);
this.medias.set(media.id, media);
}
deregister(id) {
this.medias.delete(id);
}
get(id) {
const media = this.medias.get(id);
if (media) {
return [...this.staticFactories, ...this.dynamicFactories.values()].reduce((acc, factory) => factory(acc), media);
}
return;
}
exists(id) {
return this.medias.has(id);
}
registerFactory(name, factory) {
if (factory) {
this.dynamicFactories.set(name, factory);
}
}
deregisterFactory(name) {
this.dynamicFactories.delete(name);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyMediaService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyMediaService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyMediaService, decorators: [{
type: Injectable
}] });
class TellyDurationCapperService {
constructor() {
this.events = inject(TellyEventsService);
}
set(cap, media) {
media.events
.pipe(takeUntil(merge(this.events.destroy$, this.events.reconfigure$)), eventType([VideoEvent.LoadedData, VideoEvent.Ended, VideoEvent.Seeked, VideoEvent.Seeking]))
.subscribe(e => {
switch (e.type) {
case VideoEvent.LoadedData:
this.cap = cap ?? media.duration;
break;
case VideoEvent.Seeking:
if (this.cap && media.time >= this.cap) {
media.seek(this.cap - 0.001);
media.play(true);
}
break;
case VideoEvent.Ended:
media.setRate(1);
media.indicate('End');
break;
}
});
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyDurationCapperService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyDurationCapperService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyDurationCapperService, decorators: [{
type: Injectable
}] });
class TellyPluginOrchestratorService {
constructor(plugins) {
this.plugins = [];
this.config = inject(tellyConfigToken);
this.tellyMedia = inject(TellyMediaService);
plugins = plugins || [];
this.plugins = Array.isArray(plugins) ? plugins : [plugins];
}
registerMediaFactory() {
this.plugins
.filter(this.canRegisterMediaFactory)
.forEach((plugin) => this.tellyMedia.staticFactories.push(plugin.config.mediaFactory));
}
canRegisterMediaFactory(plugin) {
return plugin.config.mediaFactory != null;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyPluginOrchestratorService, deps: [{ token: tellyPluginToken, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyPluginOrchestratorService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyPluginOrchestratorService, decorators: [{
type: Injectable
}], ctorParameters: () => [{ type: undefined, decorators: [{
type: Optional
}, {
type: Inject,
args: [tellyPluginToken]
}] }] });
class TellyFullscreenService {
constructor() {
this.fullscreen = signal(false);
}
enter() {
this.fullscreen.set(true);
}
exit() {
this.fullscreen.set(false);
}
toggle() {
this.fullscreen.update((x) => !x);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyFullscreenService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyFullscreenService }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.9", ngImport: i0, type: TellyFullscreenService, decorators: [{
type: Injectable
}] });
function pluginFactory(plugin, config) {
return new plugin(config);
}
function provideTellyPlayer(config) {
return makeEnvironmentProviders([
{
provide: tellyConfigToken,
useValue: config,
multi: false,
},
TellyMediaService,
TellyDurationCapperService,
TellyEventsService,
TellyPluginOrchestratorService,
TellyFullscreenService,
]);
}
function provideTellyPlugin(plugin, config) {
return makeEnvironmentProviders([
{
provide: tellyPluginConfigToken,
useValue: config,
},
{
provide: tellyPluginToken,
useFactory: pluginFactory,
deps: [plugin, tellyPluginConfigToken],
multi: true,
},
]);
}
/**
* Generated bundle index. Do not edit.
*/
export { TellyDurationCapperService, TellyEventsService, TellyFullscreenService, TellyMediaService, TellyPluginOrchestratorService, pluginFactory, provideTellyPlayer, provideTellyPlugin };
//# sourceMappingURL=ngx-telly-player-services.mjs.map