diff --git a/embed/min/player.js b/embed/min/player.js index 9ff8e1bc..acb01a8f 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},ucFirst:function(e){return e.charAt(0).toUpperCase()+e.slice(1)},number:function(e){if(isNaN(Number(e))||0==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){if(isNaN(Number(e)))return e;var t=["bytes","KB","MB","GB","TB","PB"];if(0==e)unit=t[0];else{var i=Math.floor(Math.log(Math.abs(e))/Math.log(1024));i<0?unit=t[0]:(e/=Math.pow(1024,i),unit=t[i])}return this.number(e)+unit},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";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]?e[r]=t[r]:(r in e||(MistUtil.array.is(t[r])?e[r]=[]:e[r]={}),this.extend(e[r],t[r],!0));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;i<e.length;i++)if(e[i]==t)return i;return-1},is:function(e){return"isArray"in Array?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)},multiSort:function(e,t){var i=function(e,t){return isNaN(e)||isNaN(t)?e.localeCompare(t):Math.sign(e-t)};if(!t.length)return e.sort(i);function r(e,t){function i(e,t,i){if(!(t in e))throw"Invalid sorting rule: "+JSON.stringify([t,i])+'. "'+t+'" is not a key of '+JSON.stringify(e);if("number"==typeof i&&t in e)return e[t]*i;var r=i.indexOf(e[t]);return r>=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("?")},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;s<n[a].match(/{/g).length;){var o=e.match(/@@#@@([^}]*})/);e=e.replace(o[0],"@@#@@"),n[a]+=o[1],s++}e=e.replace("@@#@@","@@@@")}for(var a in e=e.replace(/[^@]*?{[^]*?}/g,function(e){var r=e.split("{"),n=r[0].split(","),a="{"+r.slice(1).join("}");for(var s in n){n[s]=n[s].trim();var o="."+t+n[s];i&&(o+=",\n."+t+" "+n[s]),n[s]=o}return"\n"+n+" "+a}),n)e=e.replace(/@@@@/,n[a]);if(!r)return e;r.textContent=e}},empty:function(e){for(;e.lastChild;){if(e.lastChild.lastChild&&this.empty(e.lastChild),"attachedListeners"in e.lastChild)for(var t in e.lastChild.attachedListeners)MistUtil.event.removeListener(e.lastChild.attachedListeners[t]);e.removeChild(e.lastChild)}},event:{send:function(e,t,i){try{return(r=new Event(e,{bubbles:!0,cancelable:!0})).message=t,i.dispatchEvent(r),r}catch(n){try{var r;return(r=document.createEvent("Event")).initEvent(e,!0,!0),r.message=t,i.dispatchEvent(r),r}catch(e){return!1}}return!0},addListener:function(e,t,i,r){e.addEventListener(t,i),r||(r=e),"attachedListeners"in r||(r.attachedListeners=[]);var n={element:e,type:t,callback:i};return r.attachedListeners.push(n),n},removeListener:function(e){e.element.removeEventListener(e.type,e.callback)}},scripts:{list:{},insert:function(e,t,i){var r=this;if(i&&i.errorListeners.push({src:e,onevent:t}),e in this.list)return this.list[e].subscribers.push(t.onerror),void("onload"in t&&(this.list[e].tag.hasLoaded?t.onload():MistUtil.event.addListener(this.list[e].tag,"load",t.onload)));var n=document.createElement("script");n.hasLoaded=!1,n.setAttribute("src",e),n.setAttribute("crossorigin","anonymous"),document.head.appendChild(n),n.onerror=function(e){t.onerror(e)},n.onload=function(e){this.hasLoaded=!0,i.destroyed||t.onload(e)},n.addEventListener("error",function(e){t.onerror(e)});var a=!1;return window.onerror&&(a=window.onerror),window.onerror=function(i,n,s,o,l){if(a&&a.apply(this,arguments),n==e)for(var c in t.onerror(l),r.list[e].subscribers)r.list[e].subscribers[c](l)},this.list[e]={subscribers:[t.onerror],tag:n},n}},tracks:{parse:function(e){var t={};for(var i in e){var r=MistUtil.object.extend({},e[i]);"meta"==r.type&&(r.type=r.codec,r.codec="meta"),r.type in t||(t[r.type]={}),t[r.type]["idx"in r?r.idx:r.trackid]=r;var n={};for(var a in r)switch(a){case"width":n[a]=r.width+"×"+r.height;break;case"bps":if("meta"==r.codec)continue;var s;if(r.bps>0)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(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}},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;s<e.y.length;s++){var o=e.y[s]-a;a=e.y[s],e.y[s]=o}var l=[],c={x:{min:e.x[0]-n,max:e.x[0]-n},y:{min:-1*e.y[0],max:-1*e.y[0]}};function d(e,t){if(arguments.length)c.x.min=Math.min(c.x.min,e),c.x.max=Math.max(c.x.max,e),c.y.min=Math.min(c.y.min,-1*t),c.y.max=Math.max(c.y.max,-1*t);else{var i=l[0].split(",");c={x:{min:i[0],max:i[0]},y:{min:i[1],max:i[1]}};for(var r=1;r<l.length;r++){d((i=l[r].split(","))[0],-1*i[1])}}}l.push([e.x[0]-n,-1*e.y[0]].join(","));for(s=1;s<e.y.length;s++)d(e.x[s]-n,-1*e.y[s]),l.push("L "+[e.x[s]-n,-1*e.y[s]].join(","));var u=document.createElementNS(i,"defs");r.appendChild(u);var p=document.createElementNS(i,"linearGradient");function h(){"x"in t&&("min"in t.x&&(c.x.min=t.x.min),"max"in t.x&&(c.x.max=t.x.max),"count"in t.x&&(c.x.min=c.x.max-t.x.count)),"y"in t&&("min"in t.y&&(c.y.min=-1*t.y.max),"max"in t.y&&(c.y.max=-1*t.y.min)),r.setAttributeNS(null,"viewBox",[c.x.min,c.y.min,c.x.max-c.x.min,c.y.max-c.y.min].join(" ")),p.setAttributeNS(null,"x1",0),p.setAttributeNS(null,"x2",0),t.reverseGradient?(p.setAttributeNS(null,"y1",c.y.max),p.setAttributeNS(null,"y2",c.y.min)):(p.setAttributeNS(null,"y1",c.y.min),p.setAttributeNS(null,"y2",c.y.max))}u.appendChild(p),p.setAttributeNS(null,"id",MistUtil.createUnique()),p.setAttributeNS(null,"gradientUnits","userSpaceOnUse"),p.innerHTML+='<stop offset="0" stop-color="green"/>',p.innerHTML+='<stop offset="0.33" stop-color="yellow"/>',p.innerHTML+='<stop offset="0.66" stop-color="orange"/>',p.innerHTML+='<stop offset="1" stop-color="red"/>',h();var m=document.createElementNS(i,"path");return r.appendChild(m),m.setAttributeNS(null,"stroke-width","0.1"),m.setAttributeNS(null,"fill","none"),m.setAttributeNS(null,"stroke","url(#"+p.getAttribute("id")+")"),m.setAttributeNS(null,"d","M"+l.join(" L")),m.addData=function(e){if(!isNaN(e.y)){if(t.differentiate){var i=e.y-a;a=e.y,e.y=i}l.push([e.x-n,-1*e.y].join(",")),t.x&&t.x.count&&l.length>t.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]}};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+='<svg viewBox="0 0 '+a.size.width+" "+a.size.height+'"'+("width"in i?' width="'+i.width+'"':"")+("height"in i?' height="'+i.height+'"':"")+' class="mist icon '+t+'">',s+='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100%" width="100%">',s+=n,s+="</svg>",s+="</svg>";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",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:"video"},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"},{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>200||!this.info.hasVideo||"audio"==this.source.type.split("/")[1]},then:{type:"container",children:[{type:"loop",classes:["mistvideo-pointer"]},{type:"fullscreen",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<=200},then:{type:"container",classes:["mistvideo-center"],children:[{type:"loop",classes:["mistvideo-pointer"]},{type:"fullscreen",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:'<path d="M6.26004984594 3.0550109625C5.27445051914 3.68940862462 4.67905105702 4.78142391497 4.67968264562 5.95354422781C4.67968264562 5.95354422781 4.70004942312 39.0717540916 4.70004942312 39.0717540916C4.70302341604 40.3033886636 5.36331656075 41.439734231 6.43188211452 42.0521884912C7.50044766829 42.6646427515 8.81469531629 42.6600161659 9.87892235656 42.0400537716C9.87892235656 42.0400537716 38.5612768409 25.4802882606 38.5612768409 25.4802882606C39.6181165777 24.8606067582 40.2663250096 23.7262617523 40.2636734301 22.5011460995C40.2610218505 21.2760304467 39.6079092743 20.1445019555 38.5483970356 19.5294009803C38.5483970356 19.5294009803 9.84567577375 2.9709566275 9.84567577375 2.9709566275C8.72898008118 2.32550764609 7.34527425735 2.35794451351 6.26004984594 3.0550109625C6.26004984594 3.0550109625 6.26004984594 3.0550109625 6.26004984594 3.0550109625" class="fill" />'},largeplay:{size:45,svg:'<path d="M6.26004984594 3.0550109625C5.27445051914 3.68940862462 4.67905105702 4.78142391497 4.67968264562 5.95354422781C4.67968264562 5.95354422781 4.70004942312 39.0717540916 4.70004942312 39.0717540916C4.70302341604 40.3033886636 5.36331656075 41.439734231 6.43188211452 42.0521884912C7.50044766829 42.6646427515 8.81469531629 42.6600161659 9.87892235656 42.0400537716C9.87892235656 42.0400537716 38.5612768409 25.4802882606 38.5612768409 25.4802882606C39.6181165777 24.8606067582 40.2663250096 23.7262617523 40.2636734301 22.5011460995C40.2610218505 21.2760304467 39.6079092743 20.1445019555 38.5483970356 19.5294009803C38.5483970356 19.5294009803 9.84567577375 2.9709566275 9.84567577375 2.9709566275C8.72898008118 2.32550764609 7.34527425735 2.35794451351 6.26004984594 3.0550109625C6.26004984594 3.0550109625 6.26004984594 3.0550109625 6.26004984594 3.0550109625" class="stroke" />'},pause:{size:45,svg:'<g><path d="m 7.5,38.531275 a 4.0011916,4.0011916 0 0 0 3.749999,3.96873 l 2.2812501,0 a 4.0011916,4.0011916 0 0 0 3.96875,-3.75003 l 0,-32.28123 a 4.0011916,4.0011916 0 0 0 -3.75,-3.96875 l -2.2812501,0 a 4.0011916,4.0011916 0 0 0 -3.968749,3.75 l 0,32.28128 z" class="fill" /><path d="m 27.5,38.531275 a 4.0011916,4.0011916 0 0 0 3.75,3.9687 l 2.28125,0 a 4.0011916,4.0011916 0 0 0 3.96875,-3.75 l 0,-32.28126 a 4.0011916,4.0011916 0 0 0 -3.75,-3.96875 l -2.28125,0 a 4.0011916,4.0011916 0 0 0 -3.96875,3.75 l 0,32.28131 z" class="fill" /></g>'},speaker:{size:45,svg:'<path d="m 32.737813,5.2037363 c -1.832447,-1.10124 -4.200687,-0.8622 -5.771871,0.77112 0,0 -7.738819,8.0443797 -7.738819,8.0443797 0,0 -3.417976,0 -3.417976,0 -1.953668,0 -3.54696,1.65618 -3.54696,3.68694 0,0 0,9.58644 0,9.58644 0,2.03094 1.593292,3.68712 3.54696,3.68712 0,0 3.417976,0 3.417976,0 0,0 7.738819,8.04474 7.738819,8.04474 1.572104,1.63404 3.938942,1.8747 5.771871,0.77076 0,0 0,-34.5914997 0,-34.5914997 z" class="stroke semiFill toggle" />'},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return'<defs><mask id="'+e+'"><path d="m6.202 33.254 86.029-28.394c2.6348-0.86966 4.7433 0.77359 4.7433 3.3092v28.617c0 1.9819-1.6122 3.5773-3.6147 3.5773h-86.75c-4.3249 0-5.0634-5.5287-0.40598-7.1098" fill="#fff" /></mask></defs><rect mask="url(#'+e+')" class="slider horizontal semiFill" width="100%" height="100%" /><path d="m6.202 33.254 86.029-28.394c2.6348-0.86966 4.7433 0.77359 4.7433 3.3092v28.617c0 1.9819-1.6122 3.5773-3.6147 3.5773h-86.75c-4.3249 0-5.0634-5.5287-0.40598-7.1098" class="stroke" /><rect x="0" y="0" width="100%" height="100%" fill="rgba(0,0,0,0.001)"/>'}},muted:{size:45,svg:'<g class="stroke" stroke-linecap="round" vector-effect="none" stroke-width="2"><path d="m25.587 5.2036c-1.8324-1.1012-4.2007-0.8622-5.7719 0.77112 0 0-7.7388 8.0444-7.7388 8.0444h-3.418c-1.9537 0-3.547 1.6562-3.547 3.6869v9.5864c0 2.0309 1.5933 3.6871 3.547 3.6871h3.418s7.7388 8.0447 7.7388 8.0447c1.5721 1.634 3.9389 1.8747 5.7719 0.77076v-34.591 z" /><path d="m30.032 27.86 9.8517-9.8517"/><path d="m30.032 18.008 9.8517 9.8517"/></g>'},fullscreen:{size:45,svg:'<path d="m2.5 10.928v8.5898l4.9023-2.8008 9.6172 5.7832-9.6172 5.7832-4.9023-2.8008v8.5898h15.031l-4.9004-2.8008 9.8691-5.6387 9.8691 5.6387-4.9004 2.8008h15.031v-8.5898l-4.9023 2.8008-9.6172-5.7832 9.6172-5.7832 4.9023 2.8008v-8.5898h-15.033l4.9023 2.8008-9.8691 5.6387-9.8691-5.6387 4.9023-2.8008z" class="fill">'},loop:{size:45,svg:'<path d="M 21.279283,3.749797 A 18.750203,18.750203 0 0 0 8.0304417,9.2511582 L 12.740779,13.961496 A 12.083464,12.083464 0 0 1 21.279283,10.416536 12.083464,12.083464 0 0 1 33.362748,22.5 12.083464,12.083464 0 0 1 21.279283,34.583464 12.083464,12.083464 0 0 1 12.740779,31.038504 l 3.063185,-3.063185 H 4.9705135 V 38.80877 L 8.0304417,35.748842 A 18.750203,18.750203 0 0 0 21.279283,41.250203 18.750203,18.750203 0 0 0 40.029486,22.5 18.750203,18.750203 0 0 0 21.279283,3.749797 Z" class="stroke semiFill toggle" />'},settings:{size:45,svg:'<path d="m24.139 3.834-1.4785 4.3223c-1.1018 0.0088-2.2727 0.13204-3.2031 0.33594l-2.3281-3.9473c-1.4974 0.45304-2.9327 1.091-4.2715 1.9004l1.3457 4.3672c-0.87808 0.62225-1.685 1.3403-2.4023 2.1426l-4.1953-1.8223c-0.9476 1.2456-1.7358 2.6055-2.3457 4.0469l3.6523 2.7383c-0.34895 1.0215-0.58154 2.0787-0.69336 3.1523l-4.4531 0.98828c-0.00716 0.14696-0.011931 0.29432-0.015625 0.44141 0.00628 1.4179 0.17336 2.8307 0.49805 4.2109l4.5703 0.070312c0.32171 1.0271 0.75826 2.0138 1.3008 2.9434l-3.0391 3.4355c0.89502 1.2828 1.9464 2.4492 3.1309 3.4707l3.7363-2.6289c0.86307 0.64582 1.7958 1.192 2.7812 1.6289l-0.43555 4.541c1.4754 0.52082 3.0099 0.85458 4.5684 0.99414l1.4766-4.3223c0.05369 3e-3 0.10838 0.005313 0.16211 0.007812 1.024-0.0061 2.0436-0.12048 3.043-0.34375l2.3281 3.9473c1.4974-0.45304 2.9327-1.091 4.2715-1.9004l-1.3457-4.3672c0.87808-0.62225 1.685-1.3403 2.4023-2.1426l4.1953 1.8223c0.9476-1.2456 1.7358-2.6055 2.3457-4.0469l-3.6523-2.7383c0.34895-1.0215 0.58154-2.0787 0.69336-3.1523l4.4531-0.98828c0.0072-0.14698 0.011925-0.29432 0.015625-0.44141-0.0062-1.4179-0.17336-2.8307-0.49805-4.2109l-4.5703-0.070312c-0.32171-1.0271-0.75826-2.0138-1.3008-2.9434l3.0391-3.4355c-0.89502-1.2828-1.9464-2.4492-3.1309-3.4707l-3.7363 2.6289c-0.86307-0.64582-1.7958-1.192-2.7812-1.6289l0.43555-4.541c-1.4754-0.52082-3.0099-0.85457-4.5684-0.99414zm-1.6387 7.8789a10.786 10.786 0 0 1 10.787 10.787 10.786 10.786 0 0 1-10.787 10.787 10.786 10.786 0 0 1-10.787-10.787 10.786 10.786 0 0 1 10.787-10.787z" class="fill"/>'},loading:{size:100,svg:'<path d="m49.998 8.7797e-4c-0.060547 0.0018431-0.12109 0.0037961-0.18164 0.0058593-0.1251 0.0015881-0.25012 0.0061465-0.375 0.013672h-0.001954c-27.388 0.30599-49.432 22.59-49.439 49.98 0.020074 2.6488 0.25061 5.292 0.68945 7.904 3.8792-24.231 24.77-42.065 49.311-42.096v-0.0058582h0.001954c4.3638 3.0803e-4 7.9013-3.5366 7.9021-7.9002 1.474e-4 -2.0958-0.83235-4.106-2.3144-5.5879-1.482-1.482-3.492-2.3145-5.5879-2.3144-6.5007e-4 -7.9369e-8 -0.0013001-7.9369e-8 -0.001954 0" class="semiFill spin"></path>'},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return'<defs><mask id="'+i+'"><rect x="0" y="0" width="25" height="25" fill="#fff"/><rect x="-5" y="-5" width="17.5" height="35" fill="#000" transform="rotate(180,12.5,12.5)"><animateTransform attributeName="transform" type="rotate" from="0,12.5,12.5" to="180,12.5,12.5" begin="DOMNodeInsertedIntoDocument" dur="'+t/2+'s" repeatCount="1"/></rect><rect x="0" y="0" width="12.5" height="25" fill="#fff"/><rect x="-5" y="-5" width="17.5" height="35" fill="#000" transform="rotate(360,12.5,12.5)"><animate attributeType="CSS" attributeName="opacity" from="0" to="1" begin="DOMNodeInsertedIntoDocument" dur="'+t+'s" calcMode="discrete" repeatCount="1" /><animateTransform attributeName="transform" type="rotate" from="180,12.5,12.5" to="360,12.5,12.5" begin="DOMNodeInsertedIntoDocument+'+t/2+'s" dur="'+t/2+'s" repeatCount="1"/></rect><circle cx="12.5" cy="12.5" r="8" fill="#000"/></mask></defs><circle cx="12.5" cy="12.5" r="12.5" class="fill" mask="url(#'+i+')"/>'}},popout:{size:45,svg:'<path d="m24.721 11.075c-12.96 0.049575-32.113 15.432-10.336 28.834-7.6763-7.9825-2.4795-21.824 10.336-22.19v5.5368l15.276-8.862-15.276-8.86v5.5419z" class="stroke fill"/>'},switchvideo:{size:45,svg:'<path d="m8.4925 18.786c-3.9578 1.504-6.4432 3.632-6.4434 5.9982 2.183e-4 4.1354 7.5562 7.5509 17.399 8.1467v4.7777l10.718-6.2573-10.718-6.2529v4.5717c-6.9764-0.4712-12.229-2.5226-12.227-4.9859 6.693e-4 -0.72127 0.45868-1.4051 1.2714-2.0267zm28.015 0v3.9715c0.81164 0.62126 1.2685 1.3059 1.2692 2.0267-0.0014 1.4217-1.791 2.75-4.8021 3.6968-2.0515 0.82484-0.93693 3.7696 1.2249 2.9659 5.3088-1.8593 8.7426-3.8616 8.7514-6.6627-1.26e-4 -2.3662-2.4856-4.4942-6.4434-5.9982z" class="fill"/><rect rect x="10.166" y="7.7911" width="24.668" height="15.432" class="stroke"/>'}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;return 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&&MistUtil.event.addListener(e.video,"canplay",function(){if(e.player.api.paused){var t=e.player.api.play();t&&t.catch(function(t){if(!e.destroyed&&(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.catch(function(){if(!e.destroyed){e.log("Autoplay failed even with muted video. Unmuting and showing play button."),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)}}).then(function(){if(!e.destroyed){e.log("Autoplay worked! Video will be unmuted on mouseover if the page has been interacted with.");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.video.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)}},function(){})}})}}),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;s<a.length;s++)MistUtil.event.addListener(a[s],"click",function(e){e.stopPropagation()});MistUtil.event.addListener(t.video,"play",function(){e.player.api.paused&&e.player.api.play()},i.target),MistUtil.event.addListener(t.video,"pause",function(t){e.player.api.paused||e.player.api.pause()},i.target),MistUtil.event.addListener(t.video,"seeking",function(){e.player.api.currentTime=this.currentTime},i.target),MistUtil.event.addListener(t.video,"timeupdate",function(){if(!e.player.api.pausedesync){var t=this.currentTime-e.player.api.currentTime,i=Math.abs(t);if(i>30)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;i<e.secondary.length;i++){var n=r(e.secondary[i].MistVideo,t);if(n)return n}return!1}var n=r(t,t.options.target),a=r(t,i.options.target),s=!n.paused,o=document.createElement("div");if(a.parentElement.insertBefore(o,a),n.parentElement.insertBefore(a,n),o.parentElement.insertBefore(n,o),o.parentElement.removeChild(o),s)try{n.play(),a.play()}catch(e){}var l={width:n.style.width,height:n.style.height,currentTarget:n.currentTarget};n.currentTarget=a.currentTarget,a.currentTarget=l.currentTarget,t.player.resizeAll()}),t},controls:function(){if(this.options.controls&&"stock"!=this.options.controls){MistUtil.class.add(this.container,"hasControls");var e=this.UI.buildStructure(this.skin.structure.controls);return MistUtil.isTouchDevice()&&(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;t.updateBar=function(e){if(this.kids.bar){if(!isFinite(r.player.api.duration))return void(this.kids.bar.style.display="none");this.kids.bar.style.display="",w=Math.min(1,Math.max(0,this.time2perc(e))),this.kids.bar.style.width=100*w+"%"}},t.time2perc=function(e){if(!isFinite(r.player.api.duration))return 0;var t=0;if("live"==r.info.type){var i=.001*r.info.meta.buffer_window;t=(e-r.player.api.duration+i)/i}else t=e/r.player.api.duration;return Math.min(1,Math.max(0,t))},t.buildBuffer=function(e,t){var i=document.createElement("div");return i.className="buffer",i.style.left=100*this.time2perc(e)+"%",i.style.width=100*(this.time2perc(t)-this.time2perc(e))+"%",i},t.updateBuffers=function(e){for(var t=this.querySelectorAll(".buffer"),i=0;i<t.length;i++)this.removeChild(t[i]);if(e)for(i=0;i<e.length;i++)this.appendChild(this.buildBuffer(e.start(i),e.end(i)))};var n=0,a=!1;MistUtil.event.addListener(i,"progress",function(){!function e(){(new Date).getTime()-n>1e3?(t.updateBuffers(r.player.api.buffered),n=(new Date).getTime()):a||(a=r.timers.start(function(){e(),a=!1},1e3))}()},t);var s=0,o=!1;MistUtil.event.addListener(i,"timeupdate",function(){!function e(){(new Date).getTime()-s>200&&!c?(t.updateBar(r.player.api.currentTime),s=(new Date).getTime()):o||(o=r.timers.start(function(){e(),o=!1},1e3))}()},t),MistUtil.event.addListener(i,"seeking",function(){t.updateBar(r.player.api.currentTime)},t),t.getPos=function(e){var t=MistUtil.getPos(this,e);return"live"==r.info.type?(t-1)*(.001*r.info.meta.buffer_window)+r.player.api.duration:!!isFinite(r.player.api.duration)&&t*r.player.api.duration},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 l=r.UI.buildStructure({type:"tooltip"});l.style.opacity=0,t.appendChild(l),MistUtil.event.addListener(e,"mouseout",function(){c||(l.style.opacity=0)}),t.moveTooltip=function(e){var t=this.getPos(e);if(!1!==t){l.setText(MistUtil.format.time(t)),l.style.opacity=1;var i=MistUtil.getPos(this,e),r={bottom:20};i>.5?(r.right=100*(1-i)+"%",l.triangle.setMode("bottom","right")):(r.left=100*i+"%",l.triangle.setMode("bottom","left")),l.setPos(r)}else l.style.opacity=0},MistUtil.event.addListener(e,"mousemove",function(e){t.moveTooltip(e)});var c=!1;return MistUtil.event.addListener(e,"mousedown",function(i){if(1==i.which){c=!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&&(c=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),l.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(){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 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){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;i<t.length;i++)t[i].setAttribute("vertical"==a.mode?"height":"width",e+"%")},MistUtil.event.addListener(o,"volumechange",function(){a.set(s.player.api.muted?0:100*s.player.api.volume)},a);var l=MistUtil.event.addListener(o,"loadstart",function(){"localStorage"in window&&null!=localStorage&&"mistVolume"in localStorage&&(s.player.api.volume=localStorage.mistVolume),MistUtil.event.removeListener(l)});a.addPadding=function(e){return e*(1-(this.margin.start+this.margin.end))+this.margin.start},a.removePadding=function(e){var t=(e-this.margin.start)/(1-(this.margin.start+this.margin.end));return t=Math.max(t,0),t=Math.min(t,1)},a.getPos=function(e){return this.addPadding(MistUtil.getPos(this,e))},a.setVolume=function(e){s.player.api.muted=!1;var t=this.removePadding(MistUtil.getPos(this,e));t=1-Math.pow(1-t,.5),s.player.api.volume=t;try{localStorage.mistVolume=s.player.api.volume}catch(e){}},MistUtil.event.addListener(a,"mouseup",function(e){1==e.which&&a.setVolume(e)});var c=s.UI.buildStructure({type:"tooltip"});c.style.opacity=0,c.triangle.setMode("bottom","right"),n.style.position="relative",n.appendChild(c),MistUtil.event.addListener(a,"mouseover",function(){c.style.opacity=1}),MistUtil.event.addListener(a,"mouseout",function(){d||(c.style.opacity=0)}),a.moveTooltip=function(e){c.style.opacity=1;var t=MistUtil.getPos(this,e);c.setText(Math.round(100*this.removePadding(t))+"%"),c.setPos({bottom:46,right:100*(1-t)+"%"})},MistUtil.event.addListener(a,"mousemove",function(e){a.moveTooltip(e)});var d=!1;return MistUtil.event.addListener(a,"mousedown",function(e){if(1==e.which){d=!0,a.setVolume(e),c.style.opacity=1;var t=MistUtil.event.addListener(document,"mousemove",function(e){a.setVolume(e),a.moveTooltip(e)},a),i=MistUtil.event.addListener(document,"mouseup",function(e){1==e.which&&(d=!1,MistUtil.event.removeListener(t),MistUtil.event.removeListener(i),c.style.opacity=0,(!e.path||MistUtil.array.indexOf(e.path,a)<0)&&a.setVolume(e))},a)}}),n},currentTime:function(){var e=this,t=document.createElement("div"),i=document.createTextNode("");t.appendChild(i);e.player.api;var r=MistUtil.format.time;return t.set=function(){var t=e.player.api.currentTime;i.nodeValue=r(t)},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(e){!isNaN(e)&&isFinite(e)?(this.style.display="",i.nodeValue=MistUtil.format.time(e)):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.skin.icons.build("loop"),t=(this.video,this.player.api);return e.set=function(){t.loop?MistUtil.class.remove(this,"off"):MistUtil.class.add(this,"off")},MistUtil.event.addListener(e,"click",function(e){t.loop=!t.loop,this.set()}),e.set(),e}},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){switch(e.key){case"Escape":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()}},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(e.log("User selected "+t+" track with id "+i),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)<i(t)?-1:0});for(var o in s){var l=s[o],c=i[l];if("subtitle"==l){if(!("player"in e&&"api"in e.player&&"setSubtitle"in e.player.api)){e.log("Subtitle selection was disabled as this player does not support it.");continue}var d=!1;for(var u in e.info.source){var p=e.info.source[u];if("html5/text/vtt"==p.type&&MistUtil.http.url.split(p.url).protocol==MistUtil.http.url.split(e.source.url).protocol){d=p.url.replace(/.srt$/,".vtt");break}}if(!d){e.log("Subtitle selection was disabled as an SRT source could not be found.");continue}c[""]={trackid:"",different:{none:"None"}}}var h=document.createElement("tr");if(h.title="The current "+l+" track",t.appendChild(h),"decodingIssues"in e.skin.blueprints){var m=document.createElement("td");if(h.appendChild(m),"subtitle"!=l){var f=document.createElement("input");f.setAttribute("type","checkbox"),f.setAttribute("checked",""),f.setAttribute("title","Whether or not to play "+l),f.trackType=l,m.appendChild(f),n[l]=f,e.options.setTracks&&e.options.setTracks[l]&&("none"==e.options.setTracks[l]?f.checked=!1:f.checked=!0),MistUtil.event.addListener(f,"change",function(){var e=0;for(var t in n)n[t].checked&&e++;if(0==e)for(var t in n)if(t!=this.trackType&&!n[t].checked){n[t].checked=!0,a(t,!0);break}var i="none";i=this.checked?this.trackType in r?r[this.trackType].value:"auto":"none",a(this.trackType,this.checked?i:"none")}),MistUtil.event.addListener(e.video,"playerUpdate_trackChanged",function(e){e.message.type==l&&("none"==e.message.value?this.checked=!1:this.checked=!0)},b)}}var v=document.createElement("td");h.appendChild(v),v.appendChild(document.createTextNode(MistUtil.format.ucFirst(l)+":"));m=document.createElement("td");h.appendChild(m);var y=MistUtil.object.keys(c);function g(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]<t[i]?-1:0})}if(y.length>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,m.appendChild(b),"subtitle"!=l){var M=document.createElement("option");b.appendChild(M),M.value="",M.appendChild(document.createTextNode("Automatic"))}var k=g(c[MistUtil.object.keys(c)[0]].same);if(k.length)(T=document.createElement("span")).className="mistvideo-description",m.appendChild(T),m.appendChild(document.createTextNode(k.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 u in U){var x=c[U[u]];M=document.createElement("option");b.appendChild(M),M.value="idx"in x?x.idx:x.trackid,MistUtil.object.keys(x.different).length?M.appendChild(document.createTextNode(g(x.different).join(" "))):M.appendChild(document.createTextNode("Track "+(Number(u)+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(""!=this.value){var t=MistUtil.object.extend({},c[this.value]);t.label=g(t.describe).join(" "),t.src=MistUtil.http.url.addParam(d,{track:this.value}),e.player.api.setSubtitle(t)}else e.player.api.setSubtitle()}),"localStorage"in window&&null!=localStorage&&"mistSubtitleLanguage"in localStorage)for(var u in c)if(c[u].lang==localStorage.mistSubtitleLanguage){b.value=u;var C=document.createEvent("Event");C.initEvent("change"),b.dispatchEvent(C);break}}else MistUtil.event.addListener(b,"change",function(){this.trackType in n&&(n[this.trackType].checked=!0),a(this.trackType,this.value)})}else{var T;(T=document.createElement("span")).className="mistvideo-description",m.appendChild(T),T.appendChild(document.createTextNode(g(c[y[0]].same).join(" ")))}}}},text:function(e){var t=document.createElement("span");return t.appendChild(document.createTextNode(e.text)),t},placeholder:function(){var e=document.createElement("div"),t=this.calcSize();return e.style.width=t.width+"px",e.style.height=t.height+"px",this.options.poster&&(e.style.background="url('"+this.options.poster+"') no-repeat 50%/contain"),e},timeout:function(e){if(!(!1 in e)){var t="delay"in e?e.delay:5,i=this.skin.icons.build("timeout",!1,{delay:t});return i.timeout=this.timers.start(function(){e.function()},1e3*t),i}},polling:function(){var e=document.createElement("div"),t=this.skin.icons.build("loading");return e.appendChild(t),e},loading:function(){var e=this,t=this.skin.icons.build("loading",50);if("player"in e&&e.player.api){var i=!1;function r(t){e.container.setAttribute("data-loading",t.type),function t(){i||(i=e.timers.start(function(){i=!1,e.monitor.vars&&e.monitor.vars.score>=.999?n():t()},1e3))}()}function n(){e.container.removeAttribute("data-loading"),i&&e.timers.stop(i),i=!1}var a=["waiting","seeking","stalled"];for(var s in a)MistUtil.event.addListener(e.video,a[s],function(t){!this.paused&&"container"in e&&r(t)},t);a=["seeked","playing","canplay","paused","ended"];for(var s in a)MistUtil.event.addListener(e.video,a[s],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 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(/\<error>/,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");r&&t.clear(),r=!o.passive||"passive",n=(new Date).getTime();var c=this.log(s,"error"),d=t.message(s,!1,o);i=d;var u=document.createElement("div");if(u.className="mistvideo-buttoncontainer",d.appendChild(u),MistUtil.empty(u),o.softReload){var 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()}};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.defaultPrevented&&t.clear()}},t.clear=function(){for(var i=t.querySelectorAll("svg.icon.timeout"),n=0;n<i.length;n++)e.timers.stop(i[n].timeout);MistUtil.empty(t),MistUtil.class.remove(t,"show"),r=!1},this.clearError=t.clear,"video"in e){var s=["timeupdate","playing","canplay"];for(var o in s)MistUtil.event.addListener(e.video,s[o],function(i){if(r){if("timeupdate"==i.type){if(0==e.player.api.currentTime)return;if((new Date).getTime()-n<2e3)return}e.log("Removing error window because of "+i.type+" event"),t.clear()}},t)}return t},tooltip:function(){var e=document.createElement("div"),t=document.createTextNode("");e.appendChild(t),e.setText=function(e){t.nodeValue=e};var i=document.createElement("div");return e.triangle=i,i.className="triangle",e.appendChild(i),i.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}},colors:{fill:"#fff",semiFill:"rgba(255,255,255,0.5)",stroke:"#fff",strokeWidth:1.5,background:"rgba(0,0,0,0.8)",progressBackground:"#333",accent:"#0f0"}},MistSkins.dev={structure:MistUtil.object.extend({},MistSkins.default.structure,!0),blueprints:{timeout:function(){return!1},log:function(){var e=document.createElement("div");e.appendChild(document.createTextNode("Logs"));var t=document.createElement("div");t.className="logs",e.appendChild(t);var i=document.createElement("table");t.appendChild(i);var r=this,n={message:!1},a=!1,s=!0;function o(e,r,o){if(o||(o={}),n.message==r)return a++,n.counter.nodeValue=a,void(2==a&&n.counter.parentElement&&(n.counter.parentElement.style.display=""));a=1;var l=document.createElement("tr");l.className="entry",o.type&&"log"!=o.type&&(MistUtil.class.add(l,"type-"+o.type),r=MistUtil.format.ucFirst(o.type)+": "+r),i.appendChild(l);var c=document.createElement("td");c.className="timestamp",l.appendChild(c);var d=e.toLocaleTimeString().split(" ");d[0]+="."+("00"+e.getMilliseconds()).slice(-3),c.appendChild(document.createTextNode(d[0])),"currentTime"in o&&(c.title="Video playback time: "+MistUtil.format.time(o.currentTime,{ms:!0}));var u=document.createElement("td");l.appendChild(u);var p=document.createElement("span");p.className="message",u.appendChild(p),p.appendChild(document.createTextNode(r));var h=document.createElement("span");h.style.display="none",h.className="counter",u.appendChild(h);var m=document.createTextNode(a);h.appendChild(m),s&&(t.scrollTop=t.scrollHeight),n={message:r,counter:m}}for(var l in MistUtil.event.addListener(t,"scroll",function(){s=t.scrollTop+t.clientHeight>=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&&"getVideoPlaybackQuality"in e.player.api){var t=e.player.api.getVideoPlaybackQuality();if(t)return t.droppedVideoFrames?MistUtil.format.number(t.droppedVideoFrames):0}},"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(){})}}},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){if(e instanceof Promise)return void e.then(function(e){i.set(e)},function(){});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()}),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()}),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()}),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"],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()}},{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),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.choosePlayer()?(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,"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,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<this.threshold()||void 0)},action:function(){var e=this.vars.score;this.MistVideo.showError("Poor playback: "+Math.max(0,Math.round(100*e))+"%",{passive:!0,reload:!0,nextCombo:!0,ignore:!0,type:"poor_playback"})}},"monitor"in i.options&&(i.monitor.default=MistUtil.object.extend({},i.monitor),MistUtil.object.extend(i.monitor,i.options.monitor));var r=["loadstart","play","playing"];for(var n in r)MistUtil.event.addListener(i.video,r[n],function(){i.monitor.init()});r=["loadeddata","pause","abort","emptied","ended"];for(var n in r)MistUtil.event.addListener(i.video,r[n],function(){i.monitor&&i.monitor.destroy()});r=["seeking","seeked","ratechange"];for(var n in r)MistUtil.event.addListener(i.video,r[n],function(){i.monitor&&i.monitor.reset()})}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){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;r<t.secondary.length;r++){var n=e(t.secondary[r].MistVideo,i);if(n)return n}return!1}var t=e(i,i.options.target);if(!t)throw"Main video not found";if(t.p.resize(),"secondary"in i){function r(t){if(t.MistVideo){if("player"in t.MistVideo){var n=e(i,t.MistVideo.options.target);if(!n)throw"Secondary video not found";n.p.resize()}}else i.timers.start(function(){r(t)},100)}for(var n in i.secondary)r(i.secondary[n])}}),i.player.resize=function(e){var t=i.video.currentTarget.querySelector(".mistvideo");return t.hasAttribute("data-fullscreen")?(this.setSize({height:window.innerHeight,width:window.innerWidth}),!0):(size=i.calcSize(e),this.setSize(size),t.style.width=size.width+"px",t.style.height=size.height+"px",!i.options.fillSpace||e&&e.reiterating?i.video.currentTarget.clientHeight&&i.video.currentTarget.clientHeight<size.height?this.resize({width:!1,height:i.video.currentTarget.clientHeight,reiterating:!0}):i.video.currentTarget.clientWidth&&i.video.currentTarget.clientWidth<size.width?this.resize({width:i.video.currentTarget.clientWidth,height:!1,reiterating:!0}):(i.log("Player size calculated: "+size.width+" x "+size.height+" px"),!0):this.resize({width:window.innerWidth,height:!1,reiterating:!0}))},MistUtil.class.has(i.options.target,"mistvideo-secondaryVideo")||(MistUtil.event.addListener(window,"resize",function(){i.destroyed||i.player.resizeAll()},i.video),MistUtil.event.addListener(i.options.target,"resize",function(){i.player.resizeAll()},i.video),i.player.resizeAll())),i.player.api&&("setSource"in i.player.api&&(i.sourceParams={},i.player.api.setSourceParams=function(e,t){MistUtil.object.extend(i.sourceParams,t),i.player.api.setSource(MistUtil.http.url.addParam(e,t))},"setTracks"in i.player.api||(i.player.api.setTracks=function(e){var t=MistUtil.tracks.parse(i.info.meta.tracks);for(var r in e)r in t&&(e[r]in t[r]||"none"==e[r])||(i.log("Skipping trackselection of "+r+" track "+e[r]+" because it does not exist"),delete e[r]);var n=i.source.url,a=i.player.api.currentTime;if(this.setSourceParams(n,e),"live"!=i.info.type){var s=function(){this.currentTime=a,this.removeEventListener("loadedmetadata",s)};MistUtil.event.addListener(i.video,"loadedmetadata",s)}})),!("setTracks"in i.player.api)&&"setTrack"in i.player.api&&(i.player.api.setTracks=function(e){for(var t in e)i.player.api.setTrack(t,e[t])}),t.setTracks)){var a=MistUtil.object.extend({},t.setTracks);if("subtitle"in t.setTracks&&"setSubtitle"in i.player.api&&i.player.onready(function(){var e=!1;for(var t in i.info.source){var r=i.info.source[t];if("html5/text/vtt"==r.type&&MistUtil.http.url.split(r.url).protocol==MistUtil.http.url.split(i.source.url).protocol){e=r.url.replace(/.srt$/,".vtt");break}}if(e){var n=MistUtil.tracks.parse(i.info.meta.tracks);"subtitle"in n&&a.subtitle in n.subtitle&&(meta=n.subtitle[a.subtitle],meta.src=MistUtil.http.url.addParam(e,{track:a.subtitle}),meta.label="automatic",meta.lang="unknown",i.player.api.setSubtitle(meta),MistUtil.event.send("playerUpdate_trackChanged",{type:"subtitle",trackid:a.subtitle},i.video),delete a.subtitle)}}),"setTrack"in i.player.api)i.player.onready(function(){for(var e in a)i.player.api.setTrack(e,a[e]),MistUtil.event.send("playerUpdate_trackChanged",{type:e,trackid:a[e]},i.video)});else if("setTracks"in i.player.api)for(var n in i.player.onready(function(){i.player.api.setTracks(a)}),a)MistUtil.event.send("playerUpdate_trackChanged",{type:n,trackid:a[n]},i.video)}for(var n in i.player.onreadylist)i.player.onreadylist[n]();MistUtil.event.send("initialized",null,t.target),i.log("Initialized"),i.options.callback&&t.callback(i)})):i.options.startCombo?(delete i.options.startCombo,i.unload(),i=mistPlay(i.stream,i.options)):(i.showError("No compatible player/source combo found.",{reload:!0}),MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed"))}function a(){var e=i.urlappend(t.host+"/json_"+encodeURIComponent(i.stream)+".js");i.log("Requesting stream info from "+e),MistUtil.http.get(e,function(e){i.destroyed||n(JSON.parse(e))},function(e){i.showError("Connection failed: the media server may be offline",{reload:30}),i.info||(MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed"))})}if(t||(t={}),"undefined"!=typeof mistoptions&&(t=MistUtil.object.extend(MistUtil.object.extend({},mistoptions),t)),(t=MistUtil.object.extend({host:null,autoplay:!0,controls:!0,loop:!1,poster:!1,muted:!1,callback:!1,streaminfo:!1,startCombo:!1,forceType:!1,forcePlayer:!1,forceSource:!1,forcePriority:!1,monitor:!1,reloadDelay:!1,urlappend:!1,setTracks:!1,fillSpace:!1,width:!1,height:!1,maxwidth:!1,maxheight:!1,MistVideoObject:!1},t)).host&&(t.host=MistUtil.http.url.sanitizeHost(t.host)),this.options=t,this.stream=e,this.info=!1,this.logs=[],this.log=function(e,r){r||(r="log");var n=MistUtil.event.send(r,e,t.target),a={type:r};if(this.logs.push({time:new Date,message:e,data:a}),"dev"==this.options.skin)try{var s="["+(r||"log")+"] "+(i.destroyed?"[DESTROYED] ":"")+(this.player&&this.player.api?MistUtil.format.time(this.player.api.currentTime,{ms:!0})+" ":"")+e;r&&"log"!=r?console.warn(s):console.log(s)}catch(e){}return n},this.log("Initializing.."),this.timers={list:{},start:function(e,t){var r=setTimeout(function(){delete i.timers.list[r],e()},t);return this.list[r]=new Date((new Date).getTime()+t),r},stop:function(e){var t;for(var i in"all"==e?t=this.list:(t={})[e]=1,t)clearTimeout(i),delete this.list[i]}},this.errorListeners=[],this.resumeTime=!1,this.urlappend=function(e){return this.options.urlappend&&(e+=this.options.urlappend),e},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.startCombo&&(e.startCombo.started={player:!1,source:!1}),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?(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:(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&&(sortopions.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}};function d(t){return e.startCombo&&!e.startCombo.started[t]?e.startCombo[t]==c[t].current||e.startCombo[t]==c[t].list[c[t].current]?(e.startCombo.started[t]=!0,1):2:0}for(var u in c[l.outer].list)if(c[l.outer].current=u,!(d(l.outer)>=2))for(var p in c[l.inner].list)if(c[l.inner].current=p,!(d(l.inner)>=1)){a=c.source.list[c.source.current];var h=c.player.list[c.player.current].shortname,m=mistplayers[h];if(m.isMimeSupported(a.type)&&m.isBrowserSupported(a.type,a,i))return{player:h,source:a,source_index:c.source.current};t||i.log("Checking "+m.name+" with "+a.type+".. Nope.")}return!1},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("Found a working combo: "+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..");var t=i.options.host.replace(/^http/i,"ws"),s=new WebSocket(i.urlappend(t+"/json_"+encodeURIComponent(i.stream)+".js"));i.socket=s,s.die=!1,s.destroy=function(){this.die=!0,this.close()},s.onopen=function(e){this.wasConnected=!0},s.onclose=function(t){if(!this.die)return this.wasConnected?(i.log("Reopening websocket.."),void e()):void a()};var o=!1;s.addEventListener("message",function(e){var t=JSON.parse(e.data);if(t||i.showError("Error while parsing stream status stream. Obtained: "+e.data.toString(),{reload:!0}),"error"in t){var a;switch(e=t.error,"on_error"in t&&(i.log(e),e=t.on_error),i.state=t.error,t.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(t.error,"error"),o||(o=MistUtil.event.addListener(i.video,"ended",function(){i.showError(t.error,{polling:!0})})),void(o=MistUtil.event.addListener(i.video,"waiting",function(){i.showError(t.error,{polling:!0})}));a={polling:!0};break;default:a={reload:!0}}i.showError(e,a)}else{if(i.state="Stream is online",i.clearError(),o&&MistUtil.event.removeListener(o),!i.info)return void n(t);var s=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}(t,i.info);if(s){if("source"in s)return void("error"in i.info&&i.reload());i.info=MistUtil.object.extend(i.info,t),i.info.updated=new Date;var l=!1;for(var c in s)switch(c){case"meta":for(var d in s[c])switch(d){case"tracks":i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",t,i.video)}break;case"width":case"height":l=!0}l&&i.player.resize()}else i.log("Metachange: no differences detected")}})}()}else a();return this.unload=function(){if(!this.destroyed){for(var e in this.log("Unloading.."),this.destroyed=!0,this.timers.stop("all"),this.errorListeners){var t=this.errorListeners[e];if(t.src in MistUtil.scripts.list){var r=MistUtil.array.indexOf(MistUtil.scripts.list[t.src].subscribers);r>=0&&MistUtil.scripts.list[t.src].subscribers.splice(r,1)}}if("monitor"in i&&"destroy"in i.monitor&&i.monitor.destroy(),this.socket&&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(n){i.log("Error while unloading player: "+n.message)}if(this.UI&&this.UI.elements)for(var e in this.UI.elements){var n=this.UI.elements[e];if("attachedListeners"in n)for(var e in n.attachedListeners)MistUtil.event.removeListener(n.attachedListeners[e]);n.parentNode&&n.parentNode.removeChild(n)}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(){var e="player"in this&&"api"in this.player&&this.player.api.currentTime;if(this.unload(),i=mistPlay(this.stream,this.options),e&&"live"!=this.info.type){var t=function(){i.player&&i.player.api&&(i.player.api.currentTime=e),this.removeEventListener("initialized",t)};MistUtil.event.addListener(this.options.target,"initialized",t)}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();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},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";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]?e[r]=t[r]:(r in e||(MistUtil.array.is(t[r])?e[r]=[]:e[r]={}),this.extend(e[r],t[r],!0));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;i<e.length;i++)if(e[i]==t)return i;return-1},is:function(e){return"isArray"in Array?Array.isArray(e):"[object Array]"===Object.prototype.toString.call(e)},multiSort:function(e,t){var i=function(e,t){return isNaN(e)||isNaN(t)?e.localeCompare(t):Math.sign(e-t)};if(!t.length)return e.sort(i);function r(e,t){function i(e,t,i){if(!(t in e))throw"Invalid sorting rule: "+JSON.stringify([t,i])+'. "'+t+'" is not a key of '+JSON.stringify(e);if("number"==typeof i&&t in e)return e[t]*i;var r=i.indexOf(e[t]);return r>=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("?")},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;s<n[a].match(/{/g).length;){var o=e.match(/@@#@@([^}]*})/);e=e.replace(o[0],"@@#@@"),n[a]+=o[1],s++}e=e.replace("@@#@@","@@@@")}for(var a in e=e.replace(/[^@]*?{[^]*?}/g,function(e){var r=e.split("{"),n=r[0].split(","),a="{"+r.slice(1).join("}");for(var s in n){n[s]=n[s].trim();var o="."+t+n[s];i&&(o+=",\n."+t+" "+n[s]),n[s]=o}return"\n"+n+" "+a}),n)e=e.replace(/@@@@/,n[a]);if(!r)return e;r.textContent=e}},empty:function(e){for(;e.lastChild;){if(e.lastChild.lastChild&&this.empty(e.lastChild),"attachedListeners"in e.lastChild)for(var t in e.lastChild.attachedListeners)MistUtil.event.removeListener(e.lastChild.attachedListeners[t]);e.removeChild(e.lastChild)}},event:{send:function(e,t,i){try{return(r=new Event(e,{bubbles:!0,cancelable:!0})).message=t,i.dispatchEvent(r),r}catch(n){try{var r;return(r=document.createEvent("Event")).initEvent(e,!0,!0),r.message=t,i.dispatchEvent(r),r}catch(e){return!1}}return!0},addListener:function(e,t,i,r){e.addEventListener(t,i),r||(r=e),"attachedListeners"in r||(r.attachedListeners=[]);var n={element:e,type:t,callback:i};return r.attachedListeners.push(n),n},removeListener:function(e){e.element.removeEventListener(e.type,e.callback)}},scripts:{list:{},insert:function(e,t,i){var r=this;if(i&&i.errorListeners.push({src:e,onevent:t}),e in this.list)return this.list[e].subscribers.push(t.onerror),void("onload"in t&&(this.list[e].tag.hasLoaded?t.onload():MistUtil.event.addListener(this.list[e].tag,"load",t.onload)));var n=document.createElement("script");n.hasLoaded=!1,n.setAttribute("src",e),n.setAttribute("crossorigin","anonymous"),document.head.appendChild(n),n.onerror=function(e){t.onerror(e)},n.onload=function(e){this.hasLoaded=!0,i.destroyed||t.onload(e)},n.addEventListener("error",function(e){t.onerror(e)});var a=!1;return window.onerror&&(a=window.onerror),window.onerror=function(i,n,s,o,l){if(a&&a.apply(this,arguments),n==e)for(var c in t.onerror(l),r.list[e].subscribers)r.list[e].subscribers[c](l)},this.list[e]={subscribers:[t.onerror],tag:n},n}},tracks:{parse:function(e){var t={};for(var i in e){var r=MistUtil.object.extend({},e[i]);"meta"==r.type&&(r.type=r.codec,r.codec="meta"),r.type in t||(t[r.type]={}),t[r.type]["idx"in r?r.idx:r.trackid]=r;var n={};for(var a in r)switch(a){case"width":n[a]=r.width+"×"+r.height;break;case"bps":if("meta"==r.codec)continue;var s;if(r.bps>0)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(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}},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;s<e.y.length;s++){var o=e.y[s]-a;a=e.y[s],e.y[s]=o}var l=[],c={x:{min:e.x[0]-n,max:e.x[0]-n},y:{min:-1*e.y[0],max:-1*e.y[0]}};function d(e,t){if(arguments.length)c.x.min=Math.min(c.x.min,e),c.x.max=Math.max(c.x.max,e),c.y.min=Math.min(c.y.min,-1*t),c.y.max=Math.max(c.y.max,-1*t);else{var i=l[0].split(",");c={x:{min:i[0],max:i[0]},y:{min:i[1],max:i[1]}};for(var r=1;r<l.length;r++){d((i=l[r].split(","))[0],-1*i[1])}}}l.push([e.x[0]-n,-1*e.y[0]].join(","));for(s=1;s<e.y.length;s++)d(e.x[s]-n,-1*e.y[s]),l.push("L "+[e.x[s]-n,-1*e.y[s]].join(","));var u=document.createElementNS(i,"defs");r.appendChild(u);var p=document.createElementNS(i,"linearGradient");function h(){"x"in t&&("min"in t.x&&(c.x.min=t.x.min),"max"in t.x&&(c.x.max=t.x.max),"count"in t.x&&(c.x.min=c.x.max-t.x.count)),"y"in t&&("min"in t.y&&(c.y.min=-1*t.y.max),"max"in t.y&&(c.y.max=-1*t.y.min)),r.setAttributeNS(null,"viewBox",[c.x.min,c.y.min,c.x.max-c.x.min,c.y.max-c.y.min].join(" ")),p.setAttributeNS(null,"x1",0),p.setAttributeNS(null,"x2",0),t.reverseGradient?(p.setAttributeNS(null,"y1",c.y.max),p.setAttributeNS(null,"y2",c.y.min)):(p.setAttributeNS(null,"y1",c.y.min),p.setAttributeNS(null,"y2",c.y.max))}u.appendChild(p),p.setAttributeNS(null,"id",MistUtil.createUnique()),p.setAttributeNS(null,"gradientUnits","userSpaceOnUse"),p.innerHTML+='<stop offset="0" stop-color="green"/>',p.innerHTML+='<stop offset="0.33" stop-color="yellow"/>',p.innerHTML+='<stop offset="0.66" stop-color="orange"/>',p.innerHTML+='<stop offset="1" stop-color="red"/>',h();var m=document.createElementNS(i,"path");return r.appendChild(m),m.setAttributeNS(null,"stroke-width","0.1"),m.setAttributeNS(null,"fill","none"),m.setAttributeNS(null,"stroke","url(#"+p.getAttribute("id")+")"),m.setAttributeNS(null,"d","M"+l.join(" L")),m.addData=function(e){if(!isNaN(e.y)){if(t.differentiate){var i=e.y-a;a=e.y,e.y=i}l.push([e.x-n,-1*e.y].join(",")),t.x&&t.x.count&&l.length>t.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]}};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+='<svg viewBox="0 0 '+a.size.width+" "+a.size.height+'"'+("width"in i?' width="'+i.width+'"':"")+("height"in i?' height="'+i.height+'"':"")+' class="mist icon '+t+'">',s+='<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100%" width="100%">',s+=n,s+="</svg>",s+="</svg>";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",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:"video"},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"},{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>200||!this.info.hasVideo||"audio"==this.source.type.split("/")[1]},then:{type:"container",children:[{type:"loop",classes:["mistvideo-pointer"]},{type:"fullscreen",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<=200},then:{type:"container",classes:["mistvideo-center"],children:[{type:"loop",classes:["mistvideo-pointer"]},{type:"fullscreen",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:'<path d="M6.26004984594 3.0550109625C5.27445051914 3.68940862462 4.67905105702 4.78142391497 4.67968264562 5.95354422781C4.67968264562 5.95354422781 4.70004942312 39.0717540916 4.70004942312 39.0717540916C4.70302341604 40.3033886636 5.36331656075 41.439734231 6.43188211452 42.0521884912C7.50044766829 42.6646427515 8.81469531629 42.6600161659 9.87892235656 42.0400537716C9.87892235656 42.0400537716 38.5612768409 25.4802882606 38.5612768409 25.4802882606C39.6181165777 24.8606067582 40.2663250096 23.7262617523 40.2636734301 22.5011460995C40.2610218505 21.2760304467 39.6079092743 20.1445019555 38.5483970356 19.5294009803C38.5483970356 19.5294009803 9.84567577375 2.9709566275 9.84567577375 2.9709566275C8.72898008118 2.32550764609 7.34527425735 2.35794451351 6.26004984594 3.0550109625C6.26004984594 3.0550109625 6.26004984594 3.0550109625 6.26004984594 3.0550109625" class="fill" />'},largeplay:{size:45,svg:'<path d="M6.26004984594 3.0550109625C5.27445051914 3.68940862462 4.67905105702 4.78142391497 4.67968264562 5.95354422781C4.67968264562 5.95354422781 4.70004942312 39.0717540916 4.70004942312 39.0717540916C4.70302341604 40.3033886636 5.36331656075 41.439734231 6.43188211452 42.0521884912C7.50044766829 42.6646427515 8.81469531629 42.6600161659 9.87892235656 42.0400537716C9.87892235656 42.0400537716 38.5612768409 25.4802882606 38.5612768409 25.4802882606C39.6181165777 24.8606067582 40.2663250096 23.7262617523 40.2636734301 22.5011460995C40.2610218505 21.2760304467 39.6079092743 20.1445019555 38.5483970356 19.5294009803C38.5483970356 19.5294009803 9.84567577375 2.9709566275 9.84567577375 2.9709566275C8.72898008118 2.32550764609 7.34527425735 2.35794451351 6.26004984594 3.0550109625C6.26004984594 3.0550109625 6.26004984594 3.0550109625 6.26004984594 3.0550109625" class="stroke" />'},pause:{size:45,svg:'<g><path d="m 7.5,38.531275 a 4.0011916,4.0011916 0 0 0 3.749999,3.96873 l 2.2812501,0 a 4.0011916,4.0011916 0 0 0 3.96875,-3.75003 l 0,-32.28123 a 4.0011916,4.0011916 0 0 0 -3.75,-3.96875 l -2.2812501,0 a 4.0011916,4.0011916 0 0 0 -3.968749,3.75 l 0,32.28128 z" class="fill" /><path d="m 27.5,38.531275 a 4.0011916,4.0011916 0 0 0 3.75,3.9687 l 2.28125,0 a 4.0011916,4.0011916 0 0 0 3.96875,-3.75 l 0,-32.28126 a 4.0011916,4.0011916 0 0 0 -3.75,-3.96875 l -2.28125,0 a 4.0011916,4.0011916 0 0 0 -3.96875,3.75 l 0,32.28131 z" class="fill" /></g>'},speaker:{size:45,svg:'<path d="m 32.737813,5.2037363 c -1.832447,-1.10124 -4.200687,-0.8622 -5.771871,0.77112 0,0 -7.738819,8.0443797 -7.738819,8.0443797 0,0 -3.417976,0 -3.417976,0 -1.953668,0 -3.54696,1.65618 -3.54696,3.68694 0,0 0,9.58644 0,9.58644 0,2.03094 1.593292,3.68712 3.54696,3.68712 0,0 3.417976,0 3.417976,0 0,0 7.738819,8.04474 7.738819,8.04474 1.572104,1.63404 3.938942,1.8747 5.771871,0.77076 0,0 0,-34.5914997 0,-34.5914997 z" class="stroke semiFill toggle" />'},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return'<defs><mask id="'+e+'"><path d="m6.202 33.254 86.029-28.394c2.6348-0.86966 4.7433 0.77359 4.7433 3.3092v28.617c0 1.9819-1.6122 3.5773-3.6147 3.5773h-86.75c-4.3249 0-5.0634-5.5287-0.40598-7.1098" fill="#fff" /></mask></defs><rect mask="url(#'+e+')" class="slider horizontal semiFill" width="100%" height="100%" /><path d="m6.202 33.254 86.029-28.394c2.6348-0.86966 4.7433 0.77359 4.7433 3.3092v28.617c0 1.9819-1.6122 3.5773-3.6147 3.5773h-86.75c-4.3249 0-5.0634-5.5287-0.40598-7.1098" class="stroke" /><rect x="0" y="0" width="100%" height="100%" fill="rgba(0,0,0,0.001)"/>'}},muted:{size:45,svg:'<g class="stroke" stroke-linecap="round" vector-effect="none" stroke-width="2"><path d="m25.587 5.2036c-1.8324-1.1012-4.2007-0.8622-5.7719 0.77112 0 0-7.7388 8.0444-7.7388 8.0444h-3.418c-1.9537 0-3.547 1.6562-3.547 3.6869v9.5864c0 2.0309 1.5933 3.6871 3.547 3.6871h3.418s7.7388 8.0447 7.7388 8.0447c1.5721 1.634 3.9389 1.8747 5.7719 0.77076v-34.591 z" /><path d="m30.032 27.86 9.8517-9.8517"/><path d="m30.032 18.008 9.8517 9.8517"/></g>'},fullscreen:{size:45,svg:'<path d="m2.5 10.928v8.5898l4.9023-2.8008 9.6172 5.7832-9.6172 5.7832-4.9023-2.8008v8.5898h15.031l-4.9004-2.8008 9.8691-5.6387 9.8691 5.6387-4.9004 2.8008h15.031v-8.5898l-4.9023 2.8008-9.6172-5.7832 9.6172-5.7832 4.9023 2.8008v-8.5898h-15.033l4.9023 2.8008-9.8691 5.6387-9.8691-5.6387 4.9023-2.8008z" class="fill">'},loop:{size:45,svg:'<path d="M 21.279283,3.749797 A 18.750203,18.750203 0 0 0 8.0304417,9.2511582 L 12.740779,13.961496 A 12.083464,12.083464 0 0 1 21.279283,10.416536 12.083464,12.083464 0 0 1 33.362748,22.5 12.083464,12.083464 0 0 1 21.279283,34.583464 12.083464,12.083464 0 0 1 12.740779,31.038504 l 3.063185,-3.063185 H 4.9705135 V 38.80877 L 8.0304417,35.748842 A 18.750203,18.750203 0 0 0 21.279283,41.250203 18.750203,18.750203 0 0 0 40.029486,22.5 18.750203,18.750203 0 0 0 21.279283,3.749797 Z" class="stroke semiFill toggle" />'},settings:{size:45,svg:'<path d="m24.139 3.834-1.4785 4.3223c-1.1018 0.0088-2.2727 0.13204-3.2031 0.33594l-2.3281-3.9473c-1.4974 0.45304-2.9327 1.091-4.2715 1.9004l1.3457 4.3672c-0.87808 0.62225-1.685 1.3403-2.4023 2.1426l-4.1953-1.8223c-0.9476 1.2456-1.7358 2.6055-2.3457 4.0469l3.6523 2.7383c-0.34895 1.0215-0.58154 2.0787-0.69336 3.1523l-4.4531 0.98828c-0.00716 0.14696-0.011931 0.29432-0.015625 0.44141 0.00628 1.4179 0.17336 2.8307 0.49805 4.2109l4.5703 0.070312c0.32171 1.0271 0.75826 2.0138 1.3008 2.9434l-3.0391 3.4355c0.89502 1.2828 1.9464 2.4492 3.1309 3.4707l3.7363-2.6289c0.86307 0.64582 1.7958 1.192 2.7812 1.6289l-0.43555 4.541c1.4754 0.52082 3.0099 0.85458 4.5684 0.99414l1.4766-4.3223c0.05369 3e-3 0.10838 0.005313 0.16211 0.007812 1.024-0.0061 2.0436-0.12048 3.043-0.34375l2.3281 3.9473c1.4974-0.45304 2.9327-1.091 4.2715-1.9004l-1.3457-4.3672c0.87808-0.62225 1.685-1.3403 2.4023-2.1426l4.1953 1.8223c0.9476-1.2456 1.7358-2.6055 2.3457-4.0469l-3.6523-2.7383c0.34895-1.0215 0.58154-2.0787 0.69336-3.1523l4.4531-0.98828c0.0072-0.14698 0.011925-0.29432 0.015625-0.44141-0.0062-1.4179-0.17336-2.8307-0.49805-4.2109l-4.5703-0.070312c-0.32171-1.0271-0.75826-2.0138-1.3008-2.9434l3.0391-3.4355c-0.89502-1.2828-1.9464-2.4492-3.1309-3.4707l-3.7363 2.6289c-0.86307-0.64582-1.7958-1.192-2.7812-1.6289l0.43555-4.541c-1.4754-0.52082-3.0099-0.85457-4.5684-0.99414zm-1.6387 7.8789a10.786 10.786 0 0 1 10.787 10.787 10.786 10.786 0 0 1-10.787 10.787 10.786 10.786 0 0 1-10.787-10.787 10.786 10.786 0 0 1 10.787-10.787z" class="fill"/>'},loading:{size:100,svg:'<path d="m49.998 8.7797e-4c-0.060547 0.0018431-0.12109 0.0037961-0.18164 0.0058593-0.1251 0.0015881-0.25012 0.0061465-0.375 0.013672h-0.001954c-27.388 0.30599-49.432 22.59-49.439 49.98 0.020074 2.6488 0.25061 5.292 0.68945 7.904 3.8792-24.231 24.77-42.065 49.311-42.096v-0.0058582h0.001954c4.3638 3.0803e-4 7.9013-3.5366 7.9021-7.9002 1.474e-4 -2.0958-0.83235-4.106-2.3144-5.5879-1.482-1.482-3.492-2.3145-5.5879-2.3144-6.5007e-4 -7.9369e-8 -0.0013001-7.9369e-8 -0.001954 0" class="semiFill spin"></path>'},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return'<defs><mask id="'+i+'"><rect x="0" y="0" width="25" height="25" fill="#fff"/><rect x="-5" y="-5" width="17.5" height="35" fill="#000" transform="rotate(180,12.5,12.5)"><animateTransform attributeName="transform" type="rotate" from="0,12.5,12.5" to="180,12.5,12.5" begin="DOMNodeInsertedIntoDocument" dur="'+t/2+'s" repeatCount="1"/></rect><rect x="0" y="0" width="12.5" height="25" fill="#fff"/><rect x="-5" y="-5" width="17.5" height="35" fill="#000" transform="rotate(360,12.5,12.5)"><animate attributeType="CSS" attributeName="opacity" from="0" to="1" begin="DOMNodeInsertedIntoDocument" dur="'+t+'s" calcMode="discrete" repeatCount="1" /><animateTransform attributeName="transform" type="rotate" from="180,12.5,12.5" to="360,12.5,12.5" begin="DOMNodeInsertedIntoDocument+'+t/2+'s" dur="'+t/2+'s" repeatCount="1"/></rect><circle cx="12.5" cy="12.5" r="8" fill="#000"/></mask></defs><circle cx="12.5" cy="12.5" r="12.5" class="fill" mask="url(#'+i+')"/>'}},popout:{size:45,svg:'<path d="m24.721 11.075c-12.96 0.049575-32.113 15.432-10.336 28.834-7.6763-7.9825-2.4795-21.824 10.336-22.19v5.5368l15.276-8.862-15.276-8.86v5.5419z" class="stroke fill"/>'},switchvideo:{size:45,svg:'<path d="m8.4925 18.786c-3.9578 1.504-6.4432 3.632-6.4434 5.9982 2.183e-4 4.1354 7.5562 7.5509 17.399 8.1467v4.7777l10.718-6.2573-10.718-6.2529v4.5717c-6.9764-0.4712-12.229-2.5226-12.227-4.9859 6.693e-4 -0.72127 0.45868-1.4051 1.2714-2.0267zm28.015 0v3.9715c0.81164 0.62126 1.2685 1.3059 1.2692 2.0267-0.0014 1.4217-1.791 2.75-4.8021 3.6968-2.0515 0.82484-0.93693 3.7696 1.2249 2.9659 5.3088-1.8593 8.7426-3.8616 8.7514-6.6627-1.26e-4 -2.3662-2.4856-4.4942-6.4434-5.9982z" class="fill"/><rect rect x="10.166" y="7.7911" width="24.668" height="15.432" class="stroke"/>'}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;return 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&&MistUtil.event.addListener(e.video,"canplay",function(){if(e.player.api.paused){var t=e.player.api.play();t&&t.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")}).catch(function(){if(!e.destroyed){e.log("Autoplay failed even with muted video. Unmuting and showing play button."),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)}}).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.video.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)}},function(){})}else e.reporting&&(e.reporting.stats.d.autoplay="failed")})}else e.reporting&&(e.reporting.stats.d.autoplay="success")}),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;s<a.length;s++)MistUtil.event.addListener(a[s],"click",function(e){e.stopPropagation()});MistUtil.event.addListener(t.video,"play",function(){e.player.api.paused&&e.player.api.play()},i.target),MistUtil.event.addListener(t.video,"pause",function(t){e.player.api.paused||e.player.api.pause()},i.target),MistUtil.event.addListener(t.video,"seeking",function(){e.player.api.currentTime=this.currentTime},i.target),MistUtil.event.addListener(t.video,"timeupdate",function(){if(!e.player.api.pausedesync){var t=this.currentTime-e.player.api.currentTime,i=Math.abs(t);if(i>30)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;i<e.secondary.length;i++){var n=r(e.secondary[i].MistVideo,t);if(n)return n}return!1}var n=r(t,t.options.target),a=r(t,i.options.target),s=!n.paused,o=document.createElement("div");if(a.parentElement.insertBefore(o,a),n.parentElement.insertBefore(a,n),o.parentElement.insertBefore(n,o),o.parentElement.removeChild(o),s)try{n.play(),a.play()}catch(e){}var l={width:n.style.width,height:n.style.height,currentTarget:n.currentTarget};n.currentTarget=a.currentTarget,a.currentTarget=l.currentTarget,t.player.resizeAll()}),t},controls:function(){if(this.options.controls&&"stock"!=this.options.controls){MistUtil.class.add(this.container,"hasControls");var e=this.UI.buildStructure(this.skin.structure.controls);return MistUtil.isTouchDevice()&&(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;t.updateBar=function(e){if(this.kids.bar){if(!isFinite(r.player.api.duration))return void(this.kids.bar.style.display="none");this.kids.bar.style.display="",w=Math.min(1,Math.max(0,this.time2perc(e))),this.kids.bar.style.width=100*w+"%"}},t.time2perc=function(e){if(!isFinite(r.player.api.duration))return 0;var t=0;if("live"==r.info.type){var i=.001*r.info.meta.buffer_window;t=(e-r.player.api.duration+i)/i}else t=e/r.player.api.duration;return Math.min(1,Math.max(0,t))},t.buildBuffer=function(e,t){var i=document.createElement("div");return i.className="buffer",i.style.left=100*this.time2perc(e)+"%",i.style.width=100*(this.time2perc(t)-this.time2perc(e))+"%",i},t.updateBuffers=function(e){for(var t=this.querySelectorAll(".buffer"),i=0;i<t.length;i++)this.removeChild(t[i]);if(e)for(i=0;i<e.length;i++)this.appendChild(this.buildBuffer(e.start(i),e.end(i)))};var n=0,a=!1;MistUtil.event.addListener(i,"progress",function(){!function e(){(new Date).getTime()-n>1e3?(t.updateBuffers(r.player.api.buffered),n=(new Date).getTime()):a||(a=r.timers.start(function(){e(),a=!1},1e3))}()},t);var s=0,o=!1;MistUtil.event.addListener(i,"timeupdate",function(){!function e(){(new Date).getTime()-s>200&&!c?(t.updateBar(r.player.api.currentTime),s=(new Date).getTime()):o||(o=r.timers.start(function(){e(),o=!1},1e3))}()},t),MistUtil.event.addListener(i,"seeking",function(){t.updateBar(r.player.api.currentTime)},t),t.getPos=function(e){var t=MistUtil.getPos(this,e);return"live"==r.info.type?(t-1)*(.001*r.info.meta.buffer_window)+r.player.api.duration:!!isFinite(r.player.api.duration)&&t*r.player.api.duration},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 l=r.UI.buildStructure({type:"tooltip"});l.style.opacity=0,t.appendChild(l),MistUtil.event.addListener(e,"mouseout",function(){c||(l.style.opacity=0)}),t.moveTooltip=function(e){var t=this.getPos(e);if(!1!==t){l.setText(MistUtil.format.time(t)),l.style.opacity=1;var i=MistUtil.getPos(this,e),r={bottom:20};i>.5?(r.right=100*(1-i)+"%",l.triangle.setMode("bottom","right")):(r.left=100*i+"%",l.triangle.setMode("bottom","left")),l.setPos(r)}else l.style.opacity=0},MistUtil.event.addListener(e,"mousemove",function(e){t.moveTooltip(e)});var c=!1;return MistUtil.event.addListener(e,"mousedown",function(i){if(1==i.which){c=!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&&(c=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),l.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(){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 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){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;i<t.length;i++)t[i].setAttribute("vertical"==a.mode?"height":"width",e+"%")},MistUtil.event.addListener(o,"volumechange",function(){a.set(s.player.api.muted?0:100*s.player.api.volume)},a);var l=MistUtil.event.addListener(o,"loadedmetadata",function(){"localStorage"in window&&null!=localStorage&&"mistVolume"in localStorage&&(s.player.api.volume=localStorage.mistVolume),MistUtil.event.removeListener(l)});a.addPadding=function(e){return e*(1-(this.margin.start+this.margin.end))+this.margin.start},a.removePadding=function(e){var t=(e-this.margin.start)/(1-(this.margin.start+this.margin.end));return t=Math.max(t,0),t=Math.min(t,1)},a.getPos=function(e){return this.addPadding(MistUtil.getPos(this,e))},a.setVolume=function(e){s.player.api.muted=!1;var t=this.removePadding(MistUtil.getPos(this,e));t=1-Math.pow(1-t,.5),s.player.api.volume=t;try{localStorage.mistVolume=s.player.api.volume}catch(e){}},MistUtil.event.addListener(a,"mouseup",function(e){1==e.which&&a.setVolume(e)});var c=s.UI.buildStructure({type:"tooltip"});c.style.opacity=0,c.triangle.setMode("bottom","right"),n.style.position="relative",n.appendChild(c),MistUtil.event.addListener(a,"mouseover",function(){c.style.opacity=1}),MistUtil.event.addListener(a,"mouseout",function(){d||(c.style.opacity=0)}),a.moveTooltip=function(e){c.style.opacity=1;var t=MistUtil.getPos(this,e);c.setText(Math.round(100*this.removePadding(t))+"%"),c.setPos({bottom:46,right:100*(1-t)+"%"})},MistUtil.event.addListener(a,"mousemove",function(e){a.moveTooltip(e)});var d=!1;return MistUtil.event.addListener(a,"mousedown",function(e){if(1==e.which){d=!0,a.setVolume(e),c.style.opacity=1;var t=MistUtil.event.addListener(document,"mousemove",function(e){a.setVolume(e),a.moveTooltip(e)},a),i=MistUtil.event.addListener(document,"mouseup",function(e){1==e.which&&(d=!1,MistUtil.event.removeListener(t),MistUtil.event.removeListener(i),c.style.opacity=0,(!e.path||MistUtil.array.indexOf(e.path,a)<0)&&a.setVolume(e))},a)}}),n},currentTime:function(){var e=this,t=document.createElement("div"),i=document.createTextNode("");t.appendChild(i);e.player.api;var r=MistUtil.format.time;return t.set=function(){var t=e.player.api.currentTime;i.nodeValue=r(t)},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(e){!isNaN(e)&&isFinite(e)?(this.style.display="",i.nodeValue=MistUtil.format.time(e)):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.skin.icons.build("loop"),t=(this.video,this.player.api);return e.set=function(){t.loop?MistUtil.class.remove(this,"off"):MistUtil.class.add(this,"off")},MistUtil.event.addListener(e,"click",function(e){t.loop=!t.loop,this.set()}),e.set(),e}},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){switch(e.key){case"Escape":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()}},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(e.log("User selected "+t+" track with id "+i),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)<i(t)?-1:0});for(var o in s){var l=s[o],c=i[l];if("subtitle"==l){if(!("player"in e&&"api"in e.player&&"setSubtitle"in e.player.api)){e.log("Subtitle selection was disabled as this player does not support it.");continue}var d=!1;for(var u in e.info.source){var p=e.info.source[u];if("html5/text/vtt"==p.type&&MistUtil.http.url.split(p.url).protocol==MistUtil.http.url.split(e.source.url).protocol){d=p.url.replace(/.srt$/,".vtt");break}}if(!d){e.log("Subtitle selection was disabled as an SRT source could not be found.");continue}c[""]={trackid:"",different:{none:"None"}}}var h=document.createElement("tr");if(h.title="The current "+l+" track",t.appendChild(h),"decodingIssues"in e.skin.blueprints){var m=document.createElement("td");if(h.appendChild(m),"subtitle"!=l){var f=document.createElement("input");f.setAttribute("type","checkbox"),f.setAttribute("checked",""),f.setAttribute("title","Whether or not to play "+l),f.trackType=l,m.appendChild(f),n[l]=f,e.options.setTracks&&e.options.setTracks[l]&&("none"==e.options.setTracks[l]?f.checked=!1:f.checked=!0),MistUtil.event.addListener(f,"change",function(){var e=0;for(var t in n)n[t].checked&&e++;if(0==e)for(var t in n)if(t!=this.trackType&&!n[t].checked){n[t].checked=!0,a(t,!0);break}var i="none";i=this.checked?this.trackType in r?r[this.trackType].value:"auto":"none",a(this.trackType,this.checked?i:"none")}),MistUtil.event.addListener(e.video,"playerUpdate_trackChanged",function(e){e.message.type==l&&("none"==e.message.value?this.checked=!1:this.checked=!0)},b)}}var v=document.createElement("td");h.appendChild(v),v.appendChild(document.createTextNode(MistUtil.format.ucFirst(l)+":"));m=document.createElement("td");h.appendChild(m);var y=MistUtil.object.keys(c);function g(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]<t[i]?-1:0})}if(y.length>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,m.appendChild(b),"subtitle"!=l){var M=document.createElement("option");b.appendChild(M),M.value="",M.appendChild(document.createTextNode("Automatic"))}var k=g(c[MistUtil.object.keys(c)[0]].same);if(k.length)(T=document.createElement("span")).className="mistvideo-description",m.appendChild(T),m.appendChild(document.createTextNode(k.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 u in U){var x=c[U[u]];M=document.createElement("option");b.appendChild(M),M.value="idx"in x?x.idx:x.trackid,MistUtil.object.keys(x.different).length?M.appendChild(document.createTextNode(g(x.different).join(" "))):M.appendChild(document.createTextNode("Track "+(Number(u)+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(""!=this.value){var t=MistUtil.object.extend({},c[this.value]);t.label=g(t.describe).join(" "),t.src=MistUtil.http.url.addParam(d,{track:this.value}),e.player.api.setSubtitle(t)}else e.player.api.setSubtitle()}),"localStorage"in window&&null!=localStorage&&"mistSubtitleLanguage"in localStorage)for(var u in c)if(c[u].lang==localStorage.mistSubtitleLanguage){b.value=u;var C=document.createEvent("Event");C.initEvent("change"),b.dispatchEvent(C);break}}else MistUtil.event.addListener(b,"change",function(){this.trackType in n&&(n[this.trackType].checked=!0),a(this.trackType,this.value)})}else{var T;(T=document.createElement("span")).className="mistvideo-description",m.appendChild(T),T.appendChild(document.createTextNode(g(c[y[0]].same).join(" ")))}}}},text:function(e){var t=document.createElement("span");return t.appendChild(document.createTextNode(e.text)),t},placeholder:function(){var e=document.createElement("div"),t=this.calcSize();return e.style.width=t.width+"px",e.style.height=t.height+"px",this.options.poster&&(e.style.background="url('"+this.options.poster+"') no-repeat 50%/contain"),e},timeout:function(e){if(!(!1 in e)){var t="delay"in e?e.delay:5,i=this.skin.icons.build("timeout",!1,{delay:t});return i.timeout=this.timers.start(function(){e.function()},1e3*t),i}},polling:function(){var e=document.createElement("div"),t=this.skin.icons.build("loading");return e.appendChild(t),e},loading:function(){var e=this,t=this.skin.icons.build("loading",50);if("player"in e&&e.player.api){var i=!1;function r(t){e.container.setAttribute("data-loading",t.type),function t(){i||(i=e.timers.start(function(){i=!1,e.monitor.vars&&e.monitor.vars.score>=.999?n():t()},1e3))}()}function n(){e.container.removeAttribute("data-loading"),i&&e.timers.stop(i),i=!1}var a=["waiting","seeking","stalled"];for(var s in a)MistUtil.event.addListener(e.video,a[s],function(t){!this.paused&&"container"in e&&r(t)},t);a=["seeked","playing","canplay","paused","ended"];for(var s in a)MistUtil.event.addListener(e.video,a[s],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 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(/\<error>/,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");r&&t.clear(),r=!o.passive||"passive",n=(new Date).getTime();var c=this.log(s,"error"),d=t.message(s,!1,o);i=d;var u=document.createElement("div");if(u.className="mistvideo-buttoncontainer",d.appendChild(u),MistUtil.empty(u),o.softReload){var 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.defaultPrevented&&t.clear()}},t.clear=function(){for(var i=t.querySelectorAll("svg.icon.timeout"),n=0;n<i.length;n++)e.timers.stop(i[n].timeout);MistUtil.empty(t),MistUtil.class.remove(t,"show"),r=!1},this.clearError=t.clear,"video"in e){var s=["timeupdate","playing","canplay"];for(var o in s)MistUtil.event.addListener(e.video,s[o],function(i){if(r){if("timeupdate"==i.type){if(0==e.player.api.currentTime)return;if((new Date).getTime()-n<2e3)return}e.log("Removing error window because of "+i.type+" event"),t.clear()}},t)}return t},tooltip:function(){var e=document.createElement("div"),t=document.createTextNode("");e.appendChild(t),e.setText=function(e){t.nodeValue=e};var i=document.createElement("div");return e.triangle=i,i.className="triangle",e.appendChild(i),i.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}},colors:{fill:"#fff",semiFill:"rgba(255,255,255,0.5)",stroke:"#fff",strokeWidth:1.5,background:"rgba(0,0,0,0.8)",progressBackground:"#333",accent:"#0f0"}},MistSkins.dev={structure:MistUtil.object.extend({},MistSkins.default.structure,!0),blueprints:{timeout:function(){return!1},log:function(){var e=document.createElement("div");e.appendChild(document.createTextNode("Logs"));var t=document.createElement("div");t.className="logs",e.appendChild(t);var i=document.createElement("table");t.appendChild(i);var r=this,n={message:!1},a=!1,s=!0;function o(e,r,o){if(o||(o={}),n.message==r)return a++,n.counter.nodeValue=a,void(2==a&&n.counter.parentElement&&(n.counter.parentElement.style.display=""));a=1;var l=document.createElement("tr");l.className="entry",o.type&&"log"!=o.type&&(MistUtil.class.add(l,"type-"+o.type),r=MistUtil.format.ucFirst(o.type)+": "+r),i.appendChild(l);var c=document.createElement("td");c.className="timestamp",l.appendChild(c);var d=e.toLocaleTimeString().split(" ");d[0]+="."+("00"+e.getMilliseconds()).slice(-3),c.appendChild(document.createTextNode(d[0])),"currentTime"in o&&(c.title="Video playback time: "+MistUtil.format.time(o.currentTime,{ms:!0}));var u=document.createElement("td");l.appendChild(u);var p=document.createElement("span");p.className="message",u.appendChild(p),p.appendChild(document.createTextNode(r));var h=document.createElement("span");h.style.display="none",h.className="counter",u.appendChild(h);var m=document.createTextNode(a);h.appendChild(m),s&&(t.scrollTop=t.scrollHeight),n={message:r,counter:m}}for(var l in MistUtil.event.addListener(t,"scroll",function(){s=t.scrollTop+t.clientHeight>=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&&"getVideoPlaybackQuality"in e.player.api){var t=e.player.api.getVideoPlaybackQuality();if(t)return t.droppedVideoFrames?MistUtil.format.number(t.droppedVideoFrames):0}},"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(){})}}},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){if(e instanceof Promise)return void e.then(function(e){i.set(e)},function(){});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"],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),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.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<this.threshold()||void 0)},action:function(){var e=this.vars.score;this.MistVideo.showError("Poor playback: "+Math.max(0,Math.round(100*e))+"%",{passive:!0,reload:!0,nextCombo:!0,ignore:!0,type:"poor_playback"})}},"monitor"in i.options&&(i.monitor.default=MistUtil.object.extend({},i.monitor),MistUtil.object.extend(i.monitor,i.options.monitor));var r=["loadstart","play","playing"];for(var n in r)MistUtil.event.addListener(i.video,r[n],function(){i.monitor.init()});r=["loadeddata","pause","abort","emptied","ended"];for(var n in r)MistUtil.event.addListener(i.video,r[n],function(){i.monitor&&i.monitor.destroy()});r=["seeking","seeked","ratechange"];for(var n in r)MistUtil.event.addListener(i.video,r[n],function(){i.monitor&&i.monitor.reset()})}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){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;r<t.secondary.length;r++){var n=e(t.secondary[r].MistVideo,i);if(n)return n}return!1}var t=e(i,i.options.target);if(!t)throw"Main video not found";if(t.p.resize(),"secondary"in i){function r(t){if(t.MistVideo){if("player"in t.MistVideo){var n=e(i,t.MistVideo.options.target);if(!n)throw"Secondary video not found";n.p.resize()}}else i.timers.start(function(){r(t)},100)}for(var n in i.secondary)r(i.secondary[n])}}),i.player.resize=function(e){var t=i.video.currentTarget.querySelector(".mistvideo");return t.hasAttribute("data-fullscreen")?(this.setSize({height:window.innerHeight,width:window.innerWidth}),!0):(size=i.calcSize(e),this.setSize(size),t.style.width=size.width+"px",t.style.height=size.height+"px",!i.options.fillSpace||e&&e.reiterating?i.video.currentTarget.clientHeight&&i.video.currentTarget.clientHeight<size.height?this.resize({width:!1,height:i.video.currentTarget.clientHeight,reiterating:!0}):i.video.currentTarget.clientWidth&&i.video.currentTarget.clientWidth<size.width?this.resize({width:i.video.currentTarget.clientWidth,height:!1,reiterating:!0}):(i.log("Player size calculated: "+size.width+" x "+size.height+" px"),!0):this.resize({width:window.innerWidth,height:!1,reiterating:!0}))},MistUtil.class.has(i.options.target,"mistvideo-secondaryVideo")||(MistUtil.event.addListener(window,"resize",function(){i.destroyed||i.player.resizeAll()},i.video),MistUtil.event.addListener(i.options.target,"resize",function(){i.player.resizeAll()},i.video),i.player.resizeAll())),i.player.api&&("setSource"in i.player.api&&(i.sourceParams={},i.player.api.setSourceParams=function(e,t){MistUtil.object.extend(i.sourceParams,t),i.player.api.setSource(MistUtil.http.url.addParam(e,t))},"setTracks"in i.player.api||(i.player.api.setTracks=function(e){var t=MistUtil.tracks.parse(i.info.meta.tracks);for(var r in e)r in t&&(e[r]in t[r]||"none"==e[r])||(i.log("Skipping trackselection of "+r+" track "+e[r]+" because it does not exist"),delete e[r]);var n=i.source.url,a=i.player.api.currentTime;if(this.setSourceParams(n,e),"live"!=i.info.type){var s=function(){this.currentTime=a,this.removeEventListener("loadedmetadata",s)};MistUtil.event.addListener(i.video,"loadedmetadata",s)}})),!("setTracks"in i.player.api)&&"setTrack"in i.player.api&&(i.player.api.setTracks=function(e){for(var t in e)i.player.api.setTrack(t,e[t])}),t.setTracks)){var a=MistUtil.object.extend({},t.setTracks);if("subtitle"in t.setTracks&&"setSubtitle"in i.player.api&&i.player.onready(function(){var e=!1;for(var t in i.info.source){var r=i.info.source[t];if("html5/text/vtt"==r.type&&MistUtil.http.url.split(r.url).protocol==MistUtil.http.url.split(i.source.url).protocol){e=r.url.replace(/.srt$/,".vtt");break}}if(e){var n=MistUtil.tracks.parse(i.info.meta.tracks);"subtitle"in n&&a.subtitle in n.subtitle&&(meta=n.subtitle[a.subtitle],meta.src=MistUtil.http.url.addParam(e,{track:a.subtitle}),meta.label="automatic",meta.lang="unknown",i.player.api.setSubtitle(meta),MistUtil.event.send("playerUpdate_trackChanged",{type:"subtitle",trackid:a.subtitle},i.video),delete a.subtitle)}}),"setTrack"in i.player.api)i.player.onready(function(){for(var e in a)i.player.api.setTrack(e,a[e]),MistUtil.event.send("playerUpdate_trackChanged",{type:e,trackid:a[e]},i.video)});else if("setTracks"in i.player.api)for(var n in i.player.onready(function(){i.player.api.setTracks(a)}),a)MistUtil.event.send("playerUpdate_trackChanged",{type:n,trackid:a[n]},i.video)}for(var n in i.player.onreadylist)i.player.onreadylist[n]();MistUtil.event.send("initialized",null,t.target),i.log("Initialized"),i.options.callback&&t.callback(i)})):i.options.startCombo?(delete i.options.startCombo,i.unload("No compatible players found - retrying without startCombo."),mistPlay(i.stream,i.options)):(i.showError("No compatible player/source combo found.",{reload:!0}),MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed"))}function a(){var e=i.urlappend(t.host+"/json_"+encodeURIComponent(i.stream)+".js");i.log("Requesting stream info from "+e),MistUtil.http.get(e,function(e){i.destroyed||n(JSON.parse(e))},function(e){i.showError("Connection failed: the media server may be offline",{reload:30}),i.info||(MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed"))})}if(t||(t={}),"undefined"!=typeof mistoptions&&(t=MistUtil.object.extend(MistUtil.object.extend({},mistoptions),t)),(t=MistUtil.object.extend({host:null,autoplay:!0,controls:!0,loop:!1,poster:!1,muted:!1,callback:!1,streaminfo:!1,startCombo:!1,forceType:!1,forcePlayer:!1,forceSource:!1,forcePriority:!1,monitor:!1,reloadDelay:!1,urlappend:!1,setTracks:!1,fillSpace:!1,width:!1,height:!1,maxwidth:!1,maxheight:!1,MistVideoObject:!1},t)).host&&(t.host=MistUtil.http.url.sanitizeHost(t.host)),this.options=t,this.stream=e,this.info=!1,this.logs=[],this.log=function(e,r){r||(r="log");var n=MistUtil.event.send(r,e,t.target),a={type:r};if(this.logs.push({time:new Date,message:e,data:a}),"dev"==this.options.skin)try{var s="["+(r||"log")+"] "+(i.destroyed?"[DESTROYED] ":"")+(this.player&&this.player.api?MistUtil.format.time(this.player.api.currentTime,{ms:!0})+" ":"")+e;r&&"log"!=r?console.warn(s):console.log(s)}catch(e){}return n},this.log("Initializing.."),this.bootMs=(new Date).getTime(),this.timers={list:{},start:function(e,t){var r=setTimeout(function(){delete i.timers.list[r],e()},t);return this.list[r]=new Date((new Date).getTime()+t),r},stop:function(e){var t;for(var i in"all"==e?t=this.list:(t={})[e]=1,t)clearTimeout(i),delete this.list[i]}},this.errorListeners=[],this.resumeTime=!1,this.urlappend=function(e){return this.options.urlappend&&(e+=this.options.urlappend),e},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?(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:(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<n.length;s++)if(n[s].shortname==e.startCombo.player){e.startCombo.player=s;break}}function d(t){return e.startCombo&&!e.startCombo.started[t]?e.startCombo[t]==c[t].current||e.startCombo[t]==c[t].list[c[t].current]?(e.startCombo.started[t]=!0,1):2:0}for(var u in c[l.outer].list)if(c[l.outer].current=u,!(d(l.outer)>=2))for(var p in c[l.inner].list)if(c[l.inner].current=p,!(d(l.inner)>=1)){a=c.source.list[c.source.current];var h=c.player.list[c.player.current].shortname,m=mistplayers[h];if(m.isMimeSupported(a.type)&&m.isBrowserSupported(a.type,a,i))return{player:h,source:a,source_index:c.source.current};t||i.log("Checking "+m.name+" with "+a.type+".. Nope.")}return!1},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("Found a working combo: "+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..");var t=i.options.host.replace(/^http/i,"ws"),s=new WebSocket(i.urlappend(t+"/json_"+encodeURIComponent(i.stream)+".js"));i.socket=s,s.die=!1,s.destroy=function(){this.die=!0,this.onclose=function(){},this.close()},s.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){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.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.reporting.stats.add("nWaiting")}),MistUtil.event.addListener(e,"stalled",function(){i.reporting.stats.add("nStalled")}),MistUtil.event.addListener(i.options.target,"error",function(e){i.reporting.stats.add("nError"),i.reporting.stats.set("lastError",e.message)}),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.videoHeight}}),Object.defineProperty(c,"videoWidth",{get:function(){return i.video.videoWidth}}),Object.defineProperty(c,"playerHeight",{get:function(){return i.video.clientHeight}}),Object.defineProperty(c,"playerWidth",{get:function(){return i.video.clientWidth}}),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()}})},s.onclose=function(t){if(!this.die)return this.wasConnected?(i.log("Reopening websocket.."),void e()):void a()};var o=!1;s.addEventListener("message",function(e){var t=JSON.parse(e.data);if(t||i.showError("Error while parsing stream status stream. Obtained: "+e.data.toString(),{reload:!0}),"error"in t){var a;switch(e=t.error,"on_error"in t&&(i.log(e),e=t.on_error),i.state=t.error,t.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(t.error,"error"),o||(o=MistUtil.event.addListener(i.video,"ended",function(){i.showError(t.error,{polling:!0})})),void(o=MistUtil.event.addListener(i.video,"waiting",function(){i.showError(t.error,{polling:!0})}));a={polling:!0};break;default:a={reload:!0}}i.showError(e,a)}else{if(i.state="Stream is online",i.clearError(),o&&MistUtil.event.removeListener(o),!i.info)return void n(t);var s=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}(t,i.info);if(s){if("source"in s)return void("error"in i.info&&i.reload("Reloading, stream info has error"));i.info=MistUtil.object.extend(i.info,t),i.info.updated=new Date;var l=!1;for(var c in s)switch(c){case"meta":for(var d in s[c])switch(d){case"tracks":i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",t,i.video)}break;case"width":case"height":l=!0}l&&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.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.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/min/wrappers/mews.js b/embed/min/wrappers/mews.js index b37bcaef..940edafc 100644 --- a/embed/min/wrappers/mews.js +++ b/embed/min/wrappers/mews.js @@ -1 +1 @@ -mistplayers.mews={name:"MSE websocket player",mimes:["ws/video/mp4","ws/video/webm"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return this.mimes.indexOf(e)==-1?false:true},isBrowserSupported:function(e,t,i){if(!("WebSocket"in window)||!("MediaSource"in window)){return false}if(location.protocol.replace(/^http/,"ws")!=MistUtil.http.url.split(t.url.replace(/^http/,"ws")).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(navigator.platform.toUpperCase().indexOf("MAC")>=0){return false}function n(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"mp4a.40.34";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()}}var s={};for(var r in i.info.meta.tracks){if(i.info.meta.tracks[r].type!="meta"){s[n(i.info.meta.tracks[r])]=i.info.meta.tracks[r].codec}}var a=e.split("/")[2];function o(e){return MediaSource.isTypeSupported("video/"+a+';codecs="'+e+'"')}t.supportedCodecs=[];for(var r in s){var u=o(r);if(u){t.supportedCodecs.push(s[r])}}if(!i.options.forceType&&!i.options.forcePlayer){if(t.supportedCodecs.length<t.simul_tracks){i.log("Not enough playable tracks for this source");return false}}return t.supportedCodecs.length>0},player:function(){}};var p=mistplayers.mews.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var i=document.createElement("video");i.setAttribute("playsinline","");var n=["autoplay","loop","poster"];for(var s in n){var r=n[s];if(e.options[r]){i.setAttribute(r,e.options[r]===true?"":e.options[r])}}if(e.options.muted){i.muted=true}if(e.info.type=="live"){i.loop=false}if(e.options.controls=="stock"){i.setAttribute("controls","")}i.setAttribute("crossorigin","anonymous");this.setSize=function(e){i.style.width=e.width+"px";i.style.height=e.height+"px"};var a=this;function o(){if(a.ws.readyState==a.ws.OPEN&&a.ms.readyState=="open"&&a.sb){t(i);if(e.options.autoplay){a.api.play()}return true}}this.msinit=function(){return new Promise(function(e,t){a.ms=new MediaSource;i.src=URL.createObjectURL(a.ms);a.ms.onsourceopen=function(){e()};a.ms.onsourceclose=function(e){console.error("ms close",e);u({type:"stop"})};a.ms.onsourceended=function(e){console.error("ms ended",e);function t(e,t,n){var s,r;s=new Blob([e],{type:n});r=window.URL.createObjectURL(s);i(r,t);setTimeout(function(){return window.URL.revokeObjectURL(r)},1e3)}function i(e,t){var i;i=document.createElement("a");i.href=e;i.download=t;document.body.appendChild(i);i.style="display: none";i.click();i.remove()}if(a.debugging){var n=0;for(var s=0;s<a.sb.appended.length;s++){n+=a.sb.appended[s].length}var r=new Uint8Array(n);var n=0;for(var s=0;s<a.sb.appended.length;s++){r.set(a.sb.appended[s],n);n+=a.sb.appended[s].length}t(r,"appended.mp4.bin","application/octet-stream")}u({type:"stop"})}})};this.msinit().then(function(){if(a.sb){e.log("Not creating source buffer as one already exists.");return}o()});this.onsbinit=[];this.sbinit=function(t){if(!t){e.showError("Did not receive any codec: nothing to initialize.");return}a.sb=a.ms.addSourceBuffer("video/"+e.source.type.split("/")[2]+';codecs="'+t.join(",")+'"');a.sb.mode="segments";a.sb._codecs=t;a.sb._duration=1;a.sb._size=0;a.sb.queue=[];var n=[];a.sb.do_on_updateend=n;a.sb.appending=null;a.sb.appended=[];var s=0;a.sb.addEventListener("updateend",function(){if(!a.sb){e.log("Reached updateend but the source buffer is "+JSON.stringify(a.sb)+". ");return}if(a.debugging){if(a.sb.appending)a.sb.appended.push(a.sb.appending);a.sb.appending=null}if(s>=500){s=0;a.sb._clean(10)}else{s++}var t=n.slice();n=[];for(var r in t){if(!a.sb){if(a.debugging){console.warn("I was doing on_updateend but the sb was reset")}break}if(a.sb.updating){n.concat(t.slice(r));if(a.debugging){console.warn("I was doing on_updateend but was interrupted")}break}t[r](r<t.length-1?t.slice(r):[])}if(!a.sb){return}a.sb._busy=false;if(a.sb&&a.sb.queue.length>0&&!a.sb.updating&&!i.error){a.sb._append(this.queue.shift())}});a.sb.error=function(e){console.error("sb error",e)};a.sb.abort=function(e){console.error("sb abort",e)};a.sb._doNext=function(e){n.push(e)};a.sb._do=function(e){if(this.updating||this._busy){this._doNext(e)}else{e()}};a.sb._append=function(e){if(!e){return}if(!e.buffer){return}if(a.debugging){a.sb.appending=new Uint8Array(e)}if(a.sb._busy){if(a.debugging)console.warn("I wanted to append data, but now I won't because the thingy was still busy. Putting it back in the queue.");a.sb.queue.unshift(e);return}a.sb._busy=true;a.sb.appendBuffer(e)};if(a.msgqueue){if(a.msgqueue[0]){var r=false;if(a.msgqueue[0].length){for(var o in a.msgqueue[0]){if(a.sb.updating||a.sb.queue.length||a.sb._busy){a.sb.queue.push(a.msgqueue[0][o])}else{a.sb._append(a.msgqueue[0][o])}}}else{r=true}a.msgqueue.shift();if(a.msgqueue.length==0){a.msgqueue=false}e.log("The newly initialized source buffer was filled with data from a seperate message queue."+(a.msgqueue?" "+a.msgqueue.length+" more message queue(s) remain.":""));if(r){e.log("The seperate message queue was empty; manually triggering any onupdateend functions");a.sb.dispatchEvent(new Event("updateend"))}}}a.sb._clean=function(e){if(!e)e=180;if(i.currentTime>e){a.sb._do(function(){a.sb.remove(0,Math.max(.1,i.currentTime-e))})}};if(a.onsbinit.length){a.onsbinit.shift()()}};this.wsconnect=function(){return new Promise(function(t,n){this.ws=new WebSocket(e.source.url);this.ws.binaryType="arraybuffer";this.ws.onopen=function(){t()};this.ws.onerror=function(t){e.showError("MP4 over WS: websocket error")};this.ws.onclose=function(t){e.log("MP4 over WS: websocket closed")};this.ws.listeners={};this.ws.addListener=function(e,t){if(!(e in this.listeners)){this.listeners[e]=[]}this.listeners[e].push(t)};this.ws.removeListener=function(e,t){if(!(e in this.listeners)){return}var i=this.listeners[e].indexOf(t);if(i<0){return}this.listeners[e].splice(i,1);return true};a.msgqueue=false;var s=1;var r=[];this.ws.onmessage=function(t){if(!t.data){throw"Received invalid data"}if(typeof t.data=="string"){var n=JSON.parse(t.data);if(a.debugging&&n.type!="on_time"){console.log("ws message",n)}switch(n.type){case"on_stop":{var r;r=MistUtil.event.addListener(i,"waiting",function(e){MistUtil.event.send("ended",null,i);MistUtil.event.removeListener(r)});break}case"on_time":{var o=n.data.current-i.currentTime*1e3;var f=a.ws.serverDelay.get();var d=Math.max(500+f,f*2);if(e.info.type!="live"){d+=2e3}if(a.debugging)console.log("on_time received",n.data.current/1e3,"currtime",i.currentTime,s+"x","buffer",Math.round(o),"/",Math.round(d),e.info.type=="live"?"latency:"+Math.round(n.data.end-i.currentTime*1e3)+"ms":"","listeners",a.ws.listeners&&a.ws.listeners.on_time?a.ws.listeners.on_time:0,"msgqueue",a.msgqueue?a.msgqueue.length:0,n.data);if(!a.sb){e.log("Received on_time, but the source buffer is being cleared right now. Ignoring.");break}if(a.sb._duration!=n.data.end*.001){a.sb._duration=n.data.end*.001;MistUtil.event.send("durationchange",null,e.video)}e.info.meta.buffer_window=n.data.end-n.data.begin;a.sb.paused=false;if(e.info.type=="live"){if(s==1){if(n.data.play_rate_curr=="auto"){if(i.currentTime>0){if(o-d>d){s=1.1+Math.min(1,(o-d)/d)*.15;i.playbackRate*=s;e.log("Our buffer is big, so increase the playback speed to catch up.")}else if(o<d/2){s=.9;i.playbackRate*=s;e.log("Our buffer is small, so decrease the playback speed to catch up.")}}}}else if(s>1){if(o<d){i.playbackRate/=s;s=1;e.log("Our buffer is small enough, so return to real time playback.")}}else{if(o>d){i.playbackRate/=s;s=1;e.log("Our buffer is big enough, so return to real time playback.")}}}else{if(s==1){if(n.data.play_rate_curr=="auto"){if(o<d/2){if(o<-1e4){u({type:"seek",seek_time:i.currentTime*1e3})}else{s=2;e.log("Our buffer is negative, so request a faster download rate.");u({type:"set_speed",play_rate:s})}}else if(o-d>d){e.log("Our buffer is big, so request a slower download rate.");s=.5;u({type:"set_speed",play_rate:s})}}}else if(s>1){if(o>d){u({type:"set_speed",play_rate:"auto"});s=1;e.log("The buffer is big enough, so ask for realtime download rate.")}}else{if(o<d){u({type:"set_speed",play_rate:"auto"});s=1;e.log("The buffer is small enough, so ask for realtime download rate.")}}}break}case"tracks":{function c(e,t){if(!t){return false}if(e.length!=t.length){return false}for(var i in e){if(t.indexOf(e[i])<0){return false}}return true}if(c(a.last_codecs?a.last_codecs:a.sb._codecs,n.data.codecs)){if(a.debugging)console.log("reached switching point");if(n.data.current>0){if(a.sb){a.sb._do(function(){a.sb.remove(0,n.data.current*.001)})}}e.log("Player switched tracks, keeping source buffer as codecs are the same as before.")}else{if(a.debugging){console.warn("Different codecs!");console.warn("video time",i.currentTime,"waiting until",n.data.current*.001)}a.last_codecs=n.data.codecs;if(a.msgqueue){a.msgqueue.push([])}else{a.msgqueue=[[]]}var l=function(){if(a&&a.sb){a.sb._do(function(t){if(!a.sb.updating){if(!isNaN(a.ms.duration))a.sb.remove(0,Infinity);a.sb.queue=[];a.ms.removeSourceBuffer(a.sb);a.sb=null;var s=(n.data.current*.001).toFixed(3);i.src="";a.ms.onsourceclose=null;a.ms.onsourceended=null;if(a.debugging&&t&&t.length){console.warn("There are do_on_updateend functions queued, which I *should* re-apply after clearing the sb.")}a.msinit().then(function(){a.sbinit(n.data.codecs);a.sb.do_on_updateend=t;var r=MistUtil.event.addListener(i,"loadedmetadata",function(){e.log("Buffer cleared, setting playback position to "+MistUtil.format.time(s,{ms:true}));var t=function(){i.currentTime=s;if(i.currentTime<s){a.sb._doNext(t);if(a.debugging){console.log("Could not set playback position")}}else{if(a.debugging){console.log("Set playback position to "+MistUtil.format.time(s,{ms:true}))}var e=function(){a.sb._doNext(function(){if(i.buffered.length){if(a.debugging){console.log(i.buffered.start(0),i.buffered.end(0),i.currentTime)}if(i.buffered.start(0)>i.currentTime){var t=i.buffered.start(0);i.currentTime=t;if(i.currentTime!=t){e()}}}else{e()}})};e()}};t();MistUtil.event.removeListener(r)})})}else{l()}})}else{if(a.debugging){console.warn("sb not available to do clear")}a.onsbinit.push(l)}};if(!n.data.codecs||!n.data.codecs.length){e.showError("Track switch does not contain any codecs, aborting.");e.options.setTracks=false;l();break}if(a.debugging){console.warn("reached switching point",n.data.current*.001,MistUtil.format.time(n.data.current*.001))}l()}}}if(n.type in this.listeners){for(var p=this.listeners[n.type].length-1;p>=0;p--){this.listeners[n.type][p](n)}}return}var b=new Uint8Array(t.data);if(b){if(a.sb&&!a.msgqueue){if(a.sb.updating||a.sb.queue.length||a.sb._busy){a.sb.queue.push(b)}else{a.sb._append(b)}}else{if(!a.msgqueue){a.msgqueue=[[]]}a.msgqueue[a.msgqueue.length-1].push(b)}}else{e.log("Expecting data from websocket, but received none?!")}};this.ws.serverDelay={delays:[],log:function(e){var t=false;switch(e){case"seek":case"set_speed":{t=e;break}case"request_codec_data":{t="codec_data";break}default:{return}}if(t){var i=(new Date).getTime();function n(){a.ws.serverDelay.add((new Date).getTime()-i);a.ws.removeListener(t,n)}a.ws.addListener(t,n)}},add:function(e){this.delays.unshift(e);if(this.delays.length>5){this.delays.splice(5)}},get:function(){if(this.delays.length){let e=0;let t=0;for(null;t<this.delays.length;t++){if(t>=3){break}e+=this.delays[t]}return e/t}return 500}}}.bind(this))};this.wsconnect().then(function(){var t=function(e){a.sbinit(e.data.codecs);o();a.ws.removeListener("codec_data",t)};this.ws.addListener("codec_data",t);u({type:"request_codec_data",supported_codecs:e.source.supportedCodecs})}.bind(this));function u(e){if(!a.ws){throw"No websocket to send to"}if(a.ws.readyState>=a.ws.CLOSING){a.wsconnect().then(function(){u(e)});return}if(a.debugging){console.log("ws send",e)}a.ws.serverDelay.log(e.type);a.ws.send(JSON.stringify(e))}a.findBuffer=function(e){var t=false;for(var n=0;n<i.buffered.length;n++){if(i.buffered.start(n)<=e&&i.buffered.end(n)>=e){t=n;break}}return t};this.api={play:function(t){return new Promise(function(n,s){var r=function(o){if(!a.sb){e.log("Attempting to play, but the source buffer is being cleared. Waiting for next on_time.");return}if(e.info.type=="live"){if(t||i.currentTime==0){var u=function(){if(i.buffered.length){var t=a.findBuffer(o.data.current*.001);if(t!==false){if(i.buffered.start(t)>i.currentTime||i.buffered.end(t)<i.currentTime){i.currentTime=o.data.current*.001;e.log("Setting live playback position to "+MistUtil.format.time(i.currentTime))}i.play().then(n).catch(s);a.sb.paused=false;a.sb.removeEventListener("updateend",u)}}};a.sb.addEventListener("updateend",u)}else{a.sb.paused=false;i.play().then(n).catch(s)}a.ws.removeListener("on_time",r)}else if(o.data.current>i.currentTime){a.sb.paused=false;i.play().then(n).catch(s);a.ws.removeListener("on_time",r)}};a.ws.addListener("on_time",r);var o={type:"play"};if(t){o.seek_time="live"}u(o)})},pause:function(){i.pause();u({type:"hold"});if(a.sb){a.sb.paused=true}},setTracks:function(e){e.type="tracks";e=MistUtil.object.extend({type:"tracks",audio:null,video:null,seek_time:Math.max(0,i.currentTime*1e3-(500+a.ws.serverDelay.get()))},e);u(e)},unload:function(){a.api.pause();a.sb._do(function(){a.sb.remove(0,Infinity);try{a.ms.endOfStream()}catch(e){}});a.ws.close();delete window.mistMewsOnVisibilityChange;document.removeEventListener("visibilitychange",l)}};Object.defineProperty(this.api,"currentTime",{get:function(){return i.currentTime},set:function(t){MistUtil.event.send("seeking",t,i);u({type:"seek",seek_time:Math.max(0,t*1e3-(250+a.ws.serverDelay.get()))});var n=function(e){a.ws.removeListener("seek",n);var s=function(e){a.ws.removeListener("on_time",s);t=(e.data.current*.001).toFixed(3);var n=function(){i.currentTime=t;if(i.currentTime!=t){if(a.debugging)console.log("Failed to set video.currentTime, wanted:",t,"got:",i.currentTime);a.sb._doNext(n)}};n()};a.ws.addListener("on_time",s)};a.ws.addListener("seek",n);i.currentTime=t;e.log("Seeking to "+MistUtil.format.time(t,{ms:true})+" ("+t+")")}});Object.defineProperty(this.api,"duration",{get:function(){return a.sb?a.sb._duration:1}});Object.defineProperty(this.api,"playbackRate",{get:function(){return i.playbackRate},set:function(e){var t=function(e){i.playbackRate=e.data.play_rate};a.ws.addListener("set_speed",t);u({type:"set_speed",play_rate:e==1?"auto":e})}});function f(e){Object.defineProperty(a.api,e,{get:function(){return i[e]},set:function(t){return i[e]=t}})}var d=["volume","buffered","muted","loop","paused",,"error","textTracks","webkitDroppedFrameCount","webkitDecodedFrameCount"];for(var s in d){f(d[s])}MistUtil.event.addListener(i,"ended",function(){if(a.api.loop){a.api.currentTime=0;a.sb._do(function(){a.sb.remove(0,Infinity)})}});var c=false;function l(){if(document.hidden){if(!a.sb.paused){a.api.pause();c=true;if(e.info.type=="live"){c="live"}e.log("Pausing the player as the tab is inactive.")}}else if(c){a.api.play(c=="live");c=false;e.log("Restarting the player as the tab is now active again.")}}if(!window.mistMewsOnVisibilityChange){window.mistMewsOnVisibilityChange=true;document.addEventListener("visibilitychange",l)}var p=false;MistUtil.event.addListener(i,"seeking",function(){p=true;var e=MistUtil.event.addListener(i,"seeked",function(){p=false;MistUtil.event.removeListener(e)})});MistUtil.event.addListener(i,"waiting",function(){if(p){return}var t=a.findBuffer(i.currentTime);if(t!==false){if(t+1<i.buffered.length&&i.buffered.start(t+1)-i.currentTime<1e4){e.log("Skipped over buffer gap (from "+MistUtil.format.time(i.currentTime)+" to "+MistUtil.format.time(i.buffered.start(t+1))+")");i.currentTime=i.buffered.start(t+1)}}});if(a.debugging){MistUtil.event.addListener(i,"waiting",function(){var e=[];var t=false;for(var n=0;n<i.buffered.length;n++){if(i.currentTime>=i.buffered.start(n)&&i.currentTime<=i.buffered.end(n)){t=true}e.push([i.buffered.start(n),i.buffered.end(n)])}console.log("waiting","currentTime",i.currentTime,"buffers",e,t?"contained":"outside of buffer","readystate",i.readyState,"networkstate",i.networkState);if(i.readyState>=2&&i.networkState>=2){console.error("Why am I waiting?!")}})}}; \ No newline at end of file +mistplayers.mews={name:"MSE websocket player",mimes:["ws/video/mp4","ws/video/webm"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return this.mimes.indexOf(e)==-1?false:true},isBrowserSupported:function(e,t,i){if(!("WebSocket"in window)||!("MediaSource"in window)){return false}if(location.protocol.replace(/^http/,"ws")!=MistUtil.http.url.split(t.url.replace(/^http/,"ws")).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(navigator.platform.toUpperCase().indexOf("MAC")>=0){return false}function n(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"mp4a.40.34";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()}}var s={};for(var r in i.info.meta.tracks){if(i.info.meta.tracks[r].type!="meta"){s[n(i.info.meta.tracks[r])]=i.info.meta.tracks[r].codec}}var a=e.split("/")[2];function o(e){return MediaSource.isTypeSupported("video/"+a+';codecs="'+e+'"')}t.supportedCodecs=[];for(var r in s){var u=o(r);if(u){t.supportedCodecs.push(s[r])}}if(!i.options.forceType&&!i.options.forcePlayer){if(t.supportedCodecs.length<t.simul_tracks){i.log("Not enough playable tracks for this source");return false}}return t.supportedCodecs.length>0},player:function(){}};var p=mistplayers.mews.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var i=document.createElement("video");i.setAttribute("playsinline","");var n=["autoplay","loop","poster"];for(var s in n){var r=n[s];if(e.options[r]){i.setAttribute(r,e.options[r]===true?"":e.options[r])}}if(e.options.muted){i.muted=true}if(e.info.type=="live"){i.loop=false}if(e.options.controls=="stock"){i.setAttribute("controls","")}i.setAttribute("crossorigin","anonymous");this.setSize=function(e){i.style.width=e.width+"px";i.style.height=e.height+"px"};var a=this;function o(){if(a.ws.readyState==a.ws.OPEN&&a.ms.readyState=="open"&&a.sb){t(i);if(e.options.autoplay){a.api.play()}return true}}this.msinit=function(){return new Promise(function(e,t){a.ms=new MediaSource;i.src=URL.createObjectURL(a.ms);a.ms.onsourceopen=function(){e()};a.ms.onsourceclose=function(e){console.error("ms close",e);u({type:"stop"})};a.ms.onsourceended=function(e){console.error("ms ended",e);function t(e,t,n){var s,r;s=new Blob([e],{type:n});r=window.URL.createObjectURL(s);i(r,t);setTimeout(function(){return window.URL.revokeObjectURL(r)},1e3)}function i(e,t){var i;i=document.createElement("a");i.href=e;i.download=t;document.body.appendChild(i);i.style="display: none";i.click();i.remove()}if(a.debugging){var n=0;for(var s=0;s<a.sb.appended.length;s++){n+=a.sb.appended[s].length}var r=new Uint8Array(n);var n=0;for(var s=0;s<a.sb.appended.length;s++){r.set(a.sb.appended[s],n);n+=a.sb.appended[s].length}t(r,"appended.mp4.bin","application/octet-stream")}u({type:"stop"})}})};this.msinit().then(function(){if(a.sb){e.log("Not creating source buffer as one already exists.");return}o()});this.onsbinit=[];this.sbinit=function(t){if(!t){e.showError("Did not receive any codec: nothing to initialize.");return}a.sb=a.ms.addSourceBuffer("video/"+e.source.type.split("/")[2]+';codecs="'+t.join(",")+'"');a.sb.mode="segments";a.sb._codecs=t;a.sb._duration=1;a.sb._size=0;a.sb.queue=[];var n=[];a.sb.do_on_updateend=n;a.sb.appending=null;a.sb.appended=[];var s=0;a.sb.addEventListener("updateend",function(){if(!a.sb){e.log("Reached updateend but the source buffer is "+JSON.stringify(a.sb)+". ");return}if(a.debugging){if(a.sb.appending)a.sb.appended.push(a.sb.appending);a.sb.appending=null}if(s>=500){s=0;a.sb._clean(10)}else{s++}var t=n.slice();n=[];for(var r in t){if(!a.sb){if(a.debugging){console.warn("I was doing on_updateend but the sb was reset")}break}if(a.sb.updating){n.concat(t.slice(r));if(a.debugging){console.warn("I was doing on_updateend but was interrupted")}break}t[r](r<t.length-1?t.slice(r):[])}if(!a.sb){return}a.sb._busy=false;if(a.sb&&a.sb.queue.length>0&&!a.sb.updating&&!i.error){a.sb._append(this.queue.shift())}});a.sb.error=function(e){console.error("sb error",e)};a.sb.abort=function(e){console.error("sb abort",e)};a.sb._doNext=function(e){n.push(e)};a.sb._do=function(e){if(this.updating||this._busy){this._doNext(e)}else{e()}};a.sb._append=function(e){if(!e){return}if(!e.buffer){return}if(a.debugging){a.sb.appending=new Uint8Array(e)}if(a.sb._busy){if(a.debugging)console.warn("I wanted to append data, but now I won't because the thingy was still busy. Putting it back in the queue.");a.sb.queue.unshift(e);return}a.sb._busy=true;a.sb.appendBuffer(e)};if(a.msgqueue){if(a.msgqueue[0]){var r=false;if(a.msgqueue[0].length){for(var o in a.msgqueue[0]){if(a.sb.updating||a.sb.queue.length||a.sb._busy){a.sb.queue.push(a.msgqueue[0][o])}else{a.sb._append(a.msgqueue[0][o])}}}else{r=true}a.msgqueue.shift();if(a.msgqueue.length==0){a.msgqueue=false}e.log("The newly initialized source buffer was filled with data from a seperate message queue."+(a.msgqueue?" "+a.msgqueue.length+" more message queue(s) remain.":""));if(r){e.log("The seperate message queue was empty; manually triggering any onupdateend functions");a.sb.dispatchEvent(new Event("updateend"))}}}a.sb._clean=function(e){if(!e)e=180;if(i.currentTime>e){a.sb._do(function(){a.sb.remove(0,Math.max(.1,i.currentTime-e))})}};if(a.onsbinit.length){a.onsbinit.shift()()}};this.wsconnect=function(){return new Promise(function(t,n){this.ws=new WebSocket(e.source.url);this.ws.binaryType="arraybuffer";this.ws.s=this.ws.send;this.ws.send=function(){if(this.readyState==1){return this.s.apply(this,arguments)}return false};this.ws.onopen=function(){this.wasConnected=true;t()};this.ws.onerror=function(t){e.showError("MP4 over WS: websocket error")};this.ws.onclose=function(t){e.log("MP4 over WS: websocket closed");if(this.wasConnected&&!e.destroyed){e.log("MP4 over WS: reopening websocket");a.wsconnect().then(function(){if(!a.sb){var t=function(e){if(!a.sb){a.sbinit(e.data.codecs)}else{a.api.play()}a.ws.removeListener("codec_data",t)};a.ws.addListener("codec_data",t);u({type:"request_codec_data",supported_codecs:e.source.supportedCodecs})}else{a.api.play()}},function(){Mistvideo.error("Lost connection to the Media Server")})}};this.ws.listeners={};this.ws.addListener=function(e,t){if(!(e in this.listeners)){this.listeners[e]=[]}this.listeners[e].push(t)};this.ws.removeListener=function(e,t){if(!(e in this.listeners)){return}var i=this.listeners[e].indexOf(t);if(i<0){return}this.listeners[e].splice(i,1);return true};a.msgqueue=false;var s=1;var r=[];this.ws.onmessage=function(t){if(!t.data){throw"Received invalid data"}if(typeof t.data=="string"){var n=JSON.parse(t.data);if(a.debugging&&n.type!="on_time"){console.log("ws message",n)}switch(n.type){case"on_stop":{var r;r=MistUtil.event.addListener(i,"waiting",function(e){a.sb.paused=true;MistUtil.event.send("ended",null,i);MistUtil.event.removeListener(r)});break}case"on_time":{var o=n.data.current-i.currentTime*1e3;var d=a.ws.serverDelay.get();var c=Math.max(500+d,d*2);if(e.info.type!="live"){c+=2e3}if(a.debugging)console.log("on_time received",n.data.current/1e3,"currtime",i.currentTime,s+"x","buffer",Math.round(o),"/",Math.round(c),e.info.type=="live"?"latency:"+Math.round(n.data.end-i.currentTime*1e3)+"ms":"","bitrate:"+MistUtil.format.bits(a.monitor.currentBps)+"/s","listeners",a.ws.listeners&&a.ws.listeners.on_time?a.ws.listeners.on_time:0,"msgqueue",a.msgqueue?a.msgqueue.length:0,n.data);if(!a.sb){e.log("Received on_time, but the source buffer is being cleared right now. Ignoring.");break}if(a.sb._duration!=n.data.end*.001){a.sb._duration=n.data.end*.001;MistUtil.event.send("durationchange",null,e.video)}e.info.meta.buffer_window=n.data.end-n.data.begin;a.sb.paused=false;if(e.info.type=="live"){if(s==1){if(n.data.play_rate_curr=="auto"){if(i.currentTime>0){if(o-c>c){s=1.1+Math.min(1,(o-c)/c)*.15;i.playbackRate*=s;e.log("Our buffer is big, so increase the playback speed to catch up.")}else if(o<c/2){s=.9;i.playbackRate*=s;e.log("Our buffer is small, so decrease the playback speed to catch up.")}}}}else if(s>1){if(o<c){i.playbackRate/=s;s=1;e.log("Our buffer is small enough, so return to real time playback.")}}else{if(o>c){i.playbackRate/=s;s=1;e.log("Our buffer is big enough, so return to real time playback.")}}}else{if(s==1){if(n.data.play_rate_curr=="auto"){if(o<c/2){if(o<-1e4){u({type:"seek",seek_time:i.currentTime*1e3})}else{s=2;e.log("Our buffer is negative, so request a faster download rate.");u({type:"set_speed",play_rate:s})}}else if(o-c>c){e.log("Our buffer is big, so request a slower download rate.");s=.5;u({type:"set_speed",play_rate:s})}}}else if(s>1){if(o>c){u({type:"set_speed",play_rate:"auto"});s=1;e.log("The buffer is big enough, so ask for realtime download rate.")}}else{if(o<c){u({type:"set_speed",play_rate:"auto"});s=1;e.log("The buffer is small enough, so ask for realtime download rate.")}}}if(e.reporting&&n.data.tracks){e.reporting.stats.d.tracks=n.data.tracks.join(",")}break}case"tracks":{function f(e,t){if(!t){return false}if(e.length!=t.length){return false}for(var i in e){if(t.indexOf(e[i])<0){return false}}return true}if(f(a.last_codecs?a.last_codecs:a.sb._codecs,n.data.codecs)){if(a.debugging)console.log("reached switching point");if(n.data.current>0){if(a.sb){a.sb._do(function(){a.sb.remove(0,n.data.current*.001)})}}e.log("Player switched tracks, keeping source buffer as codecs are the same as before.")}else{if(a.debugging){console.warn("Different codecs!");console.warn("video time",i.currentTime,"waiting until",n.data.current*.001)}a.last_codecs=n.data.codecs;if(a.msgqueue){a.msgqueue.push([])}else{a.msgqueue=[[]]}var l=function(){if(a&&a.sb){a.sb._do(function(t){if(!a.sb.updating){if(!isNaN(a.ms.duration))a.sb.remove(0,Infinity);a.sb.queue=[];a.ms.removeSourceBuffer(a.sb);a.sb=null;var s=(n.data.current*.001).toFixed(3);i.src="";a.ms.onsourceclose=null;a.ms.onsourceended=null;if(a.debugging&&t&&t.length){console.warn("There are do_on_updateend functions queued, which I *should* re-apply after clearing the sb.")}a.msinit().then(function(){a.sbinit(n.data.codecs);a.sb.do_on_updateend=t;var r=MistUtil.event.addListener(i,"loadedmetadata",function(){e.log("Buffer cleared, setting playback position to "+MistUtil.format.time(s,{ms:true}));var t=function(){i.currentTime=s;if(i.currentTime<s){a.sb._doNext(t);if(a.debugging){console.log("Could not set playback position")}}else{if(a.debugging){console.log("Set playback position to "+MistUtil.format.time(s,{ms:true}))}var e=function(){a.sb._doNext(function(){if(i.buffered.length){if(a.debugging){console.log(i.buffered.start(0),i.buffered.end(0),i.currentTime)}if(i.buffered.start(0)>i.currentTime){var t=i.buffered.start(0);i.currentTime=t;if(i.currentTime!=t){e()}}}else{e()}})};e()}};t();MistUtil.event.removeListener(r)})})}else{l()}})}else{if(a.debugging){console.warn("sb not available to do clear")}a.onsbinit.push(l)}};if(!n.data.codecs||!n.data.codecs.length){e.showError("Track switch does not contain any codecs, aborting.");e.options.setTracks=false;l();break}if(a.debugging){console.warn("reached switching point",n.data.current*.001,MistUtil.format.time(n.data.current*.001))}l()}}}if(n.type in this.listeners){for(var p=this.listeners[n.type].length-1;p>=0;p--){this.listeners[n.type][p](n)}}return}var b=new Uint8Array(t.data);if(b){for(var p in a.monitor.bitCounter){a.monitor.bitCounter[p]+=t.data.byteLength*8}if(a.sb&&!a.msgqueue){if(a.sb.updating||a.sb.queue.length||a.sb._busy){a.sb.queue.push(b)}else{a.sb._append(b)}}else{if(!a.msgqueue){a.msgqueue=[[]]}a.msgqueue[a.msgqueue.length-1].push(b)}}else{e.log("Expecting data from websocket, but received none?!")}};this.ws.serverDelay={delays:[],log:function(e){var t=false;switch(e){case"seek":case"set_speed":{t=e;break}case"request_codec_data":{t="codec_data";break}default:{return}}if(t){var i=(new Date).getTime();function n(){a.ws.serverDelay.add((new Date).getTime()-i);a.ws.removeListener(t,n)}a.ws.addListener(t,n)}},add:function(e){this.delays.unshift(e);if(this.delays.length>5){this.delays.splice(5)}},get:function(){if(this.delays.length){let e=0;let t=0;for(null;t<this.delays.length;t++){if(t>=3){break}e+=this.delays[t]}return e/t}return 500}}}.bind(this))};this.wsconnect().then(function(){var t=function(e){a.sbinit(e.data.codecs);o();a.ws.removeListener("codec_data",t)};this.ws.addListener("codec_data",t);u({type:"request_codec_data",supported_codecs:e.source.supportedCodecs})}.bind(this));function u(e){if(!a.ws){throw"No websocket to send to"}if(a.ws.readyState>=a.ws.CLOSING){a.wsconnect().then(function(){u(e)});return}if(a.debugging){console.log("ws send",e)}a.ws.serverDelay.log(e.type);a.ws.send(JSON.stringify(e))}a.findBuffer=function(e){var t=false;for(var n=0;n<i.buffered.length;n++){if(i.buffered.start(n)<=e&&i.buffered.end(n)>=e){t=n;break}}return t};this.api={play:function(t){return new Promise(function(n,s){var r=function(o){if(!a.sb){e.log("Attempting to play, but the source buffer is being cleared. Waiting for next on_time.");return}if(e.info.type=="live"){if(t||i.currentTime==0){var u=function(){if(i.buffered.length){var t=a.findBuffer(o.data.current*.001);if(t!==false){if(i.buffered.start(t)>i.currentTime||i.buffered.end(t)<i.currentTime){i.currentTime=o.data.current*.001;e.log("Setting live playback position to "+MistUtil.format.time(i.currentTime))}i.play().then(n).catch(s);a.sb.paused=false;a.sb.removeEventListener("updateend",u)}}};a.sb.addEventListener("updateend",u)}else{a.sb.paused=false;i.play().then(n).catch(s)}a.ws.removeListener("on_time",r)}else if(o.data.current>i.currentTime){a.sb.paused=false;i.currentTime=o.data.current*.001;i.play().then(n).catch(s);a.ws.removeListener("on_time",r)}};a.ws.addListener("on_time",r);var o={type:"play"};if(t){o.seek_time="live"}u(o)})},pause:function(){i.pause();u({type:"hold"});if(a.sb){a.sb.paused=true}},setTracks:function(e){e.type="tracks";e=MistUtil.object.extend({type:"tracks",seek_time:Math.max(0,i.currentTime*1e3-(500+a.ws.serverDelay.get()))},e);u(e)},unload:function(){a.api.pause();a.sb._do(function(){a.sb.remove(0,Infinity);try{a.ms.endOfStream()}catch(e){}});a.ws.close()}};Object.defineProperty(this.api,"currentTime",{get:function(){return i.currentTime},set:function(t){MistUtil.event.send("seeking",t,i);u({type:"seek",seek_time:Math.max(0,t*1e3-(250+a.ws.serverDelay.get()))});var n=function(e){a.ws.removeListener("seek",n);var s=function(e){a.ws.removeListener("on_time",s);t=(e.data.current*.001).toFixed(3);var n=function(){i.currentTime=t;if(i.currentTime!=t){if(a.debugging)console.log("Failed to set video.currentTime, wanted:",t,"got:",i.currentTime);a.sb._doNext(n)}};n()};a.ws.addListener("on_time",s)};a.ws.addListener("seek",n);i.currentTime=t;e.log("Seeking to "+MistUtil.format.time(t,{ms:true})+" ("+t+")")}});Object.defineProperty(this.api,"duration",{get:function(){return a.sb?a.sb._duration:1}});Object.defineProperty(this.api,"playbackRate",{get:function(){return i.playbackRate},set:function(e){var t=function(e){i.playbackRate=e.data.play_rate};a.ws.addListener("set_speed",t);u({type:"set_speed",play_rate:e==1?"auto":e})}});function d(e){Object.defineProperty(a.api,e,{get:function(){return i[e]},set:function(t){return i[e]=t}})}var c=["volume","buffered","muted","loop","paused",,"error","textTracks","webkitDroppedFrameCount","webkitDecodedFrameCount"];for(var s in c){d(c[s])}MistUtil.event.addListener(i,"ended",function(){if(a.api.loop){a.api.currentTime=0;a.sb._do(function(){a.sb.remove(0,Infinity)})}});var f=false;MistUtil.event.addListener(i,"seeking",function(){f=true;var e=MistUtil.event.addListener(i,"seeked",function(){f=false;MistUtil.event.removeListener(e)})});MistUtil.event.addListener(i,"waiting",function(){if(f){return}var t=a.findBuffer(i.currentTime);if(t!==false){if(t+1<i.buffered.length&&i.buffered.start(t+1)-i.currentTime<1e4){e.log("Skipped over buffer gap (from "+MistUtil.format.time(i.currentTime)+" to "+MistUtil.format.time(i.buffered.start(t+1))+")");i.currentTime=i.buffered.start(t+1)}}});MistUtil.event.addListener(i,"pause",function(){if(a.sb&&!a.sb.paused){e.log("The browser paused the vid - probably because it has no audio and the tab is no longer visible. Pausing download.");u({type:"hold"});a.sb.paused=true;var t=MistUtil.event.addListener(i,"play",function(){if(a.sb&&a.sb.paused){u({type:"play"})}MistUtil.event.removeListener(t)})}});if(a.debugging){MistUtil.event.addListener(i,"waiting",function(){var e=[];var t=false;for(var n=0;n<i.buffered.length;n++){if(i.currentTime>=i.buffered.start(n)&&i.currentTime<=i.buffered.end(n)){t=true}e.push([i.buffered.start(n),i.buffered.end(n)])}console.log("waiting","currentTime",i.currentTime,"buffers",e,t?"contained":"outside of buffer","readystate",i.readyState,"networkstate",i.networkState);if(i.readyState>=2&&i.networkState>=2){console.error("Why am I waiting?!")}})}this.monitor={bitCounter:[],bitsSince:[],currentBps:null,nWaiting:0,nWaitingThreshold:3,listener:MistUtil.event.addListener(i,"waiting",function(){a.monitor.nWaiting++;if(a.monitor.nWaiting>=a.monitor.nWaitingThreshold){a.monitor.nWaiting=0;e.log("ABR threshold triggered, requesting lower quality");a.monitor.action()}}),getBitRate:function(){if(a.sb&&!a.sb.paused){this.bitCounter.push(0);this.bitsSince.push((new Date).getTime());var t,i;if(this.bitCounter.length>5){t=a.monitor.bitCounter.shift();i=this.bitsSince.shift()}else{t=a.monitor.bitCounter[0];i=this.bitsSince[0]}var n=(new Date).getTime()-i;this.currentBps=t/(n*.001)}e.timers.start(function(){a.monitor.getBitRate()},500)},action:function(){a.api.setTracks({video:"max<"+Math.round(this.currentBps)+"bps"})}};this.monitor.getBitRate()}; \ No newline at end of file diff --git a/embed/min/wrappers/webrtc.js b/embed/min/wrappers/webrtc.js index c6260667..1cb819fe 100644 --- a/embed/min/wrappers/webrtc.js +++ b/embed/min/wrappers/webrtc.js @@ -1 +1 @@ -mistplayers.webrtc={name:"WebRTC player",mimes:["webrtc"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return this.mimes.indexOf(e)==-1?false:true},isBrowserSupported:function(e,t,n){if(!("WebSocket"in window)||!("RTCPeerConnection"in window)){return false}if(location.protocol.replace(/^http/,"ws")!=MistUtil.http.url.split(t.url.replace(/^http/,"ws")).protocol){n.log("HTTP/HTTPS mismatch for this source");return false}return true},player:function(){}};var p=mistplayers.webrtc.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var n=this;if(typeof WebRTCBrowserEqualizerLoaded=="undefined"||!WebRTCBrowserEqualizerLoaded){var i=document.createElement("script");i.src=e.urlappend(e.options.host+"/webrtc.js");e.log("Retrieving webRTC browser equalizer code from "+i.src);document.head.appendChild(i);i.onerror=function(){e.showError("Failed to load webrtc browser equalizer",{nextCombo:5})};i.onload=function(){n.build(e,t)};return}var r=document.createElement("video");r.setAttribute("playsinline","");var o=["autoplay","loop","poster"];for(var s in o){var c=o[s];if(e.options[c]){r.setAttribute(c,e.options[c]===true?"":e.options[c])}}if(e.options.muted){r.muted=true}if(e.info.type=="live"){r.loop=false}if(e.options.controls=="stock"){r.setAttribute("controls","")}r.setAttribute("crossorigin","anonymous");this.setSize=function(e){r.style.width=e.width+"px";r.style.height=e.height+"px"};MistUtil.event.addListener(r,"loadeddata",b);MistUtil.event.addListener(r,"seeked",b);if(!e.options.autoplay){MistUtil.event.addListener(r,"canplay",function(){var t=MistUtil.event.addListener(r,"play",function(){e.log("Pausing because autoplay is disabled");var i=MistUtil.event.addListener(r,"pause",function(){e.options.autoplay=false;MistUtil.event.removeListener(i)});n.api.pause();MistUtil.event.removeListener(t)})})}var a=0;var l=false;var f=[];this.listeners={on_connected:function(){a=0;l=false;this.webrtc.play();MistUtil.event.send("webrtc_connected",null,r)},on_disconnected:function(){MistUtil.event.send("webrtc_disconnected",null,r);e.log("Websocket sent on_disconnect");if(!l){r.pause()}},on_answer_sdp:function(t){if(!t.result){e.showError("Failed to open stream.");this.on_disconnected();return}e.log("SDP answer received")},on_time:function(t){var n=a;a=t.current*.001-r.currentTime;if(Math.abs(n-a)>1){b()}if((!("paused"in t)||!t.paused)&&r.paused){r.play()}var i=t.end==0?Infinity:t.end*.001;if(i!=p){p=i;MistUtil.event.send("durationchange",i,r)}if(t.tracks&&f!=t.tracks){var o=e.info?MistUtil.tracks.parse(e.info.meta.tracks):[];for(var s in t.tracks){if(f.indexOf(t.tracks[s])<0){var c;for(var l in o){if(t.tracks[s]in o[l]){c=l;break}}if(!c){continue}MistUtil.event.send("playerUpdate_trackChanged",{type:c,trackid:t.tracks[s]},e.video)}}f=t.tracks}},on_seek:function(e){var t=this;MistUtil.event.send("seeked",a,r);if(e.live_point){t.webrtc.playbackrate("auto")}if("seekPromise"in this.webrtc.signaling){r.play().then(function(){if("seekPromise"in t.webrtc.signaling){t.webrtc.signaling.seekPromise.resolve("Play promise resolved")}}).catch(function(){if("seekPromise"in t.webrtc.signaling){t.webrtc.signaling.seekPromise.reject("Play promise rejected")}})}else{r.play()}},on_speed:function(e){this.webrtc.play_rate=e.play_rate_curr;MistUtil.event.send("ratechange",e,r)},on_stop:function(){e.log("Websocket sent on_stop");r.pause();MistUtil.event.send("ended",null,r);l=true}};function u(){this.peerConn=null;this.localOffer=null;this.isConnected=false;this.isConnecting=false;this.play_rate="auto";var t=this;this.on_event=function(i){switch(i.type){case"on_connected":{t.isConnected=true;t.isConnecting=false;break}case"on_answer_sdp":{t.peerConn.setRemoteDescription({type:"answer",sdp:i.answer_sdp}).then(function(){},function(e){console.error(e)});break}case"on_disconnected":{t.isConnected=false;break}}if(i.type in n.listeners){return n.listeners[i.type].call(n,i)}e.log("Unhandled WebRTC event "+i.type+": "+JSON.stringify(i));return false};this.connect=function(n){t.isConnecting=true;function i(e){var t=new Promise(function(t,n){function i(e){try{var r=RTCRtpReceiver.getCapabilities("video");for(var o=0;o<r.codecs.length;o++){if(r.codecs[o].mimeType=="video/H264"){t("H264 found :)");return}}if(e>0){setTimeout(function(){i(e-1)},100)}else{n("H264 not found :(")}}catch(e){t("Checker unavailable")}}i(e)});return t}i(5).catch(function(){e.log("Beware: this device does not seem to be able to play H264.")}).finally(function(){t.signaling=new d(t.on_event);var i={};if(e.options.RTCIceServers){i.iceServers=e.options.RTCIceServers}else if(e.source.RTCIceServers){i.iceServers=e.source.RTCIceServers}t.peerConn=new RTCPeerConnection(i);t.peerConn.ontrack=function(e){r.srcObject=e.streams[0];if(n){n()}};t.peerConn.onconnectionstatechange=function(t){if(this.destroyed){return}switch(this.connectionState){case"failed":{e.log("UDP connection failed, trying next combo.","error");e.nextCombo();break}case"disconnected":case"closed":case"new":case"connecting":case"connected":default:{e.log("WebRTC connection state changed to "+this.connectionState);break}}};t.peerConn.oniceconnectionstatechange=function(t){if(this.destroyed){return}switch(this.iceConnectionState){case"failed":{e.showError("ICE connection "+this.iceConnectionState);break}case"disconnected":case"closed":case"new":case"checking":case"connected":case"completed":default:{e.log("WebRTC ICE connection state changed to "+this.iceConnectionState);break}}}})};this.play=function(){if(!this.isConnected){throw"Not connected, cannot play"}this.peerConn.createOffer({offerToReceiveAudio:true,offerToReceiveVideo:true}).then(function(e){t.localOffer=e;t.peerConn.setLocalDescription(e).then(function(){t.signaling.sendOfferSDP(t.localOffer.sdp)},function(e){console.error(e)})},function(e){throw e})};this.stop=function(){if(!this.isConnected){throw"Not connected, cannot stop."}this.signaling.send({type:"stop"})};this.seek=function(n){var i=new Promise(function(i,r){if(!t.isConnected||!t.signaling){if(t.isConnecting){var o=MistUtil.event.addListener(e.video,"loadstart",function(){t.seek(n);MistUtil.event.removeListener(o)});return r("Not connected yet, will seek once connected")}else{return r("Failed seek: not connected")}}t.signaling.send({type:"seek",seek_time:n=="live"?"live":n*1e3});if("seekPromise"in t.signaling){t.signaling.seekPromise.reject("Doing new seek")}t.signaling.seekPromise={resolve:function(e){i("seeked");delete t.signaling.seekPromise},reject:function(e){r("Failed to seek: "+e);delete t.signaling.seekPromise}}});return i};this.pause=function(){if(!this.isConnected){throw"Not connected, cannot pause."}this.signaling.send({type:"pause"})};this.setTrack=function(e){if(!this.isConnected){throw"Not connected, cannot set track."}e.type="tracks";this.signaling.send(e)};this.playbackrate=function(e){if(typeof e=="undefined"){return n.webrtc.play_rate=="auto"?1:n.webrtc.play_rate}if(!this.isConnected){throw"Not connected, cannot change playback rate."}this.signaling.send({type:"set_speed",play_rate:e})};this.getStats=function(e){this.peerConn.getStats().then(function(t){var n={};var i=Array.from(t.entries());for(var r in i){var o=i[r];if(o[1].type=="inbound-rtp"){n[o[0]]=o[1]}}e(n)})};this.connect()}function d(t){this.ws=null;this.ws=new WebSocket(e.source.url.replace(/^http/,"ws"));var n=false;this.ws.onopen=function(){t({type:"on_connected"})};this.ws.onmessage=function(e){try{var n=JSON.parse(e.data);t(n)}catch(t){console.error("Failed to parse a response from MistServer",t,e.data)}};this.ws.onclose=function(e){switch(e.code){case 1006:{}default:{t({type:"on_disconnected",code:e.code});break}}};this.sendOfferSDP=function(e){this.send({type:"offer_sdp",offer_sdp:e})};this.send=function(e){if(!this.ws){throw"Not initialized, cannot send "+JSON.stringify(e)}this.ws.send(JSON.stringify(e))}}this.webrtc=new u;this.api={};var p;Object.defineProperty(this.api,"duration",{get:function(){return p}});Object.defineProperty(this.api,"currentTime",{get:function(){return a+r.currentTime},set:function(e){a=e-r.currentTime;r.pause();var t=n.webrtc.seek(e);MistUtil.event.send("seeking",e,r);if(t){t.catch(function(e){})}}});Object.defineProperty(this.api,"playbackRate",{get:function(){return n.webrtc.playbackrate()},set:function(e){return n.webrtc.playbackrate(e)}});function h(e){Object.defineProperty(n.api,e,{get:function(){return r[e]},set:function(t){return r[e]=t}})}var v=["volume","muted","loop","paused",,"error","textTracks","webkitDroppedFrameCount","webkitDecodedFrameCount"];for(var s in v){h(v[s])}function g(e){if(e in r){n.api[e]=function(){return r[e].call(r,arguments)}}}var v=["load","getVideoPlaybackQuality"];for(var s in v){g(v[s])}n.api.play=function(){var t;if(n.api.currentTime){t=n.api.currentTime}if(e.info&&e.info.type=="live"){t="live"}if(t){var i=new Promise(function(i,r){if(!n.webrtc.isConnected&&n.webrtc.peerConn.iceConnectionState!="completed"){if(!n.webrtc.isConnecting){e.log("Received call to play while not connected, connecting "+n.webrtc.peerConn.iceConnectionState);n.webrtc.connect(function(){n.webrtc.seek(t).then(function(e){i("played "+e)}).catch(function(e){r(e)})})}else{r("Still connecting")}}else{n.webrtc.seek(t).then(function(e){i("played "+e)}).catch(function(e){r(e)})}});return i}else{return r.play()}};n.api.getStats=function(){if(n.webrtc&&n.webrtc.isConnected){return new Promise(function(e,t){n.webrtc.peerConn.getStats().then(t=>{var n={audio:null,video:null};for(let e of t.values()){if(e.type=="track"){n[e.kind]=e}}e(n)})})}};n.api.getLatency=function(){var t=e.player.api.getStats();if(t){return new Promise(function(e,i){t.then(function(t){setTimeout(function(){var r=n.api.getStats();if(!r){i();return}r.then(function(n){var i={};for(var r in t){i[r]=t[r]&&n[r]?(n[r].jitterBufferDelay-t[r].jitterBufferDelay)/(n[r].jitterBufferEmittedCount-t[r].jitterBufferEmittedCount):null}e(i)},i)},1e3)},i)})}};n.api.pause=function(){r.pause();try{n.webrtc.pause()}catch(e){}MistUtil.event.send("paused",null,r)};n.api.setTracks=function(e){if(n.webrtc.isConnected){n.webrtc.setTrack(e)}else{var t=function(){n.webrtc.setTrack(e);MistUtil.event.removeListener({type:"webrtc_connected",callback:t,element:r})};MistUtil.event.addListener(r,"webrtc_connected",t)}};function b(){if(!n.api.textTracks[0]){return}var e=n.api.textTracks[0].currentOffset||0;if(Math.abs(a-e)<1){return}var t=[];for(var i=n.api.textTracks[0].cues.length-1;i>=0;i--){var r=n.api.textTracks[0].cues[i];n.api.textTracks[0].removeCue(r);if(!("orig"in r)){r.orig={start:r.startTime,end:r.endTime}}r.startTime=r.orig.start-a;r.endTime=r.orig.end-a;t.push(r)}for(var i in t){n.api.textTracks[0].addCue(t[i])}n.api.textTracks[0].currentOffset=a}n.api.setSubtitle=function(e){var t=r.getElementsByTagName("track");for(var n=t.length-1;n>=0;n--){r.removeChild(t[n])}if(e){var i=document.createElement("track");r.appendChild(i);i.kind="subtitles";i.label=e.label;i.srclang=e.lang;i.src=e.src;i.setAttribute("default","");i.onload=b}};MistUtil.event.addListener(r,"ended",function(){if(n.api.loop){if(e.state=="Stream is online"){n.webrtc.connect()}}});if("decodingIssues"in e.skin.blueprints){var w=["nackCount","pliCount","packetsLost","packetsReceived","bytesReceived"];for(var y in w){n.api[w[y]]=0}var k=function(){e.timers.start(function(){n.webrtc.getStats(function(e){for(var t in e){for(var i in w){if(w[i]in e[t]){n.api[w[i]]=e[t][w[i]]}}break}});k()},1e3)};k()}n.api.unload=function(){try{n.webrtc.stop();n.webrtc.signaling.ws.close()}catch(e){}};t(r)}; \ No newline at end of file +mistplayers.webrtc={name:"WebRTC player",mimes:["webrtc"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return this.mimes.indexOf(e)==-1?false:true},isBrowserSupported:function(e,t,n){if(!("WebSocket"in window)||!("RTCPeerConnection"in window)){return false}if(location.protocol.replace(/^http/,"ws")!=MistUtil.http.url.split(t.url.replace(/^http/,"ws")).protocol){n.log("HTTP/HTTPS mismatch for this source");return false}return true},player:function(){}};var p=mistplayers.webrtc.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var n=this;if(typeof WebRTCBrowserEqualizerLoaded=="undefined"||!WebRTCBrowserEqualizerLoaded){var i=document.createElement("script");i.src=e.urlappend(e.options.host+"/webrtc.js");e.log("Retrieving webRTC browser equalizer code from "+i.src);document.head.appendChild(i);i.onerror=function(){e.showError("Failed to load webrtc browser equalizer",{nextCombo:5})};i.onload=function(){n.build(e,t)};return}var r=document.createElement("video");r.setAttribute("playsinline","");var o=["autoplay","loop","poster"];for(var s in o){var c=o[s];if(e.options[c]){r.setAttribute(c,e.options[c]===true?"":e.options[c])}}if(e.options.muted){r.muted=true}if(e.info.type=="live"){r.loop=false}if(e.options.controls=="stock"){r.setAttribute("controls","")}r.setAttribute("crossorigin","anonymous");this.setSize=function(e){r.style.width=e.width+"px";r.style.height=e.height+"px"};MistUtil.event.addListener(r,"loadeddata",b);MistUtil.event.addListener(r,"seeked",b);if(!e.options.autoplay){MistUtil.event.addListener(r,"canplay",function(){var t=MistUtil.event.addListener(r,"play",function(){e.log("Pausing because autoplay is disabled");var i=MistUtil.event.addListener(r,"pause",function(){e.options.autoplay=false;MistUtil.event.removeListener(i)});n.api.pause();MistUtil.event.removeListener(t)})})}var a=0;var l=false;var f=[];this.listeners={on_connected:function(){a=0;l=false;this.webrtc.play();MistUtil.event.send("webrtc_connected",null,r)},on_disconnected:function(){MistUtil.event.send("webrtc_disconnected",null,r);e.log("Websocket sent on_disconnect");if(!l){r.pause()}},on_answer_sdp:function(t){if(!t.result){e.showError("Failed to open stream.");this.on_disconnected();return}e.log("SDP answer received")},on_time:function(t){var n=a;a=t.current*.001-r.currentTime;if(Math.abs(n-a)>1){b()}if((!("paused"in t)||!t.paused)&&r.paused){r.play()}var i=t.end==0?Infinity:t.end*.001;if(i!=p){p=i;MistUtil.event.send("durationchange",i,r)}if(t.tracks&&f!=t.tracks){var o=e.info?MistUtil.tracks.parse(e.info.meta.tracks):[];for(var s in t.tracks){if(f.indexOf(t.tracks[s])<0){var c;for(var l in o){if(t.tracks[s]in o[l]){c=l;break}}if(!c){continue}MistUtil.event.send("playerUpdate_trackChanged",{type:c,trackid:t.tracks[s]},e.video)}}f=t.tracks}if(e.reporting&&t.tracks){e.reporting.stats.d.tracks=t.tracks.join(",")}},on_seek:function(e){var t=this;MistUtil.event.send("seeked",a,r);if(e.live_point){t.webrtc.playbackrate("auto")}if("seekPromise"in this.webrtc.signaling){r.play().then(function(){if("seekPromise"in t.webrtc.signaling){t.webrtc.signaling.seekPromise.resolve("Play promise resolved")}}).catch(function(){if("seekPromise"in t.webrtc.signaling){t.webrtc.signaling.seekPromise.reject("Play promise rejected")}})}else{r.play()}},on_speed:function(e){this.webrtc.play_rate=e.play_rate_curr;MistUtil.event.send("ratechange",e,r)},on_stop:function(){e.log("Websocket sent on_stop");r.pause();MistUtil.event.send("ended",null,r);l=true}};function u(){this.peerConn=null;this.localOffer=null;this.isConnected=false;this.isConnecting=false;this.play_rate="auto";var t=this;this.on_event=function(i){switch(i.type){case"on_connected":{t.isConnected=true;t.isConnecting=false;break}case"on_answer_sdp":{t.peerConn.setRemoteDescription({type:"answer",sdp:i.answer_sdp}).then(function(){},function(e){console.error(e)});break}case"on_disconnected":{t.isConnected=false;break}}if(i.type in n.listeners){return n.listeners[i.type].call(n,i)}e.log("Unhandled WebRTC event "+i.type+": "+JSON.stringify(i));return false};this.connect=function(n){t.isConnecting=true;function i(e){var t=new Promise(function(t,n){function i(e){try{var r=RTCRtpReceiver.getCapabilities("video");for(var o=0;o<r.codecs.length;o++){if(r.codecs[o].mimeType=="video/H264"){t("H264 found :)");return}}if(e>0){setTimeout(function(){i(e-1)},100)}else{n("H264 not found :(")}}catch(e){t("Checker unavailable")}}i(e)});return t}i(5).catch(function(){e.log("Beware: this device does not seem to be able to play H264.")}).finally(function(){t.signaling=new d(t.on_event);var i={};if(e.options.RTCIceServers){i.iceServers=e.options.RTCIceServers}else if(e.source.RTCIceServers){i.iceServers=e.source.RTCIceServers}t.peerConn=new RTCPeerConnection(i);t.peerConn.ontrack=function(e){r.srcObject=e.streams[0];if(n){n()}};t.peerConn.onconnectionstatechange=function(t){if(e.destroyed){return}switch(this.connectionState){case"failed":{e.log("UDP connection failed, trying next combo.","error");e.nextCombo();break}case"disconnected":case"closed":case"new":case"connecting":case"connected":default:{e.log("WebRTC connection state changed to "+this.connectionState);break}}};t.peerConn.oniceconnectionstatechange=function(t){if(e.destroyed){return}switch(this.iceConnectionState){case"failed":{e.showError("ICE connection "+this.iceConnectionState);break}case"disconnected":case"closed":case"new":case"checking":case"connected":case"completed":default:{e.log("WebRTC ICE connection state changed to "+this.iceConnectionState);break}}}})};this.play=function(){if(!this.isConnected){throw"Not connected, cannot play"}this.peerConn.createOffer({offerToReceiveAudio:true,offerToReceiveVideo:true}).then(function(e){t.localOffer=e;t.peerConn.setLocalDescription(e).then(function(){t.signaling.sendOfferSDP(t.localOffer.sdp)},function(e){console.error(e)})},function(e){throw e})};this.stop=function(){if(!this.isConnected){throw"Not connected, cannot stop."}this.signaling.send({type:"stop"})};this.seek=function(n){var i=new Promise(function(i,r){if(!t.isConnected||!t.signaling){if(t.isConnecting){var o=MistUtil.event.addListener(e.video,"loadstart",function(){t.seek(n);MistUtil.event.removeListener(o)});return r("Not connected yet, will seek once connected")}else{return r("Failed seek: not connected")}}t.signaling.send({type:"seek",seek_time:n=="live"?"live":n*1e3});if("seekPromise"in t.signaling){t.signaling.seekPromise.reject("Doing new seek")}t.signaling.seekPromise={resolve:function(e){i("seeked");delete t.signaling.seekPromise},reject:function(e){r("Failed to seek: "+e);delete t.signaling.seekPromise}}});return i};this.pause=function(){if(!this.isConnected){throw"Not connected, cannot pause."}this.signaling.send({type:"pause"})};this.setTrack=function(e){if(!this.isConnected){throw"Not connected, cannot set track."}e.type="tracks";this.signaling.send(e)};this.playbackrate=function(e){if(typeof e=="undefined"){return n.webrtc.play_rate=="auto"?1:n.webrtc.play_rate}if(!this.isConnected){throw"Not connected, cannot change playback rate."}this.signaling.send({type:"set_speed",play_rate:e})};this.getStats=function(e){this.peerConn.getStats().then(function(t){var n={};var i=Array.from(t.entries());for(var r in i){var o=i[r];if(o[1].type=="inbound-rtp"){n[o[0]]=o[1]}}e(n)})};this.connect()}function d(t){this.ws=null;this.ws=new WebSocket(e.source.url.replace(/^http/,"ws"));var n=false;this.ws.onopen=function(){t({type:"on_connected"})};this.ws.onmessage=function(e){try{var n=JSON.parse(e.data);t(n)}catch(t){console.error("Failed to parse a response from MistServer",t,e.data)}};this.ws.onclose=function(e){switch(e.code){case 1006:{}default:{t({type:"on_disconnected",code:e.code});break}}};this.sendOfferSDP=function(e){this.send({type:"offer_sdp",offer_sdp:e})};this.send=function(e){if(!this.ws){throw"Not initialized, cannot send "+JSON.stringify(e)}this.ws.send(JSON.stringify(e))}}this.webrtc=new u;this.api={};var p;Object.defineProperty(this.api,"duration",{get:function(){return p}});Object.defineProperty(this.api,"currentTime",{get:function(){return a+r.currentTime},set:function(e){a=e-r.currentTime;r.pause();var t=n.webrtc.seek(e);MistUtil.event.send("seeking",e,r);if(t){t.catch(function(e){})}}});Object.defineProperty(this.api,"playbackRate",{get:function(){return n.webrtc.playbackrate()},set:function(e){return n.webrtc.playbackrate(e)}});function h(e){Object.defineProperty(n.api,e,{get:function(){return r[e]},set:function(t){return r[e]=t}})}var v=["volume","muted","loop","paused",,"error","textTracks","webkitDroppedFrameCount","webkitDecodedFrameCount"];for(var s in v){h(v[s])}function g(e){if(e in r){n.api[e]=function(){return r[e].call(r,arguments)}}}var v=["load","getVideoPlaybackQuality"];for(var s in v){g(v[s])}n.api.play=function(){var t;if(n.api.currentTime){t=n.api.currentTime}if(e.info&&e.info.type=="live"){t="live"}if(t){var i=new Promise(function(i,r){if(!n.webrtc.isConnected&&n.webrtc.peerConn.iceConnectionState!="completed"){if(!n.webrtc.isConnecting){e.log("Received call to play while not connected, connecting "+n.webrtc.peerConn.iceConnectionState);n.webrtc.connect(function(){n.webrtc.seek(t).then(function(e){i("played "+e)}).catch(function(e){r(e)})})}else{r("Still connecting")}}else{n.webrtc.seek(t).then(function(e){i("played "+e)}).catch(function(e){r(e)})}});return i}else{return r.play()}};n.api.getStats=function(){if(n.webrtc&&n.webrtc.isConnected){return new Promise(function(e,t){n.webrtc.peerConn.getStats().then(t=>{var n={audio:null,video:null};for(let e of t.values()){if(e.type=="track"){n[e.kind]=e}}e(n)})})}};n.api.getLatency=function(){var t=e.player.api.getStats();if(t){return new Promise(function(e,i){t.then(function(t){setTimeout(function(){var r=n.api.getStats();if(!r){i();return}r.then(function(n){var i={};for(var r in t){i[r]=t[r]&&n[r]?(n[r].jitterBufferDelay-t[r].jitterBufferDelay)/(n[r].jitterBufferEmittedCount-t[r].jitterBufferEmittedCount):null}e(i)},i)},1e3)},i)})}};n.api.pause=function(){r.pause();try{n.webrtc.pause()}catch(e){}MistUtil.event.send("paused",null,r)};n.api.setTracks=function(e){if(n.webrtc.isConnected){n.webrtc.setTrack(e)}else{var t=function(){n.webrtc.setTrack(e);MistUtil.event.removeListener({type:"webrtc_connected",callback:t,element:r})};MistUtil.event.addListener(r,"webrtc_connected",t)}};function b(){if(!n.api.textTracks[0]){return}var e=n.api.textTracks[0].currentOffset||0;if(Math.abs(a-e)<1){return}var t=[];for(var i=n.api.textTracks[0].cues.length-1;i>=0;i--){var r=n.api.textTracks[0].cues[i];n.api.textTracks[0].removeCue(r);if(!("orig"in r)){r.orig={start:r.startTime,end:r.endTime}}r.startTime=r.orig.start-a;r.endTime=r.orig.end-a;t.push(r)}for(var i in t){n.api.textTracks[0].addCue(t[i])}n.api.textTracks[0].currentOffset=a}n.api.setSubtitle=function(e){var t=r.getElementsByTagName("track");for(var n=t.length-1;n>=0;n--){r.removeChild(t[n])}if(e){var i=document.createElement("track");r.appendChild(i);i.kind="subtitles";i.label=e.label;i.srclang=e.lang;i.src=e.src;i.setAttribute("default","");i.onload=b}};MistUtil.event.addListener(r,"ended",function(){if(n.api.loop){if(e.state=="Stream is online"){n.webrtc.connect()}}});if("decodingIssues"in e.skin.blueprints){var w=["nackCount","pliCount","packetsLost","packetsReceived","bytesReceived"];for(var y in w){n.api[w[y]]=0}var k=function(){e.timers.start(function(){n.webrtc.getStats(function(e){for(var t in e){for(var i in w){if(w[i]in e[t]){n.api[w[i]]=e[t][w[i]]}}break}});k()},1e3)};k()}n.api.unload=function(){try{n.webrtc.stop();n.webrtc.signaling.ws.close();n.webrtc.peerConn.close()}catch(e){}};t(r)}; \ No newline at end of file diff --git a/embed/player.js b/embed/player.js index ac16201d..317ed5d4 100644 --- a/embed/player.js +++ b/embed/player.js @@ -28,7 +28,7 @@ function MistVideo(streamName,options) { reloadDelay: false, //don't override default reload delay urlappend: false, //don't add this to urls setTracks: false, //don't set tracks - fillSpace: false, //don't fill parent container + fillSpace: false, //don't fill parent container width: false, //no set width height: false, //no set height maxwidth: false, //no max width (apart from targets dimensions) @@ -62,6 +62,7 @@ function MistVideo(streamName,options) { return event; }; this.log("Initializing.."); + this.bootMs = new Date().getTime(); this.timers = { list: {}, //will contain the timeouts, format timeOutIndex: endTime @@ -110,14 +111,7 @@ function MistVideo(streamName,options) { var source = false; var mistPlayer = false; - - if (options.startCombo) { - options.startCombo.started = { - player: false, - source: false - }; - } - + //retrieve the sources we can loop over var sources; if (options.forceSource) { @@ -177,7 +171,7 @@ function MistVideo(streamName,options) { MistUtil.array.multiSort(players,sortoptions.player); } if ("first" in options.forcePriority) { - sortopions.first = options.forcePriority.first; //overwrite + sortoptions.first = options.forcePriority.first; //overwrite } @@ -198,6 +192,20 @@ function MistVideo(streamName,options) { current: false } }; + + if (options.startCombo) { + options.startCombo.started = { + player: false, + source: false + }; + for (var i = 0; i < players.length; i++) { + if (players[i].shortname == options.startCombo.player) { + options.startCombo.player = i; + break; + } + } + } + function checkStartCombo(which) { if ((options.startCombo) && (!options.startCombo.started[which])) { @@ -401,7 +409,16 @@ function MistVideo(streamName,options) { if (MistVideo.choosePlayer()) { - + + if (MistVideo.reporting) { + MistVideo.reporting.report({ + player: MistVideo.playerName, + sourceType: MistVideo.source.type, + sourceUrl: MistVideo.source.url, + pageUrl: location.href + }); + } + //build player MistVideo.player = new mistplayers[MistVideo.playerName].player(); @@ -416,6 +433,10 @@ function MistVideo(streamName,options) { MistVideo.container.removeAttribute("data-loading"); MistVideo.video = video; + + if (MistVideo.reporting) { + MistVideo.reporting.init(); + } if ("api" in MistVideo.player) { @@ -495,6 +516,11 @@ function MistVideo(streamName,options) { score = Math.max(score,list[list.length-1].score); this.vars.score = score; + + if (MistVideo.reporting) { + MistVideo.reporting.stats.set("playbackScore",Math.round(score*10)/10); + } + return score; }, valueToScore: function(a,b){ //calculate the moving average @@ -567,8 +593,7 @@ function MistVideo(streamName,options) { MistUtil.event.addListener(MistVideo.video,events[i],function(){ if (MistVideo.monitor) { MistVideo.monitor.reset(); } }); - } - + } } //remove placeholder and add UI structure @@ -874,6 +899,7 @@ function MistVideo(streamName,options) { MistUtil.event.send("initialized",null,options.target); MistVideo.log("Initialized"); + if (MistVideo.options.callback) { options.callback(MistVideo); } }); @@ -881,8 +907,8 @@ function MistVideo(streamName,options) { else if (MistVideo.options.startCombo) { //try again without a startCombo delete MistVideo.options.startCombo; - MistVideo.unload(); - MistVideo = mistPlay(MistVideo.stream,MistVideo.options); + MistVideo.unload("No compatible players found - retrying without startCombo."); + mistPlay(MistVideo.stream,MistVideo.options); } else { MistVideo.showError("No compatible player/source combo found.",{reload:true}); @@ -933,10 +959,188 @@ function MistVideo(streamName,options) { socket.die = false; socket.destroy = function(){ this.die = true; + this.onclose = function(){}; this.close(); }; socket.onopen = function(e){ this.wasConnected = true; + + //report player status to MistServer + if (!MistVideo.reporting) { + MistVideo.reporting = { + stats: { + set: function(key,value){ + this.d[key] = value; + }, + add: function(key,add){ + if (typeof add == "undefined") { add = 1; } + this.d[key] += add; + }, + 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(d){ + MistVideo.socket.send(JSON.stringify(d)); + }, + reportStats: function(){ + var d = {}; + var report = false; + var newlogs = MistVideo.logs.slice(this.stats.last.nLog); + for (var i in this.stats.d) { + if (this.stats.d[i] != this.stats.last[i]) { + d[i] = this.stats.d[i]; + this.stats.last[i] = d[i]; + report = true; + } + } + if (report) { + if (newlogs.length) { + d.logs = []; + for (var i in newlogs) { + d.logs.push(newlogs[i].message); + } + } + this.report(d); + } + MistVideo.timers.start(function(){ + MistVideo.reporting.reportStats(); + },5e3); + }, + init: function(){ + var video = MistVideo.video; + + var firstPlay = MistUtil.event.addListener(video,"playing",function(){ + MistVideo.reporting.stats.set("firstPlayback",new Date().getTime() - MistVideo.bootMs); + MistUtil.event.removeListener(firstPlay); + }); + + //set listeners for player reporting + MistUtil.event.addListener(video,"waiting",function(){ + MistVideo.reporting.stats.add("nWaiting"); + }); + MistUtil.event.addListener(video,"stalled",function(){ + MistVideo.reporting.stats.add("nStalled"); + }); + MistUtil.event.addListener(MistVideo.options.target,"error",function(e){ + MistVideo.reporting.stats.add("nError"); + MistVideo.reporting.stats.set("lastError",e.message); + }); + + if (Object && Object.defineProperty) { + var timeWaiting = 0; + var waitingSince = false; + var timeStalled = 0; + var stalledSince = false; + var timeUnpaused = 0; + var unpausedSince = false; + var d = MistVideo.reporting.stats.d; + Object.defineProperty(d,"timeWaiting",{ + get: function(){ + return timeWaiting + (waitingSince ? (new Date()).getTime() - waitingSince : 0); + } + }); + Object.defineProperty(d,"timeStalled",{ + get: function(){ + return timeStalled + (stalledSince ? (new Date()).getTime() - stalledSince : 0); + } + }); + Object.defineProperty(d,"timeUnpaused",{ + get: function(){ + return timeUnpaused + (unpausedSince ? (new Date()).getTime() - unpausedSince : 0); + } + }); + Object.defineProperty(d,"nLog",{ + get: function(){ + return MistVideo.logs.length; + } + }); + Object.defineProperty(d,"videoHeight",{ + get: function(){ + return MistVideo.video.videoHeight; + } + }); + Object.defineProperty(d,"videoWidth",{ + get: function(){ + return MistVideo.video.videoWidth; + } + }); + Object.defineProperty(d,"playerHeight",{ + get: function(){ + return MistVideo.video.clientHeight; + } + }); + Object.defineProperty(d,"playerWidth",{ + get: function(){ + return MistVideo.video.clientWidth; + } + }); + + MistUtil.event.addListener(video,"waiting",function(){ + timeWaiting = d.timeWaiting; //in case we get waiting several times in a row + waitingSince = (new Date()).getTime(); + }); + MistUtil.event.addListener(video,"stalled",function(){ + timeStalled = d.timeStalled; //in case we get stalled several times in a row + stalledSince = (new Date()).getTime(); + }); + var events = ["playing","pause"]; + for (var i in events) { + MistUtil.event.addListener(video,events[i],function(){ + timeWaiting = d.timeWaiting; + timeStalled = d.timeStalled; + waitingSince = false; + stalledSince = false; + }); + } + MistUtil.event.addListener(video,"playing",function(){ + timeUnpaused = d.timeUnpaused; //in case we get playing several times in a row + unpausedSince = (new Date()).getTime(); + }); + MistUtil.event.addListener(video,"pause",function(){ + timeUnpaused = d.timeUnpaused; + unpausedSince = false; + }); + + + + } + + + //periodically send the gathered stats + this.reportStats(); + + } + }; + } + }; socket.onclose = function(e){ if (this.die) { @@ -1063,7 +1267,7 @@ function MistVideo(streamName,options) { if ("source" in diff) { if ("error" in MistVideo.info) { - MistVideo.reload(); + MistVideo.reload("Reloading, stream info has error"); } return; } @@ -1090,11 +1294,11 @@ function MistVideo(streamName,options) { } break; } - case "width": - case "height": { - resized = true; - break; - } + case "width": + case "height": { + resized = true; + break; + } } } @@ -1111,6 +1315,8 @@ function MistVideo(streamName,options) { } }); + + } openSocket(); } @@ -1118,7 +1324,7 @@ function MistVideo(streamName,options) { openWithGet(); } - this.unload = function(){ + this.unload = function(reason){ if (this.destroyed) { return; } this.log("Unloading.."); @@ -1138,6 +1344,9 @@ function MistVideo(streamName,options) { MistVideo.monitor.destroy(); } if (this.socket) { + if (this.reporting) { + this.reporting.report({unload:reason ? reason : null}); + } this.socket.destroy(); } if ((this.player) && (this.player.api)) { @@ -1173,17 +1382,17 @@ function MistVideo(streamName,options) { delete this.video; }; - this.reload = function(){ + this.reload = function(reason){ var time = ("player" in this && "api" in this.player ? this.player.api.currentTime : false); - this.unload(); - MistVideo = mistPlay(this.stream,this.options); + this.unload(reason); + var NewMistVideo = mistPlay(this.stream,this.options); if ((time) && (this.info.type != "live")) { //after load, try to restore the video position var f = function(){ - if (MistVideo.player && MistVideo.player.api) { - MistVideo.player.api.currentTime = time; + if (NewMistVideo.player && NewMistVideo.player.api) { + NewMistVideo.player.api.currentTime = time; } this.removeEventListener("initialized",f); }; @@ -1212,7 +1421,7 @@ function MistVideo(streamName,options) { } } - this.unload(); + this.unload("nextCombo"); var opts = this.options; opts.startCombo = startCombo; MistVideo = mistPlay(this.stream,opts); diff --git a/embed/skins.js b/embed/skins.js index 2e883a18..3c8af2fa 100644 --- a/embed/skins.js +++ b/embed/skins.js @@ -357,9 +357,12 @@ MistSkins["default"] = { var promise = MistVideo.player.api.play(); if (promise) { - promise.catch(function(){ + promise.then(function(){ + if (MistVideo.reporting) { MistVideo.reporting.stats.d.autoplay = "success"; } + }).catch(function(){ if (MistVideo.destroyed) { return; } MistVideo.log("Autoplay failed even with muted video. Unmuting and showing play button."); + if (MistVideo.reporting) { MistVideo.reporting.stats.d.autoplay = "failed"; } MistVideo.player.api.muted = false; //play has failed @@ -388,6 +391,8 @@ MistSkins["default"] = { MistVideo.log("Autoplay worked! Video will be unmuted on mouseover if the page has been interacted with."); + if (MistVideo.reporting) { MistVideo.reporting.stats.d.autoplay = "muted"; } + //show large "muted" icon var largeMutedButton = MistVideo.skin.icons.build("muted",100); MistUtil.class.add(largeMutedButton,"mistvideo-pointer"); @@ -432,9 +437,11 @@ MistSkins["default"] = { },function(){}); } } + else if (MistVideo.reporting) { MistVideo.reporting.stats.d.autoplay = "failed"; } }); } } + else if (MistVideo.reporting) { MistVideo.reporting.stats.d.autoplay = "success"; } }); } @@ -1046,7 +1053,7 @@ MistSkins["default"] = { },button); //apply initial video state - var initevent = MistUtil.event.addListener(video,"loadstart",function(){ + var initevent = MistUtil.event.addListener(video,"loadedmetadata",function(){ if (('localStorage' in window) && (localStorage != null) && ('mistVolume' in localStorage)) { MistVideo.player.api.volume = localStorage['mistVolume']; } @@ -1953,7 +1960,7 @@ MistSkins["default"] = { type: "button", label: "Reload player", onclick: function(){ - MistVideo.reload(); + MistVideo.reload("Reloading because reload button was clicked."); } }; if (!isNaN(options.reload+"")) { obj.delay = options.reload; } @@ -2470,7 +2477,7 @@ MistSkins.dev = { MistUtil.event.addListener(select,"change",function(){ MistVideo.options.forcePlayer = (this.value == "" ? false : this.value); if (MistVideo.options.forcePlayer != MistVideo.playerName) { //only reload if there is a change - MistVideo.reload(); + MistVideo.reload("Reloading to force player."); } }); @@ -2512,7 +2519,7 @@ MistSkins.dev = { MistUtil.event.addListener(select,"change",function(){ MistVideo.options.forceType = (this.value == "" ? false : this.value); if ((!MistVideo.source) || (MistVideo.options.forceType != MistVideo.source.type)) { //only reload if there is a change - MistVideo.reload(); + MistVideo.reload("Reloading to force new type."); } }); @@ -2546,7 +2553,7 @@ MistSkins.dev = { MistUtil.event.addListener(select,"change",function(){ MistVideo.options.forceSource = (this.value == "" ? false : this.value); if (MistVideo.options.forceSource != MistVideo.source.index) { //only reload if there is a change - MistVideo.reload(); + MistVideo.reload("Reloading to force new source."); } }); @@ -2601,7 +2608,7 @@ MistSkins.dev.structure.submenu.children.unshift({ title: "Build MistVideo again", label: "MistVideo.reload();", onclick: function(){ - this.reload(); + this.reload("Dev-reload button clicked."); } },{ type: "button", diff --git a/embed/util.js b/embed/util.js index d7b795e5..3fc5395e 100644 --- a/embed/util.js +++ b/embed/util.js @@ -37,7 +37,7 @@ var MistUtil = { return string.charAt(0).toUpperCase()+string.slice(1); }, number: function(num) { - if ((isNaN(Number(num))) || (num == 0)) { return num; } + if ((isNaN(Number(num))) || (Number(num) == 0)) { return num; } //rounding //use a significance of three, but don't round "visible" digits @@ -58,10 +58,10 @@ var MistUtil = { return num; }, - bytes: function(val){ + bytes: function(val,bits){ if (isNaN(Number(val))) { return val; } - var suffix = ["bytes","KB","MB","GB","TB","PB"]; + var suffix = bits ? ["bits","Kb","Mb","Gb","Tb","Pb"] : ["bytes","KB","MB","GB","TB","PB"]; if (val == 0) { unit = suffix[0]; } @@ -77,6 +77,7 @@ var MistUtil = { } return this.number(val)+unit; }, + bits: function(val) { return this.bytes(val,true); }, mime2human: function(mime){ switch (mime) { case "html5/video/webm": { diff --git a/embed/wrappers/mews.js b/embed/wrappers/mews.js index 190054f2..a2c3b4cd 100644 --- a/embed/wrappers/mews.js +++ b/embed/wrappers/mews.js @@ -333,14 +333,45 @@ p.prototype.build = function (MistVideo,callback) { this.ws = new WebSocket(MistVideo.source.url); this.ws.binaryType = "arraybuffer"; + this.ws.s = this.ws.send; + this.ws.send = function(){ + if (this.readyState == 1) { + return this.s.apply(this,arguments); + } + return false; + }; this.ws.onopen = function(){ + this.wasConnected = true; resolve(); }; this.ws.onerror = function(e){ MistVideo.showError("MP4 over WS: websocket error"); - } + }; this.ws.onclose = function(e){ MistVideo.log("MP4 over WS: websocket closed"); + if (this.wasConnected && (!MistVideo.destroyed)) { + MistVideo.log("MP4 over WS: reopening websocket"); + player.wsconnect().then(function(){ + if (!player.sb) { + //retrieve codec info + var f = function(msg){ + //got codec data, set up source buffer + + if (!player.sb) { player.sbinit(msg.data.codecs); } + else { player.api.play(); } + + player.ws.removeListener("codec_data",f); + }; + player.ws.addListener("codec_data",f); + send({type:"request_codec_data",supported_codecs:MistVideo.source.supportedCodecs}); + } + else { + player.api.play(); + } + },function(){ + Mistvideo.error("Lost connection to the Media Server"); + }); + } }; this.ws.listeners = {}; //kind of event listener list for websocket messages this.ws.addListener = function(type,f){ @@ -367,6 +398,7 @@ p.prototype.build = function (MistVideo,callback) { //the last fragment has been added to the buffer var eObj; eObj = MistUtil.event.addListener(video,"waiting",function(e){ + player.sb.paused = true; MistUtil.event.send("ended",null,video); MistUtil.event.removeListener(eObj); }); @@ -378,7 +410,7 @@ p.prototype.build = function (MistVideo,callback) { var serverDelay = player.ws.serverDelay.get(); var desiredBuffer = Math.max(500+serverDelay,serverDelay*2); if (MistVideo.info.type != "live") { desiredBuffer += 2000; } //if VoD, keep an extra 2 seconds of buffer - if (player.debugging) console.log("on_time received",msg.data.current/1e3,"currtime",video.currentTime,requested_rate+"x","buffer",Math.round(buffer),"/",Math.round(desiredBuffer),(MistVideo.info.type == "live" ? "latency:"+Math.round(msg.data.end-video.currentTime*1e3)+"ms" : ""),"listeners",player.ws.listeners && player.ws.listeners.on_time ? player.ws.listeners.on_time : 0,"msgqueue",player.msgqueue ? player.msgqueue.length : 0,msg.data); + if (player.debugging) console.log("on_time received",msg.data.current/1e3,"currtime",video.currentTime,requested_rate+"x","buffer",Math.round(buffer),"/",Math.round(desiredBuffer),(MistVideo.info.type == "live" ? "latency:"+Math.round(msg.data.end-video.currentTime*1e3)+"ms" : ""),"bitrate:"+MistUtil.format.bits(player.monitor.currentBps)+"/s","listeners",player.ws.listeners && player.ws.listeners.on_time ? player.ws.listeners.on_time : 0,"msgqueue",player.msgqueue ? player.msgqueue.length : 0,msg.data); if (!player.sb) { MistVideo.log("Received on_time, but the source buffer is being cleared right now. Ignoring."); @@ -466,6 +498,11 @@ p.prototype.build = function (MistVideo,callback) { } } } + + if (MistVideo.reporting && msg.data.tracks) { + MistVideo.reporting.stats.d.tracks = msg.data.tracks.join(","); + } + break; } case "tracks": { @@ -605,6 +642,9 @@ p.prototype.build = function (MistVideo,callback) { } var data = new Uint8Array(e.data); if (data) { + for (var i in player.monitor.bitCounter) { + player.monitor.bitCounter[i] += e.data.byteLength*8; + } if ((player.sb) && (!player.msgqueue)) { if (player.sb.updating || player.sb.queue.length || player.sb._busy) { player.sb.queue.push(data); @@ -755,6 +795,7 @@ p.prototype.build = function (MistVideo,callback) { } else if (e.data.current > video.currentTime) { player.sb.paused = false; + video.currentTime = e.data.current*1e-3; video.play().then(resolve).catch(reject); player.ws.removeListener("on_time",f); } @@ -768,15 +809,13 @@ p.prototype.build = function (MistVideo,callback) { }, pause: function(){ video.pause(); - send({type: "hold",}); + send({type: "hold"}); if (player.sb) { player.sb.paused = true; } }, setTracks: function(obj){ obj.type = "tracks"; obj = MistUtil.object.extend({ type: "tracks", - audio: null, - video: null, seek_time: Math.max(0,video.currentTime*1e3-(500+player.ws.serverDelay.get())) },obj); send(obj); @@ -791,9 +830,7 @@ p.prototype.build = function (MistVideo,callback) { //it's okay if it fails } catch (e) { } }); - player.ws.close(); - delete window.mistMewsOnVisibilityChange; - document.removeEventListener("visibilitychange",onVisibilityChange); + player.ws.close(); } }; @@ -881,32 +918,6 @@ p.prototype.build = function (MistVideo,callback) { }); } }); - //pause if tab is hidden to prevent buildup of frames - var autopaused = false; - //only add this once! - function onVisibilityChange() { - if (document.hidden) { - //check if we are playing (not video.paused! that already returns true) - if (!player.sb.paused) { - player.api.pause(); - autopaused = true; - if (MistVideo.info.type == "live") { - autopaused = "live"; //go to live point - //NB: even if the player wasn't near the live point when it was paused, we've likely exited the buffer while we were paused, so the current position probably won't exist anymore. Just skip to live. - } - MistVideo.log("Pausing the player as the tab is inactive."); - } - } - else if (autopaused) { - player.api.play(autopaused == "live"); - autopaused = false; - MistVideo.log("Restarting the player as the tab is now active again."); - } - } - if (!window.mistMewsOnVisibilityChange) { - window.mistMewsOnVisibilityChange = true; - document.addEventListener("visibilitychange",onVisibilityChange); - } var seeking = false; MistUtil.event.addListener(video,"seeking",function(){ @@ -927,6 +938,19 @@ p.prototype.build = function (MistVideo,callback) { } } }); + MistUtil.event.addListener(video,"pause",function(){ + if (player.sb && !player.sb.paused) { + MistVideo.log("The browser paused the vid - probably because it has no audio and the tab is no longer visible. Pausing download."); + send({type:"hold"}); + player.sb.paused = true; + var p = MistUtil.event.addListener(video,"play",function(){ + if (player.sb && player.sb.paused) { + send({type:"play"}); + } + MistUtil.event.removeListener(p); + }); + } + }); if (player.debugging) { MistUtil.event.addListener(video,"waiting",function(){ @@ -949,4 +973,54 @@ p.prototype.build = function (MistVideo,callback) { }); } + + //ABR: monitor playback issues and switch to lower bitrate track if available + this.monitor = { + bitCounter: [], + bitsSince: [], + currentBps: null, + nWaiting: 0, + nWaitingThreshold: 3, + listener: MistUtil.event.addListener(video,"waiting",function(){ + player.monitor.nWaiting++; + + if (player.monitor.nWaiting >= player.monitor.nWaitingThreshold) { + player.monitor.nWaiting = 0; + MistVideo.log("ABR threshold triggered, requesting lower quality"); + player.monitor.action(); + } + }), + getBitRate: function(){ + if (player.sb && !player.sb.paused) { + + this.bitCounter.push(0); + this.bitsSince.push(new Date().getTime()); + + //calculate current bitrate + var bits, since; + if (this.bitCounter.length > 5) { + bits = player.monitor.bitCounter.shift(); + since = this.bitsSince.shift(); + } + else { + bits = player.monitor.bitCounter[0]; + since = this.bitsSince[0]; + } + var dt = new Date().getTime() - since; + this.currentBps = bits / (dt*1e-3); + + //console.log(MistUtil.format.bytes(this.currentBps)+"its/s"); + + } + + MistVideo.timers.start(function(){ + player.monitor.getBitRate(); + },500); + }, + action: function(){ + player.api.setTracks({video:"max<"+Math.round(this.currentBps)+"bps"}); + } + }; + + this.monitor.getBitRate(); }; diff --git a/embed/wrappers/webrtc.js b/embed/wrappers/webrtc.js index 6a0026f8..f2520415 100644 --- a/embed/wrappers/webrtc.js +++ b/embed/wrappers/webrtc.js @@ -157,6 +157,10 @@ p.prototype.build = function (MistVideo,callback) { currenttracks = ev.tracks; } + + if (MistVideo.reporting && ev.tracks) { + MistVideo.reporting.stats.d.tracks = ev.tracks.join(","); + } }, on_seek: function(e){ var thisPlayer = this; @@ -276,7 +280,7 @@ p.prototype.build = function (MistVideo,callback) { if (callback) { callback(); } }; thisWebRTCPlayer.peerConn.onconnectionstatechange = function(e){ - if (this.destroyed) { return; } //the player doesn't exist any more + if (MistVideo.destroyed) { return; } //the player doesn't exist any more switch (this.connectionState) { case "failed": { //WebRTC will never work (firewall maybe?) @@ -296,7 +300,7 @@ p.prototype.build = function (MistVideo,callback) { } }; thisWebRTCPlayer.peerConn.oniceconnectionstatechange = function(e){ - if (this.destroyed) { return; } //the player doesn't exist any more + if (MistVideo.destroyed) { return; } //the player doesn't exist any more switch (this.iceConnectionState) { case "failed": { MistVideo.showError("ICE connection "+this.iceConnectionState); @@ -722,6 +726,7 @@ p.prototype.build = function (MistVideo,callback) { try { me.webrtc.stop(); me.webrtc.signaling.ws.close(); + me.webrtc.peerConn.close(); } catch (e) {} };