From 6db9a9ad177b23a15c195f7f330d3e33adc1f7bb Mon Sep 17 00:00:00 2001 From: Cat Date: Tue, 5 Feb 2019 16:29:32 +0100 Subject: [PATCH 1/3] Embed: track idx compatibility for 3.0 --- embed/imgs/tmp.svg | 2 ++ embed/min/player.js | 2 +- embed/min/wrappers/dashjs.js | 2 +- embed/player.js | 4 ++-- embed/skins.js | 8 ++++---- embed/util.js | 2 +- embed/wrappers/dashjs.js | 10 ++++++---- 7 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 embed/imgs/tmp.svg diff --git a/embed/imgs/tmp.svg b/embed/imgs/tmp.svg new file mode 100644 index 00000000..a21a789d --- /dev/null +++ b/embed/imgs/tmp.svg @@ -0,0 +1,2 @@ + + diff --git a/embed/min/player.js b/embed/min/player.js index 7f831612..155e3036 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),o=Math.round(e%1*1e3);e=Math.floor(e-60*a);var s=[];return r&&(r=r+" day"+(r>1?"s":"")+", "),n||r?(s.push(n),s.push(("0"+a).slice(-2))):s.push(a),s.push(("0"+Math.floor(e)).slice(-2)),t.ms&&(s[s.length-1]+="."+("000"+o).slice(-3)),(r||"")+s.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";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-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=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 o in t){var s=t[o];if(0!=(a=i(r(s,e),r(s,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&&(a.onerror=function(){n(a)})},n&&(a.onerror=function(){n(a)},a.ontimeout=a.onerror),"POST"==e){var o,s=[];for(var l in i)s.push(l+"="+encodeURIComponent(i[l]));s.length&&(o=s.join("&")),a.send(o)}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:"")}}},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}return e in n?n[e]instanceof Array?n[e].push(a):a(n[e]):(n[e]=[a],MistUtil.http.get(e,function(t){for(var i in n[e])n[e][i](t);n[e]=t},function(){throw"Failed to load CSS from "+e})),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 a in e=e.replace(/[^@]*?{[^]*?}/g,function(e){var r=e.split("{"),n=r[0].split(","),a="{"+r.slice(1).join("}");for(var o in n){n[o]=n[o].trim();var s="."+t+n[o];i&&(s+=",\n."+t+" "+n[o]),n[o]=s}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{(r=new Event(e,{bubbles:!0,cancelable:!0})).message=t,i.dispatchEvent(r)}catch(n){try{var r;(r=document.createEvent("Event")).initEvent(e,!0,!0),r.message=t,i.dispatchEvent(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.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,o,s,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][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 o;if(r.bps>0)o=r.bps>131072?Math.round(r.bps/1024/1024*8)+"mbps":Math.round(r.bps/1024*8)+"kbps",n[a]=o;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 s in t){var l=!1;for(var i in t[s])if(l){if(MistUtil.object.keys(t[s]).length>1)for(var a in t[s][i].describe)l[a]!=t[s][i].describe[a]&&delete l[a]}else l=MistUtil.object.extend({},t[s][i].describe);for(var i in t[s]){var c={},d={};for(var a in t[s][i].describe)a in l?d[a]=t[s][i].describe[a]:c[a]=t[s][i].describe[a];t[s][i].different=c,t[s][i].same=d;var u=MistUtil.object.values(c);t[s][i].displayName=u.length?u.join(", "):MistUtil.object.values(t[s][i].describe).join(" ")}var p={};for(var i in t[s]){if(t[s][i].displayName in p){var h=1;for(var i in t[s])t[s][i].different.trackid=h+")",t[s][i].displayName="Track "+h+" ("+t[s][i].displayName+")",h++;break}p[t[s][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,o=Math.max(0,(t.clientX/i-n)/a);return o=Math.min(o,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 o=1;ot.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"}};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 o="";o+='',o+='',o+=n,o+="",o+="";var s=document.createElement("div");return s.innerHTML=o,s.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)"string"==typeof this.css[i]&&t.push(MistUtil.css.load(e.urlappend(this.css[i]),this.colors));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 o=MistUtil.css.createStyle(t.css[r],a);n.appendChild(o)}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 s=this.buildStructure(t.children[r]);s&&n.appendChild(s)}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=e.skin.css.length;for(var a in n&&(i.style.opacity="0"),e.skin.css){var o=e.skin.css[a];o.callback=function(e){this.textContent=MistUtil.css.prependClass(e,r,!0),--n<=0&&(i.style.opacity="")},""!=o.textContent&&o.callback(o.textContent),i.appendChild(o)}MistUtil.class.add(i,r);var s=MistUtil.getBrowser();return s&&MistUtil.class.add(i,"browser-"+s),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}}]},{type:"speaker",classse:["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"},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:''},largeplay:{size:45,svg:''},pause:{size:45,svg:''},speaker:{size:45,svg:''},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return''}},muted:{size:45,svg:''},fullscreen:{size:45,svg:''},loop:{size:45,svg:''},settings:{size:45,svg:''},loading:{size:100,svg:''},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return''}},popout:{size:45,svg:''},switchvideo:{size:45,svg:''}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;return MistUtil.event.addListener(e.video,"contextmenu",function(t){t.preventDefault(),e.container.setAttribute("data-show-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||(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)}})}})}}),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"),o=0;o30)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 .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);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"},o=function(e){window.removeEventListener("mousemove",a),window.removeEventListener("click",o),MistUtil.event.addListener(r,"click",s)},s=function(e){e.stopPropagation(),r.removeEventListener("click",s),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",o,t)};return MistUtil.event.addListener(r,"click",s),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.player.api,n=this;t.updateBar=function(e){if(this.kids.bar){if(!isFinite(r.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.duration))return 0;var t=0;if("live"==n.info.type){var i=.001*n.info.meta.buffer_window;t=(e-r.duration+i)/i}else t=e/r.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.5?(r.right=100*(1-i)+"%",a.triangle.setMode("bottom","right")):(r.left=100*i+"%",a.triangle.setMode("bottom","left")),a.setPos(r)}else a.style.opacity=0},MistUtil.event.addListener(e,"mousemove",function(e){t.moveTooltip(e)});var o=!1;return MistUtil.event.addListener(e,"mousedown",function(i){if(1==i.which){o=!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&&(o=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),a.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")},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.player.api&&MistUtil.event.addListener(e.video,"click",function(){e.player.api.paused?e.player.api.play():MistUtil.isTouchDevice()||e.player.api.pause()},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 o=this;a.mode="mode"in e?e.mode:"vertical","vertical"==a.mode&&(a.style.transform="rotate(90deg)"),a.margin={start:.15,end:.1};var s=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;ii(t)?1:i(e)t[i]?1:t[e]1&&"player"in e&&"api"in e.player&&("setTrack"in e.player.api||"setTracks"in e.player.api||"setSource"in e.player.api)){var b=document.createElement("select");if(b.title="Select another "+l+" track",r[l]=b,b.trackType=l,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)(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),m.appendChild(document.createTextNode(k.join(" ")));var w=MistUtil.object.keys(c,function(e,t){return Number(e)-Number(t)});for(var u in w){var U=c[w[u]];M=document.createElement("option");b.appendChild(M),M.value=U.trackid,MistUtil.object.keys(U.different).length?M.appendChild(document.createTextNode(g(U.different).join(" "))):M.appendChild(document.createTextNode("Track "+(Number(u)+1)))}if("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 x=document.createEvent("Event");x.initEvent("change"),b.dispatchEvent(x);break}}else MistUtil.event.addListener(b,"change",function(){this.trackType in n&&(n[this.trackType].checked=!0),a(this.trackType,this.value)}),MistUtil.event.addListener(e.video,"playerUpdate_trackChanged",function(t){t.message.type==l&&(b.value=t.message.trackid,e.log("Player selected "+l+" track with id "+t.message.trackid))},b)}else{var C;(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),C.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 o in a)MistUtil.event.addListener(e.video,a[o],function(t){!this.paused&&"container"in e&&r(t)},t);a=["seeked","playing","canplay","paused"];for(var o in a)MistUtil.event.addListener(e.video,a[o],function(t){"container"in e&&n()},t),MistUtil.event.addListener(e.video,"progress",function(t){"container"in e&&"monitor"in e&&"vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.score>.99&&n()},t)}return t},error:function(){var e=this,t=document.createElement("div");t.message=function(t,i,r){MistUtil.empty(this);var n=document.createElement("div");if(n.className="message",this.appendChild(n),!r.polling&&!r.passive){var a=document.createElement("h3");n.appendChild(a),a.appendChild(document.createTextNode("The player has encountered a problem"))}var o=document.createElement("p");if(n.appendChild(o),n.update=function(e){MistUtil.empty(o),o.appendChild(document.createTextNode(e))},t){e.info.on_error&&(t=e.info.on_error.replace(/\/,t)),n.update(t);var s=document.createElement("p");if(s.className="details mistvideo-description",n.appendChild(s),i)s.appendChild(document.createTextNode(i));else if("decodingIssues"in e.skin.blueprints){if("player"in e&&"api"in e.player){if(i=[],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]))}}s.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(o,s){s||(s={softReload:!(!e.video||!e.video.load),reload:!0,nextCombo:!!e.info,polling:!1,passive:!1});var l=s.type?s.type:o;if(!(l in a)){if(!0===s.reload&&(e.options.reloadDelay&&!isNaN(Number(e.options.reloadDelay))?s.reload=Number(e.options.reloadDelay):s.reload=10),s.passive){if(!0===r)return;if(r)return i.update(o),void(n=(new Date).getTime());t.setAttribute("data-passive","")}else t.removeAttribute("data-passive");r=!s.passive||"passive",n=(new Date).getTime(),this.log(o,"error");var c=t.message(o,!1,s);i=c;var d=document.createElement("div");if(d.className="mistvideo-buttoncontainer",c.appendChild(d),MistUtil.empty(d),s.softReload){var u={type:"button",label:"Reload video",onclick:function(){e.player.api.load()}};isNaN(s.softReload+"")||(u.delay=s.softReload),d.appendChild(e.UI.buildStructure(u))}if(s.reload){u={type:"button",label:"Reload player",onclick:function(){e.reload()}};isNaN(s.reload+"")||(u.delay=s.reload),d.appendChild(e.UI.buildStructure(u))}if(s.nextCombo){u={type:"button",label:"Next source",onclick:function(){e.nextCombo()}};isNaN(s.nextCombo+"")||(u.delay=s.nextCombo),d.appendChild(e.UI.buildStructure(u))}if(s.ignore){u={type:"button",label:"Ignore",onclick:function(){this.clearError(),a[l]=!0}};isNaN(s.ignore+"")||(u.delay=s.ignore),d.appendChild(e.UI.buildStructure(u))}s.polling&&d.appendChild(e.UI.buildStructure({type:"polling"})),MistUtil.class.add(t,"show"),"container"in e&&e.container.removeAttribute("data-loading")}},t.clear=function(i){for(var n=t.querySelectorAll("svg.icon.timeout"),a=0;a=t.scrollHeight-5}),r.logs)s(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),s(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),s(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)}},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 o=document.createTextNode(e.value?e.value:"");a.appendChild(o);var s=document.createElement("span");a.appendChild(s),i.set=function(e){if(0!==e&&(this.style.display=""),"object"==typeof e){if("val"in e&&(o.nodeValue=e.val,a.className="value"),s.children.length)return(t=s.children[0]).addData(e);var t=MistUtil.createGraph({x:[e.x],y:[e.y]},e.options);return s.style.display="",MistUtil.empty(s),s.appendChild(t)}return o.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 o in t.info.source){var s=t.info.source[o];if(!(s.type in a)){a[s.type]=1;n=document.createElement("option");r.appendChild(n),n.value=s.type,n.appendChild(document.createTextNode(MistUtil.format.mime2human(s.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 o=t.info.source[a];n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(o.url+" ("+MistUtil.format.mime2human(o.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:[{if:function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"video.load();",onclick:function(){this.player.api.load()}}},{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.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=data.error;return"on_error"in e&&(i.log(n),n=data.on_error),void i.showError(n,{reload:!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("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 o="maxwidth"in t&&t.maxwidth?t.maxwidth:window.innerWidth,s="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),o&&r>o&&l(r/o),s&&n>s&&l(n/s)}}}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 o in i.info.meta.tracks)a=Math.max(a,i.info.meta.tracks[o].lastms);e.lastms=a}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.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?.97:.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=2))for(var u in l[s.inner].list)if(l[s.inner].current=u,!(c(s.inner)>=1)){a=l.source.list[l.source.current];var p=l.player.list[l.player.current],h=mistplayers[p];if(h.isMimeSupported(a.type)&&h.isBrowserSupported(a.type,a,i))return{player:p,source:a,source_index:l.source.current};t||i.log("Checking "+h.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 a=i.options.host.replace(/^http/i,"ws"),o=new WebSocket(i.urlappend(a+"/json_"+encodeURIComponent(i.stream)+".js"));i.socket=o,o.die=!1,o.destroy=function(){this.die=!0,this.close()},o.onopen=function(e){this.wasConnected=!0},o.onclose=function(r){if(!this.die){if(this.wasConnected)return i.log("Reopening websocket.."),void 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"))}},o.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),t.error){case"Stream is offline":i.info=!1;case"Stream is initializing":case"Stream is booting":case"Stream is waiting for data":case"Stream is shutting down":a={polling:!0};break;default:a={reload:!0}}i.showError(e,a)}else{if(!i.info)return void n(t);var o=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(o){if("source"in o)return void("error"in i.info&&i.reload());i.info=MistUtil.object.extend(i.info,t),i.info.updated=new Date;var s=!1;for(var l in o)switch(l){case"meta":for(var c in o[l])switch(c){case"tracks":i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",t,i.video)}break;case"width":case"height":s=!0}s&&i.player.resize()}else i.log("Metachange: no differences detected")}})}()}else{var a=this.urlappend(t.host+"/json_"+encodeURIComponent(this.stream)+".js");this.log("Requesting stream info from "+a),MistUtil.http.get(a,function(e){i.destroyed||n(JSON.parse(e))},function(e){var r="Connection failed (failed to load "+a+")";i.showError(r,{reload:!0}),MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed")})}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){}if(this.UI&&this.UI.elements)for(var e in this.UI.elements){var n=this.UI.elements[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),o=Math.round(e%1*1e3);e=Math.floor(e-60*a);var s=[];return r&&(r=r+" day"+(r>1?"s":"")+", "),n||r?(s.push(n),s.push(("0"+a).slice(-2))):s.push(a),s.push(("0"+Math.floor(e)).slice(-2)),t.ms&&(s[s.length-1]+="."+("000"+o).slice(-3)),(r||"")+s.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";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-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=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 o in t){var s=t[o];if(0!=(a=i(r(s,e),r(s,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&&(a.onerror=function(){n(a)})},n&&(a.onerror=function(){n(a)},a.ontimeout=a.onerror),"POST"==e){var o,s=[];for(var l in i)s.push(l+"="+encodeURIComponent(i[l]));s.length&&(o=s.join("&")),a.send(o)}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:"")}}},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}return e in n?n[e]instanceof Array?n[e].push(a):a(n[e]):(n[e]=[a],MistUtil.http.get(e,function(t){for(var i in n[e])n[e][i](t);n[e]=t},function(){throw"Failed to load CSS from "+e})),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 a in e=e.replace(/[^@]*?{[^]*?}/g,function(e){var r=e.split("{"),n=r[0].split(","),a="{"+r.slice(1).join("}");for(var o in n){n[o]=n[o].trim();var s="."+t+n[o];i&&(s+=",\n."+t+" "+n[o]),n[o]=s}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{(r=new Event(e,{bubbles:!0,cancelable:!0})).message=t,i.dispatchEvent(r)}catch(n){try{var r;(r=document.createEvent("Event")).initEvent(e,!0,!0),r.message=t,i.dispatchEvent(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.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,o,s,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 o;if(r.bps>0)o=r.bps>131072?Math.round(r.bps/1024/1024*8)+"mbps":Math.round(r.bps/1024*8)+"kbps",n[a]=o;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 s in t){var l=!1;for(var i in t[s])if(l){if(MistUtil.object.keys(t[s]).length>1)for(var a in t[s][i].describe)l[a]!=t[s][i].describe[a]&&delete l[a]}else l=MistUtil.object.extend({},t[s][i].describe);for(var i in t[s]){var c={},d={};for(var a in t[s][i].describe)a in l?d[a]=t[s][i].describe[a]:c[a]=t[s][i].describe[a];t[s][i].different=c,t[s][i].same=d;var u=MistUtil.object.values(c);t[s][i].displayName=u.length?u.join(", "):MistUtil.object.values(t[s][i].describe).join(" ")}var p={};for(var i in t[s]){if(t[s][i].displayName in p){var h=1;for(var i in t[s])t[s][i].different.trackid=h+")",t[s][i].displayName="Track "+h+" ("+t[s][i].displayName+")",h++;break}p[t[s][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,o=Math.max(0,(t.clientX/i-n)/a);return o=Math.min(o,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 o=1;ot.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"}};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 o="";o+='',o+='',o+=n,o+="",o+="";var s=document.createElement("div");return s.innerHTML=o,s.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)"string"==typeof this.css[i]&&t.push(MistUtil.css.load(e.urlappend(this.css[i]),this.colors));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 o=MistUtil.css.createStyle(t.css[r],a);n.appendChild(o)}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 s=this.buildStructure(t.children[r]);s&&n.appendChild(s)}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=e.skin.css.length;for(var a in n&&(i.style.opacity="0"),e.skin.css){var o=e.skin.css[a];o.callback=function(e){this.textContent=MistUtil.css.prependClass(e,r,!0),--n<=0&&(i.style.opacity="")},""!=o.textContent&&o.callback(o.textContent),i.appendChild(o)}MistUtil.class.add(i,r);var s=MistUtil.getBrowser();return s&&MistUtil.class.add(i,"browser-"+s),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}}]},{type:"speaker",classse:["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"},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:''},largeplay:{size:45,svg:''},pause:{size:45,svg:''},speaker:{size:45,svg:''},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return''}},muted:{size:45,svg:''},fullscreen:{size:45,svg:''},loop:{size:45,svg:''},settings:{size:45,svg:''},loading:{size:100,svg:''},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return''}},popout:{size:45,svg:''},switchvideo:{size:45,svg:''}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;return MistUtil.event.addListener(e.video,"contextmenu",function(t){t.preventDefault(),e.container.setAttribute("data-show-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||(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)}})}})}}),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"),o=0;o30)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 .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);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"},o=function(e){window.removeEventListener("mousemove",a),window.removeEventListener("click",o),MistUtil.event.addListener(r,"click",s)},s=function(e){e.stopPropagation(),r.removeEventListener("click",s),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",o,t)};return MistUtil.event.addListener(r,"click",s),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.player.api,n=this;t.updateBar=function(e){if(this.kids.bar){if(!isFinite(r.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.duration))return 0;var t=0;if("live"==n.info.type){var i=.001*n.info.meta.buffer_window;t=(e-r.duration+i)/i}else t=e/r.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.5?(r.right=100*(1-i)+"%",a.triangle.setMode("bottom","right")):(r.left=100*i+"%",a.triangle.setMode("bottom","left")),a.setPos(r)}else a.style.opacity=0},MistUtil.event.addListener(e,"mousemove",function(e){t.moveTooltip(e)});var o=!1;return MistUtil.event.addListener(e,"mousedown",function(i){if(1==i.which){o=!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&&(o=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),a.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")},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.player.api&&MistUtil.event.addListener(e.video,"click",function(){e.player.api.paused?e.player.api.play():MistUtil.isTouchDevice()||e.player.api.pause()},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 o=this;a.mode="mode"in e?e.mode:"vertical","vertical"==a.mode&&(a.style.transform="rotate(90deg)"),a.margin={start:.15,end:.1};var s=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;ii(t)?1:i(e)t[i]?1:t[e]1&&"player"in e&&"api"in e.player&&("setTrack"in e.player.api||"setTracks"in e.player.api||"setSource"in e.player.api)){var b=document.createElement("select");if(b.title="Select another "+l+" track",r[l]=b,b.trackType=l,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)(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),m.appendChild(document.createTextNode(k.join(" ")));var w=MistUtil.object.keys(c,function(e,t){return Number(e)-Number(t)});for(var u in w){var U=c[w[u]];M=document.createElement("option");b.appendChild(M),M.value="idx"in U?U.idx:U.trackid,MistUtil.object.keys(U.different).length?M.appendChild(document.createTextNode(g(U.different).join(" "))):M.appendChild(document.createTextNode("Track "+(Number(u)+1)))}if("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 x=document.createEvent("Event");x.initEvent("change"),b.dispatchEvent(x);break}}else MistUtil.event.addListener(b,"change",function(){this.trackType in n&&(n[this.trackType].checked=!0),a(this.trackType,this.value)}),MistUtil.event.addListener(e.video,"playerUpdate_trackChanged",function(t){t.message.type==l&&(b.value=t.message.trackid,e.log("Player selected "+l+" track with id "+t.message.trackid))},b)}else{var C;(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),C.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 o in a)MistUtil.event.addListener(e.video,a[o],function(t){!this.paused&&"container"in e&&r(t)},t);a=["seeked","playing","canplay","paused"];for(var o in a)MistUtil.event.addListener(e.video,a[o],function(t){"container"in e&&n()},t),MistUtil.event.addListener(e.video,"progress",function(t){"container"in e&&"monitor"in e&&"vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.score>.99&&n()},t)}return t},error:function(){var e=this,t=document.createElement("div");t.message=function(t,i,r){MistUtil.empty(this);var n=document.createElement("div");if(n.className="message",this.appendChild(n),!r.polling&&!r.passive){var a=document.createElement("h3");n.appendChild(a),a.appendChild(document.createTextNode("The player has encountered a problem"))}var o=document.createElement("p");if(n.appendChild(o),n.update=function(e){MistUtil.empty(o),o.appendChild(document.createTextNode(e))},t){e.info.on_error&&(t=e.info.on_error.replace(/\/,t)),n.update(t);var s=document.createElement("p");if(s.className="details mistvideo-description",n.appendChild(s),i)s.appendChild(document.createTextNode(i));else if("decodingIssues"in e.skin.blueprints){if("player"in e&&"api"in e.player){if(i=[],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]))}}s.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(o,s){s||(s={softReload:!(!e.video||!e.video.load),reload:!0,nextCombo:!!e.info,polling:!1,passive:!1});var l=s.type?s.type:o;if(!(l in a)){if(!0===s.reload&&(e.options.reloadDelay&&!isNaN(Number(e.options.reloadDelay))?s.reload=Number(e.options.reloadDelay):s.reload=10),s.passive){if(!0===r)return;if(r)return i.update(o),void(n=(new Date).getTime());t.setAttribute("data-passive","")}else t.removeAttribute("data-passive");r=!s.passive||"passive",n=(new Date).getTime(),this.log(o,"error");var c=t.message(o,!1,s);i=c;var d=document.createElement("div");if(d.className="mistvideo-buttoncontainer",c.appendChild(d),MistUtil.empty(d),s.softReload){var u={type:"button",label:"Reload video",onclick:function(){e.player.api.load()}};isNaN(s.softReload+"")||(u.delay=s.softReload),d.appendChild(e.UI.buildStructure(u))}if(s.reload){u={type:"button",label:"Reload player",onclick:function(){e.reload()}};isNaN(s.reload+"")||(u.delay=s.reload),d.appendChild(e.UI.buildStructure(u))}if(s.nextCombo){u={type:"button",label:"Next source",onclick:function(){e.nextCombo()}};isNaN(s.nextCombo+"")||(u.delay=s.nextCombo),d.appendChild(e.UI.buildStructure(u))}if(s.ignore){u={type:"button",label:"Ignore",onclick:function(){this.clearError(),a[l]=!0}};isNaN(s.ignore+"")||(u.delay=s.ignore),d.appendChild(e.UI.buildStructure(u))}s.polling&&d.appendChild(e.UI.buildStructure({type:"polling"})),MistUtil.class.add(t,"show"),"container"in e&&e.container.removeAttribute("data-loading")}},t.clear=function(i){for(var n=t.querySelectorAll("svg.icon.timeout"),a=0;a=t.scrollHeight-5}),r.logs)s(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),s(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),s(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)}},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 o=document.createTextNode(e.value?e.value:"");a.appendChild(o);var s=document.createElement("span");a.appendChild(s),i.set=function(e){if(0!==e&&(this.style.display=""),"object"==typeof e){if("val"in e&&(o.nodeValue=e.val,a.className="value"),s.children.length)return(t=s.children[0]).addData(e);var t=MistUtil.createGraph({x:[e.x],y:[e.y]},e.options);return s.style.display="",MistUtil.empty(s),s.appendChild(t)}return o.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 o in t.info.source){var s=t.info.source[o];if(!(s.type in a)){a[s.type]=1;n=document.createElement("option");r.appendChild(n),n.value=s.type,n.appendChild(document.createTextNode(MistUtil.format.mime2human(s.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 o=t.info.source[a];n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(o.url+" ("+MistUtil.format.mime2human(o.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:[{if:function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"video.load();",onclick:function(){this.player.api.load()}}},{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.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=data.error;return"on_error"in e&&(i.log(n),n=data.on_error),void i.showError(n,{reload:!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("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 o="maxwidth"in t&&t.maxwidth?t.maxwidth:window.innerWidth,s="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),o&&r>o&&l(r/o),s&&n>s&&l(n/s)}}}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 o in i.info.meta.tracks)a=Math.max(a,i.info.meta.tracks[o].lastms);e.lastms=a}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.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?.97:.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=2))for(var u in l[s.inner].list)if(l[s.inner].current=u,!(c(s.inner)>=1)){a=l.source.list[l.source.current];var p=l.player.list[l.player.current],h=mistplayers[p];if(h.isMimeSupported(a.type)&&h.isBrowserSupported(a.type,a,i))return{player:p,source:a,source_index:l.source.current};t||i.log("Checking "+h.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 a=i.options.host.replace(/^http/i,"ws"),o=new WebSocket(i.urlappend(a+"/json_"+encodeURIComponent(i.stream)+".js"));i.socket=o,o.die=!1,o.destroy=function(){this.die=!0,this.close()},o.onopen=function(e){this.wasConnected=!0},o.onclose=function(r){if(!this.die){if(this.wasConnected)return i.log("Reopening websocket.."),void 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"))}},o.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),t.error){case"Stream is offline":i.info=!1;case"Stream is initializing":case"Stream is booting":case"Stream is waiting for data":case"Stream is shutting down":a={polling:!0};break;default:a={reload:!0}}i.showError(e,a)}else{if(!i.info)return void n(t);var o=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(o){if("source"in o)return void("error"in i.info&&i.reload());i.info=MistUtil.object.extend(i.info,t),i.info.updated=new Date;var s=!1;for(var l in o)switch(l){case"meta":for(var c in o[l])switch(c){case"tracks":i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",t,i.video)}break;case"width":case"height":s=!0}s&&i.player.resize()}else i.log("Metachange: no differences detected")}})}()}else{var a=this.urlappend(t.host+"/json_"+encodeURIComponent(this.stream)+".js");this.log("Requesting stream info from "+a),MistUtil.http.get(a,function(e){i.destroyed||n(JSON.parse(e))},function(e){var r="Connection failed (failed to load "+a+")";i.showError(r,{reload:!0}),MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed")})}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){}if(this.UI&&this.UI.elements)for(var e in this.UI.elements){var n=this.UI.elements[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 diff --git a/embed/min/wrappers/dashjs.js b/embed/min/wrappers/dashjs.js index 4d8753b1..abdb1217 100644 --- a/embed/min/wrappers/dashjs.js +++ b/embed/min/wrappers/dashjs.js @@ -1 +1 @@ -mistplayers.dashjs={name:"Dash.js player",mimes:["dash/video/mp4"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return MistUtil.array.indexOf(this.mimes,t)==-1?false:true},isBrowserSupported:function(t,e,i){if(location.protocol!=MistUtil.http.url.split(e.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(location.protocol=="file:"){i.log("This source ("+t+") won't load if the page is run via file://");return false}return"MediaSource"in window},player:function(){this.onreadylist=[]},scriptsrc:function(t){return t+"/dashjs.js"}};var p=mistplayers.dashjs.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var i=this;this.onDashLoad=function(){if(t.destroyed){return}t.log("Building DashJS player..");var r=document.createElement("video");if("Proxy"in window){var a={get:{},set:{}};t.player.api=new Proxy(r,{get:function(t,e,i){if(e in a.get){return a.get[e].apply(t,arguments)}var r=t[e];if(typeof r==="function"){return function(){return r.apply(t,arguments)}}return r},set:function(t,e,i){if(e in a.set){return a.set[e].call(t,i)}return t[e]=i}});if(t.info.type=="live"){a.get.duration=function(){var e=0;if(this.buffered.length){e=this.buffered.end(this.buffered.length-1)}var i=((new Date).getTime()-t.player.api.lastProgress.getTime())*.001;return e+i+-1*t.player.api.liveOffset+45};a.set.currentTime=function(e){var i=e-t.player.api.duration;t.log("Seeking to "+MistUtil.format.time(e)+" ("+Math.round(i*-10)/10+"s from live)");t.video.currentTime=e};MistUtil.event.addListener(r,"progress",function(){t.player.api.lastProgress=new Date});t.player.api.lastProgress=new Date;t.player.api.liveOffset=0}}else{i.api=r}if(t.options.autoplay){r.setAttribute("autoplay","")}if(t.options.loop&&t.info.type!="live"){r.setAttribute("loop","")}if(t.options.poster){r.setAttribute("poster",t.options.poster)}if(t.options.muted){r.muted=true}if(t.options.controls=="stock"){r.setAttribute("controls","")}var s=dashjs.MediaPlayer().create();s.initialize(r,t.source.url,t.options.autoplay);i.dash=s;var n=["METRIC_ADDED","METRIC_CHANGED","METRICS_CHANGED","FRAGMENT_LOADING_STARTED","FRAGMENT_LOADING_COMPLETED","LOG","PLAYBACK_TIME_UPDATED","PLAYBACK_PROGRESS"];for(var o in dashjs.MediaPlayer.events){if(n.indexOf(o)<0){i.dash.on(dashjs.MediaPlayer.events[o],function(e){t.log("Player event fired: "+e.type)})}}t.player.setSize=function(t){this.api.style.width=t.width+"px";this.api.style.height=t.height+"px"};t.player.api.setSource=function(e){t.player.dash.attachSource(e)};t.player.api.setTrack=function(e,r){var a=MistUtil.tracks.parse(t.info.meta.tracks);if(!(e in a)||!(r in a[e])&&r!=0){t.log("Skipping trackselection of "+e+" track "+r+" because it does not exist");return}var s=[];for(var n in t.info.meta.tracks){var o=t.info.meta.tracks[n];if(o.type==e){s.push(o)}}MistUtil.array.multiSort(s,["bps"]);var l=false;for(var n in s){if(s[n].trackid==r){l=n;break}}if(l===false){return false}i.dash.setAutoSwitchQualityFor(e,false);i.dash.setFastSwitchEnabled(true);i.dash.setQualityFor(e,l);return true};i.dash.on("qualityChangeRendered",function(e){var i=[];for(var r in t.info.meta.tracks){var a=t.info.meta.tracks[r];if(a.type==e.mediaType){i.push(a)}}MistUtil.array.multiSort(i,["bps"]);var s=i[e.newQuality].trackid;MistUtil.event.send("playerUpdate_trackChanged",{type:e.mediaType,trackid:s},t.video)});var l=false;i.dash.on("allTextTracksAdded",function(){l=true});t.player.api.setSubtitle=function(e){if(!l){var r=function(){t.player.api.setSubtitle(e);i.dash.off("allTextTracksAdded",r)};i.dash.on("allTextTracksAdded",r);return}if(!e){i.dash.enableText(false);return}var a=i.dash.getTracksFor("text");for(var s in a){if(a[s].id==e.trackid){i.dash.setTextTrack(s);if(!i.dash.isTextEnabled()){i.dash.enableText()}return true}}return false};MistUtil.event.addListener(r,"progress",function(e){if(t.container.getAttribute("data-loading")=="stalled"){t.container.removeAttribute("data-loading")}});i.api.unload=function(){i.dash.reset()};t.log("Built html");e(r)};if("dashjs"in window){this.onDashLoad()}else{var r=MistUtil.scripts.insert(t.urlappend(mistplayers.dashjs.scriptsrc(t.options.host)),{onerror:function(e){var i="Failed to load dashjs.js";if(e.message){i+=": "+e.message}t.showError(i)},onload:i.onDashLoad},t)}}; \ No newline at end of file +mistplayers.dashjs={name:"Dash.js player",mimes:["dash/video/mp4"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return MistUtil.array.indexOf(this.mimes,t)==-1?false:true},isBrowserSupported:function(t,e,i){if(location.protocol!=MistUtil.http.url.split(e.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(location.protocol=="file:"){i.log("This source ("+t+") won't load if the page is run via file://");return false}return"MediaSource"in window},player:function(){this.onreadylist=[]},scriptsrc:function(t){return t+"/dashjs.js"}};var p=mistplayers.dashjs.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var i=this;this.onDashLoad=function(){if(t.destroyed){return}t.log("Building DashJS player..");var a=document.createElement("video");if("Proxy"in window){var r={get:{},set:{}};t.player.api=new Proxy(a,{get:function(t,e,i){if(e in r.get){return r.get[e].apply(t,arguments)}var a=t[e];if(typeof a==="function"){return function(){return a.apply(t,arguments)}}return a},set:function(t,e,i){if(e in r.set){return r.set[e].call(t,i)}return t[e]=i}});if(t.info.type=="live"){r.get.duration=function(){var e=0;if(this.buffered.length){e=this.buffered.end(this.buffered.length-1)}var i=((new Date).getTime()-t.player.api.lastProgress.getTime())*.001;return e+i+-1*t.player.api.liveOffset+45};r.set.currentTime=function(e){var i=e-t.player.api.duration;t.log("Seeking to "+MistUtil.format.time(e)+" ("+Math.round(i*-10)/10+"s from live)");t.video.currentTime=e};MistUtil.event.addListener(a,"progress",function(){t.player.api.lastProgress=new Date});t.player.api.lastProgress=new Date;t.player.api.liveOffset=0}}else{i.api=a}if(t.options.autoplay){a.setAttribute("autoplay","")}if(t.options.loop&&t.info.type!="live"){a.setAttribute("loop","")}if(t.options.poster){a.setAttribute("poster",t.options.poster)}if(t.options.muted){a.muted=true}if(t.options.controls=="stock"){a.setAttribute("controls","")}var s=dashjs.MediaPlayer().create();s.initialize(a,t.source.url,t.options.autoplay);i.dash=s;var n=["METRIC_ADDED","METRIC_CHANGED","METRICS_CHANGED","FRAGMENT_LOADING_STARTED","FRAGMENT_LOADING_COMPLETED","LOG","PLAYBACK_TIME_UPDATED","PLAYBACK_PROGRESS"];for(var o in dashjs.MediaPlayer.events){if(n.indexOf(o)<0){i.dash.on(dashjs.MediaPlayer.events[o],function(e){t.log("Player event fired: "+e.type)})}}t.player.setSize=function(t){this.api.style.width=t.width+"px";this.api.style.height=t.height+"px"};t.player.api.setSource=function(e){t.player.dash.attachSource(e)};t.player.api.setTrack=function(e,a){var r=MistUtil.tracks.parse(t.info.meta.tracks);if(!(e in r)||!(a in r[e])&&a!="none"){t.log("Skipping trackselection of "+e+" track "+a+" because it does not exist");return}var s=[];for(var n in t.info.meta.tracks){var o=t.info.meta.tracks[n];if(o.type==e){s.push(o)}}MistUtil.array.multiSort(s,["bps"]);var l=false;for(var n in s){var d="idx"in s[n]?s[n].idx:s[n].trackid;if(d==a){l=n;break}}if(l===false){return false}i.dash.setAutoSwitchQualityFor(e,false);i.dash.setFastSwitchEnabled(true);i.dash.setQualityFor(e,l);return true};i.dash.on("qualityChangeRendered",function(e){var i=[];for(var a in t.info.meta.tracks){var r=t.info.meta.tracks[a];if(r.type==e.mediaType){i.push(r)}}MistUtil.array.multiSort(i,["bps"]);var s="idx"in i[e.newQuality]?i[e.newQuality].idx:i[e.newQuality].trackid;MistUtil.event.send("playerUpdate_trackChanged",{type:e.mediaType,trackid:s},t.video)});var l=false;i.dash.on("allTextTracksAdded",function(){l=true});t.player.api.setSubtitle=function(e){if(!l){var a=function(){t.player.api.setSubtitle(e);i.dash.off("allTextTracksAdded",a)};i.dash.on("allTextTracksAdded",a);return}if(!e){i.dash.enableText(false);return}var r=i.dash.getTracksFor("text");for(var s in r){var n="idx"in e?e.idx:e.trackid;if(r[s].id==n){i.dash.setTextTrack(s);if(!i.dash.isTextEnabled()){i.dash.enableText()}return true}}return false};MistUtil.event.addListener(a,"progress",function(e){if(t.container.getAttribute("data-loading")=="stalled"){t.container.removeAttribute("data-loading")}});i.api.unload=function(){i.dash.reset()};t.log("Built html");e(a)};if("dashjs"in window){this.onDashLoad()}else{var a=MistUtil.scripts.insert(t.urlappend(mistplayers.dashjs.scriptsrc(t.options.host)),{onerror:function(e){var i="Failed to load dashjs.js";if(e.message){i+=": "+e.message}t.showError(i)},onload:i.onDashLoad},t)}}; \ No newline at end of file diff --git a/embed/player.js b/embed/player.js index 1446c73f..6aac1a2c 100644 --- a/embed/player.js +++ b/embed/player.js @@ -733,7 +733,7 @@ function MistVideo(streamName,options) { //check tracks exist var meta = MistUtil.tracks.parse(MistVideo.info.meta.tracks); for (var i in usetracks) { - if ((i in meta) && ((usetracks[i] in meta[i]) || (usetracks[i] == 0))) { continue; } + if ((i in meta) && ((usetracks[i] in meta[i]) || (usetracks[i] == "none"))) { continue; } MistVideo.log("Skipping trackselection of "+i+" track "+usetracks[i]+" because it does not exist"); delete usetracks[i]; } @@ -750,7 +750,7 @@ function MistVideo(streamName,options) { switch (i) { case "audio": case "video": - if (usetracks[i] == 0) { continue; } + if (usetracks[i] == "none") { continue; } hlstracks.push(usetracks[i]); break; } diff --git a/embed/skins.js b/embed/skins.js index f43fffad..7722e4fd 100644 --- a/embed/skins.js +++ b/embed/skins.js @@ -1393,7 +1393,7 @@ MistSkins["default"] = { } } - var value = 0; + var value = "none"; if (this.checked) { if (this.trackType in selections) { value = selections[this.trackType].value; @@ -1403,9 +1403,9 @@ MistSkins["default"] = { } } else { - value = 0; + value = "none"; } - changeToTracks(this.trackType,(this.checked ? value : 0)); + changeToTracks(this.trackType,(this.checked ? value : "none")); }); } } @@ -1470,7 +1470,7 @@ MistSkins["default"] = { var track = t[options[i]]; var option = document.createElement("option"); select.appendChild(option); - option.value = track.trackid; + option.value = ("idx" in track ? track.idx : track.trackid); if (MistUtil.object.keys(track.different).length) { option.appendChild(document.createTextNode(orderValues(track.different).join(" "))); } diff --git a/embed/util.js b/embed/util.js index 5f1e2dce..c1254db8 100644 --- a/embed/util.js +++ b/embed/util.js @@ -676,7 +676,7 @@ var MistUtil = { } if (!(track.type in output)) { output[track.type] = {}; } - output[track.type][track.trackid] = track; + output[track.type][("idx" in track ? track.idx : track.trackid)] = track; //make up something logical for the track displayname var name = {}; diff --git a/embed/wrappers/dashjs.js b/embed/wrappers/dashjs.js index d7e02c97..5bdaf2e0 100644 --- a/embed/wrappers/dashjs.js +++ b/embed/wrappers/dashjs.js @@ -138,7 +138,7 @@ p.prototype.build = function (MistVideo,callback) { //trackswitching MistVideo.player.api.setTrack = function(type,id){ var meta = MistUtil.tracks.parse(MistVideo.info.meta.tracks); - if ((!(type in meta)) || ((!(id in meta[type]) && (id != 0)))) { + if ((!(type in meta)) || ((!(id in meta[type]) && (id != "none")))) { MistVideo.log("Skipping trackselection of "+type+" track "+id+" because it does not exist"); return; } @@ -157,7 +157,8 @@ p.prototype.build = function (MistVideo,callback) { MistUtil.array.multiSort(mistTracks,["bps"]); var n = false; for (var i in mistTracks) { - if (mistTracks[i].trackid == id) { + var trackid = ("idx" in mistTracks[i] ? mistTracks[i].idx : mistTracks[i].trackid); + if (trackid == id) { n = i; break; } @@ -191,7 +192,7 @@ p.prototype.build = function (MistVideo,callback) { //sort by bitrate MistUtil.array.multiSort(mistTracks,["bps"]); //get mist's id for the track - var id = mistTracks[e.newQuality].trackid; + var id = ("idx" in mistTracks[e.newQuality] ? mistTracks[e.newQuality].idx : mistTracks[e.newQuality].trackid); //create an event to pass this to the skin MistUtil.event.send("playerUpdate_trackChanged",{ @@ -222,7 +223,8 @@ p.prototype.build = function (MistVideo,callback) { var dashsubs = me.dash.getTracksFor("text"); for (var i in dashsubs) { - if (dashsubs[i].id == trackmeta.trackid) { + var trackid = ("idx" in trackmeta ? trackmeta.idx : trackmeta.trackid); + if (dashsubs[i].id == trackid) { me.dash.setTextTrack(i); if (!me.dash.isTextEnabled()) { me.dash.enableText(); } return true; From b5750a5de706f2ee161b2fad51f91b3128a8bfa8 Mon Sep 17 00:00:00 2001 From: Cat Date: Tue, 12 Feb 2019 12:59:57 +0100 Subject: [PATCH 2/3] Embed: CSS parsing compatible with multiline @{} blocks, taking into account nested brackets --- embed/min/player.js | 2 +- embed/min/skins/default.css | 10 +++++----- embed/min/skins/dev.css | 10 +++++----- embed/skins/default.css | 2 +- embed/skins/general.css | 8 ++++---- embed/util.js | 29 ++++++++++++++++++++++++++--- 6 files changed, 42 insertions(+), 19 deletions(-) diff --git a/embed/min/player.js b/embed/min/player.js index 155e3036..f8286854 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),o=Math.round(e%1*1e3);e=Math.floor(e-60*a);var s=[];return r&&(r=r+" day"+(r>1?"s":"")+", "),n||r?(s.push(n),s.push(("0"+a).slice(-2))):s.push(a),s.push(("0"+Math.floor(e)).slice(-2)),t.ms&&(s[s.length-1]+="."+("000"+o).slice(-3)),(r||"")+s.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";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-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=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 o in t){var s=t[o];if(0!=(a=i(r(s,e),r(s,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&&(a.onerror=function(){n(a)})},n&&(a.onerror=function(){n(a)},a.ontimeout=a.onerror),"POST"==e){var o,s=[];for(var l in i)s.push(l+"="+encodeURIComponent(i[l]));s.length&&(o=s.join("&")),a.send(o)}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:"")}}},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}return e in n?n[e]instanceof Array?n[e].push(a):a(n[e]):(n[e]=[a],MistUtil.http.get(e,function(t){for(var i in n[e])n[e][i](t);n[e]=t},function(){throw"Failed to load CSS from "+e})),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 a in e=e.replace(/[^@]*?{[^]*?}/g,function(e){var r=e.split("{"),n=r[0].split(","),a="{"+r.slice(1).join("}");for(var o in n){n[o]=n[o].trim();var s="."+t+n[o];i&&(s+=",\n."+t+" "+n[o]),n[o]=s}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{(r=new Event(e,{bubbles:!0,cancelable:!0})).message=t,i.dispatchEvent(r)}catch(n){try{var r;(r=document.createEvent("Event")).initEvent(e,!0,!0),r.message=t,i.dispatchEvent(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.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,o,s,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 o;if(r.bps>0)o=r.bps>131072?Math.round(r.bps/1024/1024*8)+"mbps":Math.round(r.bps/1024*8)+"kbps",n[a]=o;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 s in t){var l=!1;for(var i in t[s])if(l){if(MistUtil.object.keys(t[s]).length>1)for(var a in t[s][i].describe)l[a]!=t[s][i].describe[a]&&delete l[a]}else l=MistUtil.object.extend({},t[s][i].describe);for(var i in t[s]){var c={},d={};for(var a in t[s][i].describe)a in l?d[a]=t[s][i].describe[a]:c[a]=t[s][i].describe[a];t[s][i].different=c,t[s][i].same=d;var u=MistUtil.object.values(c);t[s][i].displayName=u.length?u.join(", "):MistUtil.object.values(t[s][i].describe).join(" ")}var p={};for(var i in t[s]){if(t[s][i].displayName in p){var h=1;for(var i in t[s])t[s][i].different.trackid=h+")",t[s][i].displayName="Track "+h+" ("+t[s][i].displayName+")",h++;break}p[t[s][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,o=Math.max(0,(t.clientX/i-n)/a);return o=Math.min(o,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 o=1;ot.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"}};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 o="";o+='',o+='',o+=n,o+="",o+="";var s=document.createElement("div");return s.innerHTML=o,s.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)"string"==typeof this.css[i]&&t.push(MistUtil.css.load(e.urlappend(this.css[i]),this.colors));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 o=MistUtil.css.createStyle(t.css[r],a);n.appendChild(o)}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 s=this.buildStructure(t.children[r]);s&&n.appendChild(s)}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=e.skin.css.length;for(var a in n&&(i.style.opacity="0"),e.skin.css){var o=e.skin.css[a];o.callback=function(e){this.textContent=MistUtil.css.prependClass(e,r,!0),--n<=0&&(i.style.opacity="")},""!=o.textContent&&o.callback(o.textContent),i.appendChild(o)}MistUtil.class.add(i,r);var s=MistUtil.getBrowser();return s&&MistUtil.class.add(i,"browser-"+s),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}}]},{type:"speaker",classse:["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"},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:''},largeplay:{size:45,svg:''},pause:{size:45,svg:''},speaker:{size:45,svg:''},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return''}},muted:{size:45,svg:''},fullscreen:{size:45,svg:''},loop:{size:45,svg:''},settings:{size:45,svg:''},loading:{size:100,svg:''},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return''}},popout:{size:45,svg:''},switchvideo:{size:45,svg:''}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;return MistUtil.event.addListener(e.video,"contextmenu",function(t){t.preventDefault(),e.container.setAttribute("data-show-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||(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)}})}})}}),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"),o=0;o30)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 .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);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"},o=function(e){window.removeEventListener("mousemove",a),window.removeEventListener("click",o),MistUtil.event.addListener(r,"click",s)},s=function(e){e.stopPropagation(),r.removeEventListener("click",s),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",o,t)};return MistUtil.event.addListener(r,"click",s),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.player.api,n=this;t.updateBar=function(e){if(this.kids.bar){if(!isFinite(r.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.duration))return 0;var t=0;if("live"==n.info.type){var i=.001*n.info.meta.buffer_window;t=(e-r.duration+i)/i}else t=e/r.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.5?(r.right=100*(1-i)+"%",a.triangle.setMode("bottom","right")):(r.left=100*i+"%",a.triangle.setMode("bottom","left")),a.setPos(r)}else a.style.opacity=0},MistUtil.event.addListener(e,"mousemove",function(e){t.moveTooltip(e)});var o=!1;return MistUtil.event.addListener(e,"mousedown",function(i){if(1==i.which){o=!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&&(o=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),a.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")},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.player.api&&MistUtil.event.addListener(e.video,"click",function(){e.player.api.paused?e.player.api.play():MistUtil.isTouchDevice()||e.player.api.pause()},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 o=this;a.mode="mode"in e?e.mode:"vertical","vertical"==a.mode&&(a.style.transform="rotate(90deg)"),a.margin={start:.15,end:.1};var s=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;ii(t)?1:i(e)t[i]?1:t[e]1&&"player"in e&&"api"in e.player&&("setTrack"in e.player.api||"setTracks"in e.player.api||"setSource"in e.player.api)){var b=document.createElement("select");if(b.title="Select another "+l+" track",r[l]=b,b.trackType=l,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)(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),m.appendChild(document.createTextNode(k.join(" ")));var w=MistUtil.object.keys(c,function(e,t){return Number(e)-Number(t)});for(var u in w){var U=c[w[u]];M=document.createElement("option");b.appendChild(M),M.value="idx"in U?U.idx:U.trackid,MistUtil.object.keys(U.different).length?M.appendChild(document.createTextNode(g(U.different).join(" "))):M.appendChild(document.createTextNode("Track "+(Number(u)+1)))}if("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 x=document.createEvent("Event");x.initEvent("change"),b.dispatchEvent(x);break}}else MistUtil.event.addListener(b,"change",function(){this.trackType in n&&(n[this.trackType].checked=!0),a(this.trackType,this.value)}),MistUtil.event.addListener(e.video,"playerUpdate_trackChanged",function(t){t.message.type==l&&(b.value=t.message.trackid,e.log("Player selected "+l+" track with id "+t.message.trackid))},b)}else{var C;(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),C.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 o in a)MistUtil.event.addListener(e.video,a[o],function(t){!this.paused&&"container"in e&&r(t)},t);a=["seeked","playing","canplay","paused"];for(var o in a)MistUtil.event.addListener(e.video,a[o],function(t){"container"in e&&n()},t),MistUtil.event.addListener(e.video,"progress",function(t){"container"in e&&"monitor"in e&&"vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.score>.99&&n()},t)}return t},error:function(){var e=this,t=document.createElement("div");t.message=function(t,i,r){MistUtil.empty(this);var n=document.createElement("div");if(n.className="message",this.appendChild(n),!r.polling&&!r.passive){var a=document.createElement("h3");n.appendChild(a),a.appendChild(document.createTextNode("The player has encountered a problem"))}var o=document.createElement("p");if(n.appendChild(o),n.update=function(e){MistUtil.empty(o),o.appendChild(document.createTextNode(e))},t){e.info.on_error&&(t=e.info.on_error.replace(/\/,t)),n.update(t);var s=document.createElement("p");if(s.className="details mistvideo-description",n.appendChild(s),i)s.appendChild(document.createTextNode(i));else if("decodingIssues"in e.skin.blueprints){if("player"in e&&"api"in e.player){if(i=[],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]))}}s.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(o,s){s||(s={softReload:!(!e.video||!e.video.load),reload:!0,nextCombo:!!e.info,polling:!1,passive:!1});var l=s.type?s.type:o;if(!(l in a)){if(!0===s.reload&&(e.options.reloadDelay&&!isNaN(Number(e.options.reloadDelay))?s.reload=Number(e.options.reloadDelay):s.reload=10),s.passive){if(!0===r)return;if(r)return i.update(o),void(n=(new Date).getTime());t.setAttribute("data-passive","")}else t.removeAttribute("data-passive");r=!s.passive||"passive",n=(new Date).getTime(),this.log(o,"error");var c=t.message(o,!1,s);i=c;var d=document.createElement("div");if(d.className="mistvideo-buttoncontainer",c.appendChild(d),MistUtil.empty(d),s.softReload){var u={type:"button",label:"Reload video",onclick:function(){e.player.api.load()}};isNaN(s.softReload+"")||(u.delay=s.softReload),d.appendChild(e.UI.buildStructure(u))}if(s.reload){u={type:"button",label:"Reload player",onclick:function(){e.reload()}};isNaN(s.reload+"")||(u.delay=s.reload),d.appendChild(e.UI.buildStructure(u))}if(s.nextCombo){u={type:"button",label:"Next source",onclick:function(){e.nextCombo()}};isNaN(s.nextCombo+"")||(u.delay=s.nextCombo),d.appendChild(e.UI.buildStructure(u))}if(s.ignore){u={type:"button",label:"Ignore",onclick:function(){this.clearError(),a[l]=!0}};isNaN(s.ignore+"")||(u.delay=s.ignore),d.appendChild(e.UI.buildStructure(u))}s.polling&&d.appendChild(e.UI.buildStructure({type:"polling"})),MistUtil.class.add(t,"show"),"container"in e&&e.container.removeAttribute("data-loading")}},t.clear=function(i){for(var n=t.querySelectorAll("svg.icon.timeout"),a=0;a=t.scrollHeight-5}),r.logs)s(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),s(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),s(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)}},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 o=document.createTextNode(e.value?e.value:"");a.appendChild(o);var s=document.createElement("span");a.appendChild(s),i.set=function(e){if(0!==e&&(this.style.display=""),"object"==typeof e){if("val"in e&&(o.nodeValue=e.val,a.className="value"),s.children.length)return(t=s.children[0]).addData(e);var t=MistUtil.createGraph({x:[e.x],y:[e.y]},e.options);return s.style.display="",MistUtil.empty(s),s.appendChild(t)}return o.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 o in t.info.source){var s=t.info.source[o];if(!(s.type in a)){a[s.type]=1;n=document.createElement("option");r.appendChild(n),n.value=s.type,n.appendChild(document.createTextNode(MistUtil.format.mime2human(s.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 o=t.info.source[a];n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(o.url+" ("+MistUtil.format.mime2human(o.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:[{if:function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"video.load();",onclick:function(){this.player.api.load()}}},{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.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=data.error;return"on_error"in e&&(i.log(n),n=data.on_error),void i.showError(n,{reload:!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("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 o="maxwidth"in t&&t.maxwidth?t.maxwidth:window.innerWidth,s="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),o&&r>o&&l(r/o),s&&n>s&&l(n/s)}}}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 o in i.info.meta.tracks)a=Math.max(a,i.info.meta.tracks[o].lastms);e.lastms=a}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.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?.97:.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=2))for(var u in l[s.inner].list)if(l[s.inner].current=u,!(c(s.inner)>=1)){a=l.source.list[l.source.current];var p=l.player.list[l.player.current],h=mistplayers[p];if(h.isMimeSupported(a.type)&&h.isBrowserSupported(a.type,a,i))return{player:p,source:a,source_index:l.source.current};t||i.log("Checking "+h.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 a=i.options.host.replace(/^http/i,"ws"),o=new WebSocket(i.urlappend(a+"/json_"+encodeURIComponent(i.stream)+".js"));i.socket=o,o.die=!1,o.destroy=function(){this.die=!0,this.close()},o.onopen=function(e){this.wasConnected=!0},o.onclose=function(r){if(!this.die){if(this.wasConnected)return i.log("Reopening websocket.."),void 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"))}},o.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),t.error){case"Stream is offline":i.info=!1;case"Stream is initializing":case"Stream is booting":case"Stream is waiting for data":case"Stream is shutting down":a={polling:!0};break;default:a={reload:!0}}i.showError(e,a)}else{if(!i.info)return void n(t);var o=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(o){if("source"in o)return void("error"in i.info&&i.reload());i.info=MistUtil.object.extend(i.info,t),i.info.updated=new Date;var s=!1;for(var l in o)switch(l){case"meta":for(var c in o[l])switch(c){case"tracks":i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",t,i.video)}break;case"width":case"height":s=!0}s&&i.player.resize()}else i.log("Metachange: no differences detected")}})}()}else{var a=this.urlappend(t.host+"/json_"+encodeURIComponent(this.stream)+".js");this.log("Requesting stream info from "+a),MistUtil.http.get(a,function(e){i.destroyed||n(JSON.parse(e))},function(e){var r="Connection failed (failed to load "+a+")";i.showError(r,{reload:!0}),MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed")})}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){}if(this.UI&&this.UI.elements)for(var e in this.UI.elements){var n=this.UI.elements[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),o=Math.round(e%1*1e3);e=Math.floor(e-60*a);var s=[];return r&&(r=r+" day"+(r>1?"s":"")+", "),n||r?(s.push(n),s.push(("0"+a).slice(-2))):s.push(a),s.push(("0"+Math.floor(e)).slice(-2)),t.ms&&(s[s.length-1]+="."+("000"+o).slice(-3)),(r||"")+s.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";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-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=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 o in t){var s=t[o];if(0!=(a=i(r(s,e),r(s,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&&(a.onerror=function(){n(a)})},n&&(a.onerror=function(){n(a)},a.ontimeout=a.onerror),"POST"==e){var o,s=[];for(var l in i)s.push(l+"="+encodeURIComponent(i[l]));s.length&&(o=s.join("&")),a.send(o)}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:"")}}},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}return e in n?n[e]instanceof Array?n[e].push(a):a(n[e]):(n[e]=[a],MistUtil.http.get(e,function(t){for(var i in n[e])n[e][i](t);n[e]=t},function(){throw"Failed to load CSS from "+e})),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 o=1;o0)o=r.bps>131072?Math.round(r.bps/1024/1024*8)+"mbps":Math.round(r.bps/1024*8)+"kbps",n[a]=o;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 s in t){var l=!1;for(var i in t[s])if(l){if(MistUtil.object.keys(t[s]).length>1)for(var a in t[s][i].describe)l[a]!=t[s][i].describe[a]&&delete l[a]}else l=MistUtil.object.extend({},t[s][i].describe);for(var i in t[s]){var c={},d={};for(var a in t[s][i].describe)a in l?d[a]=t[s][i].describe[a]:c[a]=t[s][i].describe[a];t[s][i].different=c,t[s][i].same=d;var u=MistUtil.object.values(c);t[s][i].displayName=u.length?u.join(", "):MistUtil.object.values(t[s][i].describe).join(" ")}var p={};for(var i in t[s]){if(t[s][i].displayName in p){var h=1;for(var i in t[s])t[s][i].different.trackid=h+")",t[s][i].displayName="Track "+h+" ("+t[s][i].displayName+")",h++;break}p[t[s][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,o=Math.max(0,(t.clientX/i-n)/a);return o=Math.min(o,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 o=1;ot.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"}};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 o="";o+='',o+='',o+=n,o+="",o+="";var s=document.createElement("div");return s.innerHTML=o,s.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)"string"==typeof this.css[i]&&t.push(MistUtil.css.load(e.urlappend(this.css[i]),this.colors));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 o=MistUtil.css.createStyle(t.css[r],a);n.appendChild(o)}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 s=this.buildStructure(t.children[r]);s&&n.appendChild(s)}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=e.skin.css.length;for(var a in n&&(i.style.opacity="0"),e.skin.css){var o=e.skin.css[a];o.callback=function(e){this.textContent=MistUtil.css.prependClass(e,r,!0),--n<=0&&(i.style.opacity="")},""!=o.textContent&&o.callback(o.textContent),i.appendChild(o)}MistUtil.class.add(i,r);var s=MistUtil.getBrowser();return s&&MistUtil.class.add(i,"browser-"+s),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}}]},{type:"speaker",classse:["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"},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:''},largeplay:{size:45,svg:''},pause:{size:45,svg:''},speaker:{size:45,svg:''},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return''}},muted:{size:45,svg:''},fullscreen:{size:45,svg:''},loop:{size:45,svg:''},settings:{size:45,svg:''},loading:{size:100,svg:''},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return''}},popout:{size:45,svg:''},switchvideo:{size:45,svg:''}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;return MistUtil.event.addListener(e.video,"contextmenu",function(t){t.preventDefault(),e.container.setAttribute("data-show-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||(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)}})}})}}),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"),o=0;o30)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 .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);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"},o=function(e){window.removeEventListener("mousemove",a),window.removeEventListener("click",o),MistUtil.event.addListener(r,"click",s)},s=function(e){e.stopPropagation(),r.removeEventListener("click",s),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",o,t)};return MistUtil.event.addListener(r,"click",s),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.player.api,n=this;t.updateBar=function(e){if(this.kids.bar){if(!isFinite(r.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.duration))return 0;var t=0;if("live"==n.info.type){var i=.001*n.info.meta.buffer_window;t=(e-r.duration+i)/i}else t=e/r.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.5?(r.right=100*(1-i)+"%",a.triangle.setMode("bottom","right")):(r.left=100*i+"%",a.triangle.setMode("bottom","left")),a.setPos(r)}else a.style.opacity=0},MistUtil.event.addListener(e,"mousemove",function(e){t.moveTooltip(e)});var o=!1;return MistUtil.event.addListener(e,"mousedown",function(i){if(1==i.which){o=!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&&(o=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),a.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")},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.player.api&&MistUtil.event.addListener(e.video,"click",function(){e.player.api.paused?e.player.api.play():MistUtil.isTouchDevice()||e.player.api.pause()},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 o=this;a.mode="mode"in e?e.mode:"vertical","vertical"==a.mode&&(a.style.transform="rotate(90deg)"),a.margin={start:.15,end:.1};var s=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;ii(t)?1:i(e)t[i]?1:t[e]1&&"player"in e&&"api"in e.player&&("setTrack"in e.player.api||"setTracks"in e.player.api||"setSource"in e.player.api)){var b=document.createElement("select");if(b.title="Select another "+l+" track",r[l]=b,b.trackType=l,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)(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),m.appendChild(document.createTextNode(k.join(" ")));var w=MistUtil.object.keys(c,function(e,t){return Number(e)-Number(t)});for(var u in w){var U=c[w[u]];M=document.createElement("option");b.appendChild(M),M.value="idx"in U?U.idx:U.trackid,MistUtil.object.keys(U.different).length?M.appendChild(document.createTextNode(g(U.different).join(" "))):M.appendChild(document.createTextNode("Track "+(Number(u)+1)))}if("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 x=document.createEvent("Event");x.initEvent("change"),b.dispatchEvent(x);break}}else MistUtil.event.addListener(b,"change",function(){this.trackType in n&&(n[this.trackType].checked=!0),a(this.trackType,this.value)}),MistUtil.event.addListener(e.video,"playerUpdate_trackChanged",function(t){t.message.type==l&&(b.value=t.message.trackid,e.log("Player selected "+l+" track with id "+t.message.trackid))},b)}else{var C;(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),C.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 o in a)MistUtil.event.addListener(e.video,a[o],function(t){!this.paused&&"container"in e&&r(t)},t);a=["seeked","playing","canplay","paused"];for(var o in a)MistUtil.event.addListener(e.video,a[o],function(t){"container"in e&&n()},t),MistUtil.event.addListener(e.video,"progress",function(t){"container"in e&&"monitor"in e&&"vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.score>.99&&n()},t)}return t},error:function(){var e=this,t=document.createElement("div");t.message=function(t,i,r){MistUtil.empty(this);var n=document.createElement("div");if(n.className="message",this.appendChild(n),!r.polling&&!r.passive){var a=document.createElement("h3");n.appendChild(a),a.appendChild(document.createTextNode("The player has encountered a problem"))}var o=document.createElement("p");if(n.appendChild(o),n.update=function(e){MistUtil.empty(o),o.appendChild(document.createTextNode(e))},t){e.info.on_error&&(t=e.info.on_error.replace(/\/,t)),n.update(t);var s=document.createElement("p");if(s.className="details mistvideo-description",n.appendChild(s),i)s.appendChild(document.createTextNode(i));else if("decodingIssues"in e.skin.blueprints){if("player"in e&&"api"in e.player){if(i=[],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]))}}s.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(o,s){s||(s={softReload:!(!e.video||!e.video.load),reload:!0,nextCombo:!!e.info,polling:!1,passive:!1});var l=s.type?s.type:o;if(!(l in a)){if(!0===s.reload&&(e.options.reloadDelay&&!isNaN(Number(e.options.reloadDelay))?s.reload=Number(e.options.reloadDelay):s.reload=10),s.passive){if(!0===r)return;if(r)return i.update(o),void(n=(new Date).getTime());t.setAttribute("data-passive","")}else t.removeAttribute("data-passive");r=!s.passive||"passive",n=(new Date).getTime(),this.log(o,"error");var c=t.message(o,!1,s);i=c;var d=document.createElement("div");if(d.className="mistvideo-buttoncontainer",c.appendChild(d),MistUtil.empty(d),s.softReload){var u={type:"button",label:"Reload video",onclick:function(){e.player.api.load()}};isNaN(s.softReload+"")||(u.delay=s.softReload),d.appendChild(e.UI.buildStructure(u))}if(s.reload){u={type:"button",label:"Reload player",onclick:function(){e.reload()}};isNaN(s.reload+"")||(u.delay=s.reload),d.appendChild(e.UI.buildStructure(u))}if(s.nextCombo){u={type:"button",label:"Next source",onclick:function(){e.nextCombo()}};isNaN(s.nextCombo+"")||(u.delay=s.nextCombo),d.appendChild(e.UI.buildStructure(u))}if(s.ignore){u={type:"button",label:"Ignore",onclick:function(){this.clearError(),a[l]=!0}};isNaN(s.ignore+"")||(u.delay=s.ignore),d.appendChild(e.UI.buildStructure(u))}s.polling&&d.appendChild(e.UI.buildStructure({type:"polling"})),MistUtil.class.add(t,"show"),"container"in e&&e.container.removeAttribute("data-loading")}},t.clear=function(i){for(var n=t.querySelectorAll("svg.icon.timeout"),a=0;a=t.scrollHeight-5}),r.logs)s(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),s(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),s(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)}},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 o=document.createTextNode(e.value?e.value:"");a.appendChild(o);var s=document.createElement("span");a.appendChild(s),i.set=function(e){if(0!==e&&(this.style.display=""),"object"==typeof e){if("val"in e&&(o.nodeValue=e.val,a.className="value"),s.children.length)return(t=s.children[0]).addData(e);var t=MistUtil.createGraph({x:[e.x],y:[e.y]},e.options);return s.style.display="",MistUtil.empty(s),s.appendChild(t)}return o.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 o in t.info.source){var s=t.info.source[o];if(!(s.type in a)){a[s.type]=1;n=document.createElement("option");r.appendChild(n),n.value=s.type,n.appendChild(document.createTextNode(MistUtil.format.mime2human(s.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 o=t.info.source[a];n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(o.url+" ("+MistUtil.format.mime2human(o.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:[{if:function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"video.load();",onclick:function(){this.player.api.load()}}},{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.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=data.error;return"on_error"in e&&(i.log(n),n=data.on_error),void i.showError(n,{reload:!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("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 o="maxwidth"in t&&t.maxwidth?t.maxwidth:window.innerWidth,s="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),o&&r>o&&l(r/o),s&&n>s&&l(n/s)}}}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 o in i.info.meta.tracks)a=Math.max(a,i.info.meta.tracks[o].lastms);e.lastms=a}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.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?.97:.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=2))for(var u in l[s.inner].list)if(l[s.inner].current=u,!(c(s.inner)>=1)){a=l.source.list[l.source.current];var p=l.player.list[l.player.current],h=mistplayers[p];if(h.isMimeSupported(a.type)&&h.isBrowserSupported(a.type,a,i))return{player:p,source:a,source_index:l.source.current};t||i.log("Checking "+h.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 a=i.options.host.replace(/^http/i,"ws"),o=new WebSocket(i.urlappend(a+"/json_"+encodeURIComponent(i.stream)+".js"));i.socket=o,o.die=!1,o.destroy=function(){this.die=!0,this.close()},o.onopen=function(e){this.wasConnected=!0},o.onclose=function(r){if(!this.die){if(this.wasConnected)return i.log("Reopening websocket.."),void 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"))}},o.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),t.error){case"Stream is offline":i.info=!1;case"Stream is initializing":case"Stream is booting":case"Stream is waiting for data":case"Stream is shutting down":a={polling:!0};break;default:a={reload:!0}}i.showError(e,a)}else{if(!i.info)return void n(t);var o=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(o){if("source"in o)return void("error"in i.info&&i.reload());i.info=MistUtil.object.extend(i.info,t),i.info.updated=new Date;var s=!1;for(var l in o)switch(l){case"meta":for(var c in o[l])switch(c){case"tracks":i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",t,i.video)}break;case"width":case"height":s=!0}s&&i.player.resize()}else i.log("Metachange: no differences detected")}})}()}else{var a=this.urlappend(t.host+"/json_"+encodeURIComponent(this.stream)+".js");this.log("Requesting stream info from "+a),MistUtil.http.get(a,function(e){i.destroyed||n(JSON.parse(e))},function(e){var r="Connection failed (failed to load "+a+")";i.showError(r,{reload:!0}),MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed")})}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){}if(this.UI&&this.UI.elements)for(var e in this.UI.elements){var n=this.UI.elements[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 diff --git a/embed/min/skins/default.css b/embed/min/skins/default.css index 490bbfa8..1644b79b 100644 --- a/embed/min/skins/default.css +++ b/embed/min/skins/default.css @@ -17,7 +17,7 @@ button:hover{opacity:1} select{background-color:transparent;color:$stroke;border:none;margin:0 .5em;font-size:inherit;cursor:pointer;-ms-background-color:red} select>option{background-color:$background} .browser-edge select,.browser-safari select{border:1px solid $semiFill;border-top:none;border-left:none;margin-top:2px} -@keyframes spin{ +@keyframes mistvideo-spin{ 0%{transform:rotate(0)} 100%{transform:rotate(360deg)} } @@ -50,8 +50,8 @@ a{color:$accent} .mistvideo-placeholder{max-width:100%;max-height:100%} .mistvideo-topright{position:absolute;top:0;right:0} .mistvideo-topleft{position:absolute;top:0;left:0} -.mistvideo-delay-display{animation:appear 1s;animation-iteration-count:1;animation-timing-function:steps(1,end)} -@keyframes appear{ +.mistvideo-delay-display{animation:mistvideo-appear 1s;animation-iteration-count:1;animation-timing-function:steps(1,end)} +@keyframes mistvideo-appear{ from{opacity:0} to{opacity:1} } @@ -60,7 +60,7 @@ svg.icon .fill,svg.icon.fill{fill:$fill} svg.icon .semiFill,svg.icon.semiFill{fill:$semiFill} svg.icon .stroke,svg.icon.stroke{stroke:$stroke;vector-effect:non-scaling-stroke} svg.icon.off .toggle .fill,svg.icon.off .toggle .semiFill,svg.icon.off .toggle.fill,svg.icon.off .toggle.semiFill{fill:none} -svg.icon .spin,svg.icon.spin{animation:spin 1.5s infinite linear;transform-origin:50% 50%} +svg.icon .spin,svg.icon.spin{animation:mistvideo-spin 1.5s infinite linear;transform-origin:50% 50%} .vjs-text-track-display{pointer-events:none} .mistvideo{line-height:1.2;font-size:14.5px} .mistvideo svg{margin:2.5px} @@ -89,5 +89,5 @@ svg.icon.timeout{display:inline-block;height:1em;width:1em;margin:0;margin-right .mistvideo-error[data-passive] .message{max-width:none} .mistvideo-error .mistvideo-buttoncontainer{display:flex;flex-flow:row nowrap;justify-content:center} .mistvideo-error .mistvideo-buttoncontainer .mistvideo-button{white-space:nowrap} -.browser-ie .mist.icon.loading{animation:spin 1.5s infinite linear;transform-origin:50% 50%} +.browser-ie .mist.icon.loading{animation:mistvideo-spin 1.5s infinite linear;transform-origin:50% 50%} .browser-ie .mist.icon.loading .spin{animation:none} \ No newline at end of file diff --git a/embed/min/skins/dev.css b/embed/min/skins/dev.css index 1d1eff46..aade7d99 100644 --- a/embed/min/skins/dev.css +++ b/embed/min/skins/dev.css @@ -17,7 +17,7 @@ button:hover{opacity:1} select{background-color:transparent;color:$stroke;border:none;margin:0 .5em;font-size:inherit;cursor:pointer;-ms-background-color:red} select>option{background-color:$background} .browser-edge select,.browser-safari select{border:1px solid $semiFill;border-top:none;border-left:none;margin-top:2px} -@keyframes spin{ +@keyframes mistvideo-spin{ 0%{transform:rotate(0)} 100%{transform:rotate(360deg)} } @@ -50,8 +50,8 @@ a{color:$accent} .mistvideo-placeholder{max-width:100%;max-height:100%} .mistvideo-topright{position:absolute;top:0;right:0} .mistvideo-topleft{position:absolute;top:0;left:0} -.mistvideo-delay-display{animation:appear 1s;animation-iteration-count:1;animation-timing-function:steps(1,end)} -@keyframes appear{ +.mistvideo-delay-display{animation:mistvideo-appear 1s;animation-iteration-count:1;animation-timing-function:steps(1,end)} +@keyframes mistvideo-appear{ from{opacity:0} to{opacity:1} } @@ -60,7 +60,7 @@ svg.icon .fill,svg.icon.fill{fill:$fill} svg.icon .semiFill,svg.icon.semiFill{fill:$semiFill} svg.icon .stroke,svg.icon.stroke{stroke:$stroke;vector-effect:non-scaling-stroke} svg.icon.off .toggle .fill,svg.icon.off .toggle .semiFill,svg.icon.off .toggle.fill,svg.icon.off .toggle.semiFill{fill:none} -svg.icon .spin,svg.icon.spin{animation:spin 1.5s infinite linear;transform-origin:50% 50%} +svg.icon .spin,svg.icon.spin{animation:mistvideo-spin 1.5s infinite linear;transform-origin:50% 50%} .vjs-text-track-display{pointer-events:none} .mistvideo{line-height:1.2;font-size:14.5px} .mistvideo svg{margin:2.5px} @@ -89,7 +89,7 @@ svg.icon.timeout{display:inline-block;height:1em;width:1em;margin:0;margin-right .mistvideo-error[data-passive] .message{max-width:none} .mistvideo-error .mistvideo-buttoncontainer{display:flex;flex-flow:row nowrap;justify-content:center} .mistvideo-error .mistvideo-buttoncontainer .mistvideo-button{white-space:nowrap} -.browser-ie .mist.icon.loading{animation:spin 1.5s infinite linear;transform-origin:50% 50%} +.browser-ie .mist.icon.loading{animation:mistvideo-spin 1.5s infinite linear;transform-origin:50% 50%} .browser-ie .mist.icon.loading .spin{animation:none} .mistvideo-log{margin:.5em 0} .mistvideo-log .logs{max-height:10em;min-height:5em;width:100%;padding:.2em 0;padding-right:1em;overflow-y:auto;overflow-x:hidden;font-size:.9em} diff --git a/embed/skins/default.css b/embed/skins/default.css index 895c8d02..8e95e7e6 100644 --- a/embed/skins/default.css +++ b/embed/skins/default.css @@ -130,7 +130,7 @@ svg.icon.timeout { white-space: nowrap; } .browser-ie .mist.icon.loading { - animation: spin 1.5s infinite linear; + animation: mistvideo-spin 1.5s infinite linear; transform-origin: 50% 50%; } .browser-ie .mist.icon.loading .spin { animation: none; } diff --git a/embed/skins/general.css b/embed/skins/general.css index 89a6d9c3..59e2b554 100644 --- a/embed/skins/general.css +++ b/embed/skins/general.css @@ -102,7 +102,7 @@ select > option { margin-top: 2px; } -@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } +@keyframes mistvideo-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } [data-fullscreen] { position: fixed; top: 0; @@ -200,11 +200,11 @@ a { left: 0; } .mistvideo-delay-display { - animation: appear 1s; + animation: mistvideo-appear 1s; animation-iteration-count: 1; animation-timing-function: steps(1,end); } -@keyframes appear { from { opacity: 0; } to { opacity: 1; } } +@keyframes mistvideo-appear { from { opacity: 0; } to { opacity: 1; } } svg.icon { display: block; @@ -220,7 +220,7 @@ svg.icon.off .toggle.semiFill, svg.icon.off .toggle .fill, svg.icon.off .toggle .semiFill { fill: none; } svg.icon.spin, svg.icon .spin { - animation: spin 1.5s infinite linear; + animation: mistvideo-spin 1.5s infinite linear; transform-origin: 50% 50%; } .vjs-text-track-display { diff --git a/embed/util.js b/embed/util.js index c1254db8..2a7f3cf7 100644 --- a/embed/util.js +++ b/embed/util.js @@ -495,10 +495,33 @@ var MistUtil = { //remove all block comments css = css.replace(/\/\*.*?\*\//g,""); - //save all @{} blocks - var save = css.match(/@.*?{.*}/g); + //remove all @ {} blocks (media, keyframes, screen etc) and save it to re-insert them after class prepending + //match anything starting with @ something {, until the first } + var save = css.match(/@[^}]*}/g); + for (var i in save) { - css = css.replace(save[i],"@@@@"); + //add a placeholder for unfinished replace + css = css.replace(save[i],"@@#@@"); + + var replacecount = 1; + + //while the amount of }s we've replaced is smaller than the amount of {'s in the match + while (replacecount < (save[i].match(/{/g).length)) { + //find the next } and save it in a group + var match = css.match(/@@#@@([^}]*})/); //match anything starting with @@#@@ until the first } + + //replace the full match with the unfinished placeholder + css = css.replace(match[0],"@@#@@"); + + //add the group (the code untill the next }) to the save + save[i] += match[1]; + + //increase the counter + replacecount++; + } + + //after the edits, @@@@ will be replaced with the contents of save[i] + css = css.replace("@@#@@","@@@@"); } //find and replace selectors From 06eb78c345a1914472687e5f532767b8e0c38142 Mon Sep 17 00:00:00 2001 From: Cat Date: Mon, 18 Feb 2019 13:56:27 +0100 Subject: [PATCH 3/3] Embed: allow options.setTracks to set subtitles --- embed/min/player.js | 2 +- embed/player.js | 71 +++++++++++++++++++++++++++++++++++++-------- embed/skins.js | 56 +++++++++++++++++++---------------- lsp/minified.js | 32 ++++++++++---------- lsp/mist.js | 28 +++++++++++++----- 5 files changed, 128 insertions(+), 61 deletions(-) diff --git a/embed/min/player.js b/embed/min/player.js index f8286854..c0f34c56 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),o=Math.round(e%1*1e3);e=Math.floor(e-60*a);var s=[];return r&&(r=r+" day"+(r>1?"s":"")+", "),n||r?(s.push(n),s.push(("0"+a).slice(-2))):s.push(a),s.push(("0"+Math.floor(e)).slice(-2)),t.ms&&(s[s.length-1]+="."+("000"+o).slice(-3)),(r||"")+s.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";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-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=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 o in t){var s=t[o];if(0!=(a=i(r(s,e),r(s,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&&(a.onerror=function(){n(a)})},n&&(a.onerror=function(){n(a)},a.ontimeout=a.onerror),"POST"==e){var o,s=[];for(var l in i)s.push(l+"="+encodeURIComponent(i[l]));s.length&&(o=s.join("&")),a.send(o)}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:"")}}},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}return e in n?n[e]instanceof Array?n[e].push(a):a(n[e]):(n[e]=[a],MistUtil.http.get(e,function(t){for(var i in n[e])n[e][i](t);n[e]=t},function(){throw"Failed to load CSS from "+e})),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 o=1;o0)o=r.bps>131072?Math.round(r.bps/1024/1024*8)+"mbps":Math.round(r.bps/1024*8)+"kbps",n[a]=o;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 s in t){var l=!1;for(var i in t[s])if(l){if(MistUtil.object.keys(t[s]).length>1)for(var a in t[s][i].describe)l[a]!=t[s][i].describe[a]&&delete l[a]}else l=MistUtil.object.extend({},t[s][i].describe);for(var i in t[s]){var c={},d={};for(var a in t[s][i].describe)a in l?d[a]=t[s][i].describe[a]:c[a]=t[s][i].describe[a];t[s][i].different=c,t[s][i].same=d;var u=MistUtil.object.values(c);t[s][i].displayName=u.length?u.join(", "):MistUtil.object.values(t[s][i].describe).join(" ")}var p={};for(var i in t[s]){if(t[s][i].displayName in p){var h=1;for(var i in t[s])t[s][i].different.trackid=h+")",t[s][i].displayName="Track "+h+" ("+t[s][i].displayName+")",h++;break}p[t[s][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,o=Math.max(0,(t.clientX/i-n)/a);return o=Math.min(o,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 o=1;ot.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"}};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 o="";o+='',o+='',o+=n,o+="",o+="";var s=document.createElement("div");return s.innerHTML=o,s.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)"string"==typeof this.css[i]&&t.push(MistUtil.css.load(e.urlappend(this.css[i]),this.colors));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 o=MistUtil.css.createStyle(t.css[r],a);n.appendChild(o)}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 s=this.buildStructure(t.children[r]);s&&n.appendChild(s)}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=e.skin.css.length;for(var a in n&&(i.style.opacity="0"),e.skin.css){var o=e.skin.css[a];o.callback=function(e){this.textContent=MistUtil.css.prependClass(e,r,!0),--n<=0&&(i.style.opacity="")},""!=o.textContent&&o.callback(o.textContent),i.appendChild(o)}MistUtil.class.add(i,r);var s=MistUtil.getBrowser();return s&&MistUtil.class.add(i,"browser-"+s),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}}]},{type:"speaker",classse:["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"},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:''},largeplay:{size:45,svg:''},pause:{size:45,svg:''},speaker:{size:45,svg:''},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return''}},muted:{size:45,svg:''},fullscreen:{size:45,svg:''},loop:{size:45,svg:''},settings:{size:45,svg:''},loading:{size:100,svg:''},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return''}},popout:{size:45,svg:''},switchvideo:{size:45,svg:''}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;return MistUtil.event.addListener(e.video,"contextmenu",function(t){t.preventDefault(),e.container.setAttribute("data-show-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||(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)}})}})}}),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"),o=0;o30)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 .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);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"},o=function(e){window.removeEventListener("mousemove",a),window.removeEventListener("click",o),MistUtil.event.addListener(r,"click",s)},s=function(e){e.stopPropagation(),r.removeEventListener("click",s),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",o,t)};return MistUtil.event.addListener(r,"click",s),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.player.api,n=this;t.updateBar=function(e){if(this.kids.bar){if(!isFinite(r.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.duration))return 0;var t=0;if("live"==n.info.type){var i=.001*n.info.meta.buffer_window;t=(e-r.duration+i)/i}else t=e/r.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.5?(r.right=100*(1-i)+"%",a.triangle.setMode("bottom","right")):(r.left=100*i+"%",a.triangle.setMode("bottom","left")),a.setPos(r)}else a.style.opacity=0},MistUtil.event.addListener(e,"mousemove",function(e){t.moveTooltip(e)});var o=!1;return MistUtil.event.addListener(e,"mousedown",function(i){if(1==i.which){o=!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&&(o=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),a.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")},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.player.api&&MistUtil.event.addListener(e.video,"click",function(){e.player.api.paused?e.player.api.play():MistUtil.isTouchDevice()||e.player.api.pause()},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 o=this;a.mode="mode"in e?e.mode:"vertical","vertical"==a.mode&&(a.style.transform="rotate(90deg)"),a.margin={start:.15,end:.1};var s=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;ii(t)?1:i(e)t[i]?1:t[e]1&&"player"in e&&"api"in e.player&&("setTrack"in e.player.api||"setTracks"in e.player.api||"setSource"in e.player.api)){var b=document.createElement("select");if(b.title="Select another "+l+" track",r[l]=b,b.trackType=l,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)(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),m.appendChild(document.createTextNode(k.join(" ")));var w=MistUtil.object.keys(c,function(e,t){return Number(e)-Number(t)});for(var u in w){var U=c[w[u]];M=document.createElement("option");b.appendChild(M),M.value="idx"in U?U.idx:U.trackid,MistUtil.object.keys(U.different).length?M.appendChild(document.createTextNode(g(U.different).join(" "))):M.appendChild(document.createTextNode("Track "+(Number(u)+1)))}if("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 x=document.createEvent("Event");x.initEvent("change"),b.dispatchEvent(x);break}}else MistUtil.event.addListener(b,"change",function(){this.trackType in n&&(n[this.trackType].checked=!0),a(this.trackType,this.value)}),MistUtil.event.addListener(e.video,"playerUpdate_trackChanged",function(t){t.message.type==l&&(b.value=t.message.trackid,e.log("Player selected "+l+" track with id "+t.message.trackid))},b)}else{var C;(C=document.createElement("span")).className="mistvideo-description",m.appendChild(C),C.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 o in a)MistUtil.event.addListener(e.video,a[o],function(t){!this.paused&&"container"in e&&r(t)},t);a=["seeked","playing","canplay","paused"];for(var o in a)MistUtil.event.addListener(e.video,a[o],function(t){"container"in e&&n()},t),MistUtil.event.addListener(e.video,"progress",function(t){"container"in e&&"monitor"in e&&"vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.score>.99&&n()},t)}return t},error:function(){var e=this,t=document.createElement("div");t.message=function(t,i,r){MistUtil.empty(this);var n=document.createElement("div");if(n.className="message",this.appendChild(n),!r.polling&&!r.passive){var a=document.createElement("h3");n.appendChild(a),a.appendChild(document.createTextNode("The player has encountered a problem"))}var o=document.createElement("p");if(n.appendChild(o),n.update=function(e){MistUtil.empty(o),o.appendChild(document.createTextNode(e))},t){e.info.on_error&&(t=e.info.on_error.replace(/\/,t)),n.update(t);var s=document.createElement("p");if(s.className="details mistvideo-description",n.appendChild(s),i)s.appendChild(document.createTextNode(i));else if("decodingIssues"in e.skin.blueprints){if("player"in e&&"api"in e.player){if(i=[],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]))}}s.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(o,s){s||(s={softReload:!(!e.video||!e.video.load),reload:!0,nextCombo:!!e.info,polling:!1,passive:!1});var l=s.type?s.type:o;if(!(l in a)){if(!0===s.reload&&(e.options.reloadDelay&&!isNaN(Number(e.options.reloadDelay))?s.reload=Number(e.options.reloadDelay):s.reload=10),s.passive){if(!0===r)return;if(r)return i.update(o),void(n=(new Date).getTime());t.setAttribute("data-passive","")}else t.removeAttribute("data-passive");r=!s.passive||"passive",n=(new Date).getTime(),this.log(o,"error");var c=t.message(o,!1,s);i=c;var d=document.createElement("div");if(d.className="mistvideo-buttoncontainer",c.appendChild(d),MistUtil.empty(d),s.softReload){var u={type:"button",label:"Reload video",onclick:function(){e.player.api.load()}};isNaN(s.softReload+"")||(u.delay=s.softReload),d.appendChild(e.UI.buildStructure(u))}if(s.reload){u={type:"button",label:"Reload player",onclick:function(){e.reload()}};isNaN(s.reload+"")||(u.delay=s.reload),d.appendChild(e.UI.buildStructure(u))}if(s.nextCombo){u={type:"button",label:"Next source",onclick:function(){e.nextCombo()}};isNaN(s.nextCombo+"")||(u.delay=s.nextCombo),d.appendChild(e.UI.buildStructure(u))}if(s.ignore){u={type:"button",label:"Ignore",onclick:function(){this.clearError(),a[l]=!0}};isNaN(s.ignore+"")||(u.delay=s.ignore),d.appendChild(e.UI.buildStructure(u))}s.polling&&d.appendChild(e.UI.buildStructure({type:"polling"})),MistUtil.class.add(t,"show"),"container"in e&&e.container.removeAttribute("data-loading")}},t.clear=function(i){for(var n=t.querySelectorAll("svg.icon.timeout"),a=0;a=t.scrollHeight-5}),r.logs)s(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),s(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),s(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)}},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 o=document.createTextNode(e.value?e.value:"");a.appendChild(o);var s=document.createElement("span");a.appendChild(s),i.set=function(e){if(0!==e&&(this.style.display=""),"object"==typeof e){if("val"in e&&(o.nodeValue=e.val,a.className="value"),s.children.length)return(t=s.children[0]).addData(e);var t=MistUtil.createGraph({x:[e.x],y:[e.y]},e.options);return s.style.display="",MistUtil.empty(s),s.appendChild(t)}return o.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 o in t.info.source){var s=t.info.source[o];if(!(s.type in a)){a[s.type]=1;n=document.createElement("option");r.appendChild(n),n.value=s.type,n.appendChild(document.createTextNode(MistUtil.format.mime2human(s.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 o=t.info.source[a];n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(o.url+" ("+MistUtil.format.mime2human(o.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:[{if:function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"video.load();",onclick:function(){this.player.api.load()}}},{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.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=data.error;return"on_error"in e&&(i.log(n),n=data.on_error),void i.showError(n,{reload:!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("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 o="maxwidth"in t&&t.maxwidth?t.maxwidth:window.innerWidth,s="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),o&&r>o&&l(r/o),s&&n>s&&l(n/s)}}}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 o in i.info.meta.tracks)a=Math.max(a,i.info.meta.tracks[o].lastms);e.lastms=a}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.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?.97:.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=2))for(var u in l[s.inner].list)if(l[s.inner].current=u,!(c(s.inner)>=1)){a=l.source.list[l.source.current];var p=l.player.list[l.player.current],h=mistplayers[p];if(h.isMimeSupported(a.type)&&h.isBrowserSupported(a.type,a,i))return{player:p,source:a,source_index:l.source.current};t||i.log("Checking "+h.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 a=i.options.host.replace(/^http/i,"ws"),o=new WebSocket(i.urlappend(a+"/json_"+encodeURIComponent(i.stream)+".js"));i.socket=o,o.die=!1,o.destroy=function(){this.die=!0,this.close()},o.onopen=function(e){this.wasConnected=!0},o.onclose=function(r){if(!this.die){if(this.wasConnected)return i.log("Reopening websocket.."),void 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"))}},o.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),t.error){case"Stream is offline":i.info=!1;case"Stream is initializing":case"Stream is booting":case"Stream is waiting for data":case"Stream is shutting down":a={polling:!0};break;default:a={reload:!0}}i.showError(e,a)}else{if(!i.info)return void n(t);var o=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(o){if("source"in o)return void("error"in i.info&&i.reload());i.info=MistUtil.object.extend(i.info,t),i.info.updated=new Date;var s=!1;for(var l in o)switch(l){case"meta":for(var c in o[l])switch(c){case"tracks":i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",t,i.video)}break;case"width":case"height":s=!0}s&&i.player.resize()}else i.log("Metachange: no differences detected")}})}()}else{var a=this.urlappend(t.host+"/json_"+encodeURIComponent(this.stream)+".js");this.log("Requesting stream info from "+a),MistUtil.http.get(a,function(e){i.destroyed||n(JSON.parse(e))},function(e){var r="Connection failed (failed to load "+a+")";i.showError(r,{reload:!0}),MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed")})}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){}if(this.UI&&this.UI.elements)for(var e in this.UI.elements){var n=this.UI.elements[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),o=Math.round(e%1*1e3);e=Math.floor(e-60*a);var s=[];return r&&(r=r+" day"+(r>1?"s":"")+", "),n||r?(s.push(n),s.push(("0"+a).slice(-2))):s.push(a),s.push(("0"+Math.floor(e)).slice(-2)),t.ms&&(s[s.length-1]+="."+("000"+o).slice(-3)),(r||"")+s.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";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-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=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 o in t){var s=t[o];if(0!=(a=i(r(s,e),r(s,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&&(a.onerror=function(){n(a)})},n&&(a.onerror=function(){n(a)},a.ontimeout=a.onerror),"POST"==e){var o,s=[];for(var l in i)s.push(l+"="+encodeURIComponent(i[l]));s.length&&(o=s.join("&")),a.send(o)}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:"")}}},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}return e in n?n[e]instanceof Array?n[e].push(a):a(n[e]):(n[e]=[a],MistUtil.http.get(e,function(t){for(var i in n[e])n[e][i](t);n[e]=t},function(){throw"Failed to load CSS from "+e})),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 o=1;o0)o=r.bps>131072?Math.round(r.bps/1024/1024*8)+"mbps":Math.round(r.bps/1024*8)+"kbps",n[a]=o;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 s in t){var l=!1;for(var i in t[s])if(l){if(MistUtil.object.keys(t[s]).length>1)for(var a in t[s][i].describe)l[a]!=t[s][i].describe[a]&&delete l[a]}else l=MistUtil.object.extend({},t[s][i].describe);for(var i in t[s]){var c={},d={};for(var a in t[s][i].describe)a in l?d[a]=t[s][i].describe[a]:c[a]=t[s][i].describe[a];t[s][i].different=c,t[s][i].same=d;var u=MistUtil.object.values(c);t[s][i].displayName=u.length?u.join(", "):MistUtil.object.values(t[s][i].describe).join(" ")}var p={};for(var i in t[s]){if(t[s][i].displayName in p){var h=1;for(var i in t[s])t[s][i].different.trackid=h+")",t[s][i].displayName="Track "+h+" ("+t[s][i].displayName+")",h++;break}p[t[s][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,o=Math.max(0,(t.clientX/i-n)/a);return o=Math.min(o,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 o=1;ot.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"}};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 o="";o+='',o+='',o+=n,o+="",o+="";var s=document.createElement("div");return s.innerHTML=o,s.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)"string"==typeof this.css[i]&&t.push(MistUtil.css.load(e.urlappend(this.css[i]),this.colors));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 o=MistUtil.css.createStyle(t.css[r],a);n.appendChild(o)}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 s=this.buildStructure(t.children[r]);s&&n.appendChild(s)}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=e.skin.css.length;for(var a in n&&(i.style.opacity="0"),e.skin.css){var o=e.skin.css[a];o.callback=function(e){this.textContent=MistUtil.css.prependClass(e,r,!0),--n<=0&&(i.style.opacity="")},""!=o.textContent&&o.callback(o.textContent),i.appendChild(o)}MistUtil.class.add(i,r);var s=MistUtil.getBrowser();return s&&MistUtil.class.add(i,"browser-"+s),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}}]},{type:"speaker",classse:["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"},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:''},largeplay:{size:45,svg:''},pause:{size:45,svg:''},speaker:{size:45,svg:''},volume:{size:{width:100,height:45},svg:function(){var e=MistUtil.createUnique();return''}},muted:{size:45,svg:''},fullscreen:{size:45,svg:''},loop:{size:45,svg:''},settings:{size:45,svg:''},loading:{size:100,svg:''},timeout:{size:25,svg:function(e){e&&e.delay||(e={delay:10});var t=e.delay,i=MistUtil.createUnique();return''}},popout:{size:45,svg:''},switchvideo:{size:45,svg:''}}},blueprints:{container:function(){return document.createElement("div")},video:function(){var e=this;return MistUtil.event.addListener(e.video,"contextmenu",function(t){t.preventDefault(),e.container.setAttribute("data-show-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||(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)}})}})}}),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"),o=0;o30)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 .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);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"},o=function(e){window.removeEventListener("mousemove",a),window.removeEventListener("click",o),MistUtil.event.addListener(r,"click",s)},s=function(e){e.stopPropagation(),r.removeEventListener("click",s),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",o,t)};return MistUtil.event.addListener(r,"click",s),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.player.api,n=this;t.updateBar=function(e){if(this.kids.bar){if(!isFinite(r.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.duration))return 0;var t=0;if("live"==n.info.type){var i=.001*n.info.meta.buffer_window;t=(e-r.duration+i)/i}else t=e/r.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.5?(r.right=100*(1-i)+"%",a.triangle.setMode("bottom","right")):(r.left=100*i+"%",a.triangle.setMode("bottom","left")),a.setPos(r)}else a.style.opacity=0},MistUtil.event.addListener(e,"mousemove",function(e){t.moveTooltip(e)});var o=!1;return MistUtil.event.addListener(e,"mousedown",function(i){if(1==i.which){o=!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&&(o=!1,MistUtil.event.removeListener(r),MistUtil.event.removeListener(n),a.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")},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.player.api&&MistUtil.event.addListener(e.video,"click",function(){e.player.api.paused?e.player.api.play():MistUtil.isTouchDevice()||e.player.api.pause()},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 o=this;a.mode="mode"in e?e.mode:"vertical","vertical"==a.mode&&(a.style.transform="rotate(90deg)"),a.margin={start:.15,end:.1};var s=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;ii(t)?1:i(e)t[i]?1:t[e]1&&"player"in e&&"api"in e.player&&("setTrack"in e.player.api||"setTracks"in e.player.api||"setSource"in e.player.api)){var b=document.createElement("select");if(b.title="Select another "+l+" track",r[l]=b,b.trackType=l,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&&(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 o in a)MistUtil.event.addListener(e.video,a[o],function(t){!this.paused&&"container"in e&&r(t)},t);a=["seeked","playing","canplay","paused"];for(var o in a)MistUtil.event.addListener(e.video,a[o],function(t){"container"in e&&n()},t),MistUtil.event.addListener(e.video,"progress",function(t){"container"in e&&"monitor"in e&&"vars"in e.monitor&&"score"in e.monitor.vars&&e.monitor.vars.score>.99&&n()},t)}return t},error:function(){var e=this,t=document.createElement("div");t.message=function(t,i,r){MistUtil.empty(this);var n=document.createElement("div");if(n.className="message",this.appendChild(n),!r.polling&&!r.passive){var a=document.createElement("h3");n.appendChild(a),a.appendChild(document.createTextNode("The player has encountered a problem"))}var o=document.createElement("p");if(n.appendChild(o),n.update=function(e){MistUtil.empty(o),o.appendChild(document.createTextNode(e))},t){e.info.on_error&&(t=e.info.on_error.replace(/\/,t)),n.update(t);var s=document.createElement("p");if(s.className="details mistvideo-description",n.appendChild(s),i)s.appendChild(document.createTextNode(i));else if("decodingIssues"in e.skin.blueprints){if("player"in e&&"api"in e.player){if(i=[],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]))}}s.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(o,s){s||(s={softReload:!(!e.video||!e.video.load),reload:!0,nextCombo:!!e.info,polling:!1,passive:!1});var l=s.type?s.type:o;if(!(l in a)){if(!0===s.reload&&(e.options.reloadDelay&&!isNaN(Number(e.options.reloadDelay))?s.reload=Number(e.options.reloadDelay):s.reload=10),s.passive){if(!0===r)return;if(r)return i.update(o),void(n=(new Date).getTime());t.setAttribute("data-passive","")}else t.removeAttribute("data-passive");r=!s.passive||"passive",n=(new Date).getTime(),this.log(o,"error");var c=t.message(o,!1,s);i=c;var d=document.createElement("div");if(d.className="mistvideo-buttoncontainer",c.appendChild(d),MistUtil.empty(d),s.softReload){var u={type:"button",label:"Reload video",onclick:function(){e.player.api.load()}};isNaN(s.softReload+"")||(u.delay=s.softReload),d.appendChild(e.UI.buildStructure(u))}if(s.reload){u={type:"button",label:"Reload player",onclick:function(){e.reload()}};isNaN(s.reload+"")||(u.delay=s.reload),d.appendChild(e.UI.buildStructure(u))}if(s.nextCombo){u={type:"button",label:"Next source",onclick:function(){e.nextCombo()}};isNaN(s.nextCombo+"")||(u.delay=s.nextCombo),d.appendChild(e.UI.buildStructure(u))}if(s.ignore){u={type:"button",label:"Ignore",onclick:function(){this.clearError(),a[l]=!0}};isNaN(s.ignore+"")||(u.delay=s.ignore),d.appendChild(e.UI.buildStructure(u))}s.polling&&d.appendChild(e.UI.buildStructure({type:"polling"})),MistUtil.class.add(t,"show"),"container"in e&&e.container.removeAttribute("data-loading")}},t.clear=function(i){for(var n=t.querySelectorAll("svg.icon.timeout"),a=0;a=t.scrollHeight-5}),r.logs)s(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),s(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),s(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)}},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 o=document.createTextNode(e.value?e.value:"");a.appendChild(o);var s=document.createElement("span");a.appendChild(s),i.set=function(e){if(0!==e&&(this.style.display=""),"object"==typeof e){if("val"in e&&(o.nodeValue=e.val,a.className="value"),s.children.length)return(t=s.children[0]).addData(e);var t=MistUtil.createGraph({x:[e.x],y:[e.y]},e.options);return s.style.display="",MistUtil.empty(s),s.appendChild(t)}return o.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 o in t.info.source){var s=t.info.source[o];if(!(s.type in a)){a[s.type]=1;n=document.createElement("option");r.appendChild(n),n.value=s.type,n.appendChild(document.createTextNode(MistUtil.format.mime2human(s.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 o=t.info.source[a];n=document.createElement("option");r.appendChild(n),n.value=a,n.appendChild(document.createTextNode(o.url+" ("+MistUtil.format.mime2human(o.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:[{if:function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"video.load();",onclick:function(){this.player.api.load()}}},{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.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=data.error;return"on_error"in e&&(i.log(n),n=data.on_error),void i.showError(n,{reload:!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("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 o="maxwidth"in t&&t.maxwidth?t.maxwidth:window.innerWidth,s="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),o&&r>o&&l(r/o),s&&n>s&&l(n/s)}}}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 o in i.info.meta.tracks)a=Math.max(a,i.info.meta.tracks[o].lastms);e.lastms=a}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.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?.97:.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=2))for(var u in l[s.inner].list)if(l[s.inner].current=u,!(c(s.inner)>=1)){a=l.source.list[l.source.current];var p=l.player.list[l.player.current],h=mistplayers[p];if(h.isMimeSupported(a.type)&&h.isBrowserSupported(a.type,a,i))return{player:p,source:a,source_index:l.source.current};t||i.log("Checking "+h.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 a=i.options.host.replace(/^http/i,"ws"),o=new WebSocket(i.urlappend(a+"/json_"+encodeURIComponent(i.stream)+".js"));i.socket=o,o.die=!1,o.destroy=function(){this.die=!0,this.close()},o.onopen=function(e){this.wasConnected=!0},o.onclose=function(r){if(!this.die){if(this.wasConnected)return i.log("Reopening websocket.."),void 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"))}},o.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),t.error){case"Stream is offline":i.info=!1;case"Stream is initializing":case"Stream is booting":case"Stream is waiting for data":case"Stream is shutting down":a={polling:!0};break;default:a={reload:!0}}i.showError(e,a)}else{if(!i.info)return void n(t);var o=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(o){if("source"in o)return void("error"in i.info&&i.reload());i.info=MistUtil.object.extend(i.info,t),i.info.updated=new Date;var s=!1;for(var l in o)switch(l){case"meta":for(var c in o[l])switch(c){case"tracks":i.info.hasVideo=r(i.info),MistUtil.event.send("metaUpdate_tracks",t,i.video)}break;case"width":case"height":s=!0}s&&i.player.resize()}else i.log("Metachange: no differences detected")}})}()}else{var a=this.urlappend(t.host+"/json_"+encodeURIComponent(this.stream)+".js");this.log("Requesting stream info from "+a),MistUtil.http.get(a,function(e){i.destroyed||n(JSON.parse(e))},function(e){var r="Connection failed (failed to load "+a+")";i.showError(r,{reload:!0}),MistUtil.event.send("initializeFailed",null,t.target),i.log("Initialization failed")})}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){}if(this.UI&&this.UI.elements)for(var e in this.UI.elements){var n=this.UI.elements[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 diff --git a/embed/player.js b/embed/player.js index 6aac1a2c..d2c9dc0c 100644 --- a/embed/player.js +++ b/embed/player.js @@ -782,21 +782,68 @@ function MistVideo(streamName,options) { } - if (options.setTracks) { - if ("setTrack" in MistVideo.player.api) { - MistVideo.player.onready(function(){ - for (var i in options.setTracks) { - MistVideo.player.api.setTrack(i,options.setTracks[i]); + } + + if (options.setTracks) { + var setTracks = MistUtil.object.extend({},options.setTracks); + if (("subtitle" in options.setTracks) && ("setSubtitle" in MistVideo.player.api)) { + MistVideo.player.onready(function(){ + + //find the source for subtitles + var subtitleSource = false; + for (var i in MistVideo.info.source) { + var source = MistVideo.info.source[i]; + //this is a subtitle source, and it's the same protocol (HTTP/HTTPS) as the video source + if ((source.type == "html5/text/vtt") && (MistUtil.http.url.split(source.url).protocol == MistUtil.http.url.split(MistVideo.source.url).protocol)) { + subtitleSource = source.url.replace(/.srt$/,".vtt"); + break; } - }); - } - else if ("setTracks" in MistVideo.player.api) { - MistVideo.player.onready(function(){ - MistVideo.player.api.setTracks(options.setTracks); - }); - } + } + if (!subtitleSource) { return; } + + //find the track meta information + var tracks = MistUtil.tracks.parse(MistVideo.info.meta.tracks); + if (!("subtitle" in tracks) || !(setTracks.subtitle in tracks.subtitle)) { return; } + meta = tracks.subtitle[setTracks.subtitle]; + + //add source to the meta + meta.src = MistUtil.http.url.addParam(subtitleSource,{track:setTracks.subtitle}); + + meta.label = "automatic"; + meta.lang = "unknown"; + + MistVideo.player.api.setSubtitle(meta); + MistUtil.event.send("playerUpdate_trackChanged",{ + type: "subtitle", + trackid: setTracks.subtitle + }, MistVideo.video); + + delete setTracks.subtitle; + }); } + if ("setTrack" in MistVideo.player.api) { + MistVideo.player.onready(function(){ + for (var i in setTracks) { + MistVideo.player.api.setTrack(i,setTracks[i]); + MistUtil.event.send("playerUpdate_trackChanged",{ + type: i, + trackid: setTracks[i] + }, MistVideo.video); + } + }); + } + else if ("setTracks" in MistVideo.player.api) { + MistVideo.player.onready(function(){ + MistVideo.player.api.setTracks(setTracks); + }); + for (var i in setTracks) { + MistUtil.event.send("playerUpdate_trackChanged",{ + type: i, + trackid: setTracks[i] + }, MistVideo.video); + } + } } } diff --git a/embed/skins.js b/embed/skins.js index 7722e4fd..0087ed7d 100644 --- a/embed/skins.js +++ b/embed/skins.js @@ -1292,23 +1292,23 @@ MistSkins["default"] = { return MistVideo.player.api.setTrack(type,value); } else { - //gather what tracks we should use - var usetracks = {}; - for (var i in selections) { - if ((i == "subtitle") || (selections[i].value == "")) { continue; } //subtitle tracks are handled seperately - usetracks[i] = selections[i].value; - } - if (value != ""){ usetracks[type] = value; } - //use setTracks - if ("setTracks" in MistVideo.player.api) { - return MistVideo.player.api.setTracks(usetracks); - } - //use setSource - if ("setSource" in MistVideo.player.api) { - return MistVideo.player.api.setSource( - MistUtil.http.url.addParam(MistVideo.source.url,usetracks) - ); - } + //gather what tracks we should use + var usetracks = {}; + for (var i in selections) { + if ((i == "subtitle") || (selections[i].value == "")) { continue; } //subtitle tracks are handled seperately + usetracks[i] = selections[i].value; + } + if (value != ""){ usetracks[type] = value; } + //use setTracks + if ("setTracks" in MistVideo.player.api) { + return MistVideo.player.api.setTracks(usetracks); + } + //use setSource + if ("setSource" in MistVideo.player.api) { + return MistVideo.player.api.setSource( + MistUtil.http.url.addParam(MistVideo.source.url,usetracks) + ); + } } } @@ -1463,8 +1463,12 @@ MistSkins["default"] = { //add options to the select + function n(str) { + if (str == "") { return -1; } + return Number(str); + } var options = MistUtil.object.keys(t,function(a,b){ - return Number(a) - Number(b); + return n(a) - n(b); }); //sort them for (var i in options) { var track = t[options[i]]; @@ -1479,6 +1483,15 @@ MistSkins["default"] = { option.appendChild(document.createTextNode("Track "+(Number(i)+1))); } } + + MistUtil.event.addListener(MistVideo.video,"playerUpdate_trackChanged",function(e){ + + if (e.message.type != type) { return; } + select.value = e.message.trackid; + MistVideo.log("Player selected "+type+" track with id "+e.message.trackid); + + },select); + if (type == "subtitle") { MistUtil.event.addListener(select,"change",function(){ try { @@ -1538,13 +1551,6 @@ MistSkins["default"] = { } */ - MistUtil.event.addListener(MistVideo.video,"playerUpdate_trackChanged",function(e){ - - if (e.message.type != type) { return; } - select.value = e.message.trackid; - MistVideo.log("Player selected "+type+" track with id "+e.message.trackid); - - },select); } } else { diff --git a/lsp/minified.js b/lsp/minified.js index 97833c81..43df90b0 100644 --- a/lsp/minified.js +++ b/lsp/minified.js @@ -159,22 +159,22 @@ $(this).getval();$(".embed_code").setval(x(q))},help:"If the video should restar {label:"Poster",type:"str",pointer:{main:q,index:"poster"},"function":function(){q.poster=$(this).getval();$(".embed_code").setval(x(q))},help:"URL to an image that is displayed when the video is not playing."},{label:"Video URL addition",type:"str",pointer:{main:q,index:"urlappend"},help:"The embed script will append this string to the video url, useful for sending through params.",classes:["embed_code_forceprotocol"],"function":function(){q.urlappend=$(this).getval();$(".embed_code").setval(x(q))}}, {label:"Preselect tracks",type:"DOMfield",DOMfield:L,help:"Pre-select these tracks."},{label:"Monitoring action",type:"select",select:[["","Ask the viewer what to do"],["nextCombo","Try the next source / player combination"]],pointer:{main:q,index:"monitor_action"},"function":function(){q.monitor_action=$(this).getval();$(".embed_code").setval(x(q))},help:"What the player should do when playback is poor."},$("

").text("Protocol stream urls"),ba]));$.ajax({type:"GET",url:H+"json_"+C+".js",success:function(a){var b= [],c=O.find(".forceType"),d=O.find(".prioritize_type"),g;for(g in a.source){var e=a.source[g],f=UI.humanMime(e.type);b.push({label:f?f+" ("+e.type+")":UI.format.capital(e.type),type:"str",value:e.url,readonly:true,qrcode:true,clipboard:true});f=UI.humanMime(e.type);if(c.children('option[value="'+e.type+'"]').length==0){c.append($("