cdnbye
Version:
Save Your Bandwidth using WebRTC.
2 lines • 16.1 kB
JavaScript
!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.jwplayer_hls_provider=a()}}(function(){return function(){function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){return e(b[g][1][a]||a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}return a}()({1:[function(a,b,c){"use strict";function d(){}function e(a,b,c){this.fn=a,this.context=b,this.once=c||!1}function f(){this._events=new d,this._eventsCount=0}var g=Object.prototype.hasOwnProperty,h="~";Object.create&&(d.prototype=Object.create(null),(new d).__proto__||(h=!1)),f.prototype.eventNames=function(){var a,b,c=[];if(0===this._eventsCount)return c;for(b in a=this._events)g.call(a,b)&&c.push(h?b.slice(1):b);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(a)):c},f.prototype.listeners=function(a,b){var c=h?h+a:a,d=this._events[c];if(b)return!!d;if(!d)return[];if(d.fn)return[d.fn];for(var e=0,f=d.length,g=new Array(f);e<f;e++)g[e]=d[e].fn;return g},f.prototype.emit=function(a,b,c,d,e,f){var g=h?h+a:a;if(!this._events[g])return!1;var i,j,k=this._events[g],l=arguments.length;if(k.fn){switch(k.once&&this.removeListener(a,k.fn,void 0,!0),l){case 1:return k.fn.call(k.context),!0;case 2:return k.fn.call(k.context,b),!0;case 3:return k.fn.call(k.context,b,c),!0;case 4:return k.fn.call(k.context,b,c,d),!0;case 5:return k.fn.call(k.context,b,c,d,e),!0;case 6:return k.fn.call(k.context,b,c,d,e,f),!0}for(j=1,i=new Array(l-1);j<l;j++)i[j-1]=arguments[j];k.fn.apply(k.context,i)}else{var m,n=k.length;for(j=0;j<n;j++)switch(k[j].once&&this.removeListener(a,k[j].fn,void 0,!0),l){case 1:k[j].fn.call(k[j].context);break;case 2:k[j].fn.call(k[j].context,b);break;case 3:k[j].fn.call(k[j].context,b,c);break;case 4:k[j].fn.call(k[j].context,b,c,d);break;default:if(!i)for(m=1,i=new Array(l-1);m<l;m++)i[m-1]=arguments[m];k[j].fn.apply(k[j].context,i)}}return!0},f.prototype.on=function(a,b,c){var d=new e(b,c||this),f=h?h+a:a;return this._events[f]?this._events[f].fn?this._events[f]=[this._events[f],d]:this._events[f].push(d):(this._events[f]=d,this._eventsCount++),this},f.prototype.once=function(a,b,c){var d=new e(b,c||this,!0),f=h?h+a:a;return this._events[f]?this._events[f].fn?this._events[f]=[this._events[f],d]:this._events[f].push(d):(this._events[f]=d,this._eventsCount++),this},f.prototype.removeListener=function(a,b,c,e){var f=h?h+a:a;if(!this._events[f])return this;if(!b)return 0==--this._eventsCount?this._events=new d:delete this._events[f],this;var g=this._events[f];if(g.fn)g.fn!==b||e&&!g.once||c&&g.context!==c||(0==--this._eventsCount?this._events=new d:delete this._events[f]);else{for(var i=0,j=[],k=g.length;i<k;i++)(g[i].fn!==b||e&&!g[i].once||c&&g[i].context!==c)&&j.push(g[i]);j.length?this._events[f]=1===j.length?j[0]:j:0==--this._eventsCount?this._events=new d:delete this._events[f]}return this},f.prototype.removeAllListeners=function(a){var b;return a?(b=h?h+a:a,this._events[b]&&(0==--this._eventsCount?this._events=new d:delete this._events[b])):(this._events=new d,this._eventsCount=0),this},f.prototype.off=f.prototype.removeListener,f.prototype.addListener=f.prototype.on,f.prototype.setMaxListeners=function(){return this},f.prefixed=h,f.EventEmitter=f,void 0!==b&&(b.exports=f)},{}],2:[function(a,b,c){"use strict";function d(a){function b(a){return function(){}}function c(a){function b(){a.removeEventListener("playing",c),a.removeEventListener("pause",c),a.removeEventListener("abort",c),a.removeEventListener("error",c)}function c(a){b(),"playing"!=a.type&&e('play() was interrupted by a "'+a.type+'" event')}if(a.paused)return void e("video play refused");a.addEventListener("playing",c),a.addEventListener("abort",c),a.addEventListener("error",c),a.addEventListener("pause",c)}function d(){var a=G.play()||c(G);a&&a.catch?a.catch(function(a){e("video_play failed with "+a),console.warn(a),"NotAllowedError"==a.name&&G.hasAttribute("jw-gesture-required")&&(A.trigger("autoplayFailed"),G.setAttribute("autoplay-failed","failed"))}):G.hasAttribute("jw-gesture-required")&&(A.trigger("autoplayFailed"),G.setAttribute("autoplay-failed","failed"))}function e(a){}function f(){e("hls_play state: "+A.hls_state+" att:"+A.attached),!(A.hls_queued.play="ready"!=A.hls_state)&&A.attached&&(A.hls_restore_pos(),d())}function i(a){a&&("ready"==A.hls_state&&(A.hls_state="idle"),A.level_cb&&C.off(y.Events.LEVEL_LOADED,A.level_cb),A.level_cb=function(){e("hls play queued on level_cb:"+A.hls_queued.play),C.off(y.Events.LEVEL_LOADED,A.level_cb),A.level_cb=void 0,A.hls_state="ready",A.hls_queued.play&&f(),A.trigger(j.JWPLAYER_MEDIA_BUFFER_FULL)},C.on(y.Events.LEVEL_LOADED,A.level_cb),C.loadSource(a),C.media||A.attachMedia())}function k(a){return a&&a.find(function(a){return a.default})||a[0]}function l(a){if(A.renderNatively)for(var b=G.textTracks,c=a.tracks[a.track].id,d=0;d<b.length;d++)b[d].mode=b[d]._id==c?"showing":"hidden"}function m(){var a,b,c=G.seekable?G.seekable.length:0;for(b=0,a=0;a<c;a++)b=Math.max(b,G.seekable.end(a));return b}function n(){var a=G.duration,b=m();if(a==1/0&&b){var c=b-G.seekable.start(0);c!=1/0&&c>120&&(a=-c)}return a}function o(){return p()?1/0:n()}function p(){var a,b;try{if(!(b=C.streamController.levels))return;var c=b.find(function(a){return a.details});a=c&&!!c.details.live}catch(a){e("is_live failed with "+a)}return a}function q(){var a=G.buffered,b=G.duration;return!a||!a.length||b<=0||b==1/0?0:Math.min(a.end(a.length-1)/b,1)}function r(a,b,c){a==K&&c==L||(K=a,A.trigger(j.JWPLAYER_MEDIA_BUFFER,{bufferPercent:100*a,position:b,duration:o()}))}function s(){A.setState("complete"),A.trigger(j.JWPLAYER_MEDIA_COMPLETE),A.before_complete=!1}function t(a){if(void 0===a)return"";if(!a)return"0";var b=1024,c=["","K","M","G","T","P"],d=Math.floor(Math.log(a)/Math.log(b));return(a/=Math.pow(b,d))<.001?"0":(a>=b-1&&(a=Math.trunc(a)),a.toFixed(a<1?3:a<10?2:a<100?1:0).replace(/\.0*$/,"")+c[d])}function u(a){return a.height?a.height+"p":a.width?Math.round(9*a.width/16)+"p":a.bitrate?t(a.bitrate)+"bps":0}function v(){var a=C.levels||[],b=[];return a.length>1&&b.push({label:"Auto"}),a.forEach(function(a){b.push({bitrate:a.bitrate,height:a.height,label:u(a),width:a.width})}),b}function w(a){var b=C.levels||[];return a=a||C.currentLevel,{jw:-1==C.manual_level||b.length<2?0:a+1,real:b.length<2?0:a+1}}var x=h.jwplayer||window.jwplayer,y=h.Hls||window.Hls,z=a&&x(a);z.provider=this;var A=this;this.hls_restore_pos=function(){var a=this.hls_queued.seek,b=G.currentTime;"STOPPED"==C.streamController.state&&(C.streamController.startPosition=0,C.startLoad(a||0)),a&&(this._in_seek=!0,G.currentTime=a,this.trigger(j.JWPLAYER_MEDIA_SEEK,{position:b,offset:a}),G.readyState||G.dispatchEvent(new Event("seeking")),this.hls_queued.seek=0)},this.events=new g,this.addEventListener=this.on=this.events.on.bind(this.events),this.once=this.events.once.bind(this.events),this.removeEventListener=this.off=this.events.off.bind(this.events),this.trigger=this.emit=function(a){if(A.attached||A.before_complete){var b=[].slice.call(arguments);A.events.emit.apply(this.events,b),"all"!=a&&(b.unshift("all"),A.events.emit.apply(this.events,b))}},this.removeAllListeners=function(a){this.events.removeAllListeners(a)},this.hls_queued={play:!1,seek:0},this.attached=!0,this.hls_state="idle",this.is_mobile=function(){var a,b,c=navigator.userAgent;if((a=/iP(hone|ad|od)/i.test(c))||(b=/Android/i.test(c)))return{is_ios:a,is_android:b}},this.supports_captions=function(){var a=navigator.userAgent;return/(iPhone|iPad|iPod|iPod touch);.*?OS/.test(a)||/ (Chrome|Version)\/\d+(\.\d+)+.* Safari\/\d+(\.\d+)+/.test(a)||/Firefox\/(\d+(?:\.\d+)+)/.test(a)};var B,C,D,E,F=document.getElementById(a),G=F?F.querySelector("video"):void 0,H=this.is_mobile(),I={reason:"initial choice",mode:"auto"};G||(G=document.createElement("video"),H&&G.setAttribute("jw-gesture-required","")),G.className="jw-video jw-reset",G.cdnbye_dm_hls_attached=!0,function(a,b){for(var c=a;c&&!c.hasOwnProperty("src");c=Object.getPrototypeOf(c));if(c){var d=Object.getOwnPropertyDescriptor(c,"src");d.get||d.set||(d.get=function(){var b=a.getAttribute("src");return null!=b?b:""},d.set=function(b){var c=document.createElement("source");c.src=b||"",a.setAttribute("src",c.src)}),Object.defineProperty(a,"src",{configurable:!0,enumerable:!1,set:function(c){b(d.get.call(a),c)&&d.set.call(a,c)},get:d.get})}}(G,function(a,b){return b!=a+"?"});var J=h.hls_params||{};this.ad_count=0,z&&(J=z.getConfig().hlsjsConfig,z.on("captionsList",l),z.on("captionsChanged",l),z.on("adImpression",function(){A.ad_count++}),z.on("adComplete",function(){A.ad_count--}),z.on("adSkipped",function(){A.ad_count--})),this.hls=C=new y(J),z&&(z.hls=C);var K,L,M,N={durationchange:function(){L=n(),r(q(),M,L)},ended:function(){"idle"!=A.state&&"complete"!=A.state&&(A.before_complete=!0,A.trigger(j.JWPLAYER_MEDIA_BEFORECOMPLETE),A.attached&&s())},error:function(){A.trigger(j.JWPLAYER_MEDIA_ERROR,{message:"Error loading media: File could not be played"})},loadstart:function(){G.setAttribute("jw-loaded","started")},loadeddata:function(){G.setAttribute("jw-loaded","data"),A.supports_captions()&&(G.textTracks.onaddtrack=function(){A.renderNatively=!0,A.trigger("subtitlesTracks",{tracks:G.textTracks})},G.textTracks.length&&G.textTracks.onaddtrack(),A.trigger(j.JWPLAYER_MEDIA_TYPE,{mediaType:G.videoHeight?"video":"audio"}))},loadedmetadata:function(){G.muted&&(G.muted=!1,G.muted=!0),G.setAttribute("jw-loaded","meta"),L=n(),A.trigger(j.JWPLAYER_MEDIA_META,{duration:o(),height:G.videoHeight,width:G.videoWidth})},canplay:function(){E=!0,A.trigger(j.JWPLAYER_MEDIA_BUFFER_FULL)},playing:function(){A.setState("playing"),G.hasAttribute("jw-played")||G.setAttribute("jw-played",""),G.hasAttribute("jw-gesture-required")&&(G.removeAttribute("jw-gesture-required"),G.removeAttribute("autoplay-failed")),A.trigger(j.JWPLAYER_PROVIDER_FIRST_FRAME,{})},pause:function(){"complete"!=A.state&&G.currentTime!=G.duration&&A.setState("paused")},seeking:function(){A._in_seek||(A._in_seek=!0,A.trigger(j.JWPLAYER_MEDIA_SEEK,{position:M,offset:G.currentTime}))},seeked:function(){A._in_seek=!1,A.trigger(j.JWPLAYER_MEDIA_SEEKED)},progress:function(){r(q(),M,L)},timeupdate:function(){L=n(),M=L<0?-(m()-G.currentTime):G.currentTime,r(q(),M,L),"playing"==A.state&&A.trigger(j.JWPLAYER_MEDIA_TIME,{position:M,duration:o()})}};for(var O in N)G.addEventListener(O,function(a){return function(){A.attached&&N[a]()}}(O),!1);C.on(y.Events.ERROR,function(a,b){if(b.fatal){var c;switch(b.details){case y.ErrorDetails.MANIFEST_LOAD_ERROR:case y.ErrorDetails.MANIFEST_LOAD_TIMEOUT:c="Cannot load M3U8: "+b.response.statusText;break;default:c="Error loading media: "+b.details}A.trigger(j.JWPLAYER_MEDIA_ERROR,{message:c})}}),C.on(y.Events.MANIFEST_LOADED,function(){A.trigger(j.JWPLAYER_MEDIA_LEVELS,{currentQuality:w().jw,levels:v()})}),C.on(y.Events.LEVEL_SWITCH,function(a,b){var c=v(),d=w(b.level);A.trigger(j.JWPLAYER_MEDIA_LEVEL_CHANGED,{currentQuality:d.jw,levels:c});var e=c[d.real];I.level=e,I.level.index=d.real,I.level.label=-1==C.manual_level&&c.length>1?"auto":e.label,I.reason=I.reason||"auto",A.trigger("visualQuality",I),I.reason=""}),this.init=function(a){D=!1,G.setAttribute("jw-loaded","init")},this.load=function(a){if(this.attached){var b=k(a.sources).file,c=G.getAttribute("jw-loaded"),e=this.hls_queued,g=G.hasAttribute("jw-played");if(H&&!g||this.setState("loading"),e.seek=Math.max(a.starttime-(e.rw_sec||0),0),"ready"!=this.hls_state||(this.source||"")!=b||["init","started"].includes(c)){D=!1,G.load(),C.stopLoad(C.media&&"ready"==this.hls_state&&"init"==c),i(this.source=b),G.setAttribute("jw-loaded","init")}else f();H&&!g&&(D||H.is_ios&&!E||(D=!0,E=!1,d()),G.paused||"playing"==this.state||this.setState("loading"))}},this.play=function(){f()},this.pause=function(){G.pause(),A.setState("paused")},this.stop=function(){C.stopLoad(),A.setState("idle")},this.volume=function(a){G.volume=Math.min(a/100,1)},this.mute=function(a){G.muted=!!a},this.seek=function(a){if(this._in_seek=!0,"ready"==this.hls_state){var b=G.currentTime;G.currentTime=a,this.trigger(j.JWPLAYER_MEDIA_SEEK,{position:b,offset:a})}else this.hls_queued.seek=a},this.resize=function(a,b,c){},this.remove=function(){this.in_container=!1,C.stopLoad(),this.source=void 0,B===G.parentNode&&B.removeChild(G)},this.destroy=function(){for(var a in N)G.removeEventListener(a,N[a],!1);this.removeAllListeners()},this.setVisibility=function(a){B.style.visibility=a?"visible":"",B.style.opacity=a?1:0},this.setFullscreen=function(){return!1},this.getFullscreen=b("getFullscreen"),this.getContainer=function(){return B},this.setContainer=function(a){B=a,B.appendChild(G),this.in_container=!0},C.manual_level=-1,this.setCurrentQuality=function(a){a!=C.manual_level+1&&(C.manual_level=a-1,C.cdnbye_adaptive||(C.loadLevel=C.manual_level),A.trigger(j.JWPLAYER_MEDIA_LEVEL_CHANGED,{currentQuality:a,levels:v()}),I.reason="api")},this.getName=function(){return{name:"CDNBye/hls"}},this.get_position=function(){return G.currentTime},this.getQualityLevels=function(){return v()},this.getCurrentQuality=function(){return w(C.loadLevel).jw},this.getAudioTracks=b("getAudioTracks"),this.getCurrentAudioTrack=b("getCurrentAudioTrack"),this.setCurrentAudioTrack=b("setCurrentAudioTrack"),this.checkComplete=function(){return!!this.before_complete},this.attachMedia=function(){if(this.before_complete)return s();this.ad_count&&e("jwprovider attach inside ad "+this.ad_count),this.attached=!0,C.attachMedia(G)},this.detachMedia=function(){return C.trigger(y.Events.BUFFER_RESET),C.detachMedia(),this.level_cb&&(C.off(y.Events.LEVEL_LOADED,this.level_cb),this.level_cb=void 0),this.attached=!1,G},this.setState=function(a){var b=this.state||"idle";this.state=a,a!=b&&this.trigger(j.JWPLAYER_PLAYER_STATE,{newstate:a})},this.sendMediaType=function(a){var b=["oga","aac","mp3","mpeg","vorbis"].includes(a[0].type);this.trigger(j.JWPLAYER_MEDIA_TYPE,{mediaType:b?"audio":"video"})}}function e(){for(var a,b=h.jwplayer||window.jwplayer,c=0,d=[];(a=b(c++))&&a.pause;)d.push(a);return d}function f(a){return"hls"==a.type||(a.file||"").match(/\.m3u8$/)}var g=a("eventemitter3"),h=b.exports=d,i=!1,j={JWPLAYER_MEDIA_BEFORECOMPLETE:"beforeComplete",JWPLAYER_MEDIA_BUFFER:"bufferChange",JWPLAYER_MEDIA_BUFFER_FULL:"bufferFull",JWPLAYER_MEDIA_COMPLETE:"complete",JWPLAYER_MEDIA_ERROR:"mediaError",JWPLAYER_MEDIA_LEVELS:"levels",JWPLAYER_MEDIA_LEVEL_CHANGED:"levelsChanged",JWPLAYER_MEDIA_META:"meta",JWPLAYER_MEDIA_SEEK:"seek",JWPLAYER_MEDIA_SEEKED:"seeked",JWPLAYER_MEDIA_TIME:"time",JWPLAYER_MEDIA_TYPE:"mediaType",JWPLAYER_PLAYER_STATE:"state",JWPLAYER_PROVIDER_FIRST_FRAME:"providerFirstFrame"};h.getName=function(){return{name:"cdnbye/hls"}},h.supports=function(a){var b=h.Hls||window.Hls;return!e().every(function(b){var c=b.getPlaylist();return(c.every?c:[{sources:[c]}]).every(function(b){return(b.allSources||b.sources||[{file:b.file}]).every(function(b){return b.file!=a.file})})})&&!h.disabled&&f(a)&&b&&b.isSupported()},h.attach=function(){var a=h.jwplayer||window.jwplayer;h.disabled=!1,i||(i=!0,a.api.registerProvider(this))},h.detach=function(a){h.disabled=!0,a&&a.attached&&(a.setState("idle"),a.detachMedia())},h.reload_jwplayer_instances=function(){e().forEach(function(a){var b=a.getConfig();if(b){if(b.advertising&&!b.advertising.client&&b.plugins)for(var c in b.plugins)if(b.plugins[c]===b.advertising){var d=c.match(/\/(\w+)\.js$/);b.advertising.client=d&&d[1];break}a.setup(b)}})},h.VERSION="0.0.79",h.attach()},{eventemitter3:1}]},{},[2])(2)});
//# sourceMappingURL=jwplayer.hlsjs.provider.min.js.map