@tidal-music/player-web-components 0.2.1 → 0.2.2

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.
Files changed (31) hide show
  1. package/dist/active-device-changed-DKzZonX1--oMxdziu.js +7 -0
  2. package/dist/active-device-mode-changed-Dj16yzUX-BbRjSd-6.js +7 -0
  3. package/dist/audio-context-store-Ccv6WKna-C-yxIXdl.js +36 -0
  4. package/dist/basePlayer-CxowZx76-CfK9Qp4M.js +380 -0
  5. package/dist/browserPlayer-CJUIZMXc-Cwz_EqKS.js +170 -0
  6. package/dist/generate-guid-DMif1b6n-WXvDGKGF.js +1716 -0
  7. package/dist/index.js +363 -10
  8. package/dist/load-D2Tka_Qx-BNIMgt7e.js +29305 -0
  9. package/dist/media-element-error-circuit-breaker-fMDQ6k4B-B9oZKZUK.js +22 -0
  10. package/dist/nativePlayer-Bk8Y048r-S6bg9D6D.js +232 -0
  11. package/dist/output-devices-kF_iC6GM-CnAUEjc9.js +156 -0
  12. package/dist/pushkin-BJAKy5lP-BDJR20nC.js +117 -0
  13. package/dist/pushkin-CVLqA7Zj-DJu6_unL.js +2 -0
  14. package/dist/shakaPlayer-BvtoIIdC-CizBy6it.js +1448 -0
  15. package/dist/src/helpers.d.ts +18 -0
  16. package/dist/src/index.d.ts +7 -0
  17. package/dist/src/tidal-current-time.d.ts +9 -0
  18. package/dist/src/tidal-duration-time.d.ts +9 -0
  19. package/dist/src/tidal-play-trigger.d.ts +2 -0
  20. package/dist/src/tidal-progress-bar.d.ts +2 -0
  21. package/dist/src/tidal-video-view.d.ts +2 -0
  22. package/dist/state-B888KJag-C7pa4Xs7.js +210 -0
  23. package/package.json +15 -13
  24. package/dist/_commonjsHelpers-DaMA6jEr-DtILRGNx.js +0 -8
  25. package/dist/basePlayer-Rqi9yRuo-4eKn-Akv.js +0 -528
  26. package/dist/browserPlayer-CXURpXdL-DjOb2ySS.js +0 -259
  27. package/dist/index-DHnVYeec.js +0 -3391
  28. package/dist/index.d.ts +0 -24
  29. package/dist/nativePlayer-b92CavhC-CABrQPGS.js +0 -323
  30. package/dist/output-devices-CUurcKto-C_F_9nLk.js +0 -224
  31. package/dist/shakaPlayer-D0NCOzx8-Dd1YFBoR.js +0 -24403
@@ -1,528 +0,0 @@
1
- import { f as g, b as o, l as d, y as n, P as i, k as m, e as P, v as h, D as I, q as S, j as y, w as T, g as v, h as f, L as c, d as b, C as k } from "./index-DHnVYeec.js";
2
- function R(r, e) {
3
- return new CustomEvent(
4
- "media-product-transition",
5
- {
6
- detail: {
7
- mediaProduct: r,
8
- playbackContext: e
9
- }
10
- }
11
- );
12
- }
13
- const _ = ({
14
- assetPosition: r,
15
- duration: e,
16
- playbackInfo: t,
17
- streamInfo: a
18
- }) => ({
19
- actualAssetPresentation: t.assetPresentation,
20
- actualAudioMode: "audioMode" in t ? t.audioMode : null,
21
- actualAudioQuality: "audioQuality" in t ? t.audioQuality : null,
22
- actualDuration: e,
23
- actualProductId: String(
24
- "videoId" in t ? t.videoId : t.trackId
25
- ),
26
- actualStreamType: "streamType" in t ? t.streamType : null,
27
- actualVideoQuality: "videoQuality" in t ? t.videoQuality : null,
28
- assetPosition: r,
29
- bitDepth: a.bitDepth ?? null,
30
- codec: a.codec ?? null,
31
- playbackSessionId: a.streamingSessionId,
32
- sampleRate: a.sampleRate ?? null
33
- });
34
- function A(r, e) {
35
- return new CustomEvent("ended", {
36
- detail: {
37
- mediaProduct: e,
38
- reason: r
39
- }
40
- });
41
- }
42
- function L(r) {
43
- return new CustomEvent("playback-state-change", {
44
- detail: {
45
- state: r
46
- }
47
- });
48
- }
49
- function E() {
50
- return new CustomEvent("preload-request");
51
- }
52
- function p(r) {
53
- return Math.min(Math.pow(10, (4 + r) / 20), 1 / 1);
54
- }
55
- function M(r) {
56
- switch (r) {
57
- case "completed":
58
- return "COMPLETE";
59
- case "error":
60
- return "ERROR";
61
- case "skip":
62
- default:
63
- return "OTHER";
64
- }
65
- }
66
- let C = class {
67
- #e;
68
- #s;
69
- #t;
70
- #i = void 0;
71
- #r;
72
- #a = "IDLE";
73
- #n;
74
- #o;
75
- name;
76
- constructor() {
77
- g.addEventListener("desiredVolumeLevel", () => {
78
- this.isActivePlayer && this.updateVolumeLevel();
79
- });
80
- }
81
- // Implements
82
- #d() {
83
- this.duration && Math.abs(this.#s - this.duration) <= 30 && // A false check, rather than undefined, ensures a media product transition hs been made.
84
- this.#i === !1 && (this.#i = !0, o.dispatchEvent(E()));
85
- }
86
- /**
87
- * This method should be call whenever a playback ends, for **whatever** reason.
88
- *
89
- * ended, completed, skip, reset etc
90
- */
91
- #c({
92
- endAssetPosition: e,
93
- endReason: t,
94
- streamingSessionId: a
95
- }) {
96
- this.debugLog("mediaProductEnded"), d.preloadedStreamingSessionId && performance.mark(
97
- "streaming_metrics:playback_statistics:idealStartTimestamp",
98
- {
99
- detail: d.preloadedStreamingSessionId,
100
- startTime: n.now()
101
- }
102
- );
103
- const s = i.getMediaProductTransition(a);
104
- s && o.dispatchEvent(
105
- A(t, s.mediaProduct)
106
- ), this.eventTrackingStreamingEnded(a, {
107
- endAssetPosition: e,
108
- endReason: t
109
- }), i.deleteSession(a), this.currentStreamingSessionId === a && (this.currentStreamingSessionId = void 0), this.updateVolumeLevelForNextProduct();
110
- }
111
- adjustedVolume(e) {
112
- const t = m("desiredVolumeLevel"), a = m("loudnessNormalizationMode");
113
- let s = t;
114
- return a === "ALBUM" && e.albumReplayGain && (s *= p(e.albumReplayGain)), a === "TRACK" && e.trackReplayGain && (s *= p(e.trackReplayGain)), this.debugLog(
115
- "adjustedVolume",
116
- `Volume adjusted from ${t} to ${s}`
117
- ), parseFloat(s.toFixed(2));
118
- }
119
- // Implements
120
- attachPlaybackEngineEndedHandler() {
121
- this.#t || (this.#t = this.playbackEngineEndedHandler.bind(this), o.addEventListener(
122
- "ended",
123
- this.#t
124
- ));
125
- }
126
- /**
127
- * Cleans up stored stream info and media product transitions
128
- * for preloadedStreamingSessionId if it does not match
129
- * currentStreamingSessionId.
130
- */
131
- cleanUpStoredPreloadInfo() {
132
- this.preloadedStreamingSessionId && this.preloadedStreamingSessionId !== this.currentStreamingSessionId && (i.deleteSession(this.preloadedStreamingSessionId), this.preloadedStreamingSessionId = void 0);
133
- }
134
- // Implements
135
- debugLog(...e) {
136
- document.location.href.includes("localhost") && document.location.hash.includes("debug") && console.debug(
137
- `[%cPlayerSDK${this.name ? `%c${d.activePlayer?.name === this.name ? "⚯" : "⚮"}%c` + this.name : ""}${this.#e ? "%c::%c" + this.#e?.split("-").pop() : ""}%c]`,
138
- "color:#00d6ff",
139
- ...this.name ? [
140
- "color:inherit",
141
- "color:#b7fa34"
142
- // green foreground
143
- ] : [],
144
- ...this.#e ? [
145
- "color:inherit",
146
- "color:#d947ff"
147
- // purple foreground
148
- ] : [],
149
- "color:inherit",
150
- ...e
151
- );
152
- }
153
- detachPlaybackEngineEndedHandler() {
154
- this.#t && (o.removeEventListener(
155
- "ended",
156
- this.#t
157
- ), this.#t = void 0);
158
- }
159
- /**
160
- * Commits play_log playbackSession and streaming_metrics playbackStatistics.
161
- *
162
- * @param streamingSessionId
163
- */
164
- eventTrackingStreamingEnded(e, {
165
- endAssetPosition: t,
166
- endReason: a
167
- }) {
168
- const s = n.now();
169
- P([
170
- h({
171
- endAssetPosition: t,
172
- endTimestamp: s,
173
- streamingSessionId: e
174
- })
175
- ]).catch(console.error), I([
176
- S({
177
- endReason: M(a),
178
- endTimestamp: s,
179
- streamingSessionId: e
180
- }),
181
- y({
182
- streamingSessionId: e,
183
- timestamp: s
184
- })
185
- ]).catch(console.error);
186
- }
187
- eventTrackingStreamingStarted(e) {
188
- if (!e)
189
- return;
190
- performance.mark(
191
- "streaming_metrics:playback_statistics:actualStartTimestamp",
192
- {
193
- detail: e,
194
- startTime: n.now()
195
- }
196
- ), performance.measure("idealStartTimestamp -> actualStartTimestamp", {
197
- detail: e,
198
- end: "streaming_metrics:playback_statistics:actualStartTimestamp",
199
- start: "streaming_metrics:playback_statistics:idealStartTimestamp"
200
- });
201
- try {
202
- S({
203
- actualStartTimestamp: n.timestamp(
204
- "streaming_metrics:playback_statistics:actualStartTimestamp",
205
- e
206
- ),
207
- idealStartTimestamp: n.timestamp(
208
- "streaming_metrics:playback_statistics:idealStartTimestamp",
209
- e
210
- ),
211
- outputDevice: this.#r,
212
- streamingSessionId: e
213
- });
214
- } catch (l) {
215
- console.error(
216
- l,
217
- "actualStartTimestamp or idealStartTimestamp is missing for this streaming session"
218
- );
219
- } finally {
220
- performance.clearMarks(
221
- "streaming_metrics:playback_statistics:actualStartTimestamp"
222
- ), performance.clearMarks(
223
- "streaming_metrics:playback_statistics:idealStartTimestamp"
224
- );
225
- }
226
- const t = i.getMediaProductTransition(e);
227
- if (!t) {
228
- i.hasStartedStreamInfo(e) ? console.error(
229
- `A media product transition for streaming session #${e} has not been saved and could thus not be found for play log reporting.`
230
- ) : (i.deleteStreamInfo(e), console.warn(
231
- `Streaming session #${e} has been discarded due to a new load. This could mean you have a bug in your code where you call load on Player more than once time in a very short time frame.`
232
- ));
233
- return;
234
- }
235
- const { mediaProduct: a, playbackContext: s } = t, u = n.now();
236
- h({
237
- actualAssetPresentation: s.actualAssetPresentation,
238
- actualAudioMode: "actualAudioMode" in s ? s.actualAudioMode : null,
239
- actualProductId: s.actualProductId,
240
- actualQuality: s.actualAudioQuality || s.actualVideoQuality,
241
- extras: a.extras,
242
- isPostPaywall: v(
243
- s.actualAssetPresentation,
244
- a
245
- ),
246
- playbackSessionId: e,
247
- productType: T(
248
- a.productType
249
- ),
250
- requestedProductId: a.productId,
251
- sourceId: a.sourceId,
252
- sourceType: a.sourceType,
253
- startAssetPosition: this.startAssetPosition,
254
- startTimestamp: u,
255
- streamingSessionId: e
256
- }).catch(console.error);
257
- }
258
- finishCurrentMediaProduct(e) {
259
- if (!this.hasStarted())
260
- return;
261
- const t = this.#e, a = t ? i.hasStreamInfo(t) : !1;
262
- this.preloadedStreamingSessionId || (this.playbackState = "IDLE"), t && a && this.#c({
263
- endAssetPosition: this.currentTime,
264
- endReason: e,
265
- streamingSessionId: t
266
- });
267
- }
268
- getPosition() {
269
- return 0;
270
- }
271
- /**
272
- * Refetches playbackinfo.
273
- */
274
- async hardReload(e, t) {
275
- return this.currentStreamingSessionId && this.finishCurrentMediaProduct("skip"), f(e, t);
276
- }
277
- hasNextItem() {
278
- return this.preloadedStreamingSessionId;
279
- }
280
- hasStarted() {
281
- return this.currentStreamingSessionId && i.hasStartedStreamInfo(this.currentStreamingSessionId);
282
- }
283
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
284
- load(e, t) {
285
- return Promise.resolve();
286
- }
287
- /**
288
- * If playback info is prefetched or expired, do a hard reload.
289
- *
290
- * @returns {boolean} True if hard reloaded, else false.
291
- */
292
- async maybeHardReload() {
293
- const e = this.prefetched || this.expired;
294
- return this.currentMediaProduct && e ? (await this.hardReload(this.currentMediaProduct, 0), !0) : !1;
295
- }
296
- /**
297
- * This method should be call whenever a playback starts, for **whatever** reason.
298
- *
299
- * skip, load.
300
- *
301
- * @param streamingSessionId
302
- */
303
- mediaProductStarted(e) {
304
- !e || i.hasStartedStreamInfo(e) || (this.debugLog("mediaProductStarted"), this.eventTrackingStreamingStarted(e), i.setStartedStreamInfo(e), this.updateVolumeLevel(), this.#i = !1, this.preloadedStreamingSessionId = void 0, this.unloadPreloadedMediaProduct().catch(console.error), this.attachPlaybackEngineEndedHandler());
305
- }
306
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
307
- next(e) {
308
- return Promise.resolve();
309
- }
310
- /**
311
- * When re-using a nexted item for a load, overwrite the nexted MediaProduct with the provided one.
312
- * To ensure sourceId, sourceType and referenceId from the load call is correct for the playback -
313
- * and not a stale incorrect one from the next call.
314
- *
315
- * @param streamingSessionId
316
- * @param partialMediaProduct
317
- */
318
- overwriteMediaProduct(e, t) {
319
- const a = i.getMediaProductTransition(e);
320
- if (a) {
321
- i.deleteMediaProductTransition(e);
322
- const s = {
323
- mediaProduct: {
324
- ...a.mediaProduct,
325
- ...t
326
- },
327
- playbackContext: {
328
- ...a.playbackContext
329
- }
330
- };
331
- i.saveMediaProductTransition(
332
- e,
333
- s
334
- );
335
- }
336
- }
337
- pause() {
338
- }
339
- play() {
340
- return Promise.resolve();
341
- }
342
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
343
- playbackEngineEndedHandler(e) {
344
- return Promise.resolve();
345
- }
346
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
347
- reset(e) {
348
- return Promise.resolve();
349
- }
350
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
351
- seek(e) {
352
- }
353
- /**
354
- * Handle play log reporting for seeking.
355
- * Seek start should log a PLAYBACK_START action if playing post seek.
356
- */
357
- seekEnd(e) {
358
- const t = this.currentStreamingSessionId;
359
- if (t) {
360
- const a = () => c(t, {
361
- actionType: "PLAYBACK_START",
362
- assetPosition: e,
363
- timestamp: n.now()
364
- });
365
- if (this.playbackState === "PLAYING")
366
- a().catch(console.error);
367
- else {
368
- const s = () => {
369
- this.playbackState === "PLAYING" && (a().catch(console.error), o.removeEventListener(
370
- "playback-state-change",
371
- s
372
- ));
373
- };
374
- o.addEventListener(
375
- "playback-state-change",
376
- s
377
- );
378
- }
379
- }
380
- }
381
- /**
382
- * Handle play log reporting for seeking.
383
- * Seek start should log a PLAYBACK_STOP action.
384
- */
385
- seekStart(e) {
386
- this.currentStreamingSessionId && c(this.currentStreamingSessionId, {
387
- actionType: "PLAYBACK_STOP",
388
- assetPosition: e,
389
- timestamp: n.now()
390
- }).catch(console.error);
391
- }
392
- async setStateToXIfNotYInZMs(e, t, a) {
393
- await b(e), this.playbackState !== t && (this.playbackState = a);
394
- }
395
- skipToPreloadedMediaProduct() {
396
- return Promise.resolve();
397
- }
398
- unloadPreloadedMediaProduct() {
399
- return Promise.resolve();
400
- }
401
- updateOutputDevice() {
402
- return Promise.resolve();
403
- }
404
- /**
405
- * Hydrates the volume level from config, and adjusts
406
- * it before setting, if loudness normalization is
407
- * enabled.
408
- */
409
- updateVolumeLevel() {
410
- const e = i.getStreamInfo(
411
- this.currentStreamingSessionId
412
- );
413
- e && (this.volume = this.adjustedVolume(e));
414
- }
415
- /**
416
- * Adjusts the volume for the next track.
417
- * Can be called on product ended to have the level ready.
418
- */
419
- updateVolumeLevelForNextProduct() {
420
- const e = i.getStreamInfo(
421
- this.preloadedStreamingSessionId
422
- );
423
- e && (this.volume = this.adjustedVolume(e));
424
- }
425
- get currentMediaProduct() {
426
- return i.getMediaProductTransition(
427
- this.currentStreamingSessionId
428
- )?.mediaProduct ?? null;
429
- }
430
- set currentStreamingSessionId(e) {
431
- this.#e = e;
432
- }
433
- get currentStreamingSessionId() {
434
- return this.#e;
435
- }
436
- set currentTime(e) {
437
- this.#s = e, this.#d();
438
- }
439
- get currentTime() {
440
- return this.#s;
441
- }
442
- get duration() {
443
- const e = i.getMediaProductTransition(
444
- this.currentStreamingSessionId
445
- );
446
- return e ? e.playbackContext.actualDuration : null;
447
- }
448
- get expired() {
449
- const e = i.getStreamInfo(
450
- this.currentStreamingSessionId
451
- );
452
- return e ? e.expires <= Date.now() : !1;
453
- }
454
- get isActivePlayer() {
455
- return d.activePlayer && this.name === d.activePlayer.name;
456
- }
457
- get nextItem() {
458
- if (this.preloadedStreamingSessionId)
459
- return i.getMediaProductTransition(
460
- this.preloadedStreamingSessionId
461
- );
462
- }
463
- set outputDeviceType(e) {
464
- this.#r = e ? k(e) : void 0;
465
- }
466
- set playbackState(e) {
467
- const t = this.#a;
468
- if (t === e || !this.currentStreamingSessionId)
469
- return;
470
- const a = (u, l) => t === u && l === e;
471
- switch (!0) {
472
- case a("NOT_PLAYING", "STALLED"):
473
- case a("IDLE", "STALLED"):
474
- return;
475
- case a("PLAYING", "NOT_PLAYING"):
476
- case a("PLAYING", "IDLE"): {
477
- this.duration && this.currentTime < this.duration && c(this.currentStreamingSessionId, {
478
- actionType: "PLAYBACK_STOP",
479
- assetPosition: this.currentTime,
480
- timestamp: n.now()
481
- }).catch(console.error);
482
- break;
483
- }
484
- case a("IDLE", "PLAYING"):
485
- case a("NOT_PLAYING", "PLAYING"): {
486
- this.currentTime !== this.startAssetPosition && c(this.currentStreamingSessionId, {
487
- actionType: "PLAYBACK_START",
488
- assetPosition: this.currentTime,
489
- timestamp: n.now()
490
- }).catch(console.error);
491
- break;
492
- }
493
- }
494
- this.#a = e, this.debugLog(`playbackState: ${e}`);
495
- const s = d.activePlayer === void 0;
496
- (this.isActivePlayer || s) && o.dispatchEvent(L(this.#a));
497
- }
498
- get playbackState() {
499
- return this.#a;
500
- }
501
- get prefetched() {
502
- return i.getStreamInfo(
503
- this.currentStreamingSessionId
504
- )?.prefetched;
505
- }
506
- set preloadedStreamingSessionId(e) {
507
- this.#n = e;
508
- }
509
- get preloadedStreamingSessionId() {
510
- return this.#n;
511
- }
512
- get startAssetPosition() {
513
- return this.#o;
514
- }
515
- set startAssetPosition(e) {
516
- this.#o = e;
517
- }
518
- get volume() {
519
- return 1;
520
- }
521
- set volume(e) {
522
- }
523
- };
524
- export {
525
- C,
526
- _ as R,
527
- R as w
528
- };