@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,30 +1,30 @@
1
- import { G as I, Y as g, V as p } from "./basePlayer-BcooVl9P-WesO1_17.js";
2
- import { C as P, O as y, a as L, T as c, b as S, S as E, _ as b } from "./index-DbGwqQeZ.js";
1
+ import { C as I, R as g, w as p } from "./basePlayer-Rqi9yRuo-4eKn-Akv.js";
2
+ import { c as P, A as y, P as c, b as S, k as E, d as L } from "./index-DHnVYeec.js";
3
3
  class f extends I {
4
4
  #t;
5
- #i;
6
- #n;
7
- #a = !0;
8
- #o;
5
+ #r;
6
+ #i = !0;
7
+ #d;
9
8
  #e;
9
+ #a = document.createElement("video");
10
10
  #s = !1;
11
11
  name = "browserPlayer";
12
12
  constructor() {
13
13
  super(), this.playbackState = "IDLE";
14
14
  const e = () => {
15
15
  this.mediaElement && !this.mediaElement.paused && (this.playbackState = "PLAYING");
16
- }, t = (a) => {
16
+ }, i = (a) => {
17
17
  this.currentStreamingSessionId && a.target instanceof HTMLMediaElement && c.overwriteDuration(
18
18
  this.currentStreamingSessionId,
19
19
  a.target.duration
20
20
  );
21
- }, i = () => {
21
+ }, t = () => {
22
22
  this.playbackState = "STALLED";
23
23
  }, s = () => {
24
24
  (async () => {
25
25
  const a = this.#t;
26
26
  if (a) {
27
- if (this.preloadedStreamingSessionId && a.currentTime === a.duration && (await b(1e3), a.currentTime !== a.duration))
27
+ if (this.preloadedStreamingSessionId && a.currentTime === a.duration && (await L(1e3), a.currentTime !== a.duration))
28
28
  return;
29
29
  this.playbackState = "NOT_PLAYING";
30
30
  }
@@ -40,65 +40,62 @@ class f extends I {
40
40
  this.mediaElement && (this.currentTime = this.mediaElement.currentTime, this.seekEnd(this.currentTime));
41
41
  };
42
42
  this.#e = {
43
- durationChangeHandler: t,
43
+ durationChangeHandler: i,
44
44
  endedHandler: d,
45
45
  errorHandler: r,
46
46
  pauseHandler: s,
47
47
  playHandler: e,
48
48
  playingHandler: e,
49
49
  seekedHandler: o,
50
- stalledHandler: i,
50
+ stalledHandler: t,
51
51
  timeUpdateHandler: n,
52
- waitingHandler: i
53
- }, P().then().catch(console.error), this.#i = y, this.#n = L, this.currentPlayer = this.#i;
52
+ waitingHandler: t
53
+ }, P().then().catch(console.error), this.#r = y, this.currentPlayer = this.#r;
54
54
  }
55
- #r() {
56
- return [this.#i, this.#n].filter((e) => e !== this.#t).pop();
57
- }
58
- #d(e, t) {
55
+ #n(e, i) {
59
56
  this.debugLog(
60
57
  "mediaElementEvents",
61
- t ? "adding to" : "removing from",
58
+ i ? "adding to" : "removing from",
62
59
  e
63
60
  );
64
- const i = t ? "addEventListener" : "removeEventListener";
65
- e[i](
61
+ const t = i ? "addEventListener" : "removeEventListener";
62
+ e[t](
66
63
  "durationchange",
67
64
  this.#e.durationChangeHandler,
68
65
  {
69
66
  passive: !0
70
67
  }
71
- ), e[i]("play", this.#e.playHandler, {
68
+ ), e[t]("play", this.#e.playHandler, {
72
69
  passive: !0
73
- }), e[i](
70
+ }), e[t](
74
71
  "playing",
75
72
  this.#e.playingHandler,
76
73
  { passive: !0 }
77
- ), e[i](
74
+ ), e[t](
78
75
  "timeupdate",
79
76
  this.#e.timeUpdateHandler,
80
77
  { passive: !0 }
81
- ), e[i](
78
+ ), e[t](
82
79
  "pause",
83
80
  this.#e.pauseHandler,
84
81
  { passive: !0 }
85
- ), e[i](
82
+ ), e[t](
86
83
  "ended",
87
84
  this.#e.endedHandler,
88
85
  { passive: !0 }
89
- ), e[i](
86
+ ), e[t](
90
87
  "error",
91
88
  this.#e.errorHandler,
92
89
  { passive: !0 }
93
- ), e[i](
90
+ ), e[t](
94
91
  "waiting",
95
92
  this.#e.waitingHandler,
96
93
  { passive: !0 }
97
- ), e[i](
94
+ ), e[t](
98
95
  "stalled",
99
96
  this.#e.stalledHandler,
100
97
  { passive: !0 }
101
- ), e[i](
98
+ ), e[t](
102
99
  "seeked",
103
100
  this.#e.seekedHandler,
104
101
  { passive: !0 }
@@ -107,46 +104,46 @@ class f extends I {
107
104
  getPosition() {
108
105
  return this.debugLog("getPosition"), this.mediaElement && (this.mediaElement.ended ? this.currentTime = 0 : this.currentTime = this.mediaElement.currentTime), this.currentTime;
109
106
  }
110
- async load(e, t) {
111
- this.debugLog("load", e), this.currentTime = e.assetPosition, this.startAssetPosition = e.assetPosition, await P(), await this.reset(), this.#a = !1, t === "explicit" && (this.playbackState = "NOT_PLAYING");
112
- const { assetPosition: i, mediaProduct: s, playbackInfo: n, streamInfo: d } = e;
107
+ async load(e, i) {
108
+ this.debugLog("load", e), this.currentTime = e.assetPosition, this.startAssetPosition = e.assetPosition, await P(), await this.reset(), this.#i = !1, i === "explicit" && (this.playbackState = "NOT_PLAYING");
109
+ const { assetPosition: t, mediaProduct: s, playbackInfo: n, streamInfo: d } = e;
113
110
  this.currentStreamingSessionId = d.streamingSessionId;
114
111
  const { currentPlayer: r } = this;
115
112
  if (!r)
116
113
  return;
117
114
  const o = new Promise(
118
- (h) => r.addEventListener("canplay", () => h(), {
115
+ (u) => r.addEventListener("canplay", () => u(), {
119
116
  once: !0
120
117
  })
121
118
  );
122
- r.src = d.streamUrl, r.currentTime = i, r.load();
119
+ r.src = d.streamUrl, r.currentTime = t, r.load();
123
120
  const a = new Promise(
124
- (h) => r.addEventListener(
121
+ (u) => r.addEventListener(
125
122
  "durationchange",
126
123
  (m) => {
127
- m.target instanceof HTMLMediaElement && h(m.target.duration);
124
+ m.target instanceof HTMLMediaElement && u(m.target.duration);
128
125
  },
129
126
  { once: !0 }
130
127
  )
131
128
  );
132
129
  if (await o, this.currentStreamingSessionId !== d.streamingSessionId)
133
130
  return;
134
- const l = await a, u = g({
135
- assetPosition: i,
131
+ const l = await a, h = g({
132
+ assetPosition: t,
136
133
  duration: l,
137
134
  playbackInfo: n,
138
135
  streamInfo: d
139
136
  });
140
137
  return c.saveMediaProductTransition(
141
138
  d.streamingSessionId,
142
- { mediaProduct: s, playbackContext: u }
139
+ { mediaProduct: s, playbackContext: h }
143
140
  ), this.debugLog("dispatching mediaProductTransition"), S.dispatchEvent(
144
- p(s, u)
141
+ p(s, h)
145
142
  ), this.#s ? (this.#s = !1, this.play()) : Promise.resolve();
146
143
  }
147
144
  async next(e) {
148
145
  this.debugLog("next", e), this.playbackState === "IDLE" && (this.playbackState = "NOT_PLAYING");
149
- const { mediaProduct: t, playbackInfo: i, streamInfo: s } = e, n = this.#r();
146
+ const { mediaProduct: i, playbackInfo: t, streamInfo: s } = e, n = this.#a;
150
147
  if (this.preloadedStreamingSessionId = s.streamingSessionId, !n)
151
148
  return;
152
149
  n.src = s.streamUrl, n.load();
@@ -161,16 +158,16 @@ class f extends I {
161
158
  ), r = g({
162
159
  assetPosition: 0,
163
160
  duration: d,
164
- playbackInfo: i,
161
+ playbackInfo: t,
165
162
  streamInfo: s
166
163
  });
167
164
  c.saveMediaProductTransition(
168
165
  s.streamingSessionId,
169
166
  {
170
- mediaProduct: t,
167
+ mediaProduct: i,
171
168
  playbackContext: r
172
169
  }
173
- );
170
+ ), this.#i = !1;
174
171
  }
175
172
  pause() {
176
173
  this.debugLog("pause"), this.mediaElement && this.mediaElement.pause();
@@ -182,25 +179,26 @@ class f extends I {
182
179
  }
183
180
  async playbackEngineEndedHandler(e) {
184
181
  if (this.isActivePlayer) {
185
- const { reason: t } = e.detail;
186
- t === "completed" && (this.hasNextItem() ? (await this.skipToPreloadedMediaProduct(), await this.play()) : (console.warn("No item preloaded, not progressing."), this.playbackState = "NOT_PLAYING"));
182
+ const { reason: i } = e.detail;
183
+ i === "completed" && (this.hasNextItem() ? (await this.skipToPreloadedMediaProduct(), await this.play()) : (console.warn("No item preloaded, not progressing."), this.playbackState = "NOT_PLAYING"));
187
184
  }
188
185
  }
189
186
  async reset({ keepPreload: e } = { keepPreload: !1 }) {
190
- if (this.#a)
187
+ if (this.#i)
191
188
  return Promise.resolve();
192
189
  this.debugLog("reset"), this.playbackState !== "IDLE" && this.finishCurrentMediaProduct("skip"), this.playbackState = "IDLE", this.detachPlaybackEngineEndedHandler(), this.currentStreamingSessionId = void 0, e || (this.preloadedStreamingSessionId = void 0);
193
- const { currentPlayer: t } = this;
194
- return t && t.readyState !== 0 && (t.load(), await new Promise(
195
- (i) => t.addEventListener("emptied", () => i(), { passive: !0 })
196
- )), this.#a = !0, Promise.resolve();
190
+ const { currentPlayer: i } = this;
191
+ return i && i.readyState !== 0 && (i.load(), await new Promise(
192
+ (t) => i.addEventListener("emptied", () => t(), { passive: !0 })
193
+ )), this.#i = !0, Promise.resolve();
197
194
  }
195
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
198
196
  seek(e) {
199
197
  this.debugLog("seek", e);
200
- const { currentPlayer: t } = this, i = e;
201
- if (t)
202
- return this.seekStart(this.currentTime), "fastSeek" in t ? t.fastSeek(i) : t.currentTime = i, new Promise((s) => {
203
- t.addEventListener("seeked", () => s(t.currentTime), {
198
+ const { currentPlayer: i } = this, t = e;
199
+ if (i)
200
+ return this.seekStart(this.currentTime), "fastSeek" in i ? i.fastSeek(t) : i.currentTime = t, new Promise((s) => {
201
+ i.addEventListener("seeked", () => s(i.currentTime), {
204
202
  once: !0
205
203
  });
206
204
  });
@@ -214,16 +212,14 @@ class f extends I {
214
212
  this.playbackState = "NOT_PLAYING";
215
213
  return;
216
214
  }
217
- this.debugLog(
215
+ if (this.debugLog(
218
216
  "skipToPreloadedMediaProduct",
219
217
  this.preloadedStreamingSessionId
220
- );
221
- const t = this.#r();
222
- if (t) {
223
- this.currentPlayer = t, this.currentStreamingSessionId = String(this.preloadedStreamingSessionId), this.preloadedStreamingSessionId = void 0;
224
- const { mediaProduct: i, playbackContext: s } = e;
218
+ ), this.#a.src && this.currentPlayer) {
219
+ this.currentPlayer.src = this.#a.src, this.currentStreamingSessionId = String(this.preloadedStreamingSessionId), this.preloadedStreamingSessionId = void 0;
220
+ const { mediaProduct: i, playbackContext: t } = e;
225
221
  S.dispatchEvent(
226
- p(i, s)
222
+ p(i, t)
227
223
  ), this.playbackState === "IDLE" && (this.playbackState = "NOT_PLAYING");
228
224
  }
229
225
  }
@@ -236,20 +232,20 @@ class f extends I {
236
232
  "unloadPreloadedMediaProduct",
237
233
  this.preloadedStreamingSessionId
238
234
  ), this.cleanUpStoredPreloadInfo();
239
- const e = this.#r();
235
+ const e = this.#a;
240
236
  e && (e.src = "", e.load());
241
237
  }
242
238
  get currentPlayer() {
243
239
  return this.#t;
244
240
  }
245
241
  set currentPlayer(e) {
246
- this.debugLog("set currentPlayer", e), this.#t && (this.#d(this.#t, !1), this.#t.load()), e && (this.#t = e, this.#d(e, !0));
242
+ this.debugLog("set currentPlayer", e), this.#t && (this.#n(this.#t, !1), this.#t.load()), e && (this.#t = e, this.#n(e, !0));
247
243
  }
248
244
  get mediaElement() {
249
245
  return this.currentPlayer ?? null;
250
246
  }
251
247
  get ready() {
252
- return this.#o;
248
+ return this.#d;
253
249
  }
254
250
  get volume() {
255
251
  return E("desiredVolumeLevel");