diff --git a/embed/min/player.js b/embed/min/player.js index a26da177..f803d373 100644 --- a/embed/min/player.js +++ b/embed/min/player.js @@ -1 +1 @@ -var MistUtil={format:{time:function(e,t){if(isNaN(e)||!isFinite(e))return e;t||(t={});var i=e<0?" ago":"";e=Math.abs(e);var r=Math.floor(e/86400);e-=86400*r;var n=Math.floor(e/3600);e-=3600*n;var a=Math.floor(e/60),s=Math.round(e%1*1e3);e=Math.floor(e-60*a);var o=[];return r&&(r=r+" day"+(r>1?"s":"")+", "),n||r?(o.push(n),o.push(("0"+a).slice(-2))):o.push(a),o.push(("0"+Math.floor(e)).slice(-2)),t.ms&&(o[o.length-1]+="."+("000"+s).slice(-3)),(r||"")+o.join(":")+i},ago:function(e,t){if(isNaN(e.getTime()))return"";var i=t||(new Date).getTime()-e.getTime(),r="",n=i<0;return n&&(i*=-1),i<1e3?r="live":i<6e4?(r=Math.round(i/1e3)+" sec",n?r="in "+r:r+=" ago"):r=!t&&(new Date).toLocaleDateString()==e.toLocaleDateString()||t<864e5?e.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit",second:"2-digit"}):i<5184e5?e.toLocaleString(void 0,{weekday:"short",hour:"numeric",minute:"2-digit",second:"2-digit"}):!t&&(new Date).getFullYear()==e.getFullYear()||t<316224e5?e.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit",second:"2-digit"}):e.toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit"}),r},ucFirst:function(e){return e.charAt(0).toUpperCase()+e.slice(1)},number:function(e){if(isNaN(Number(e))||0==Number(e))return e;var t=Math.max(3,Math.ceil(Math.log(e)/Math.LN10)),i=Math.pow(10,t-Math.floor(Math.log(e)/Math.LN10)-1);if((e=Math.round(e*i)/i)>=1e4){number=e.toString().split(".");for(var r=/(\d+)(\d{3})/;r.test(number[0]);)number[0]=number[0].replace(r,"$1 $2");e=number.join(".")}return e},bytes:function(e,t){if(isNaN(Number(e)))return e;var i=t?["bits","Kb","Mb","Gb","Tb","Pb"]:["bytes","KB","MB","GB","TB","PB"];if(0==e)unit=i[0];else{var r=Math.floor(Math.log(Math.abs(e))/Math.log(1024));r<0?unit=i[0]:(e/=Math.pow(1024,r),unit=i[r])}return this.number(e)+unit},bits:function(e){return this.bytes(e,!0)},mime2human:function(e){switch(e){case"html5/video/webm":return"WebM";case"html5/application/vnd.apple.mpegurl":return"HLS (TS)";case"html5/application/vnd.apple.mpegurl;version=7":return"HLS (CMAF)";case"flash/10":return"Flash (RTMP)";case"flash/11":return"Flash (HDS)";case"flash/7":return"Flash (Progressive)";case"html5/video/mpeg":return"TS";case"html5/application/vnd.ms-sstr+xml":case"html5/application/vnd.ms-ss":return"Smooth Streaming";case"dash/video/mp4":return"DASH";case"webrtc":return"WebRTC (WS)";case"whep":return"WebRTC (WHEP)";case"silverlight":return"Smooth streaming (Silverlight)";case"html5/text/vtt":return"VTT subtitles";case"html5/text/plain":return"SRT subtitles";default:return e.replace("html5/","").replace("video/","").replace("audio/","").toLocaleUpperCase()}}},class:{add:function(e,t){if("classList"in e)e.classList.add(t);else{var i=this.get(e);i.push(t),this.set(e,i)}},remove:function(e,t){if("classList"in e)e.classList.remove(t);else{for(var i=this.get(e),r=i.length-1;r>=0;r--)i[r]==t&&i.splice(r);this.set(e,i)}},get:function(e){var t=e.getAttribute("class");return t&&""!=t?t.split(" "):[]},set:function(e,t){e.setAttribute("class",t.join(" "))},has:function(e,t){return e.className.split(" ").indexOf(t)>=0}},object:{extend:function(e,t,i){for(var r in t)i&&"object"==typeof t[r]&&!("nodeType"in t[r])?(r in e||(MistUtil.array.is(t[r])?e[r]=[]:e[r]={}),this.extend(e[r],t[r],!0)):e[r]=t[r];return e},keys:function(e,t){var i=[];for(var r in e)i.push(r);return t&&("function"!=typeof t&&(t=function(e,t){return e.localeCompare(t)}),i.sort((function(i,r){return t(i,r,e[i],e[r])}))),i},values:function(e,t){var i=this.keys(e,t);for(var r in values=[],i)values.push(e[i[r]]);return values}},array:{indexOf:function(e,t){if(!(e instanceof Array))throw"Tried to use indexOf on something that is not an array";if("indexOf"in e)return e.indexOf(t);for(var i;it?1:e=0?r:i.length}if("function"==typeof e)return e(t);if("object"==typeof e){if(e instanceof Array)return i(t,e[0],e[1]);for(var r in e)return i(t,r,e[r])}if(e in t)return t[e];throw"Invalid sorting rule: "+e+". This should be a function, object or key of "+JSON.stringify(t)+"."}return e.sort((function(e,n){var a=0;for(var s in t){var o=t[s];if(0!=(a=i(r(o,e),r(o,n))))break}return a})),e}},createUnique:function(){var e="uid"+Math.random().toString().replace("0.","");return document.querySelector("."+e)?createUnique():e},http:{getpost:function(e,t,i,r,n){var a=new XMLHttpRequest;if(a.open(e,t,!0),"POST"==e&&a.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n&&(a.timeout=8e3),a.onload=function(){var e=a.status;e>=200&&e<300?r(a.response):n&&n(a)},n&&(a.onerror=function(){n(a)},a.ontimeout=a.onerror),"POST"==e){var s,o=[];for(var l in i)o.push(l+"="+encodeURIComponent(i[l]));o.length&&(s=o.join("&")),a.send(s)}else a.send()},get:function(e,t,i){this.getpost("GET",e,null,t,i)},post:function(e,t,i,r){this.getpost("POST",e,t,i,r)},url:{addParam:function(e,t){var i=e.split("?"),r=[i.shift()],n=[];for(var a in i.length&&(n=i[0].split("&")),t)n.push(a+"="+t[a]);return n.length&&r.push(n.join("&")),r.join("?")},append:function(e,t){var i=document.createElement("a");return i.href=e,"?"==t[0]?""==i.search?i.search=t:i.search+="&"+t.slice(1):"&"==t[0]?""==i.search?i.search="?"+t.slice(1):i.search+=t:i.href+=t,i.href},split:function(e){var t=document.createElement("a");return t.href=e,{protocol:t.protocol,host:t.hostname,hash:t.hash,port:t.port,path:t.pathname.replace(/\/*$/,"")}},sanitizeHost:function(e){var t=MistUtil.http.url.split(e);return t.protocol+"//"+t.host+(t.port&&""!=t.port?":"+t.port:"")+(t.hash&&""!=t.hash?"#"+t.hash:"")+(t.path?"/"==t.path.charAt(0)?t.path:"/"+t.path:"")}}},css:{cache:{},load:function(e,t,i){var r=document.createElement("style");r.type="text/css",r.setAttribute("data-source",e),i&&(r.callback=i);var n=this.cache;function a(e){var i=MistUtil.css.applyColors(e,t);"callback"in r?r.callback(i):r.textContent=i}if(e in n)n[e]instanceof Array?n[e].push(a):a(n[e]);else{n[e]=[a];var s=3;!function t(){MistUtil.http.get(e,(function(t){for(var i in n[e])n[e][i](t);n[e]=t}),(function(){if(s>0)s--,setTimeout(t,2e3);else{var i="/*Failed to load*/";for(var r in n[e])n[e][r](i);n[e]=i}}))}()}return r},applyColors:function(e,t){return e.replace(/\$([^\s^;^}]*)/g,(function(e,i){var r=i.split("."),n=t;for(var a in r)n=n[r[a]];return n}))},createStyle:function(e,t,i){var r=document.createElement("style");return r.type="text/css",e&&(t&&(e=this.prependClass(e,t,i)),r.textContent=e),r},prependClass:function(e,t,i){var r=!1;"string"!=typeof e&&("unprepended"in(r=e)||(r.unprepended=r.textContent),e=r.unprepended);var n=(e=e.replace(/\/\*.*?\*\//g,"")).match(/@[^}]*}/g);for(var a in n){e=e.replace(n[a],"@@#@@");for(var s=1;s0)s=r.bps>131072?Math.round(r.bps/1024/1024*8)+"mbps":Math.round(r.bps/1024*8)+"kbps",n[a]=s;break;case"fpks":r.fpks>0&&(n[a]=r.fpks/1e3+"fps");break;case"channels":r.channels>0&&(n[a]=1==r.channels?"Mono":2==r.channels?"Stereo":"Surround ("+r.channels+"ch)");break;case"rate":n[a]=Math.round(.001*r.rate)+"Khz";break;case"language":"Undetermined"!=r[a]&&(n[a]=r[a]);break;case"codec":if("meta"==r.codec)continue;n[a]=r[a]}r.describe=n}for(var o in t){var l=!1;for(var i in t[o])if(l){if(MistUtil.object.keys(t[o]).length>1)for(var a in t[o][i].describe)l[a]!=t[o][i].describe[a]&&delete l[a]}else l=MistUtil.object.extend({},t[o][i].describe);for(var i in t[o]){var c={},d={};for(var a in t[o][i].describe)a in l?d[a]=t[o][i].describe[a]:c[a]=t[o][i].describe[a];t[o][i].different=c,t[o][i].same=d;var u=MistUtil.object.values(c);t[o][i].displayName=u.length?u.join(", "):MistUtil.object.values(t[o][i].describe).join(" ")}var p={};for(var i in t[o]){if(t[o][i].displayName in p){var h=1;for(var i in t[o])t[o][i].different.trackid=h+")",t[o][i].displayName="Track "+h+" ("+t[o][i].displayName+")",h++;break}p[t[o][i].displayName]=1}}return t},translateCodec:function(e){function t(t){return("0"+e.init.charCodeAt(t).toString(16)).slice(-2)}switch(e.codec){case"AAC":return"mp4a.40.2";case"MP3":return"mp3";case"AC3":return"ec-3";case"H264":return"avc1."+t(1)+t(2)+t(3);case"HEVC":return"hev1."+t(1)+t(6)+t(7)+t(8)+t(9)+t(10)+t(11)+t(12);default:return e.codec.toLowerCase()}}},isTouchDevice:function(){return"ontouchstart"in window||navigator.msMaxTouchPoints>0},getPos:function(e,t){e.currentStyle||window.getComputedStyle(e,null);for(var i=1,r=e;r;)r.style.zoom&&""!=r.style.zoom&&(i*=parseFloat(r.style.zoom,10)),r=r.parentElement;var n=e.getBoundingClientRect().left-(parseInt(e.borderLeftWidth,10)||0),a=e.getBoundingClientRect().width,s=Math.max(0,(t.clientX/i-n)/a);return s=Math.min(s,1)},createGraph:function(e,t){var i="http://www.w3.org/2000/svg",r=document.createElementNS(i,"svg");r.setAttributeNS(null,"height","100%"),r.setAttributeNS(null,"width","100%"),r.setAttributeNS(null,"class","mist icon graph"),r.setAttributeNS(null,"preserveAspectRatio","none");var n=e.x[0],a=e.y[0];if(t.differentiate)for(var s=1;st.x.count&&(l.shift(),d()),d(e.x-n,-1*e.y),this.setAttributeNS(null,"d","M"+l.join(" L")),h()}},r.addData=function(e){m.addData(e)},r},getBrowser:function(){var e=window.navigator.userAgent;return e.indexOf("MSIE ")>=0||e.indexOf("Trident/")>=0?"ie":e.indexOf("Edge/")>=0?"edge":e.indexOf("Opera")>=0||e.indexOf("OPR")>=0?"opera":e.indexOf("Chrome")>=0?"chrome":e.indexOf("Safari")>=0?"safari":e.indexOf("Firefox")>=0&&"firefox"},getAndroid:function(){var e=navigator.userAgent.toLowerCase().match(/android\s([\d\.]*)/i);return!!e&&e[1]},sources:{find:function(e,t){e:for(var i in e){for(var r in t)if("protocol"==r){if(e[i].url.slice(0,t.protocol.length)!=t.protocol)continue e}else if(e[i][r]!=t[r])continue e;return e[i]}return!1}}};if(void 0===MistSkins)var MistSkins={};if("undefined"!=typeof mistoptions&&"host"in mistoptions)var misthost=MistUtil.http.url.sanitizeHost(mistoptions.host);else misthost="..";function MistSkin(e){e.skin=this,this.applySkinOptions=function(t){var i;return"string"==typeof t&&t in MistSkins&&(t=MistUtil.object.extend({},MistSkins[t],!0)),i="inherit"in t&&t.inherit&&t.inherit in MistSkins?this.applySkinOptions(t.inherit):MistSkins.default,this.structure=MistUtil.object.extend({},i.structure),t&&"structure"in t&&MistUtil.object.extend(this.structure,t.structure),this.blueprints=MistUtil.object.extend({},i.blueprints),t&&"blueprints"in t&&MistUtil.object.extend(this.blueprints,t.blueprints),this.icons=MistUtil.object.extend({},i.icons,!0),t&&"icons"in t&&MistUtil.object.extend(this.icons.blueprints,t.icons),this.icons.build=function(t,i,r){i||(i=22);var n,a=this.blueprints[t];n="function"==typeof a.svg?a.svg.call(e,r):a.svg,"object"!=typeof i&&(i={height:i,width:i}),"object"!=typeof a.size&&(a.size={height:a.size,width:a.size}),(!("width"in i)&&"height"in i||!("height"in i)&&"width"in i)&&("width"in i&&(i.height=i.width*a.size.height/a.size.width),"height"in i&&(i.width=i.height*a.size.width/a.size.height));var s="";s+='',s+='',s+=n,s+="",s+="";var o=document.createElement("div");return o.innerHTML=s,o.firstChild},this.colors=MistUtil.object.extend({},i.colors),t&&"colors"in t&&MistUtil.object.extend(this.colors,t.colors,!0),this.css=MistUtil.object.extend({},i.css),t&&"css"in t&&MistUtil.object.extend(this.css,t.css),this},this.applySkinOptions("skin"in e.options?e.options.skin:"default");var t=[];for(var i in this.css)if("string"==typeof this.css[i]){var r=MistUtil.css.load(e.urlappend(this.css[i]),this.colors);t.push(r)}this.css=t}function MistUI(e,t){e.UI=this,this.elements=[],this.buildStructure=function(t){if("function"==typeof t&&(t=t.call(e)),"if"in t){var i=!1;if(t.if.call(e,t)?i=t.then:"else"in t&&(i=t.else),!i)return;for(var r in t)["if","then","else"].indexOf(r)<0&&(r in i?(i[r]instanceof Array||(i[r]=[i[r]]),i[r]=i[r].concat(t[r])):i[r]=t[r]);return this.buildStructure(i)}if("type"in t&&t.type in e.skin.blueprints){var n=e.skin.blueprints[t.type].call(e,t);if(!n)return;if(MistUtil.class.add(n,"mistvideo-"+t.type),"css"in t){var a=MistUtil.createUnique();for(var r in t.css=[].concat(t.css),t.css){var s=MistUtil.css.createStyle(t.css[r],a);n.appendChild(s)}MistUtil.class.add(n,a),n.uid=a}if("classes"in t)for(var r in t.classes)MistUtil.class.add(n,t.classes[r]);if("title"in t&&(n.title=t.title),"style"in t)for(var r in t.style)n.style[r]=t.style[r];if("children"in t)for(var r in t.children){var o=this.buildStructure(t.children[r]);o&&n.appendChild(o)}return e.UI.elements.push(n),n}return!1},this.build=function(){return this.buildStructure(t||e.skin.structure.main)};var i=this.build(),r=MistUtil.createUnique(),n=0;for(var a in e.skin.css.length&&(i.style.opacity=0),e.skin.css){var s=e.skin.css[a];s.callback=function(t){"/*Failed to load*/"==t?(this.textContent=t,e.showError("Failed to load CSS from "+this.getAttribute("data-source"))):this.textContent=MistUtil.css.prependClass(t,r,!0),n++,e.skin.css.length<=n&&(i.style.opacity="")},""!=s.textContent&&s.callback(s.textContent),i.appendChild(s)}MistUtil.class.add(i,r);var o=MistUtil.getBrowser();return o&&MistUtil.class.add(i,"browser-"+o),i}MistSkins.default={structure:{main:{if:function(){return!!this.info.hasVideo&&"audio"!=this.source.type.split("/")[1]},then:{type:"placeholder",classes:["mistvideo"],children:[{type:"hoverWindow",classes:["mistvideo-maincontainer"],mode:"pos",style:{position:"relative"},transition:{hide:"left: 0; right: 0; bottom: -43px;",show:"bottom: 0;",viewport:"left:0; right: 0; top: -1000px; bottom: 0;"},button:{type:"videocontainer"},children:[{type:"loading"},{type:"error"}],window:{type:"controls"}}]},else:{type:"container",classes:["mistvideo"],style:{overflow:"visible"},children:[{type:"controls",classes:["mistvideo-novideo"],style:{width:"480px"}},{type:"loading"},{type:"error"},{if:function(){return"stock"==this.options.controls},then:{type:"video",style:{position:"absolute"}},else:{type:"video",style:{position:"absolute",display:"none"}}}]}},videocontainer:{type:"container",children:[{type:"videobackground",alwaysDisplay:!1,delay:5},{type:"video"},{type:"subtitles"}]},controls:{if:function(){return!!(this.player&&this.player.api&&this.player.api.play)},then:{type:"container",classes:["mistvideo-column"],children:[{type:"progress",classes:["mistvideo-pointer"]},{type:"container",classes:["mistvideo-main","mistvideo-padding","mistvideo-row","mistvideo-background"],children:[{type:"play",classes:["mistvideo-pointer"]},{type:"currentTime"},{if:function(){return"size"in this&&this.size.width>300||!this.info.hasVideo||"audio"==this.source.type.split("/")[1]},then:{type:"totalTime"}},{type:"container",classes:["mistvideo-align-right"],children:[{type:"container",children:[{type:"container",classes:["mistvideo-volume_container"],children:[{type:"volume",mode:"horizontal",size:{height:22},classes:["mistvideo-pointer"]}]},{type:"speaker",classes:["mistvideo-pointer"],style:{"margin-left":"-2px"}}]},{if:function(){return"size"in this&&this.size.width>300||!this.info.hasVideo||"audio"==this.source.type.split("/")[1]},then:{type:"container",children:[{type:"chromecast",classes:["mistvideo-pointer"]},{type:"loop",classes:["mistvideo-pointer"]},{type:"fullscreen",classes:["mistvideo-pointer"]},{type:"picture-in-picture",classes:["mistvideo-pointer"]}]}},{type:"hoverWindow",mode:"pos",transition:{hide:"right: -1000px; bottom: 44px;",show:"right: 5px;",viewport:"right: 0; left: 0; bottom: 0; top: -1000px"},button:{type:"settings",classes:["mistvideo-pointer"]},window:{type:"submenu"}}]}]}]},else:{if:function(){return!(!this.player||!this.player.api)},then:{type:"hoverWindow",mode:"pos",transition:{hide:"right: -1000px; bottom: 44px;",show:"right: 2.5px;",viewport:"right: 0; left: -1000px; bottom: 0; top: -1000px"},style:{right:"5px",left:"auto"},button:{type:"settings",classes:["mistvideo-background","mistvideo-padding"]},window:{type:"submenu"}}}},submenu:{type:"container",style:{width:"80%",maxWidth:"25em",zIndex:2},classes:["mistvideo-padding","mistvideo-column","mistvideo-background"],children:[{type:"tracks"},{if:function(){return"size"in this&&this.size.width<=300},then:{type:"container",classes:["mistvideo-center"],children:[{type:"chromecast",classes:["mistvideo-pointer"]},{type:"loop",classes:["mistvideo-pointer"]},{type:"fullscreen",classes:["mistvideo-pointer"]},{type:"picture-in-picture",classes:["mistvideo-pointer"]}]}}]},placeholder:{type:"container",classes:["mistvideo","mistvideo-delay-display"],children:[{type:"placeholder"},{type:"loading"},{type:"error"}]},secondaryVideo:function(e){return{type:"hoverWindow",classes:["mistvideo"],mode:"pos",transition:{hide:"left: 10px; bottom: -40px;",show:"bottom: 10px;",viewport:"left: 0; right: 0; top: 0; bottom: 0"},button:{type:"container",children:[{type:"videocontainer"}]},window:{type:"switchVideo",classes:["mistvideo-controls","mistvideo-padding","mistvideo-background","mistvideo-pointer"],containers:e}}}},css:{skin:misthost+"/skins/default.css"},icons:{blueprints:{play:{size:45,svg:''},largeplay:{size:45,svg:''},pause:{size:45,svg:''},speaker:{size:45,svg:''},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return''}},muted:{size:45,svg:''},fullscreen:{size:45,svg:''},pip:{size:45,svg:''},loop:{size:45,svg:''},settings:{size:45,svg:''},loading:{size:100,svg:''},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return''}},popout:{size:45,svg:''},switchvideo:{size:45,svg:''}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;if(MistUtil.event.addListener(e.video,"contextmenu",(function(t){t.preventDefault(),e.container.setAttribute("data-show-submenu",""),e.container.removeAttribute("data-hide-submenu"),e.container.removeAttribute("data-hidecursor");var i=function(){e.container.removeAttribute("data-show-submenu"),e.container.removeEventListener("mouseout",i)};MistUtil.event.addListener(e.container,"mouseout",i)})),e.video.hideTimer=!1,e.video.hideCursor=function(){this.hideTimer&&clearTimeout(this.hideTimer),this.hideTimer=e.timers.start((function(){e.container.setAttribute("data-hidecursor","");var t=e.container.querySelector(".mistvideo-controls");t&&t.parentNode.setAttribute("data-hidecursor","")}),3e3)},MistUtil.event.addListener(e.video,"mousemove",(function(){e.container.removeAttribute("data-hidecursor");var t=e.container.querySelector(".mistvideo-controls");t&&t.parentNode.removeAttribute("data-hidecursor"),e.video.hideCursor()})),MistUtil.event.addListener(e.video,"mouseout",(function(){e.video.hideTimer&&e.timers.stop(e.video.hideTimer)})),e.options.autoplay)var t=MistUtil.event.addListener(e.video,"canplay",(function(){if(e.player.api&&e.player.api.paused){var i=e.player.api.play();i&&i.catch((function(t){if(!e.destroyed)if(e.log("Autoplay failed. Retrying with muted audio.."),e.info.hasVideo){e.player.api.muted=!0,MistUtil.event.send("volumechange",null,e.video);var i=e.player.api.play();i&&i.then((function(){e.reporting&&(e.reporting.stats.d.autoplay="success")})).then((function(){if(!e.destroyed){e.log("Autoplay worked! Video will be unmuted on mouseover if the page has been interacted with."),e.reporting&&(e.reporting.stats.d.autoplay="muted");var t=e.skin.icons.build("muted",100);MistUtil.class.add(t,"mistvideo-pointer"),e.container.appendChild(t),MistUtil.event.addListener(t,"click",(function(){e.player.api.muted=!1,e.container.removeChild(t)}));var i=!1,r=function(){i=!0,document.body.removeEventListener("click",r)};MistUtil.event.addListener(document.body,"click",r,e.video);var n=function(){i&&(e.player.api.muted=!1,e.video.removeEventListener("mouseenter",n),e.log("Re-enabled sound"))};MistUtil.event.addListener(e.video,"mouseenter",n);var a=function(){e.player.api.muted||(t.parentNode&&e.container.removeChild(t),e.video.removeEventListener("volumechange",a),document.body.removeEventListener("click",r),e.video.removeEventListener("mouseenter",n))};MistUtil.event.addListener(e.video,"volumechange",a)}})).catch((function(){if(!e.destroyed){e.log("Autoplay failed even with muted video. Unmuting and showing play button."),e.timers.start((function(){e.player.api.paused&&(e.player.api.pause(),e.monitor&&e.monitor.destroy())}),5e3),e.reporting&&(e.reporting.stats.d.autoplay="failed"),e.player.api.muted=!1;var t=e.skin.icons.build("largeplay",150);MistUtil.class.add(t,"mistvideo-pointer"),e.container.appendChild(t),MistUtil.event.addListener(t,"click",(function(){e.player.api.paused&&e.player.api.play()}));var i=function(){e.container.removeChild(t),e.video.removeEventListener("play",i)};MistUtil.event.addListener(e.video,"play",i)}}))}else e.reporting&&(e.reporting.stats.d.autoplay="failed")}))}else e.reporting&&(e.reporting.stats.d.autoplay="success");MistUtil.event.removeListener(t)}));return this.video},videocontainer:function(){return this.UI.buildStructure(this.skin.structure.videocontainer)},secondaryVideo:function(e){e||(e={}),e.options||(e.options={});var t=this;"secondary"in t||(t.secondary=[]);var i=MistUtil.object.extend({},t.options);i=MistUtil.object.extend(i,e.options),t.secondary.push(i);var r={primary:t,secondary:!1};i.target=document.createElement("div"),delete i.container;var n={};return i.MistVideoObject=n,MistUtil.event.addListener(i.target,"initialized",(function(){var e=n.reference;i.MistVideo=e,r.secondary=e,e.player.api.muted=!0,e.player.api.loop=!1;for(var a=i.target.querySelectorAll(".mistvideo-controls"),s=0;s30)e.player.api.pausedesync=!0,e.player.api.currentTime=this.currentTime,e.log("Re-syncing with main video by seeking (desync: "+t+"s)");else if(i>.01){var r=.1;i<1&&(r=.05),(r=1+r*Math.sign(t))!=e.player.api.playbackRate&&e.log("Re-syncing by changing the playback rate (desync: "+Math.round(1e3*t)+"ms, rate: "+r+")"),e.player.api.playbackRate=r}else 1!=e.player.api.playbackRate&&(e.player.api.playbackRate=1,e.log("Sync with main video achieved (desync: "+Math.round(1e3*t)+"ms)"))}}),i.target),MistUtil.event.addListener(e.video,"seeked",(function(){e.player.api.pausedesync=!1}))})),i.skin=MistUtil.object.extend({},t.skin,!0),i.skin.structure.main=MistUtil.object.extend({},t.skin.structure.secondaryVideo(r)),mistPlay(t.stream,i),i.target},switchVideo:function(e){var t=document.createElement("div");return t.appendChild(this.skin.icons.build("switchvideo")),MistUtil.event.addListener(t,"click",(function(){var t=e.containers.primary,i=e.containers.secondary;function r(e,t){if(e.video.currentTarget==t)return e.video;if(e.secondary)for(var i=0;i300&&(e.style.zoom=1.5),e}},submenu:function(){return this.UI.buildStructure(this.skin.structure.submenu)},hoverWindow:function(e){var t={type:"container",classes:"classes"in e?e.classes:[],children:"children"in e?e.children:[]};switch(t.classes.push("hover_window_container"),"classes"in e.window||(e.window.classes=[]),e.window.classes.push("inner_window"),e.window.classes.push("mistvideo-container"),e.window={type:"container",classes:["outer_window"],children:[e.window]},"classes"in e.button||(e.button.classes=[]),e.button.classes.push("pointer"),e.mode){case"left":t.classes.push("horizontal"),t.children=[e.window,e.button];break;case"right":t.classes.push("horizontal"),t.children=[e.button,e.window];break;case"top":t.classes.push("vertical"),t.children=[e.button,e.window];break;case"bottom":t.classes.push("vertical"),t.children=[e.window,e.button];break;case"pos":t.children=[e.button,e.window],"classes"in e.window||(e.window.classes=[]);break;default:throw"Unsupported mode for structure type hoverWindow"}return"transition"in e&&("css"in t||(t.css=[]),t.css.push(".hover_window_container:hover > .outer_window:not([data-hidecursor]) > .inner_window { "+e.transition.show+" }\n.hover_window_container > .outer_window { "+e.transition.viewport+" }\n.hover_window_container > .outer_window > .inner_window { "+e.transition.hide+" }")),t.classes.push(e.mode),this.UI.buildStructure(t)},draggable:function(e){var t=this.skin.blueprints.container(e),i=this,r=this.skin.icons.build("fullscreen",16);MistUtil.class.remove(r,"fullscreen"),MistUtil.class.add(r,"draggable-icon"),t.appendChild(r),r.style.alignSelf="flex-end",r.style.position="absolute",r.style.cursor="move";var n={},a=function(e){t.style.left=e.clientX-n.x+"px",t.style.top=e.clientY-n.y+"px"},s=function(e){window.removeEventListener("mousemove",a),window.removeEventListener("click",s),MistUtil.event.addListener(r,"click",o)},o=function(e){e.stopPropagation(),r.removeEventListener("click",o),n.x=i.container.getBoundingClientRect().left-(t.getBoundingClientRect().left-e.clientX),n.y=i.container.getBoundingClientRect().top-(t.getBoundingClientRect().top-e.clientY),t.style.position="absolute",t.style.right="auto",t.style.bottom="auto",i.container.appendChild(t),a(e),MistUtil.event.addListener(window,"mousemove",a,t),MistUtil.event.addListener(window,"click",s,t)};return MistUtil.event.addListener(r,"click",o),t},progress:function(){var e=document.createElement("div"),t=document.createElement("div");e.appendChild(t),t.kids={},t.kids.bar=document.createElement("div"),t.kids.bar.className="bar",t.appendChild(t.kids.bar);var i=this.video,r=this,n=1/0;if(r.info&&r.info.meta&&r.info.meta.tracks)for(var a in r.info.meta.tracks).001*r.info.meta.tracks[a].firstms1e3?(t.updateBuffers(r.player.api.buffered),l=(new Date).getTime()):c||(c=r.timers.start((function(){e(),c=!1}),1e3))}()}),t);var d=0,u=!1;MistUtil.event.addListener(i,"timeupdate",(function(){!function e(){(new Date).getTime()-d>200&&!f?(t.updateBar(r.player.api.currentTime),d=(new Date).getTime()):u||(u=r.timers.start((function(){e(),u=!1}),1e3))}()}),t),MistUtil.event.addListener(i,"seeking",(function(){t.updateBar(r.player.api.currentTime)}),t),t.getPos=function(e){var t=isNaN(e)?MistUtil.getPos(this,e):e;return"live"==r.info.type?(t-1)*o()+r.player.api.duration:!!isFinite(r.player.api.duration)&&t*(r.player.api.duration-s())+s()},t.seek=function(e){var t=this.getPos(e);r.player.api.currentTime=t},MistUtil.event.addListener(e,"mouseup",(function(e){1==e.which&&t.seek(e)}));var p=r.UI.buildStructure({type:"tooltip"});p.style.opacity=0,t.appendChild(p),MistUtil.event.addListener(e,"mouseout",(function(){f||(p.style.opacity=0)})),t.moveTooltip=function(e){var t=this.getPos(e);if(!1!==t){p.setDisplay(t),p.style.opacity=1;var i=MistUtil.getPos(this,e),r={bottom:20};i>.5?(r.right=100*(1-i)+"%",p.triangle.setMode("bottom","right")):(r.left=100*i+"%",p.triangle.setMode("bottom","left")),p.setPos(r)}else p.style.opacity=0};var h=document.createElement("span");h.setAttribute("class","mistvideo-realtime");var m=document.createTextNode("");h.appendChild(m),p.setDisplay=function(e){if(r.options.useDateTime&&r.info&&r.info.unixoffset){var i=t.getPos(1)-t.getPos(0),n=.001*(new Date).getTime()-(.001*r.info.unixoffset+t.getPos(1)),a=Math.max(i,n),s="";if("live"==r.info.type)if(a<60)s=MistUtil.format.ago(new Date(r.info.unixoffset+1e3*e));else{var o=.001*(new Date).getTime()-(.001*r.info.unixoffset+e);o<172800&&(s+=" - "+MistUtil.format.time(o))}else s+=MistUtil.format.time(e);if(a>=60){m.nodeValue=" at "+MistUtil.format.ago(new Date(r.info.unixoffset+1e3*e),1e3*a);var l=document.createDocumentFragment();l.appendChild(document.createTextNode(s)),l.appendChild(h),p.setHtml(l)}else m.nodeValue="",p.setText(s)}else p.setText(MistUtil.format.time(e))},MistUtil.event.addListener(e,"mousemove",(function(e){t.moveTooltip(e)}));var f=!1;return MistUtil.event.addListener(e,"mousedown",(function(i){if(1==i.which){f=!0,t.updateBar(t.getPos(i));var r=MistUtil.event.addListener(document,"mousemove",(function(e){t.updateBar(t.getPos(e)),t.moveTooltip(e)}),t),n=MistUtil.event.addListener(document,"mouseup",(function(i){1==i.which&&(f=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),p.style.opacity=0,(!i.path||MistUtil.array.indexOf(i.path,e)<0)&&t.seek(i))}),t)}})),e},play:function(){var e=this,t=document.createElement("div");t.appendChild(this.skin.icons.build("play")),t.appendChild(this.skin.icons.build("pause")),t.setState=function(e){this.setAttribute("data-state",e)},t.setState("paused");var i=this.video;return MistUtil.event.addListener(i,"playing",(function(){t.setState("playing"),e.options.autoplay=!0}),t),MistUtil.event.addListener(i,"pause",(function(){t.setState("paused")}),t),MistUtil.event.addListener(i,"paused",(function(){t.setState("paused")}),t),MistUtil.event.addListener(i,"ended",(function(){t.setState("paused")}),t),MistUtil.event.addListener(t,"click",(function(){e.player.api.error&&e.player.api.load(),e.player.api.paused?e.player.api.play():(e.player.api.pause(),e.options.autoplay=!1)})),e.player.api&&MistUtil.event.addListener(e.video,"click",(function(){e.player.api.paused?e.player.api.play():MistUtil.isTouchDevice()||(e.player.api.pause(),e.options.autoplay=!1)}),t),t},speaker:function(){if(!this.player.api||!("muted"in this.player.api))return!1;var e=!1,t=this.info.meta.tracks;for(var i in t)if("audio"==t[i].type){e=!0;break}if(!e)return!1;var r=this.skin.icons.build("speaker"),n=this,a=this.video;return n.player.api.volume&&!n.player.api.muted||MistUtil.class.add(r,"off"),MistUtil.event.addListener(a,"volumechange",(function(){n.player.api.volume&&!n.player.api.muted?MistUtil.class.remove(r,"off"):MistUtil.class.add(r,"off")}),r),MistUtil.event.addListener(r,"click",(function(e){n.player.api.muted=!n.player.api.muted})),r},volume:function(e){if(!this.player.api||!("volume"in this.player.api))return!1;var t=!1,i=this.info.meta.tracks;for(var r in i)if("audio"==i[r].type){t=!0;break}if(!t)return!1;var n=document.createElement("div"),a=this.skin.icons.build("volume","size"in e&&e.size);n.appendChild(a);var s=this;a.mode="mode"in e?e.mode:"vertical","vertical"==a.mode&&(a.style.transform="rotate(90deg)"),a.margin={start:.15,end:.1};var o=this.video;a.set=function(e){100!=(e=100-100*Math.pow(1-e/100,2))&&0!=e&&(e=100*this.addPadding(e/100));for(var t=a.querySelectorAll(".slider"),i=0;i6e4&&e.size.width>=600&&(n.nodeValue=" (at "+MistUtil.format.ago(o)+")")),t.setAttribute("title",MistUtil.format.ago(o,3456e7))}else r=a(s),t.setAttribute("title",r);i.nodeValue=r},t.set(),MistUtil.event.addListener(e.video,"timeupdate",(function(){t.set()}),t),MistUtil.event.addListener(e.video,"seeking",(function(){t.set()}),t),t},totalTime:function(){var e=this,t=document.createElement("div"),i=document.createTextNode("");t.appendChild(i);this.player.api;return"live"==e.info.type?(i.nodeValue="live",t.className="live"):(t.set=function(r){if(!isNaN(r)&&isFinite(r))if(this.style.display="",e.options.useDateTime&&e.info&&"live"==e.info.type&&e.info.unixoffset){var n=new Date(1e3*r+e.info.unixoffset);i.nodeValue=MistUtil.format.ago(n),t.setAttribute("title",MistUtil.format.ago(n,3456e7))}else i.nodeValue=MistUtil.format.time(r),t.setAttribute("title",i.nodeValue);else this.style.display="none"},MistUtil.event.addListener(e.video,"durationchange",(function(){var i=e.player.api.duration;t.set(i)}),t)),t},playername:function(){if(this.playerName&&this.playerName in mistplayers){var e=document.createElement("span");return e.appendChild(document.createTextNode(mistplayers[this.playerName].name)),e}},mimetype:function(){if(this.source){var e=document.createElement("a");return e.href=this.source.url,e.target="_blank",e.title=e.href+" ("+this.source.type+")",e.appendChild(document.createTextNode(MistUtil.format.mime2human(this.source.type))),e}},logo:function(e){if("element"in e)return e.element;if("src"in e){var t=document.createElement("img");return t.src=e.src,t}},settings:function(){var e=this,t=this.skin.icons.build("settings"),i=void 0!==document.ontouchstart;return MistUtil.event.addListener(t,"click",(function(){e.container.hasAttribute("data-show-submenu")?(i&&e.container.setAttribute("data-hide-submenu",""),e.container.removeAttribute("data-show-submenu")):(e.container.setAttribute("data-show-submenu",""),e.container.removeAttribute("data-hide-submenu"))})),t},loop:function(){if("loop"in this.player.api&&"live"!=this.info.type){var e=this,t=this.skin.icons.build("loop");this.video;return t.set=function(){e.player.api.loop?MistUtil.class.remove(this,"off"):MistUtil.class.add(this,"off")},MistUtil.event.addListener(t,"click",(function(t){e.player.api.loop=!e.player.api.loop,this.set()})),t.set(),t}},fullscreen:function(){if("setSize"in this.player&&this.info.hasVideo&&"audio"!=this.source.type.split("/")[1]){var e=this,t=["requestFullscreen","webkitRequestFullscreen","mozRequestFullScreen","msRequestFullscreen","webkitEnterFullscreen"],i=[function(){return e.container},function(){return e.video}],r=!1;e:for(var n in i)for(var a in t)if(t[a]in i[n]()){(r={}).request=function(){return r.fullscreenableElement()[t[a]]()};var s=["exitFullscreen","webkitCancelFullScreen","mozCancelFullScreen","msExitFullscreen","webkitExitFullscreen"],o=["fullscreenElement","webkitFullscreenElement","mozFullScreenElement","msFullscreenElement","webkitFullscreenElement"];r.cancel=function(){return document[s[a]]()},r.element=function(){return document[o[a]]},r.event=["fullscreenchange","webkitfullscreenchange","mozfullscreenchange","MSFullscreenChange","webkitfullscreenchange"][a],r.fullscreenableElement=i[n];break e}if(!r){var l=function(e){if("Escape"===e.key)r.cancel()};(r={event:"fakefullscreenchange",fullscreenableElement:function(){return e.container}}).request=function(){return r.element=function(){return e.container},MistUtil.event.send(r.event,null,document),document.addEventListener("keydown",l),!0},r.cancel=function(){return r.element=function(){return null},document.removeEventListener("keydown",l),MistUtil.event.send(r.event,null,document),!0},r.element=function(){return null}}var c=this.skin.icons.build("fullscreen");return MistUtil.event.addListener(c,"click",d),MistUtil.event.addListener(e.video,"dblclick",d),MistUtil.event.addListener(document,r.event,(function(){r.element()==r.fullscreenableElement()?e.container.setAttribute("data-fullscreen",""):e.container.hasAttribute("data-fullscreen")&&e.container.removeAttribute("data-fullscreen"),e.player.resizeAll()}),c),c}function d(){r.element()?r.cancel():r.request()}},"picture-in-picture":function(){if("setSize"in this.player&&this.info.hasVideo&&"audio"!=this.source.type.split("/")[1]&&document.pictureInPictureEnabled){var e=this;if("requestPictureInPicture"in e.video){var t=this.skin.icons.build("pip");return t.set=function(){document.pictureInPictureElement?MistUtil.class.remove(this,"off"):MistUtil.class.add(this,"off")},MistUtil.event.addListener(t,"click",(function(){var i;(i=document.pictureInPictureElement?document.exitPictureInPicture():e.video.requestPictureInPicture())?i.then((function(){t.set()})):t.set()})),t.set(),t}}},tracks:function(){if(this.info&&this.video){var e=this,t=document.createElement("table");return i(this.info.meta.tracks),MistUtil.event.addListener(e.video,"metaUpdate_tracks",(function(e){i(e.message.meta.tracks)}),t),t}function i(i){MistUtil.empty(t),i=MistUtil.tracks.parse(i);var r={},n={};function a(t,i){if(i?e.log("User selected "+t+" track with id "+i):(e.log("User selected automatic track selection for "+t),MistUtil.event.send("trackSetToAuto",t,e.video)),e.options.setTracks||(e.options.setTracks={}),e.options.setTracks[t]=i,!0===i&&r[t]&&MistUtil.event.send("change",null,r[t]),"setTrack"in e.player.api)return e.player.api.setTrack(t,i);var n={};for(var a in r)"subtitle"!=a&&""!=r[a].value&&(n[a]=r[a].value);return""!=i&&(n[t]=i),"setTracks"in e.player.api?e.player.api.setTracks(n):"setSource"in e.player.api?e.player.api.setSource(MistUtil.http.url.addParam(e.source.url,n)):void 0}var s=MistUtil.object.keys(i,(function(e,t){function i(e){switch(e){case"audio":return"aaaaaaa";case"video":return"aaaaaab";default:return e}}return i(e)>i(t)?1:i(e)1&&"player"in e&&"api"in e.player&&("setTrack"in e.player.api||"setTracks"in e.player.api||"setSource"in e.player.api)){var b=document.createElement("select");if(b.title="Select another "+l+" track",r[l]=b,b.trackType=l,f.appendChild(b),"subtitle"!=l){var k=document.createElement("option");b.appendChild(k),k.value="",k.appendChild(document.createTextNode("Automatic"))}var M=S(c[MistUtil.object.keys(c)[0]].same);if(M.length)(x=document.createElement("span")).className="mistvideo-description",f.appendChild(x),f.appendChild(document.createTextNode(M.join(" ")));function w(e){return""==e?-1:Number(e)}var U=MistUtil.object.keys(c,(function(e,t){return w(e)-w(t)}));for(var p in U){var C=c[U[p]];k=document.createElement("option");b.appendChild(k),k.value="idx"in C?C.idx:C.trackid,MistUtil.object.keys(C.different).length?k.appendChild(document.createTextNode(S(C.different).join(" "))):k.appendChild(document.createTextNode("Track "+(Number(p)+1)))}if(MistUtil.event.addListener(e.video,"playerUpdate_trackChanged",(function(t){t.message.type==l&&"none"!=t.message.trackid&&(b.value=t.message.trackid,e.log("Player selected "+l+" track with id "+t.message.trackid))}),b),"subtitle"==l){if(MistUtil.event.addListener(b,"change",(function(){try{localStorage.mistSubtitleLanguage=c[this.value].lang}catch(e){}if("setWSSubtitle"in e.player.api)e.player.api.setWSSubtitle(""==this.value?void 0:this.value);else if(""!=this.value){var t=MistUtil.object.extend({},c[this.value]);t.label=S(t.describe).join(" "),t.src=MistUtil.http.url.addParam(u,{track:this.value}),e.player.api.setSubtitle(t)}else e.player.api.setSubtitle()})),"localStorage"in window&&null!=localStorage&&"mistSubtitleLanguage"in localStorage)for(var p in c)if(c[p].lang==localStorage.mistSubtitleLanguage){b.value=p;var T=document.createEvent("Event");T.initEvent("change"),b.dispatchEvent(T);break}}else MistUtil.event.addListener(b,"change",(function(){this.trackType in n&&(n[this.trackType].checked=!0),a(this.trackType,this.value)}))}else{var x;(x=document.createElement("span")).className="mistvideo-description",f.appendChild(x),x.appendChild(document.createTextNode(S(c[g[0]].same).join(" ")))}}function S(e){var t={trackid:0,language:1,width:2,bps:3,fpks:4,channels:5,codec:6,rate:7};return MistUtil.object.values(e,(function(e,i,r,n){return t[e]>t[i]?1:t[e]=.999?n():a()}),1e3))}var s=["waiting","seeking","stalled"];for(var o in s)MistUtil.event.addListener(e.video,s[o],(function(t){e.player.api&&!e.player.api.paused&&"container"in e&&r(t)}),t);s=["seeked","playing","canplay","paused","ended"];for(var o in s)MistUtil.event.addListener(e.video,s[o],(function(t){"container"in e&&n()}),t);MistUtil.event.addListener(e.video,"progress",(function(t){"container"in e&&"monitor"in e&&"vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.score>.99&&n()}),t)}return t},error:function(){var e=this,t=document.createElement("div");t.message=function(t,i,r){MistUtil.empty(this);var n=document.createElement("div");if(n.className="message",this.appendChild(n),!r.polling&&!r.passive&&!r.hideTitle){var a=document.createElement("h3");n.appendChild(a),a.appendChild(document.createTextNode("The "+(e.casting?"chromecast":"player")+" has encountered a problem"))}var s=document.createElement("p");if(n.appendChild(s),n.update=function(e){MistUtil.empty(s),s.innerHTML=e},t){e.info.on_error&&(t=e.info.on_error.replace(/\/,t)),n.update(t);var o=document.createElement("p");if(o.className="details mistvideo-description",n.appendChild(o),i)o.appendChild(document.createTextNode(i));else if("decodingIssues"in e.skin.blueprints){if("player"in e&&"api"in e.player&&e.video){if(i=[],void 0!==e.state&&i.push(["Stream state:",e.state]),void 0!==e.player.api.currentTime&&i.push(["Current video time:",MistUtil.format.time(e.player.api.currentTime)]),"video"in e&&"getVideoPlaybackQuality"in e.video){var l=e.video.getVideoPlaybackQuality();"droppedVideoFrames"in l&&"totalVideoFrames"in l&&l.totalVideoFrames&&i.push(["Frames dropped/total:",MistUtil.format.number(l.droppedVideoFrames)+"/"+MistUtil.format.number(l.totalVideoFrames)]),"corruptedVideoFrames"in l&&l.corruptedVideoFrames&&i.push(["Corrupted frames:",MistUtil.format.number(l.corruptedVideoFrames)])}i.push({0:["NETWORK EMPTY:","not yet initialized"],1:["NETWORK IDLE:","resource selected, but not in use"],2:["NETWORK LOADING:","data is being downloaded"],3:["NETWORK NO SOURCE:","could not locate source"]}[e.video.networkState]);if(i.push({0:["HAVE NOTHING:","no information about ready state"],1:["HAVE METADATA:","metadata has been loaded"],2:["HAVE CURRENT DATA:","data for the current playback position is available, but not for the next frame"],3:["HAVE FUTURE DATA:","data for current and next frame is available"],4:["HAVE ENOUGH DATA:","can start playing"]}[e.video.readyState]),!r.passive){var c=document.createElement("table");for(var d in i){var u=document.createElement("tr");for(var p in c.appendChild(u),i[d]){var h=document.createElement("td");u.appendChild(h),h.appendChild(document.createTextNode(i[d][p]))}}o.appendChild(c)}}var m,f=document.createElement("div");f.className="mistvideo-container mistvideo-column",f.style.textAlign="left",f.style.marginBottom="1em",n.appendChild(f),(m=e.UI.buildStructure({type:"forcePlayer"}))&&f.appendChild(m),(m=e.UI.buildStructure({type:"forceType"}))&&f.appendChild(m)}}return n};var i,r=!1,n=!1,a={};if(this.showError=function(s,o){o||(o={softReload:!!(e.player&&e.player.api&&e.player.api.load),reload:!0,nextCombo:!!e.info,polling:!1,passive:!1});var l=o.type?o.type:s;if(!(l in a)){if(!0===o.reload&&(e.options.reloadDelay&&!isNaN(Number(e.options.reloadDelay))?o.reload=Number(e.options.reloadDelay):o.reload=10),o.passive){if(!0===r)return;if(r)return i.update(s),void(n=(new Date).getTime());t.setAttribute("data-passive","")}else t.removeAttribute("data-passive");var c;r&&t.clear(),r=!o.passive||"passive",n=(new Date).getTime(),e.casting||(c=this.log(s,"error"));var d=t.message(s,!1,o);i=d;var u=document.createElement("div");if(u.className="mistvideo-buttoncontainer",d.appendChild(u),MistUtil.empty(u),e.casting&&!o.passive){var p={type:"button",label:"Stop casting",onclick:function(){e.detachFromCast()}};isNaN(o.softReload+"")||(p.delay=o.softReload),u.appendChild(e.UI.buildStructure(p))}if(o.softReload&&!e.casting){p={type:"button",label:"Reload video",onclick:function(){e.player.api.load()}};isNaN(o.softReload+"")||(p.delay=o.softReload),u.appendChild(e.UI.buildStructure(p))}if(o.reload){p={type:"button",label:"Reload player",onclick:function(){e.reload("Reloading because reload button was clicked.")}};isNaN(o.reload+"")||(p.delay=o.reload),u.appendChild(e.UI.buildStructure(p))}if(o.nextCombo){p={type:"button",label:"Next source",onclick:function(){e.nextCombo()}};isNaN(o.nextCombo+"")||(p.delay=o.nextCombo),u.appendChild(e.UI.buildStructure(p))}if(o.ignore){p={type:"button",label:"Ignore",onclick:function(){this.clearError(),a[l]=!0}};isNaN(o.ignore+"")||(p.delay=o.ignore),u.appendChild(e.UI.buildStructure(p))}o.polling&&u.appendChild(e.UI.buildStructure({type:"polling"})),MistUtil.class.add(t,"show"),"container"in e&&e.container.removeAttribute("data-loading"),c&&c.defaultPrevented&&(e.log("Error event was defaultPrevented, not showing."),t.clear())}},t.clear=function(){for(var i=t.querySelectorAll("svg.icon.timeout"),n=0;n=0;e--)r.removeChild(r.children[e])},e.setHtml=function(n){r.empty(),r.appendChild(n),"html"!=t&&(e.removeChild(i),e.appendChild(r),t="html")};var n=document.createElement("div");return e.triangle=n,n.className="triangle",e.appendChild(n),n.setMode=function(e,t){e||(e="bottom"),t||(t="left");var i=["bottom","top","right","left"];for(var r in i){this.style[i[r]]="";var n=MistUtil.format.ucFirst(i[r]);this.style["border"+n]="",this.style["border"+n+"Color"]=""}var a={top:"bottom",bottom:"top",left:"right",right:"left"};this.style[e]="-10px",this.style["border"+MistUtil.format.ucFirst(a[e])]="none",this.style["border"+MistUtil.format.ucFirst(e)+"Color"]="transparent",this.style[t]=0,this.style["border"+MistUtil.format.ucFirst(a[t])]="none"},e.setPos=function(e){var t={left:"auto",right:"auto",top:"auto",bottom:"auto"};for(var i in MistUtil.object.extend(t,e),t)isNaN(t[i])||(t[i]+="px"),this.style[i]=t[i]},e},button:function(e){var t=document.createElement("button"),i=this;if(e.onclick&&(MistUtil.event.addListener(t,"click",(function(){e.onclick.call(i,arguments)})),e.delay)){var r=this.UI.buildStructure({type:"timeout",delay:e.delay,function:e.onclick});r&&t.appendChild(r)}return t.appendChild(document.createTextNode(e.label)),t},videobackground:function(e){e||(e={}),e.delay||(e.delay=5);for(var t=document.createElement("div"),i=this,r=[],n=0;n<2;n++){var a=document.createElement("canvas");a._context=a.getContext("2d"),t.appendChild(a),r.push(a)}var s=0,o=!1;function l(){if(e.alwaysDisplay||i.video.videoWidth/i.video.videoHeight!=t.clientWidth/t.clientHeight){r[s].removeAttribute("data-front"),++s>=r.length&&(s=0);var n=r[s],a=n._context;n.width=i.video.videoWidth,n.height=i.video.videoHeight,a.drawImage(i.video,0,0),n.setAttribute("data-front","")}i.player.api.paused?o=!1:i.timers.start((function(){l()}),1e3*e.delay)}return MistUtil.event.addListener(i.video,"playing",(function(){o||(l(),o=!0)})),t},subtitles:function(e){if(!("WebSocket"in window))return!1;var t=this;if(!("player"in t)||!("api"in t.player)||!("currentTime"in t.player.api))return!1;if(!("metaTrackSubscriptions"in t))return!1;var i=document.createElement("div"),r=document.createElement("span");i.appendChild(r);var n=document.createTextNode("");r.appendChild(n);var a=!1;function s(e){n.nodeValue=e.data.replace(/\<\/?[bui]\>/gi,"").replace(/{\/?[bui]}/gi,"").replace(/{\\a\d+}/gi,"").replace(/\<\/?font[^>]*?\>/gi,""),a&&(t.timers.stop(a),a=null),function i(r){a=t.timers.start((function(){if(t.player.api.paused)var r=MistUtil.event.addListener(t.video,"playing",(function(){i(e.time+("duration"in e?e.duration:5e3)-1e3*t.player.api.currentTime),MistUtil.event.removeListener(r)}));else n.nodeValue=""}),r)}("duration"in e?e.duration:5e3)}if(MistUtil.event.addListener(t.video,"seeked",(function(){n.nodeValue="",a&&t.timers.stop(a),a=null})),!("setWSSubtitle"in t.player.api)){var o=!1;t.player.api.setWSSubtitle=function(e){e!=o&&(void 0!==e&&t.metaTrackSubscriptions.add(e,s),e!=o&&t.metaTrackSubscriptions.remove(o,s),o="undefined"!=e&&e)}}return i},chromecast:function(){var e=this;if(!(!"".indexOf||e.options.host.indexOf("localhost")>-1||e.options.host.indexOf("::1")>-1)){var t,i,r,n,a=document.createElement("div"),s=document.createElement("div");s.className="mistvideo-casting";var o={},l={currentTime:!1,paused:!0,volume:1,muted:!1,buffer:[],loop:e.player.api?e.player.api.loop:e.options.loop};if(e.casting=!1,window.chrome&&window.chrome.cast||window.loadedCastApi)"loading"==window.loadedCastApi?(e.log("Not appending chromecast script - still loading"),e.timers.start((function(){d()}),200)):(e.log("Not appending chromecast script - already loaded"),d());else{window.__onGCastApiAvailable=function(t,i){t||e.log("Error while loading chromecast API: "+i),d()},window.loadedCastApi="loading";var c=document.createElement("script");c.setAttribute("src","//www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"),document.head.appendChild(c),e.log("Appending chromecast script")}return a}function d(c){if(!window.chrome||!window.chrome.cast||!window.chrome.cast.isAvailable||c>5)return a.parentNode&&a.parentNode.removeChild(a),e.log("Chromecast is not supported"),void console.warn(chrome,chrome.cast,chrome.cast?chrome.cast.isAvailable:void 0,cast);if(!window.cast)return c||(c=0),e.log("Casting api loaded but cast function not yet available, retrying.."),void e.timers.start((function(){d(c++)}),200);e.log("Chromecast API loaded"),window.loadedCastApi&&"loading"!=window.loadedCastApi||(window.loadedCastApi=!0);var u=document.createElement("google-cast-launcher");function p(a){MistUtil.class.remove(u,"active"),MistUtil.class.remove(e.container,"casting"),s.parentNode&&s.parentNode.removeChild(s),!a&&cast.framework.CastContext.getInstance().getCurrentSession()&&cast.framework.CastContext.getInstance().getCurrentSession().endSession(!0),t?(e.player.api=t,t.currentTime=l.currentTime,t.play(),e.reload=i,e.nextCombo=r,e.unload=n):e.player.api.play(),e.player.api&&e.player.api.setTracks&&MistUtil.object.keys(o).length&&e.player.api.setTracks(o),e.casting=!1,e.log("Detached chromecast session")}a.appendChild(u),cast.framework.CastContext.getInstance().setOptions({receiverApplicationId:"E5F1558C",autoJoinPolicy:chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),e.detachFromCast=p,u.addEventListener("click",(function(a){if(a.stopPropagation(),MistUtil.class.has(u,"active"))p();else{function c(){cast.framework.CastContext.getInstance().getCurrentSession().addMessageListener("urn:x-cast:mistcaster",(function(t,i){if(e.destroyed&&p(),(i=JSON.parse(i)).type)switch(i.type){case"log":case"error":e.log("[Chromecast] "+i.message,i.type);break;case"showError":e.showError.apply(e,i.args);break;case"event":switch(i.event){case"timeupdate":l.currentTime=i.currentTime,MistUtil.event.send(i.event,"chromecast",e.video);break;case"progress":l.buffer=i.buffer,MistUtil.event.send(i.event,"chromecast",e.video);break;case"pause":case"paused":case"ended":case"play":case"playing":l.paused=i.paused,MistUtil.event.send(i.event,"chromecast",e.video);break;case"volumechange":l.volume=i.volume,l.muted=i.muted,MistUtil.event.send(i.event,"chromecast",e.video);break;default:MistUtil.event.send(i.event,"chromecast",e.video)}break;case"detach":i.n==e.n&&p(!0);break;default:console.log("Unknown chromecast message type",i)}}));var a={type:"load",n:e.n,options:{host:e.options.host,loop:e.options.loop,poster:e.options.poster,streaminfo:e.options.streaminfo,urlappend:e.options.urlappend,forcePriority:e.options.forcePriority,setTracks:e.options.setTracks,controls:!1,skin:"default"},stream:e.stream};e.info&&"live"!=e.info.type&&(a.time=e.player.api.currentTime),"dev"==e.options.skin&&(a.options.skin=e.options.skin),e.player&&e.player.api&&(a.volume=e.player.api.volume,a.muted=e.player.api.muted,a.options.loop=e.player.api.loop),MistCast.send(a),t=e.player.api,i=e.reload,r=e.nextCombo,n=e.unload,o=e.options.setTracks?e.options.setTracks:{},e.player.api=new Proxy(t,{get:function(e,t,i){var r=e[t];switch(t){case"muted":case"volume":case"currentTime":case"paused":case"loop":return l[t];case"buffered":return new function(){this.length=l.buffer.length,this.start=function(e){return l.buffer[e][0]},this.end=function(e){return l.buffer[e][1]}};case"setTracks":case"play":case"pause":return function(){for(var e=[],i=0;i=t.scrollHeight-5})),r.logs)o(r.logs[l].time,r.logs[l].message,r.logs[l].data);return MistUtil.event.addListener(r.options.target,"log",(function(e){if(e.message){var t={};r.player&&r.player.api&&"currentTime"in r.player.api&&(t.currentTime=r.player.api.currentTime),o(new Date,e.message,t)}}),e),MistUtil.event.addListener(r.options.target,"error",(function(e){if(e.message){var t={type:"error"};r.player&&r.player.api&&"currentTime"in r.player.api&&(t.currentTime=r.player.api.currentTime),o(new Date,e.message,t)}}),e),e},decodingIssues:function(){if(this.player){var e=this,t=document.createElement("div");if(e.player.api){var i={"Playback score":function(){if("monitor"in e){if("vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.values.length){var t=e.monitor.vars.values[e.monitor.vars.values.length-1];if("score"in t){Math.min(1,Math.max(0,t.score));return{x:t.clock,y:Math.min(1,Math.max(0,t.score)),options:{y:{min:0,max:1},x:{count:10}},val:Math.round(100*Math.min(1,Math.max(0,e.monitor.vars.score)))+"%"}}}return 0}},"Corrupted frames":function(){if(e.player.api&&"getVideoPlaybackQuality"in e.player.api){var t=e.player.api.getVideoPlaybackQuality();if(t)return t.corruptedVideoFrames?{val:MistUtil.format.number(t.corruptedVideoFrames),x:.001*(new Date).getTime(),y:t.corruptedVideoFrames,options:{x:{count:10}}}:0}},"Dropped frames":function(){if(e.player.api){if("getVideoPlaybackQuality"in e.player.api){var t=e.player.api.getVideoPlaybackQuality();if(t)return t.droppedVideoFrames?MistUtil.format.number(t.droppedVideoFrames):0}if("webkitDroppedFrameCount"in e.player.api)return e.player.api.webkitDroppedFrameCount}},"Total frames":function(){if(e.player.api&&"getVideoPlaybackQuality"in e.player.api){var t=e.player.api.getVideoPlaybackQuality();if(t)return MistUtil.format.number(t.totalVideoFrames)}},"Decoded audio":function(){if(e.player.api)return MistUtil.format.bytes(e.player.api.webkitAudioDecodedByteCount)},"Decoded video":function(){if(e.player.api)return MistUtil.format.bytes(e.player.api.webkitVideoDecodedByteCount)},"Negative acknowledgements":function(){if(e.player.api)return MistUtil.format.number(e.player.api.nackCount)},"Picture losses":function(){return MistUtil.format.number(e.player.api.pliCount)},"Packets lost":function(){return MistUtil.format.number(e.player.api.packetsLost)},"Packets received":function(){return MistUtil.format.number(e.player.api.packetsReceived)},"Bytes received":function(){if(e.player.api)return MistUtil.format.bytes(e.player.api.bytesReceived)},"Local latency [ms]":function(){if(e.player.api&&"getLatency"in e.player.api){var t=e.player.api.getLatency();return t?new Promise((function(e,i){t.then((function(t){var i=[];for(var r in t)t[r]&&i.push(r[0]+":"+Math.round(1e3*t[r]));i.length?e(i.join(" ")):e()}),i)})):new Promise((function(e,t){e()}),(function(){}))}},"Current bitrate":function(){var t;return e.player.monitor&&"currentBps"in e.player.monitor?(t=MistUtil.format.bits(e.player.monitor.currentBps))?t+"ps":t:e.player.api&&"currentBps"in e.player.api?(t=MistUtil.format.bits(e.player.api.currentBps()))?t+"ps":t:void 0},"Framerate in":function(){if(e.player.api&&"framerate_in"in e.player.api)return MistUtil.format.number(e.player.api.framerate_in())},"Framerate out":function(){if(e.player.api&&"framerate_out"in e.player.api)return MistUtil.format.number(e.player.api.framerate_out())}},r=[];for(var n in i)void 0!==i[n]()&&a({name:n,function:i[n]});t.update=function(){for(var i in r)r[i]();e.timers.start((function(){t.update()}),1e3)},t.update()}return t}function a(e){var i=document.createElement("label");t.appendChild(i),i.style.display="none";var n=document.createElement("span");i.appendChild(n),n.appendChild(document.createTextNode(e.name+":")),n.className="mistvideo-description";var a=document.createElement("span");i.appendChild(a);var s=document.createTextNode(e.value?e.value:"");a.appendChild(s);var o=document.createElement("span");a.appendChild(o),i.set=function(e){if(0!==e&&(this.style.display=""),"object"==typeof e){try{if(e instanceof Promise)return void e.then((function(e){i.set(e)}),(function(){}))}catch(e){}if("val"in e&&(s.nodeValue=e.val,a.className="value"),o.children.length)return(t=o.children[0]).addData(e);var t=MistUtil.createGraph({x:[e.x],y:[e.y]},e.options);return o.style.display="",MistUtil.empty(o),o.appendChild(t)}return s.nodeValue=e},t.appendChild(i),r.push((function(){var t=e.function();i.set(t)}))}},forcePlayer:function(){var e=document.createElement("label");e.title="Reload MistVideo and use the selected player";var t=this,i=document.createElement("span");e.appendChild(i),i.appendChild(document.createTextNode("Force player: "));var r=document.createElement("select");e.appendChild(r);var n=document.createElement("option");for(var a in r.appendChild(n),n.value="",n.appendChild(document.createTextNode("Automatic")),mistplayers){n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(mistplayers[a].name))}return this.options.forcePlayer&&(r.value=this.options.forcePlayer),MistUtil.event.addListener(r,"change",(function(){t.options.forcePlayer=""!=this.value&&this.value,t.options.forcePlayer!=t.playerName&&t.reload("Reloading to force player.")})),e},forceType:function(){if(this.info){var e=document.createElement("label");e.title="Reload MistVideo and use the selected protocol";var t=this,i=document.createElement("span");e.appendChild(i),i.appendChild(document.createTextNode("Force protocol: "));var r=document.createElement("select");e.appendChild(r);var n=document.createElement("option");r.appendChild(n),n.value="",n.appendChild(document.createTextNode("Automatic"));var a={};for(var s in t.info.source){var o=t.info.source[s];if(!(o.type in a)){a[o.type]=1;n=document.createElement("option");r.appendChild(n),n.value=o.type,n.appendChild(document.createTextNode(MistUtil.format.mime2human(o.type)))}}return this.options.forceType&&(r.value=this.options.forceType),MistUtil.event.addListener(r,"change",(function(){t.options.forceType=""!=this.value&&this.value,t.source&&t.options.forceType==t.source.type||t.reload("Reloading to force new type.")})),e}},forceSource:function(){var e=document.createElement("label");e.title="Reload MistVideo and use the selected source";var t=this,i=document.createElement("span");e.appendChild(i),i.appendChild(document.createTextNode("Force source: "));var r=document.createElement("select");e.appendChild(r);var n=document.createElement("option");for(var a in r.appendChild(n),n.value="",n.appendChild(document.createTextNode("Automatic")),t.info.source){var s=t.info.source[a];n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(s.url+" ("+MistUtil.format.mime2human(s.type)+")"))}return this.options.forceSource&&(r.value=this.options.forceSource),MistUtil.event.addListener(r,"change",(function(){t.options.forceSource=""!=this.value&&this.value,t.options.forceSource!=t.source.index&&t.reload("Reloading to force new source.")})),e}}},MistSkins.dev.css={skin:misthost+"/skins/dev.css"},MistSkins.dev.structure.submenu=MistUtil.object.extend({},MistSkins.default.structure.submenu,!0),MistSkins.dev.structure.submenu.type="draggable",MistSkins.dev.structure.submenu.style.width="25em",MistSkins.dev.structure.submenu.children.unshift({type:"container",style:{flexShrink:1},classes:["mistvideo-column"],children:[{if:function(){return this.playerName&&this.source},then:{type:"container",classes:["mistvideo-description","mistvideo-displayCombo"],style:{display:"block"},children:[{type:"playername",style:{display:"inline"}},{type:"text",text:"is playing",style:{margin:"0 0.2em"}},{type:"mimetype"}]}},{type:"log"},{type:"decodingIssues"},{type:"container",classes:["mistvideo-column","mistvideo-devcontrols"],style:{"font-size":"0.9em"},children:[{type:"text",text:"Player control"},{type:"container",classes:["mistvideo-devbuttons"],style:{"flex-wrap":"wrap"},children:[{type:"button",title:"Build MistVideo again",label:"MistVideo.reload();",onclick:function(){this.reload("Dev-reload button clicked.")}},{type:"button",title:"Switch to the next available player and source combination",label:"MistVideo.nextCombo();",onclick:function(){this.nextCombo()}}]},{type:"forcePlayer"},{type:"forceType"}]}]});var mistplayers={};function MistPlayer(){}function mistPlay(e,t){return new MistVideo(e,t)}function MistVideo(e,t){var i=this;function r(e){if("meta"in e&&"tracks"in e.meta){var t=e.meta.tracks;for(var i in t)if("video"==t[i].type)return!0}return!1}function n(e){if(i.player&&i.player.api&&i.player.api.unload&&(i.log("Received new stream info while a player was already loaded: unloading player"),i.player.api.unload()),i.info=e,i.info.updated=new Date,MistUtil.event.send("haveStreamInfo",e,i.options.target),i.log("Stream info was loaded succesfully."),"error"in e){var n=e.error;return"on_error"in e?(i.log(n),n=e.on_error):"perc"in e&&(n+=" ("+Math.round(10*e.perc)/10+"%)"),void i.showError(n,{reload:!0,hideTitle:!0})}if(i.calcSize=function(e){e||(e={width:!1,height:!1});var r=e.width||!(!("width"in t)||!t.width)&&t.width,n=e.height||!(!("height"in t)||!t.height)&&t.height;if(this.info&&"source"in this.info)if(this.info.hasVideo&&"audio"!=this.source.type.split("/")[1]){if(!r||!n){var a=i.info.width/i.info.height;if(r||n)r?n=r/a:r=n*a;else{var s="maxwidth"in t&&t.maxwidth?t.maxwidth:window.innerWidth,o="maxheight"in t&&t.maxheight?t.maxheight:window.innerHeight;r=i.info.width,n=i.info.height;function l(e){r/=e,n/=e}r<426&&l(r/426),n<240&&l(n/240),s&&r>s&&l(r/s),o&&n>o&&l(n/o)}}}else r||(r=480),n||(n=42);else r=640,n=480;return this.size={width:Math.round(r),height:Math.round(n)},this.size},e.hasVideo=r(e),"live"==e.type){var a=0;for(var s in i.info.meta.tracks)a=Math.max(a,i.info.meta.tracks[s].lastms);e.lastms=a}else{var o=i.resumeTime;if(o){var l=function(){i.player&&i.player.api&&(i.player.api.currentTime=o),this.removeEventListener("initialized",l)};MistUtil.event.addListener(i.options.target,"initialized",l)}}i.options.ABR_bitrate&&i.options.ABR_resize&&i.info&&!i.info.selver&&(i.options.ABR_bitrate=!1),i.choosePlayer()?(i.reporting&&i.reporting.report({player:i.playerName,sourceType:i.source.type,sourceUrl:i.source.url,pageUrl:location.href}),i.player=new mistplayers[i.playerName].player,i.player.onreadylist=[],i.player.onready=function(e){this.onreadylist.push(e)},i.player.build(i,(function(e){if(i.log("Building new player"),i.container.removeAttribute("data-loading"),i.video=e,i.reporting&&i.reporting.init(),"api"in i.player){i.monitor={MistVideo:i,delay:1,averagingSteps:20,threshold:function(){return"webrtc"==this.MistVideo.source.type?.95:.75},init:function(){if(!this.vars||!this.vars.active){this.MistVideo.log("Enabling monitor"),this.vars={values:[],score:!1,active:!0};var e=this;!function t(){e.vars&&e.vars.active&&(e.vars.timer=e.MistVideo.timers.start((function(){var i=e.calcScore();!1!==i&&e.check(i)&&e.action(),t()}),1e3*e.delay))}()}},destroy:function(){this.vars&&this.vars.active&&(this.MistVideo.log("Disabling monitor"),this.MistVideo.timers.stop(this.vars.timer),delete this.vars)},reset:function(){this.vars&&this.vars.active?(this.MistVideo.log("Resetting monitor"),this.vars.values=[]):this.init()},calcScore:function(){var e=this.vars.values;if(e.push(this.getValue()),e.length<=1)return!1;var t=this.valueToScore(e[0],e[e.length-1]);return e.length>this.averagingSteps&&e.shift(),t=Math.max(t,e[e.length-1].score),this.vars.score=t,i.reporting&&i.reporting.stats.set("playbackScore",Math.round(10*t)/10),t},valueToScore:function(e,t){var i=1;return"player"in this.MistVideo&&"api"in this.MistVideo.player&&"playbackRate"in this.MistVideo.player.api&&(i=this.MistVideo.player.api.playbackRate),(t.video-e.video)/(t.clock-e.clock)/i},getValue:function(){var e={clock:.001*(new Date).getTime(),video:this.MistVideo.player.api.currentTime};return this.vars.values.length&&(e.score=this.valueToScore(this.vars.values[this.vars.values.length-1],e)),e},check:function(e){return!(this.vars.values.length<.5*this.averagingSteps)&&(e=e.socket.CLOSING&&e.init(),this.send_queue.push(t)};var t=!1;if(e.socket.setTracks=function(){e.s({type:"tracks",meta:MistUtil.object.keys(e.subscriptions).join(",")})},e.socket.onopen=function(){for(i.log("Metadata socket opened"),e.socket.setTracks(),1!=i.player.api.playbackRate&&e.s({type:"set_speed",play_rate:i.player.api.playbackRate}),e.s({type:"seek",seek_time:Math.round(1e3*i.player.api.currentTime),ff_to:Math.round(1e3*(i.player.api.currentTime+5))}),e.socket.addEventListener("message",(function(r){if(r.data){var n=JSON.parse(r.data);if(n){if("time"in n&&"track"in n&&"data"in n){var a=!1;if("all"in e.subscriptions&&(e.subscriptions.all.buffer.push(n),a=!0),n.track in e.subscriptions&&(e.subscriptions[n.track].buffer.push(n),a=!0),a)if(e.checktimer){var s=i.timers.list[e.checktimer];if(s)s>(new Date).getTime()+n.time-1e3*i.player.api.currentTime&&(i.log("The metadata socket received a message that should be displayed sooner than the current check time; resetting"),i.timers.stop(e.checktimer),e.checktimer=null,e.check())}else e.check()}if("type"in n)switch(n.type){case"on_time":!t&&n.data.current>1e3*(i.player.api.currentTime+30)&&(t=!0,e.s({type:"hold"}),i.log("Pausing metadata buffer because it is very far ahead, checking again in 5 seconds: "+n.data.current+" > "+1e3*i.player.api.currentTime),i.timers.start((function(){i.player.api.paused||e.s({type:"play"}),e.s({type:"fast_forward",ff_to:Math.round(1e3*(i.player.api.currentTime+5))})}),5e3));break;case"seek":for(var o in e.subscriptions)e.subscriptions[o].buffer=[];i.log("Cleared metadata buffer after completed seek"),e.checktimer&&(i.timers.stop(e.checktimer),e.checktimer=null)}}else i.log("Subtitle websocket received invalid message.")}else i.log("Subtitle websocket received empty message.")})),e.socket.onclose=function(){i.log("Metadata socket closed")};e.send_queue.length&&e.socket.readyState==e.socket.OPEN;)e.s(e.send_queue.shift())},!("seeked"in this.listeners)){var r=(new Date).getTime();e.check=function(){if(e.checktimer&&(i.timers.stop(e.checktimer),e.checktimer=null),!i.player.api.paused){var t=null;for(var n in e.subscriptions){for(var a=e.subscriptions[n].buffer;a.length&&a[0].time<=1e3*i.player.api.currentTime;){var s=a.shift();if(!(s.time<1e3*(i.player.api.currentTime-5)))for(var o in e.subscriptions[n].callbacks)e.subscriptions[n].callbacks[o].call(i,s)}a.length&&(t=Math.min(null===t?1e9:t,a[0].time))}var l=(new Date).getTime();if(l>r+5e3&&(e.s({type:"fast_forward",ff_to:Math.round(1e3*(i.player.api.currentTime+5))}),r=l),t){var c=t-1e3*i.player.api.currentTime;e.checktimer=i.timers.start((function(){e.check()}),c)}}},this.listeners.seeked=MistUtil.event.addListener(i.video,"seeked",(function(){for(var t in e.subscriptions)e.subscriptions[t].buffer=[];e.s({type:"seek",seek_time:Math.round(1e3*i.player.api.currentTime),ff_to:Math.round(1e3*(i.player.api.currentTime+5))}),r=(new Date).getTime()})),this.listeners.pause=MistUtil.event.addListener(i.video,"pause",(function(){e.s({type:"hold"}),i.timers.stop(e.checktimer),e.checktimer=null})),this.listeners.playing=MistUtil.event.addListener(i.video,"playing",(function(){e.s({type:"play"}),e.checktimer||e.check()})),this.listeners.ratechange=MistUtil.event.addListener(i.video,"ratechange",(function(){e.s({type:"set_speed",play_rate:i.player.api.playbackRate})}))}e.socket.readyState==e.socket.OPEN&&e.socket.onopen()},destroy:function(){for(var e in i.log("Closing metadata socket.."),this.socket.close(),this.socket=null,this.subscriptions={},this.listeners)MistUtil.event.removeListener(this.listeners[e]);this.listeners={}},add:function(e,t){"function"!=typeof e||t||(t=e,e="all"),"function"==typeof t&&(e in this.subscriptions||(this.subscriptions[e]={buffer:[],callbacks:[]}),this.subscriptions[e].callbacks.push(t),null===this.socket?this.init():this.socket.setTracks())},remove:function(e,t){if(e in this.subscriptions){for(var i in this.subscriptions[e].callbacks)if(t==this.subscriptions[e].callbacks[i]){this.subscriptions[e].callbacks.splice(i,1);break}0==this.subscriptions[e].callbacks.length&&(delete this.subscriptions[e],MistUtil.object.keys(this.subscriptions).length?this.socket.setTracks():this.destroy())}}},"function"==typeof t.subscribeToMetaTrack&&(t.subscribeToMetaTrack=[["all",t.subscribeToMetaTrack]]),t.subscribeToMetaTrack.length))for(var n in"object"!=typeof t.subscribeToMetaTrack[0]&&(t.subscribeToMetaTrack=[t.subscribeToMetaTrack]),t.subscribeToMetaTrack)i.metaTrackSubscriptions.add.apply(i.metaTrackSubscriptions,t.subscribeToMetaTrack[n])}}MistUtil.empty(i.options.target),new MistSkin(i),i.container=new MistUI(i),i.options.target.appendChild(i.container),i.container.setAttribute("data-loading",""),i.video.p=i.player;r=["abort","canplay","canplaythrough",,"emptied","ended","loadeddata","loadedmetadata","loadstart","pause","play","playing","ratechange","seeked","seeking","stalled","volumechange","waiting","metaUpdate_tracks","resizing"];for(var n in r)MistUtil.event.addListener(i.video,r[n],(function(e){e.message&&"chromecast"==e.message||i.log("Player event fired: "+e.type)}));if(MistUtil.event.addListener(i.video,"error",(function(e){var t;if("player"in i&&"api"in i.player&&"error"in i.player.api&&i.player.api.error)if("message"in i.player.api.error)t=i.player.api.error.message;else if("code"in i.player.api.error&&i.player.api.error instanceof MediaError){var r={1:"MEDIA_ERR_ABORTED: The fetching of the associated resource was aborted by the user's request.",2:"MEDIA_ERR_NETWORK: Some kind of network error occurred which prevented the media from being successfully fetched, despite having previously been available.",3:"MEDIA_ERR_DECODE: Despite having previously been determined to be usable, an error occurred while trying to decode the media resource, resulting in an error.",4:"MEDIA_ERR_SRC_NOT_SUPPORTED: The associated resource or media provider object (such as a MediaStream) has been found to be unsuitable."};t=i.player.api.error.code in r?r[i.player.api.error.code]:"MediaError code "+i.player.api.error.code}else"string"!=typeof(t=i.player.api.error)&&(t=JSON.stringify(t));else t="An error was encountered.";"Stream is online"==i.state?i.showError(t):(i.log(t,"error"),i.showError(i.state,{polling:!0}))})),"setSize"in i.player&&(i.player.videocontainer=i.video.parentNode,i.video.currentTarget=i.options.target,MistUtil.class.has(i.options.target,"mistvideo-secondaryVideo")||(i.player.resizeAll=function(){function e(t,i){if(t.video.currentTarget==i)return t.video;if(t.secondary)for(var r=0;r3600&&(t.reloadDelay/=1e3,this.log("A reloadDelay of more than an hour was set: assuming milliseconds were intended. ReloadDelay is now "+t.reloadDelay+"s")),new MistSkin(this),this.checkCombo=function(e,t){e||(e={}),e=MistUtil.object.extend(MistUtil.object.extend({},this.options),e);var r,n,a=!1;for(var s in e.forceSource?(r=[i.info.source[e.forceSource]],i.log("Forcing source "+e.forceSource+": "+r[0].type+" @ "+r[0].url)):e.forceType?(r=i.info.source.filter((function(t){return t.type==e.forceType})),i.log("Forcing type "+e.forceType)):r=i.info.source,mistplayers)mistplayers[s].shortname=s;e.forcePlayer&&mistplayers[e.forcePlayer]?(n=[mistplayers[e.forcePlayer]],i.log("Forcing player "+e.forcePlayer)):n=MistUtil.object.values(mistplayers),r=[].concat(r);var o={first:"source",source:[function(e){return"origIndex"in e||(e.origIndex=i.info.source.indexOf(e)),e.origIndex}],player:[{priority:1}]},l={inner:"player",outer:"source"};if(e.forcePriority){if("source"in e.forcePriority){if(!(e.forcePriority.source instanceof Array))throw"forcePriority.source is not an array.";o.source=e.forcePriority.source.concat(o.source),MistUtil.array.multiSort(r,o.source)}if("player"in e.forcePriority){if(!(e.forcePriority.player instanceof Array))throw"forcePriority.player is not an array.";o.player=e.forcePriority.player.concat(o.player),MistUtil.array.multiSort(n,o.player)}"first"in e.forcePriority&&(o.first=e.forcePriority.first),"player"==o.first&&(l.outer="player",l.inner="source")}var c={player:{list:n,current:!1},source:{list:r,current:!1}};if(e.startCombo){e.startCombo.started={player:!1,source:!1};for(s=0;s=2))for(var v in c[l.inner].list)if(c[l.inner].current=v,!(d(l.inner)>=1)){a=c.source.list[c.source.current];var y=c.player.list[c.player.current].shortname,g=mistplayers[y];if(g.isMimeSupported(a.type)){var b=g.isBrowserSupported(a.type,a,i);if(b){var k=p(b);if(k>u.score&&(t||i.log("Found a "+(u.score?"better":"working")+" combo: "+g.name+" with "+a.url+" (Score: "+k+")"),(u={score:k,player:y,source:a,source_index:c.source.current}).score==m))return u}}}return!!u.score&&u},this.choosePlayer=function(){i.log("Checking available players..");var e=this.checkCombo();if(!e)return!1;var t=mistplayers[e.player],r=e.source;return i.log("Selected: "+t.name+" with "+r.type+" @ "+r.url),i.playerName=e.player,(r=MistUtil.object.extend({},r)).index=e.source_index,r.url=i.urlappend(r.url),i.source=r,MistUtil.event.send("comboChosen","Player/source combination selected",i.options.target),!0},i.calcSize=function(){return{width:640,height:480}},MistUtil.empty(i.options.target),new MistSkin(i),i.container=new MistUI(i,i.skin.structure.placeholder),i.options.target.appendChild(i.container),i.container.setAttribute("data-loading",""),"WebSocket"in window){!function e(){i.log("Opening stream status stream through websocket..");var t,s=i.options.host.replace(/^http/i,"ws");s=MistUtil.http.url.addParam(i.urlappend(s+"/json_"+encodeURIComponent(i.stream)+".js"),{metaeverywhere:1,inclzero:1});try{t=new WebSocket(s)}catch(e){return i.log("Error while attempting to open WebSocket to "+s),void a()}i.socket=t,t.die=!1,t.destroy=function(){this.die=!0,i.reporting&&(i.reporting.reportStats(),i.reporting=!1),this.onclose=function(){},this.close()},t.timeOut=i.timers.start((function(){t.readyState<=1&&(t.destroy(),a())}),5e3),t.onopen=function(e){this.wasConnected=!0,i.reporting||(i.reporting={stats:{set:function(e,t){this.d[e]=t},add:function(e,t){void 0===t&&(t=1),this.d[e]+=t},d:{nWaiting:0,timeWaiting:0,nStalled:0,timeStalled:0,timeUnpaused:0,nError:0,nLog:0,videoHeight:null,videoWidth:null,playerHeight:null,playerWidth:null},last:{firstPlayback:null,nWaiting:0,timeWaiting:0,nStalled:0,timeStalled:0,timeUnpaused:0,nError:0,lastError:null,playbackScore:1,nLog:0,autoplay:null,videoHeight:null,videoWidth:null,playerHeight:null,playerWidth:null}},report:function(e){1==i.socket.readyState&&i.socket.send(JSON.stringify(e))},reportStats:function(){var e={},t=!1,r=i.logs.slice(this.stats.last.nLog);for(var n in this.stats.d)this.stats.d[n]!=this.stats.last[n]&&(e[n]=this.stats.d[n],this.stats.last[n]=e[n],t=!0);if(t){if(r.length)for(var n in e.logs=[],r)e.logs.push(r[n].message);this.report(e)}i.timers.start((function(){i.reporting&&i.reporting.reportStats()}),5e3)},init:function(){var e=i.video,t=MistUtil.event.addListener(e,"playing",(function(){i.reporting.stats.set("firstPlayback",(new Date).getTime()-i.bootMs),MistUtil.event.removeListener(t)}));if(MistUtil.event.addListener(e,"waiting",(function(){i&&i.reporting&&i.reporting.stats.add("nWaiting")})),MistUtil.event.addListener(e,"stalled",(function(){i&&i.reporting&&i.reporting.stats.add("nStalled")})),MistUtil.event.addListener(i.options.target,"error",(function(e){i&&i.reporting&&(i.reporting.stats.add("nError"),i.reporting.stats.set("lastError",e.message))}),e),Object&&Object.defineProperty){var r=0,n=!1,a=0,s=!1,o=0,l=!1,c=i.reporting.stats.d;Object.defineProperty(c,"timeWaiting",{get:function(){return r+(n?(new Date).getTime()-n:0)}}),Object.defineProperty(c,"timeStalled",{get:function(){return a+(s?(new Date).getTime()-s:0)}}),Object.defineProperty(c,"timeUnpaused",{get:function(){return o+(l?(new Date).getTime()-l:0)}}),Object.defineProperty(c,"nLog",{get:function(){return i.logs.length}}),Object.defineProperty(c,"videoHeight",{get:function(){return i.video?i.video.videoHeight:null}}),Object.defineProperty(c,"videoWidth",{get:function(){return i.video?i.video.videoWidth:null}}),Object.defineProperty(c,"playerHeight",{get:function(){return i.video?i.video.clientHeight:null}}),Object.defineProperty(c,"playerWidth",{get:function(){return i.video?i.video.clientWidth:null}}),MistUtil.event.addListener(e,"waiting",(function(){r=c.timeWaiting,n=(new Date).getTime()})),MistUtil.event.addListener(e,"stalled",(function(){a=c.timeStalled,s=(new Date).getTime()}));var d=["playing","pause"];for(var u in d)MistUtil.event.addListener(e,d[u],(function(){r=c.timeWaiting,a=c.timeStalled,n=!1,s=!1}));MistUtil.event.addListener(e,"playing",(function(){o=c.timeUnpaused,l=(new Date).getTime()})),MistUtil.event.addListener(e,"pause",(function(){o=c.timeUnpaused,l=!1}))}this.reportStats()}})},t.onclose=function(t){if(!this.die)return this.wasConnected?(i.log("Reopening websocket.."),void e()):void a()};var o=!1;t.addEventListener("message",(function(e){t.timeOut&&(i.timers.stop(t.timeOut),t.timeOut=!1);var a=JSON.parse(e.data);if(a||i.showError("Error while parsing stream status stream. Obtained: "+e.data.toString(),{reload:!0}),"error"in a){var s;e=a.error;switch("on_error"in a?(i.log(e),e=a.on_error):"perc"in a&&(e+=" ("+Math.round(10*a.perc)/10+"%)"),i.state=a.error,a.error){case"Stream is offline":i.info=!1,i.player&&i.player.api&&i.player.api.currentTime&&(i.resumeTime=i.player.api.currentTime);case"Stream is initializing":case"Stream is booting":case"Stream is waiting for data":case"Stream is shutting down":case"Stream status is invalid?!":if(i.player&&i.player.api&&!i.player.api.paused)return i.log(a.error,"error"),o||(o=MistUtil.event.addListener(i.video,"ended",(function(){i.showError(a.error,{polling:!0})}))),void(o=MistUtil.event.addListener(i.video,"waiting",(function(){i.showError(a.error,{polling:!0})})));s={polling:!0};break;default:s={reload:!0}}i.showError(e,s)}else{if(i.state="Stream is online",i.clearError(),o&&MistUtil.event.removeListener(o),!i.info)return void n(a);var l=function e(t,i){if(t==i)return!1;if("object"==typeof t&&void 0!==i){var r={};for(var n in t)if(!(MistUtil.array.indexOf(["lastms","hasVideo"],n)>=0)){var a=e(t[n],i[n]);a&&(r[n]=!0===a?[t[n],i[n]]:a)}for(var n in i)MistUtil.array.indexOf(["lastms","hasVideo"],n)>=0||n in t||(r[n]=[t[n],i[n]]);return!!MistUtil.object.keys(r).length&&r}return!0}(a,i.info);if(l){if("source"in l&&"error"in i.info)return void i.reload("Reloading, stream info has error");i.info=MistUtil.object.extend(i.info,a),i.info.updated=new Date;var c=!1;for(var d in l)switch(d){case"meta":for(var u in l[d])if("tracks"===u)i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",a,i.video);break;case"width":case"height":c=!0}c&&i.player.resize()}else i.log("Metachange: no differences detected")}}))}()}else a();return this.unload=function(e){if(!this.destroyed){for(var t in this.log("Unloading.."),this.destroyed=!0,this.timers.stop("all"),this.errorListeners){var r=this.errorListeners[t];if(r.src in MistUtil.scripts.list){var n=MistUtil.array.indexOf(MistUtil.scripts.list[r.src].subscribers);n>=0&&MistUtil.scripts.list[r.src].subscribers.splice(n,1)}}if("monitor"in i&&"destroy"in i.monitor&&i.monitor.destroy(),this.socket&&(this.reporting&&(this.reporting.reportStats(),this.reporting.report({unload:e||null})),this.socket.destroy()),this.player&&this.player.api&&("pause"in this.player.api&&this.player.api.pause(),"setSource"in this.player.api&&this.player.api.setSource(""),"unload"in this.player.api))try{this.player.api.unload()}catch(a){i.log("Error while unloading player: "+a.message)}if(this.metaTrackSubscriptions&&this.metaTrackSubscriptions.socket&&this.metaTrackSubscriptions.destroy(),this.UI&&this.UI.elements)for(var t in this.UI.elements){var a=this.UI.elements[t];if("attachedListeners"in a)for(var t in a.attachedListeners)MistUtil.event.removeListener(a.attachedListeners[t]);a.parentNode&&a.parentNode.removeChild(a)}this.video&&MistUtil.empty(this.video),"container"in this&&(MistUtil.empty(this.container),delete this.container),MistUtil.empty(this.options.target),delete this.video}},this.reload=function(e){var t="player"in this&&"api"in this.player&&this.player.api.currentTime;this.unload(e);var r=mistPlay(this.stream,this.options);if(t&&"live"!=this.info.type){var n=function(){r.player&&r.player.api&&(r.player.api.currentTime=t),this.removeEventListener("initialized",n)};MistUtil.event.addListener(this.options.target,"initialized",n)}return i},this.nextCombo=function(){var e=!1;"player"in this&&"api"in this.player&&(e=this.player.api.currentTime);var t={source:this.source.index,player:this.playerName};if(!this.checkCombo({startCombo:t},!0)){if(!this.checkCombo({startCombo:!1},!0))return;t=!1}this.unload("nextCombo");var r=this.options;if(r.startCombo=t,i=mistPlay(this.stream,r),e&&isFinite(e)&&"live"!=this.info.type){var n=function(){"player"in i&&"api"in i.player&&(i.player.api.currentTime=e),this.removeEventListener("initialized",n)};MistUtil.event.addListener(r.target,"initialized",n)}},this.onPlayerBuilt=function(){},t.MistVideoObject&&(t.MistVideoObject.reference=this),this} \ No newline at end of file +var MistUtil={format:{time:function(e,t){if(isNaN(e)||!isFinite(e))return e;t||(t={});var i=e<0?" ago":"";e=Math.abs(e);var r=Math.floor(e/86400);e-=86400*r;var n=Math.floor(e/3600);e-=3600*n;var a=Math.floor(e/60),s=Math.round(e%1*1e3);e=Math.floor(e-60*a);var o=[];return r&&(r=r+" day"+(r>1?"s":"")+", "),n||r?(o.push(n),o.push(("0"+a).slice(-2))):o.push(a),o.push(("0"+Math.floor(e)).slice(-2)),t.ms&&(o[o.length-1]+="."+("000"+s).slice(-3)),(r||"")+o.join(":")+i},ago:function(e,t){if(isNaN(e.getTime()))return"";var i=t||(new Date).getTime()-e.getTime(),r="",n=i<0;return n&&(i*=-1),i<1e3?r="live":i<6e4?(r=Math.round(i/1e3)+" sec",n?r="in "+r:r+=" ago"):r=!t&&(new Date).toLocaleDateString()==e.toLocaleDateString()||t<864e5?e.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit",second:"2-digit"}):i<5184e5?e.toLocaleString(void 0,{weekday:"short",hour:"numeric",minute:"2-digit",second:"2-digit"}):!t&&(new Date).getFullYear()==e.getFullYear()||t<316224e5?e.toLocaleString(void 0,{month:"short",day:"numeric",weekday:"short",hour:"numeric",minute:"2-digit",second:"2-digit"}):e.toLocaleString(void 0,{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit"}),r},ucFirst:function(e){return e.charAt(0).toUpperCase()+e.slice(1)},number:function(e){if(isNaN(Number(e))||0==Number(e))return e;var t=Math.max(3,Math.ceil(Math.log(e)/Math.LN10)),i=Math.pow(10,t-Math.floor(Math.log(e)/Math.LN10)-1);if((e=Math.round(e*i)/i)>=1e4){number=e.toString().split(".");for(var r=/(\d+)(\d{3})/;r.test(number[0]);)number[0]=number[0].replace(r,"$1 $2");e=number.join(".")}return e},bytes:function(e,t){if(isNaN(Number(e)))return e;var i=t?["bits","Kb","Mb","Gb","Tb","Pb"]:["bytes","KB","MB","GB","TB","PB"];if(0==e)unit=i[0];else{var r=Math.floor(Math.log(Math.abs(e))/Math.log(1024));r<0?unit=i[0]:(e/=Math.pow(1024,r),unit=i[r])}return this.number(e)+unit},bits:function(e){return this.bytes(e,!0)},mime2human:function(e){switch(e){case"html5/video/webm":return"WebM";case"html5/application/vnd.apple.mpegurl":return"HLS (TS)";case"html5/application/vnd.apple.mpegurl;version=7":return"HLS (CMAF)";case"flash/10":return"Flash (RTMP)";case"flash/11":return"Flash (HDS)";case"flash/7":return"Flash (Progressive)";case"html5/video/mpeg":return"TS";case"html5/application/vnd.ms-sstr+xml":case"html5/application/vnd.ms-ss":return"Smooth Streaming";case"dash/video/mp4":return"DASH";case"webrtc":return"WebRTC (WS)";case"whep":return"WebRTC (WHEP)";case"silverlight":return"Smooth streaming (Silverlight)";case"html5/text/vtt":return"VTT subtitles";case"html5/text/plain":return"SRT subtitles";default:return e.replace("html5/","").replace("video/","").replace("audio/","").toLocaleUpperCase()}}},class:{add:function(e,t){if("classList"in e)e.classList.add(t);else{var i=this.get(e);i.push(t),this.set(e,i)}},remove:function(e,t){if("classList"in e)e.classList.remove(t);else{for(var i=this.get(e),r=i.length-1;r>=0;r--)i[r]==t&&i.splice(r);this.set(e,i)}},get:function(e){var t=e.getAttribute("class");return t&&""!=t?t.split(" "):[]},set:function(e,t){e.setAttribute("class",t.join(" "))},has:function(e,t){return e.className.split(" ").indexOf(t)>=0}},object:{extend:function(e,t,i){for(var r in t)i&&"object"==typeof t[r]&&!("nodeType"in t[r])?(r in e||(MistUtil.array.is(t[r])?e[r]=[]:e[r]={}),this.extend(e[r],t[r],!0)):e[r]=t[r];return e},keys:function(e,t){var i=[];for(var r in e)i.push(r);return t&&("function"!=typeof t&&(t=function(e,t){return e.localeCompare(t)}),i.sort((function(i,r){return t(i,r,e[i],e[r])}))),i},values:function(e,t){var i=this.keys(e,t);for(var r in values=[],i)values.push(e[i[r]]);return values}},array:{indexOf:function(e,t){if(!(e instanceof Array))throw"Tried to use indexOf on something that is not an array";if("indexOf"in e)return e.indexOf(t);for(var i;it?1:e=0?r:i.length}if("function"==typeof e)return e(t);if("object"==typeof e){if(e instanceof Array)return i(t,e[0],e[1]);for(var r in e)return i(t,r,e[r])}if(e in t)return t[e];throw"Invalid sorting rule: "+e+". This should be a function, object or key of "+JSON.stringify(t)+"."}return e.sort((function(e,n){var a=0;for(var s in t){var o=t[s];if(0!=(a=i(r(o,e),r(o,n))))break}return a})),e}},createUnique:function(){var e="uid"+Math.random().toString().replace("0.","");return document.querySelector("."+e)?createUnique():e},http:{getpost:function(e,t,i,r,n){var a=new XMLHttpRequest;if(a.open(e,t,!0),"POST"==e&&a.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n&&(a.timeout=8e3),a.onload=function(){var e=a.status;e>=200&&e<300?r(a.response):n&&n(a)},n&&(a.onerror=function(){n(a)},a.ontimeout=a.onerror),"POST"==e){var s,o=[];for(var l in i)o.push(l+"="+encodeURIComponent(i[l]));o.length&&(s=o.join("&")),a.send(s)}else a.send()},get:function(e,t,i){this.getpost("GET",e,null,t,i)},post:function(e,t,i,r){this.getpost("POST",e,t,i,r)},url:{addParam:function(e,t){var i=e.split("?"),r=[i.shift()],n=[];for(var a in i.length&&(n=i[0].split("&")),t)n.push(a+"="+t[a]);return n.length&&r.push(n.join("&")),r.join("?")},append:function(e,t){var i=document.createElement("a");return i.href=e,"?"==t[0]?""==i.search?i.search=t:i.search+="&"+t.slice(1):"&"==t[0]?""==i.search?i.search="?"+t.slice(1):i.search+=t:i.href+=t,i.href},split:function(e){var t=document.createElement("a");return t.href=e,{protocol:t.protocol,host:t.hostname,hash:t.hash,port:t.port,path:t.pathname.replace(/\/*$/,"")}},sanitizeHost:function(e){var t=MistUtil.http.url.split(e);return t.protocol+"//"+t.host+(t.port&&""!=t.port?":"+t.port:"")+(t.hash&&""!=t.hash?"#"+t.hash:"")+(t.path?"/"==t.path.charAt(0)?t.path:"/"+t.path:"")}}},css:{cache:{},load:function(e,t,i){var r=document.createElement("style");r.type="text/css",r.setAttribute("data-source",e),i&&(r.callback=i);var n=this.cache;function a(e){var i=MistUtil.css.applyColors(e,t);"callback"in r?r.callback(i):r.textContent=i}if(e in n)n[e]instanceof Array?n[e].push(a):a(n[e]);else{n[e]=[a];var s=3;!function t(){MistUtil.http.get(e,(function(t){for(var i in n[e])n[e][i](t);n[e]=t}),(function(){if(s>0)s--,setTimeout(t,2e3);else{var i="/*Failed to load*/";for(var r in n[e])n[e][r](i);n[e]=i}}))}()}return r},applyColors:function(e,t){return e.replace(/\$([^\s^;^}]*)/g,(function(e,i){var r=i.split("."),n=t;for(var a in r)n=n[r[a]];return n}))},createStyle:function(e,t,i){var r=document.createElement("style");return r.type="text/css",e&&(t&&(e=this.prependClass(e,t,i)),r.textContent=e),r},prependClass:function(e,t,i){var r=!1;"string"!=typeof e&&("unprepended"in(r=e)||(r.unprepended=r.textContent),e=r.unprepended);var n=(e=e.replace(/\/\*.*?\*\//g,"")).match(/@[^}]*}/g);for(var a in n){e=e.replace(n[a],"@@#@@");for(var s=1;s0)s=r.bps>131072?Math.round(r.bps/1024/1024*8)+"mbps":Math.round(r.bps/1024*8)+"kbps",n[a]=s;break;case"fpks":r.fpks>0&&(n[a]=r.fpks/1e3+"fps");break;case"channels":r.channels>0&&(n[a]=1==r.channels?"Mono":2==r.channels?"Stereo":"Surround ("+r.channels+"ch)");break;case"rate":n[a]=Math.round(.001*r.rate)+"Khz";break;case"language":"Undetermined"!=r[a]&&(n[a]=r[a]);break;case"codec":if("meta"==r.codec)continue;n[a]=r[a]}r.describe=n}for(var o in t){var l=!1;for(var i in t[o])if(l){if(MistUtil.object.keys(t[o]).length>1)for(var a in t[o][i].describe)l[a]!=t[o][i].describe[a]&&delete l[a]}else l=MistUtil.object.extend({},t[o][i].describe);for(var i in t[o]){var c={},d={};for(var a in t[o][i].describe)a in l?d[a]=t[o][i].describe[a]:c[a]=t[o][i].describe[a];t[o][i].different=c,t[o][i].same=d;var u=MistUtil.object.values(c);t[o][i].displayName=u.length?u.join(", "):MistUtil.object.values(t[o][i].describe).join(" ")}var p={};for(var i in t[o]){if(t[o][i].displayName in p){var h=1;for(var i in t[o])t[o][i].different.trackid=h+")",t[o][i].displayName="Track "+h+" ("+t[o][i].displayName+")",h++;break}p[t[o][i].displayName]=1}}return t},translateCodec:function(e){function t(t){return("0"+e.init.charCodeAt(t).toString(16)).slice(-2)}switch(e.codec){case"AAC":return"mp4a.40.2";case"MP3":return"mp3";case"AC3":return"ec-3";case"H264":return"avc1."+t(1)+t(2)+t(3);case"HEVC":return"hev1."+t(1)+t(6)+t(7)+t(8)+t(9)+t(10)+t(11)+t(12);default:return e.codec.toLowerCase()}}},isTouchDevice:function(){return"ontouchstart"in window||navigator.msMaxTouchPoints>0},getPos:function(e,t){e.currentStyle||window.getComputedStyle(e,null);for(var i=1,r=e;r;)r.style.zoom&&""!=r.style.zoom&&(i*=parseFloat(r.style.zoom,10)),r=r.parentElement;var n=e.getBoundingClientRect().left-(parseInt(e.borderLeftWidth,10)||0),a=e.getBoundingClientRect().width,s=Math.max(0,(t.clientX/i-n)/a);return s=Math.min(s,1)},createGraph:function(e,t){var i="http://www.w3.org/2000/svg",r=document.createElementNS(i,"svg");r.setAttributeNS(null,"height","100%"),r.setAttributeNS(null,"width","100%"),r.setAttributeNS(null,"class","mist icon graph"),r.setAttributeNS(null,"preserveAspectRatio","none");var n=e.x[0],a=e.y[0];if(t.differentiate)for(var s=1;st.x.count&&(l.shift(),d()),d(e.x-n,-1*e.y),this.setAttributeNS(null,"d","M"+l.join(" L")),h()}},r.addData=function(e){m.addData(e)},r},getBrowser:function(){var e=window.navigator.userAgent;return e.indexOf("MSIE ")>=0||e.indexOf("Trident/")>=0?"ie":e.indexOf("Edge/")>=0?"edge":e.indexOf("Opera")>=0||e.indexOf("OPR")>=0?"opera":e.indexOf("Chrome")>=0?"chrome":e.indexOf("Safari")>=0?"safari":e.indexOf("Firefox")>=0&&"firefox"},getAndroid:function(){var e=navigator.userAgent.toLowerCase().match(/android\s([\d\.]*)/i);return!!e&&e[1]},sources:{find:function(e,t){e:for(var i in e){for(var r in t)if("protocol"==r){if(e[i].url.slice(0,t.protocol.length)!=t.protocol)continue e}else if(e[i][r]!=t[r])continue e;return e[i]}return!1}}};if(void 0===MistSkins)var MistSkins={};if("undefined"!=typeof mistoptions&&"host"in mistoptions)var misthost=MistUtil.http.url.sanitizeHost(mistoptions.host);else misthost="..";function MistSkin(e){e.skin=this,this.applySkinOptions=function(t){var i;return"string"==typeof t&&t in MistSkins&&(t=MistUtil.object.extend({},MistSkins[t],!0)),i="inherit"in t&&t.inherit&&t.inherit in MistSkins?this.applySkinOptions(t.inherit):MistSkins.default,this.structure=MistUtil.object.extend({},i.structure),t&&"structure"in t&&MistUtil.object.extend(this.structure,t.structure),this.blueprints=MistUtil.object.extend({},i.blueprints),t&&"blueprints"in t&&MistUtil.object.extend(this.blueprints,t.blueprints),this.icons=MistUtil.object.extend({},i.icons,!0),t&&"icons"in t&&MistUtil.object.extend(this.icons.blueprints,t.icons),this.icons.build=function(t,i,r){i||(i=22);var n,a=this.blueprints[t];n="function"==typeof a.svg?a.svg.call(e,r):a.svg,"object"!=typeof i&&(i={height:i,width:i}),"object"!=typeof a.size&&(a.size={height:a.size,width:a.size}),(!("width"in i)&&"height"in i||!("height"in i)&&"width"in i)&&("width"in i&&(i.height=i.width*a.size.height/a.size.width),"height"in i&&(i.width=i.height*a.size.width/a.size.height));var s="";s+='',s+='',s+=n,s+="",s+="";var o=document.createElement("div");return o.innerHTML=s,o.firstChild},this.colors=MistUtil.object.extend({},i.colors),t&&"colors"in t&&MistUtil.object.extend(this.colors,t.colors,!0),this.css=MistUtil.object.extend({},i.css),t&&"css"in t&&MistUtil.object.extend(this.css,t.css),this},this.applySkinOptions("skin"in e.options?e.options.skin:"default");var t=[];for(var i in this.css)if("string"==typeof this.css[i]){var r=MistUtil.css.load(e.urlappend(this.css[i]),this.colors);t.push(r)}this.css=t}function MistUI(e,t){e.UI=this,this.elements=[],this.buildStructure=function(t){if("function"==typeof t&&(t=t.call(e)),"if"in t){var i=!1;if(t.if.call(e,t)?i=t.then:"else"in t&&(i=t.else),!i)return;for(var r in t)["if","then","else"].indexOf(r)<0&&(r in i?(i[r]instanceof Array||(i[r]=[i[r]]),i[r]=i[r].concat(t[r])):i[r]=t[r]);return this.buildStructure(i)}if("type"in t&&t.type in e.skin.blueprints){var n=e.skin.blueprints[t.type].call(e,t);if(!n)return;if(MistUtil.class.add(n,"mistvideo-"+t.type),"css"in t){var a=MistUtil.createUnique();for(var r in t.css=[].concat(t.css),t.css){var s=MistUtil.css.createStyle(t.css[r],a);n.appendChild(s)}MistUtil.class.add(n,a),n.uid=a}if("classes"in t)for(var r in t.classes)MistUtil.class.add(n,t.classes[r]);if("title"in t&&(n.title=t.title),"style"in t)for(var r in t.style)n.style[r]=t.style[r];if("children"in t)for(var r in t.children){var o=this.buildStructure(t.children[r]);o&&n.appendChild(o)}return e.UI.elements.push(n),n}return!1},this.build=function(){return this.buildStructure(t||e.skin.structure.main)};var i=this.build(),r=MistUtil.createUnique(),n=0;for(var a in e.skin.css.length&&(i.style.opacity=0),e.skin.css){var s=e.skin.css[a];s.callback=function(t){"/*Failed to load*/"==t?(this.textContent=t,e.showError("Failed to load CSS from "+this.getAttribute("data-source"))):this.textContent=MistUtil.css.prependClass(t,r,!0),n++,e.skin.css.length<=n&&(i.style.opacity="")},""!=s.textContent&&s.callback(s.textContent),i.appendChild(s)}MistUtil.class.add(i,r);var o=MistUtil.getBrowser();return o&&MistUtil.class.add(i,"browser-"+o),i}MistSkins.default={structure:{main:{if:function(){return!!this.info.hasVideo&&"audio"!=this.source.type.split("/")[1]},then:{type:"placeholder",classes:["mistvideo"],children:[{type:"hoverWindow",classes:["mistvideo-maincontainer"],mode:"pos",style:{position:"relative"},transition:{hide:"left: 0; right: 0; bottom: -43px;",show:"bottom: 0;",viewport:"left:0; right: 0; top: -1000px; bottom: 0;"},button:{type:"videocontainer"},children:[{type:"loading"},{type:"error"}],window:{type:"controls"}}]},else:{type:"container",classes:["mistvideo"],style:{overflow:"visible"},children:[{type:"controls",classes:["mistvideo-novideo"],style:{width:"480px"}},{type:"loading"},{type:"error"},{if:function(){return"stock"==this.options.controls},then:{type:"video",style:{position:"absolute"}},else:{type:"video",style:{position:"absolute",display:"none"}}}]}},videocontainer:{type:"container",children:[{type:"videobackground",alwaysDisplay:!1,delay:5},{type:"video"},{type:"subtitles"}]},controls:{if:function(){return!!(this.player&&this.player.api&&this.player.api.play)},then:{type:"container",classes:["mistvideo-column"],children:[{type:"progress",classes:["mistvideo-pointer"]},{type:"container",classes:["mistvideo-main","mistvideo-padding","mistvideo-row","mistvideo-background"],children:[{type:"play",classes:["mistvideo-pointer"]},{type:"currentTime"},{if:function(){return"size"in this&&this.size.width>300||!this.info.hasVideo||"audio"==this.source.type.split("/")[1]},then:{type:"totalTime"}},{type:"container",classes:["mistvideo-align-right"],children:[{type:"container",children:[{type:"container",classes:["mistvideo-volume_container"],children:[{type:"volume",mode:"horizontal",size:{height:22},classes:["mistvideo-pointer"]}]},{type:"speaker",classes:["mistvideo-pointer"],style:{"margin-left":"-2px"}}]},{if:function(){return"size"in this&&this.size.width>300||!this.info.hasVideo||"audio"==this.source.type.split("/")[1]},then:{type:"container",children:[{type:"chromecast",classes:["mistvideo-pointer"]},{type:"loop",classes:["mistvideo-pointer"]},{type:"fullscreen",classes:["mistvideo-pointer"]},{type:"picture-in-picture",classes:["mistvideo-pointer"]}]}},{type:"hoverWindow",mode:"pos",transition:{hide:"right: -1000px; bottom: 44px;",show:"right: 5px;",viewport:"right: 0; left: 0; bottom: 0; top: -1000px"},button:{type:"settings",classes:["mistvideo-pointer"]},window:{type:"submenu"}}]}]}]},else:{if:function(){return!(!this.player||!this.player.api)},then:{type:"hoverWindow",mode:"pos",transition:{hide:"right: -1000px; bottom: 44px;",show:"right: 2.5px;",viewport:"right: 0; left: -1000px; bottom: 0; top: -1000px"},style:{right:"5px",left:"auto"},button:{type:"settings",classes:["mistvideo-background","mistvideo-padding"]},window:{type:"submenu"}}}},submenu:{type:"container",style:{width:"80%",maxWidth:"25em",zIndex:2},classes:["mistvideo-padding","mistvideo-column","mistvideo-background"],children:[{type:"tracks"},{if:function(){return"size"in this&&this.size.width<=300},then:{type:"container",classes:["mistvideo-center"],children:[{type:"chromecast",classes:["mistvideo-pointer"]},{type:"loop",classes:["mistvideo-pointer"]},{type:"fullscreen",classes:["mistvideo-pointer"]},{type:"picture-in-picture",classes:["mistvideo-pointer"]}]}}]},placeholder:{type:"container",classes:["mistvideo","mistvideo-delay-display"],children:[{type:"placeholder"},{type:"loading"},{type:"error"}]},secondaryVideo:function(e){return{type:"hoverWindow",classes:["mistvideo"],mode:"pos",transition:{hide:"left: 10px; bottom: -40px;",show:"bottom: 10px;",viewport:"left: 0; right: 0; top: 0; bottom: 0"},button:{type:"container",children:[{type:"videocontainer"}]},window:{type:"switchVideo",classes:["mistvideo-controls","mistvideo-padding","mistvideo-background","mistvideo-pointer"],containers:e}}}},css:{skin:misthost+"/skins/default.css"},icons:{blueprints:{play:{size:45,svg:''},largeplay:{size:45,svg:''},pause:{size:45,svg:''},speaker:{size:45,svg:''},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return''}},muted:{size:45,svg:''},fullscreen:{size:45,svg:''},pip:{size:45,svg:''},loop:{size:45,svg:''},settings:{size:45,svg:''},loading:{size:100,svg:''},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return''}},popout:{size:45,svg:''},switchvideo:{size:45,svg:''}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;if(MistUtil.event.addListener(e.video,"contextmenu",(function(t){t.preventDefault(),e.container.setAttribute("data-show-submenu",""),e.container.removeAttribute("data-hide-submenu"),e.container.removeAttribute("data-hidecursor");var i=function(){e.container.removeAttribute("data-show-submenu"),e.container.removeEventListener("mouseout",i)};MistUtil.event.addListener(e.container,"mouseout",i)})),e.video.hideTimer=!1,e.video.hideCursor=function(){this.hideTimer&&clearTimeout(this.hideTimer),this.hideTimer=e.timers.start((function(){e.container.setAttribute("data-hidecursor","");var t=e.container.querySelector(".mistvideo-controls");t&&t.parentNode.setAttribute("data-hidecursor","")}),3e3)},MistUtil.event.addListener(e.video,"mousemove",(function(){e.container.removeAttribute("data-hidecursor");var t=e.container.querySelector(".mistvideo-controls");t&&t.parentNode.removeAttribute("data-hidecursor"),e.video.hideCursor()})),MistUtil.event.addListener(e.video,"mouseout",(function(){e.video.hideTimer&&e.timers.stop(e.video.hideTimer)})),e.options.autoplay)var t=MistUtil.event.addListener(e.video,"canplay",(function(){if(e.player.api&&e.player.api.paused){var i=e.player.api.play();i&&i.catch((function(t){if(!e.destroyed)if(e.log("Autoplay failed. Retrying with muted audio.."),e.info.hasVideo){e.player.api.muted=!0,MistUtil.event.send("volumechange",null,e.video);var i=e.player.api.play();i&&i.then((function(){e.reporting&&(e.reporting.stats.d.autoplay="success")})).then((function(){if(!e.destroyed){e.log("Autoplay worked! Video will be unmuted on mouseover if the page has been interacted with."),e.reporting&&(e.reporting.stats.d.autoplay="muted");var t=e.skin.icons.build("muted",100);MistUtil.class.add(t,"mistvideo-pointer"),e.container.appendChild(t),MistUtil.event.addListener(t,"click",(function(){e.player.api.muted=!1,e.container.removeChild(t)}));var i=!1,r=function(){i=!0,document.body.removeEventListener("click",r)};MistUtil.event.addListener(document.body,"click",r,e.video);var n=function(){i&&(e.player.api.muted=!1,e.video.removeEventListener("mouseenter",n),e.log("Re-enabled sound"))};MistUtil.event.addListener(e.video,"mouseenter",n);var a=function(){e.player.api.muted||(t.parentNode&&e.container.removeChild(t),e.video.removeEventListener("volumechange",a),document.body.removeEventListener("click",r),e.video.removeEventListener("mouseenter",n))};MistUtil.event.addListener(e.video,"volumechange",a)}})).catch((function(){if(!e.destroyed){e.log("Autoplay failed even with muted video. Unmuting and showing play button."),e.timers.start((function(){e.player.api.paused&&(e.player.api.pause(),e.monitor&&e.monitor.destroy())}),5e3),e.reporting&&(e.reporting.stats.d.autoplay="failed"),e.player.api.muted=!1;var t=e.skin.icons.build("largeplay",150);MistUtil.class.add(t,"mistvideo-pointer"),e.container.appendChild(t),MistUtil.event.addListener(t,"click",(function(){e.player.api.paused&&e.player.api.play()}));var i=function(){e.container.removeChild(t),e.video.removeEventListener("play",i)};MistUtil.event.addListener(e.video,"play",i)}}))}else e.reporting&&(e.reporting.stats.d.autoplay="failed")}))}else e.reporting&&(e.reporting.stats.d.autoplay="success");MistUtil.event.removeListener(t)}));return this.video},videocontainer:function(){return this.UI.buildStructure(this.skin.structure.videocontainer)},secondaryVideo:function(e){e||(e={}),e.options||(e.options={});var t=this;"secondary"in t||(t.secondary=[]);var i=MistUtil.object.extend({},t.options);i=MistUtil.object.extend(i,e.options),t.secondary.push(i);var r={primary:t,secondary:!1};i.target=document.createElement("div"),delete i.container;var n={};return i.MistVideoObject=n,MistUtil.event.addListener(i.target,"initialized",(function(){var e=n.reference;i.MistVideo=e,r.secondary=e,e.player.api.muted=!0,e.player.api.loop=!1;for(var a=i.target.querySelectorAll(".mistvideo-controls"),s=0;s30)e.player.api.pausedesync=!0,e.player.api.currentTime=this.currentTime,e.log("Re-syncing with main video by seeking (desync: "+t+"s)");else if(i>.01){var r=.1;i<1&&(r=.05),(r=1+r*Math.sign(t))!=e.player.api.playbackRate&&e.log("Re-syncing by changing the playback rate (desync: "+Math.round(1e3*t)+"ms, rate: "+r+")"),e.player.api.playbackRate=r}else 1!=e.player.api.playbackRate&&(e.player.api.playbackRate=1,e.log("Sync with main video achieved (desync: "+Math.round(1e3*t)+"ms)"))}}),i.target),MistUtil.event.addListener(e.video,"seeked",(function(){e.player.api.pausedesync=!1}))})),i.skin=MistUtil.object.extend({},t.skin,!0),i.skin.structure.main=MistUtil.object.extend({},t.skin.structure.secondaryVideo(r)),mistPlay(t.stream,i),i.target},switchVideo:function(e){var t=document.createElement("div");return t.appendChild(this.skin.icons.build("switchvideo")),MistUtil.event.addListener(t,"click",(function(){var t=e.containers.primary,i=e.containers.secondary;function r(e,t){if(e.video.currentTarget==t)return e.video;if(e.secondary)for(var i=0;i300&&(e.style.zoom=1.5),e}},submenu:function(){return this.UI.buildStructure(this.skin.structure.submenu)},hoverWindow:function(e){var t={type:"container",classes:"classes"in e?e.classes:[],children:"children"in e?e.children:[]};switch(t.classes.push("hover_window_container"),"classes"in e.window||(e.window.classes=[]),e.window.classes.push("inner_window"),e.window.classes.push("mistvideo-container"),e.window={type:"container",classes:["outer_window"],children:[e.window]},"classes"in e.button||(e.button.classes=[]),e.button.classes.push("pointer"),e.mode){case"left":t.classes.push("horizontal"),t.children=[e.window,e.button];break;case"right":t.classes.push("horizontal"),t.children=[e.button,e.window];break;case"top":t.classes.push("vertical"),t.children=[e.button,e.window];break;case"bottom":t.classes.push("vertical"),t.children=[e.window,e.button];break;case"pos":t.children=[e.button,e.window],"classes"in e.window||(e.window.classes=[]);break;default:throw"Unsupported mode for structure type hoverWindow"}return"transition"in e&&("css"in t||(t.css=[]),t.css.push(".hover_window_container:hover > .outer_window:not([data-hidecursor]) > .inner_window { "+e.transition.show+" }\n.hover_window_container > .outer_window { "+e.transition.viewport+" }\n.hover_window_container > .outer_window > .inner_window { "+e.transition.hide+" }")),t.classes.push(e.mode),this.UI.buildStructure(t)},draggable:function(e){var t=this.skin.blueprints.container(e),i=this,r=this.skin.icons.build("fullscreen",16);MistUtil.class.remove(r,"fullscreen"),MistUtil.class.add(r,"draggable-icon"),t.appendChild(r),r.style.alignSelf="flex-end",r.style.position="absolute",r.style.cursor="move";var n={},a=function(e){t.style.left=e.clientX-n.x+"px",t.style.top=e.clientY-n.y+"px"},s=function(e){window.removeEventListener("mousemove",a),window.removeEventListener("click",s),MistUtil.event.addListener(r,"click",o)},o=function(e){e.stopPropagation(),r.removeEventListener("click",o),n.x=i.container.getBoundingClientRect().left-(t.getBoundingClientRect().left-e.clientX),n.y=i.container.getBoundingClientRect().top-(t.getBoundingClientRect().top-e.clientY),t.style.position="absolute",t.style.right="auto",t.style.bottom="auto",i.container.appendChild(t),a(e),MistUtil.event.addListener(window,"mousemove",a,t),MistUtil.event.addListener(window,"click",s,t)};return MistUtil.event.addListener(r,"click",o),t},progress:function(){var e=document.createElement("div"),t=document.createElement("div");e.appendChild(t),t.kids={},t.kids.bar=document.createElement("div"),t.kids.bar.className="bar",t.appendChild(t.kids.bar);var i=this.video,r=this,n=1/0;if(r.info&&r.info.meta&&r.info.meta.tracks)for(var a in r.info.meta.tracks).001*r.info.meta.tracks[a].firstms1e3?(t.updateBuffers(r.player.api.buffered),l=(new Date).getTime()):c||(c=r.timers.start((function(){e(),c=!1}),1e3))}()}),t);var d=0,u=!1;MistUtil.event.addListener(i,"timeupdate",(function(){!function e(){(new Date).getTime()-d>200&&!f?(t.updateBar(r.player.api.currentTime),d=(new Date).getTime()):u||(u=r.timers.start((function(){e(),u=!1}),1e3))}()}),t),MistUtil.event.addListener(i,"seeking",(function(){t.updateBar(r.player.api.currentTime)}),t),t.getPos=function(e){var t=isNaN(e)?MistUtil.getPos(this,e):e;return"live"==r.info.type?(t-1)*o()+r.player.api.duration:!!isFinite(r.player.api.duration)&&t*(r.player.api.duration-s())+s()},t.seek=function(e){var t=this.getPos(e);r.player.api.currentTime=t},MistUtil.event.addListener(e,"mouseup",(function(e){1==e.which&&t.seek(e)}));var p=r.UI.buildStructure({type:"tooltip"});p.style.opacity=0,t.appendChild(p),MistUtil.event.addListener(e,"mouseout",(function(){f||(p.style.opacity=0)})),t.moveTooltip=function(e){var t=this.getPos(e);if(!1!==t){p.setDisplay(t),p.style.opacity=1;var i=MistUtil.getPos(this,e),r={bottom:20};i>.5?(r.right=100*(1-i)+"%",p.triangle.setMode("bottom","right")):(r.left=100*i+"%",p.triangle.setMode("bottom","left")),p.setPos(r)}else p.style.opacity=0};var h=document.createElement("span");h.setAttribute("class","mistvideo-realtime");var m=document.createTextNode("");h.appendChild(m),p.setDisplay=function(e){if(r.options.useDateTime&&r.info&&r.info.unixoffset){var i=t.getPos(1)-t.getPos(0),n=.001*(new Date).getTime()-(.001*r.info.unixoffset+t.getPos(1)),a=Math.max(i,n),s="";if("live"==r.info.type)if(a<60)s=MistUtil.format.ago(new Date(r.info.unixoffset+1e3*e));else{var o=.001*(new Date).getTime()-(.001*r.info.unixoffset+e);o<172800&&(s+=" - "+MistUtil.format.time(o))}else s+=MistUtil.format.time(e);if(a>=60){m.nodeValue=" at "+MistUtil.format.ago(new Date(r.info.unixoffset+1e3*e),1e3*a);var l=document.createDocumentFragment();l.appendChild(document.createTextNode(s)),l.appendChild(h),p.setHtml(l)}else m.nodeValue="",p.setText(s)}else p.setText(MistUtil.format.time(e))},MistUtil.event.addListener(e,"mousemove",(function(e){t.moveTooltip(e)}));var f=!1;return MistUtil.event.addListener(e,"mousedown",(function(i){if(1==i.which){f=!0,t.updateBar(t.getPos(i));var r=MistUtil.event.addListener(document,"mousemove",(function(e){t.updateBar(t.getPos(e)),t.moveTooltip(e)}),t),n=MistUtil.event.addListener(document,"mouseup",(function(i){1==i.which&&(f=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),p.style.opacity=0,(!i.path||MistUtil.array.indexOf(i.path,e)<0)&&t.seek(i))}),t)}})),e},play:function(){var e=this,t=document.createElement("div");t.appendChild(this.skin.icons.build("play")),t.appendChild(this.skin.icons.build("pause")),t.setState=function(e){this.setAttribute("data-state",e)},t.setState("paused");var i=this.video;return MistUtil.event.addListener(i,"playing",(function(){t.setState("playing"),e.options.autoplay=!0}),t),MistUtil.event.addListener(i,"pause",(function(){t.setState("paused")}),t),MistUtil.event.addListener(i,"paused",(function(){t.setState("paused")}),t),MistUtil.event.addListener(i,"ended",(function(){t.setState("paused")}),t),MistUtil.event.addListener(t,"click",(function(){e.player.api.error&&e.player.api.load(),e.player.api.paused?e.player.api.play():(e.player.api.pause(),e.options.autoplay=!1)})),e.player.api&&MistUtil.event.addListener(e.video,"click",(function(){e.player.api.paused?e.player.api.play():MistUtil.isTouchDevice()||(e.player.api.pause(),e.options.autoplay=!1)}),t),t},speaker:function(){if(!this.player.api||!("muted"in this.player.api))return!1;var e=!1,t=this.info.meta.tracks;for(var i in t)if("audio"==t[i].type){e=!0;break}if(!e)return!1;var r=this.skin.icons.build("speaker"),n=this,a=this.video;return n.player.api.volume&&!n.player.api.muted||MistUtil.class.add(r,"off"),MistUtil.event.addListener(a,"volumechange",(function(){n.player.api.volume&&!n.player.api.muted?MistUtil.class.remove(r,"off"):MistUtil.class.add(r,"off")}),r),MistUtil.event.addListener(r,"click",(function(e){n.player.api.muted=!n.player.api.muted})),r},volume:function(e){if(!this.player.api||!("volume"in this.player.api))return!1;var t=!1,i=this.info.meta.tracks;for(var r in i)if("audio"==i[r].type){t=!0;break}if(!t)return!1;var n=document.createElement("div"),a=this.skin.icons.build("volume","size"in e&&e.size);n.appendChild(a);var s=this;a.mode="mode"in e?e.mode:"vertical","vertical"==a.mode&&(a.style.transform="rotate(90deg)"),a.margin={start:.15,end:.1};var o=this.video;a.set=function(e){100!=(e=100-100*Math.pow(1-e/100,2))&&0!=e&&(e=100*this.addPadding(e/100));for(var t=a.querySelectorAll(".slider"),i=0;i6e4&&e.size.width>=600&&(n.nodeValue=" (at "+MistUtil.format.ago(o)+")")),t.setAttribute("title",MistUtil.format.ago(o,3456e7))}else r=a(s),t.setAttribute("title",r);i.nodeValue=r},t.set(),MistUtil.event.addListener(e.video,"timeupdate",(function(){t.set()}),t),MistUtil.event.addListener(e.video,"seeking",(function(){t.set()}),t),t},totalTime:function(){var e=this,t=document.createElement("div"),i=document.createTextNode("");t.appendChild(i);this.player.api;return"live"==e.info.type?(i.nodeValue="live",t.className="live"):(t.set=function(r){if(!isNaN(r)&&isFinite(r))if(this.style.display="",e.options.useDateTime&&e.info&&"live"==e.info.type&&e.info.unixoffset){var n=new Date(1e3*r+e.info.unixoffset);i.nodeValue=MistUtil.format.ago(n),t.setAttribute("title",MistUtil.format.ago(n,3456e7))}else i.nodeValue=MistUtil.format.time(r),t.setAttribute("title",i.nodeValue);else this.style.display="none"},MistUtil.event.addListener(e.video,"durationchange",(function(){var i=e.player.api.duration;t.set(i)}),t)),t},playername:function(){if(this.playerName&&this.playerName in mistplayers){var e=document.createElement("span");return e.appendChild(document.createTextNode(mistplayers[this.playerName].name)),e}},mimetype:function(){if(this.source){var e=document.createElement("a");return e.href=this.source.url,e.target="_blank",e.title=e.href+" ("+this.source.type+")",e.appendChild(document.createTextNode(MistUtil.format.mime2human(this.source.type))),e}},logo:function(e){if("element"in e)return e.element;if("src"in e){var t=document.createElement("img");return t.src=e.src,t}},settings:function(){var e=this,t=this.skin.icons.build("settings"),i=void 0!==document.ontouchstart;return MistUtil.event.addListener(t,"click",(function(){e.container.hasAttribute("data-show-submenu")?(i&&e.container.setAttribute("data-hide-submenu",""),e.container.removeAttribute("data-show-submenu")):(e.container.setAttribute("data-show-submenu",""),e.container.removeAttribute("data-hide-submenu"))})),t},loop:function(){if("loop"in this.player.api&&"live"!=this.info.type){var e=this,t=this.skin.icons.build("loop");this.video;return t.set=function(){e.player.api.loop?MistUtil.class.remove(this,"off"):MistUtil.class.add(this,"off")},MistUtil.event.addListener(t,"click",(function(t){e.player.api.loop=!e.player.api.loop,this.set()})),t.set(),t}},fullscreen:function(){if("setSize"in this.player&&this.info.hasVideo&&"audio"!=this.source.type.split("/")[1]){var e=this,t=["requestFullscreen","webkitRequestFullscreen","mozRequestFullScreen","msRequestFullscreen","webkitEnterFullscreen"],i=[function(){return e.container},function(){return e.video}],r=!1;e:for(var n in i)for(var a in t)if(t[a]in i[n]()){(r={}).request=function(){return r.fullscreenableElement()[t[a]]()};var s=["exitFullscreen","webkitCancelFullScreen","mozCancelFullScreen","msExitFullscreen","webkitExitFullscreen"],o=["fullscreenElement","webkitFullscreenElement","mozFullScreenElement","msFullscreenElement","webkitFullscreenElement"];r.cancel=function(){return document[s[a]]()},r.element=function(){return document[o[a]]},r.event=["fullscreenchange","webkitfullscreenchange","mozfullscreenchange","MSFullscreenChange","webkitfullscreenchange"][a],r.fullscreenableElement=i[n];break e}if(!r){var l=function(e){if("Escape"===e.key)r.cancel()};(r={event:"fakefullscreenchange",fullscreenableElement:function(){return e.container}}).request=function(){return r.element=function(){return e.container},MistUtil.event.send(r.event,null,document),document.addEventListener("keydown",l),!0},r.cancel=function(){return r.element=function(){return null},document.removeEventListener("keydown",l),MistUtil.event.send(r.event,null,document),!0},r.element=function(){return null}}var c=this.skin.icons.build("fullscreen");return MistUtil.event.addListener(c,"click",d),MistUtil.event.addListener(e.video,"dblclick",d),MistUtil.event.addListener(document,r.event,(function(){r.element()==r.fullscreenableElement()?e.container.setAttribute("data-fullscreen",""):e.container.hasAttribute("data-fullscreen")&&e.container.removeAttribute("data-fullscreen"),e.player.resizeAll()}),c),c}function d(){r.element()?r.cancel():r.request()}},"picture-in-picture":function(){if("setSize"in this.player&&this.info.hasVideo&&"audio"!=this.source.type.split("/")[1]&&document.pictureInPictureEnabled){var e=this;if("requestPictureInPicture"in e.video){var t=this.skin.icons.build("pip");return t.set=function(){document.pictureInPictureElement?MistUtil.class.remove(this,"off"):MistUtil.class.add(this,"off")},MistUtil.event.addListener(t,"click",(function(){var i;(i=document.pictureInPictureElement?document.exitPictureInPicture():e.video.requestPictureInPicture())?i.then((function(){t.set()})):t.set()})),t.set(),t}}},tracks:function(){if(this.info&&this.video){var e=this,t=document.createElement("table");return i(this.info.meta.tracks),MistUtil.event.addListener(e.video,"metaUpdate_tracks",(function(e){i(e.message.meta.tracks)}),t),t}function i(i){MistUtil.empty(t),i=MistUtil.tracks.parse(i);var r={},n={};function a(t,i){if(i?e.log("User selected "+t+" track with id "+i):(e.log("User selected automatic track selection for "+t),MistUtil.event.send("trackSetToAuto",t,e.video)),e.options.setTracks||(e.options.setTracks={}),e.options.setTracks[t]=i,!0===i&&r[t]&&MistUtil.event.send("change",null,r[t]),"setTrack"in e.player.api)return e.player.api.setTrack(t,i);var n={};for(var a in r)"subtitle"!=a&&""!=r[a].value&&(n[a]=r[a].value);return""!=i&&(n[t]=i),"setTracks"in e.player.api?e.player.api.setTracks(n):"setSource"in e.player.api?e.player.api.setSource(MistUtil.http.url.addParam(e.source.url,n)):void 0}var s=MistUtil.object.keys(i,(function(e,t){function i(e){switch(e){case"audio":return"aaaaaaa";case"video":return"aaaaaab";default:return e}}return i(e)>i(t)?1:i(e)1&&"player"in e&&"api"in e.player&&("setTrack"in e.player.api||"setTracks"in e.player.api||"setSource"in e.player.api)){var b=document.createElement("select");if(b.title="Select another "+l+" track",r[l]=b,b.trackType=l,f.appendChild(b),"subtitle"!=l){var k=document.createElement("option");b.appendChild(k),k.value="",k.appendChild(document.createTextNode("Automatic"))}var M=S(c[MistUtil.object.keys(c)[0]].same);if(M.length)(x=document.createElement("span")).className="mistvideo-description",f.appendChild(x),f.appendChild(document.createTextNode(M.join(" ")));function w(e){return""==e?-1:Number(e)}var U=MistUtil.object.keys(c,(function(e,t){return w(e)-w(t)}));for(var p in U){var C=c[U[p]];k=document.createElement("option");b.appendChild(k),k.value="idx"in C?C.idx:C.trackid,MistUtil.object.keys(C.different).length?k.appendChild(document.createTextNode(S(C.different).join(" "))):k.appendChild(document.createTextNode("Track "+(Number(p)+1)))}if(MistUtil.event.addListener(e.video,"playerUpdate_trackChanged",(function(t){t.message.type==l&&"none"!=t.message.trackid&&(b.value=t.message.trackid,e.log("Player selected "+l+" track with id "+t.message.trackid))}),b),"subtitle"==l){if(MistUtil.event.addListener(b,"change",(function(){try{localStorage.mistSubtitleLanguage=c[this.value].lang}catch(e){}if("setWSSubtitle"in e.player.api)e.player.api.setWSSubtitle(""==this.value?void 0:this.value);else if(""!=this.value){var t=MistUtil.object.extend({},c[this.value]);t.label=S(t.describe).join(" "),t.src=MistUtil.http.url.addParam(u,{track:this.value}),e.player.api.setSubtitle(t)}else e.player.api.setSubtitle()})),"localStorage"in window&&null!=localStorage&&"mistSubtitleLanguage"in localStorage)for(var p in c)if(c[p].lang==localStorage.mistSubtitleLanguage){b.value=p;var T=document.createEvent("Event");T.initEvent("change"),b.dispatchEvent(T);break}}else MistUtil.event.addListener(b,"change",(function(){this.trackType in n&&(n[this.trackType].checked=!0),a(this.trackType,this.value)}))}else{var x;(x=document.createElement("span")).className="mistvideo-description",f.appendChild(x),x.appendChild(document.createTextNode(S(c[g[0]].same).join(" ")))}}function S(e){var t={trackid:0,language:1,width:2,bps:3,fpks:4,channels:5,codec:6,rate:7};return MistUtil.object.values(e,(function(e,i,r,n){return t[e]>t[i]?1:t[e]=.999?n():a()}),1e3))}var s=["waiting","seeking","stalled"];for(var o in s)MistUtil.event.addListener(e.video,s[o],(function(t){e.player.api&&!e.player.api.paused&&"container"in e&&r(t)}),t);s=["seeked","playing","canplay","paused","ended"];for(var o in s)MistUtil.event.addListener(e.video,s[o],(function(t){"container"in e&&n()}),t);MistUtil.event.addListener(e.video,"progress",(function(t){"container"in e&&"monitor"in e&&"vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.score>.99&&n()}),t)}return t},error:function(){var e=this,t=document.createElement("div");t.message=function(t,i,r){MistUtil.empty(this);var n=document.createElement("div");if(n.className="message",this.appendChild(n),!r.polling&&!r.passive&&!r.hideTitle){var a=document.createElement("h3");n.appendChild(a),a.appendChild(document.createTextNode("The "+(e.casting?"chromecast":"player")+" has encountered a problem"))}var s=document.createElement("p");if(n.appendChild(s),n.update=function(e){MistUtil.empty(s),s.innerHTML=e},t){e.info.on_error&&(t=e.info.on_error.replace(/\/,t)),n.update(t);var o=document.createElement("p");if(o.className="details mistvideo-description",n.appendChild(o),i)o.appendChild(document.createTextNode(i));else if("decodingIssues"in e.skin.blueprints){if("player"in e&&"api"in e.player&&e.video){if(i=[],void 0!==e.state&&i.push(["Stream state:",e.state]),void 0!==e.player.api.currentTime&&i.push(["Current video time:",MistUtil.format.time(e.player.api.currentTime)]),"video"in e&&"getVideoPlaybackQuality"in e.video){var l=e.video.getVideoPlaybackQuality();"droppedVideoFrames"in l&&"totalVideoFrames"in l&&l.totalVideoFrames&&i.push(["Frames dropped/total:",MistUtil.format.number(l.droppedVideoFrames)+"/"+MistUtil.format.number(l.totalVideoFrames)]),"corruptedVideoFrames"in l&&l.corruptedVideoFrames&&i.push(["Corrupted frames:",MistUtil.format.number(l.corruptedVideoFrames)])}i.push({0:["NETWORK EMPTY:","not yet initialized"],1:["NETWORK IDLE:","resource selected, but not in use"],2:["NETWORK LOADING:","data is being downloaded"],3:["NETWORK NO SOURCE:","could not locate source"]}[e.video.networkState]);if(i.push({0:["HAVE NOTHING:","no information about ready state"],1:["HAVE METADATA:","metadata has been loaded"],2:["HAVE CURRENT DATA:","data for the current playback position is available, but not for the next frame"],3:["HAVE FUTURE DATA:","data for current and next frame is available"],4:["HAVE ENOUGH DATA:","can start playing"]}[e.video.readyState]),!r.passive){var c=document.createElement("table");for(var d in i){var u=document.createElement("tr");for(var p in c.appendChild(u),i[d]){var h=document.createElement("td");u.appendChild(h),h.appendChild(document.createTextNode(i[d][p]))}}o.appendChild(c)}}var m,f=document.createElement("div");f.className="mistvideo-container mistvideo-column",f.style.textAlign="left",f.style.marginBottom="1em",n.appendChild(f),(m=e.UI.buildStructure({type:"forcePlayer"}))&&f.appendChild(m),(m=e.UI.buildStructure({type:"forceType"}))&&f.appendChild(m)}}return n};var i,r=!1,n=!1,a={};if(this.showError=function(s,o){o||(o={softReload:!!(e.player&&e.player.api&&e.player.api.load),reload:!0,nextCombo:!!e.info,polling:!1,passive:!1});var l=o.type?o.type:s;if(!(l in a)){if(!0===o.reload&&(e.options.reloadDelay&&!isNaN(Number(e.options.reloadDelay))?o.reload=Number(e.options.reloadDelay):o.reload=10),o.passive){if(!0===r)return;if(r)return i.update(s),void(n=(new Date).getTime());t.setAttribute("data-passive","")}else t.removeAttribute("data-passive");var c;r&&t.clear(),r=!o.passive||"passive",n=(new Date).getTime(),e.casting||(c=this.log(s,"error"));var d=t.message(s,!1,o);i=d;var u=document.createElement("div");if(u.className="mistvideo-buttoncontainer",d.appendChild(u),MistUtil.empty(u),e.casting&&!o.passive){var p={type:"button",label:"Stop casting",onclick:function(){e.detachFromCast()}};isNaN(o.softReload+"")||(p.delay=o.softReload),u.appendChild(e.UI.buildStructure(p))}if(o.softReload&&!e.casting){p={type:"button",label:"Reload video",onclick:function(){e.player.api.load()}};isNaN(o.softReload+"")||(p.delay=o.softReload),u.appendChild(e.UI.buildStructure(p))}if(o.reload){p={type:"button",label:"Reload player",onclick:function(){e.reload("Reloading because reload button was clicked.")}};isNaN(o.reload+"")||(p.delay=o.reload),u.appendChild(e.UI.buildStructure(p))}if(o.nextCombo){p={type:"button",label:"Next source",onclick:function(){e.nextCombo()}};isNaN(o.nextCombo+"")||(p.delay=o.nextCombo),u.appendChild(e.UI.buildStructure(p))}if(o.ignore){p={type:"button",label:"Ignore",onclick:function(){this.clearError(),a[l]=!0}};isNaN(o.ignore+"")||(p.delay=o.ignore),u.appendChild(e.UI.buildStructure(p))}o.polling&&u.appendChild(e.UI.buildStructure({type:"polling"})),MistUtil.class.add(t,"show"),"container"in e&&e.container.removeAttribute("data-loading"),c&&c.defaultPrevented&&(e.log("Error event was defaultPrevented, not showing."),t.clear())}},t.clear=function(){for(var i=t.querySelectorAll("svg.icon.timeout"),n=0;n=0;e--)r.removeChild(r.children[e])},e.setHtml=function(n){r.empty(),r.appendChild(n),"html"!=t&&(e.removeChild(i),e.appendChild(r),t="html")};var n=document.createElement("div");return e.triangle=n,n.className="triangle",e.appendChild(n),n.setMode=function(e,t){e||(e="bottom"),t||(t="left");var i=["bottom","top","right","left"];for(var r in i){this.style[i[r]]="";var n=MistUtil.format.ucFirst(i[r]);this.style["border"+n]="",this.style["border"+n+"Color"]=""}var a={top:"bottom",bottom:"top",left:"right",right:"left"};this.style[e]="-10px",this.style["border"+MistUtil.format.ucFirst(a[e])]="none",this.style["border"+MistUtil.format.ucFirst(e)+"Color"]="transparent",this.style[t]=0,this.style["border"+MistUtil.format.ucFirst(a[t])]="none"},e.setPos=function(e){var t={left:"auto",right:"auto",top:"auto",bottom:"auto"};for(var i in MistUtil.object.extend(t,e),t)isNaN(t[i])||(t[i]+="px"),this.style[i]=t[i]},e},button:function(e){var t=document.createElement("button"),i=this;if(e.onclick&&(MistUtil.event.addListener(t,"click",(function(){e.onclick.call(i,arguments)})),e.delay)){var r=this.UI.buildStructure({type:"timeout",delay:e.delay,function:e.onclick});r&&t.appendChild(r)}return t.appendChild(document.createTextNode(e.label)),t},videobackground:function(e){e||(e={}),e.delay||(e.delay=5);for(var t=document.createElement("div"),i=this,r=[],n=0;n<2;n++){var a=document.createElement("canvas");a._context=a.getContext("2d"),t.appendChild(a),r.push(a)}var s=0,o=!1;function l(){if(e.alwaysDisplay||i.video.videoWidth/i.video.videoHeight!=t.clientWidth/t.clientHeight){r[s].removeAttribute("data-front"),++s>=r.length&&(s=0);var n=r[s],a=n._context;n.width=i.video.videoWidth,n.height=i.video.videoHeight,a.drawImage(i.video,0,0),n.setAttribute("data-front","")}i.player.api.paused?o=!1:i.timers.start((function(){l()}),1e3*e.delay)}return MistUtil.event.addListener(i.video,"playing",(function(){o||(l(),o=!0)})),t},subtitles:function(e){if(!("WebSocket"in window))return!1;var t=this;if(!("player"in t)||!("api"in t.player)||!("currentTime"in t.player.api))return!1;if(!("metaTrackSubscriptions"in t))return!1;var i=document.createElement("div"),r=document.createElement("span");i.appendChild(r);var n=document.createTextNode("");r.appendChild(n);var a=!1;function s(e){n.nodeValue=e.data.replace(/\<\/?[bui]\>/gi,"").replace(/{\/?[bui]}/gi,"").replace(/{\\a\d+}/gi,"").replace(/\<\/?font[^>]*?\>/gi,""),a&&(t.timers.stop(a),a=null),function i(r){a=t.timers.start((function(){if(t.player.api.paused)var r=MistUtil.event.addListener(t.video,"playing",(function(){i(e.time+("duration"in e?e.duration:5e3)-1e3*t.player.api.currentTime),MistUtil.event.removeListener(r)}));else n.nodeValue=""}),r)}("duration"in e?e.duration:5e3)}if(MistUtil.event.addListener(t.video,"seeked",(function(){n.nodeValue="",a&&t.timers.stop(a),a=null})),!("setWSSubtitle"in t.player.api)){var o=!1;t.player.api.setWSSubtitle=function(e){e!=o&&(void 0!==e&&t.metaTrackSubscriptions.add(e,s),e!=o&&t.metaTrackSubscriptions.remove(o,s),o="undefined"!=e&&e)}}return i},chromecast:function(){var e=this;if(!(!"".indexOf||e.options.host.indexOf("localhost")>-1||e.options.host.indexOf("::1")>-1)){var t,i,r,n,a=document.createElement("div"),s=document.createElement("div");s.className="mistvideo-casting";var o={},l={currentTime:!1,paused:!0,volume:1,muted:!1,buffer:[],loop:e.player.api?e.player.api.loop:e.options.loop};if(e.casting=!1,window.chrome&&window.chrome.cast||window.loadedCastApi)"loading"==window.loadedCastApi?(e.log("Not appending chromecast script - still loading"),e.timers.start((function(){d()}),200)):(e.log("Not appending chromecast script - already loaded"),d());else{window.__onGCastApiAvailable=function(t,i){t||e.log("Error while loading chromecast API: "+i),d()},window.loadedCastApi="loading";var c=document.createElement("script");c.setAttribute("src","//www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"),document.head.appendChild(c),e.log("Appending chromecast script")}return a}function d(c){if(!window.chrome||!window.chrome.cast||!window.chrome.cast.isAvailable||c>5)return a.parentNode&&a.parentNode.removeChild(a),void e.log("Chromecast is not supported");if(!window.cast)return c||(c=0),e.log("Casting api loaded but cast function not yet available, retrying.."),void e.timers.start((function(){d(c++)}),200);e.log("Chromecast API loaded"),window.loadedCastApi&&"loading"!=window.loadedCastApi||(window.loadedCastApi=!0);var u=document.createElement("google-cast-launcher");function p(a){MistUtil.class.remove(u,"active"),MistUtil.class.remove(e.container,"casting"),s.parentNode&&s.parentNode.removeChild(s),!a&&cast.framework.CastContext.getInstance().getCurrentSession()&&cast.framework.CastContext.getInstance().getCurrentSession().endSession(!0),t?(e.player.api=t,t.currentTime=l.currentTime,t.play(),e.reload=i,e.nextCombo=r,e.unload=n):e.player.api.play(),e.player.api&&e.player.api.setTracks&&MistUtil.object.keys(o).length&&e.player.api.setTracks(o),e.casting=!1,e.log("Detached chromecast session")}a.appendChild(u),cast.framework.CastContext.getInstance().setOptions({receiverApplicationId:"E5F1558C",autoJoinPolicy:chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),e.detachFromCast=p,u.addEventListener("click",(function(a){if(a.stopPropagation(),MistUtil.class.has(u,"active"))p();else{function c(){cast.framework.CastContext.getInstance().getCurrentSession().addMessageListener("urn:x-cast:mistcaster",(function(t,i){if(e.destroyed&&p(),(i=JSON.parse(i)).type)switch(i.type){case"log":case"error":e.log("[Chromecast] "+i.message,i.type);break;case"showError":e.showError.apply(e,i.args);break;case"event":switch(i.event){case"timeupdate":l.currentTime=i.currentTime,MistUtil.event.send(i.event,"chromecast",e.video);break;case"progress":l.buffer=i.buffer,MistUtil.event.send(i.event,"chromecast",e.video);break;case"pause":case"paused":case"ended":case"play":case"playing":l.paused=i.paused,MistUtil.event.send(i.event,"chromecast",e.video);break;case"volumechange":l.volume=i.volume,l.muted=i.muted,MistUtil.event.send(i.event,"chromecast",e.video);break;default:MistUtil.event.send(i.event,"chromecast",e.video)}break;case"detach":i.n==e.n&&p(!0);break;default:console.log("Unknown chromecast message type",i)}}));var a={type:"load",n:e.n,options:{host:e.options.host,loop:e.options.loop,poster:e.options.poster,streaminfo:e.options.streaminfo,urlappend:e.options.urlappend,forcePriority:e.options.forcePriority,setTracks:e.options.setTracks,controls:!1,skin:"default"},stream:e.stream};e.info&&"live"!=e.info.type&&(a.time=e.player.api.currentTime),"dev"==e.options.skin&&(a.options.skin=e.options.skin),e.player&&e.player.api&&(a.volume=e.player.api.volume,a.muted=e.player.api.muted,a.options.loop=e.player.api.loop),MistCast.send(a),t=e.player.api,i=e.reload,r=e.nextCombo,n=e.unload,o=e.options.setTracks?e.options.setTracks:{},e.player.api=new Proxy(t,{get:function(e,t,i){var r=e[t];switch(t){case"muted":case"volume":case"currentTime":case"paused":case"loop":return l[t];case"buffered":return new function(){this.length=l.buffer.length,this.start=function(e){return l.buffer[e][0]},this.end=function(e){return l.buffer[e][1]}};case"setTracks":case"play":case"pause":return function(){for(var e=[],i=0;i=t.scrollHeight-5})),r.logs)o(r.logs[l].time,r.logs[l].message,r.logs[l].data);return MistUtil.event.addListener(r.options.target,"log",(function(e){if(e.message){var t={};r.player&&r.player.api&&"currentTime"in r.player.api&&(t.currentTime=r.player.api.currentTime),o(new Date,e.message,t)}}),e),MistUtil.event.addListener(r.options.target,"error",(function(e){if(e.message){var t={type:"error"};r.player&&r.player.api&&"currentTime"in r.player.api&&(t.currentTime=r.player.api.currentTime),o(new Date,e.message,t)}}),e),e},decodingIssues:function(){if(this.player){var e=this,t=document.createElement("div");if(e.player.api){var i={"Playback score":function(){if("monitor"in e){if("vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.values.length){var t=e.monitor.vars.values[e.monitor.vars.values.length-1];if("score"in t){Math.min(1,Math.max(0,t.score));return{x:t.clock,y:Math.min(1,Math.max(0,t.score)),options:{y:{min:0,max:1},x:{count:10}},val:Math.round(100*Math.min(1,Math.max(0,e.monitor.vars.score)))+"%"}}}return 0}},"Corrupted frames":function(){if(e.player.api&&"getVideoPlaybackQuality"in e.player.api){var t=e.player.api.getVideoPlaybackQuality();if(t)return t.corruptedVideoFrames?{val:MistUtil.format.number(t.corruptedVideoFrames),x:.001*(new Date).getTime(),y:t.corruptedVideoFrames,options:{x:{count:10}}}:0}},"Dropped frames":function(){if(e.player.api){if("getVideoPlaybackQuality"in e.player.api){var t=e.player.api.getVideoPlaybackQuality();if(t)return t.droppedVideoFrames?MistUtil.format.number(t.droppedVideoFrames):0}if("webkitDroppedFrameCount"in e.player.api)return e.player.api.webkitDroppedFrameCount}},"Total frames":function(){if(e.player.api&&"getVideoPlaybackQuality"in e.player.api){var t=e.player.api.getVideoPlaybackQuality();if(t)return MistUtil.format.number(t.totalVideoFrames)}},"Decoded audio":function(){if(e.player.api)return MistUtil.format.bytes(e.player.api.webkitAudioDecodedByteCount)},"Decoded video":function(){if(e.player.api)return MistUtil.format.bytes(e.player.api.webkitVideoDecodedByteCount)},"Negative acknowledgements":function(){if(e.player.api)return MistUtil.format.number(e.player.api.nackCount)},"Picture losses":function(){return MistUtil.format.number(e.player.api.pliCount)},"Packets lost":function(){return MistUtil.format.number(e.player.api.packetsLost)},"Packets received":function(){return MistUtil.format.number(e.player.api.packetsReceived)},"Bytes received":function(){if(e.player.api)return MistUtil.format.bytes(e.player.api.bytesReceived)},"Local latency [ms]":function(){if(e.player.api&&"getLatency"in e.player.api){var t=e.player.api.getLatency();return t?new Promise((function(e,i){t.then((function(t){var i=[];for(var r in t)t[r]&&i.push(r[0]+":"+Math.round(1e3*t[r]));i.length?e(i.join(" ")):e()}),i)})):new Promise((function(e,t){e()}),(function(){}))}},"Current bitrate":function(){var t;return e.player.monitor&&"currentBps"in e.player.monitor?(t=MistUtil.format.bits(e.player.monitor.currentBps))?t+"ps":t:e.player.api&&"currentBps"in e.player.api?(t=MistUtil.format.bits(e.player.api.currentBps()))?t+"ps":t:void 0},"Framerate in":function(){if(e.player.api&&"framerate_in"in e.player.api)return MistUtil.format.number(e.player.api.framerate_in())},"Framerate out":function(){if(e.player.api&&"framerate_out"in e.player.api)return MistUtil.format.number(e.player.api.framerate_out())}},r=[];for(var n in i)void 0!==i[n]()&&a({name:n,function:i[n]});t.update=function(){for(var i in r)r[i]();e.timers.start((function(){t.update()}),1e3)},t.update()}return t}function a(e){var i=document.createElement("label");t.appendChild(i),i.style.display="none";var n=document.createElement("span");i.appendChild(n),n.appendChild(document.createTextNode(e.name+":")),n.className="mistvideo-description";var a=document.createElement("span");i.appendChild(a);var s=document.createTextNode(e.value?e.value:"");a.appendChild(s);var o=document.createElement("span");a.appendChild(o),i.set=function(e){if(0!==e&&(this.style.display=""),"object"==typeof e){try{if(e instanceof Promise)return void e.then((function(e){i.set(e)}),(function(){}))}catch(e){}if("val"in e&&(s.nodeValue=e.val,a.className="value"),o.children.length)return(t=o.children[0]).addData(e);var t=MistUtil.createGraph({x:[e.x],y:[e.y]},e.options);return o.style.display="",MistUtil.empty(o),o.appendChild(t)}return s.nodeValue=e},t.appendChild(i),r.push((function(){var t=e.function();i.set(t)}))}},forcePlayer:function(){var e=document.createElement("label");e.title="Reload MistVideo and use the selected player";var t=this,i=document.createElement("span");e.appendChild(i),i.appendChild(document.createTextNode("Force player: "));var r=document.createElement("select");e.appendChild(r);var n=document.createElement("option");for(var a in r.appendChild(n),n.value="",n.appendChild(document.createTextNode("Automatic")),mistplayers){n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(mistplayers[a].name))}return this.options.forcePlayer&&(r.value=this.options.forcePlayer),MistUtil.event.addListener(r,"change",(function(){t.options.forcePlayer=""!=this.value&&this.value,t.options.forcePlayer!=t.playerName&&t.reload("Reloading to force player.")})),e},forceType:function(){if(this.info){var e=document.createElement("label");e.title="Reload MistVideo and use the selected protocol";var t=this,i=document.createElement("span");e.appendChild(i),i.appendChild(document.createTextNode("Force protocol: "));var r=document.createElement("select");e.appendChild(r);var n=document.createElement("option");r.appendChild(n),n.value="",n.appendChild(document.createTextNode("Automatic"));var a={};for(var s in t.info.source){var o=t.info.source[s];if(!(o.type in a)){a[o.type]=1;n=document.createElement("option");r.appendChild(n),n.value=o.type,n.appendChild(document.createTextNode(MistUtil.format.mime2human(o.type)))}}return this.options.forceType&&(r.value=this.options.forceType),MistUtil.event.addListener(r,"change",(function(){t.options.forceType=""!=this.value&&this.value,t.source&&t.options.forceType==t.source.type||t.reload("Reloading to force new type.")})),e}},forceSource:function(){var e=document.createElement("label");e.title="Reload MistVideo and use the selected source";var t=this,i=document.createElement("span");e.appendChild(i),i.appendChild(document.createTextNode("Force source: "));var r=document.createElement("select");e.appendChild(r);var n=document.createElement("option");for(var a in r.appendChild(n),n.value="",n.appendChild(document.createTextNode("Automatic")),t.info.source){var s=t.info.source[a];n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(s.url+" ("+MistUtil.format.mime2human(s.type)+")"))}return this.options.forceSource&&(r.value=this.options.forceSource),MistUtil.event.addListener(r,"change",(function(){t.options.forceSource=""!=this.value&&this.value,t.options.forceSource!=t.source.index&&t.reload("Reloading to force new source.")})),e}}},MistSkins.dev.css={skin:misthost+"/skins/dev.css"},MistSkins.dev.structure.submenu=MistUtil.object.extend({},MistSkins.default.structure.submenu,!0),MistSkins.dev.structure.submenu.type="draggable",MistSkins.dev.structure.submenu.style.width="25em",MistSkins.dev.structure.submenu.children.unshift({type:"container",style:{flexShrink:1},classes:["mistvideo-column"],children:[{if:function(){return this.playerName&&this.source},then:{type:"container",classes:["mistvideo-description","mistvideo-displayCombo"],style:{display:"block"},children:[{type:"playername",style:{display:"inline"}},{type:"text",text:"is playing",style:{margin:"0 0.2em"}},{type:"mimetype"}]}},{type:"log"},{type:"decodingIssues"},{type:"container",classes:["mistvideo-column","mistvideo-devcontrols"],style:{"font-size":"0.9em"},children:[{type:"text",text:"Player control"},{type:"container",classes:["mistvideo-devbuttons"],style:{"flex-wrap":"wrap"},children:[{type:"button",title:"Build MistVideo again",label:"MistVideo.reload();",onclick:function(){this.reload("Dev-reload button clicked.")}},{type:"button",title:"Switch to the next available player and source combination",label:"MistVideo.nextCombo();",onclick:function(){this.nextCombo()}}]},{type:"forcePlayer"},{type:"forceType"}]}]});var mistplayers={};function MistPlayer(){}function mistPlay(e,t){return new MistVideo(e,t)}function MistVideo(e,t){var i=this;function r(e){if("meta"in e&&"tracks"in e.meta){var t=e.meta.tracks;for(var i in t)if("video"==t[i].type)return!0}return!1}function n(e){if(i.player&&i.player.api&&i.player.api.unload&&(i.log("Received new stream info while a player was already loaded: unloading player"),i.player.api.unload()),i.info=e,i.info.updated=new Date,MistUtil.event.send("haveStreamInfo",e,i.options.target),i.log("Stream info was loaded succesfully."),"error"in e){var n=e.error;return"on_error"in e?(i.log(n),n=e.on_error):"perc"in e&&(n+=" ("+Math.round(10*e.perc)/10+"%)"),void i.showError(n,{reload:!0,hideTitle:!0})}if(i.calcSize=function(e){e||(e={width:!1,height:!1});var r=e.width||!(!("width"in t)||!t.width)&&t.width,n=e.height||!(!("height"in t)||!t.height)&&t.height;if(this.info&&"source"in this.info)if(this.info.hasVideo&&"audio"!=this.source.type.split("/")[1]){if(!r||!n){var a=i.info.width/i.info.height;if(r||n)r?n=r/a:r=n*a;else{var s="maxwidth"in t&&t.maxwidth?t.maxwidth:window.innerWidth,o="maxheight"in t&&t.maxheight?t.maxheight:window.innerHeight;r=i.info.width,n=i.info.height;function l(e){r/=e,n/=e}r<426&&l(r/426),n<240&&l(n/240),s&&r>s&&l(r/s),o&&n>o&&l(n/o)}}}else r||(r=480),n||(n=42);else r=640,n=480;return this.size={width:Math.round(r),height:Math.round(n)},this.size},e.hasVideo=r(e),"live"==e.type){var a=0;for(var s in i.info.meta.tracks)a=Math.max(a,i.info.meta.tracks[s].lastms);e.lastms=a}else{var o=i.resumeTime;if(o){var l=function(){i.player&&i.player.api&&(i.player.api.currentTime=o),this.removeEventListener("initialized",l)};MistUtil.event.addListener(i.options.target,"initialized",l)}}i.options.ABR_bitrate&&i.options.ABR_resize&&i.info&&!i.info.selver&&(i.options.ABR_bitrate=!1),i.choosePlayer()?(i.reporting&&i.reporting.report({player:i.playerName,sourceType:i.source.type,sourceUrl:i.source.url,pageUrl:location.href}),i.player=new mistplayers[i.playerName].player,i.player.onreadylist=[],i.player.onready=function(e){this.onreadylist.push(e)},i.player.build(i,(function(e){if(i.log("Building new player"),i.container.removeAttribute("data-loading"),i.video=e,i.reporting&&i.reporting.init(),"api"in i.player){i.monitor={MistVideo:i,delay:1,averagingSteps:20,threshold:function(){return"webrtc"==this.MistVideo.source.type?.95:.75},init:function(){if(!this.vars||!this.vars.active){this.MistVideo.log("Enabling monitor"),this.vars={values:[],score:!1,active:!0};var e=this;!function t(){e.vars&&e.vars.active&&(e.vars.timer=e.MistVideo.timers.start((function(){var i=e.calcScore();!1!==i&&e.check(i)&&e.action(),t()}),1e3*e.delay))}()}},destroy:function(){this.vars&&this.vars.active&&(this.MistVideo.log("Disabling monitor"),this.MistVideo.timers.stop(this.vars.timer),delete this.vars)},reset:function(){this.vars&&this.vars.active?(this.MistVideo.log("Resetting monitor"),this.vars.values=[]):this.init()},calcScore:function(){var e=this.vars.values;if(e.push(this.getValue()),e.length<=1)return!1;var t=this.valueToScore(e[0],e[e.length-1]);return e.length>this.averagingSteps&&e.shift(),t=Math.max(t,e[e.length-1].score),this.vars.score=t,i.reporting&&i.reporting.stats.set("playbackScore",Math.round(10*t)/10),t},valueToScore:function(e,t){var i=1;return"player"in this.MistVideo&&"api"in this.MistVideo.player&&"playbackRate"in this.MistVideo.player.api&&(i=this.MistVideo.player.api.playbackRate),(t.video-e.video)/(t.clock-e.clock)/i},getValue:function(){var e={clock:.001*(new Date).getTime(),video:this.MistVideo.player.api.currentTime};return this.vars.values.length&&(e.score=this.valueToScore(this.vars.values[this.vars.values.length-1],e)),e},check:function(e){return!(this.vars.values.length<.5*this.averagingSteps)&&(e=e.socket.CLOSING&&e.init(),this.send_queue.push(t)};var t=!1;if(e.socket.setTracks=function(){e.s({type:"tracks",meta:MistUtil.object.keys(e.subscriptions).join(",")})},e.socket.onopen=function(){for(i.log("Metadata socket opened"),e.socket.setTracks(),1!=i.player.api.playbackRate&&e.s({type:"set_speed",play_rate:i.player.api.playbackRate}),e.s({type:"seek",seek_time:Math.round(1e3*i.player.api.currentTime),ff_to:Math.round(1e3*(i.player.api.currentTime+5))}),e.socket.addEventListener("message",(function(r){if(r.data){var n=JSON.parse(r.data);if(n){if("time"in n&&"track"in n&&"data"in n){var a=!1;if("all"in e.subscriptions&&(e.subscriptions.all.buffer.push(n),a=!0),n.track in e.subscriptions&&(e.subscriptions[n.track].buffer.push(n),a=!0),a)if(e.checktimer){var s=i.timers.list[e.checktimer];if(s)s>(new Date).getTime()+n.time-1e3*i.player.api.currentTime&&(i.log("The metadata socket received a message that should be displayed sooner than the current check time; resetting"),i.timers.stop(e.checktimer),e.checktimer=null,e.check())}else e.check()}if("type"in n)switch(n.type){case"on_time":!t&&n.data.current>1e3*(i.player.api.currentTime+30)&&(t=!0,e.s({type:"hold"}),i.log("Pausing metadata buffer because it is very far ahead, checking again in 5 seconds: "+n.data.current+" > "+1e3*i.player.api.currentTime),i.timers.start((function(){i.player.api.paused||e.s({type:"play"}),e.s({type:"fast_forward",ff_to:Math.round(1e3*(i.player.api.currentTime+5))})}),5e3));break;case"seek":for(var o in e.subscriptions)e.subscriptions[o].buffer=[];i.log("Cleared metadata buffer after completed seek"),e.checktimer&&(i.timers.stop(e.checktimer),e.checktimer=null)}}else i.log("Subtitle websocket received invalid message.")}else i.log("Subtitle websocket received empty message.")})),e.socket.onclose=function(){i.log("Metadata socket closed")};e.send_queue.length&&e.socket.readyState==e.socket.OPEN;)e.s(e.send_queue.shift())},!("seeked"in this.listeners)){var r=(new Date).getTime();e.check=function(){if(e.checktimer&&(i.timers.stop(e.checktimer),e.checktimer=null),!i.player.api.paused){var t=null;for(var n in e.subscriptions){for(var a=e.subscriptions[n].buffer;a.length&&a[0].time<=1e3*i.player.api.currentTime;){var s=a.shift();if(!(s.time<1e3*(i.player.api.currentTime-5)))for(var o in e.subscriptions[n].callbacks)e.subscriptions[n].callbacks[o].call(i,s)}a.length&&(t=Math.min(null===t?1e9:t,a[0].time))}var l=(new Date).getTime();if(l>r+5e3&&(e.s({type:"fast_forward",ff_to:Math.round(1e3*(i.player.api.currentTime+5))}),r=l),t){var c=t-1e3*i.player.api.currentTime;e.checktimer=i.timers.start((function(){e.check()}),c)}}},this.listeners.seeked=MistUtil.event.addListener(i.video,"seeked",(function(){for(var t in e.subscriptions)e.subscriptions[t].buffer=[];e.s({type:"seek",seek_time:Math.round(1e3*i.player.api.currentTime),ff_to:Math.round(1e3*(i.player.api.currentTime+5))}),r=(new Date).getTime()})),this.listeners.pause=MistUtil.event.addListener(i.video,"pause",(function(){e.s({type:"hold"}),i.timers.stop(e.checktimer),e.checktimer=null})),this.listeners.playing=MistUtil.event.addListener(i.video,"playing",(function(){e.s({type:"play"}),e.checktimer||e.check()})),this.listeners.ratechange=MistUtil.event.addListener(i.video,"ratechange",(function(){e.s({type:"set_speed",play_rate:i.player.api.playbackRate})}))}e.socket.readyState==e.socket.OPEN&&e.socket.onopen()},destroy:function(){for(var e in i.log("Closing metadata socket.."),this.socket.close(),this.socket=null,this.subscriptions={},this.listeners)MistUtil.event.removeListener(this.listeners[e]);this.listeners={}},add:function(e,t){"function"!=typeof e||t||(t=e,e="all"),"function"==typeof t&&(e in this.subscriptions||(this.subscriptions[e]={buffer:[],callbacks:[]}),this.subscriptions[e].callbacks.push(t),null===this.socket?this.init():this.socket.setTracks())},remove:function(e,t){if(e in this.subscriptions){for(var i in this.subscriptions[e].callbacks)if(t==this.subscriptions[e].callbacks[i]){this.subscriptions[e].callbacks.splice(i,1);break}0==this.subscriptions[e].callbacks.length&&(delete this.subscriptions[e],MistUtil.object.keys(this.subscriptions).length?this.socket.setTracks():this.destroy())}}},"function"==typeof t.subscribeToMetaTrack&&(t.subscribeToMetaTrack=[["all",t.subscribeToMetaTrack]]),t.subscribeToMetaTrack.length))for(var n in"object"!=typeof t.subscribeToMetaTrack[0]&&(t.subscribeToMetaTrack=[t.subscribeToMetaTrack]),t.subscribeToMetaTrack)i.metaTrackSubscriptions.add.apply(i.metaTrackSubscriptions,t.subscribeToMetaTrack[n])}}MistUtil.empty(i.options.target),new MistSkin(i),i.container=new MistUI(i),i.options.target.appendChild(i.container),i.container.setAttribute("data-loading",""),i.video.p=i.player;r=["abort","canplay","canplaythrough",,"emptied","ended","loadeddata","loadedmetadata","loadstart","pause","play","playing","ratechange","seeked","seeking","stalled","volumechange","waiting","metaUpdate_tracks","resizing"];for(var n in r)MistUtil.event.addListener(i.video,r[n],(function(e){e.message&&"chromecast"==e.message||i.log("Player event fired: "+e.type)}));if(MistUtil.event.addListener(i.video,"error",(function(e){var t;if("player"in i&&"api"in i.player&&"error"in i.player.api&&i.player.api.error)if("message"in i.player.api.error)t=i.player.api.error.message;else if("code"in i.player.api.error&&i.player.api.error instanceof MediaError){var r={1:"MEDIA_ERR_ABORTED: The fetching of the associated resource was aborted by the user's request.",2:"MEDIA_ERR_NETWORK: Some kind of network error occurred which prevented the media from being successfully fetched, despite having previously been available.",3:"MEDIA_ERR_DECODE: Despite having previously been determined to be usable, an error occurred while trying to decode the media resource, resulting in an error.",4:"MEDIA_ERR_SRC_NOT_SUPPORTED: The associated resource or media provider object (such as a MediaStream) has been found to be unsuitable."};t=i.player.api.error.code in r?r[i.player.api.error.code]:"MediaError code "+i.player.api.error.code}else"string"!=typeof(t=i.player.api.error)&&(t=JSON.stringify(t));else t="An error was encountered.";"Stream is online"==i.state?i.showError(t):(i.log(t,"error"),i.showError(i.state,{polling:!0}))})),"setSize"in i.player&&(i.player.videocontainer=i.video.parentNode,i.video.currentTarget=i.options.target,MistUtil.class.has(i.options.target,"mistvideo-secondaryVideo")||(i.player.resizeAll=function(){function e(t,i){if(t.video.currentTarget==i)return t.video;if(t.secondary)for(var r=0;r3600&&(t.reloadDelay/=1e3,this.log("A reloadDelay of more than an hour was set: assuming milliseconds were intended. ReloadDelay is now "+t.reloadDelay+"s")),new MistSkin(this),this.checkCombo=function(e,t){e||(e={}),e=MistUtil.object.extend(MistUtil.object.extend({},this.options),e);var r,n,a=!1;for(var s in e.forceSource?(r=[i.info.source[e.forceSource]],i.log("Forcing source "+e.forceSource+": "+r[0].type+" @ "+r[0].url)):e.forceType?(r=i.info.source.filter((function(t){return t.type==e.forceType})),i.log("Forcing type "+e.forceType)):r=i.info.source,mistplayers)mistplayers[s].shortname=s;e.forcePlayer&&mistplayers[e.forcePlayer]?(n=[mistplayers[e.forcePlayer]],i.log("Forcing player "+e.forcePlayer)):n=MistUtil.object.values(mistplayers),r=[].concat(r);var o={first:"source",source:[function(e){return"origIndex"in e||(e.origIndex=i.info.source.indexOf(e)),e.origIndex}],player:[{priority:1}]},l={inner:"player",outer:"source"};if(e.forcePriority){if("source"in e.forcePriority){if(!(e.forcePriority.source instanceof Array))throw"forcePriority.source is not an array.";o.source=e.forcePriority.source.concat(o.source),MistUtil.array.multiSort(r,o.source)}if("player"in e.forcePriority){if(!(e.forcePriority.player instanceof Array))throw"forcePriority.player is not an array.";o.player=e.forcePriority.player.concat(o.player),MistUtil.array.multiSort(n,o.player)}"first"in e.forcePriority&&(o.first=e.forcePriority.first),"player"==o.first&&(l.outer="player",l.inner="source")}var c={player:{list:n,current:!1},source:{list:r,current:!1}};if(e.startCombo){e.startCombo.started={player:!1,source:!1};for(s=0;s=2))for(var v in c[l.inner].list)if(c[l.inner].current=v,!(d(l.inner)>=1)){a=c.source.list[c.source.current];var y=c.player.list[c.player.current].shortname,g=mistplayers[y];if(g.isMimeSupported(a.type)){var b=g.isBrowserSupported(a.type,a,i);if(b){var k=p(b);if(k>u.score&&(t||i.log("Found a "+(u.score?"better":"working")+" combo: "+g.name+" with "+a.url+" (Score: "+k+")"),(u={score:k,player:y,source:a,source_index:c.source.current}).score==m))return u}}}return!!u.score&&u},this.choosePlayer=function(){i.log("Checking available players..");var e=this.checkCombo();if(!e)return!1;var t=mistplayers[e.player],r=e.source;return i.log("Selected: "+t.name+" with "+r.type+" @ "+r.url),i.playerName=e.player,(r=MistUtil.object.extend({},r)).index=e.source_index,r.url=i.urlappend(r.url),i.source=r,MistUtil.event.send("comboChosen","Player/source combination selected",i.options.target),!0},i.calcSize=function(){return{width:640,height:480}},MistUtil.empty(i.options.target),new MistSkin(i),i.container=new MistUI(i,i.skin.structure.placeholder),i.options.target.appendChild(i.container),i.container.setAttribute("data-loading",""),"WebSocket"in window){!function e(){i.log("Opening stream status stream through websocket..");var t,s=i.options.host.replace(/^http/i,"ws");s=MistUtil.http.url.addParam(i.urlappend(s+"/json_"+encodeURIComponent(i.stream)+".js"),{metaeverywhere:1,inclzero:1});try{t=new WebSocket(s)}catch(e){return i.log("Error while attempting to open WebSocket to "+s),void a()}i.socket=t,t.die=!1,t.destroy=function(){this.die=!0,i.reporting&&(i.reporting.reportStats(),i.reporting=!1),this.onclose=function(){},this.close()},t.timeOut=i.timers.start((function(){t.readyState<=1&&(t.destroy(),a())}),5e3),t.onopen=function(e){this.wasConnected=!0,i.reporting||(i.reporting={stats:{set:function(e,t){this.d[e]=t},add:function(e,t){void 0===t&&(t=1),this.d[e]+=t},d:{nWaiting:0,timeWaiting:0,nStalled:0,timeStalled:0,timeUnpaused:0,nError:0,nLog:0,videoHeight:null,videoWidth:null,playerHeight:null,playerWidth:null},last:{firstPlayback:null,nWaiting:0,timeWaiting:0,nStalled:0,timeStalled:0,timeUnpaused:0,nError:0,lastError:null,playbackScore:1,nLog:0,autoplay:null,videoHeight:null,videoWidth:null,playerHeight:null,playerWidth:null}},report:function(e){1==i.socket.readyState&&i.socket.send(JSON.stringify(e))},reportStats:function(){var e={},t=!1,r=i.logs.slice(this.stats.last.nLog);for(var n in this.stats.d)this.stats.d[n]!=this.stats.last[n]&&(e[n]=this.stats.d[n],this.stats.last[n]=e[n],t=!0);if(t){if(r.length)for(var n in e.logs=[],r)e.logs.push(r[n].message);this.report(e)}i.timers.start((function(){i.reporting&&i.reporting.reportStats()}),5e3)},init:function(){var e=i.video,t=MistUtil.event.addListener(e,"playing",(function(){i.reporting.stats.set("firstPlayback",(new Date).getTime()-i.bootMs),MistUtil.event.removeListener(t)}));if(MistUtil.event.addListener(e,"waiting",(function(){i&&i.reporting&&i.reporting.stats.add("nWaiting")})),MistUtil.event.addListener(e,"stalled",(function(){i&&i.reporting&&i.reporting.stats.add("nStalled")})),MistUtil.event.addListener(i.options.target,"error",(function(e){i&&i.reporting&&(i.reporting.stats.add("nError"),i.reporting.stats.set("lastError",e.message))}),e),Object&&Object.defineProperty){var r=0,n=!1,a=0,s=!1,o=0,l=!1,c=i.reporting.stats.d;Object.defineProperty(c,"timeWaiting",{get:function(){return r+(n?(new Date).getTime()-n:0)}}),Object.defineProperty(c,"timeStalled",{get:function(){return a+(s?(new Date).getTime()-s:0)}}),Object.defineProperty(c,"timeUnpaused",{get:function(){return o+(l?(new Date).getTime()-l:0)}}),Object.defineProperty(c,"nLog",{get:function(){return i.logs.length}}),Object.defineProperty(c,"videoHeight",{get:function(){return i.video?i.video.videoHeight:null}}),Object.defineProperty(c,"videoWidth",{get:function(){return i.video?i.video.videoWidth:null}}),Object.defineProperty(c,"playerHeight",{get:function(){return i.video?i.video.clientHeight:null}}),Object.defineProperty(c,"playerWidth",{get:function(){return i.video?i.video.clientWidth:null}}),MistUtil.event.addListener(e,"waiting",(function(){r=c.timeWaiting,n=(new Date).getTime()})),MistUtil.event.addListener(e,"stalled",(function(){a=c.timeStalled,s=(new Date).getTime()}));var d=["playing","pause"];for(var u in d)MistUtil.event.addListener(e,d[u],(function(){r=c.timeWaiting,a=c.timeStalled,n=!1,s=!1}));MistUtil.event.addListener(e,"playing",(function(){o=c.timeUnpaused,l=(new Date).getTime()})),MistUtil.event.addListener(e,"pause",(function(){o=c.timeUnpaused,l=!1}))}this.reportStats()}})},t.onclose=function(t){if(!this.die)return this.wasConnected?(i.log("Reopening websocket.."),void e()):void a()};var o=!1;t.addEventListener("message",(function(e){t.timeOut&&(i.timers.stop(t.timeOut),t.timeOut=!1);var a=JSON.parse(e.data);if(a||i.showError("Error while parsing stream status stream. Obtained: "+e.data.toString(),{reload:!0}),"error"in a){var s;e=a.error;switch("on_error"in a?(i.log(e),e=a.on_error):"perc"in a&&(e+=" ("+Math.round(10*a.perc)/10+"%)"),i.state=a.error,a.error){case"Stream is offline":i.info=!1,i.player&&i.player.api&&i.player.api.currentTime&&(i.resumeTime=i.player.api.currentTime);case"Stream is initializing":case"Stream is booting":case"Stream is waiting for data":case"Stream is shutting down":case"Stream status is invalid?!":if(i.player&&i.player.api&&!i.player.api.paused)return i.log(a.error,"error"),o||(o=MistUtil.event.addListener(i.video,"ended",(function(){i.showError(a.error,{polling:!0})}))),void(o=MistUtil.event.addListener(i.video,"waiting",(function(){i.showError(a.error,{polling:!0})})));s={polling:!0};break;default:s={reload:!0}}i.showError(e,s)}else{if(i.state="Stream is online",i.clearError(),o&&MistUtil.event.removeListener(o),!i.info)return void n(a);var l=function e(t,i){if(t==i)return!1;if("object"==typeof t&&void 0!==i){var r={};for(var n in t)if(!(MistUtil.array.indexOf(["lastms","hasVideo"],n)>=0)){var a=e(t[n],i[n]);a&&(r[n]=!0===a?[t[n],i[n]]:a)}for(var n in i)MistUtil.array.indexOf(["lastms","hasVideo"],n)>=0||n in t||(r[n]=[t[n],i[n]]);return!!MistUtil.object.keys(r).length&&r}return!0}(a,i.info);if(l){if("source"in l&&"error"in i.info)return void i.reload("Reloading, stream info has error");i.info=MistUtil.object.extend(i.info,a),i.info.updated=new Date;var c=!1;for(var d in l)switch(d){case"meta":for(var u in l[d])if("tracks"===u)i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",a,i.video);break;case"width":case"height":c=!0}c&&i.player.resize()}else i.log("Metachange: no differences detected")}}))}()}else a();return this.unload=function(e){if(!this.destroyed){for(var t in this.log("Unloading.."),this.destroyed=!0,this.timers.stop("all"),this.errorListeners){var r=this.errorListeners[t];if(r.src in MistUtil.scripts.list){var n=MistUtil.array.indexOf(MistUtil.scripts.list[r.src].subscribers);n>=0&&MistUtil.scripts.list[r.src].subscribers.splice(n,1)}}if("monitor"in i&&"destroy"in i.monitor&&i.monitor.destroy(),this.socket&&(this.reporting&&(this.reporting.reportStats(),this.reporting.report({unload:e||null})),this.socket.destroy()),this.player&&this.player.api&&("pause"in this.player.api&&this.player.api.pause(),"setSource"in this.player.api&&this.player.api.setSource(""),"unload"in this.player.api))try{this.player.api.unload()}catch(a){i.log("Error while unloading player: "+a.message)}if(this.metaTrackSubscriptions&&this.metaTrackSubscriptions.socket&&this.metaTrackSubscriptions.destroy(),this.UI&&this.UI.elements)for(var t in this.UI.elements){var a=this.UI.elements[t];if("attachedListeners"in a)for(var t in a.attachedListeners)MistUtil.event.removeListener(a.attachedListeners[t]);a.parentNode&&a.parentNode.removeChild(a)}this.video&&MistUtil.empty(this.video),"container"in this&&(MistUtil.empty(this.container),delete this.container),MistUtil.empty(this.options.target),delete this.video}},this.reload=function(e){var t="player"in this&&"api"in this.player&&this.player.api.currentTime;this.unload(e);var r=mistPlay(this.stream,this.options);if(t&&"live"!=this.info.type){var n=function(){r.player&&r.player.api&&(r.player.api.currentTime=t),this.removeEventListener("initialized",n)};MistUtil.event.addListener(this.options.target,"initialized",n)}return i},this.nextCombo=function(){var e=!1;"player"in this&&"api"in this.player&&(e=this.player.api.currentTime);var t={source:this.source.index,player:this.playerName};if(!this.checkCombo({startCombo:t},!0)){if(!this.checkCombo({startCombo:!1},!0))return;t=!1}this.unload("nextCombo");var r=this.options;if(r.startCombo=t,i=mistPlay(this.stream,r),e&&isFinite(e)&&"live"!=this.info.type){var n=function(){"player"in i&&"api"in i.player&&(i.player.api.currentTime=e),this.removeEventListener("initialized",n)};MistUtil.event.addListener(r.target,"initialized",n)}},this.onPlayerBuilt=function(){},t.MistVideoObject&&(t.MistVideoObject.reference=this),this} \ No newline at end of file diff --git a/embed/skins.js b/embed/skins.js index 95c2ff5a..0ac851f3 100644 --- a/embed/skins.js +++ b/embed/skins.js @@ -2555,7 +2555,6 @@ MistSkins["default"] = { if (!window.chrome || !window.chrome.cast || !window.chrome.cast.isAvailable || (tries > 5)) { if (ele.parentNode) { ele.parentNode.removeChild(ele); } MistVideo.log("Chromecast is not supported"); - console.warn(chrome,chrome.cast,chrome.cast ? chrome.cast.isAvailable : undefined,cast); return; } diff --git a/lsp/footer.html b/lsp/footer.html index 8cef7e6e..8fcac986 100644 --- a/lsp/footer.html +++ b/lsp/footer.html @@ -1,12 +1,14 @@
+

Management Interface