Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 74fcd1f

Browse files
authored
feat(video): updated to match new specs (#2452)
1 parent 9f857cb commit 74fcd1f

File tree

7 files changed

+1123
-114
lines changed

7 files changed

+1123
-114
lines changed

.changeset/giant-camels-accept.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ebay/ebayui-core": minor
3+
---
4+
5+
feat(video): updated to match new specs

src/components/ebay-video/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</span>
88
</h1>
99

10-
## ebay-video (_ALPHA_, some APIs might change)
10+
## ebay-video
1111

1212
Video player. Supports either MPD or M3U8 playlist formats.
1313
Natively uses dash.js player under the hood. Loads it async after the video player is loaded on the page.

src/components/ebay-video/component.ts

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import type { WithNormalizedProps } from "../../global";
44
import { getElements } from "./elements";
55
const DEFAULT_SPINNER_TIMEOUT = 2000;
66

7+
declare global {
8+
interface Window {
9+
shaka: any;
10+
}
11+
}
12+
713
const eventList = [
814
"abort",
915
"canplay",
@@ -29,14 +35,14 @@ const videoConfig = {
2935
addSeekBar: true,
3036
controlPanelElements: [
3137
"play_pause",
32-
"time_and_duration",
38+
"current_time",
3339
"spacer",
34-
"mute",
40+
"total_time",
41+
"captions",
42+
"mute_popover",
3543
"report",
36-
"fullscreen",
37-
"overflow_menu",
44+
"fullscreen_button",
3845
],
39-
overflowMenuButtons: ["captions"],
4046
};
4147

4248
export interface PlayPauseEvent {
@@ -57,7 +63,15 @@ interface VideoInput extends Omit<Marko.HTML.Video, `on${string}`> {
5763
"volume-slider"?: boolean;
5864
clip?: any[];
5965
source: Marko.AttrTag<Marko.HTML.Source>;
66+
/**
67+
* @deprecated Use `a11y-report-text` instead
68+
*/
6069
"report-text"?: AttrString;
70+
"a11y-report-text"?: AttrString;
71+
"a11y-mute-text"?: AttrString;
72+
"a11y-unmute-text"?: AttrString;
73+
"a11y-fullscreen-text"?: AttrString;
74+
"a11y-exit-fullscreen-text"?: AttrString;
6175
"spinner-timeout"?: number;
6276
thumbnail?: string;
6377
track?: Marko.AttrTag<Marko.HTML.Track>;
@@ -79,7 +93,6 @@ interface State {
7993
isLoaded: boolean;
8094
volumeSlider: boolean;
8195
action: "play" | "pause" | "";
82-
showLoading: boolean;
8396
}
8497

8598
class Video extends Marko.Component<Input, State> {
@@ -108,6 +121,24 @@ class Video extends Marko.Component<Input, State> {
108121
if (!this.input.width && this.video) {
109122
const { width: containerWidth } = this.root.getBoundingClientRect();
110123
this.containerEl.setAttribute("width", containerWidth.toString());
124+
this.alignSeekbar();
125+
}
126+
}
127+
128+
alignSeekbar() {
129+
if (this.el) {
130+
const buttonPanel = this.el.querySelector<HTMLElement>(
131+
".shaka-controls-button-panel",
132+
)!;
133+
const spacer = buttonPanel.querySelector(".shaka-spacer")!;
134+
const rangeContainer = this.el.querySelector<HTMLElement>(
135+
".shaka-range-container",
136+
)!;
137+
const buttonPanelRect = buttonPanel.getBoundingClientRect();
138+
const spacerRect = spacer.getBoundingClientRect();
139+
140+
rangeContainer.style.marginRight = `${buttonPanelRect.right - spacerRect.right}px`;
141+
rangeContainer.style.marginLeft = `${spacerRect.left - buttonPanelRect.left}px`;
111142
}
112143
}
113144

@@ -117,10 +148,12 @@ class Video extends Marko.Component<Input, State> {
117148
this.video.controls = false;
118149

119150
this.emit("pause", { originalEvent, player: this.player });
151+
this.alignSeekbar();
120152
}
121153

122154
handlePlaying(originalEvent: Event) {
123155
this.showControls();
156+
this.alignSeekbar();
124157

125158
if (this.input.playView === "fullscreen") {
126159
this.video.requestFullscreen();
@@ -197,7 +230,6 @@ class Video extends Marko.Component<Input, State> {
197230
this.state = {
198231
volumeSlider: false,
199232
action: "",
200-
showLoading: false,
201233
isLoaded: true,
202234
failed: false,
203235
played: false,
@@ -248,7 +280,14 @@ class Video extends Marko.Component<Input, State> {
248280
}
249281

250282
_attach() {
251-
const { Report, TextSelection } = getElements(this);
283+
const {
284+
Report,
285+
CurrentTime,
286+
TotalTime,
287+
MuteButton,
288+
FullscreenButton,
289+
TextSelection,
290+
} = getElements(this);
252291
// eslint-disable-next-line no-undef,new-cap
253292
this.ui = new this.shaka.ui.Overlay(
254293
this.player,
@@ -263,10 +302,31 @@ class Video extends Marko.Component<Input, State> {
263302
.changeLocale([document.documentElement.lang]);
264303
}
265304

305+
// eslint-disable-next-line no-undef,new-cap
306+
this.shaka.ui.Controls.registerElement("report", new Report.Factory());
307+
308+
// eslint-disable-next-line no-undef,new-cap
309+
this.shaka.ui.Controls.registerElement(
310+
"current_time",
311+
new CurrentTime.Factory(),
312+
);
313+
314+
// eslint-disable-next-line no-undef,new-cap
315+
this.shaka.ui.Controls.registerElement(
316+
"total_time",
317+
new TotalTime.Factory(),
318+
);
319+
320+
// eslint-disable-next-line no-undef,new-cap
321+
this.shaka.ui.Controls.registerElement(
322+
"mute_popover",
323+
new MuteButton.Factory(),
324+
);
325+
266326
// eslint-disable-next-line no-undef,new-cap
267327
this.shaka.ui.Controls.registerElement(
268-
"report",
269-
new Report.Factory(this.input.reportText),
328+
"fullscreen_button",
329+
new FullscreenButton.Factory(),
270330
);
271331

272332
// eslint-disable-next-line no-undef,new-cap
@@ -317,7 +377,7 @@ class Video extends Marko.Component<Input, State> {
317377
this.video = this.root.querySelector("video")!;
318378
this.containerEl = this.root.querySelector(".video-player__container")!;
319379
this.video.volume = this.input.volume || 1;
320-
this.video.muted = this.input.muted || false;
380+
this.video.muted = this.input.muted !== false;
321381

322382
this.subscribeTo(this.video)
323383
.on("playing", this.handlePlaying.bind(this))
@@ -345,10 +405,12 @@ class Video extends Marko.Component<Input, State> {
345405
shakaLoad()
346406
.then((shaka: any) => {
347407
this.shaka = shaka.default || shaka;
408+
window.shaka = this.shaka; // Set global object for some components to access
348409

349410
this.handleSuccess();
350411
})
351412
.catch((e: Error) => {
413+
console.log(e);
352414
this.handleError(e);
353415
});
354416
}

0 commit comments

Comments
 (0)