@v360-tech/v360-player 1.4.0 → 1.4.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,12 +1,12 @@
1
1
  import l from "hls.js";
2
2
  import a from "jquery";
3
- const t = {
3
+ const e = {
4
4
  None: "none",
5
5
  DualLayer: "dual-layer",
6
6
  Segments: "segments",
7
7
  MinimalWave: "minimal-wave"
8
8
  }, v = {
9
- [t.None]: `
9
+ [e.None]: `
10
10
  .progress-bar {
11
11
  flex: 1;
12
12
  height: 4px;
@@ -24,7 +24,7 @@ const t = {
24
24
  border-radius: 2px;
25
25
  }
26
26
  `,
27
- [t.DualLayer]: `
27
+ [e.DualLayer]: `
28
28
  .progress-bar {
29
29
  flex: 1;
30
30
  height: 8px;
@@ -67,7 +67,7 @@ const t = {
67
67
  transform: translateY(-50%) scale(1.2);
68
68
  }
69
69
  `,
70
- [t.Segments]: `
70
+ [e.Segments]: `
71
71
  .progress-bar {
72
72
  flex: 1;
73
73
  height: 4px;
@@ -105,7 +105,7 @@ const t = {
105
105
  background: #40A2FF;
106
106
  }
107
107
  `,
108
- [t.MinimalWave]: `
108
+ [e.MinimalWave]: `
109
109
  .progress-bar {
110
110
  flex: 1;
111
111
  height: 2px;
@@ -165,7 +165,7 @@ const t = {
165
165
  "speed-2.00": `<img src="${N}" width="24" height="24" alt="2x speed">`
166
166
  }, j = "X-Jewel-Store", D = "69d2c1660df6540944e25eb708fb252724ab27fb";
167
167
  class z extends HTMLElement {
168
- progressBarStyle = t.None;
168
+ progressBarStyle = e.None;
169
169
  _hls;
170
170
  _videoPlayer;
171
171
  background = "dark";
@@ -175,7 +175,7 @@ class z extends HTMLElement {
175
175
  return g / A * 100;
176
176
  }
177
177
  isValidProgressBarStyle(A) {
178
- return Object.values(t).includes(A);
178
+ return Object.values(e).includes(A);
179
179
  }
180
180
  // Import icons from dedicated file
181
181
  svgIcons = W;
@@ -200,7 +200,7 @@ class z extends HTMLElement {
200
200
  }
201
201
  attributeChangedCallback(A, g, I) {
202
202
  if (A === "progress-bar-style")
203
- this.progressBarStyle = this.isValidProgressBarStyle(I) ? I : t.None, this.render();
203
+ this.progressBarStyle = this.isValidProgressBarStyle(I) ? I : e.None, this.render();
204
204
  else if (A === "background")
205
205
  this.background = I === "light" ? "light" : "dark", this.updateControlsColor();
206
206
  else if (A === "aspect-ratio") {
@@ -219,26 +219,26 @@ class z extends HTMLElement {
219
219
  if (!A || !g) return;
220
220
  const I = () => {
221
221
  if (!this._videoPlayer) return;
222
- const i = this._videoPlayer.currentTime / this._videoPlayer.duration * 100;
223
- if (g.style.width = `${i}%`, this.progressBarStyle === t.Segments) {
224
- const e = this.shadowRoot?.querySelectorAll(".progress-segment");
225
- e && e.forEach((C, o) => {
226
- const n = (o + 1) * (100 / e.length);
227
- i >= n ? C.classList.add("filled") : C.classList.remove("filled");
222
+ const t = this._videoPlayer.currentTime / this._videoPlayer.duration * 100;
223
+ if (g.style.width = `${t}%`, this.progressBarStyle === e.Segments) {
224
+ const o = this.shadowRoot?.querySelectorAll(".progress-segment");
225
+ o && o.forEach((i, C) => {
226
+ const c = (C + 1) * (100 / o.length);
227
+ t >= c ? i.classList.add("filled") : i.classList.remove("filled");
228
228
  });
229
229
  }
230
230
  };
231
231
  this._videoPlayer.addEventListener("timeupdate", I);
232
- const s = (i) => {
233
- if (!this._videoPlayer || !(i instanceof MouseEvent)) return;
234
- const e = A.getBoundingClientRect(), C = Math.max(0, Math.min(1, (i.clientX - e.left) / e.width));
235
- this._videoPlayer.currentTime = C * this._videoPlayer.duration;
232
+ const s = (t) => {
233
+ if (!this._videoPlayer || !(t instanceof MouseEvent)) return;
234
+ const o = A.getBoundingClientRect(), i = Math.max(0, Math.min(1, (t.clientX - o.left) / o.width));
235
+ this._videoPlayer.currentTime = i * this._videoPlayer.duration;
236
236
  };
237
237
  A.addEventListener("click", s);
238
238
  }
239
239
  renderProgressBar() {
240
240
  switch (this.progressBarStyle) {
241
- case t.DualLayer:
241
+ case e.DualLayer:
242
242
  return `
243
243
  <div class="progress-bar">
244
244
  <div class="progress-bar-buffer"></div>
@@ -246,7 +246,7 @@ class z extends HTMLElement {
246
246
  <div class="progress-handle"></div>
247
247
  </div>
248
248
  `;
249
- case t.Segments:
249
+ case e.Segments:
250
250
  return `
251
251
  <div class="progress-bar">
252
252
  ${Array.from({ length: 20 }, (A, g) => `
@@ -254,14 +254,14 @@ class z extends HTMLElement {
254
254
  `).join("")}
255
255
  </div>
256
256
  `;
257
- case t.MinimalWave:
257
+ case e.MinimalWave:
258
258
  return `
259
259
  <div class="progress-bar">
260
260
  <div class="progress-bar-fill" style="width: 0%"></div>
261
261
  <div class="progress-wave"></div>
262
262
  </div>
263
263
  `;
264
- case t.None:
264
+ case e.None:
265
265
  default:
266
266
  return "";
267
267
  }
@@ -469,13 +469,13 @@ class z extends HTMLElement {
469
469
  async initializeHls(A, g) {
470
470
  return new Promise((I, s) => {
471
471
  try {
472
- const i = {
473
- debug: !0,
472
+ const o = {
473
+ // debug: true,
474
474
  enableWorker: !0,
475
475
  lowLatencyMode: !0,
476
476
  backBufferLength: 90,
477
- startLevel: -1,
478
- autoStartLoad: !0,
477
+ startLevel: parseInt(this.getAttribute("default-quality") || "-1"),
478
+ autoStartLoad: this.hasAttribute("auto-play"),
479
479
  manifestLoadingTimeOut: 2e4,
480
480
  manifestLoadingMaxRetry: 3,
481
481
  manifestLoadingRetryDelay: 500,
@@ -485,11 +485,11 @@ class z extends HTMLElement {
485
485
  fragLoadingTimeOut: 2e4,
486
486
  fragLoadingMaxRetry: 3,
487
487
  fragLoadingRetryDelay: 500,
488
- xhrSetup: (e) => {
489
- e.withCredentials = !1, e.setRequestHeader(j, D);
488
+ xhrSetup: (i) => {
489
+ i.withCredentials = !1, i.setRequestHeader(j, D);
490
490
  }
491
491
  };
492
- this._hls = new l(i), this._hls.on(l.Events.ERROR, (e, C) => {
492
+ this._hls = new l(o), this._hls.on(l.Events.ERROR, (i, C) => {
493
493
  if (console.error("HLS Error:", C), C.fatal)
494
494
  switch (C.type) {
495
495
  case l.ErrorTypes.NETWORK_ERROR:
@@ -504,26 +504,26 @@ class z extends HTMLElement {
504
504
  }
505
505
  }), this._hls.on(l.Events.MEDIA_ATTACHED, () => {
506
506
  console.log("Media attached, loading source:", g), this._hls?.loadSource(g);
507
- }), this._hls.on(l.Events.MANIFEST_PARSED, (e, C) => {
508
- console.log("Manifest parsed, levels:", C.levels), this.startListeners(), I(), this.hasAttribute("auto-play") && (console.log("Attempting autoplay..."), A.play().then(() => console.log("Playback started successfully")).catch(async (o) => {
509
- console.error("Autoplay failed:", o), A.muted = !0;
507
+ }), this._hls.on(l.Events.MANIFEST_PARSED, (i, C) => {
508
+ console.log("Manifest parsed, levels:", C.levels), this.startListeners(), I(), this.hasAttribute("auto-play") && (console.log("Attempting autoplay..."), A.play().then(() => console.log("Playback started successfully")).catch(async (c) => {
509
+ console.error("Autoplay failed:", c), A.muted = !0;
510
510
  try {
511
511
  await A.play(), console.log("Muted autoplay successful");
512
- } catch (n) {
513
- console.error("Muted autoplay also failed:", n);
512
+ } catch (d) {
513
+ console.error("Muted autoplay also failed:", d);
514
514
  }
515
515
  }));
516
516
  }), console.log("Attaching media element..."), this._hls.attachMedia(A);
517
- } catch (i) {
518
- console.error("Error in HLS initialization:", i), s(i);
517
+ } catch (t) {
518
+ console.error("Error in HLS initialization:", t), s(t);
519
519
  }
520
520
  });
521
521
  }
522
522
  startListeners() {
523
523
  if (!this.shadowRoot) return;
524
- const A = a(this.shadowRoot).find(".play"), g = a(this.shadowRoot).find(".pause"), I = a(this.shadowRoot).find(".forward"), s = a(this.shadowRoot).find(".backward"), i = a(this.shadowRoot).find(".fullscreen");
525
- if (A.on("click", () => this.play()), g.on("click", () => this.pause()), I.on("click", () => this.forward()), s.on("click", () => this.backward()), i.on("click", () => this.toggleFullscreen()), this._videoPlayer) {
526
- const e = a(this.shadowRoot).find(".duration"), C = a(this.shadowRoot).find(".progress-bar"), o = a(this.shadowRoot).find(".speed-container");
524
+ const A = a(this.shadowRoot).find(".play"), g = a(this.shadowRoot).find(".pause"), I = a(this.shadowRoot).find(".forward"), s = a(this.shadowRoot).find(".backward"), t = a(this.shadowRoot).find(".fullscreen");
525
+ if (A.on("click", () => this.play()), g.on("click", () => this.pause()), I.on("click", () => this.forward()), s.on("click", () => this.backward()), t.on("click", () => this.toggleFullscreen()), this._videoPlayer) {
526
+ const o = a(this.shadowRoot).find(".duration"), i = a(this.shadowRoot).find(".progress-bar"), C = a(this.shadowRoot).find(".speed-container");
527
527
  this._videoPlayer.addEventListener("play", () => {
528
528
  A.hide(), g.show();
529
529
  }), this._videoPlayer.addEventListener("pause", () => {
@@ -532,30 +532,30 @@ class z extends HTMLElement {
532
532
  if (!this._videoPlayer || !this.shadowRoot) return;
533
533
  const r = this._videoPlayer.currentTime, m = this._videoPlayer.duration, u = r / m * 100;
534
534
  if (this.hasAttribute("show-time-display")) {
535
- const h = this.shadowRoot.querySelector(".current-time");
536
- h && (h.textContent = this.formatTime(r));
535
+ const p = this.shadowRoot.querySelector(".current-time");
536
+ p && (p.textContent = this.formatTime(r));
537
537
  }
538
538
  const b = this.shadowRoot.querySelector(".progress-bar-fill");
539
- if (b instanceof HTMLElement && (b.style.width = `${u}%`), this.progressBarStyle === t.Segments) {
540
- const h = this.shadowRoot.querySelectorAll(".progress-segment");
541
- h.forEach((M, w) => {
542
- const y = (w + 1) * (100 / h.length);
539
+ if (b instanceof HTMLElement && (b.style.width = `${u}%`), this.progressBarStyle === e.Segments) {
540
+ const p = this.shadowRoot.querySelectorAll(".progress-segment");
541
+ p.forEach((M, w) => {
542
+ const y = (w + 1) * (100 / p.length);
543
543
  u >= y ? M.classList.add("filled") : M.classList.remove("filled");
544
544
  });
545
545
  }
546
546
  }), this._videoPlayer.addEventListener("loadedmetadata", () => {
547
- this.hasAttribute("show-time-display") && e.text(this.formatTime(this._videoPlayer.duration));
548
- }), C.on("click", (r) => {
547
+ this.hasAttribute("show-time-display") && o.text(this.formatTime(this._videoPlayer.duration));
548
+ }), i.on("click", (r) => {
549
549
  const m = r.currentTarget.getBoundingClientRect(), u = (r.clientX - m.left) / m.width;
550
550
  this._videoPlayer.currentTime = u * this._videoPlayer.duration;
551
551
  });
552
- const n = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2], p = this.getAttribute("playback-speeds")?.split(",").map(Number) || n, d = parseFloat(this.getAttribute("default-speed") || "1");
553
- let c = p.indexOf(d);
554
- c === -1 && (c = p.indexOf(1) || 0), d && !isNaN(d) && (this._videoPlayer.playbackRate = d, o.text(`${d}x`)), this.hasAttribute("show-speed-control") ? (o.show(), o.html(this.getSpeedIcon(d)), o.on("click", () => {
555
- c = (c + 1) % p.length;
556
- const r = p[c];
557
- this._videoPlayer.playbackRate = r, o.html(this.getSpeedIcon(r));
558
- })) : o.hide();
552
+ const c = [0.25, 0.5, 0.75, 1, 1.25, 1.5, 2], d = this.getAttribute("playback-speeds")?.split(",").map(Number) || c, n = parseFloat(this.getAttribute("default-speed") || "1");
553
+ let h = d.indexOf(n);
554
+ h === -1 && (h = d.indexOf(1) || 0), n && !isNaN(n) && (this._videoPlayer.playbackRate = n, C.text(`${n}x`)), this.hasAttribute("show-speed-control") ? (C.show(), C.html(this.getSpeedIcon(n)), C.on("click", () => {
555
+ h = (h + 1) % d.length;
556
+ const r = d[h];
557
+ this._videoPlayer.playbackRate = r, C.html(this.getSpeedIcon(r));
558
+ })) : C.hide();
559
559
  }
560
560
  }
561
561
  play() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@v360-tech/v360-player",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "description": "A lightweight, customizable HLS video player web component with built-in controls",
5
5
  "type": "module",
6
6
  "main": "dist/v360-player.browser.js",