@latest-thinking/lt-player 1.0.9-c → 1.0.9-e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -24,9 +24,9 @@ export class LTPlayerManager {
|
|
|
24
24
|
|
|
25
25
|
let domElements: NodeListOf<HTMLElement>;
|
|
26
26
|
|
|
27
|
-
domElements = document.querySelectorAll(`.${process.env.DEFAULT_DOM_HTML_ELEMENTS}`);
|
|
27
|
+
domElements = document.querySelectorAll(`.${process.env.DEFAULT_DOM_HTML_ELEMENTS}, #${process.env.DEFAULT_DOM_HTML_ELEMENTS}`);
|
|
28
28
|
|
|
29
|
-
if (domElements.length
|
|
29
|
+
if (domElements.length !== 0) {
|
|
30
30
|
domElements = document.querySelectorAll('[data-lt-player-config]');
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -51,8 +51,9 @@ export class LTPlayerManager {
|
|
|
51
51
|
/**
|
|
52
52
|
* Init player by identifier
|
|
53
53
|
* @param identifier
|
|
54
|
+
* @param playerConfig
|
|
54
55
|
*/
|
|
55
|
-
initByClassOrID(identifier: string) {
|
|
56
|
+
initByClassOrID(identifier: string, playerConfig?: playerConfigType) {
|
|
56
57
|
|
|
57
58
|
if (typeof identifier !== 'string') {
|
|
58
59
|
console.error('Identifier has another type of');
|
|
@@ -69,7 +70,7 @@ export class LTPlayerManager {
|
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
71
72
|
return new Promise(resolve => {
|
|
72
|
-
this.initBySelector(defaultSelector).then(
|
|
73
|
+
this.initBySelector(defaultSelector, playerConfig).then(result => {
|
|
73
74
|
resolve(result);
|
|
74
75
|
})
|
|
75
76
|
})
|
|
@@ -79,13 +80,24 @@ export class LTPlayerManager {
|
|
|
79
80
|
/**
|
|
80
81
|
* Init player by HTMLElement selector
|
|
81
82
|
* @param selector
|
|
83
|
+
* @param playerConfig
|
|
82
84
|
*/
|
|
83
|
-
initBySelector(selector: HTMLElement) {
|
|
84
|
-
let playerConfig = selector.dataset.ltPlayerConfig;
|
|
85
|
+
initBySelector(selector: HTMLElement, playerConfig?: playerConfigType) {
|
|
85
86
|
|
|
86
|
-
|
|
87
|
+
let config: playerConfigType | string = selector.dataset.ltPlayerConfig;
|
|
87
88
|
|
|
88
|
-
|
|
89
|
+
if (!config) {
|
|
90
|
+
config = playerConfig;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (config !== undefined) {
|
|
94
|
+
let configData: playerConfigType;
|
|
95
|
+
|
|
96
|
+
if (typeof config === "string") {
|
|
97
|
+
configData = JSON.parse(config);
|
|
98
|
+
} else {
|
|
99
|
+
configData = config;
|
|
100
|
+
}
|
|
89
101
|
|
|
90
102
|
Object.assign(configData.body, {playerContainer: selector})
|
|
91
103
|
|
|
@@ -96,13 +108,17 @@ export class LTPlayerManager {
|
|
|
96
108
|
})
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
111
|
+
return new Promise((resolve, reject) => {
|
|
112
|
+
console.error(`Lt Player: No "data-lt-player-config" attribute is set on element!`);
|
|
113
|
+
console.log(selector)
|
|
114
|
+
console.error('Use one of below examples')
|
|
115
|
+
console.table({
|
|
116
|
+
Example_1: '<div class="lt-player" data-lt-player-config="{config}"> </div>',
|
|
117
|
+
})
|
|
118
|
+
reject()
|
|
104
119
|
})
|
|
105
|
-
|
|
120
|
+
|
|
121
|
+
|
|
106
122
|
}
|
|
107
123
|
|
|
108
124
|
/**
|
|
@@ -110,25 +126,27 @@ export class LTPlayerManager {
|
|
|
110
126
|
* @param playerConfig
|
|
111
127
|
* @protected
|
|
112
128
|
*/
|
|
113
|
-
public initPlayer(playerConfig?: playerConfigType) {
|
|
129
|
+
public initPlayer(playerConfig?: playerConfigType): Promise<any> | null {
|
|
114
130
|
|
|
115
131
|
const setup = new LTPlayerSetup();
|
|
116
132
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
if (!setup.checkIfPlayerExists(playerConfig)) {
|
|
135
|
+
reject('Duplicate player');
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
let setupPLayer = setup.init(playerConfig);
|
|
139
|
+
|
|
140
|
+
if (setupPLayer) {
|
|
141
|
+
setupPLayer.then( result => {
|
|
142
|
+
this.players.push(result);
|
|
143
|
+
resolve(result);
|
|
144
|
+
})
|
|
145
|
+
} else {
|
|
146
|
+
reject('Player is not setup')
|
|
147
|
+
}
|
|
131
148
|
|
|
149
|
+
})
|
|
132
150
|
}
|
|
133
151
|
|
|
134
152
|
/**
|
|
@@ -5,10 +5,30 @@ import {ValidatorService} from "../services/ValidatorService";
|
|
|
5
5
|
import * as playerSchema from "../json-schema/player-config.json";
|
|
6
6
|
import {LTPLayerAddInfo} from "./addInfo/LTPlayerAddInfoManager";
|
|
7
7
|
import Plyr from "plyr";
|
|
8
|
+
import {LTPlayerDevMethode} from "./LTPlayerDevMethode";
|
|
9
|
+
import Player = LTPlayerDevMethode.Player;
|
|
8
10
|
|
|
9
11
|
export class LTPlayerSetup {
|
|
12
|
+
|
|
10
13
|
additionalInfoService: LTPLayerAddInfo.Controller;
|
|
11
14
|
|
|
15
|
+
checkIfPlayerExists(playerConfig?: playerConfigType): boolean
|
|
16
|
+
{
|
|
17
|
+
let response: boolean = false;
|
|
18
|
+
|
|
19
|
+
if (playerConfig.body.playerContainer instanceof HTMLElement) {
|
|
20
|
+
response = true;
|
|
21
|
+
if (window.Player !== undefined) {
|
|
22
|
+
window.Player.players.forEach(player => {
|
|
23
|
+
if (player.playerConfig.getPlayerElementContainer() === playerConfig.body.playerContainer) {
|
|
24
|
+
response = false;
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
|
|
12
32
|
init(playerConfig?: playerConfigType): Promise<any> {
|
|
13
33
|
|
|
14
34
|
Helper.setDebugEvent('Start init player', 'info');
|