Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/nextjs/app/vimeo-video/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Page() {
<section>
<Player
as={VimeoVideo}
src="https://vimeo.com/648359100"
src="https://vimeo.com/76979871"
poster="https://i.vimeocdn.com/video/1539127996-82b8c8aeb7a7b2c51709cbef3bd0a5a3e0a96b191b3f1c9246c9b357c2ac7996-d_1280"
config={{
color: 'ffadef',
Expand Down
2 changes: 1 addition & 1 deletion packages/vimeo-video-element/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h1>&lt;vimeo-video&gt;</h1>
};

loadbtn.onclick = () => {
video.src = 'https://vimeo.com/638371504';
video.src = 'https://vimeo.com/76979871';
}

video.addEventListener('loadstart', (e) => {
Expand Down
14 changes: 14 additions & 0 deletions packages/vimeo-video-element/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ test('play promise', async function (t) {
t.ok(!video.paused, 'is playing after video.play()');
});

test('dispatches an error event when the video does not exist', async function (t) {
const video = await fixture(`<vimeo-video
src="https://vimeo.com/585758234/1ef30fd6da"
muted
></vimeo-video>`);

const event = await new Promise((resolve) => video.addEventListener('error', resolve, { once: true }));

t.ok(event instanceof ErrorEvent, 'is an ErrorEvent');
t.equal(event.error?.name, 'NotFoundError', 'carries the Vimeo error');
t.ok(event.message, 'has an error message');
t.equal(video.error, event.error, 'exposes the error via video.error');
});

function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
Expand Down
12 changes: 12 additions & 0 deletions packages/vimeo-video-element/vimeo-video-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class VimeoVideoElement extends MediaPlayedRangesMixin(globalThis.HTMLElement ??
#videoWidth = NaN;
#videoHeight = NaN;
#config = null;
#error = null;
/** Distinguishes a remount from SSR hydration.
* See load()
*/
Expand Down Expand Up @@ -167,6 +168,7 @@ class VimeoVideoElement extends MediaPlayedRangesMixin(globalThis.HTMLElement ??
this.#readyState = 0;
this.#videoWidth = NaN;
this.#videoHeight = NaN;
this.#error = null;
this.dispatchEvent(new Event('emptied'));

let oldApi = this.api;
Expand Down Expand Up @@ -279,10 +281,16 @@ class VimeoVideoElement extends MediaPlayedRangesMixin(globalThis.HTMLElement ??
#setupApiListeners() {
const textTracksVideo = document.createElement('video');
this.textTracks = textTracksVideo.textTracks;
this.api.ready().catch((error) => {
this.#error = error;
this.dispatchEvent(new ErrorEvent('error', { error, message: error?.message }));
});
Comment thread
spuppo-mux marked this conversation as resolved.
Resolved
Comment thread
spuppo-mux marked this conversation as resolved.
Resolved
this.api.getTextTracks().then((vimeoTracks) => {
vimeoTracks.forEach((t) => {
textTracksVideo.addTextTrack(t.kind, t.label, t.language);
});
}).catch(() => {
// getTextTracks() waits on ready(), so its rejection is already surfaced above.
});
this.textTracks.addEventListener('change', () => {
const active = Array.from(this.textTracks).find((t) => t.mode === 'showing');
Expand Down Expand Up @@ -424,6 +432,10 @@ class VimeoVideoElement extends MediaPlayedRangesMixin(globalThis.HTMLElement ??
return this.api?.pause();
}

get error() {
return this.#error;
}

get ended() {
return this.#currentTime >= this.#duration;
}
Expand Down
Loading