Skip to content

Commit 4fa3346

Browse files
feat: SNI-6834 add basic vue video component
1 parent ca52699 commit 4fa3346

3 files changed

Lines changed: 88 additions & 11 deletions

File tree

packages/vue/sampleApp/App.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
<template>
22
<div>
3+
<h1>AdvancedVideo</h1>
4+
<AdvancedVideo :cldVid="cldVid" />
5+
<h1>AdvancedImage</h1>
36
<AdvancedImage :cldImg="cldImg" :plugins="plugins" />
47
</div>
58
</template>
69

710
<script lang="ts">
811
import { defineComponent } from "vue";
9-
import { AdvancedImage, responsive } from "../dist";
12+
import { AdvancedImage, AdvancedVideo, responsive } from "../dist";
1013
import { CloudinaryImage } from "@cloudinary/url-gen/assets/CloudinaryImage";
14+
import { CloudinaryVideo } from "@cloudinary/url-gen/assets/CloudinaryVideo";
1115
1216
export default defineComponent({
1317
name: "App",
1418
components: {
1519
AdvancedImage,
20+
AdvancedVideo,
1621
},
1722
setup(props) {
1823
const cldImg = new CloudinaryImage(
@@ -21,10 +26,17 @@ export default defineComponent({
2126
{ analytics: false }
2227
);
2328
29+
const cldVid = new CloudinaryVideo(
30+
"docs/walking_talking",
31+
{ cloudName: "demo" },
32+
{ analytics: false }
33+
);
34+
2435
const plugins = [responsive({ steps: 100 })];
2536
2637
return {
2738
cldImg,
39+
cldVid,
2840
plugins,
2941
};
3042
},
Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,79 @@
11
<template>
2-
<video :src="url" />
2+
<video ref="videoRef" />
33
</template>
44

5-
<script lang="ts">
6-
import { defineComponent } from "vue";
5+
<script setup lang="ts">
6+
// import { defineComponent } from "vue";
77
8-
export default defineComponent({
9-
name: "AdvancedVideo",
10-
props: {
11-
url: String,
12-
},
8+
// export default defineComponent({
9+
// name: "AdvancedVideo",
10+
// props: {
11+
// url: String,
12+
// },
13+
// });
14+
15+
/**
16+
* @memberOf CloudinaryVueSDK
17+
* @type {Component}
18+
* @description The Cloudinary video component.
19+
* @prop {CloudinaryVideo} cldVid Generated by @cloudinary/url-gen
20+
* @prop {Plugins} plugins Advanced video component plugins accessibility(), responsive(), lazyload(), placeholder()
21+
*/
22+
23+
import { ref, onMounted, onUpdated, onUnmounted } from "vue";
24+
import { CloudinaryVideo } from "@cloudinary/url-gen/assets/CloudinaryVideo";
25+
import {
26+
HtmlVideoLayer,
27+
Plugins,
28+
VideoSources,
29+
cancelCurrentlyRunningPlugins,
30+
} from "@cloudinary/html";
31+
import { SDKAnalyticsConstants } from "../internal/SDKAnalyticsConstants";
32+
33+
interface VideoProps {
34+
cldVid: CloudinaryVideo;
35+
plugins?: Plugins;
36+
sources?: VideoSources;
37+
38+
[x: string]: any;
39+
}
40+
41+
// Disabled linting due to [@vue/compiler-sfc] `defineProps` is a compiler macro and no longer needs to be imported.
42+
// eslint-disable-next-line no-undef
43+
const props = defineProps<VideoProps>();
44+
45+
const videoRef = ref(null);
46+
let htmlLayerInstance;
47+
48+
/**
49+
* On mount, creates a new HTMLLayer instance and initializes with ref to img element,
50+
* user generated cloudinaryVideo and the plugins to be used.
51+
*/
52+
onMounted(() => {
53+
htmlLayerInstance = new HtmlVideoLayer(
54+
videoRef.value,
55+
props.cldVid,
56+
props.sources,
57+
props.plugins
58+
// SDKAnalyticsConstants
59+
);
60+
});
61+
62+
/**
63+
* On update, we cancel running plugins and update image instance with the state of user
64+
* cloudinaryVideo and the state of plugins.
65+
*/
66+
onUpdated(() => {
67+
cancelCurrentlyRunningPlugins(htmlLayerInstance.htmlPluginState);
68+
// call html layer to update the dom again with plugins and reset toBeCanceled
69+
htmlLayerInstance.update(props.cldVid, props.plugins, SDKAnalyticsConstants);
70+
});
71+
72+
/**
73+
* On unmount, we cancel the currently running plugins.
74+
*/
75+
onUnmounted(() => {
76+
// Safely cancel running events on unmount.
77+
cancelCurrentlyRunningPlugins(htmlLayerInstance.htmlPluginState);
1378
});
1479
</script>

packages/vue/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import {
99
} from "@cloudinary/html";
1010

1111
import AdvancedImage from "./components/AdvancedImage.vue";
12-
// import AdvancedVideo from "./components/AdvancedVideo.vue";
12+
import AdvancedVideo from "./components/AdvancedVideo.vue";
1313

1414
export {
1515
placeholder,
1616
accessibility,
1717
lazyload,
1818
responsive,
1919
AdvancedImage,
20-
// AdvancedVideo,
20+
AdvancedVideo,
2121
};

0 commit comments

Comments
 (0)