@tidal-music/player-web-components 0.1.1 → 0.2.0

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,12 +1,12 @@
1
- import { Y as I, O as g, V as p } from "./basePlayer-a-avZASH-Ux-6s9Ex.js";
2
- import { N as P, A as y, O as E, k as h, y as S, b as L, R as k } from "./index-tM9JvbA8.js";
1
+ import { C as I, R as g, w as p } from "./basePlayer-C5QIyqfj-Dxhlf4BZ.js";
2
+ import { a as P, I as y, P as c, b as S, k as E, c as L } from "./index-vp_MoGvy.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() {
@@ -14,7 +14,7 @@ class f extends I {
14
14
  const e = () => {
15
15
  this.mediaElement && !this.mediaElement.paused && (this.playbackState = "PLAYING");
16
16
  }, i = (a) => {
17
- this.currentStreamingSessionId && a.target instanceof HTMLMediaElement && h.overwriteDuration(
17
+ this.currentStreamingSessionId && a.target instanceof HTMLMediaElement && c.overwriteDuration(
18
18
  this.currentStreamingSessionId,
19
19
  a.target.duration
20
20
  );
@@ -24,22 +24,20 @@ class f extends I {
24
24
  (async () => {
25
25
  const a = this.#t;
26
26
  if (a) {
27
- if (this.preloadedStreamingSessionId && a.currentTime === a.duration && (await k(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
  }
31
31
  })().catch(console.error);
32
32
  }, n = (a) => {
33
33
  if (a instanceof Event) {
34
- const c = a.target;
35
- c.readyState > HTMLMediaElement.HAVE_NOTHING && (this.currentTime = c.currentTime);
34
+ const l = a.target;
35
+ l.readyState > HTMLMediaElement.HAVE_NOTHING && (this.currentTime = l.currentTime);
36
36
  }
37
37
  }, d = (a) => {
38
38
  n(a), this.finishCurrentMediaProduct("completed");
39
- }, r = (a) => console.error("HTMLMediaElement errored", a), l = () => {
40
- this.mediaElement && (this.currentTime = this.mediaElement.currentTime, this.seekStart());
41
- }, o = () => {
42
- this.mediaElement && (this.currentTime = this.mediaElement.currentTime, this.seekEnd());
39
+ }, r = (a) => console.error("HTMLMediaElement errored", a), o = () => {
40
+ this.mediaElement && (this.currentTime = this.mediaElement.currentTime, this.seekEnd(this.currentTime));
43
41
  };
44
42
  this.#e = {
45
43
  durationChangeHandler: i,
@@ -49,16 +47,12 @@ class f extends I {
49
47
  playHandler: e,
50
48
  playingHandler: e,
51
49
  seekedHandler: o,
52
- seekingHandler: l,
53
50
  stalledHandler: t,
54
51
  timeUpdateHandler: n,
55
52
  waitingHandler: t
56
- }, P().then().catch(console.error), this.#i = y, this.#n = E, this.currentPlayer = this.#i;
53
+ }, P().then().catch(console.error), this.#r = y, this.currentPlayer = this.#r;
57
54
  }
58
- #r() {
59
- return [this.#i, this.#n].filter((e) => e !== this.#t).pop();
60
- }
61
- #d(e, i) {
55
+ #n(e, i) {
62
56
  this.debugLog(
63
57
  "mediaElementEvents",
64
58
  i ? "adding to" : "removing from",
@@ -101,10 +95,6 @@ class f extends I {
101
95
  "stalled",
102
96
  this.#e.stalledHandler,
103
97
  { passive: !0 }
104
- ), e[t](
105
- "seeking",
106
- this.#e.seekingHandler,
107
- { passive: !0 }
108
98
  ), e[t](
109
99
  "seeked",
110
100
  this.#e.seekedHandler,
@@ -115,19 +105,19 @@ class f extends I {
115
105
  return this.debugLog("getPosition"), this.mediaElement && (this.mediaElement.ended ? this.currentTime = 0 : this.currentTime = this.mediaElement.currentTime), this.currentTime;
116
106
  }
117
107
  async load(e, i) {
118
- this.debugLog("load", e), this.currentTime = e.assetPosition, this.startAssetPosition = e.assetPosition, await P(), await this.reset(), this.#a = !1, i === "explicit" && (this.playbackState = "NOT_PLAYING");
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");
119
109
  const { assetPosition: t, mediaProduct: s, playbackInfo: n, streamInfo: d } = e;
120
110
  this.currentStreamingSessionId = d.streamingSessionId;
121
111
  const { currentPlayer: r } = this;
122
112
  if (!r)
123
113
  return;
124
- const l = new Promise(
114
+ const o = new Promise(
125
115
  (u) => r.addEventListener("canplay", () => u(), {
126
116
  once: !0
127
117
  })
128
118
  );
129
119
  r.src = d.streamUrl, r.currentTime = t, r.load();
130
- const o = new Promise(
120
+ const a = new Promise(
131
121
  (u) => r.addEventListener(
132
122
  "durationchange",
133
123
  (m) => {
@@ -136,32 +126,32 @@ class f extends I {
136
126
  { once: !0 }
137
127
  )
138
128
  );
139
- if (await l, this.currentStreamingSessionId !== d.streamingSessionId)
129
+ if (await o, this.currentStreamingSessionId !== d.streamingSessionId)
140
130
  return;
141
- const a = await o, c = g({
131
+ const l = await a, h = g({
142
132
  assetPosition: t,
143
- duration: a,
133
+ duration: l,
144
134
  playbackInfo: n,
145
135
  streamInfo: d
146
136
  });
147
- return h.saveMediaProductTransition(
137
+ return c.saveMediaProductTransition(
148
138
  d.streamingSessionId,
149
- { mediaProduct: s, playbackContext: c }
139
+ { mediaProduct: s, playbackContext: h }
150
140
  ), this.debugLog("dispatching mediaProductTransition"), S.dispatchEvent(
151
- p(s, c)
141
+ p(s, h)
152
142
  ), this.#s ? (this.#s = !1, this.play()) : Promise.resolve();
153
143
  }
154
144
  async next(e) {
155
145
  this.debugLog("next", e), this.playbackState === "IDLE" && (this.playbackState = "NOT_PLAYING");
156
- const { mediaProduct: i, playbackInfo: t, streamInfo: s } = e, n = this.#r();
146
+ const { mediaProduct: i, playbackInfo: t, streamInfo: s } = e, n = this.#a;
157
147
  if (this.preloadedStreamingSessionId = s.streamingSessionId, !n)
158
148
  return;
159
149
  n.src = s.streamUrl, n.load();
160
150
  const d = await new Promise(
161
- (l) => n.addEventListener(
151
+ (o) => n.addEventListener(
162
152
  "durationchange",
163
- (o) => {
164
- o.target instanceof HTMLMediaElement && l(o.target.duration);
153
+ (a) => {
154
+ a.target instanceof HTMLMediaElement && o(a.target.duration);
165
155
  },
166
156
  { once: !0 }
167
157
  )
@@ -171,13 +161,13 @@ class f extends I {
171
161
  playbackInfo: t,
172
162
  streamInfo: s
173
163
  });
174
- h.saveMediaProductTransition(
164
+ c.saveMediaProductTransition(
175
165
  s.streamingSessionId,
176
166
  {
177
167
  mediaProduct: i,
178
168
  playbackContext: r
179
169
  }
180
- );
170
+ ), this.#i = !1;
181
171
  }
182
172
  pause() {
183
173
  this.debugLog("pause"), this.mediaElement && this.mediaElement.pause();
@@ -194,19 +184,20 @@ class f extends I {
194
184
  }
195
185
  }
196
186
  async reset({ keepPreload: e } = { keepPreload: !1 }) {
197
- if (this.#a)
187
+ if (this.#i)
198
188
  return Promise.resolve();
199
- this.debugLog("reset"), this.playbackState !== "IDLE" && this.hasStarted() && this.finishCurrentMediaProduct("skip"), this.playbackState = "IDLE", this.detachPlaybackEngineEndedHandler(), this.currentStreamingSessionId = void 0, e || (this.preloadedStreamingSessionId = void 0);
189
+ this.debugLog("reset"), this.playbackState !== "IDLE" && this.finishCurrentMediaProduct("skip"), this.playbackState = "IDLE", this.detachPlaybackEngineEndedHandler(), this.currentStreamingSessionId = void 0, e || (this.preloadedStreamingSessionId = void 0);
200
190
  const { currentPlayer: i } = this;
201
191
  return i && i.readyState !== 0 && (i.load(), await new Promise(
202
192
  (t) => i.addEventListener("emptied", () => t(), { passive: !0 })
203
- )), this.#a = !0, Promise.resolve();
193
+ )), this.#i = !0, Promise.resolve();
204
194
  }
195
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
205
196
  seek(e) {
206
197
  this.debugLog("seek", e);
207
198
  const { currentPlayer: i } = this, t = e;
208
199
  if (i)
209
- return "fastSeek" in i ? i.fastSeek(t) : i.currentTime = t, new Promise((s) => {
200
+ return this.seekStart(this.currentTime), "fastSeek" in i ? i.fastSeek(t) : i.currentTime = t, new Promise((s) => {
210
201
  i.addEventListener("seeked", () => s(i.currentTime), {
211
202
  once: !0
212
203
  });
@@ -214,23 +205,21 @@ class f extends I {
214
205
  }
215
206
  // eslint-disable-next-line @typescript-eslint/require-await
216
207
  async skipToPreloadedMediaProduct() {
217
- const e = h.getMediaProductTransition(
208
+ const e = c.getMediaProductTransition(
218
209
  this.preloadedStreamingSessionId
219
210
  );
220
211
  if (!e) {
221
212
  this.playbackState = "NOT_PLAYING";
222
213
  return;
223
214
  }
224
- this.debugLog(
215
+ if (this.debugLog(
225
216
  "skipToPreloadedMediaProduct",
226
217
  this.preloadedStreamingSessionId
227
- );
228
- const i = this.#r();
229
- if (i) {
230
- this.currentPlayer = i, this.currentStreamingSessionId = String(this.preloadedStreamingSessionId), this.preloadedStreamingSessionId = void 0;
231
- const { mediaProduct: t, 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;
232
221
  S.dispatchEvent(
233
- p(t, s)
222
+ p(i, t)
234
223
  ), this.playbackState === "IDLE" && (this.playbackState = "NOT_PLAYING");
235
224
  }
236
225
  }
@@ -243,23 +232,23 @@ class f extends I {
243
232
  "unloadPreloadedMediaProduct",
244
233
  this.preloadedStreamingSessionId
245
234
  ), this.cleanUpStoredPreloadInfo();
246
- const e = this.#r();
235
+ const e = this.#a;
247
236
  e && (e.src = "", e.load());
248
237
  }
249
238
  get currentPlayer() {
250
239
  return this.#t;
251
240
  }
252
241
  set currentPlayer(e) {
253
- 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));
254
243
  }
255
244
  get mediaElement() {
256
245
  return this.currentPlayer ?? null;
257
246
  }
258
247
  get ready() {
259
- return this.#o;
248
+ return this.#d;
260
249
  }
261
250
  get volume() {
262
- return L("desiredVolumeLevel");
251
+ return E("desiredVolumeLevel");
263
252
  }
264
253
  set volume(e) {
265
254
  this.debugLog("Setting volume to", e), this.currentPlayer && (this.currentPlayer.volume = e);