videojs-mobile-ui 1.1.4 → 1.2.0
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/README.md +104 -53
- package/dist/videojs-mobile-ui.cjs.js +194 -42
- package/dist/videojs-mobile-ui.css +6 -0
- package/dist/videojs-mobile-ui.es.js +194 -42
- package/dist/videojs-mobile-ui.js +194 -42
- package/dist/videojs-mobile-ui.min.js +2 -2
- package/docs/api/TouchOverlay.html +772 -0
- package/docs/api/fonts/OpenSans-Bold-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-Bold-webfont.svg +1830 -0
- package/docs/api/fonts/OpenSans-Bold-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-BoldItalic-webfont.svg +1830 -0
- package/docs/api/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-Italic-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-Italic-webfont.svg +1830 -0
- package/docs/api/fonts/OpenSans-Italic-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-Light-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-Light-webfont.svg +1831 -0
- package/docs/api/fonts/OpenSans-Light-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-LightItalic-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-LightItalic-webfont.svg +1835 -0
- package/docs/api/fonts/OpenSans-LightItalic-webfont.woff +0 -0
- package/docs/api/fonts/OpenSans-Regular-webfont.eot +0 -0
- package/docs/api/fonts/OpenSans-Regular-webfont.svg +1831 -0
- package/docs/api/fonts/OpenSans-Regular-webfont.woff +0 -0
- package/docs/api/global.html +1485 -0
- package/docs/api/index.html +159 -0
- package/docs/api/plugin.js.html +266 -0
- package/docs/api/scripts/linenumber.js +25 -0
- package/docs/api/scripts/prettify/Apache-License-2.0.txt +202 -0
- package/docs/api/scripts/prettify/lang-css.js +2 -0
- package/docs/api/scripts/prettify/prettify.js +28 -0
- package/docs/api/styles/jsdoc-default.css +358 -0
- package/docs/api/styles/prettify-jsdoc.css +111 -0
- package/docs/api/styles/prettify-tomorrow.css +132 -0
- package/docs/api/swipeFullscreen.js.html +173 -0
- package/docs/api/touchOverlay.js.html +203 -0
- package/index.html +238 -170
- package/package.json +6 -4
- package/scripts/netlify.js +16 -0
- package/scripts/readme-options.js +370 -0
- package/src/plugin.css +6 -0
- package/src/plugin.js +64 -38
- package/src/swipeFullscreen.js +122 -0
- package/src/touchOverlay.js +6 -2
- package/test/plugin.test.js +57 -41
- package/test/swipeFullscreen.test.js +365 -0
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
/*! @name videojs-mobile-ui @version 1.
|
|
1
|
+
/*! @name videojs-mobile-ui @version 1.2.0 @license MIT */
|
|
2
2
|
import videojs from 'video.js';
|
|
3
3
|
import window from 'global/window';
|
|
4
4
|
|
|
5
|
-
var version = "1.
|
|
5
|
+
var version = "1.2.0";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @file touchOverlay.js
|
|
9
9
|
* Touch UI component
|
|
10
10
|
*/
|
|
11
|
+
|
|
12
|
+
/** @import Player from 'video.js/dist/types/player' */
|
|
13
|
+
|
|
11
14
|
const Component = videojs.getComponent('Component');
|
|
12
15
|
const dom = videojs.dom || videojs;
|
|
13
16
|
|
|
@@ -23,7 +26,7 @@ class TouchOverlay extends Component {
|
|
|
23
26
|
* @param {Player} player
|
|
24
27
|
* The `Player` that this class should be attached to.
|
|
25
28
|
*
|
|
26
|
-
* @param {
|
|
29
|
+
* @param {options} [options]
|
|
27
30
|
* The key/value store of player options.
|
|
28
31
|
*/
|
|
29
32
|
constructor(player, options) {
|
|
@@ -112,7 +115,9 @@ class TouchOverlay extends Component {
|
|
|
112
115
|
if (event.target !== this.el_) {
|
|
113
116
|
return;
|
|
114
117
|
}
|
|
115
|
-
event.
|
|
118
|
+
if (event.cancelable) {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
}
|
|
116
121
|
this.taps += 1;
|
|
117
122
|
if (this.taps === 1) {
|
|
118
123
|
this.removeClass('skip');
|
|
@@ -138,13 +143,184 @@ class TouchOverlay extends Component {
|
|
|
138
143
|
}
|
|
139
144
|
Component.registerComponent('TouchOverlay', TouchOverlay);
|
|
140
145
|
|
|
141
|
-
|
|
146
|
+
/** @import Player from 'video.js/dist/types/player' */
|
|
147
|
+
/** @import Plugin from 'video.js/dist/types/plugin' */
|
|
148
|
+
/** @import {MobileUiOptions} from './plugin' */
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Sets up swiping to enter and exit fullscreen.
|
|
152
|
+
*
|
|
153
|
+
* @this {Plugin}
|
|
154
|
+
* @param {Player} player
|
|
155
|
+
* The player to initialise on.
|
|
156
|
+
* @param {MobileUiOptions} pluginOptions
|
|
157
|
+
* The options used by the mobile ui plugin.
|
|
158
|
+
*/
|
|
159
|
+
const initSwipe = (player, pluginOptions) => {
|
|
160
|
+
const {
|
|
161
|
+
swipeToFullscreen,
|
|
162
|
+
swipeFromFullscreen
|
|
163
|
+
} = pluginOptions.fullscreen;
|
|
164
|
+
if (swipeToFullscreen) {
|
|
165
|
+
player.addClass('using-fs-swipe-up');
|
|
166
|
+
}
|
|
167
|
+
if (swipeFromFullscreen) {
|
|
168
|
+
player.addClass('using-fs-swipe-down');
|
|
169
|
+
}
|
|
170
|
+
let touchStartY = 0;
|
|
171
|
+
let couldBeSwiping = false;
|
|
172
|
+
const swipeThreshold = 30;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Monitor the possible start of a swipe
|
|
176
|
+
*
|
|
177
|
+
* @param {TouchEvent} e Triggering touch event
|
|
178
|
+
*/
|
|
179
|
+
const onStart = e => {
|
|
180
|
+
const isFullscreen = player.isFullscreen();
|
|
181
|
+
if (!isFullscreen && !swipeToFullscreen || isFullscreen && !swipeFromFullscreen) {
|
|
182
|
+
couldBeSwiping = false;
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
touchStartY = e.changedTouches[0].clientY;
|
|
186
|
+
couldBeSwiping = true;
|
|
187
|
+
player.tech_.el().style.transition = '';
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Monitor the movement of a swipe
|
|
192
|
+
*
|
|
193
|
+
* @param {TouchEvent} e Triggering touch event
|
|
194
|
+
*/
|
|
195
|
+
const onMove = e => {
|
|
196
|
+
if (!couldBeSwiping) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const currentY = e.touches[0].clientY;
|
|
200
|
+
const deltaY = touchStartY - currentY;
|
|
201
|
+
const isFullscreen = player.isFullscreen();
|
|
202
|
+
let scale = 1;
|
|
203
|
+
if (!isFullscreen && deltaY > 0) {
|
|
204
|
+
// Swiping up to enter fullscreen: Zoom in (Max 1.1)
|
|
205
|
+
scale = 1 + Math.min(0.1, deltaY / 500);
|
|
206
|
+
player.tech_.el().style.transform = `scale(${scale})`;
|
|
207
|
+
} else if (isFullscreen && deltaY < 0) {
|
|
208
|
+
// Swiping down to exit fullscreen: Zoom out (Min 0.9)
|
|
209
|
+
scale = 1 - Math.min(0.1, Math.abs(deltaY) / 500);
|
|
210
|
+
player.tech_.el().style.transform = `scale(${scale})`;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Monitor the touch end to determine a valid swipe
|
|
216
|
+
*
|
|
217
|
+
* @param {TouchEvent} e Triggering touch event
|
|
218
|
+
*/
|
|
219
|
+
const onEnd = e => {
|
|
220
|
+
if (!couldBeSwiping) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
couldBeSwiping = false;
|
|
224
|
+
player.tech_.el().style.transition = 'transform 0.3s ease-out';
|
|
225
|
+
player.tech_.el().style.transform = 'scale(1)';
|
|
226
|
+
if (e.type === 'touchcancel') {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const touchEndY = e.changedTouches[0].clientY;
|
|
230
|
+
const deltaY = touchStartY - touchEndY;
|
|
231
|
+
if (deltaY > swipeThreshold && !player.isFullscreen()) {
|
|
232
|
+
player.requestFullscreen().catch(err => {
|
|
233
|
+
player.log.warn('Browser refused fullscreen', err);
|
|
234
|
+
});
|
|
235
|
+
} else if (deltaY < -swipeThreshold && player.isFullscreen()) {
|
|
236
|
+
player.exitFullscreen();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
player.el().addEventListener('touchstart', onStart, {
|
|
240
|
+
passive: true
|
|
241
|
+
});
|
|
242
|
+
player.el().addEventListener('touchmove', onMove, {
|
|
243
|
+
passive: true
|
|
244
|
+
});
|
|
245
|
+
player.el().addEventListener('touchend', onEnd, {
|
|
246
|
+
passive: true
|
|
247
|
+
});
|
|
248
|
+
player.el().addEventListener('touchcancel', onEnd, {
|
|
249
|
+
passive: true
|
|
250
|
+
});
|
|
251
|
+
player.on('dispose', () => {
|
|
252
|
+
player.el().removeEventListener('touchstart', onStart, {
|
|
253
|
+
passive: true
|
|
254
|
+
});
|
|
255
|
+
player.el().removeEventListener('touchmove', onMove, {
|
|
256
|
+
passive: true
|
|
257
|
+
});
|
|
258
|
+
player.el().removeEventListener('touchend', onEnd, {
|
|
259
|
+
passive: true
|
|
260
|
+
});
|
|
261
|
+
player.el().removeEventListener('touchcancel', onEnd, {
|
|
262
|
+
passive: true
|
|
263
|
+
});
|
|
264
|
+
player.tech_.el().style.transform = '';
|
|
265
|
+
player.tech_.el().style.transition = '';
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* @typedef {Object} MobileUiOptions
|
|
271
|
+
* @property {Object} [fullscreen]
|
|
272
|
+
* Options for fullscreen behaviours.
|
|
273
|
+
* @property {boolean} [fullscreen.enterOnRotate]
|
|
274
|
+
* If the device is rotated, enter fullscreen.
|
|
275
|
+
* Default `true`.
|
|
276
|
+
* @property {boolean} [fullscreen.exitOnRotate]
|
|
277
|
+
* If the device is rotated, exit fullscreen, unless `lockOnRotate` is used.
|
|
278
|
+
* Default `true`.
|
|
279
|
+
* @property {boolean} [fullscreen.lockOnRotate]
|
|
280
|
+
* When going fullscreen in response to rotation (`enterOnRotate`), also lock the orientation (not supported by iOS).
|
|
281
|
+
* Default `true`.
|
|
282
|
+
* @property {boolean} [fullscreen.lockToLandscapeOnEnter]
|
|
283
|
+
* When fullscreen is entered by any means, lock the orientation (not supported by iOS).
|
|
284
|
+
* Default `false`.
|
|
285
|
+
* @property {boolean} [fullscreen.swipeToFullscreen]
|
|
286
|
+
* Swipe up to enter fullscreen.
|
|
287
|
+
* Default `false`.
|
|
288
|
+
* @property {boolean} [fullscreen.swipeFromFullscreen]
|
|
289
|
+
* Swipe down to exit fullscreen.
|
|
290
|
+
* Won't do anything on iOS native fullscreen, which has its own swipe down exit gesture.
|
|
291
|
+
* Default `false`.
|
|
292
|
+
* @property {boolean} [fullscreen.disabled]
|
|
293
|
+
* All fullscreen functionality provided by this plugin disabled.
|
|
294
|
+
* Default `false`.
|
|
295
|
+
* @property {Object} [touchControls]
|
|
296
|
+
* Options for tap overlay.
|
|
297
|
+
* @property {number} [touchControls.seekSeconds]
|
|
298
|
+
* Increment to seek in seconds.
|
|
299
|
+
* Default `10`.
|
|
300
|
+
* @property {number} [touchControls.tapTimeout]
|
|
301
|
+
* Timeout to consider multiple taps as double rather than two single.
|
|
302
|
+
* Default `300`.
|
|
303
|
+
* @property {boolean} [touchControls.disableOnEnd]
|
|
304
|
+
* Disable the touch overlay when the video ends.
|
|
305
|
+
* Useful if an end screen overlay is used to avoid conflict.
|
|
306
|
+
* Default `false`.
|
|
307
|
+
* @property {boolean} [touchControls.disabled]
|
|
308
|
+
* All tap overlay functionality provided by this plugin disabled.
|
|
309
|
+
* Default `false`.
|
|
310
|
+
* @internal
|
|
311
|
+
* @property {boolean} [forceForTesting]
|
|
312
|
+
* Used in unit tests
|
|
313
|
+
*/
|
|
314
|
+
|
|
315
|
+
/** @type {MobileUiOptions} */
|
|
142
316
|
const defaults = {
|
|
143
317
|
fullscreen: {
|
|
144
318
|
enterOnRotate: true,
|
|
145
319
|
exitOnRotate: true,
|
|
146
320
|
lockOnRotate: true,
|
|
147
321
|
lockToLandscapeOnEnter: false,
|
|
322
|
+
swipeToFullscreen: false,
|
|
323
|
+
swipeFromFullscreen: false,
|
|
148
324
|
disabled: false
|
|
149
325
|
},
|
|
150
326
|
touchControls: {
|
|
@@ -187,7 +363,7 @@ const getOrientation = () => {
|
|
|
187
363
|
* @param {Player} player
|
|
188
364
|
* A Video.js player object.
|
|
189
365
|
*
|
|
190
|
-
* @param {
|
|
366
|
+
* @param {MobileUiOptions} [options={}]
|
|
191
367
|
* A plain object containing options for the plugin.
|
|
192
368
|
*/
|
|
193
369
|
const onPlayerReady = (player, options) => {
|
|
@@ -204,17 +380,22 @@ const onPlayerReady = (player, options) => {
|
|
|
204
380
|
if (options.fullscreen.disabled) {
|
|
205
381
|
return;
|
|
206
382
|
}
|
|
383
|
+
if (options.fullscreen.swipeToFullscreen || options.fullscreen.swipeFromFullscreen) {
|
|
384
|
+
initSwipe(player, options);
|
|
385
|
+
}
|
|
207
386
|
let locked = false;
|
|
208
387
|
const rotationHandler = () => {
|
|
209
388
|
const currentOrientation = getOrientation();
|
|
210
389
|
if (currentOrientation === 'landscape' && options.fullscreen.enterOnRotate) {
|
|
211
|
-
if (player.paused()
|
|
212
|
-
player.requestFullscreen()
|
|
390
|
+
if (!player.paused() && !player.isFullscreen()) {
|
|
391
|
+
player.requestFullscreen().catch(err => {
|
|
392
|
+
player.log.warn('Browser refused fullscreen request:', err);
|
|
393
|
+
});
|
|
213
394
|
if ((options.fullscreen.lockOnRotate || options.fullscreen.lockToLandscapeOnEnter) && screen.orientation && screen.orientation.lock) {
|
|
214
395
|
screen.orientation.lock('landscape').then(() => {
|
|
215
396
|
locked = true;
|
|
216
|
-
}).catch(
|
|
217
|
-
videojs.log('Browser refused orientation lock:',
|
|
397
|
+
}).catch(err => {
|
|
398
|
+
videojs.log.warn('Browser refused orientation lock:', err);
|
|
218
399
|
});
|
|
219
400
|
}
|
|
220
401
|
}
|
|
@@ -239,6 +420,7 @@ const onPlayerReady = (player, options) => {
|
|
|
239
420
|
}
|
|
240
421
|
}
|
|
241
422
|
player.on('fullscreenchange', _ => {
|
|
423
|
+
player.log('fullscreenchange', player.isFullscreen(), options.fullscreen.lockToLandscapeOnEnter, getOrientation());
|
|
242
424
|
if (player.isFullscreen() && options.fullscreen.lockToLandscapeOnEnter && getOrientation() === 'portrait') {
|
|
243
425
|
screen.orientation.lock('landscape').then(() => {
|
|
244
426
|
locked = true;
|
|
@@ -259,40 +441,10 @@ const onPlayerReady = (player, options) => {
|
|
|
259
441
|
};
|
|
260
442
|
|
|
261
443
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
* Adds a monile UI for player control, and fullscreen orientation control
|
|
444
|
+
* Adds a mobile UI for player control, and fullscreen orientation control
|
|
265
445
|
*
|
|
266
446
|
* @function mobileUi
|
|
267
|
-
* @param {
|
|
268
|
-
* Plugin options.
|
|
269
|
-
* @param {boolean} [options.forceForTesting=false]
|
|
270
|
-
* Enables the display regardless of user agent, for testing purposes
|
|
271
|
-
* @param {Object} [options.fullscreen={}]
|
|
272
|
-
* Fullscreen options.
|
|
273
|
-
* @param {boolean} [options.fullscreen.disabled=false]
|
|
274
|
-
* If true no fullscreen handling except the *deprecated* iOS fullwindow hack
|
|
275
|
-
* @param {boolean} [options.fullscreen.enterOnRotate=true]
|
|
276
|
-
* Whether to go fullscreen when rotating to landscape
|
|
277
|
-
* @param {boolean} [options.fullscreen.exitOnRotate=true]
|
|
278
|
-
* Whether to leave fullscreen when rotating to portrait (if not locked)
|
|
279
|
-
* @param {boolean} [options.fullscreen.lockOnRotate=true]
|
|
280
|
-
* Whether to lock orientation when rotating to landscape
|
|
281
|
-
* Unlocked when exiting fullscreen or on 'ended
|
|
282
|
-
* @param {boolean} [options.fullscreen.lockToLandscapeOnEnter=false]
|
|
283
|
-
* Whether to always lock orientation to landscape on fullscreen mode
|
|
284
|
-
* Unlocked when exiting fullscreen or on 'ended'
|
|
285
|
-
* @param {Object} [options.touchControls={}]
|
|
286
|
-
* Touch UI options.
|
|
287
|
-
* @param {boolean} [options.touchControls.disabled=false]
|
|
288
|
-
* If true no touch controls are added.
|
|
289
|
-
* @param {int} [options.touchControls.seekSeconds=10]
|
|
290
|
-
* Number of seconds to seek on double-tap
|
|
291
|
-
* @param {int} [options.touchControls.tapTimeout=300]
|
|
292
|
-
* Interval in ms to be considered a doubletap
|
|
293
|
-
* @param {boolean} [options.touchControls.disableOnEnd=false]
|
|
294
|
-
* Whether to disable when the video ends (e.g., if there is an endscreen)
|
|
295
|
-
* Never shows if the endscreen plugin is present
|
|
447
|
+
* @param {MobileUiOptions} [options={}] Plugin options
|
|
296
448
|
*/
|
|
297
449
|
const mobileUi = function (options = {}) {
|
|
298
450
|
if (options.forceForTesting || videojs.browser.IS_ANDROID || videojs.browser.IS_IOS) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @name videojs-mobile-ui @version 1.
|
|
1
|
+
/*! @name videojs-mobile-ui @version 1.2.0 @license MIT */
|
|
2
2
|
(function (global, factory) {
|
|
3
3
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('video.js')) :
|
|
4
4
|
typeof define === 'function' && define.amd ? define(['video.js'], factory) :
|
|
@@ -9,12 +9,15 @@
|
|
|
9
9
|
|
|
10
10
|
var videojs__default = /*#__PURE__*/_interopDefaultLegacy(videojs);
|
|
11
11
|
|
|
12
|
-
var version = "1.
|
|
12
|
+
var version = "1.2.0";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @file touchOverlay.js
|
|
16
16
|
* Touch UI component
|
|
17
17
|
*/
|
|
18
|
+
|
|
19
|
+
/** @import Player from 'video.js/dist/types/player' */
|
|
20
|
+
|
|
18
21
|
const Component = videojs__default["default"].getComponent('Component');
|
|
19
22
|
const dom = videojs__default["default"].dom || videojs__default["default"];
|
|
20
23
|
|
|
@@ -30,7 +33,7 @@
|
|
|
30
33
|
* @param {Player} player
|
|
31
34
|
* The `Player` that this class should be attached to.
|
|
32
35
|
*
|
|
33
|
-
* @param {
|
|
36
|
+
* @param {options} [options]
|
|
34
37
|
* The key/value store of player options.
|
|
35
38
|
*/
|
|
36
39
|
constructor(player, options) {
|
|
@@ -119,7 +122,9 @@
|
|
|
119
122
|
if (event.target !== this.el_) {
|
|
120
123
|
return;
|
|
121
124
|
}
|
|
122
|
-
event.
|
|
125
|
+
if (event.cancelable) {
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
}
|
|
123
128
|
this.taps += 1;
|
|
124
129
|
if (this.taps === 1) {
|
|
125
130
|
this.removeClass('skip');
|
|
@@ -145,13 +150,184 @@
|
|
|
145
150
|
}
|
|
146
151
|
Component.registerComponent('TouchOverlay', TouchOverlay);
|
|
147
152
|
|
|
148
|
-
|
|
153
|
+
/** @import Player from 'video.js/dist/types/player' */
|
|
154
|
+
/** @import Plugin from 'video.js/dist/types/plugin' */
|
|
155
|
+
/** @import {MobileUiOptions} from './plugin' */
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Sets up swiping to enter and exit fullscreen.
|
|
159
|
+
*
|
|
160
|
+
* @this {Plugin}
|
|
161
|
+
* @param {Player} player
|
|
162
|
+
* The player to initialise on.
|
|
163
|
+
* @param {MobileUiOptions} pluginOptions
|
|
164
|
+
* The options used by the mobile ui plugin.
|
|
165
|
+
*/
|
|
166
|
+
const initSwipe = (player, pluginOptions) => {
|
|
167
|
+
const {
|
|
168
|
+
swipeToFullscreen,
|
|
169
|
+
swipeFromFullscreen
|
|
170
|
+
} = pluginOptions.fullscreen;
|
|
171
|
+
if (swipeToFullscreen) {
|
|
172
|
+
player.addClass('using-fs-swipe-up');
|
|
173
|
+
}
|
|
174
|
+
if (swipeFromFullscreen) {
|
|
175
|
+
player.addClass('using-fs-swipe-down');
|
|
176
|
+
}
|
|
177
|
+
let touchStartY = 0;
|
|
178
|
+
let couldBeSwiping = false;
|
|
179
|
+
const swipeThreshold = 30;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Monitor the possible start of a swipe
|
|
183
|
+
*
|
|
184
|
+
* @param {TouchEvent} e Triggering touch event
|
|
185
|
+
*/
|
|
186
|
+
const onStart = e => {
|
|
187
|
+
const isFullscreen = player.isFullscreen();
|
|
188
|
+
if (!isFullscreen && !swipeToFullscreen || isFullscreen && !swipeFromFullscreen) {
|
|
189
|
+
couldBeSwiping = false;
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
touchStartY = e.changedTouches[0].clientY;
|
|
193
|
+
couldBeSwiping = true;
|
|
194
|
+
player.tech_.el().style.transition = '';
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Monitor the movement of a swipe
|
|
199
|
+
*
|
|
200
|
+
* @param {TouchEvent} e Triggering touch event
|
|
201
|
+
*/
|
|
202
|
+
const onMove = e => {
|
|
203
|
+
if (!couldBeSwiping) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const currentY = e.touches[0].clientY;
|
|
207
|
+
const deltaY = touchStartY - currentY;
|
|
208
|
+
const isFullscreen = player.isFullscreen();
|
|
209
|
+
let scale = 1;
|
|
210
|
+
if (!isFullscreen && deltaY > 0) {
|
|
211
|
+
// Swiping up to enter fullscreen: Zoom in (Max 1.1)
|
|
212
|
+
scale = 1 + Math.min(0.1, deltaY / 500);
|
|
213
|
+
player.tech_.el().style.transform = `scale(${scale})`;
|
|
214
|
+
} else if (isFullscreen && deltaY < 0) {
|
|
215
|
+
// Swiping down to exit fullscreen: Zoom out (Min 0.9)
|
|
216
|
+
scale = 1 - Math.min(0.1, Math.abs(deltaY) / 500);
|
|
217
|
+
player.tech_.el().style.transform = `scale(${scale})`;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Monitor the touch end to determine a valid swipe
|
|
223
|
+
*
|
|
224
|
+
* @param {TouchEvent} e Triggering touch event
|
|
225
|
+
*/
|
|
226
|
+
const onEnd = e => {
|
|
227
|
+
if (!couldBeSwiping) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
couldBeSwiping = false;
|
|
231
|
+
player.tech_.el().style.transition = 'transform 0.3s ease-out';
|
|
232
|
+
player.tech_.el().style.transform = 'scale(1)';
|
|
233
|
+
if (e.type === 'touchcancel') {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const touchEndY = e.changedTouches[0].clientY;
|
|
237
|
+
const deltaY = touchStartY - touchEndY;
|
|
238
|
+
if (deltaY > swipeThreshold && !player.isFullscreen()) {
|
|
239
|
+
player.requestFullscreen().catch(err => {
|
|
240
|
+
player.log.warn('Browser refused fullscreen', err);
|
|
241
|
+
});
|
|
242
|
+
} else if (deltaY < -swipeThreshold && player.isFullscreen()) {
|
|
243
|
+
player.exitFullscreen();
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
player.el().addEventListener('touchstart', onStart, {
|
|
247
|
+
passive: true
|
|
248
|
+
});
|
|
249
|
+
player.el().addEventListener('touchmove', onMove, {
|
|
250
|
+
passive: true
|
|
251
|
+
});
|
|
252
|
+
player.el().addEventListener('touchend', onEnd, {
|
|
253
|
+
passive: true
|
|
254
|
+
});
|
|
255
|
+
player.el().addEventListener('touchcancel', onEnd, {
|
|
256
|
+
passive: true
|
|
257
|
+
});
|
|
258
|
+
player.on('dispose', () => {
|
|
259
|
+
player.el().removeEventListener('touchstart', onStart, {
|
|
260
|
+
passive: true
|
|
261
|
+
});
|
|
262
|
+
player.el().removeEventListener('touchmove', onMove, {
|
|
263
|
+
passive: true
|
|
264
|
+
});
|
|
265
|
+
player.el().removeEventListener('touchend', onEnd, {
|
|
266
|
+
passive: true
|
|
267
|
+
});
|
|
268
|
+
player.el().removeEventListener('touchcancel', onEnd, {
|
|
269
|
+
passive: true
|
|
270
|
+
});
|
|
271
|
+
player.tech_.el().style.transform = '';
|
|
272
|
+
player.tech_.el().style.transition = '';
|
|
273
|
+
});
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* @typedef {Object} MobileUiOptions
|
|
278
|
+
* @property {Object} [fullscreen]
|
|
279
|
+
* Options for fullscreen behaviours.
|
|
280
|
+
* @property {boolean} [fullscreen.enterOnRotate]
|
|
281
|
+
* If the device is rotated, enter fullscreen.
|
|
282
|
+
* Default `true`.
|
|
283
|
+
* @property {boolean} [fullscreen.exitOnRotate]
|
|
284
|
+
* If the device is rotated, exit fullscreen, unless `lockOnRotate` is used.
|
|
285
|
+
* Default `true`.
|
|
286
|
+
* @property {boolean} [fullscreen.lockOnRotate]
|
|
287
|
+
* When going fullscreen in response to rotation (`enterOnRotate`), also lock the orientation (not supported by iOS).
|
|
288
|
+
* Default `true`.
|
|
289
|
+
* @property {boolean} [fullscreen.lockToLandscapeOnEnter]
|
|
290
|
+
* When fullscreen is entered by any means, lock the orientation (not supported by iOS).
|
|
291
|
+
* Default `false`.
|
|
292
|
+
* @property {boolean} [fullscreen.swipeToFullscreen]
|
|
293
|
+
* Swipe up to enter fullscreen.
|
|
294
|
+
* Default `false`.
|
|
295
|
+
* @property {boolean} [fullscreen.swipeFromFullscreen]
|
|
296
|
+
* Swipe down to exit fullscreen.
|
|
297
|
+
* Won't do anything on iOS native fullscreen, which has its own swipe down exit gesture.
|
|
298
|
+
* Default `false`.
|
|
299
|
+
* @property {boolean} [fullscreen.disabled]
|
|
300
|
+
* All fullscreen functionality provided by this plugin disabled.
|
|
301
|
+
* Default `false`.
|
|
302
|
+
* @property {Object} [touchControls]
|
|
303
|
+
* Options for tap overlay.
|
|
304
|
+
* @property {number} [touchControls.seekSeconds]
|
|
305
|
+
* Increment to seek in seconds.
|
|
306
|
+
* Default `10`.
|
|
307
|
+
* @property {number} [touchControls.tapTimeout]
|
|
308
|
+
* Timeout to consider multiple taps as double rather than two single.
|
|
309
|
+
* Default `300`.
|
|
310
|
+
* @property {boolean} [touchControls.disableOnEnd]
|
|
311
|
+
* Disable the touch overlay when the video ends.
|
|
312
|
+
* Useful if an end screen overlay is used to avoid conflict.
|
|
313
|
+
* Default `false`.
|
|
314
|
+
* @property {boolean} [touchControls.disabled]
|
|
315
|
+
* All tap overlay functionality provided by this plugin disabled.
|
|
316
|
+
* Default `false`.
|
|
317
|
+
* @internal
|
|
318
|
+
* @property {boolean} [forceForTesting]
|
|
319
|
+
* Used in unit tests
|
|
320
|
+
*/
|
|
321
|
+
|
|
322
|
+
/** @type {MobileUiOptions} */
|
|
149
323
|
const defaults = {
|
|
150
324
|
fullscreen: {
|
|
151
325
|
enterOnRotate: true,
|
|
152
326
|
exitOnRotate: true,
|
|
153
327
|
lockOnRotate: true,
|
|
154
328
|
lockToLandscapeOnEnter: false,
|
|
329
|
+
swipeToFullscreen: false,
|
|
330
|
+
swipeFromFullscreen: false,
|
|
155
331
|
disabled: false
|
|
156
332
|
},
|
|
157
333
|
touchControls: {
|
|
@@ -194,7 +370,7 @@
|
|
|
194
370
|
* @param {Player} player
|
|
195
371
|
* A Video.js player object.
|
|
196
372
|
*
|
|
197
|
-
* @param {
|
|
373
|
+
* @param {MobileUiOptions} [options={}]
|
|
198
374
|
* A plain object containing options for the plugin.
|
|
199
375
|
*/
|
|
200
376
|
const onPlayerReady = (player, options) => {
|
|
@@ -211,17 +387,22 @@
|
|
|
211
387
|
if (options.fullscreen.disabled) {
|
|
212
388
|
return;
|
|
213
389
|
}
|
|
390
|
+
if (options.fullscreen.swipeToFullscreen || options.fullscreen.swipeFromFullscreen) {
|
|
391
|
+
initSwipe(player, options);
|
|
392
|
+
}
|
|
214
393
|
let locked = false;
|
|
215
394
|
const rotationHandler = () => {
|
|
216
395
|
const currentOrientation = getOrientation();
|
|
217
396
|
if (currentOrientation === 'landscape' && options.fullscreen.enterOnRotate) {
|
|
218
|
-
if (player.paused()
|
|
219
|
-
player.requestFullscreen()
|
|
397
|
+
if (!player.paused() && !player.isFullscreen()) {
|
|
398
|
+
player.requestFullscreen().catch(err => {
|
|
399
|
+
player.log.warn('Browser refused fullscreen request:', err);
|
|
400
|
+
});
|
|
220
401
|
if ((options.fullscreen.lockOnRotate || options.fullscreen.lockToLandscapeOnEnter) && screen.orientation && screen.orientation.lock) {
|
|
221
402
|
screen.orientation.lock('landscape').then(() => {
|
|
222
403
|
locked = true;
|
|
223
|
-
}).catch(
|
|
224
|
-
videojs__default["default"].log('Browser refused orientation lock:',
|
|
404
|
+
}).catch(err => {
|
|
405
|
+
videojs__default["default"].log.warn('Browser refused orientation lock:', err);
|
|
225
406
|
});
|
|
226
407
|
}
|
|
227
408
|
}
|
|
@@ -246,6 +427,7 @@
|
|
|
246
427
|
}
|
|
247
428
|
}
|
|
248
429
|
player.on('fullscreenchange', _ => {
|
|
430
|
+
player.log('fullscreenchange', player.isFullscreen(), options.fullscreen.lockToLandscapeOnEnter, getOrientation());
|
|
249
431
|
if (player.isFullscreen() && options.fullscreen.lockToLandscapeOnEnter && getOrientation() === 'portrait') {
|
|
250
432
|
screen.orientation.lock('landscape').then(() => {
|
|
251
433
|
locked = true;
|
|
@@ -266,40 +448,10 @@
|
|
|
266
448
|
};
|
|
267
449
|
|
|
268
450
|
/**
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* Adds a monile UI for player control, and fullscreen orientation control
|
|
451
|
+
* Adds a mobile UI for player control, and fullscreen orientation control
|
|
272
452
|
*
|
|
273
453
|
* @function mobileUi
|
|
274
|
-
* @param {
|
|
275
|
-
* Plugin options.
|
|
276
|
-
* @param {boolean} [options.forceForTesting=false]
|
|
277
|
-
* Enables the display regardless of user agent, for testing purposes
|
|
278
|
-
* @param {Object} [options.fullscreen={}]
|
|
279
|
-
* Fullscreen options.
|
|
280
|
-
* @param {boolean} [options.fullscreen.disabled=false]
|
|
281
|
-
* If true no fullscreen handling except the *deprecated* iOS fullwindow hack
|
|
282
|
-
* @param {boolean} [options.fullscreen.enterOnRotate=true]
|
|
283
|
-
* Whether to go fullscreen when rotating to landscape
|
|
284
|
-
* @param {boolean} [options.fullscreen.exitOnRotate=true]
|
|
285
|
-
* Whether to leave fullscreen when rotating to portrait (if not locked)
|
|
286
|
-
* @param {boolean} [options.fullscreen.lockOnRotate=true]
|
|
287
|
-
* Whether to lock orientation when rotating to landscape
|
|
288
|
-
* Unlocked when exiting fullscreen or on 'ended
|
|
289
|
-
* @param {boolean} [options.fullscreen.lockToLandscapeOnEnter=false]
|
|
290
|
-
* Whether to always lock orientation to landscape on fullscreen mode
|
|
291
|
-
* Unlocked when exiting fullscreen or on 'ended'
|
|
292
|
-
* @param {Object} [options.touchControls={}]
|
|
293
|
-
* Touch UI options.
|
|
294
|
-
* @param {boolean} [options.touchControls.disabled=false]
|
|
295
|
-
* If true no touch controls are added.
|
|
296
|
-
* @param {int} [options.touchControls.seekSeconds=10]
|
|
297
|
-
* Number of seconds to seek on double-tap
|
|
298
|
-
* @param {int} [options.touchControls.tapTimeout=300]
|
|
299
|
-
* Interval in ms to be considered a doubletap
|
|
300
|
-
* @param {boolean} [options.touchControls.disableOnEnd=false]
|
|
301
|
-
* Whether to disable when the video ends (e.g., if there is an endscreen)
|
|
302
|
-
* Never shows if the endscreen plugin is present
|
|
454
|
+
* @param {MobileUiOptions} [options={}] Plugin options
|
|
303
455
|
*/
|
|
304
456
|
const mobileUi = function (options = {}) {
|
|
305
457
|
if (options.forceForTesting || videojs__default["default"].browser.IS_ANDROID || videojs__default["default"].browser.IS_IOS) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/*! @name videojs-mobile-ui @version 1.
|
|
2
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("video.js")):"function"==typeof define&&define.amd?define(["video.js"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).videojsMobileUi=t(e.videojs)}(this,function(e){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var
|
|
1
|
+
/*! @name videojs-mobile-ui @version 1.2.0 @license MIT */
|
|
2
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("video.js")):"function"==typeof define&&define.amd?define(["video.js"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).videojsMobileUi=t(e.videojs)}(this,function(e){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=t(e);const n=s.default.getComponent("Component"),o=s.default.dom||s.default;n.registerComponent("TouchOverlay",class extends n{constructor(e,t){super(e,t),this.seekSeconds=t.seekSeconds,this.tapTimeout=t.tapTimeout,this.taps=0,this.addChild("playToggle",{}),e.on(["playing","userinactive"],e=>{this.removeClass("show-play-toggle")}),0===this.player_.options_.inactivityTimeout&&(this.player_.options_.inactivityTimeout=5e3),this.handleTaps_=s.default.fn.debounce(e=>{const t=(this.taps-1)*this.seekSeconds;if(this.taps=0,t<1)return;const s=this.el_.getBoundingClientRect(),n=e.changedTouches[0].clientX-s.left;if(n<.4*s.width)this.player_.currentTime(Math.max(0,this.player_.currentTime()-t)),this.addClass("reverse");else{if(!(n>s.width-.4*s.width))return;this.player_.currentTime(Math.min(this.player_.duration(),this.player_.currentTime()+t)),this.removeClass("reverse")}this.removeClass("show-play-toggle"),this.setAttribute("data-skip-text",`${t} ${this.localize("seconds")}`),this.removeClass("skip"),window.requestAnimationFrame(()=>{this.addClass("skip")})},this.tapTimeout),this.enable()}createEl(){return o.createEl("div",{className:"vjs-touch-overlay",tabIndex:-1})}handleTap(e){e.target===this.el_&&(e.cancelable&&e.preventDefault(),this.taps+=1,1===this.taps&&(this.removeClass("skip"),this.toggleClass("show-play-toggle")),this.handleTaps_(e))}enable(){this.firstTapCaptured=!1,this.on("touchend",this.handleTap)}disable(){this.off("touchend",this.handleTap)}});const i={fullscreen:{enterOnRotate:!0,exitOnRotate:!0,lockOnRotate:!0,lockToLandscapeOnEnter:!1,swipeToFullscreen:!1,swipeFromFullscreen:!1,disabled:!1},touchControls:{seekSeconds:10,tapTimeout:300,disableOnEnd:!1,disabled:!1}},l=window.screen,r=()=>{if(l){const e=((l.orientation||{}).type||l.mozOrientation||l.msOrientation||"").split("-")[0];if("landscape"===e||"portrait"===e)return e}return"number"==typeof window.orientation?0===window.orientation||180===window.orientation?"portrait":"landscape":"portrait"},a=(e,t)=>{if(e.addClass("vjs-mobile-ui"),!t.touchControls.disabled){(t.touchControls.disableOnEnd||"function"==typeof e.endscreen)&&e.addClass("vjs-mobile-ui-disable-end");const s=e.children_.indexOf(e.getChild("ControlBar"));e.touchOverlay=e.addChild("TouchOverlay",t.touchControls,s)}if(t.fullscreen.disabled)return;(t.fullscreen.swipeToFullscreen||t.fullscreen.swipeFromFullscreen)&&((e,t)=>{const{swipeToFullscreen:s,swipeFromFullscreen:n}=t.fullscreen;s&&e.addClass("using-fs-swipe-up"),n&&e.addClass("using-fs-swipe-down");let o=0,i=!1;const l=t=>{const l=e.isFullscreen();!l&&!s||l&&!n?i=!1:(o=t.changedTouches[0].clientY,i=!0,e.tech_.el().style.transition="")},r=t=>{if(!i)return;const s=t.touches[0].clientY,n=o-s,l=e.isFullscreen();let r=1;!l&&n>0?(r=1+Math.min(.1,n/500),e.tech_.el().style.transform=`scale(${r})`):l&&n<0&&(r=1-Math.min(.1,Math.abs(n)/500),e.tech_.el().style.transform=`scale(${r})`)},a=t=>{if(!i)return;if(i=!1,e.tech_.el().style.transition="transform 0.3s ease-out",e.tech_.el().style.transform="scale(1)","touchcancel"===t.type)return;const s=t.changedTouches[0].clientY,n=o-s;n>30&&!e.isFullscreen()?e.requestFullscreen().catch(t=>{e.log.warn("Browser refused fullscreen",t)}):n<-30&&e.isFullscreen()&&e.exitFullscreen()};e.el().addEventListener("touchstart",l,{passive:!0}),e.el().addEventListener("touchmove",r,{passive:!0}),e.el().addEventListener("touchend",a,{passive:!0}),e.el().addEventListener("touchcancel",a,{passive:!0}),e.on("dispose",()=>{e.el().removeEventListener("touchstart",l,{passive:!0}),e.el().removeEventListener("touchmove",r,{passive:!0}),e.el().removeEventListener("touchend",a,{passive:!0}),e.el().removeEventListener("touchcancel",a,{passive:!0}),e.tech_.el().style.transform="",e.tech_.el().style.transition=""})})(e,t);let n=!1;const o=()=>{const o=r();"landscape"===o&&t.fullscreen.enterOnRotate?e.paused()||e.isFullscreen()||(e.requestFullscreen().catch(t=>{e.log.warn("Browser refused fullscreen request:",t)}),(t.fullscreen.lockOnRotate||t.fullscreen.lockToLandscapeOnEnter)&&l.orientation&&l.orientation.lock&&l.orientation.lock("landscape").then(()=>{n=!0}).catch(e=>{s.default.log.warn("Browser refused orientation lock:",e)})):"portrait"===o&&t.fullscreen.exitOnRotate&&!n&&e.isFullscreen()&&e.exitFullscreen()};(t.fullscreen.enterOnRotate||t.fullscreen.exitOnRotate)&&(s.default.browser.IS_IOS?(window.addEventListener("orientationchange",o),e.on("dispose",()=>{window.removeEventListener("orientationchange",o)})):l.orientation&&(l.orientation.onchange=o,e.on("dispose",()=>{l.orientation.onchange=null}))),e.on("fullscreenchange",o=>{e.log("fullscreenchange",e.isFullscreen(),t.fullscreen.lockToLandscapeOnEnter,r()),e.isFullscreen()&&t.fullscreen.lockToLandscapeOnEnter&&"portrait"===r()?l.orientation.lock("landscape").then(()=>{n=!0}).catch(e=>{s.default.log("Browser refused orientation lock:",e)}):!e.isFullscreen()&&n&&(l.orientation.unlock(),n=!1)}),e.on("ended",e=>{!0===n&&(l.orientation.unlock(),n=!1)})},c=function(e={}){(e.forceForTesting||s.default.browser.IS_ANDROID||s.default.browser.IS_IOS)&&this.ready(()=>{a(this,s.default.obj.merge(i,e))})};return s.default.registerPlugin("mobileUi",c),c.VERSION="1.2.0",c});
|