diff --git a/dist/openplayerjs-youtube.js b/dist/openplayerjs-youtube.js index ca9b49f..18dd1c3 100644 --- a/dist/openplayerjs-youtube.js +++ b/dist/openplayerjs-youtube.js @@ -194,6 +194,56 @@ function _defineProperty(obj, key, value) { module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports; +/***/ }), + +/***/ 215: +/***/ ((module, __unused_webpack_exports, __webpack_require__) => { + +var objectWithoutPropertiesLoose = __webpack_require__(71); + +function _objectWithoutProperties(source, excluded) { + if (source == null) return {}; + var target = objectWithoutPropertiesLoose(source, excluded); + var key, i; + + if (Object.getOwnPropertySymbols) { + var sourceSymbolKeys = Object.getOwnPropertySymbols(source); + + for (i = 0; i < sourceSymbolKeys.length; i++) { + key = sourceSymbolKeys[i]; + if (excluded.indexOf(key) >= 0) continue; + if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; + target[key] = source[key]; + } + } + + return target; +} + +module.exports = _objectWithoutProperties, module.exports.__esModule = true, module.exports["default"] = module.exports; + +/***/ }), + +/***/ 71: +/***/ ((module) => { + +function _objectWithoutPropertiesLoose(source, excluded) { + if (source == null) return {}; + var target = {}; + var sourceKeys = Object.keys(source); + var key, i; + + for (i = 0; i < sourceKeys.length; i++) { + key = sourceKeys[i]; + if (excluded.indexOf(key) >= 0) continue; + target[key] = source[key]; + } + + return target; +} + +module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports; + /***/ }) /******/ }); @@ -257,15 +307,19 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; -/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(416); -/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var simple_load_script__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(714); -/* harmony import */ var simple_load_script__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(simple_load_script__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(215); +/* harmony import */ var _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0__); +/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(416); +/* harmony import */ var _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1__); +/* harmony import */ var simple_load_script__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(714); +/* harmony import */ var simple_load_script__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(simple_load_script__WEBPACK_IMPORTED_MODULE_2__); + +var _excluded = ["url", "nocookie"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } -function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_0___default()(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _babel_runtime_helpers_defineProperty__WEBPACK_IMPORTED_MODULE_1___default()(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } @@ -301,40 +355,40 @@ var YouTube = function YouTube(element, media) { var playerVars = _objectSpread(_objectSpread({}, opts), options); var library = playerVars.url, - noCookies = playerVars.nocookie; - delete playerVars.url; - delete playerVars.nocookie; + noCookies = playerVars.nocookie, + rest = _babel_runtime_helpers_objectWithoutProperties__WEBPACK_IMPORTED_MODULE_0___default()(playerVars, _excluded); function _getYouTubeId(url) { return url.match(/(?:(?:youtu\.be\/)|(?:v=)|(?:\/v\/))(\w+)/)[1]; } - function _startInterval() { + var _startInterval = function _startInterval() { interval = setInterval(function () { var event = new CustomEvent('timeupdate'); element.dispatchEvent(event); }, 250); - } + }; - function _stopInterval() { + var _stopInterval = function _stopInterval() { if (interval) { clearInterval(interval); } - } + }; var playerSettings = { id: id, videoId: _getYouTubeId(media.src), height: isAudio ? 1 : element.offsetHeight, width: isAudio ? 1 : element.offsetWidth, - playerVars: playerVars, + widget_referrer: window.location.host, origin: window.location.host, + playerVars: rest, events: { onReady: function onReady(e) { player = e.target; var iframe = player.getIframe(); - if (element.muted) { + if ('msLaunchUri' in window.navigator && !('documentMode' in document) || /chrome/i.test(window.navigator.userAgent) || element.muted) { player.mute(); } @@ -471,7 +525,7 @@ var YouTube = function YouTube(element, media) { playerVars.enablejsapi = 1; if (typeof YT === 'undefined' || !YT.loaded) { - simple_load_script__WEBPACK_IMPORTED_MODULE_1___default()(library); + simple_load_script__WEBPACK_IMPORTED_MODULE_2___default()(library); } return this; diff --git a/dist/openplayerjs-youtube.min.js b/dist/openplayerjs-youtube.min.js index 5a1a9c9..7da9a5b 100644 --- a/dist/openplayerjs-youtube.min.js +++ b/dist/openplayerjs-youtube.min.js @@ -1 +1 @@ -!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(()=>(()=>{var e={714:(e,t)=>{"use strict";function r(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw a}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r0&&void 0!==arguments[0]?arguments[0]:{};if(arguments.length>1)return Promise.all(Array.prototype.slice.call(arguments).map(e));var n=l(t);return new Promise((function(e,o){if(c(t)&&t.url||n){n&&(t={url:t}),t=Object.assign({},v,t);var a=s(t);if(a){var i=d(t),u=t.removeScript;if(t.callBackName||t.jsonp){var l=r(y(t),3),m=l[0],b=l[1],h=l[2];t.url=m,b[h]=function(r){delete b[h],p(u,a,i),f(t),e(r||u?void 0:i)}}else i.addEventListener("load",(function(){p(u,a,i),f(t),e(u?void 0:i)}));i.addEventListener("error",(function(){a.removeChild(i),o("Error: loading script")})),i.src=t.url,a.appendChild(i)}else o("Error: no DOM element to append script")}else o("Error: object with url or url string needed")}))};var o=window,a="_$_".concat("simpleLoadScript","CallBacks_$_"),i=0,u=function(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()},c=function(e){return"object"===u(e)},l=function(e){return"string"===u(e)},s=function(e){return e.insertInto?document.querySelector(e.insertInto):e.inBody?document.body:document.head},d=function(e){var t=document.createElement("script");if(e.attrs&&c(e.attrs))for(var r=0,n=Object.keys(e.attrs);r{e.exports=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};return(()=>{"use strict";var e=r(416),t=r.n(e),n=r(714),o=r.n(n);function a(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var r=1;r2&&void 0!==arguments[2]&&arguments[2],u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},c=1,l=!1,s=!0,d=new Promise((function(e){e()})),f="op-yt__".concat(e.id||(new Date).getTime()),p="AUDIO"===e.tagName,y=i(i({},{url:"https://www.youtube.com/iframe_api",autoplay:0,controls:0,disablekb:1,end:0,loop:0,modestbranding:0,playsinline:0,rel:0,showinfo:0,start:0,iv_load_policy:3,nocookie:!1}),u),v=y.url,m=y.nocookie;function b(e){return e.match(/(?:(?:youtu\.be\/)|(?:v=)|(?:\/v\/))(\w+)/)[1]}function h(){n=setInterval((function(){var t=new CustomEvent("timeupdate");e.dispatchEvent(t)}),250)}function g(){n&&clearInterval(n)}delete y.url,delete y.nocookie;var w={id:f,videoId:b(t.src),height:p?1:e.offsetHeight,width:p?1:e.offsetWidth,playerVars:y,origin:window.location.host,events:{onReady:function(t){var n=(r=t.target).getIframe();e.muted&&r.mute(),["mouseover","mouseout"].forEach((function(t){n.addEventListener(t,(function(t){var r=new CustomEvent(t.type);e.dispatchEvent(r)}))})),["loadedmetadata","loadeddata","canplay"].forEach((function(t){var r=new CustomEvent(t);e.dispatchEvent(r)}))},onStateChange:function(t){var r=[];switch(t.data){case 0:r=["ended"],s=!1,l=!y.loop,y.loop||g();break;case 1:r=["play","playing"],s=!1,l=!1,h();break;case 2:r=["pause"],s=!0,l=!1,g();break;case 3:r=["progress"],l=!1;break;case 5:r=["loadeddata","loadedmetadata","canplay"],s=!0,l=!1;break;default:r=["loadedmetadata"],s=!0,l=!1}for(var n=0,o=r.length;n-1)&&!y.playlist&&-1===t.src.indexOf("playlist=")&&(y.playlist=b(t.src)),y.controls=0,y.enablejsapi=1,"undefined"!=typeof YT&&YT.loaded||o()(v),this}}function O(){return null}function j(e){return"video/x-youtube"===e}function E(){r.playVideo()}function P(){r.pauseVideo()}function T(){r&&r.destroy()}return window.onYouTubeIframeAPIReady=function(){return k(),new YT.Player(f,w)},Object.freeze({promise:d,create:k,load:O,canPlayType:j,play:E,pause:P,destroy:T,set src(e){if(_source="string"==typeof e?e:e[0].src,r){var t=b(_source);a?r.loadVideoById(t):r.cueVideoById(t)}},get src(){return r?r.getVideoUrl():""},set volume(t){c=t,r&&(r.setVolume(100*t),setTimeout((function(){var t=new CustomEvent("volumechange");e.dispatchEvent(t)}),50))},get volume(){return r&&(c=r.getVolume()/100),c},set muted(t){r&&(t?r.mute():r.unMute(),setTimeout((function(){var t=new CustomEvent("volumechange");e.dispatchEvent(t)}),50))},get muted(){return!!r&&r.isMuted()},set playbackRate(e){r&&r.setPlaybackRate(e)},get playbackRate(){return r?r.getPlaybackRate():1},set defaultPlaybackRate(e){r&&r.setPlaybackRate(e)},get defaultPlaybackRate(){return r?r.getPlaybackRate():1},set currentTime(t){r&&(r.seekTo(t),setTimeout((function(){var t=new CustomEvent("timeupdate");e.dispatchEvent(t)}),50))},get currentTime(){return r?r.getCurrentTime():0},get duration(){return r?r.getDuration():0},get paused(){return s},get ended(){return l}})}))})(),n=n.default})())); \ No newline at end of file +!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(this,(()=>(()=>{var e={714:(e,t)=>{"use strict";function r(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(e)))return;var r=[],n=!0,o=!1,a=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw a}}return r}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r0&&void 0!==arguments[0]?arguments[0]:{};if(arguments.length>1)return Promise.all(Array.prototype.slice.call(arguments).map(e));var n=l(t);return new Promise((function(e,o){if(c(t)&&t.url||n){n&&(t={url:t}),t=Object.assign({},v,t);var a=s(t);if(a){var i=d(t),u=t.removeScript;if(t.callBackName||t.jsonp){var l=r(y(t),3),m=l[0],b=l[1],h=l[2];t.url=m,b[h]=function(r){delete b[h],f(u,a,i),p(t),e(r||u?void 0:i)}}else i.addEventListener("load",(function(){f(u,a,i),p(t),e(u?void 0:i)}));i.addEventListener("error",(function(){a.removeChild(i),o("Error: loading script")})),i.src=t.url,a.appendChild(i)}else o("Error: no DOM element to append script")}else o("Error: object with url or url string needed")}))};var o=window,a="_$_".concat("simpleLoadScript","CallBacks_$_"),i=0,u=function(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()},c=function(e){return"object"===u(e)},l=function(e){return"string"===u(e)},s=function(e){return e.insertInto?document.querySelector(e.insertInto):e.inBody?document.body:document.head},d=function(e){var t=document.createElement("script");if(e.attrs&&c(e.attrs))for(var r=0,n=Object.keys(e.attrs);r{e.exports=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports},215:(e,t,r)=>{var n=r(71);e.exports=function(e,t){if(null==e)return{};var r,o,a=n(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a},e.exports.__esModule=!0,e.exports.default=e.exports},71:e=>{e.exports=function(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n=0||(o[r]=e[r]);return o},e.exports.__esModule=!0,e.exports.default=e.exports}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return e[n](a,a.exports,r),a.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var n={};return(()=>{"use strict";var e=r(215),t=r.n(e),n=r(416),o=r.n(n),a=r(714),i=r.n(a),u=["url","nocookie"];function c(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function l(e){for(var t=1;t2&&void 0!==arguments[2]&&arguments[2],c=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},s=1,d=!1,p=!0,f=new Promise((function(e){e()})),y="op-yt__".concat(e.id||(new Date).getTime()),v="AUDIO"===e.tagName,m=l(l({},{url:"https://www.youtube.com/iframe_api",autoplay:0,controls:0,disablekb:1,end:0,loop:0,modestbranding:0,playsinline:0,rel:0,showinfo:0,start:0,iv_load_policy:3,nocookie:!1}),c),b=m.url,h=m.nocookie,g=t()(m,u);function w(e){return e.match(/(?:(?:youtu\.be\/)|(?:v=)|(?:\/v\/))(\w+)/)[1]}var O=function(){o=setInterval((function(){var t=new CustomEvent("timeupdate");e.dispatchEvent(t)}),250)},k=function(){o&&clearInterval(o)},j={id:y,videoId:w(r.src),height:v?1:e.offsetHeight,width:v?1:e.offsetWidth,widget_referrer:window.location.host,origin:window.location.host,playerVars:g,events:{onReady:function(t){var r=(n=t.target).getIframe();("msLaunchUri"in window.navigator&&!("documentMode"in document)||/chrome/i.test(window.navigator.userAgent)||e.muted)&&n.mute(),["mouseover","mouseout"].forEach((function(t){r.addEventListener(t,(function(t){var r=new CustomEvent(t.type);e.dispatchEvent(r)}))})),["loadedmetadata","loadeddata","canplay"].forEach((function(t){var r=new CustomEvent(t);e.dispatchEvent(r)}))},onStateChange:function(t){var r=[];switch(t.data){case 0:r=["ended"],p=!1,d=!m.loop,m.loop||k();break;case 1:r=["play","playing"],p=!1,d=!1,O();break;case 2:r=["pause"],p=!0,d=!1,k();break;case 3:r=["progress"],d=!1;break;case 5:r=["loadeddata","loadedmetadata","canplay"],p=!0,d=!1;break;default:r=["loadedmetadata"],p=!0,d=!1}for(var n=0,o=r.length;n-1)&&!m.playlist&&-1===r.src.indexOf("playlist=")&&(m.playlist=w(r.src)),m.controls=0,m.enablejsapi=1,"undefined"!=typeof YT&&YT.loaded||i()(b),this}}function x(){return null}function P(e){return"video/x-youtube"===e}function _(){n.playVideo()}function T(){n.pauseVideo()}function S(){n&&n.destroy()}return window.onYouTubeIframeAPIReady=function(){return E(),new YT.Player(y,j)},Object.freeze({promise:f,create:E,load:x,canPlayType:P,play:_,pause:T,destroy:S,set src(e){if(_source="string"==typeof e?e:e[0].src,n){var t=w(_source);a?n.loadVideoById(t):n.cueVideoById(t)}},get src(){return n?n.getVideoUrl():""},set volume(t){s=t,n&&(n.setVolume(100*t),setTimeout((function(){var t=new CustomEvent("volumechange");e.dispatchEvent(t)}),50))},get volume(){return n&&(s=n.getVolume()/100),s},set muted(t){n&&(t?n.mute():n.unMute(),setTimeout((function(){var t=new CustomEvent("volumechange");e.dispatchEvent(t)}),50))},get muted(){return!!n&&n.isMuted()},set playbackRate(e){n&&n.setPlaybackRate(e)},get playbackRate(){return n?n.getPlaybackRate():1},set defaultPlaybackRate(e){n&&n.setPlaybackRate(e)},get defaultPlaybackRate(){return n?n.getPlaybackRate():1},set currentTime(t){n&&(n.seekTo(t),setTimeout((function(){var t=new CustomEvent("timeupdate");e.dispatchEvent(t)}),50))},get currentTime(){return n?n.getCurrentTime():0},get duration(){return n?n.getDuration():0},get paused(){return p},get ended(){return d}})}))})(),n=n.default})())); \ No newline at end of file diff --git a/src/youtube.js b/src/youtube.js index 24efdc0..01636c9 100644 --- a/src/youtube.js +++ b/src/youtube.js @@ -29,10 +29,7 @@ const YouTube = (element, media, autoplay = false, options = {}) => { nocookie: false, }; const playerVars = { ...opts, ...options }; - const { url: library, nocookie: noCookies } = playerVars; - - delete playerVars.url; - delete playerVars.nocookie; + const { url: library, nocookie: noCookies , ...rest } = playerVars; /** * Formats: @@ -48,14 +45,14 @@ const YouTube = (element, media, autoplay = false, options = {}) => { return url.match(/(?:(?:youtu\.be\/)|(?:v=)|(?:\/v\/))(\w+)/)[1]; } - function _startInterval() { + const _startInterval = () => { // create timer interval = setInterval(() => { const event = new CustomEvent('timeupdate'); element.dispatchEvent(event); }, 250); } - function _stopInterval() { + const _stopInterval = () => { if (interval) { clearInterval(interval); } @@ -66,15 +63,17 @@ const YouTube = (element, media, autoplay = false, options = {}) => { videoId: _getYouTubeId(media.src), height: isAudio ? 1 : element.offsetHeight, width: isAudio ? 1 : element.offsetWidth, - playerVars, + widget_referrer: window.location.host, origin: window.location.host, + playerVars: rest, events: { onReady: e => { player = e.target; const iframe = player.getIframe(); - // Check for `muted` attribute to start video without sound - if (element.muted) { + // Check if browser is a Chromium browser or the main element is muted; if so, mute it + // @see https://github.com/videojs/videojs-youtube/issues/593 + if ('msLaunchUri' in window.navigator && !('documentMode' in document) || /chrome/i.test(window.navigator.userAgent) || element.muted) { player.mute(); } @@ -92,7 +91,6 @@ const YouTube = (element, media, autoplay = false, options = {}) => { }, onStateChange: e => { let events = []; - switch (e.data) { case 0: // YT.PlayerState.ENDED events = ['ended'];