|
1 | 1 | <template> |
2 | | - <video :src="url" /> |
| 2 | + <video ref="videoRef" /> |
3 | 3 | </template> |
4 | 4 |
|
5 | | -<script lang="ts"> |
6 | | -import { defineComponent } from "vue"; |
| 5 | +<script setup lang="ts"> |
| 6 | +// import { defineComponent } from "vue"; |
7 | 7 |
|
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); |
13 | 78 | }); |
14 | 79 | </script> |
0 commit comments