@vidkit-cloud/player-vue 0.0.0-stage → 1.0.0-dev.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.
- package/LICENSE +21 -0
- package/README.md +104 -2
- package/dist/event-names.d.ts +15 -0
- package/dist/event-names.js +15 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +3 -0
- package/dist/internal/controller-of.d.ts +3 -0
- package/dist/internal/controller-of.js +9 -0
- package/dist/player-ref.d.ts +8 -0
- package/dist/player-ref.js +1 -0
- package/dist/use-vidkit-player.d.ts +9 -0
- package/dist/use-vidkit-player.js +31 -0
- package/dist/vidkit-player-controls.d.ts +19 -0
- package/dist/vidkit-player-controls.js +1 -0
- package/dist/vidkit-player.d.ts +162 -0
- package/dist/vidkit-player.js +83 -0
- package/package.json +70 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VidKit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vidkit-cloud/player-vue
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The [VidKit](https://vidkit.cloud) video player as a Vue component, with a composable for its methods and typed events.
|
|
4
|
+
|
|
5
|
+
```vue
|
|
6
|
+
<script setup lang="ts">
|
|
7
|
+
import { ref } from 'vue'
|
|
8
|
+
import { VidKitPlayer, useVidKitPlayer, type PlayerRef } from '@vidkit-cloud/player-vue'
|
|
9
|
+
|
|
10
|
+
const playerRef = ref<PlayerRef | null>(null)
|
|
11
|
+
const player = useVidKitPlayer(playerRef)
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<template>
|
|
15
|
+
<VidKitPlayer
|
|
16
|
+
ref="playerRef"
|
|
17
|
+
video-id="019a7e10-5b3c-7d21-a0f4-3e8b2c1d9f05"
|
|
18
|
+
muted
|
|
19
|
+
@ended="() => console.log('watched to the end')"
|
|
20
|
+
@error="(e) => console.warn(e.code)"
|
|
21
|
+
/>
|
|
22
|
+
<button :disabled="!player.isReady.value" @click="player.play()">Play</button>
|
|
23
|
+
</template>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Vue 3.3 and newer. The player itself is loaded from VidKit when the component mounts, so you get player updates and your team's branding without upgrading the package. It is built on [`@vidkit-cloud/player-js`](https://www.npmjs.com/package/@vidkit-cloud/player-js), whose README describes the options, events and errors in full.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm install @vidkit-cloud/player-vue
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## `<VidKitPlayer>`
|
|
35
|
+
|
|
36
|
+
It renders a `<div>` holding the player. Until the player is up, the `<div>` keeps the player's size, so nothing on the page moves. Classes and styles you give the component fall through to that `<div>`, never to the player's own element.
|
|
37
|
+
|
|
38
|
+
**Props.** Every option of `createPlayer`, with the same name and type; in templates, `video-id`, `aspect-ratio` and so on. Only `videoId` is required.
|
|
39
|
+
|
|
40
|
+
| Prop | Type | What it does |
|
|
41
|
+
| ---------------- | ------------------------ | ----------------------------------------------------------------------------------------- |
|
|
42
|
+
| `videoId` | `string` | The video to play. |
|
|
43
|
+
| `autoplay` | `boolean` | Start playing at once. Such a start is muted, as browsers require. |
|
|
44
|
+
| `muted` | `boolean` | Start without sound. |
|
|
45
|
+
| `loop` | `boolean` | Play again from the beginning at the end. |
|
|
46
|
+
| `start` | `number` | Where the first play starts, in seconds. |
|
|
47
|
+
| `aspectRatio` | `string` or `number` | The player's shape: `"16:9"`, or width divided by height. |
|
|
48
|
+
| `controlsLayout` | `"islands"`, `"classic"` | How the controls are laid out. |
|
|
49
|
+
| `color` | `string` | The accent colour, as `#rrggbb`. |
|
|
50
|
+
| `hideTitle` | `boolean` | Show no title on the poster. |
|
|
51
|
+
| `playerVersion` | `string` | Pins the player to one version, like `"1.2.0"`. Leave it out to get every player release. |
|
|
52
|
+
| `playerUrl` | `string` | Where the player script is loaded from. The first player on a page decides it. |
|
|
53
|
+
|
|
54
|
+
A setting you leave out keeps what the video was published with in VidKit. `autoplay`, `muted`, `loop` and `hideTitle` can only be switched on: `false` is the same as leaving them out.
|
|
55
|
+
|
|
56
|
+
**Events.** Each carries its event's payload, and every payload is an object.
|
|
57
|
+
|
|
58
|
+
| Event | Payload | When |
|
|
59
|
+
| ----------------- | ----------------------------------- | ---------------------------------------------------------------- |
|
|
60
|
+
| `ready` | `{ videoId, playerVersion }` | The player is up; again after a call-to-action swaps a video in. |
|
|
61
|
+
| `error` | `{ code, message, fatal, videoId }` | The start failed, or playback failed. Check `fatal`. |
|
|
62
|
+
| `play` | `{ cause }` | Playback starts: `"autoplay"`, `"user"` or `"programmatic"`. |
|
|
63
|
+
| `pause` | `{}` | |
|
|
64
|
+
| `ended` | `{}` | |
|
|
65
|
+
| `time-update` | `{ currentTime }` | About four times a second while playing. |
|
|
66
|
+
| `duration-change` | `{ duration }` | The duration became known, or changed. |
|
|
67
|
+
| `waiting` | `{}` | Playback stalled to buffer. |
|
|
68
|
+
| `playing` | `{}` | Playback is moving again after a start or a stall. |
|
|
69
|
+
| `rate-change` | `{ playbackRate }` | The speed changed. |
|
|
70
|
+
| `volume-change` | `{ volume, muted }` | |
|
|
71
|
+
| `video-change` | `{ videoId, previousVideoId }` | A call-to-action swapped another video into the player. |
|
|
72
|
+
|
|
73
|
+
**Changing props.**
|
|
74
|
+
|
|
75
|
+
- A new `videoId` replaces the player with one for that video, in the same `<div>`.
|
|
76
|
+
- A new `loop`, `aspectRatio` or `controlsLayout` goes to the running player.
|
|
77
|
+
- Any other change is ignored, with a warning in development. A new `color` is among them for now: set it when the player is created.
|
|
78
|
+
|
|
79
|
+
**Template ref.** It holds a `PlayerRef`: the player's methods, getters and `on`/`off`, as `createPlayer` returns them. It stays the same object when a new `videoId` replaces the player, and is `null` before the component mounts.
|
|
80
|
+
|
|
81
|
+
**`<KeepAlive>`.** Deactivating the component pauses the player and keeps it; only unmounting removes it.
|
|
82
|
+
|
|
83
|
+
## `useVidKitPlayer(playerRef)`
|
|
84
|
+
|
|
85
|
+
- **`isReady: Ref<boolean>`**: whether the player is up.
|
|
86
|
+
- **`error: Ref<PlayerError | null>`**: what the player is failing with, or `null`. A failure the player is still retrying (`fatal: false`) clears when playback moves again.
|
|
87
|
+
- **`play()`, `pause()`, `seek(seconds)`, `setVolume(volume)`, `setMuted(muted)`, `setPlaybackRate(rate)`**: they act on the player the ref holds now, and do nothing before it is up.
|
|
88
|
+
|
|
89
|
+
It holds no `currentTime`, which would change four times a second. Listen to `@time-update`, or read `playerRef.value?.currentTime`.
|
|
90
|
+
|
|
91
|
+
## Server rendering (Nuxt)
|
|
92
|
+
|
|
93
|
+
On a server the component renders only the `<div>`, with the player's size reserved. The player is created in the browser after hydration, with no hydration warning.
|
|
94
|
+
|
|
95
|
+
## Errors
|
|
96
|
+
|
|
97
|
+
The `error` event and `error` carry the codes of `@vidkit-cloud/player-js`: `video_not_found`, `video_not_ready`, `loader_unavailable` and the others. A failed start leaves the `<div>` empty and its size reserved: the component draws no error screen, so you decide what to show. Removing the component while the player starts is not an error, and emits nothing.
|
|
98
|
+
|
|
99
|
+
## Types
|
|
100
|
+
|
|
101
|
+
`PlayerRef`, `VidKitPlayerControls`, and from `@vidkit-cloud/player-js`: `Player`, `PlayerOptions`, `PlayerEvent`, `PlayerEventMap`, `PlayerError`, `PlayerErrorCode`, `PlayerErrorPayload`.
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The name `<VidKitPlayer>` emits each event of the player under. */
|
|
2
|
+
export declare const EVENT_NAMES: {
|
|
3
|
+
readonly ready: "ready";
|
|
4
|
+
readonly error: "error";
|
|
5
|
+
readonly play: "play";
|
|
6
|
+
readonly pause: "pause";
|
|
7
|
+
readonly ended: "ended";
|
|
8
|
+
readonly timeupdate: "time-update";
|
|
9
|
+
readonly durationchange: "duration-change";
|
|
10
|
+
readonly waiting: "waiting";
|
|
11
|
+
readonly playing: "playing";
|
|
12
|
+
readonly ratechange: "rate-change";
|
|
13
|
+
readonly volumechange: "volume-change";
|
|
14
|
+
readonly videochange: "video-change";
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The name `<VidKitPlayer>` emits each event of the player under. */
|
|
2
|
+
export const EVENT_NAMES = {
|
|
3
|
+
ready: 'ready',
|
|
4
|
+
error: 'error',
|
|
5
|
+
play: 'play',
|
|
6
|
+
pause: 'pause',
|
|
7
|
+
ended: 'ended',
|
|
8
|
+
timeupdate: 'time-update',
|
|
9
|
+
durationchange: 'duration-change',
|
|
10
|
+
waiting: 'waiting',
|
|
11
|
+
playing: 'playing',
|
|
12
|
+
ratechange: 'rate-change',
|
|
13
|
+
volumechange: 'volume-change',
|
|
14
|
+
videochange: 'video-change',
|
|
15
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { VidKitPlayer } from './vidkit-player.js';
|
|
2
|
+
export { useVidKitPlayer } from './use-vidkit-player.js';
|
|
3
|
+
export { PlayerError } from '@vidkit-cloud/player-js';
|
|
4
|
+
export type { PlayerRef } from './player-ref.js';
|
|
5
|
+
export type { VidKitPlayerControls } from './vidkit-player-controls.js';
|
|
6
|
+
export type { Player, PlayerErrorCode, PlayerErrorPayload, PlayerEvent, PlayerEventMap, PlayerOptions, } from '@vidkit-cloud/player-js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The controller a `PlayerRef` holds, or `null` when it holds none. */
|
|
2
|
+
export function controllerOf(value) {
|
|
3
|
+
if (!value || typeof value !== 'object')
|
|
4
|
+
return null;
|
|
5
|
+
const candidate = value;
|
|
6
|
+
return typeof candidate.subscribe === 'function' && typeof candidate.attach === 'function'
|
|
7
|
+
? value
|
|
8
|
+
: null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Player } from '@vidkit-cloud/player-js';
|
|
2
|
+
/**
|
|
3
|
+
* What a template ref on `<VidKitPlayer>` holds: the `Player`, with its
|
|
4
|
+
* methods, getters and `on`/`off`. It stays the same object when a new
|
|
5
|
+
* `videoId` replaces the player behind it. `null` before the component has
|
|
6
|
+
* mounted.
|
|
7
|
+
*/
|
|
8
|
+
export type PlayerRef = Player;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import type { PlayerRef } from './player-ref.js';
|
|
3
|
+
import type { VidKitPlayerControls } from './vidkit-player-controls.js';
|
|
4
|
+
/**
|
|
5
|
+
* The state and the methods of the player behind a `<VidKitPlayer>`'s
|
|
6
|
+
* template ref. It holds no `currentTime`, which would change four times a
|
|
7
|
+
* second: listen to `@time-update`, or read `playerRef.value?.currentTime`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useVidKitPlayer(playerRef: Ref<PlayerRef | null>): VidKitPlayerControls;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ref, shallowRef, watch } from 'vue';
|
|
2
|
+
import { controllerOf } from './internal/controller-of.js';
|
|
3
|
+
/**
|
|
4
|
+
* The state and the methods of the player behind a `<VidKitPlayer>`'s
|
|
5
|
+
* template ref. It holds no `currentTime`, which would change four times a
|
|
6
|
+
* second: listen to `@time-update`, or read `playerRef.value?.currentTime`.
|
|
7
|
+
*/
|
|
8
|
+
export function useVidKitPlayer(playerRef) {
|
|
9
|
+
const isReady = ref(false);
|
|
10
|
+
const error = shallowRef(null);
|
|
11
|
+
watch(playerRef, (value, _previous, onCleanup) => {
|
|
12
|
+
const controller = controllerOf(value);
|
|
13
|
+
const sync = () => {
|
|
14
|
+
isReady.value = controller?.isReady ?? false;
|
|
15
|
+
error.value = controller?.error ?? null;
|
|
16
|
+
};
|
|
17
|
+
sync();
|
|
18
|
+
if (controller)
|
|
19
|
+
onCleanup(controller.subscribe(sync));
|
|
20
|
+
}, { immediate: true, flush: 'post' });
|
|
21
|
+
return {
|
|
22
|
+
isReady,
|
|
23
|
+
error,
|
|
24
|
+
play: () => playerRef.value?.play() ?? Promise.resolve(),
|
|
25
|
+
pause: () => playerRef.value?.pause(),
|
|
26
|
+
seek: (seconds) => playerRef.value?.seek(seconds),
|
|
27
|
+
setVolume: (volume) => playerRef.value?.setVolume(volume),
|
|
28
|
+
setMuted: (muted) => playerRef.value?.setMuted(muted),
|
|
29
|
+
setPlaybackRate: (rate) => playerRef.value?.setPlaybackRate(rate),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PlayerError } from '@vidkit-cloud/player-js';
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
|
+
/** What `useVidKitPlayer` returns. */
|
|
4
|
+
export interface VidKitPlayerControls {
|
|
5
|
+
/** Whether the player is up. */
|
|
6
|
+
isReady: Ref<boolean>;
|
|
7
|
+
/**
|
|
8
|
+
* What the player is failing with, or `null`. A failure the player is
|
|
9
|
+
* still retrying clears when playback moves again.
|
|
10
|
+
*/
|
|
11
|
+
error: Ref<PlayerError | null>;
|
|
12
|
+
/** These act on the player the ref holds now, and do nothing before it is up. */
|
|
13
|
+
play(): Promise<void>;
|
|
14
|
+
pause(): void;
|
|
15
|
+
seek(seconds: number): void;
|
|
16
|
+
setVolume(volume: number): void;
|
|
17
|
+
setMuted(muted: boolean): void;
|
|
18
|
+
setPlaybackRate(rate: number): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { type PlayerEventMap } from '@vidkit-cloud/player-js';
|
|
2
|
+
import { type PropType } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* The VidKit player. It renders a `<div>` holding the player, with the
|
|
5
|
+
* player's size reserved until it is up, so nothing on the page moves.
|
|
6
|
+
* Classes and styles given to it fall through to that `<div>`.
|
|
7
|
+
*
|
|
8
|
+
* - A new `videoId` replaces the player with one for that video.
|
|
9
|
+
* - A new value of a live option (`loop`, `aspectRatio`, `controlsLayout`)
|
|
10
|
+
* goes to the running player; other changes are ignored, with a warning in
|
|
11
|
+
* development.
|
|
12
|
+
* - Under `<KeepAlive>`, deactivating pauses the player and keeps it.
|
|
13
|
+
* - On a server it renders only the `<div>`; the player is created in the
|
|
14
|
+
* browser, after the page has hydrated.
|
|
15
|
+
*/
|
|
16
|
+
export declare const VidKitPlayer: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
17
|
+
readonly videoId: {
|
|
18
|
+
readonly type: StringConstructor;
|
|
19
|
+
readonly required: true;
|
|
20
|
+
};
|
|
21
|
+
readonly autoplay: {
|
|
22
|
+
readonly type: BooleanConstructor;
|
|
23
|
+
readonly default: undefined;
|
|
24
|
+
};
|
|
25
|
+
readonly muted: {
|
|
26
|
+
readonly type: BooleanConstructor;
|
|
27
|
+
readonly default: undefined;
|
|
28
|
+
};
|
|
29
|
+
readonly loop: {
|
|
30
|
+
readonly type: BooleanConstructor;
|
|
31
|
+
readonly default: undefined;
|
|
32
|
+
};
|
|
33
|
+
readonly start: {
|
|
34
|
+
readonly type: NumberConstructor;
|
|
35
|
+
readonly default: undefined;
|
|
36
|
+
};
|
|
37
|
+
readonly aspectRatio: {
|
|
38
|
+
readonly type: PropType<string | number>;
|
|
39
|
+
readonly default: undefined;
|
|
40
|
+
};
|
|
41
|
+
readonly controlsLayout: {
|
|
42
|
+
readonly type: PropType<"islands" | "classic">;
|
|
43
|
+
readonly default: undefined;
|
|
44
|
+
};
|
|
45
|
+
readonly color: {
|
|
46
|
+
readonly type: StringConstructor;
|
|
47
|
+
readonly default: undefined;
|
|
48
|
+
};
|
|
49
|
+
readonly hideTitle: {
|
|
50
|
+
readonly type: BooleanConstructor;
|
|
51
|
+
readonly default: undefined;
|
|
52
|
+
};
|
|
53
|
+
readonly playerVersion: {
|
|
54
|
+
readonly type: StringConstructor;
|
|
55
|
+
readonly default: undefined;
|
|
56
|
+
};
|
|
57
|
+
readonly playerUrl: {
|
|
58
|
+
readonly type: StringConstructor;
|
|
59
|
+
readonly default: undefined;
|
|
60
|
+
};
|
|
61
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
64
|
+
ready: (_payload: PlayerEventMap["ready"]) => true;
|
|
65
|
+
error: (_payload: PlayerEventMap["error"]) => true;
|
|
66
|
+
play: (_payload: PlayerEventMap["play"]) => true;
|
|
67
|
+
pause: (_payload: PlayerEventMap["pause"]) => true;
|
|
68
|
+
ended: (_payload: PlayerEventMap["ended"]) => true;
|
|
69
|
+
'time-update': (_payload: PlayerEventMap["timeupdate"]) => true;
|
|
70
|
+
'duration-change': (_payload: PlayerEventMap["durationchange"]) => true;
|
|
71
|
+
waiting: (_payload: PlayerEventMap["waiting"]) => true;
|
|
72
|
+
playing: (_payload: PlayerEventMap["playing"]) => true;
|
|
73
|
+
'rate-change': (_payload: PlayerEventMap["ratechange"]) => true;
|
|
74
|
+
'volume-change': (_payload: PlayerEventMap["volumechange"]) => true;
|
|
75
|
+
'video-change': (_payload: PlayerEventMap["videochange"]) => true;
|
|
76
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
77
|
+
readonly videoId: {
|
|
78
|
+
readonly type: StringConstructor;
|
|
79
|
+
readonly required: true;
|
|
80
|
+
};
|
|
81
|
+
readonly autoplay: {
|
|
82
|
+
readonly type: BooleanConstructor;
|
|
83
|
+
readonly default: undefined;
|
|
84
|
+
};
|
|
85
|
+
readonly muted: {
|
|
86
|
+
readonly type: BooleanConstructor;
|
|
87
|
+
readonly default: undefined;
|
|
88
|
+
};
|
|
89
|
+
readonly loop: {
|
|
90
|
+
readonly type: BooleanConstructor;
|
|
91
|
+
readonly default: undefined;
|
|
92
|
+
};
|
|
93
|
+
readonly start: {
|
|
94
|
+
readonly type: NumberConstructor;
|
|
95
|
+
readonly default: undefined;
|
|
96
|
+
};
|
|
97
|
+
readonly aspectRatio: {
|
|
98
|
+
readonly type: PropType<string | number>;
|
|
99
|
+
readonly default: undefined;
|
|
100
|
+
};
|
|
101
|
+
readonly controlsLayout: {
|
|
102
|
+
readonly type: PropType<"islands" | "classic">;
|
|
103
|
+
readonly default: undefined;
|
|
104
|
+
};
|
|
105
|
+
readonly color: {
|
|
106
|
+
readonly type: StringConstructor;
|
|
107
|
+
readonly default: undefined;
|
|
108
|
+
};
|
|
109
|
+
readonly hideTitle: {
|
|
110
|
+
readonly type: BooleanConstructor;
|
|
111
|
+
readonly default: undefined;
|
|
112
|
+
};
|
|
113
|
+
readonly playerVersion: {
|
|
114
|
+
readonly type: StringConstructor;
|
|
115
|
+
readonly default: undefined;
|
|
116
|
+
};
|
|
117
|
+
readonly playerUrl: {
|
|
118
|
+
readonly type: StringConstructor;
|
|
119
|
+
readonly default: undefined;
|
|
120
|
+
};
|
|
121
|
+
}>> & Readonly<{
|
|
122
|
+
onReady?: ((_payload: {
|
|
123
|
+
videoId: string;
|
|
124
|
+
playerVersion: string;
|
|
125
|
+
}) => any) | undefined;
|
|
126
|
+
onError?: ((_payload: import("@vidkit-cloud/player-js").PlayerErrorPayload) => any) | undefined;
|
|
127
|
+
onPlay?: ((_payload: {
|
|
128
|
+
cause: "autoplay" | "user" | "programmatic";
|
|
129
|
+
}) => any) | undefined;
|
|
130
|
+
onPause?: ((_payload: Record<string, never>) => any) | undefined;
|
|
131
|
+
onEnded?: ((_payload: Record<string, never>) => any) | undefined;
|
|
132
|
+
onWaiting?: ((_payload: Record<string, never>) => any) | undefined;
|
|
133
|
+
onPlaying?: ((_payload: Record<string, never>) => any) | undefined;
|
|
134
|
+
"onTime-update"?: ((_payload: {
|
|
135
|
+
currentTime: number;
|
|
136
|
+
}) => any) | undefined;
|
|
137
|
+
"onDuration-change"?: ((_payload: {
|
|
138
|
+
duration: number;
|
|
139
|
+
}) => any) | undefined;
|
|
140
|
+
"onRate-change"?: ((_payload: {
|
|
141
|
+
playbackRate: number;
|
|
142
|
+
}) => any) | undefined;
|
|
143
|
+
"onVolume-change"?: ((_payload: {
|
|
144
|
+
volume: number;
|
|
145
|
+
muted: boolean;
|
|
146
|
+
}) => any) | undefined;
|
|
147
|
+
"onVideo-change"?: ((_payload: {
|
|
148
|
+
videoId: string;
|
|
149
|
+
previousVideoId: string;
|
|
150
|
+
}) => any) | undefined;
|
|
151
|
+
}>, {
|
|
152
|
+
readonly autoplay: boolean;
|
|
153
|
+
readonly muted: boolean;
|
|
154
|
+
readonly loop: boolean;
|
|
155
|
+
readonly start: number;
|
|
156
|
+
readonly aspectRatio: string | number;
|
|
157
|
+
readonly controlsLayout: "islands" | "classic";
|
|
158
|
+
readonly color: string;
|
|
159
|
+
readonly hideTitle: boolean;
|
|
160
|
+
readonly playerVersion: string;
|
|
161
|
+
readonly playerUrl: string;
|
|
162
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createPlayerController, reservedBoxStyle, } from '@vidkit-cloud/player-js';
|
|
2
|
+
import { defineComponent, h, onBeforeUnmount, onDeactivated, onMounted, ref, watch, } from 'vue';
|
|
3
|
+
import { EVENT_NAMES } from './event-names.js';
|
|
4
|
+
const EVENTS = Object.keys(EVENT_NAMES);
|
|
5
|
+
// Every option of createPlayer, with its type. A boolean left out stays
|
|
6
|
+
// `undefined`, so the video keeps what it was published with.
|
|
7
|
+
const props = {
|
|
8
|
+
videoId: { type: String, required: true },
|
|
9
|
+
autoplay: { type: Boolean, default: undefined },
|
|
10
|
+
muted: { type: Boolean, default: undefined },
|
|
11
|
+
loop: { type: Boolean, default: undefined },
|
|
12
|
+
start: { type: Number, default: undefined },
|
|
13
|
+
aspectRatio: { type: [String, Number], default: undefined },
|
|
14
|
+
controlsLayout: { type: String, default: undefined },
|
|
15
|
+
color: { type: String, default: undefined },
|
|
16
|
+
hideTitle: { type: Boolean, default: undefined },
|
|
17
|
+
playerVersion: { type: String, default: undefined },
|
|
18
|
+
playerUrl: { type: String, default: undefined },
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The VidKit player. It renders a `<div>` holding the player, with the
|
|
22
|
+
* player's size reserved until it is up, so nothing on the page moves.
|
|
23
|
+
* Classes and styles given to it fall through to that `<div>`.
|
|
24
|
+
*
|
|
25
|
+
* - A new `videoId` replaces the player with one for that video.
|
|
26
|
+
* - A new value of a live option (`loop`, `aspectRatio`, `controlsLayout`)
|
|
27
|
+
* goes to the running player; other changes are ignored, with a warning in
|
|
28
|
+
* development.
|
|
29
|
+
* - Under `<KeepAlive>`, deactivating pauses the player and keeps it.
|
|
30
|
+
* - On a server it renders only the `<div>`; the player is created in the
|
|
31
|
+
* browser, after the page has hydrated.
|
|
32
|
+
*/
|
|
33
|
+
export const VidKitPlayer = defineComponent({
|
|
34
|
+
name: 'VidKitPlayer',
|
|
35
|
+
props,
|
|
36
|
+
emits: {
|
|
37
|
+
ready: (_payload) => true,
|
|
38
|
+
error: (_payload) => true,
|
|
39
|
+
play: (_payload) => true,
|
|
40
|
+
pause: (_payload) => true,
|
|
41
|
+
ended: (_payload) => true,
|
|
42
|
+
'time-update': (_payload) => true,
|
|
43
|
+
'duration-change': (_payload) => true,
|
|
44
|
+
waiting: (_payload) => true,
|
|
45
|
+
playing: (_payload) => true,
|
|
46
|
+
'rate-change': (_payload) => true,
|
|
47
|
+
'volume-change': (_payload) => true,
|
|
48
|
+
'video-change': (_payload) => true,
|
|
49
|
+
},
|
|
50
|
+
setup(given, { emit, expose }) {
|
|
51
|
+
const controller = createPlayerController();
|
|
52
|
+
const box = ref(null);
|
|
53
|
+
const isReady = ref(false);
|
|
54
|
+
const unsubscribe = controller.subscribe(() => {
|
|
55
|
+
isReady.value = controller.isReady;
|
|
56
|
+
});
|
|
57
|
+
const offs = EVENTS.map((event) => controller.on(event, (payload) => emit(EVENT_NAMES[event], payload)));
|
|
58
|
+
const options = () => {
|
|
59
|
+
const out = {};
|
|
60
|
+
for (const [name, value] of Object.entries(given)) {
|
|
61
|
+
if (value !== undefined)
|
|
62
|
+
out[name] = value;
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
};
|
|
66
|
+
onMounted(() => {
|
|
67
|
+
if (box.value)
|
|
68
|
+
controller.attach(box.value, options());
|
|
69
|
+
});
|
|
70
|
+
watch(options, (next) => controller.update(next));
|
|
71
|
+
onDeactivated(() => controller.pause());
|
|
72
|
+
onBeforeUnmount(() => {
|
|
73
|
+
controller.detach();
|
|
74
|
+
unsubscribe();
|
|
75
|
+
offs.forEach((off) => off());
|
|
76
|
+
});
|
|
77
|
+
expose(controller);
|
|
78
|
+
return () => h('div', {
|
|
79
|
+
ref: box,
|
|
80
|
+
style: isReady.value ? undefined : reservedBoxStyle(given.aspectRatio),
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vidkit-cloud/player-vue",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0-dev.2",
|
|
4
|
+
"description": "The VidKit video player as a Vue component, with a composable for its methods and typed events",
|
|
5
|
+
"author": "VidKit",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://vidkit.cloud",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"vidkit",
|
|
10
|
+
"video",
|
|
11
|
+
"player",
|
|
12
|
+
"vue",
|
|
13
|
+
"hls"
|
|
14
|
+
],
|
|
15
|
+
"private": false,
|
|
16
|
+
"type": "module",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"module": "./dist/index.js",
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"dev": "vitest",
|
|
33
|
+
"build": "tsc -p tsconfig.build.json",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"lint": "eslint .",
|
|
36
|
+
"format": "prettier --write .",
|
|
37
|
+
"format:check": "prettier --check .",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"test:watch": "vitest",
|
|
40
|
+
"test:cov": "vitest run --coverage",
|
|
41
|
+
"verify:package": "node scripts/verify-package.cjs",
|
|
42
|
+
"check-branch-name": "bash .husky/scripts/check-branch-name.sh",
|
|
43
|
+
"prepare": "husky",
|
|
44
|
+
"release": "semantic-release"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@vidkit-cloud/player-js": "^1.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"vue": "^3.3.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@commitlint/cli": "^21.3.0",
|
|
54
|
+
"@commitlint/config-conventional": "^21.3.0",
|
|
55
|
+
"@eslint/js": "^10.0.1",
|
|
56
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
57
|
+
"@semantic-release/github": "^12.0.11",
|
|
58
|
+
"@semantic-release/release-notes-generator": "^14.1.1",
|
|
59
|
+
"@vitest/coverage-v8": "^4.1.12",
|
|
60
|
+
"@vue/test-utils": "^2.6.0",
|
|
61
|
+
"eslint": "^10.16.0",
|
|
62
|
+
"globals": "^17.14.0",
|
|
63
|
+
"husky": "^9.1.7",
|
|
64
|
+
"jsdom": "^31.0.1",
|
|
65
|
+
"prettier": "^3.10.1",
|
|
66
|
+
"semantic-release": "^25.0.9",
|
|
67
|
+
"typescript": "^6.0.3",
|
|
68
|
+
"typescript-eslint": "^8.74.0",
|
|
69
|
+
"vitest": "^4.1.12",
|
|
70
|
+
"vue": "^3.5.46"
|
|
71
|
+
}
|
|
72
|
+
}
|