@media-quest/engine 0.0.39 → 0.0.41
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/dist/public-api.d.ts +8 -21
- package/dist/public-api.js +53 -32
- package/dist/public-api.js.map +1 -1
- package/package.json +26 -26
- package/src/Delement/DButton.ts +25 -25
- package/src/Delement/DElement.dto.ts +6 -6
- package/src/Delement/DElement.ts +198 -190
- package/src/Delement/DImg.ts +48 -48
- package/src/Delement/DStyle.ts +382 -391
- package/src/Delement/DText.ts +23 -23
- package/src/Delement/Ddiv.ts +44 -44
- package/src/Delement/button-click-action.ts +42 -42
- package/src/Delement/css.spec.ts +40 -40
- package/src/Delement/css.ts +70 -56
- package/src/Delement/element-factory.ts +49 -49
- package/src/engine/SchemaEngine.ts +159 -160
- package/src/engine/SchemaResult.ts +10 -12
- package/src/engine/dplayer.spec.ts +91 -92
- package/src/engine/dplayer.ts +104 -106
- package/src/engine/history-que.spec.ts +67 -69
- package/src/engine/history-que.ts +17 -21
- package/src/engine/next-que.spec.ts +121 -122
- package/src/engine/next-que.ts +101 -101
- package/src/events/mq-events.ts +63 -76
- package/src/page/Page.ts +197 -180
- package/src/page/page-result.ts +11 -12
- package/src/page/task-manager.ts +263 -263
- package/src/page/task-state.ts +65 -65
- package/src/public-api.ts +25 -26
- package/src/utils/DUtil.ts +2 -3
- package/tsconfig.json +19 -19
package/src/page/task-manager.ts
CHANGED
|
@@ -1,263 +1,263 @@
|
|
|
1
|
-
import { DTimestamp } from "../common/DTimestamp";
|
|
2
|
-
import { Task } from "./task";
|
|
3
|
-
import { DStyle, PStyle } from "../Delement/DStyle";
|
|
4
|
-
import { ScaleService } from "../engine/scale";
|
|
5
|
-
import { TaskState } from "./task-state";
|
|
6
|
-
|
|
7
|
-
export class TaskManager {
|
|
8
|
-
private readonly TAG = "[TaskManager]: ";
|
|
9
|
-
private readonly videoElement = document.createElement("video");
|
|
10
|
-
private readonly audioElement = document.createElement("audio");
|
|
11
|
-
private readonly showConsoleLogs = false;
|
|
12
|
-
private readonly defaultVideoStyles: PStyle = {
|
|
13
|
-
height: 50,
|
|
14
|
-
width: 100,
|
|
15
|
-
top: 0,
|
|
16
|
-
left: 0,
|
|
17
|
-
};
|
|
18
|
-
private videoStyles: PStyle;
|
|
19
|
-
private runningTask: { task: Task; startedAt: DTimestamp } | false = false;
|
|
20
|
-
private taskList: Array<Task> = [];
|
|
21
|
-
private delayRef: number | false = false;
|
|
22
|
-
|
|
23
|
-
clear() {
|
|
24
|
-
if (this.showConsoleLogs) console.log(this.TAG + "CLEAR");
|
|
25
|
-
if (typeof this.delayRef === "number") {
|
|
26
|
-
window.clearTimeout(this.delayRef);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
this.pauseVideo();
|
|
30
|
-
this.pauseAudio();
|
|
31
|
-
this.videoElement.removeAttribute("src");
|
|
32
|
-
this.videoElement.load();
|
|
33
|
-
this.audioElement.removeAttribute("src");
|
|
34
|
-
this.audioElement.load();
|
|
35
|
-
this.taskList = [];
|
|
36
|
-
this.runningTask = false;
|
|
37
|
-
this.hideVideo();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getState(): TaskState {
|
|
41
|
-
const c = this.runningTask;
|
|
42
|
-
const isGifMode = this.videoElement.loop;
|
|
43
|
-
const audioIsPlaying = c && c.task.kind === "play-audio-task" && !this.audioElement.paused;
|
|
44
|
-
const videoIsPlaying = c && c.task.kind === "play-video-task" && !this.videoElement.paused;
|
|
45
|
-
const blockResponseButton = c && c.task.blockResponseButton;
|
|
46
|
-
const blockAudio = c && c.task.blockAudio;
|
|
47
|
-
const blockVideo = c && c.task.blockVideo;
|
|
48
|
-
const blockFormInput = c && c.task.blockFormInput;
|
|
49
|
-
const videoIsMuted = this.videoElement.muted;
|
|
50
|
-
|
|
51
|
-
const videoIsAtTheEnd = this.videoElement.ended;
|
|
52
|
-
let videoPlayState: TaskState["videoPlayState"] = videoIsMuted ? "paused-and-muted" : "paused";
|
|
53
|
-
|
|
54
|
-
if (videoIsPlaying) {
|
|
55
|
-
videoPlayState = videoIsMuted ? "playing-and-muted" : "playing";
|
|
56
|
-
}
|
|
57
|
-
if (videoIsAtTheEnd) {
|
|
58
|
-
videoPlayState = videoIsMuted ? "ended-and-muted" : "ended";
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
audioIsPlaying,
|
|
63
|
-
videoPlayState,
|
|
64
|
-
isGifMode,
|
|
65
|
-
blockFormInput,
|
|
66
|
-
blockResponseButton,
|
|
67
|
-
blockAudio,
|
|
68
|
-
blockVideo,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
constructor(
|
|
73
|
-
private readonly mediaLayer: HTMLDivElement,
|
|
74
|
-
private readonly scale: ScaleService,
|
|
75
|
-
private readonly onError: (error: string) => void,
|
|
76
|
-
) {
|
|
77
|
-
this.hideVideo();
|
|
78
|
-
this.mediaLayer.appendChild(this.videoElement);
|
|
79
|
-
this.mediaLayer.appendChild(this.audioElement);
|
|
80
|
-
this.videoStyles = this.defaultVideoStyles;
|
|
81
|
-
DStyle.normalize(this.videoElement);
|
|
82
|
-
DStyle.applyStyles(this.videoElement, this.videoStyles, this.scale.scale);
|
|
83
|
-
|
|
84
|
-
this.videoElement.onended = () => {
|
|
85
|
-
const next = this.getNextTask();
|
|
86
|
-
if (next) {
|
|
87
|
-
this.execute(next);
|
|
88
|
-
} else {
|
|
89
|
-
this.runningTask = false;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
this.videoElement.onerror = (e) => {
|
|
93
|
-
if (this.videoElement.src !== "") {
|
|
94
|
-
onError("Error playing video: " + this.videoElement.src);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
this.audioElement.onended = () => {
|
|
99
|
-
const next = this.getNextTask();
|
|
100
|
-
if (next) {
|
|
101
|
-
this.execute(next);
|
|
102
|
-
} else {
|
|
103
|
-
this.runningTask = false;
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
execute(task: Task): boolean {
|
|
109
|
-
// console.log("EXECUTE TASK" + task.kind);
|
|
110
|
-
const curr = this.runningTask;
|
|
111
|
-
// TODO Background-task should be handeled as its own kind or something.
|
|
112
|
-
let isBackgroundTask = false;
|
|
113
|
-
|
|
114
|
-
// Check if we should remove the current task.
|
|
115
|
-
if (curr && Task.shallRemoveCurrent(task) && Task.notEq(curr.task, task)) {
|
|
116
|
-
this.pauseAudio();
|
|
117
|
-
this.pauseVideo();
|
|
118
|
-
this.runningTask = false;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (!curr) {
|
|
122
|
-
this.runningTask = { startedAt: DTimestamp.now(), task: task };
|
|
123
|
-
} else if (Task.notEq(curr.task, task)) {
|
|
124
|
-
this.runningTask = { startedAt: DTimestamp.now(), task: task };
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (task.priority === "replace-all" || task.priority === "replace-queue") {
|
|
128
|
-
this.taskList = [];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// STARTING PLAY VIDEO
|
|
132
|
-
if (task.kind === "play-video-task") {
|
|
133
|
-
this.showVideo();
|
|
134
|
-
// this.pauseAudio()
|
|
135
|
-
this.loadVideo(task.url);
|
|
136
|
-
if (task.loop) {
|
|
137
|
-
this.videoElement.loop = true;
|
|
138
|
-
isBackgroundTask = true;
|
|
139
|
-
} else {
|
|
140
|
-
this.videoElement.loop = false;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
this.videoElement.play();
|
|
145
|
-
} catch (e) {
|
|
146
|
-
console.error(e);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// STARTING PLAY AUDIO
|
|
151
|
-
if (task.kind === "play-audio-task") {
|
|
152
|
-
if (!this.videoElement.loop) {
|
|
153
|
-
this.pauseVideo();
|
|
154
|
-
}
|
|
155
|
-
if (task.url !== this.audioElement.src) {
|
|
156
|
-
this.audioElement.src = task.url;
|
|
157
|
-
}
|
|
158
|
-
this.audioElement.play();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (task.kind === "delay-task") {
|
|
162
|
-
if (typeof this.delayRef === "number") {
|
|
163
|
-
window.clearTimeout(this.delayRef);
|
|
164
|
-
}
|
|
165
|
-
this.delayRef = window.setTimeout(() => {
|
|
166
|
-
const next = this.getNextTask();
|
|
167
|
-
if (next) {
|
|
168
|
-
this.execute(next);
|
|
169
|
-
} else {
|
|
170
|
-
this.runningTask = false;
|
|
171
|
-
}
|
|
172
|
-
}, task.duration);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (isBackgroundTask) {
|
|
176
|
-
const startNextTask = this.getNextTask();
|
|
177
|
-
if (startNextTask) {
|
|
178
|
-
this.execute(startNextTask);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return true;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
setVideoStyles(styles: PStyle) {
|
|
186
|
-
this.videoStyles = { ...styles };
|
|
187
|
-
DStyle.applyStyles(this.videoElement, this.videoStyles, this.scale.scale);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
autoPlaySequence(tasks: Task[]) {
|
|
191
|
-
this.taskList = [...tasks];
|
|
192
|
-
const next = this.getNextTask();
|
|
193
|
-
if (next) {
|
|
194
|
-
this.execute(next);
|
|
195
|
-
if (next.kind === "play-video-task" && next.loop) {
|
|
196
|
-
this.videoElement.loop = true;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
loadVideo(url: string) {
|
|
202
|
-
// console.log("LOAD VIDEO " + !!url + " ");
|
|
203
|
-
if (this.videoElement.src !== url) {
|
|
204
|
-
this.videoElement.src = url;
|
|
205
|
-
}
|
|
206
|
-
this.showVideo();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private playVideoElement() {
|
|
210
|
-
this.videoElement
|
|
211
|
-
.play()
|
|
212
|
-
.then(() => {})
|
|
213
|
-
.catch((e) => {
|
|
214
|
-
console.log(e);
|
|
215
|
-
this.onError("Error playing video.");
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
private showVideo() {
|
|
220
|
-
this.videoElement.style.display = "block";
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
private hideVideo() {
|
|
224
|
-
this.videoElement.style.display = "none";
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
pauseVideo() {
|
|
228
|
-
try {
|
|
229
|
-
if (!this.videoElement.loop) {
|
|
230
|
-
this.videoElement.pause();
|
|
231
|
-
}
|
|
232
|
-
} catch (e) {
|
|
233
|
-
console.log(e);
|
|
234
|
-
this.onError("Error pausing video.");
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
pauseAudio() {
|
|
239
|
-
try {
|
|
240
|
-
if (!this.audioElement.loop) {
|
|
241
|
-
this.audioElement.pause();
|
|
242
|
-
}
|
|
243
|
-
} catch (e) {
|
|
244
|
-
console.log(e);
|
|
245
|
-
this.onError("Error pausing audio.");
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
private getNextTask(): Task | false {
|
|
250
|
-
// console.log("Getting next task.");
|
|
251
|
-
// console.log(this.taskList);
|
|
252
|
-
const first = this.taskList.shift();
|
|
253
|
-
return first ?? false;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
muteVideo() {
|
|
257
|
-
this.videoElement.muted = true;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
unMuteVideo() {
|
|
261
|
-
this.videoElement.muted = false;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
1
|
+
import { DTimestamp } from "../common/DTimestamp";
|
|
2
|
+
import { Task } from "./task";
|
|
3
|
+
import { DStyle, PStyle } from "../Delement/DStyle";
|
|
4
|
+
import { ScaleService } from "../engine/scale";
|
|
5
|
+
import { TaskState } from "./task-state";
|
|
6
|
+
|
|
7
|
+
export class TaskManager {
|
|
8
|
+
private readonly TAG = "[TaskManager]: ";
|
|
9
|
+
private readonly videoElement = document.createElement("video");
|
|
10
|
+
private readonly audioElement = document.createElement("audio");
|
|
11
|
+
private readonly showConsoleLogs = false;
|
|
12
|
+
private readonly defaultVideoStyles: PStyle = {
|
|
13
|
+
height: 50,
|
|
14
|
+
width: 100,
|
|
15
|
+
top: 0,
|
|
16
|
+
left: 0,
|
|
17
|
+
};
|
|
18
|
+
private videoStyles: PStyle;
|
|
19
|
+
private runningTask: { task: Task; startedAt: DTimestamp } | false = false;
|
|
20
|
+
private taskList: Array<Task> = [];
|
|
21
|
+
private delayRef: number | false = false;
|
|
22
|
+
|
|
23
|
+
clear() {
|
|
24
|
+
if (this.showConsoleLogs) console.log(this.TAG + "CLEAR");
|
|
25
|
+
if (typeof this.delayRef === "number") {
|
|
26
|
+
window.clearTimeout(this.delayRef);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
this.pauseVideo();
|
|
30
|
+
this.pauseAudio();
|
|
31
|
+
this.videoElement.removeAttribute("src");
|
|
32
|
+
this.videoElement.load();
|
|
33
|
+
this.audioElement.removeAttribute("src");
|
|
34
|
+
this.audioElement.load();
|
|
35
|
+
this.taskList = [];
|
|
36
|
+
this.runningTask = false;
|
|
37
|
+
this.hideVideo();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getState(): TaskState {
|
|
41
|
+
const c = this.runningTask;
|
|
42
|
+
const isGifMode = this.videoElement.loop;
|
|
43
|
+
const audioIsPlaying = c && c.task.kind === "play-audio-task" && !this.audioElement.paused;
|
|
44
|
+
const videoIsPlaying = c && c.task.kind === "play-video-task" && !this.videoElement.paused;
|
|
45
|
+
const blockResponseButton = c && c.task.blockResponseButton;
|
|
46
|
+
const blockAudio = c && c.task.blockAudio;
|
|
47
|
+
const blockVideo = c && c.task.blockVideo;
|
|
48
|
+
const blockFormInput = c && c.task.blockFormInput;
|
|
49
|
+
const videoIsMuted = this.videoElement.muted;
|
|
50
|
+
|
|
51
|
+
const videoIsAtTheEnd = this.videoElement.ended;
|
|
52
|
+
let videoPlayState: TaskState["videoPlayState"] = videoIsMuted ? "paused-and-muted" : "paused";
|
|
53
|
+
|
|
54
|
+
if (videoIsPlaying) {
|
|
55
|
+
videoPlayState = videoIsMuted ? "playing-and-muted" : "playing";
|
|
56
|
+
}
|
|
57
|
+
if (videoIsAtTheEnd) {
|
|
58
|
+
videoPlayState = videoIsMuted ? "ended-and-muted" : "ended";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
audioIsPlaying,
|
|
63
|
+
videoPlayState,
|
|
64
|
+
isGifMode,
|
|
65
|
+
blockFormInput,
|
|
66
|
+
blockResponseButton,
|
|
67
|
+
blockAudio,
|
|
68
|
+
blockVideo,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
constructor(
|
|
73
|
+
private readonly mediaLayer: HTMLDivElement,
|
|
74
|
+
private readonly scale: ScaleService,
|
|
75
|
+
private readonly onError: (error: string) => void,
|
|
76
|
+
) {
|
|
77
|
+
this.hideVideo();
|
|
78
|
+
this.mediaLayer.appendChild(this.videoElement);
|
|
79
|
+
this.mediaLayer.appendChild(this.audioElement);
|
|
80
|
+
this.videoStyles = this.defaultVideoStyles;
|
|
81
|
+
DStyle.normalize(this.videoElement);
|
|
82
|
+
DStyle.applyStyles(this.videoElement, this.videoStyles, this.scale.scale);
|
|
83
|
+
|
|
84
|
+
this.videoElement.onended = () => {
|
|
85
|
+
const next = this.getNextTask();
|
|
86
|
+
if (next) {
|
|
87
|
+
this.execute(next);
|
|
88
|
+
} else {
|
|
89
|
+
this.runningTask = false;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
this.videoElement.onerror = (e) => {
|
|
93
|
+
if (this.videoElement.src !== "") {
|
|
94
|
+
onError("Error playing video: " + this.videoElement.src);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
this.audioElement.onended = () => {
|
|
99
|
+
const next = this.getNextTask();
|
|
100
|
+
if (next) {
|
|
101
|
+
this.execute(next);
|
|
102
|
+
} else {
|
|
103
|
+
this.runningTask = false;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
execute(task: Task): boolean {
|
|
109
|
+
// console.log("EXECUTE TASK" + task.kind);
|
|
110
|
+
const curr = this.runningTask;
|
|
111
|
+
// TODO Background-task should be handeled as its own kind or something.
|
|
112
|
+
let isBackgroundTask = false;
|
|
113
|
+
|
|
114
|
+
// Check if we should remove the current task.
|
|
115
|
+
if (curr && Task.shallRemoveCurrent(task) && Task.notEq(curr.task, task)) {
|
|
116
|
+
this.pauseAudio();
|
|
117
|
+
this.pauseVideo();
|
|
118
|
+
this.runningTask = false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!curr) {
|
|
122
|
+
this.runningTask = { startedAt: DTimestamp.now(), task: task };
|
|
123
|
+
} else if (Task.notEq(curr.task, task)) {
|
|
124
|
+
this.runningTask = { startedAt: DTimestamp.now(), task: task };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (task.priority === "replace-all" || task.priority === "replace-queue") {
|
|
128
|
+
this.taskList = [];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// STARTING PLAY VIDEO
|
|
132
|
+
if (task.kind === "play-video-task") {
|
|
133
|
+
this.showVideo();
|
|
134
|
+
// this.pauseAudio()
|
|
135
|
+
this.loadVideo(task.url);
|
|
136
|
+
if (task.loop) {
|
|
137
|
+
this.videoElement.loop = true;
|
|
138
|
+
isBackgroundTask = true;
|
|
139
|
+
} else {
|
|
140
|
+
this.videoElement.loop = false;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
this.videoElement.play();
|
|
145
|
+
} catch (e) {
|
|
146
|
+
console.error(e);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// STARTING PLAY AUDIO
|
|
151
|
+
if (task.kind === "play-audio-task") {
|
|
152
|
+
if (!this.videoElement.loop) {
|
|
153
|
+
this.pauseVideo();
|
|
154
|
+
}
|
|
155
|
+
if (task.url !== this.audioElement.src) {
|
|
156
|
+
this.audioElement.src = task.url;
|
|
157
|
+
}
|
|
158
|
+
this.audioElement.play();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (task.kind === "delay-task") {
|
|
162
|
+
if (typeof this.delayRef === "number") {
|
|
163
|
+
window.clearTimeout(this.delayRef);
|
|
164
|
+
}
|
|
165
|
+
this.delayRef = window.setTimeout(() => {
|
|
166
|
+
const next = this.getNextTask();
|
|
167
|
+
if (next) {
|
|
168
|
+
this.execute(next);
|
|
169
|
+
} else {
|
|
170
|
+
this.runningTask = false;
|
|
171
|
+
}
|
|
172
|
+
}, task.duration);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (isBackgroundTask) {
|
|
176
|
+
const startNextTask = this.getNextTask();
|
|
177
|
+
if (startNextTask) {
|
|
178
|
+
this.execute(startNextTask);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
setVideoStyles(styles: PStyle) {
|
|
186
|
+
this.videoStyles = { ...styles };
|
|
187
|
+
DStyle.applyStyles(this.videoElement, this.videoStyles, this.scale.scale);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
autoPlaySequence(tasks: Task[]) {
|
|
191
|
+
this.taskList = [...tasks];
|
|
192
|
+
const next = this.getNextTask();
|
|
193
|
+
if (next) {
|
|
194
|
+
this.execute(next);
|
|
195
|
+
if (next.kind === "play-video-task" && next.loop) {
|
|
196
|
+
this.videoElement.loop = true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
loadVideo(url: string) {
|
|
202
|
+
// console.log("LOAD VIDEO " + !!url + " ");
|
|
203
|
+
if (this.videoElement.src !== url) {
|
|
204
|
+
this.videoElement.src = url;
|
|
205
|
+
}
|
|
206
|
+
this.showVideo();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private playVideoElement() {
|
|
210
|
+
this.videoElement
|
|
211
|
+
.play()
|
|
212
|
+
.then(() => {})
|
|
213
|
+
.catch((e) => {
|
|
214
|
+
console.log(e);
|
|
215
|
+
this.onError("Error playing video.");
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private showVideo() {
|
|
220
|
+
this.videoElement.style.display = "block";
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private hideVideo() {
|
|
224
|
+
this.videoElement.style.display = "none";
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
pauseVideo() {
|
|
228
|
+
try {
|
|
229
|
+
if (!this.videoElement.loop) {
|
|
230
|
+
this.videoElement.pause();
|
|
231
|
+
}
|
|
232
|
+
} catch (e) {
|
|
233
|
+
console.log(e);
|
|
234
|
+
this.onError("Error pausing video.");
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
pauseAudio() {
|
|
239
|
+
try {
|
|
240
|
+
if (!this.audioElement.loop) {
|
|
241
|
+
this.audioElement.pause();
|
|
242
|
+
}
|
|
243
|
+
} catch (e) {
|
|
244
|
+
console.log(e);
|
|
245
|
+
this.onError("Error pausing audio.");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private getNextTask(): Task | false {
|
|
250
|
+
// console.log("Getting next task.");
|
|
251
|
+
// console.log(this.taskList);
|
|
252
|
+
const first = this.taskList.shift();
|
|
253
|
+
return first ?? false;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
muteVideo() {
|
|
257
|
+
this.videoElement.muted = true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
unMuteVideo() {
|
|
261
|
+
this.videoElement.muted = false;
|
|
262
|
+
}
|
|
263
|
+
}
|
package/src/page/task-state.ts
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { DTimestamp } from "../common/DTimestamp";
|
|
2
|
-
import diff = DTimestamp.diff;
|
|
3
|
-
|
|
4
|
-
export type TaskState = {
|
|
5
|
-
audioIsPlaying: boolean;
|
|
6
|
-
isGifMode: boolean;
|
|
7
|
-
videoPlayState:
|
|
8
|
-
| "playing"
|
|
9
|
-
| "paused"
|
|
10
|
-
| "ended"
|
|
11
|
-
| "playing-and-muted"
|
|
12
|
-
| "paused-and-muted"
|
|
13
|
-
| "ended-and-muted";
|
|
14
|
-
blockFormInput: boolean;
|
|
15
|
-
blockResponseButton: boolean;
|
|
16
|
-
blockAudio: boolean;
|
|
17
|
-
blockVideo: boolean;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type TaskStateDiff = Partial<TaskState> & { __diffed__: true };
|
|
21
|
-
export const TaskState = {
|
|
22
|
-
eq: (a: TaskState, b: TaskState) => {
|
|
23
|
-
return (
|
|
24
|
-
a.audioIsPlaying === b.audioIsPlaying &&
|
|
25
|
-
a.isGifMode === b.isGifMode &&
|
|
26
|
-
a.videoPlayState === b.videoPlayState &&
|
|
27
|
-
a.blockFormInput === b.blockFormInput &&
|
|
28
|
-
a.blockResponseButton === b.blockResponseButton &&
|
|
29
|
-
a.blockAudio === b.blockAudio &&
|
|
30
|
-
a.blockVideo === b.blockVideo
|
|
31
|
-
);
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
getDiff: (curr: TaskState, prev: TaskState | false): TaskStateDiff => {
|
|
35
|
-
if (prev === false) {
|
|
36
|
-
return curr as TaskStateDiff;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const diff = {} as TaskStateDiff;
|
|
40
|
-
|
|
41
|
-
if (curr.audioIsPlaying !== prev.audioIsPlaying) {
|
|
42
|
-
diff.audioIsPlaying = curr.audioIsPlaying;
|
|
43
|
-
}
|
|
44
|
-
if (curr.isGifMode !== prev.isGifMode) {
|
|
45
|
-
diff.isGifMode = curr.isGifMode;
|
|
46
|
-
}
|
|
47
|
-
if (curr.videoPlayState !== prev.videoPlayState) {
|
|
48
|
-
diff.videoPlayState = curr.videoPlayState;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (curr.blockFormInput !== prev.blockFormInput) {
|
|
52
|
-
diff.blockFormInput = curr.blockFormInput;
|
|
53
|
-
}
|
|
54
|
-
if (curr.blockResponseButton !== prev.blockResponseButton) {
|
|
55
|
-
diff.blockResponseButton = curr.blockResponseButton;
|
|
56
|
-
}
|
|
57
|
-
if (curr.blockAudio !== prev.blockAudio) {
|
|
58
|
-
diff.blockAudio = curr.blockAudio;
|
|
59
|
-
}
|
|
60
|
-
if (curr.blockVideo !== prev.blockVideo) {
|
|
61
|
-
diff.blockVideo = curr.blockVideo;
|
|
62
|
-
}
|
|
63
|
-
return diff;
|
|
64
|
-
},
|
|
65
|
-
};
|
|
1
|
+
import { DTimestamp } from "../common/DTimestamp";
|
|
2
|
+
import diff = DTimestamp.diff;
|
|
3
|
+
|
|
4
|
+
export type TaskState = {
|
|
5
|
+
audioIsPlaying: boolean;
|
|
6
|
+
isGifMode: boolean;
|
|
7
|
+
videoPlayState:
|
|
8
|
+
| "playing"
|
|
9
|
+
| "paused"
|
|
10
|
+
| "ended"
|
|
11
|
+
| "playing-and-muted"
|
|
12
|
+
| "paused-and-muted"
|
|
13
|
+
| "ended-and-muted";
|
|
14
|
+
blockFormInput: boolean;
|
|
15
|
+
blockResponseButton: boolean;
|
|
16
|
+
blockAudio: boolean;
|
|
17
|
+
blockVideo: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type TaskStateDiff = Partial<TaskState> & { __diffed__: true };
|
|
21
|
+
export const TaskState = {
|
|
22
|
+
eq: (a: TaskState, b: TaskState) => {
|
|
23
|
+
return (
|
|
24
|
+
a.audioIsPlaying === b.audioIsPlaying &&
|
|
25
|
+
a.isGifMode === b.isGifMode &&
|
|
26
|
+
a.videoPlayState === b.videoPlayState &&
|
|
27
|
+
a.blockFormInput === b.blockFormInput &&
|
|
28
|
+
a.blockResponseButton === b.blockResponseButton &&
|
|
29
|
+
a.blockAudio === b.blockAudio &&
|
|
30
|
+
a.blockVideo === b.blockVideo
|
|
31
|
+
);
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
getDiff: (curr: TaskState, prev: TaskState | false): TaskStateDiff => {
|
|
35
|
+
if (prev === false) {
|
|
36
|
+
return curr as TaskStateDiff;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const diff = {} as TaskStateDiff;
|
|
40
|
+
|
|
41
|
+
if (curr.audioIsPlaying !== prev.audioIsPlaying) {
|
|
42
|
+
diff.audioIsPlaying = curr.audioIsPlaying;
|
|
43
|
+
}
|
|
44
|
+
if (curr.isGifMode !== prev.isGifMode) {
|
|
45
|
+
diff.isGifMode = curr.isGifMode;
|
|
46
|
+
}
|
|
47
|
+
if (curr.videoPlayState !== prev.videoPlayState) {
|
|
48
|
+
diff.videoPlayState = curr.videoPlayState;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (curr.blockFormInput !== prev.blockFormInput) {
|
|
52
|
+
diff.blockFormInput = curr.blockFormInput;
|
|
53
|
+
}
|
|
54
|
+
if (curr.blockResponseButton !== prev.blockResponseButton) {
|
|
55
|
+
diff.blockResponseButton = curr.blockResponseButton;
|
|
56
|
+
}
|
|
57
|
+
if (curr.blockAudio !== prev.blockAudio) {
|
|
58
|
+
diff.blockAudio = curr.blockAudio;
|
|
59
|
+
}
|
|
60
|
+
if (curr.blockVideo !== prev.blockVideo) {
|
|
61
|
+
diff.blockVideo = curr.blockVideo;
|
|
62
|
+
}
|
|
63
|
+
return diff;
|
|
64
|
+
},
|
|
65
|
+
};
|