This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
bitdash-directive.ts
79 lines (65 loc) · 2.77 KB
/
bitdash-directive.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import * as angular from 'angular';
import {IMIUIConfig} from '../interface/interfaces';
import {IBitdashDirective, IBitmovinUIManager, IConfig, IMyElement, IPlayer, IReason, IWindow} from './../interface/interfaces';
const BitdashDirective = ($window: IWindow, $log: angular.ILogService) => ({
controller: 'MiBitdashController',
controllerAs: 'bitdashVm',
replace: true,
restrict: 'EA',
scope: {
config: '=',
options: '=?',
webcast: '=',
},
template: `<div id="mi-bitdash-player" width="100%" height="auto"></div>`,
link(scope: IBitdashDirective): void {
let bitmovinPlayer: IPlayer;
let bitmovinUIManager: IBitmovinUIManager;
let bitmovinControlbar: IMyElement;
const config: IConfig = scope.config;
const webcast: any = scope.webcast;
buildPlayer();
function buildPlayer(): void {
bitmovinPlayer = $window.window.bitmovin.player('mi-bitdash-player');
if (angular.isDefined(bitmovinPlayer) && bitmovinPlayer.isReady() === true) {
bitmovinPlayer.destroy();
bitmovinPlayer = $window.window.bitmovin.player('mi-bitdash-player');
}
if ((webcast.state === 'live') && config.source.hls_ticket) {
// Get a hive-enabled player through bitdash.initHiveSDN
$window.window.bitmovin.initHiveSDN(bitmovinPlayer, {debugLevel: 'off'});
}
loadPlayer(config);
}
function getAudioOnlyPlayerConfig(): IMIUIConfig {
return webcast.theme.audioOnlyFileUrl ? {audioOnlyOverlayConfig: {backgroundImageUrl: webcast.theme.audioOnlyFileUrl, hiddeIndicator: true}} : {};
}
function loadPlayer(conf: IConfig): void {
bitmovinPlayer.setup(conf)
.then(() => {
bitmovinUIManager = $window.window.bitmovin.playerui.UIManager.Factory;
if (isAudioOnly()) {
bitmovinUIManager.buildAudioOnlyUI(bitmovinPlayer, getAudioOnlyPlayerConfig());
} else {
bitmovinUIManager.buildAudioVideoUI(bitmovinPlayer);
}
bitmovinControlbar = getElementsByClassName('bitmovinplayer-container');
if (bitmovinControlbar) {
bitmovinControlbar.style.minWidth = '175px';
bitmovinControlbar.style.minHeight = '101px';
document.getElementById('bitmovinplayer-video-mi-bitdash-player').setAttribute('title', webcast.name);
}
}, (reason: IReason) => {
$log.log(`Error: ${reason.code} - ${reason.message}`);
});
}
function isAudioOnly(): boolean {
return webcast.layout.layout === 'audio-only';
}
function getElementsByClassName(className: string): IMyElement {
return document.getElementsByClassName(className)[0] as IMyElement;
}
}
} as angular.IDirective);
export default BitdashDirective;
BitdashDirective.$inject = ['$window', '$log'];