tiny-essentials 1.28.7 → 1.28.9
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/changelog/1/28/9.md +17 -0
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyDebugger.min.js +1 -0
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyMediaPlayer.min.js +1 -1
- package/dist/v1/TinyRadioFm.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/browserDetector.cjs +228 -0
- package/dist/v1/basics/browserDetector.d.mts +66 -0
- package/dist/v1/basics/browserDetector.mjs +207 -0
- package/dist/v1/basics/index.cjs +6 -0
- package/dist/v1/basics/index.d.mts +2 -1
- package/dist/v1/basics/index.mjs +2 -1
- package/dist/v1/build/TinyDebugger.cjs +7 -0
- package/dist/v1/build/TinyDebugger.d.mts +3 -0
- package/dist/v1/build/TinyDebugger.mjs +2 -0
- package/dist/v1/index.cjs +8 -0
- package/dist/v1/index.d.mts +3 -1
- package/dist/v1/index.mjs +4 -2
- package/dist/v1/libs/TinyDebugger.cjs +380 -0
- package/dist/v1/libs/TinyDebugger.d.mts +132 -0
- package/dist/v1/libs/TinyDebugger.mjs +351 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.cjs +39 -3
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.d.mts +10 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlAudio.mjs +35 -3
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.cjs +39 -3
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.d.mts +10 -0
- package/dist/v1/libs/TinyMediaPlayer/HtmlVideo.mjs +35 -3
- package/dist/v1/libs/TinyMediaPlayer/Mock.cjs +333 -0
- package/dist/v1/libs/TinyMediaPlayer/Mock.d.mts +154 -0
- package/dist/v1/libs/TinyMediaPlayer/Mock.mjs +296 -0
- package/dist/v1/libs/TinyMediaPlayer/SoundCloud.cjs +30 -0
- package/dist/v1/libs/TinyMediaPlayer/SoundCloud.d.mts +10 -0
- package/dist/v1/libs/TinyMediaPlayer/SoundCloud.mjs +26 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.cjs +39 -3
- package/dist/v1/libs/TinyMediaPlayer/Youtube.d.mts +10 -0
- package/dist/v1/libs/TinyMediaPlayer/Youtube.mjs +32 -3
- package/dist/v1/libs/TinyMediaPlayer/index.cjs +18 -0
- package/dist/v1/libs/TinyMediaPlayer/index.d.mts +10 -0
- package/dist/v1/libs/TinyMediaPlayer/index.mjs +16 -0
- package/dist/v1/libs/TinyMediaPlayer.cjs +156 -31
- package/dist/v1/libs/TinyMediaPlayer.d.mts +43 -7
- package/dist/v1/libs/TinyMediaPlayer.mjs +148 -31
- package/dist/v1/libs/TinyPromiseQueue.cjs +6 -4
- package/dist/v1/libs/TinyPromiseQueue.d.mts +8 -6
- package/dist/v1/libs/TinyPromiseQueue.mjs +6 -4
- package/dist/v1/libs/TinyRadioFm.cjs +271 -138
- package/dist/v1/libs/TinyRadioFm.d.mts +67 -3
- package/dist/v1/libs/TinyRadioFm.mjs +239 -123
- package/docs/v1/README.md +2 -0
- package/docs/v1/basics/browserDetector.md +135 -0
- package/docs/v1/libs/TinyDebugger.md +119 -0
- package/docs/v1/libs/TinyMediaPlayer.md +26 -22
- package/docs/v1/libs/TinyRadioFm.md +25 -3
- package/package.json +13 -1
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { createCheckDestroyed } from '../utils.mjs';
|
|
2
|
+
import { BaseMediaAdapter } from './index.mjs';
|
|
3
|
+
import { isValidObj } from '../../basics/objChecker.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* @typedef {import('../../basics/mediaContent.mjs').PictureDataType} PictureDataType
|
|
6
|
+
* @typedef {import('../../basics/mediaContent.mjs').MediaContent<PictureDataType>} MediaContent
|
|
7
|
+
* @typedef {import('./index.mjs').ContentData} ContentData
|
|
8
|
+
* @typedef {import('./index.mjs').ContentTimeData} ContentTimeData
|
|
9
|
+
*/
|
|
10
|
+
const checkDestroy = createCheckDestroyed('MockMediaAdapter');
|
|
11
|
+
const createdAt = new Date().toISOString();
|
|
12
|
+
/**
|
|
13
|
+
* MOCK VERSION of BaseMediaAdapter
|
|
14
|
+
*
|
|
15
|
+
* This file simulates the behavior of the Media Adapter for testing purposes.
|
|
16
|
+
*/
|
|
17
|
+
class MockMediaAdapter extends BaseMediaAdapter {
|
|
18
|
+
get id() {
|
|
19
|
+
return 'mock';
|
|
20
|
+
}
|
|
21
|
+
#isReady = true;
|
|
22
|
+
#currentVolume = 1.0;
|
|
23
|
+
/** @type {string|null} */
|
|
24
|
+
#currentContentId = null;
|
|
25
|
+
#destroyed = false;
|
|
26
|
+
#isPlaying = false;
|
|
27
|
+
#isPaused = false;
|
|
28
|
+
#isEnded = false;
|
|
29
|
+
#isMuted = false;
|
|
30
|
+
#currentTime = 0; // in milliseconds
|
|
31
|
+
#totalDuration = 60000; // 60 seconds in milliseconds
|
|
32
|
+
/**
|
|
33
|
+
* @returns {boolean}
|
|
34
|
+
*/
|
|
35
|
+
get destroyed() {
|
|
36
|
+
return this.#destroyed;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @returns {boolean}
|
|
40
|
+
*/
|
|
41
|
+
get isPlaying() {
|
|
42
|
+
checkDestroy(this.#destroyed);
|
|
43
|
+
return this.#isPlaying;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @returns {string|null}
|
|
47
|
+
*/
|
|
48
|
+
get currentContentId() {
|
|
49
|
+
checkDestroy(this.#destroyed);
|
|
50
|
+
return this.#currentContentId;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @returns {number}
|
|
54
|
+
*/
|
|
55
|
+
get volume() {
|
|
56
|
+
checkDestroy(this.#destroyed);
|
|
57
|
+
return this.#currentVolume;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @param {number} value - O volume de 0.0 a 1.0.
|
|
61
|
+
* @throws {RangeError} Se o valor estiver fora do intervalo.
|
|
62
|
+
*/
|
|
63
|
+
set volume(value) {
|
|
64
|
+
checkDestroy(this.#destroyed);
|
|
65
|
+
if (typeof value !== 'number' || value < 0 || value > 1) {
|
|
66
|
+
throw new RangeError('Volume must be a number between 0.0 and 1.0.');
|
|
67
|
+
}
|
|
68
|
+
this.#currentVolume = value;
|
|
69
|
+
this.emit('volumeChange', value);
|
|
70
|
+
}
|
|
71
|
+
constructor() {
|
|
72
|
+
super();
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Checks whether the media adapter is fully initialized and ready.
|
|
76
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
77
|
+
*/
|
|
78
|
+
isReady() {
|
|
79
|
+
checkDestroy(this.#destroyed);
|
|
80
|
+
return this.#isReady;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Checks whether the media adapter is paused.
|
|
84
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
85
|
+
*/
|
|
86
|
+
isPaused() {
|
|
87
|
+
checkDestroy(this.#destroyed);
|
|
88
|
+
return this.#isPaused;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Checks whether the media adapter is ended.
|
|
92
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
93
|
+
*/
|
|
94
|
+
isEnded() {
|
|
95
|
+
checkDestroy(this.#destroyed);
|
|
96
|
+
return this.#isEnded;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Asynchronously waits until the content media adapter is fully initialized and ready.
|
|
100
|
+
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|
|
101
|
+
*/
|
|
102
|
+
async waitIsReady() {
|
|
103
|
+
checkDestroy(this.#destroyed);
|
|
104
|
+
return Promise.resolve();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Retrieves a consolidated object containing all time-related metrics for the current media content.
|
|
108
|
+
* @returns {ContentTimeData} An object containing total, current, remaining time, and playback percentage.
|
|
109
|
+
*/
|
|
110
|
+
getTimeData() {
|
|
111
|
+
checkDestroy(this.#destroyed);
|
|
112
|
+
const total = this.getTotalDuration();
|
|
113
|
+
const current = this.getCurrentTime();
|
|
114
|
+
const remaining = total > 0 ? total - current : 0;
|
|
115
|
+
const playbackPercentage = total > 0 ? (current / total) * 100 : 0;
|
|
116
|
+
return { total, current, remaining, playbackPercentage };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Determines if this adapter can play the provided content.
|
|
120
|
+
* @param {MediaContent} content - The media content to evaluate.
|
|
121
|
+
* @returns {boolean} True if the adapter can handle the content, false otherwise.
|
|
122
|
+
*/
|
|
123
|
+
static canHandle(content) {
|
|
124
|
+
return content && typeof content.url === 'string';
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Determines if this adapter can play the provided content.
|
|
128
|
+
* @param {MediaContent} content - The media content to evaluate.
|
|
129
|
+
* @returns {boolean} True if the adapter can handle the content, false otherwise.
|
|
130
|
+
*/
|
|
131
|
+
canHandle(content) {
|
|
132
|
+
checkDestroy(this.#destroyed);
|
|
133
|
+
return MockMediaAdapter.canHandle(content);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Starts or resumes playback of the provided content.
|
|
137
|
+
* @param {MediaContent} content - The media content to play.
|
|
138
|
+
* @returns {Promise<void>}
|
|
139
|
+
*/
|
|
140
|
+
async play(content) {
|
|
141
|
+
checkDestroy(this.#destroyed);
|
|
142
|
+
if (!isValidObj(content)) {
|
|
143
|
+
throw new TypeError('Invalid media content provided to play().');
|
|
144
|
+
}
|
|
145
|
+
this.#currentContentId = typeof content.url === 'string' ? content.url : 'mock';
|
|
146
|
+
this.#isPaused = false;
|
|
147
|
+
this.#isEnded = false;
|
|
148
|
+
this.#isPlaying = true;
|
|
149
|
+
// Simulate a small delay for loading
|
|
150
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
151
|
+
this.emit('play');
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Pauses the current playback.
|
|
155
|
+
* @returns {Promise<void>}
|
|
156
|
+
*/
|
|
157
|
+
async pause() {
|
|
158
|
+
checkDestroy(this.#destroyed);
|
|
159
|
+
this.#isPaused = true;
|
|
160
|
+
this.#isEnded = false;
|
|
161
|
+
this.#isPlaying = false;
|
|
162
|
+
this.emit('pause');
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Stops the playback completely and resets the internal platform state.
|
|
166
|
+
* @returns {Promise<void>}
|
|
167
|
+
*/
|
|
168
|
+
async stop() {
|
|
169
|
+
checkDestroy(this.#destroyed);
|
|
170
|
+
this.#isPaused = false;
|
|
171
|
+
this.#isEnded = true;
|
|
172
|
+
this.#isPlaying = false;
|
|
173
|
+
this.#currentTime = 0;
|
|
174
|
+
this.emit('ended');
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Seeks to a specific time in the media timeline.
|
|
178
|
+
* @param {number} timeMs - The target time in milliseconds.
|
|
179
|
+
* @returns {Promise<void>}
|
|
180
|
+
*/
|
|
181
|
+
async seek(timeMs) {
|
|
182
|
+
checkDestroy(this.#destroyed);
|
|
183
|
+
if (typeof timeMs !== 'number') {
|
|
184
|
+
throw new TypeError('Seek time must be a number.');
|
|
185
|
+
}
|
|
186
|
+
this.#currentTime = timeMs;
|
|
187
|
+
this.emit('seek', this.#currentTime);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Checks whether the player is currently muted.
|
|
191
|
+
* @returns {boolean|null} True if muted, false otherwise.
|
|
192
|
+
*/
|
|
193
|
+
isMuted() {
|
|
194
|
+
checkDestroy(this.#destroyed);
|
|
195
|
+
return this.#isMuted;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Mutes the current playback.
|
|
199
|
+
* @returns {Promise<void>}
|
|
200
|
+
*/
|
|
201
|
+
async mute() {
|
|
202
|
+
checkDestroy(this.#destroyed);
|
|
203
|
+
this.#isMuted = true;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Unmutes the current playback.
|
|
207
|
+
* @returns {Promise<void>}
|
|
208
|
+
*/
|
|
209
|
+
async unMute() {
|
|
210
|
+
checkDestroy(this.#destroyed);
|
|
211
|
+
this.#isMuted = false;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Retrieves the current playback time from the underlying API.
|
|
215
|
+
* @returns {number} The current time in milliseconds.
|
|
216
|
+
*/
|
|
217
|
+
getCurrentTime() {
|
|
218
|
+
checkDestroy(this.#destroyed);
|
|
219
|
+
return this.#currentTime;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Gets the total duration of the content.
|
|
223
|
+
* @returns {number} The total duration in milliseconds.
|
|
224
|
+
*/
|
|
225
|
+
getTotalDuration() {
|
|
226
|
+
checkDestroy(this.#destroyed);
|
|
227
|
+
return this.#totalDuration;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Gets the remaining time until the content ends.
|
|
231
|
+
* @returns {number} The remaining time in milliseconds.
|
|
232
|
+
*/
|
|
233
|
+
getRemainingTime() {
|
|
234
|
+
checkDestroy(this.#destroyed);
|
|
235
|
+
const total = this.getTotalDuration();
|
|
236
|
+
const current = this.getCurrentTime();
|
|
237
|
+
return total > 0 ? total - current : 0;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Gets the percentage of the content that has been played.
|
|
241
|
+
* @returns {number} The percentage from 0 to 100.
|
|
242
|
+
*/
|
|
243
|
+
getPlaybackPercentage() {
|
|
244
|
+
checkDestroy(this.#destroyed);
|
|
245
|
+
const total = this.getTotalDuration();
|
|
246
|
+
const current = this.getCurrentTime();
|
|
247
|
+
return total > 0 ? (current / total) * 100 : 0;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Sets the playback volume for the underlying API.
|
|
251
|
+
* @param {number} volume - The volume level from 0.0 to 1.0.
|
|
252
|
+
* @returns {void}
|
|
253
|
+
*/
|
|
254
|
+
setVolume(volume) {
|
|
255
|
+
checkDestroy(this.#destroyed);
|
|
256
|
+
this.volume = volume;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Gets the playback volume for the underlying API.
|
|
260
|
+
* @returns {number} - The volume level from 0.0 to 1.0.
|
|
261
|
+
*/
|
|
262
|
+
getVolume() {
|
|
263
|
+
checkDestroy(this.#destroyed);
|
|
264
|
+
return this.volume;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Retrieves the metadata of the currently loaded content, returning a structured
|
|
268
|
+
* object containing details such as the content ID, title, author, and duration.
|
|
269
|
+
* @returns {Promise<ContentData>}
|
|
270
|
+
*/
|
|
271
|
+
async getContentData() {
|
|
272
|
+
checkDestroy(this.#destroyed);
|
|
273
|
+
return {
|
|
274
|
+
id: this.#currentContentId ?? 'mock',
|
|
275
|
+
createdAt,
|
|
276
|
+
artistId: 'mock-artist',
|
|
277
|
+
artistName: 'Mock Artist',
|
|
278
|
+
description: 'Mock description',
|
|
279
|
+
title: 'Mock Title',
|
|
280
|
+
duration: this.#totalDuration,
|
|
281
|
+
avatar: '',
|
|
282
|
+
url: '',
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Cleans up the instance.
|
|
287
|
+
* @returns {void}
|
|
288
|
+
*/
|
|
289
|
+
destroy() {
|
|
290
|
+
if (this.#destroyed)
|
|
291
|
+
return;
|
|
292
|
+
this.#destroyed = true;
|
|
293
|
+
super.destroy();
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
export { MockMediaAdapter };
|
|
@@ -290,6 +290,12 @@ class SoundCloudMediaAdapter extends index.BaseMediaAdapter {
|
|
|
290
290
|
/** @type {number} */
|
|
291
291
|
#preMuteVolume = 1.0;
|
|
292
292
|
|
|
293
|
+
/** @type {boolean} */
|
|
294
|
+
#isPaused = false;
|
|
295
|
+
|
|
296
|
+
/** @type {boolean} */
|
|
297
|
+
#isEnded = false;
|
|
298
|
+
|
|
293
299
|
/**
|
|
294
300
|
* Gets whether the adapter has been destroyed.
|
|
295
301
|
* @returns {boolean}
|
|
@@ -369,6 +375,24 @@ class SoundCloudMediaAdapter extends index.BaseMediaAdapter {
|
|
|
369
375
|
return this.#isReady;
|
|
370
376
|
}
|
|
371
377
|
|
|
378
|
+
/**
|
|
379
|
+
* Checks whether the media adapter is paused.
|
|
380
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
381
|
+
*/
|
|
382
|
+
isPaused() {
|
|
383
|
+
checkDestroy(this.#destroyed);
|
|
384
|
+
return this.#isPaused;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Checks whether the media adapter is ended.
|
|
389
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
390
|
+
*/
|
|
391
|
+
isEnded() {
|
|
392
|
+
checkDestroy(this.#destroyed);
|
|
393
|
+
return this.#isEnded;
|
|
394
|
+
}
|
|
395
|
+
|
|
372
396
|
/**
|
|
373
397
|
* Asynchronously waits until the SoundCloud media adapter is fully initialized and ready.
|
|
374
398
|
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|
|
@@ -538,16 +562,22 @@ class SoundCloudMediaAdapter extends index.BaseMediaAdapter {
|
|
|
538
562
|
|
|
539
563
|
this.#widget.bind(SoundCloudMediaAdapter.Events.PLAY, (/** @type {any} */ event) => {
|
|
540
564
|
eventSync(event);
|
|
565
|
+
this.#isPaused = false;
|
|
566
|
+
this.#isEnded = false;
|
|
541
567
|
this.#masterEmitter?.emit('play');
|
|
542
568
|
});
|
|
543
569
|
|
|
544
570
|
this.#widget.bind(SoundCloudMediaAdapter.Events.PAUSE, (/** @type {any} */ event) => {
|
|
545
571
|
eventSync(event);
|
|
572
|
+
this.#isPaused = true;
|
|
573
|
+
this.#isEnded = false;
|
|
546
574
|
this.#masterEmitter?.emit('pause');
|
|
547
575
|
});
|
|
548
576
|
|
|
549
577
|
this.#widget.bind(SoundCloudMediaAdapter.Events.FINISH, (/** @type {any} */ event) => {
|
|
550
578
|
eventSync(event);
|
|
579
|
+
this.#isPaused = false;
|
|
580
|
+
this.#isEnded = true;
|
|
551
581
|
this.#masterEmitter?.emit('ended');
|
|
552
582
|
});
|
|
553
583
|
|
|
@@ -187,6 +187,16 @@ declare class SoundCloudMediaAdapter extends BaseMediaAdapter {
|
|
|
187
187
|
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
188
188
|
*/
|
|
189
189
|
isReady(): boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Checks whether the media adapter is paused.
|
|
192
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
193
|
+
*/
|
|
194
|
+
isPaused(): boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Checks whether the media adapter is ended.
|
|
197
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
198
|
+
*/
|
|
199
|
+
isEnded(): boolean;
|
|
190
200
|
/**
|
|
191
201
|
* Asynchronously waits until the SoundCloud media adapter is fully initialized and ready.
|
|
192
202
|
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|
|
@@ -253,6 +253,10 @@ class SoundCloudMediaAdapter extends BaseMediaAdapter {
|
|
|
253
253
|
#isMuted = false;
|
|
254
254
|
/** @type {number} */
|
|
255
255
|
#preMuteVolume = 1.0;
|
|
256
|
+
/** @type {boolean} */
|
|
257
|
+
#isPaused = false;
|
|
258
|
+
/** @type {boolean} */
|
|
259
|
+
#isEnded = false;
|
|
256
260
|
/**
|
|
257
261
|
* Gets whether the adapter has been destroyed.
|
|
258
262
|
* @returns {boolean}
|
|
@@ -318,6 +322,22 @@ class SoundCloudMediaAdapter extends BaseMediaAdapter {
|
|
|
318
322
|
checkDestroy(this.#destroyed);
|
|
319
323
|
return this.#isReady;
|
|
320
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Checks whether the media adapter is paused.
|
|
327
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
328
|
+
*/
|
|
329
|
+
isPaused() {
|
|
330
|
+
checkDestroy(this.#destroyed);
|
|
331
|
+
return this.#isPaused;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Checks whether the media adapter is ended.
|
|
335
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
336
|
+
*/
|
|
337
|
+
isEnded() {
|
|
338
|
+
checkDestroy(this.#destroyed);
|
|
339
|
+
return this.#isEnded;
|
|
340
|
+
}
|
|
321
341
|
/**
|
|
322
342
|
* Asynchronously waits until the SoundCloud media adapter is fully initialized and ready.
|
|
323
343
|
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|
|
@@ -474,14 +494,20 @@ class SoundCloudMediaAdapter extends BaseMediaAdapter {
|
|
|
474
494
|
});
|
|
475
495
|
this.#widget.bind(SoundCloudMediaAdapter.Events.PLAY, (/** @type {any} */ event) => {
|
|
476
496
|
eventSync(event, 'PLAY');
|
|
497
|
+
this.#isPaused = false;
|
|
498
|
+
this.#isEnded = false;
|
|
477
499
|
this.#masterEmitter?.emit('play');
|
|
478
500
|
});
|
|
479
501
|
this.#widget.bind(SoundCloudMediaAdapter.Events.PAUSE, (/** @type {any} */ event) => {
|
|
480
502
|
eventSync(event, 'PAUSE');
|
|
503
|
+
this.#isPaused = true;
|
|
504
|
+
this.#isEnded = false;
|
|
481
505
|
this.#masterEmitter?.emit('pause');
|
|
482
506
|
});
|
|
483
507
|
this.#widget.bind(SoundCloudMediaAdapter.Events.FINISH, (/** @type {any} */ event) => {
|
|
484
508
|
eventSync(event, 'FINISH');
|
|
509
|
+
this.#isPaused = false;
|
|
510
|
+
this.#isEnded = true;
|
|
485
511
|
this.#masterEmitter?.emit('ended');
|
|
486
512
|
});
|
|
487
513
|
this.#widget.bind(SoundCloudMediaAdapter.Events.LOAD_PROGRESS, (/** @type {any} */ event) => {
|
|
@@ -300,6 +300,12 @@ class YoutubeMediaAdapter extends index.BaseMediaAdapter {
|
|
|
300
300
|
/** @type {number} */
|
|
301
301
|
#pollingTimeUpdateValue = 250;
|
|
302
302
|
|
|
303
|
+
/** @type {boolean} */
|
|
304
|
+
#isPaused = false;
|
|
305
|
+
|
|
306
|
+
/** @type {boolean} */
|
|
307
|
+
#isEnded = false;
|
|
308
|
+
|
|
303
309
|
get pollingTimeUpdateValue() {
|
|
304
310
|
checkDestroy(this.#destroyed);
|
|
305
311
|
return this.#pollingTimeUpdateValue;
|
|
@@ -388,6 +394,24 @@ class YoutubeMediaAdapter extends index.BaseMediaAdapter {
|
|
|
388
394
|
return this.#isReady;
|
|
389
395
|
}
|
|
390
396
|
|
|
397
|
+
/**
|
|
398
|
+
* Checks whether the media adapter is paused.
|
|
399
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
400
|
+
*/
|
|
401
|
+
isPaused() {
|
|
402
|
+
checkDestroy(this.#destroyed);
|
|
403
|
+
return this.#isPaused;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Checks whether the media adapter is ended.
|
|
408
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
409
|
+
*/
|
|
410
|
+
isEnded() {
|
|
411
|
+
checkDestroy(this.#destroyed);
|
|
412
|
+
return this.#isEnded;
|
|
413
|
+
}
|
|
414
|
+
|
|
391
415
|
/**
|
|
392
416
|
* Asynchronously waits until the YouTube media adapter is fully initialized and ready.
|
|
393
417
|
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|
|
@@ -507,9 +531,21 @@ class YoutubeMediaAdapter extends index.BaseMediaAdapter {
|
|
|
507
531
|
if (ytEvent === 'onStateChange') {
|
|
508
532
|
const state = args[0];
|
|
509
533
|
if (objChecker.isValidObj(state)) {
|
|
510
|
-
if (state.data === YoutubeMediaAdapter.PlayerState.PLAYING)
|
|
511
|
-
|
|
512
|
-
|
|
534
|
+
if (state.data === YoutubeMediaAdapter.PlayerState.PLAYING) {
|
|
535
|
+
this.#isPaused = false;
|
|
536
|
+
this.#isEnded = false;
|
|
537
|
+
masterEmitter.emit('play');
|
|
538
|
+
}
|
|
539
|
+
if (state.data === YoutubeMediaAdapter.PlayerState.PAUSED) {
|
|
540
|
+
this.#isPaused = true;
|
|
541
|
+
this.#isEnded = false;
|
|
542
|
+
masterEmitter.emit('pause');
|
|
543
|
+
}
|
|
544
|
+
if (state.data === YoutubeMediaAdapter.PlayerState.ENDED) {
|
|
545
|
+
this.#isPaused = false;
|
|
546
|
+
this.#isEnded = true;
|
|
547
|
+
masterEmitter.emit('ended');
|
|
548
|
+
}
|
|
513
549
|
}
|
|
514
550
|
}
|
|
515
551
|
return result;
|
|
@@ -241,6 +241,16 @@ declare class YoutubeMediaAdapter extends BaseMediaAdapter {
|
|
|
241
241
|
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
242
242
|
*/
|
|
243
243
|
isReady(): boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Checks whether the media adapter is paused.
|
|
246
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
247
|
+
*/
|
|
248
|
+
isPaused(): boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Checks whether the media adapter is ended.
|
|
251
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
252
|
+
*/
|
|
253
|
+
isEnded(): boolean;
|
|
244
254
|
/**
|
|
245
255
|
* Asynchronously waits until the YouTube media adapter is fully initialized and ready.
|
|
246
256
|
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|
|
@@ -266,6 +266,10 @@ class YoutubeMediaAdapter extends BaseMediaAdapter {
|
|
|
266
266
|
#timeUpdateInterval = null;
|
|
267
267
|
/** @type {number} */
|
|
268
268
|
#pollingTimeUpdateValue = 250;
|
|
269
|
+
/** @type {boolean} */
|
|
270
|
+
#isPaused = false;
|
|
271
|
+
/** @type {boolean} */
|
|
272
|
+
#isEnded = false;
|
|
269
273
|
get pollingTimeUpdateValue() {
|
|
270
274
|
checkDestroy(this.#destroyed);
|
|
271
275
|
return this.#pollingTimeUpdateValue;
|
|
@@ -341,6 +345,22 @@ class YoutubeMediaAdapter extends BaseMediaAdapter {
|
|
|
341
345
|
checkDestroy(this.#destroyed);
|
|
342
346
|
return this.#isReady;
|
|
343
347
|
}
|
|
348
|
+
/**
|
|
349
|
+
* Checks whether the media adapter is paused.
|
|
350
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
351
|
+
*/
|
|
352
|
+
isPaused() {
|
|
353
|
+
checkDestroy(this.#destroyed);
|
|
354
|
+
return this.#isPaused;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Checks whether the media adapter is ended.
|
|
358
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
359
|
+
*/
|
|
360
|
+
isEnded() {
|
|
361
|
+
checkDestroy(this.#destroyed);
|
|
362
|
+
return this.#isEnded;
|
|
363
|
+
}
|
|
344
364
|
/**
|
|
345
365
|
* Asynchronously waits until the YouTube media adapter is fully initialized and ready.
|
|
346
366
|
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|
|
@@ -447,12 +467,21 @@ class YoutubeMediaAdapter extends BaseMediaAdapter {
|
|
|
447
467
|
if (ytEvent === 'onStateChange') {
|
|
448
468
|
const state = args[0];
|
|
449
469
|
if (isValidObj(state)) {
|
|
450
|
-
if (state.data === YoutubeMediaAdapter.PlayerState.PLAYING)
|
|
470
|
+
if (state.data === YoutubeMediaAdapter.PlayerState.PLAYING) {
|
|
471
|
+
this.#isPaused = false;
|
|
472
|
+
this.#isEnded = false;
|
|
451
473
|
masterEmitter.emit('play');
|
|
452
|
-
|
|
474
|
+
}
|
|
475
|
+
if (state.data === YoutubeMediaAdapter.PlayerState.PAUSED) {
|
|
476
|
+
this.#isPaused = true;
|
|
477
|
+
this.#isEnded = false;
|
|
453
478
|
masterEmitter.emit('pause');
|
|
454
|
-
|
|
479
|
+
}
|
|
480
|
+
if (state.data === YoutubeMediaAdapter.PlayerState.ENDED) {
|
|
481
|
+
this.#isPaused = false;
|
|
482
|
+
this.#isEnded = true;
|
|
455
483
|
masterEmitter.emit('ended');
|
|
484
|
+
}
|
|
456
485
|
}
|
|
457
486
|
}
|
|
458
487
|
return result;
|
|
@@ -70,6 +70,24 @@ class BaseMediaAdapter extends events.EventEmitter {
|
|
|
70
70
|
throw new Error('Method "isReady" must be implemented by the subclass.');
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Checks whether the media adapter is paused.
|
|
75
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
76
|
+
*/
|
|
77
|
+
isPaused() {
|
|
78
|
+
checkDestroy(this.#destroyed);
|
|
79
|
+
throw new Error('Method "isPaused" must be implemented by the subclass.');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Checks whether the media adapter is ended.
|
|
84
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
85
|
+
*/
|
|
86
|
+
isEnded() {
|
|
87
|
+
checkDestroy(this.#destroyed);
|
|
88
|
+
throw new Error('Method "isEnded" must be implemented by the subclass.');
|
|
89
|
+
}
|
|
90
|
+
|
|
73
91
|
/**
|
|
74
92
|
* Asynchronously waits until the content media adapter is fully initialized and ready.
|
|
75
93
|
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|
|
@@ -77,6 +77,16 @@ declare class BaseMediaAdapter extends EventEmitter {
|
|
|
77
77
|
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
78
78
|
*/
|
|
79
79
|
isReady(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Checks whether the media adapter is paused.
|
|
82
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
83
|
+
*/
|
|
84
|
+
isPaused(): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Checks whether the media adapter is ended.
|
|
87
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
88
|
+
*/
|
|
89
|
+
isEnded(): boolean;
|
|
80
90
|
/**
|
|
81
91
|
* Asynchronously waits until the content media adapter is fully initialized and ready.
|
|
82
92
|
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|
|
@@ -58,6 +58,22 @@ class BaseMediaAdapter extends EventEmitter {
|
|
|
58
58
|
checkDestroy(this.#destroyed);
|
|
59
59
|
throw new Error('Method "isReady" must be implemented by the subclass.');
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Checks whether the media adapter is paused.
|
|
63
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
64
|
+
*/
|
|
65
|
+
isPaused() {
|
|
66
|
+
checkDestroy(this.#destroyed);
|
|
67
|
+
throw new Error('Method "isPaused" must be implemented by the subclass.');
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Checks whether the media adapter is ended.
|
|
71
|
+
* @returns {boolean} True if the adapter is ready, false otherwise.
|
|
72
|
+
*/
|
|
73
|
+
isEnded() {
|
|
74
|
+
checkDestroy(this.#destroyed);
|
|
75
|
+
throw new Error('Method "isEnded" must be implemented by the subclass.');
|
|
76
|
+
}
|
|
61
77
|
/**
|
|
62
78
|
* Asynchronously waits until the content media adapter is fully initialized and ready.
|
|
63
79
|
* @returns {Promise<void>} A promise that resolves once the adapter is ready.
|