1 | import { defineComponent, ref, onMounted, onBeforeUnmount } from '@vue/composition-api';
|
2 |
|
3 |
|
4 | var script = defineComponent({
|
5 | name: 'VPip',
|
6 | props: {
|
7 |
|
8 | videoOptions: {
|
9 | type: Object,
|
10 | required: false,
|
11 | default: function _default() {
|
12 | return {
|
13 | wrapper: '',
|
14 | src: '',
|
15 | poster: '',
|
16 | class: '',
|
17 | height: '100%',
|
18 | width: '100%'
|
19 | };
|
20 | }
|
21 | },
|
22 |
|
23 | buttonOptions: {
|
24 | type: Object,
|
25 | required: false,
|
26 | default: function _default() {
|
27 | return {
|
28 | wrapper: '',
|
29 | type: 'button',
|
30 | class: '',
|
31 | label: 'Toggle picture-in-picture'
|
32 | };
|
33 | }
|
34 | },
|
35 | wrapper: {
|
36 | type: String,
|
37 | default: '',
|
38 | required: false
|
39 | }
|
40 | },
|
41 |
|
42 | setup(props, _ref) {
|
43 | var emit = _ref.emit;
|
44 |
|
45 | var video = ref(null);
|
46 | var isPipSupported = ref(false);
|
47 |
|
48 | onMounted(function () {
|
49 | isPipSupported.value = 'pictureInPictureEnabled' in document;
|
50 | video.value.addEventListener('enterpictureinpicture', function () {
|
51 | emit('video-in-pip', true);
|
52 | });
|
53 | video.value.addEventListener('leavepictureinpicture', function () {
|
54 | emit('video-in-pip', false);
|
55 | });
|
56 | });
|
57 | onBeforeUnmount(function () {
|
58 | video.value.removeEventListener('enterpictureinpicture');
|
59 | video.value.removeEventListener('leavepictureinpicture');
|
60 | });
|
61 |
|
62 | var togglePip = function togglePip() {
|
63 |
|
64 |
|
65 | if (!document.pictureInPictureElement) {
|
66 | video.value.requestPictureInPicture().catch(function (error) {
|
67 |
|
68 | emit('requesting-pip-failure', error);
|
69 | });
|
70 | } else {
|
71 | document.exitPictureInPicture().catch(function (error) {
|
72 |
|
73 | emit('exiting-pip-failure', error);
|
74 | });
|
75 | }
|
76 | };
|
77 |
|
78 | return {
|
79 | video,
|
80 | isPipSupported,
|
81 | togglePip
|
82 | };
|
83 | }
|
84 |
|
85 | });
|
86 |
|
87 | function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier /* server only */, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
|
88 | if (typeof shadowMode !== 'boolean') {
|
89 | createInjectorSSR = createInjector;
|
90 | createInjector = shadowMode;
|
91 | shadowMode = false;
|
92 | }
|
93 |
|
94 | const options = typeof script === 'function' ? script.options : script;
|
95 |
|
96 | if (template && template.render) {
|
97 | options.render = template.render;
|
98 | options.staticRenderFns = template.staticRenderFns;
|
99 | options._compiled = true;
|
100 |
|
101 | if (isFunctionalTemplate) {
|
102 | options.functional = true;
|
103 | }
|
104 | }
|
105 |
|
106 | if (scopeId) {
|
107 | options._scopeId = scopeId;
|
108 | }
|
109 | let hook;
|
110 | if (moduleIdentifier) {
|
111 |
|
112 | hook = function (context) {
|
113 |
|
114 | context =
|
115 | context ||
|
116 | (this.$vnode && this.$vnode.ssrContext) ||
|
117 | (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext);
|
118 |
|
119 | if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
|
120 | context = __VUE_SSR_CONTEXT__;
|
121 | }
|
122 |
|
123 | if (style) {
|
124 | style.call(this, createInjectorSSR(context));
|
125 | }
|
126 |
|
127 | if (context && context._registeredComponents) {
|
128 | context._registeredComponents.add(moduleIdentifier);
|
129 | }
|
130 | };
|
131 |
|
132 |
|
133 | options._ssrRegister = hook;
|
134 | }
|
135 | else if (style) {
|
136 | hook = shadowMode
|
137 | ? function (context) {
|
138 | style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
|
139 | }
|
140 | : function (context) {
|
141 | style.call(this, createInjector(context));
|
142 | };
|
143 | }
|
144 | if (hook) {
|
145 | if (options.functional) {
|
146 |
|
147 | const originalRender = options.render;
|
148 | options.render = function renderWithStyleInjection(h, context) {
|
149 | hook.call(context);
|
150 | return originalRender(h, context);
|
151 | };
|
152 | }
|
153 | else {
|
154 |
|
155 | const existing = options.beforeCreate;
|
156 | options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
|
157 | }
|
158 | }
|
159 | return script;
|
160 | }
|
161 |
|
162 |
|
163 | const __vue_script__ = script;
|
164 |
|
165 |
|
166 | var __vue_render__ = function() {
|
167 | var _vm = this;
|
168 | var _h = _vm.$createElement;
|
169 | var _c = _vm._self._c || _h;
|
170 | return _c("div", { class: _vm.wrapper }, [
|
171 | _c("div", { class: _vm.videoOptions.wrapper }, [
|
172 | _c("video", {
|
173 | ref: "video",
|
174 | class: _vm.videoOptions.class,
|
175 | attrs: {
|
176 | src: _vm.videoOptions.src,
|
177 | poster: _vm.videoOptions.poster,
|
178 | height: _vm.videoOptions.height,
|
179 | width: _vm.videoOptions.width,
|
180 | controls: ""
|
181 | }
|
182 | })
|
183 | ]),
|
184 | _vm._v(" "),
|
185 | _c("div", { class: _vm.buttonOptions.wrapper }, [
|
186 | _vm.isPipSupported
|
187 | ? _c(
|
188 | "button",
|
189 | {
|
190 | class: _vm.buttonOptions.class,
|
191 | attrs: { type: _vm.buttonOptions.type },
|
192 | on: { click: _vm.togglePip }
|
193 | },
|
194 | [_vm._v("\n " + _vm._s(_vm.buttonOptions.label) + "\n ")]
|
195 | )
|
196 | : _vm._e()
|
197 | ])
|
198 | ])
|
199 | };
|
200 | var __vue_staticRenderFns__ = [];
|
201 | __vue_render__._withStripped = true;
|
202 |
|
203 |
|
204 | const __vue_inject_styles__ = undefined;
|
205 |
|
206 | const __vue_scope_id__ = undefined;
|
207 |
|
208 | const __vue_module_identifier__ = undefined;
|
209 |
|
210 | const __vue_is_functional_template__ = false;
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | const __vue_component__ = normalizeComponent(
|
220 | { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
|
221 | __vue_inject_styles__,
|
222 | __vue_script__,
|
223 | __vue_scope_id__,
|
224 | __vue_is_functional_template__,
|
225 | __vue_module_identifier__,
|
226 | false,
|
227 | undefined,
|
228 | undefined,
|
229 | undefined
|
230 | );
|
231 |
|
232 | export default __vue_component__;
|