/** * @file touchOverlay.js * Touch UI component */ import videojs from 'video.js/dist/alt/video.core.novtt.min.js'; import window from 'global/window'; const Component = videojs.getComponent('Component'); const dom = videojs.dom || videojs; /** * The `TouchOverlay` is an overlay to capture tap events. * * @extends Component */ class TouchOverlay extends Component { /** * Creates an instance of the this class. * * @param {Player} player * The `Player` that this class should be attached to. * * @param {Object} [options] * The key/value store of player options. */ constructor(player, options) { super(player, options); this.seekSeconds = options.seekSeconds; this.tapTimeout = options.tapTimeout; // Add play toggle overlay this.addChild('playToggle', {}); // Clear overlay when playback starts or with control fade player.on(['playing', 'userinactive'], e => { if (!this.player_.paused()) { this.removeClass('show-play-toggle'); } }); // A 0 inactivity timeout won't work here if (this.player_.options_.inactivityTimeout === 0) { this.player_.options_.inactivityTimeout = 5000; } this.enable(); } /** * Builds the DOM element. * * @return {Element} * The DOM element. */ createEl() { const el = dom.createEl('div', { className: 'vjs-touch-overlay', // Touch overlay is not tabbable. tabIndex: -1, }); return el; } /** * Debounces to either handle a delayed single tap, or a double tap * * @param {Event} event * The touch event * */ handleTap(event) { // Don't handle taps on the play button if (event.target !== this.el_) { return; } event.preventDefault(); if (this.firstTapCaptured) { this.firstTapCaptured = false; if (this.timeout) { window.clearTimeout(this.timeout); } this.handleDoubleTap(event); } else { this.firstTapCaptured = true; this.timeout = window.setTimeout(() => { this.firstTapCaptured = false; this.handleSingleTap(event); }, this.tapTimeout); } } /** * Toggles display of play toggle * * @param {Event} event * The touch event * */ handleSingleTap(event) { this.removeClass('skip'); this.toggleClass('show-play-toggle'); // At the moment, we only have one