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

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.
@@ -1,25 +1,17 @@
1
- import { N as I, c as T, b as o, l as d, g as n, T as r, S as m, A as h, G as v, s as p, d as b, f as k, z as c, _ as f, V as A, p as g, h as P, D as y } from "./index-DbGwqQeZ.js";
2
- function L(i) {
3
- return g(
4
- () => P(y, {
5
- type: "play_log",
6
- ...i
7
- })
8
- );
9
- }
10
- function x(i, e) {
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) {
11
3
  return new CustomEvent(
12
4
  "media-product-transition",
13
5
  {
14
6
  detail: {
15
- mediaProduct: i,
7
+ mediaProduct: r,
16
8
  playbackContext: e
17
9
  }
18
10
  }
19
11
  );
20
12
  }
21
- const G = ({
22
- assetPosition: i,
13
+ const _ = ({
14
+ assetPosition: r,
23
15
  duration: e,
24
16
  playbackInfo: t,
25
17
  streamInfo: a
@@ -33,61 +25,35 @@ const G = ({
33
25
  ),
34
26
  actualStreamType: "streamType" in t ? t.streamType : null,
35
27
  actualVideoQuality: "videoQuality" in t ? t.videoQuality : null,
36
- assetPosition: i,
28
+ assetPosition: r,
37
29
  bitDepth: a.bitDepth ?? null,
38
30
  codec: a.codec ?? null,
39
31
  playbackSessionId: a.streamingSessionId,
40
32
  sampleRate: a.sampleRate ?? null
41
33
  });
42
- function M(i, e) {
34
+ function A(r, e) {
43
35
  return new CustomEvent("ended", {
44
36
  detail: {
45
37
  mediaProduct: e,
46
- reason: i
38
+ reason: r
47
39
  }
48
40
  });
49
41
  }
50
- function E(i) {
42
+ function L(r) {
51
43
  return new CustomEvent("playback-state-change", {
52
44
  detail: {
53
- state: i
45
+ state: r
54
46
  }
55
47
  });
56
48
  }
57
- function _() {
49
+ function E() {
58
50
  return new CustomEvent("preload-request");
59
51
  }
60
- const w = {
61
- playback: {
62
- durationMS: 0,
63
- id: "",
64
- playedMS: 0,
65
- source: {
66
- id: "",
67
- type: "playlist"
68
- },
69
- type: "TRACK"
70
- }
71
- }, R = await I(
72
- "progress",
73
- w
74
- );
75
- function C(i) {
76
- return R(i);
77
- }
78
- function D(i) {
79
- return g(
80
- () => P(y, {
81
- ...i,
82
- type: "playback"
83
- })
84
- );
85
- }
86
- function S(i) {
87
- return Math.min(Math.pow(10, (4 + i) / 20), 1 / 1);
52
+ function p(r) {
53
+ return Math.min(Math.pow(10, (4 + r) / 20), 1 / 1);
88
54
  }
89
- function N(i) {
90
- switch (i) {
55
+ function M(r) {
56
+ switch (r) {
91
57
  case "completed":
92
58
  return "COMPLETE";
93
59
  case "error":
@@ -97,33 +63,32 @@ function N(i) {
97
63
  return "OTHER";
98
64
  }
99
65
  }
100
- class Y {
66
+ let C = class {
101
67
  #e;
102
- #i;
68
+ #s;
103
69
  #t;
104
- #r = void 0;
70
+ #i = void 0;
71
+ #r;
72
+ #a = "IDLE";
105
73
  #n;
106
- #s = "IDLE";
107
74
  #o;
108
- #d;
109
- #a = /* @__PURE__ */ new Map();
110
75
  name;
111
76
  constructor() {
112
- T.addEventListener("desiredVolumeLevel", () => {
77
+ g.addEventListener("desiredVolumeLevel", () => {
113
78
  this.isActivePlayer && this.updateVolumeLevel();
114
79
  });
115
80
  }
116
81
  // Implements
117
- #c() {
118
- this.duration && Math.abs(this.#i - this.duration) <= 30 && // A false check, rather than undefined, ensures a media product transition hs been made.
119
- this.#r === !1 && (this.#r = !0, o.dispatchEvent(_()));
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()));
120
85
  }
121
86
  /**
122
87
  * This method should be call whenever a playback ends, for **whatever** reason.
123
88
  *
124
89
  * ended, completed, skip, reset etc
125
90
  */
126
- #u({
91
+ #c({
127
92
  endAssetPosition: e,
128
93
  endReason: t,
129
94
  streamingSessionId: a
@@ -135,18 +100,18 @@ class Y {
135
100
  startTime: n.now()
136
101
  }
137
102
  );
138
- const s = r.getMediaProductTransition(a);
103
+ const s = i.getMediaProductTransition(a);
139
104
  s && o.dispatchEvent(
140
- M(t, s.mediaProduct)
105
+ A(t, s.mediaProduct)
141
106
  ), this.eventTrackingStreamingEnded(a, {
142
107
  endAssetPosition: e,
143
108
  endReason: t
144
- }), this.reportPlaybackProgress(a), r.deleteSession(a), this.#a.delete(a), this.currentStreamingSessionId === a && (this.currentStreamingSessionId = void 0), this.updateVolumeLevelForNextProduct();
109
+ }), i.deleteSession(a), this.currentStreamingSessionId === a && (this.currentStreamingSessionId = void 0), this.updateVolumeLevelForNextProduct();
145
110
  }
146
111
  adjustedVolume(e) {
147
112
  const t = m("desiredVolumeLevel"), a = m("loudnessNormalizationMode");
148
113
  let s = t;
149
- return a === "ALBUM" && e.albumReplayGain && (s *= S(e.albumReplayGain)), a === "TRACK" && e.trackReplayGain && (s *= S(e.trackReplayGain)), this.debugLog(
114
+ return a === "ALBUM" && e.albumReplayGain && (s *= p(e.albumReplayGain)), a === "TRACK" && e.trackReplayGain && (s *= p(e.trackReplayGain)), this.debugLog(
150
115
  "adjustedVolume",
151
116
  `Volume adjusted from ${t} to ${s}`
152
117
  ), parseFloat(s.toFixed(2));
@@ -164,7 +129,7 @@ class Y {
164
129
  * currentStreamingSessionId.
165
130
  */
166
131
  cleanUpStoredPreloadInfo() {
167
- this.preloadedStreamingSessionId && this.preloadedStreamingSessionId !== this.currentStreamingSessionId && (r.deleteSession(this.preloadedStreamingSessionId), this.preloadedStreamingSessionId = void 0);
132
+ this.preloadedStreamingSessionId && this.preloadedStreamingSessionId !== this.currentStreamingSessionId && (i.deleteSession(this.preloadedStreamingSessionId), this.preloadedStreamingSessionId = void 0);
168
133
  }
169
134
  // Implements
170
135
  debugLog(...e) {
@@ -201,27 +166,23 @@ class Y {
201
166
  endReason: a
202
167
  }) {
203
168
  const s = n.now();
204
- L({
205
- events: [
206
- h({
207
- endAssetPosition: t,
208
- endTimestamp: s,
209
- streamingSessionId: e
210
- })
211
- ]
212
- }).catch(console.error), v({
213
- events: [
214
- p({
215
- endReason: N(a),
216
- endTimestamp: s,
217
- streamingSessionId: e
218
- }),
219
- b({
220
- streamingSessionId: e,
221
- timestamp: s
222
- })
223
- ]
224
- }).catch(console.error);
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);
225
186
  }
226
187
  eventTrackingStreamingStarted(e) {
227
188
  if (!e)
@@ -238,7 +199,7 @@ class Y {
238
199
  start: "streaming_metrics:playback_statistics:idealStartTimestamp"
239
200
  });
240
201
  try {
241
- p({
202
+ S({
242
203
  actualStartTimestamp: n.timestamp(
243
204
  "streaming_metrics:playback_statistics:actualStartTimestamp",
244
205
  e
@@ -247,7 +208,7 @@ class Y {
247
208
  "streaming_metrics:playback_statistics:idealStartTimestamp",
248
209
  e
249
210
  ),
250
- outputDevice: this.#n,
211
+ outputDevice: this.#r,
251
212
  streamingSessionId: e
252
213
  });
253
214
  } catch (l) {
@@ -262,11 +223,11 @@ class Y {
262
223
  "streaming_metrics:playback_statistics:idealStartTimestamp"
263
224
  );
264
225
  }
265
- const t = r.getMediaProductTransition(e);
226
+ const t = i.getMediaProductTransition(e);
266
227
  if (!t) {
267
- this.#a.has(e) ? console.error(
228
+ i.hasStartedStreamInfo(e) ? console.error(
268
229
  `A media product transition for streaming session #${e} has not been saved and could thus not be found for play log reporting.`
269
- ) : (r.deleteStreamInfo(e), console.warn(
230
+ ) : (i.deleteStreamInfo(e), console.warn(
270
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.`
271
232
  ));
272
233
  return;
@@ -277,22 +238,28 @@ class Y {
277
238
  actualAudioMode: "actualAudioMode" in s ? s.actualAudioMode : null,
278
239
  actualProductId: s.actualProductId,
279
240
  actualQuality: s.actualAudioQuality || s.actualVideoQuality,
280
- isPostPaywall: s.actualAssetPresentation === "FULL",
241
+ extras: a.extras,
242
+ isPostPaywall: v(
243
+ s.actualAssetPresentation,
244
+ a
245
+ ),
281
246
  playbackSessionId: e,
282
- productType: a.productType === "track" ? "TRACK" : "VIDEO",
247
+ productType: T(
248
+ a.productType
249
+ ),
283
250
  requestedProductId: a.productId,
284
251
  sourceId: a.sourceId,
285
252
  sourceType: a.sourceType,
286
253
  startAssetPosition: this.startAssetPosition,
287
254
  startTimestamp: u,
288
255
  streamingSessionId: e
289
- });
256
+ }).catch(console.error);
290
257
  }
291
258
  finishCurrentMediaProduct(e) {
292
259
  if (!this.hasStarted())
293
260
  return;
294
- const t = this.#e, a = t ? r.hasStreamInfo(t) : !1;
295
- this.preloadedStreamingSessionId || (this.playbackState = "IDLE"), t && a && this.#u({
261
+ const t = this.#e, a = t ? i.hasStreamInfo(t) : !1;
262
+ this.preloadedStreamingSessionId || (this.playbackState = "IDLE"), t && a && this.#c({
296
263
  endAssetPosition: this.currentTime,
297
264
  endReason: e,
298
265
  streamingSessionId: t
@@ -305,17 +272,15 @@ class Y {
305
272
  * Refetches playbackinfo.
306
273
  */
307
274
  async hardReload(e, t) {
308
- return this.currentStreamingSessionId && this.finishCurrentMediaProduct("skip"), k(e, t);
275
+ return this.currentStreamingSessionId && this.finishCurrentMediaProduct("skip"), f(e, t);
309
276
  }
310
277
  hasNextItem() {
311
- return this.preloadedStreamingSessionId && r.hasMediaProductTransition(
312
- this.preloadedStreamingSessionId
313
- );
278
+ return this.preloadedStreamingSessionId;
314
279
  }
315
280
  hasStarted() {
316
- return this.currentStreamingSessionId && this.#a.has(this.currentStreamingSessionId);
281
+ return this.currentStreamingSessionId && i.hasStartedStreamInfo(this.currentStreamingSessionId);
317
282
  }
318
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
283
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
319
284
  load(e, t) {
320
285
  return Promise.resolve();
321
286
  }
@@ -336,9 +301,9 @@ class Y {
336
301
  * @param streamingSessionId
337
302
  */
338
303
  mediaProductStarted(e) {
339
- !e || this.#a.has(e) || (this.debugLog("mediaProductStarted"), this.eventTrackingStreamingStarted(e), this.#a.set(e, !0), this.updateVolumeLevel(), this.#r = !1, this.preloadedStreamingSessionId = void 0, this.unloadPreloadedMediaProduct().catch(console.error), this.attachPlaybackEngineEndedHandler());
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());
340
305
  }
341
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
306
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
342
307
  next(e) {
343
308
  return Promise.resolve();
344
309
  }
@@ -351,9 +316,9 @@ class Y {
351
316
  * @param partialMediaProduct
352
317
  */
353
318
  overwriteMediaProduct(e, t) {
354
- const a = r.getMediaProductTransition(e);
319
+ const a = i.getMediaProductTransition(e);
355
320
  if (a) {
356
- r.deleteMediaProductTransition(e);
321
+ i.deleteMediaProductTransition(e);
357
322
  const s = {
358
323
  mediaProduct: {
359
324
  ...a.mediaProduct,
@@ -363,7 +328,7 @@ class Y {
363
328
  ...a.playbackContext
364
329
  }
365
330
  };
366
- r.saveMediaProductTransition(
331
+ i.saveMediaProductTransition(
367
332
  e,
368
333
  s
369
334
  );
@@ -374,38 +339,15 @@ class Y {
374
339
  play() {
375
340
  return Promise.resolve();
376
341
  }
377
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
342
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
378
343
  playbackEngineEndedHandler(e) {
379
344
  return Promise.resolve();
380
345
  }
381
- reportPlaybackProgress(e) {
382
- const t = r.getMediaProductTransition(e);
383
- if (!t)
384
- return;
385
- const { mediaProduct: a, playbackContext: s } = t;
386
- this.#e && D({
387
- events: [
388
- C({
389
- playback: {
390
- durationMS: Math.floor(s.actualDuration * 1e3),
391
- id: a.productId,
392
- playedMS: Math.floor(this.currentTime * 1e3),
393
- source: {
394
- id: a.sourceId,
395
- type: a.sourceType
396
- },
397
- type: a.productType === "track" ? "TRACK" : "VIDEO"
398
- },
399
- streamingSessionId: this.#e
400
- })
401
- ]
402
- }).catch(console.error);
403
- }
404
346
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
405
347
  reset(e) {
406
348
  return Promise.resolve();
407
349
  }
408
- // eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
350
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
409
351
  seek(e) {
410
352
  }
411
353
  /**
@@ -445,10 +387,10 @@ class Y {
445
387
  actionType: "PLAYBACK_STOP",
446
388
  assetPosition: e,
447
389
  timestamp: n.now()
448
- });
390
+ }).catch(console.error);
449
391
  }
450
392
  async setStateToXIfNotYInZMs(e, t, a) {
451
- await f(e), this.playbackState !== t && (this.playbackState = a);
393
+ await b(e), this.playbackState !== t && (this.playbackState = a);
452
394
  }
453
395
  skipToPreloadedMediaProduct() {
454
396
  return Promise.resolve();
@@ -465,7 +407,7 @@ class Y {
465
407
  * enabled.
466
408
  */
467
409
  updateVolumeLevel() {
468
- const e = r.getStreamInfo(
410
+ const e = i.getStreamInfo(
469
411
  this.currentStreamingSessionId
470
412
  );
471
413
  e && (this.volume = this.adjustedVolume(e));
@@ -475,13 +417,13 @@ class Y {
475
417
  * Can be called on product ended to have the level ready.
476
418
  */
477
419
  updateVolumeLevelForNextProduct() {
478
- const e = r.getStreamInfo(
420
+ const e = i.getStreamInfo(
479
421
  this.preloadedStreamingSessionId
480
422
  );
481
423
  e && (this.volume = this.adjustedVolume(e));
482
424
  }
483
425
  get currentMediaProduct() {
484
- return r.getMediaProductTransition(
426
+ return i.getMediaProductTransition(
485
427
  this.currentStreamingSessionId
486
428
  )?.mediaProduct ?? null;
487
429
  }
@@ -492,19 +434,19 @@ class Y {
492
434
  return this.#e;
493
435
  }
494
436
  set currentTime(e) {
495
- this.#i = e, this.#c();
437
+ this.#s = e, this.#d();
496
438
  }
497
439
  get currentTime() {
498
- return this.#i;
440
+ return this.#s;
499
441
  }
500
442
  get duration() {
501
- const e = r.getMediaProductTransition(
443
+ const e = i.getMediaProductTransition(
502
444
  this.currentStreamingSessionId
503
445
  );
504
446
  return e ? e.playbackContext.actualDuration : null;
505
447
  }
506
448
  get expired() {
507
- const e = r.getStreamInfo(
449
+ const e = i.getStreamInfo(
508
450
  this.currentStreamingSessionId
509
451
  );
510
452
  return e ? e.expires <= Date.now() : !1;
@@ -514,16 +456,15 @@ class Y {
514
456
  }
515
457
  get nextItem() {
516
458
  if (this.preloadedStreamingSessionId)
517
- return r.getMediaProductTransition(
459
+ return i.getMediaProductTransition(
518
460
  this.preloadedStreamingSessionId
519
461
  );
520
462
  }
521
- // eslint-disable-next-line accessor-pairs
522
463
  set outputDeviceType(e) {
523
- this.#n = e ? A(e) : void 0;
464
+ this.#r = e ? k(e) : void 0;
524
465
  }
525
466
  set playbackState(e) {
526
- const t = this.#s;
467
+ const t = this.#a;
527
468
  if (t === e || !this.currentStreamingSessionId)
528
469
  return;
529
470
  const a = (u, l) => t === u && l === e;
@@ -533,7 +474,7 @@ class Y {
533
474
  return;
534
475
  case a("PLAYING", "NOT_PLAYING"):
535
476
  case a("PLAYING", "IDLE"): {
536
- this.reportPlaybackProgress(this.currentStreamingSessionId), this.duration && this.currentTime < this.duration && c(this.currentStreamingSessionId, {
477
+ this.duration && this.currentTime < this.duration && c(this.currentStreamingSessionId, {
537
478
  actionType: "PLAYBACK_STOP",
538
479
  assetPosition: this.currentTime,
539
480
  timestamp: n.now()
@@ -550,40 +491,38 @@ class Y {
550
491
  break;
551
492
  }
552
493
  }
553
- this.#s = e, this.debugLog(`playbackState: ${e}`);
494
+ this.#a = e, this.debugLog(`playbackState: ${e}`);
554
495
  const s = d.activePlayer === void 0;
555
- (this.isActivePlayer || s) && o.dispatchEvent(E(this.#s));
496
+ (this.isActivePlayer || s) && o.dispatchEvent(L(this.#a));
556
497
  }
557
498
  get playbackState() {
558
- return this.#s;
499
+ return this.#a;
559
500
  }
560
501
  get prefetched() {
561
- const e = r.getStreamInfo(
502
+ return i.getStreamInfo(
562
503
  this.currentStreamingSessionId
563
- );
564
- return e && e.prefetched;
504
+ )?.prefetched;
565
505
  }
566
506
  set preloadedStreamingSessionId(e) {
567
- this.#o = e;
507
+ this.#n = e;
568
508
  }
569
509
  get preloadedStreamingSessionId() {
570
- return this.#o;
510
+ return this.#n;
571
511
  }
572
512
  get startAssetPosition() {
573
- return this.#d;
513
+ return this.#o;
574
514
  }
575
515
  set startAssetPosition(e) {
576
- this.#d = e;
516
+ this.#o = e;
577
517
  }
578
- // eslint-disable-next-line @typescript-eslint/class-literal-property-style
579
518
  get volume() {
580
519
  return 1;
581
520
  }
582
521
  set volume(e) {
583
522
  }
584
- }
523
+ };
585
524
  export {
586
- Y as G,
587
- x as V,
588
- G as Y
525
+ C,
526
+ _ as R,
527
+ R as w
589
528
  };