@tidal-music/player-web-components 0.1.1 → 0.1.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.
@@ -1,5 +1,5 @@
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 { 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";
3
3
  class f extends I {
4
4
  #t;
5
5
  #i;
@@ -13,99 +13,92 @@ class f extends I {
13
13
  super(), this.playbackState = "IDLE";
14
14
  const e = () => {
15
15
  this.mediaElement && !this.mediaElement.paused && (this.playbackState = "PLAYING");
16
- }, i = (a) => {
17
- this.currentStreamingSessionId && a.target instanceof HTMLMediaElement && h.overwriteDuration(
16
+ }, t = (a) => {
17
+ this.currentStreamingSessionId && a.target instanceof HTMLMediaElement && c.overwriteDuration(
18
18
  this.currentStreamingSessionId,
19
19
  a.target.duration
20
20
  );
21
- }, t = () => {
21
+ }, i = () => {
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 k(1e3), a.currentTime !== a.duration))
27
+ if (this.preloadedStreamingSessionId && a.currentTime === a.duration && (await b(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
- durationChangeHandler: i,
43
+ durationChangeHandler: t,
46
44
  endedHandler: d,
47
45
  errorHandler: r,
48
46
  pauseHandler: s,
49
47
  playHandler: e,
50
48
  playingHandler: e,
51
49
  seekedHandler: o,
52
- seekingHandler: l,
53
- stalledHandler: t,
50
+ stalledHandler: i,
54
51
  timeUpdateHandler: n,
55
- waitingHandler: t
56
- }, P().then().catch(console.error), this.#i = y, this.#n = E, this.currentPlayer = this.#i;
52
+ waitingHandler: i
53
+ }, P().then().catch(console.error), this.#i = y, this.#n = L, this.currentPlayer = this.#i;
57
54
  }
58
55
  #r() {
59
56
  return [this.#i, this.#n].filter((e) => e !== this.#t).pop();
60
57
  }
61
- #d(e, i) {
58
+ #d(e, t) {
62
59
  this.debugLog(
63
60
  "mediaElementEvents",
64
- i ? "adding to" : "removing from",
61
+ t ? "adding to" : "removing from",
65
62
  e
66
63
  );
67
- const t = i ? "addEventListener" : "removeEventListener";
68
- e[t](
64
+ const i = t ? "addEventListener" : "removeEventListener";
65
+ e[i](
69
66
  "durationchange",
70
67
  this.#e.durationChangeHandler,
71
68
  {
72
69
  passive: !0
73
70
  }
74
- ), e[t]("play", this.#e.playHandler, {
71
+ ), e[i]("play", this.#e.playHandler, {
75
72
  passive: !0
76
- }), e[t](
73
+ }), e[i](
77
74
  "playing",
78
75
  this.#e.playingHandler,
79
76
  { passive: !0 }
80
- ), e[t](
77
+ ), e[i](
81
78
  "timeupdate",
82
79
  this.#e.timeUpdateHandler,
83
80
  { passive: !0 }
84
- ), e[t](
81
+ ), e[i](
85
82
  "pause",
86
83
  this.#e.pauseHandler,
87
84
  { passive: !0 }
88
- ), e[t](
85
+ ), e[i](
89
86
  "ended",
90
87
  this.#e.endedHandler,
91
88
  { passive: !0 }
92
- ), e[t](
89
+ ), e[i](
93
90
  "error",
94
91
  this.#e.errorHandler,
95
92
  { passive: !0 }
96
- ), e[t](
93
+ ), e[i](
97
94
  "waiting",
98
95
  this.#e.waitingHandler,
99
96
  { passive: !0 }
100
- ), e[t](
97
+ ), e[i](
101
98
  "stalled",
102
99
  this.#e.stalledHandler,
103
100
  { passive: !0 }
104
- ), e[t](
105
- "seeking",
106
- this.#e.seekingHandler,
107
- { passive: !0 }
108
- ), e[t](
101
+ ), e[i](
109
102
  "seeked",
110
103
  this.#e.seekedHandler,
111
104
  { passive: !0 }
@@ -114,67 +107,67 @@ class f extends I {
114
107
  getPosition() {
115
108
  return this.debugLog("getPosition"), this.mediaElement && (this.mediaElement.ended ? this.currentTime = 0 : this.currentTime = this.mediaElement.currentTime), this.currentTime;
116
109
  }
117
- 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");
119
- const { assetPosition: t, mediaProduct: s, playbackInfo: n, streamInfo: d } = e;
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;
120
113
  this.currentStreamingSessionId = d.streamingSessionId;
121
114
  const { currentPlayer: r } = this;
122
115
  if (!r)
123
116
  return;
124
- const l = new Promise(
125
- (u) => r.addEventListener("canplay", () => u(), {
117
+ const o = new Promise(
118
+ (h) => r.addEventListener("canplay", () => h(), {
126
119
  once: !0
127
120
  })
128
121
  );
129
- r.src = d.streamUrl, r.currentTime = t, r.load();
130
- const o = new Promise(
131
- (u) => r.addEventListener(
122
+ r.src = d.streamUrl, r.currentTime = i, r.load();
123
+ const a = new Promise(
124
+ (h) => r.addEventListener(
132
125
  "durationchange",
133
126
  (m) => {
134
- m.target instanceof HTMLMediaElement && u(m.target.duration);
127
+ m.target instanceof HTMLMediaElement && h(m.target.duration);
135
128
  },
136
129
  { once: !0 }
137
130
  )
138
131
  );
139
- if (await l, this.currentStreamingSessionId !== d.streamingSessionId)
132
+ if (await o, this.currentStreamingSessionId !== d.streamingSessionId)
140
133
  return;
141
- const a = await o, c = g({
142
- assetPosition: t,
143
- duration: a,
134
+ const l = await a, u = g({
135
+ assetPosition: i,
136
+ duration: l,
144
137
  playbackInfo: n,
145
138
  streamInfo: d
146
139
  });
147
- return h.saveMediaProductTransition(
140
+ return c.saveMediaProductTransition(
148
141
  d.streamingSessionId,
149
- { mediaProduct: s, playbackContext: c }
142
+ { mediaProduct: s, playbackContext: u }
150
143
  ), this.debugLog("dispatching mediaProductTransition"), S.dispatchEvent(
151
- p(s, c)
144
+ p(s, u)
152
145
  ), this.#s ? (this.#s = !1, this.play()) : Promise.resolve();
153
146
  }
154
147
  async next(e) {
155
148
  this.debugLog("next", e), this.playbackState === "IDLE" && (this.playbackState = "NOT_PLAYING");
156
- const { mediaProduct: i, playbackInfo: t, streamInfo: s } = e, n = this.#r();
149
+ const { mediaProduct: t, playbackInfo: i, streamInfo: s } = e, n = this.#r();
157
150
  if (this.preloadedStreamingSessionId = s.streamingSessionId, !n)
158
151
  return;
159
152
  n.src = s.streamUrl, n.load();
160
153
  const d = await new Promise(
161
- (l) => n.addEventListener(
154
+ (o) => n.addEventListener(
162
155
  "durationchange",
163
- (o) => {
164
- o.target instanceof HTMLMediaElement && l(o.target.duration);
156
+ (a) => {
157
+ a.target instanceof HTMLMediaElement && o(a.target.duration);
165
158
  },
166
159
  { once: !0 }
167
160
  )
168
161
  ), r = g({
169
162
  assetPosition: 0,
170
163
  duration: d,
171
- playbackInfo: t,
164
+ playbackInfo: i,
172
165
  streamInfo: s
173
166
  });
174
- h.saveMediaProductTransition(
167
+ c.saveMediaProductTransition(
175
168
  s.streamingSessionId,
176
169
  {
177
- mediaProduct: i,
170
+ mediaProduct: t,
178
171
  playbackContext: r
179
172
  }
180
173
  );
@@ -189,32 +182,32 @@ class f extends I {
189
182
  }
190
183
  async playbackEngineEndedHandler(e) {
191
184
  if (this.isActivePlayer) {
192
- const { reason: i } = e.detail;
193
- i === "completed" && (this.hasNextItem() ? (await this.skipToPreloadedMediaProduct(), await this.play()) : (console.warn("No item preloaded, not progressing."), this.playbackState = "NOT_PLAYING"));
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"));
194
187
  }
195
188
  }
196
189
  async reset({ keepPreload: e } = { keepPreload: !1 }) {
197
190
  if (this.#a)
198
191
  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);
200
- const { currentPlayer: i } = this;
201
- return i && i.readyState !== 0 && (i.load(), await new Promise(
202
- (t) => i.addEventListener("emptied", () => t(), { passive: !0 })
192
+ 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 })
203
196
  )), this.#a = !0, Promise.resolve();
204
197
  }
205
198
  seek(e) {
206
199
  this.debugLog("seek", e);
207
- const { currentPlayer: i } = this, t = e;
208
- if (i)
209
- return "fastSeek" in i ? i.fastSeek(t) : i.currentTime = t, new Promise((s) => {
210
- i.addEventListener("seeked", () => s(i.currentTime), {
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), {
211
204
  once: !0
212
205
  });
213
206
  });
214
207
  }
215
208
  // eslint-disable-next-line @typescript-eslint/require-await
216
209
  async skipToPreloadedMediaProduct() {
217
- const e = h.getMediaProductTransition(
210
+ const e = c.getMediaProductTransition(
218
211
  this.preloadedStreamingSessionId
219
212
  );
220
213
  if (!e) {
@@ -225,12 +218,12 @@ class f extends I {
225
218
  "skipToPreloadedMediaProduct",
226
219
  this.preloadedStreamingSessionId
227
220
  );
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;
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;
232
225
  S.dispatchEvent(
233
- p(t, s)
226
+ p(i, s)
234
227
  ), this.playbackState === "IDLE" && (this.playbackState = "NOT_PLAYING");
235
228
  }
236
229
  }
@@ -259,7 +252,7 @@ class f extends I {
259
252
  return this.#o;
260
253
  }
261
254
  get volume() {
262
- return L("desiredVolumeLevel");
255
+ return E("desiredVolumeLevel");
263
256
  }
264
257
  set volume(e) {
265
258
  this.debugLog("Setting volume to", e), this.currentPlayer && (this.currentPlayer.volume = e);