UNPKG

cdnbye

Version:

Let your viewers become your unlimitedly scalable CDN.

2 lines (1 loc) 8.7 kB
window.HlsJsPlayer=function(e){var t={};function o(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,o),n.l=!0,n.exports}return o.m=e,o.c=t,o.d=function(e,t,r){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(r,n,function(t){return e[t]}.bind(null,n));return r},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=0)}([function(e,t,o){e.exports=o(1)},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=function(){function e(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,o,r){return o&&e(t.prototype,o),r&&e(t,r),t}}(),i=s(o(2)),a=s(o(3));function s(e){return e&&e.__esModule?e:{default:e}}function c(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var d=function(e){function t(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=c(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));o.hlsOpts=e.hlsOpts||{},o.hlsOpts.mediaType=o.config.mediaType;var r=i.default.util,n=o;if(n.once("complete",(function(){if(n.config.isLive&&(r.addClass(n.root,"xgplayer-is-live"),!r.findDom(n.controls,".xgplayer-live"))){var e=r.createDom("xg-live",n.lang.LIVE||"正在直播",{},"xgplayer-live");n.controls.appendChild(e)}})),o.browser=a.default.getBrowserVersion(),void 0===n.config.useHls){if("mobile"===i.default.sniffer.device&&"MacIntel"!==navigator.platform&&"Win32"!==navigator.platform||o.browser.indexOf("Safari")>-1)return c(o)}else if(!n.config.useHls)return c(o);if(o._start=o.start,o.start=function(){window.XgVideoProxy||o.root.insertBefore(o.video,o.root.firstChild),setTimeout((function(){o.emit("complete"),o.danmu&&"function"==typeof o.danmu.resize&&o.danmu.resize()}),1)},Number.isFinite=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},!window.Hls)throw new Error("Add CDNBye Script before this script");var s=void 0;return s=new window.Hls(o.hlsOpts),o.hls=s,Object.defineProperty(n,"src",{get:function(){return n.currentSrc},set:function(e){r.removeClass(n.root,"xgplayer-is-live");var t=document.querySelector(".xgplayer-live");t&&t.parentNode.removeChild(t),n.autoplay=!0,n.paused||n.pause(),n.hls.stopLoad(),n.hls.detachMedia(),n.hls.destroy(),n.hls=new Hls(n.hlsOpts),n.register(e),n.once("canplay",(function(){n.play().catch((function(e){}))})),n.hls.loadSource(e),n.hls.attachMedia(n.video)},configurable:!0}),o.register(o.config.url),o.once("complete",(function(){s.attachMedia(n.video),n.config.videoInit||n.once("canplay",(function(){n.play().catch((function(e){}))}))})),o.once("destroy",(function(){s.stopLoad()})),o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),n(t,[{key:"switchURL",value:function(e){var t=this;t.url=e,t.config.url=e;var o=t.currentTime;i.default.util.addClass(t.root,"xgplayer-is-enter"),t.once("playing",(function(){i.default.util.removeClass(t.root,"xgplayer-is-enter")})),t.once("canplay",(function(){t.currentTime=o,t.play()})),"object"===r(t.hls)&&(t.hls.originUrl=e),t.src=e}},{key:"register",value:function(e){var t=this.hls,o=i.default.util,r=this;t.on(Hls.Events.MEDIA_ATTACHED,(function(){t.loadSource(e)})),t.on(Hls.Events.LEVEL_LOADED,(function(e,n){if(!t.inited&&(t.inited=!0,n&&n.details&&n.details.live&&(o.addClass(r.root,"xgplayer-is-live"),!o.findDom(r.root,".xgplayer-live")))){var i=o.createDom("xg-live",r.lang.LIVE||"正在直播",{},"xgplayer-live");r.controls.appendChild(i)}})),t.on(Hls.Events.ERROR,(function(e,o){if(r.emit("HLS_ERROR",{errorType:o.type,errorDetails:o.details,errorFatal:o.fatal}),o.fatal)switch(o.type){case Hls.ErrorTypes.NETWORK_ERROR:t.startLoad();break;case Hls.ErrorTypes.MEDIA_ERROR:t.recoverMediaError();break;default:r.emit("error",o)}})),this._statistics()}},{key:"_statistics",value:function(){var e={speed:0,playerType:"HlsPlayer"},t={videoDataRate:0,audioDataRate:0},o=this.hls,r=this;o.on(Hls.Events.FRAG_LOAD_PROGRESS,(function(t,o){e.speed=o.stats.loaded/1e3})),o.on(Hls.Events.FRAG_PARSING_DATA,(function(e,o){"video"===o.type&&(t.fps=parseInt(o.nb/(o.endPTS-o.startPTS)))})),o.on(Hls.Events.FRAG_PARSING_INIT_SEGMENT,(function(e,o){if(t.hasAudio=!!(o&&o.tracks&&o.tracks.audio),t.hasVideo=!!(o&&o.tracks&&o.tracks.video),t.hasAudio&&o.tracks.audio){var n=o.tracks.audio;t.audioChannelCount=n.metadata&&n.metadata.channelCount?n.metadata.channelCount:0,t.audioCodec=n.codec}if(t.hasVideo&&o.tracks.video){var i=o.tracks.video;t.videoCodec=i.codec,t.width=i.metadata&&i.metadata.width?i.metadata.width:0,t.height=i.metadata&&i.metadata.height?i.metadata.height:0}t.duration=o.frag&&o.frag.duration?o.frag.duration:0,t.level=o.frag&&o.frag.level?o.frag.level:0,(t.videoCodec||t.audioCodec)&&(t.mimeType='video/hls; codecs="'+t.videoCodec+";"+t.audioCodec+'"'),r.mediainfo=t,r.emit("media_info",t)})),this._statisticsTimmer=setInterval((function(){r.emit("statistics_info",e),e.speed=0}),1e3)}},{key:"destroy",value:function(){(function e(t,o,r){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,o);if(void 0===n){var i=Object.getPrototypeOf(t);return null===i?void 0:e(i,o,r)}if("value"in n)return n.value;var a=n.get;return void 0!==a?a.call(r):void 0})(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"destroy",this).call(this),clearInterval(this._statisticsTimmer)}}]),t}(i.default);d.isSupported=Hls.isSupported,d.HlsJs=Hls,t.default=d,e.exports=t.default},function(e,t){e.exports=window.Player},function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r={};r.getBrowserVersion=function(){var e=navigator.userAgent;if(e.toLowerCase().indexOf("mobile")>-1)return"Unknown";if(e.indexOf("Firefox")>-1)return"Firefox "+e.match(/firefox\/[\d.]+/gi)[0].match(/[\d]+/)[0];if(e.indexOf("Edge")>-1)return"Edge "+e.match(/edge\/[\d.]+/gi)[0].match(/[\d]+/)[0];if(e.indexOf("rv:11")>-1)return"IE 11";if(e.indexOf("Opera")>-1||e.indexOf("OPR")>-1){if(e.indexOf("Opera")>-1)return"Opera "+e.match(/opera\/[\d.]+/gi)[0].match(/[\d]+/)[0];if(e.indexOf("OPR")>-1)return"Opera "+e.match(/opr\/[\d.]+/gi)[0].match(/[\d]+/)[0]}else{if(e.indexOf("Chrome")>-1)return"Chrome "+e.match(/chrome\/[\d.]+/gi)[0].match(/[\d]+/)[0];if(e.indexOf("Safari")>-1)return"Safari "+e.match(/safari\/[\d.]+/gi)[0].match(/[\d]+/)[0];if(!(e.indexOf("MSIE")>-1||e.indexOf("Trident")>-1))return"Unknown";if(e.indexOf("MSIE")>-1)return"IE "+e.match(/msie [\d.]+/gi)[0].match(/[\d]+/)[0];if(e.indexOf("Trident")>-1){var t=e.match(/trident\/[\d.]+/gi)[0].match(/[\d]+/)[0];return"IE "+(parseInt(t)+4)}}},r.isP2pSupported=function(){return t=function(){if("undefined"!=typeof window)return window.MediaSource||window.WebKitMediaSource}(),o=window.SourceBuffer||window.WebKitSourceBuffer,r=t&&"function"==typeof t.isTypeSupported&&t.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"'),n=!o||o.prototype&&"function"==typeof o.prototype.appendBuffer&&"function"==typeof o.prototype.remove,!!r&&!!n&&((e=function(){if("undefined"==typeof window)return null;var e={RTCPeerConnection:window.RTCPeerConnection||window.mozRTCPeerConnection||window.webkitRTCPeerConnection,RTCSessionDescription:window.RTCSessionDescription||window.mozRTCSessionDescription||window.webkitRTCSessionDescription,RTCIceCandidate:window.RTCIceCandidate||window.mozRTCIceCandidate||window.webkitRTCIceCandidate};return e.RTCPeerConnection?e:null}())&&void 0!==e.RTCPeerConnection.prototype.createDataChannel);var e,t,o,r,n},t.default=r,e.exports=t.default}]);