Merge branch 'development' into LTS_development

# Conflicts:
#	src/output/output.cpp
This commit is contained in:
Thulinma 2016-11-22 10:15:30 +01:00
commit 046d89d50c
14 changed files with 633 additions and 862 deletions

View file

@ -572,6 +572,11 @@ function mistPlay(streamName,options) {
//embedLog('Stream info contents: '+JSON.stringify(streaminfo));
streaminfo.initTime = new Date();
//sort the sources by priority and mime, but prefer HTTPS
streaminfo.source.sort(function(a,b){
return (b.priority - a.priority) || a.type.localeCompare(b.type) || b.url.localeCompare(a.url);
});
var mistPlayer = false;
var source;
var forceType = false;
@ -579,6 +584,12 @@ function mistPlay(streamName,options) {
embedLog('Forcing '+options.forceType);
forceType = options.forceType;
}
var forceSource = false;
if (('forceSource' in options) && (options.forceSource)) {
forceSource = options.forceSource;
forceType = streaminfo.source[forceSource].type;
embedLog('Forcing source '+options.forceSource+': '+forceType+' @ '+streaminfo.source[forceSource].url);
}
var forceSupportCheck = false;
if (('forceSupportCheck' in options) && (options.forceSupportCheck)) {
embedLog('Forcing a full support check');
@ -615,16 +626,21 @@ function mistPlay(streamName,options) {
return false;
}
function checkMime(p_shortname,mime) {
embedLog('Checking if Mist broadcasts '+mime+'..');
for (var s in streaminfo.source) {
if (streaminfo.source[s].type == mime) {
embedLog('Yup! Checking browser support..');
if (mistplayers[p_shortname].isBrowserSupported(mime)) {
embedLog('Yup! This is a working player/source combo.');
var loop;
if (forceSource) {
loop = [streaminfo.source[forceSource]];
}
else {
loop = streaminfo.source;
}
for (var s in loop) {
if (loop[s].type == mime) {
if (mistplayers[p_shortname].isBrowserSupported(mime,loop[s],options)) {
embedLog('Found a working combo: '+mistplayers[p_shortname].name+' with '+mime+' @ '+loop[s].url);
streaminfo.working[p_shortname].push(mime);
if (!source) {
mistPlayer = p_shortname;
source = streaminfo.source[s];
source = loop[s];
}
if (!forceSupportCheck) {
return source;
@ -632,6 +648,8 @@ function mistPlay(streamName,options) {
}
}
}
embedLog('Mist doesn\'t broadcast '+mime+' or there is no browser support.');
return false;
}
@ -651,16 +669,16 @@ function mistPlay(streamName,options) {
}
}
options.target.innerHTML = '';
if (mistPlayer) {
embedLog('Preparing to build '+mistplayers[mistPlayer].name);
//create the options to send to the player
var playerOpts = {
src: source.url+(('urlappend' in options) && (options.urlappend) ? options.urlappend : '' ),
live: (streaminfo.type == 'live' ? true : false),
initTime: streaminfo.initTime,
meta: streaminfo.meta,
source: source
source: source,
host: options.host
};
//pass player options and handle defaults
playerOpts.autoplay = options.autoplay;
@ -733,6 +751,7 @@ function mistPlay(streamName,options) {
};
for (var i in streaminfo.meta.tracks) {
var t = streaminfo.meta.tracks[i];
var skip = false;
switch (t.type) {
case 'video':
t.desc = ['['+t.codec+']',t.width+'x'+t.height,Math.round(t.bps/1024)+'kbps',t.fpks/1e3+'fps',t.lang];
@ -743,7 +762,11 @@ function mistPlay(streamName,options) {
case 'subtitle':
t.desc = ['['+t.codec+']',t.lang];
break;
default:
skip = true;
break;
}
if (skip) { continue; }
t.desc = t.desc.join(', ');
tracks[t.type].push(t);
}

View file

@ -15,13 +15,14 @@
<script>
// global options can be set here
var mistoptions = {
host: 'http://cattop:8080'
host: 'http://cat.mistserver.org:8080'
//host: 'https://cat.mistserver.org:4433'
};
</script>
<script src=core.js></script>
<script src=wrappers/theoplayer.js></script>
<script src=wrappers/jwplayer.js></script>
<!--<script src=wrappers/theoplayer.js></script>-->
<!--<script src=wrappers/jwplayer.js></script>-->
<script src=wrappers/html5.js></script>
<script src=wrappers/dashjs.js></script>
<script src=wrappers/flash_strobe.js></script>
@ -65,26 +66,31 @@
//tryplayers = Object.keys(mistplayers);
tryplayers = [];
tryplayers.push('html5');
//tryplayers.push('dashjs');
//tryplayers.push('html5');
tryplayers.push('dashjs');
//tryplayers.push('flash_strobe');
//tryplayers.push('silverlight');
streams = [];
//streams.push('live');
//streams.push('vids+mist.mp4');
//streams.push('lama');
streams.push('bunny');
for (var j in streams) {
for (var i in tryplayers) {
var c = document.createElement('div');
c.className = 'mistvideo';
c.title = tryplayers[i];
document.body.appendChild(c);
//mistPlay('live',{
//mistPlay('vids+mist.mp4',{
//mistPlay('lama',{
mistPlay('bunny',{
mistPlay(streams[j],{
target: c,
forcePlayer: tryplayers[i],
//forceType: 'flash/7',
//forceSource: 5,
loop: true
});
}
}
};

View file

@ -5,7 +5,8 @@ mistplayers.dashjs = {
isMimeSupported: function (mimetype) {
return (this.mimes.indexOf(mimetype) == -1 ? false : true);
},
isBrowserSupported: function (mimetype) {
isBrowserSupported: function (mimetype,source,options) {
if ((options.host.substr(0,7) == 'http://') && (source.url.substr(0,8) == 'https://')) { return false; }
return (('dashjs' in window) && ('MediaSource' in window) && (location.protocol != 'file:'));
},
player: function(){}

View file

@ -5,7 +5,10 @@ mistplayers.flash_strobe = {
isMimeSupported: function (mimetype) {
return (this.mimes.indexOf(mimetype) == -1 ? false : true);
},
isBrowserSupported: function (mimetype) {
isBrowserSupported: function (mimetype,source,options) {
//check for http / https crossovers
if ((options.host.substr(0,7) == 'http://') && (source.url.substr(0,8) == 'https://')) { return false; }
var version = 0;
try {
// check in the mimeTypes
@ -38,7 +41,7 @@ p.prototype.build = function (options) {
ele.setAttribute('width',options.width);
ele.setAttribute('height',options.height);
ele.appendChild(createParam('movie',options.source.player_url));
ele.appendChild(createParam('movie',options.host+options.source.player_url));
var flashvars = 'src='+encodeURIComponent(options.src)+'&controlBarMode='+(options.controls ? 'floating' : 'none')+'&initialBufferTime=0.5&expandedBufferTime=5&minContinuousPlaybackTime=3'+(options.live ? '&streamType=live' : '')+(options.autoplay ? '&autoPlay=true' : '' );
ele.appendChild(createParam('flashvars',flashvars));
ele.appendChild(createParam('allowFullScreen','true'));

View file

@ -135,15 +135,55 @@ p.prototype.build = function (options,callback) {
ele.addEventListener('progress',nolongerdced);
}
//ele.addEventListener('stalled',dced,true);
ele.addEventListener('stalled',dced,true);
ele.addEventListener('ended',dced,true);
ele.addEventListener('pause',dced,true);
}
this.addlog('Built html');
//forward events
ele.addEventListener('error',function(e){
me.adderror(e.message);
var msg;
if ('message' in e) {
msg = e.message;
}
else {
msg = 'readyState: ';
switch (me.element.readyState) {
case 0:
msg += 'HAVE_NOTHING';
break;
case 1:
msg += 'HAVE_METADATA';
break;
case 2:
msg += 'HAVE_CURRENT_DATA';
break;
case 3:
msg += 'HAVE_FUTURE_DATA';
break;
case 4:
msg += 'HAVE_ENOUGH_DATA';
break;
}
msg += ' networkState: ';
switch (me.element.networkState) {
case 0:
msg += 'NETWORK_EMPTY';
break;
case 1:
msg += 'NETWORK_IDLE';
break;
case 2:
msg += 'NETWORK_LOADING';
break;
case 3:
msg += 'NETWORK_NO_SOURCE';
break;
}
}
me.adderror(msg);
},true);
var events = ['abort','canplay','canplaythrough','durationchange','emptied','ended','interruptbegin','interruptend','loadeddata','loadedmetadata','loadstart','pause','play','playing','ratechange','seeked','seeking','stalled','volumechange','waiting'];
for (var i in events) {

View file

@ -848,6 +848,19 @@ button.return:before {
color: rgba(0,0,0,0.8);
margin-bottom: 1em;
}
.logs {
text-indent: 0;
}
.logs > div {
display: flex;
flex-flow: row nowrap;
}
.logs > div > * {
margin-right: 1em;
}
.logs .content > * {
margin-right: 0.5em;
}
@font-face {
font-family: FuturaICGLight;

View file

@ -1,14 +1,14 @@
var MD5=function(a){function b(a,b){var c,d,g,f,i;g=a&2147483648;f=b&2147483648;c=a&1073741824;d=b&1073741824;i=(a&1073741823)+(b&1073741823);return c&d?i^2147483648^g^f:c|d?i&1073741824?i^3221225472^g^f:i^1073741824^g^f:i^g^f}function c(a,c,d,g,f,i,j){a=b(a,b(b(c&d|~c&g,f),j));return b(a<<i|a>>>32-i,c)}function d(a,c,d,g,f,i,j){a=b(a,b(b(c&g|d&~g,f),j));return b(a<<i|a>>>32-i,c)}function e(a,c,d,g,f,i,j){a=b(a,b(b(c^d^g,f),j));return b(a<<i|a>>>32-i,c)}function l(a,c,d,g,f,i,j){a=b(a,b(b(d^(c|~g),
f),j));return b(a<<i|a>>>32-i,c)}function n(a){var b="",c="",d;for(d=0;3>=d;d++)c=a>>>8*d&255,c="0"+c.toString(16),b+=c.substr(c.length-2,2);return b}var h=[],q,p,f,v,g,i,j,k,h=a.replace(/\r\n/g,"\n"),a="";for(q=0;q<h.length;q++)p=h.charCodeAt(q),128>p?a+=String.fromCharCode(p):(127<p&&2048>p?a+=String.fromCharCode(p>>6|192):(a+=String.fromCharCode(p>>12|224),a+=String.fromCharCode(p>>6&63|128)),a+=String.fromCharCode(p&63|128));h=a;a=h.length;q=a+8;p=16*((q-q%64)/64+1);f=Array(p-1);for(g=v=0;g<a;)q=
(g-g%4)/4,v=8*(g%4),f[q]|=h.charCodeAt(g)<<v,g++;q=(g-g%4)/4;f[q]|=128<<8*(g%4);f[p-2]=a<<3;f[p-1]=a>>>29;h=f;g=1732584193;i=4023233417;j=2562383102;k=271733878;for(a=0;a<h.length;a+=16)q=g,p=i,f=j,v=k,g=c(g,i,j,k,h[a+0],7,3614090360),k=c(k,g,i,j,h[a+1],12,3905402710),j=c(j,k,g,i,h[a+2],17,606105819),i=c(i,j,k,g,h[a+3],22,3250441966),g=c(g,i,j,k,h[a+4],7,4118548399),k=c(k,g,i,j,h[a+5],12,1200080426),j=c(j,k,g,i,h[a+6],17,2821735955),i=c(i,j,k,g,h[a+7],22,4249261313),g=c(g,i,j,k,h[a+8],7,1770035416),
k=c(k,g,i,j,h[a+9],12,2336552879),j=c(j,k,g,i,h[a+10],17,4294925233),i=c(i,j,k,g,h[a+11],22,2304563134),g=c(g,i,j,k,h[a+12],7,1804603682),k=c(k,g,i,j,h[a+13],12,4254626195),j=c(j,k,g,i,h[a+14],17,2792965006),i=c(i,j,k,g,h[a+15],22,1236535329),g=d(g,i,j,k,h[a+1],5,4129170786),k=d(k,g,i,j,h[a+6],9,3225465664),j=d(j,k,g,i,h[a+11],14,643717713),i=d(i,j,k,g,h[a+0],20,3921069994),g=d(g,i,j,k,h[a+5],5,3593408605),k=d(k,g,i,j,h[a+10],9,38016083),j=d(j,k,g,i,h[a+15],14,3634488961),i=d(i,j,k,g,h[a+4],20,3889429448),
g=d(g,i,j,k,h[a+9],5,568446438),k=d(k,g,i,j,h[a+14],9,3275163606),j=d(j,k,g,i,h[a+3],14,4107603335),i=d(i,j,k,g,h[a+8],20,1163531501),g=d(g,i,j,k,h[a+13],5,2850285829),k=d(k,g,i,j,h[a+2],9,4243563512),j=d(j,k,g,i,h[a+7],14,1735328473),i=d(i,j,k,g,h[a+12],20,2368359562),g=e(g,i,j,k,h[a+5],4,4294588738),k=e(k,g,i,j,h[a+8],11,2272392833),j=e(j,k,g,i,h[a+11],16,1839030562),i=e(i,j,k,g,h[a+14],23,4259657740),g=e(g,i,j,k,h[a+1],4,2763975236),k=e(k,g,i,j,h[a+4],11,1272893353),j=e(j,k,g,i,h[a+7],16,4139469664),
i=e(i,j,k,g,h[a+10],23,3200236656),g=e(g,i,j,k,h[a+13],4,681279174),k=e(k,g,i,j,h[a+0],11,3936430074),j=e(j,k,g,i,h[a+3],16,3572445317),i=e(i,j,k,g,h[a+6],23,76029189),g=e(g,i,j,k,h[a+9],4,3654602809),k=e(k,g,i,j,h[a+12],11,3873151461),j=e(j,k,g,i,h[a+15],16,530742520),i=e(i,j,k,g,h[a+2],23,3299628645),g=l(g,i,j,k,h[a+0],6,4096336452),k=l(k,g,i,j,h[a+7],10,1126891415),j=l(j,k,g,i,h[a+14],15,2878612391),i=l(i,j,k,g,h[a+5],21,4237533241),g=l(g,i,j,k,h[a+12],6,1700485571),k=l(k,g,i,j,h[a+3],10,2399980690),
j=l(j,k,g,i,h[a+10],15,4293915773),i=l(i,j,k,g,h[a+1],21,2240044497),g=l(g,i,j,k,h[a+8],6,1873313359),k=l(k,g,i,j,h[a+15],10,4264355552),j=l(j,k,g,i,h[a+6],15,2734768916),i=l(i,j,k,g,h[a+13],21,1309151649),g=l(g,i,j,k,h[a+4],6,4149444226),k=l(k,g,i,j,h[a+11],10,3174756917),j=l(j,k,g,i,h[a+2],15,718787259),i=l(i,j,k,g,h[a+9],21,3951481745),g=b(g,q),i=b(i,p),j=b(j,f),k=b(k,v);return(n(g)+n(i)+n(j)+n(k)).toLowerCase()};(function(a){a.fn.stupidtable=function(){a(this).on("click","thead th",function(){a(this).stupidsort()})};a.fn.stupidsort=function(){function b(b){var c=0,d;a(b).children("td,th").each(function(){if(c==q)return d=a(this),!1;var b=a(this).attr("colspan");c+=b?Number(b):1});b="undefined"!=typeof d.data("sort-value")?d.data("sort-value"):"undefined"!=typeof d.attr("data-sort-value")?d.attr("data-sort-value"):d.text();switch(n){case "string":case "string-ins":b=String(b).toLowerCase();break;case "int":b=
parseInt(Number(b));break;case "float":b=Number(b)}return b}var c=a(this),d=c.closest("table"),e=d.children("tbody"),l=e.children("tr"),n=c.attr("data-sort-type");if(n){var h=!0;c.hasClass("sorting-asc")&&(h=!1);var q=0;c.prevAll().each(function(){var b=a(this).attr("colspan");q+=b?Number(b):1});l.sort(function(a,c){var d=h?1:-1,a=b(a),c=b(c);return a>c?1*d:a<c?-1*d:0});e.append(l);d.find("thead th").removeClass("sorting-asc").removeClass("sorting-desc");c.addClass(h?"sorting-asc":"sorting-desc")}}})(jQuery);$(function(){UI.elements={menu:$("nav > .menu"),main:$("main"),header:$("header"),connection:{status:$("#connection"),user_and_host:$("#user_and_host"),msg:$("#message")}};UI.buildMenu();UI.stored.getOpts();try{if("mistLogin"in sessionStorage){var a=JSON.parse(sessionStorage.mistLogin);mist.user.name=a.name;mist.user.password=a.password;mist.user.host=a.host}}catch(b){}location.hash&&(a=decodeURIComponent(location.hash).substring(1).split("@")[0].split("&"),mist.user.name=a[0],a[1]&&(mist.user.host=
var MD5=function(a){function b(a,b){var g,c,d,h,i;d=a&2147483648;h=b&2147483648;g=a&1073741824;c=b&1073741824;i=(a&1073741823)+(b&1073741823);return g&c?i^2147483648^d^h:g|c?i&1073741824?i^3221225472^d^h:i^1073741824^d^h:i^d^h}function c(a,g,d,c,h,i,f){a=b(a,b(b(g&d|~g&c,h),f));return b(a<<i|a>>>32-i,g)}function d(a,g,d,c,h,i,f){a=b(a,b(b(g&c|d&~c,h),f));return b(a<<i|a>>>32-i,g)}function e(a,g,c,d,h,i,f){a=b(a,b(b(g^c^d,h),f));return b(a<<i|a>>>32-i,g)}function k(a,g,c,d,h,i,f){a=b(a,b(b(c^(g|~d),
h),f));return b(a<<i|a>>>32-i,g)}function m(a){var b="",g="",c;for(c=0;3>=c;c++)g=a>>>8*c&255,g="0"+g.toString(16),b+=g.substr(g.length-2,2);return b}var f=[],q,p,l,v,h,g,i,j,f=a.replace(/\r\n/g,"\n"),a="";for(q=0;q<f.length;q++)p=f.charCodeAt(q),128>p?a+=String.fromCharCode(p):(127<p&&2048>p?a+=String.fromCharCode(p>>6|192):(a+=String.fromCharCode(p>>12|224),a+=String.fromCharCode(p>>6&63|128)),a+=String.fromCharCode(p&63|128));f=a;a=f.length;q=a+8;p=16*((q-q%64)/64+1);l=Array(p-1);for(h=v=0;h<a;)q=
(h-h%4)/4,v=8*(h%4),l[q]|=f.charCodeAt(h)<<v,h++;q=(h-h%4)/4;l[q]|=128<<8*(h%4);l[p-2]=a<<3;l[p-1]=a>>>29;f=l;h=1732584193;g=4023233417;i=2562383102;j=271733878;for(a=0;a<f.length;a+=16)q=h,p=g,l=i,v=j,h=c(h,g,i,j,f[a+0],7,3614090360),j=c(j,h,g,i,f[a+1],12,3905402710),i=c(i,j,h,g,f[a+2],17,606105819),g=c(g,i,j,h,f[a+3],22,3250441966),h=c(h,g,i,j,f[a+4],7,4118548399),j=c(j,h,g,i,f[a+5],12,1200080426),i=c(i,j,h,g,f[a+6],17,2821735955),g=c(g,i,j,h,f[a+7],22,4249261313),h=c(h,g,i,j,f[a+8],7,1770035416),
j=c(j,h,g,i,f[a+9],12,2336552879),i=c(i,j,h,g,f[a+10],17,4294925233),g=c(g,i,j,h,f[a+11],22,2304563134),h=c(h,g,i,j,f[a+12],7,1804603682),j=c(j,h,g,i,f[a+13],12,4254626195),i=c(i,j,h,g,f[a+14],17,2792965006),g=c(g,i,j,h,f[a+15],22,1236535329),h=d(h,g,i,j,f[a+1],5,4129170786),j=d(j,h,g,i,f[a+6],9,3225465664),i=d(i,j,h,g,f[a+11],14,643717713),g=d(g,i,j,h,f[a+0],20,3921069994),h=d(h,g,i,j,f[a+5],5,3593408605),j=d(j,h,g,i,f[a+10],9,38016083),i=d(i,j,h,g,f[a+15],14,3634488961),g=d(g,i,j,h,f[a+4],20,3889429448),
h=d(h,g,i,j,f[a+9],5,568446438),j=d(j,h,g,i,f[a+14],9,3275163606),i=d(i,j,h,g,f[a+3],14,4107603335),g=d(g,i,j,h,f[a+8],20,1163531501),h=d(h,g,i,j,f[a+13],5,2850285829),j=d(j,h,g,i,f[a+2],9,4243563512),i=d(i,j,h,g,f[a+7],14,1735328473),g=d(g,i,j,h,f[a+12],20,2368359562),h=e(h,g,i,j,f[a+5],4,4294588738),j=e(j,h,g,i,f[a+8],11,2272392833),i=e(i,j,h,g,f[a+11],16,1839030562),g=e(g,i,j,h,f[a+14],23,4259657740),h=e(h,g,i,j,f[a+1],4,2763975236),j=e(j,h,g,i,f[a+4],11,1272893353),i=e(i,j,h,g,f[a+7],16,4139469664),
g=e(g,i,j,h,f[a+10],23,3200236656),h=e(h,g,i,j,f[a+13],4,681279174),j=e(j,h,g,i,f[a+0],11,3936430074),i=e(i,j,h,g,f[a+3],16,3572445317),g=e(g,i,j,h,f[a+6],23,76029189),h=e(h,g,i,j,f[a+9],4,3654602809),j=e(j,h,g,i,f[a+12],11,3873151461),i=e(i,j,h,g,f[a+15],16,530742520),g=e(g,i,j,h,f[a+2],23,3299628645),h=k(h,g,i,j,f[a+0],6,4096336452),j=k(j,h,g,i,f[a+7],10,1126891415),i=k(i,j,h,g,f[a+14],15,2878612391),g=k(g,i,j,h,f[a+5],21,4237533241),h=k(h,g,i,j,f[a+12],6,1700485571),j=k(j,h,g,i,f[a+3],10,2399980690),
i=k(i,j,h,g,f[a+10],15,4293915773),g=k(g,i,j,h,f[a+1],21,2240044497),h=k(h,g,i,j,f[a+8],6,1873313359),j=k(j,h,g,i,f[a+15],10,4264355552),i=k(i,j,h,g,f[a+6],15,2734768916),g=k(g,i,j,h,f[a+13],21,1309151649),h=k(h,g,i,j,f[a+4],6,4149444226),j=k(j,h,g,i,f[a+11],10,3174756917),i=k(i,j,h,g,f[a+2],15,718787259),g=k(g,i,j,h,f[a+9],21,3951481745),h=b(h,q),g=b(g,p),i=b(i,l),j=b(j,v);return(m(h)+m(g)+m(i)+m(j)).toLowerCase()};(function(a){a.fn.stupidtable=function(){a(this).on("click","thead th",function(){a(this).stupidsort()})};a.fn.stupidsort=function(){function b(b){var c=0,d;a(b).children("td,th").each(function(){if(c==q)return d=a(this),!1;var b=a(this).attr("colspan");c+=b?Number(b):1});b="undefined"!=typeof d.data("sort-value")?d.data("sort-value"):"undefined"!=typeof d.attr("data-sort-value")?d.attr("data-sort-value"):d.text();switch(m){case "string":case "string-ins":b=String(b).toLowerCase();break;case "int":b=
parseInt(Number(b));break;case "float":b=Number(b)}return b}var c=a(this),d=c.closest("table"),e=d.children("tbody"),k=e.children("tr"),m=c.attr("data-sort-type");if(m){var f=!0;c.hasClass("sorting-asc")&&(f=!1);var q=0;c.prevAll().each(function(){var b=a(this).attr("colspan");q+=b?Number(b):1});k.sort(function(a,c){var d=f?1:-1,a=b(a),c=b(c);return a>c?1*d:a<c?-1*d:0});e.append(k);d.find("thead th").removeClass("sorting-asc").removeClass("sorting-desc");c.addClass(f?"sorting-asc":"sorting-desc")}}})(jQuery);$(function(){UI.elements={menu:$("nav > .menu"),main:$("main"),header:$("header"),connection:{status:$("#connection"),user_and_host:$("#user_and_host"),msg:$("#message")}};UI.buildMenu();UI.stored.getOpts();try{if("mistLogin"in sessionStorage){var a=JSON.parse(sessionStorage.mistLogin);mist.user.name=a.name;mist.user.password=a.password;mist.user.host=a.host}}catch(b){}location.hash&&(a=decodeURIComponent(location.hash).substring(1).split("@")[0].split("&"),mist.user.name=a[0],a[1]&&(mist.user.host=
a[1]));mist.send(function(){$(window).trigger("hashchange")},{},{timeout:5,hide:!0});var c=0;$("body > div.filler").on("scroll",function(){var a=$(this).scrollLeft();a!=c&&UI.elements.header.css("margin-right",-1*a+"px");c=a})});$(window).on("hashchange",function(){var a=decodeURIComponent(location.hash).substring(1).split("@");a[1]||(a[1]="");a=a[1].split("&");""==a[0]&&(a[0]="Overview");UI.showTab(a[0],a[1])});
var otherhost=!1,UI={debug:!1,elements:{},stored:{getOpts:function(){var a=localStorage.stored;a&&(a=JSON.parse(a));$.extend(!0,this.vars,a);return this.vars},saveOpt:function(a,b){this.vars[a]=b;localStorage.stored=JSON.stringify(this.vars);return this.vars},vars:{helpme:!0}},interval:{clear:function(){"undefined"!=typeof this.opts&&(clearInterval(this.opts.id),delete this.opts)},set:function(a,b){this.opts&&log("[interval]","Set called on interval, but an interval is already active.");this.opts=
{delay:b,callback:a};this.opts.id=setInterval(a,b)}},returnTab:["Overview"],countrylist:{AF:"Afghanistan",AX:"&Aring;land Islands",AL:"Albania",DZ:"Algeria",AS:"American Samoa",AD:"Andorra",AO:"Angola",AI:"Anguilla",AQ:"Antarctica",AG:"Antigua and Barbuda",AR:"Argentina",AM:"Armenia",AW:"Aruba",AU:"Australia",AT:"Austria",AZ:"Azerbaijan",BS:"Bahamas",BH:"Bahrain",BD:"Bangladesh",BB:"Barbados",BY:"Belarus",BE:"Belgium",BZ:"Belize",BJ:"Benin",BM:"Bermuda",BT:"Bhutan",BO:"Bolivia, Plurinational State of",
var otherhost={host:!1,https:!1},UI={debug:!1,elements:{},stored:{getOpts:function(){var a=localStorage.stored;a&&(a=JSON.parse(a));$.extend(!0,this.vars,a);return this.vars},saveOpt:function(a,b){this.vars[a]=b;localStorage.stored=JSON.stringify(this.vars);return this.vars},vars:{helpme:!0}},interval:{clear:function(){"undefined"!=typeof this.opts&&(clearInterval(this.opts.id),delete this.opts)},set:function(a,b){this.opts&&log("[interval]","Set called on interval, but an interval is already active.");
this.opts={delay:b,callback:a};this.opts.id=setInterval(a,b)}},returnTab:["Overview"],countrylist:{AF:"Afghanistan",AX:"&Aring;land Islands",AL:"Albania",DZ:"Algeria",AS:"American Samoa",AD:"Andorra",AO:"Angola",AI:"Anguilla",AQ:"Antarctica",AG:"Antigua and Barbuda",AR:"Argentina",AM:"Armenia",AW:"Aruba",AU:"Australia",AT:"Austria",AZ:"Azerbaijan",BS:"Bahamas",BH:"Bahrain",BD:"Bangladesh",BB:"Barbados",BY:"Belarus",BE:"Belgium",BZ:"Belize",BJ:"Benin",BM:"Bermuda",BT:"Bhutan",BO:"Bolivia, Plurinational State of",
BQ:"Bonaire, Sint Eustatius and Saba",BA:"Bosnia and Herzegovina",BW:"Botswana",BV:"Bouvet Island",BR:"Brazil",IO:"British Indian Ocean Territory",BN:"Brunei Darussalam",BG:"Bulgaria",BF:"Burkina Faso",BI:"Burundi",KH:"Cambodia",CM:"Cameroon",CA:"Canada",CV:"Cape Verde",KY:"Cayman Islands",CF:"Central African Republic",TD:"Chad",CL:"Chile",CN:"China",CX:"Christmas Island",CC:"Cocos (Keeling) Islands",CO:"Colombia",KM:"Comoros",CG:"Congo",CD:"Congo, the Democratic Republic of the",CK:"Cook Islands",
CR:"Costa Rica",CI:"C&ocirc;te d'Ivoire",HR:"Croatia",CU:"Cuba",CW:"Cura&ccedil;ao",CY:"Cyprus",CZ:"Czech Republic",DK:"Denmark",DJ:"Djibouti",DM:"Dominica",DO:"Dominican Republic",EC:"Ecuador",EG:"Egypt",SV:"El Salvador",GQ:"Equatorial Guinea",ER:"Eritrea",EE:"Estonia",ET:"Ethiopia",FK:"Falkland Islands (Malvinas)",FO:"Faroe Islands",FJ:"Fiji",FI:"Finland",FR:"France",GF:"French Guiana",PF:"French Polynesia",TF:"French Southern Territories",GA:"Gabon",GM:"Gambia",GE:"Georgia",DE:"Germany",GH:"Ghana",
GI:"Gibraltar",GR:"Greece",GL:"Greenland",GD:"Grenada",GP:"Guadeloupe",GU:"Guam",GT:"Guatemala",GG:"Guernsey",GN:"Guinea",GW:"Guinea-Bissau",GY:"Guyana",HT:"Haiti",HM:"Heard Island and McDonald Islands",VA:"Holy See (Vatican City State)",HN:"Honduras",HK:"Hong Kong",HU:"Hungary",IS:"Iceland",IN:"India",ID:"Indonesia",IR:"Iran, Islamic Republic of",IQ:"Iraq",IE:"Ireland",IM:"Isle of Man",IL:"Israel",IT:"Italy",JM:"Jamaica",JP:"Japan",JE:"Jersey",JO:"Jordan",KZ:"Kazakhstan",KE:"Kenya",KI:"Kiribati",
@ -21,172 +21,182 @@ clearTimeout(this.hiding);delete this.hiding;var c=$(document).height()-$tooltip
"HLS";break;case "html5/video/mp4":b="MP4";break;case "dash/video/mp4":b="DASH";break;case "flash/11":b="HDS";break;case "flash/10":b="RTMP";break;case "flash/7":b="Progressive";break;case "html5/audio/mp3":b="MP3";break;case "html5/video/mp2t":b="TS";break;case "html5/application/vnd.ms-ss":b="Smooth";break;case "html5/text/vtt":b="VTT Subtitles";break;case "html5/text/plain":b="SRT Subtitles";break;case "html5/text/javascript":b="JSON Subtitles"}return b},popup:{element:null,show:function(a){this.element=
$("<div>").attr("id","popup").append($("<button>").text("Close").addClass("close").click(function(){UI.popup.element.fadeOut("fast",function(){UI.popup.element.remove();UI.popup.element=null})})).append(a);$("body").append(this.element)}},menu:[{Overview:{},Protocols:{},Streams:{hiddenmenu:{Edit:{},Preview:{},Embed:{}}},Push:{LTSonly:!0},Triggers:{LTSonly:!1},Logs:{},Statistics:{},"Server Stats":{}},{Disconnect:{classes:["red"]}},{Guides:{link:"http://mistserver.org/documentation#Userdocs"},Tools:{submenu:{"Release notes":{link:"http://mistserver.org/documentation#Devdocs"},
"Mist Shop":{link:"http://mistserver.org/products"},"Email for Help":{},ToS:{link:"http://mistserver.org/documentation#Legal"}}}}],buildMenu:function(){function a(a,b){var c=$("<a>").addClass("button");c.html($("<span>").addClass("plain").text(a)).append($("<span>").addClass("highlighted").text(a));for(var d in b.classes)c.addClass(b.classes[d]);"LTSonly"in b&&c.addClass("LTSonly");"link"in b?c.attr("href",b.link).attr("target","_blank"):"submenu"in b||c.click(function(b){$(this).closest(".menu").hasClass("hide")||
(UI.navto(a),b.stopPropagation())});return c}var b=UI.elements.menu,c;for(c in UI.menu){0<c&&b.append($("<br>"));for(var d in UI.menu[c]){var e=UI.menu[c][d],l=a(d,e);b.append(l);if("submenu"in e){var n=$("<span>").addClass("submenu");l.addClass("arrowdown").append(n);for(var h in e.submenu)n.append(a(h,e.submenu[h]))}else if("hiddenmenu"in e)for(h in n=$("<span>").addClass("hiddenmenu"),l.append(n),e.hiddenmenu)n.append(a(h,e.hiddenmenu[h]))}}c=$("<div>").attr("id","ih_button").text("?").click(function(){$("body").toggleClass("helpme");
(UI.navto(a),b.stopPropagation())});return c}var b=UI.elements.menu,c;for(c in UI.menu){0<c&&b.append($("<br>"));for(var d in UI.menu[c]){var e=UI.menu[c][d],k=a(d,e);b.append(k);if("submenu"in e){var m=$("<span>").addClass("submenu");k.addClass("arrowdown").append(m);for(var f in e.submenu)m.append(a(f,e.submenu[f]))}else if("hiddenmenu"in e)for(f in m=$("<span>").addClass("hiddenmenu"),k.append(m),e.hiddenmenu)m.append(a(f,e.hiddenmenu[f]))}}c=$("<div>").attr("id","ih_button").text("?").click(function(){$("body").toggleClass("helpme");
UI.stored.saveOpt("helpme",$("body").hasClass("helpme"))}).attr("title","Click to toggle the display of integrated help");UI.stored.getOpts().helpme&&$("body").addClass("helpme");b.after(c).after($("<div>").addClass("separator"))},buildUI:function(a){var b=$("<div>").addClass("input_container"),c;for(c in a){var d=a[c];if(d instanceof jQuery)b.append(d);else if("help"==d.type){var e=$("<span>").addClass("text_container").append($("<span>").addClass("description").append(d.help));b.append(e);if("classes"in
d)for(var l in d.classes)e.addClass(d.classes[l])}else if("text"==d.type)b.append($("<span>").addClass("text_container").append($("<span>").addClass("text").append(d.text)));else if("custom"==d.type)b.append(d.custom);else if("buttons"==d.type)for(l in e=$("<span>").addClass("button_container").on("keydown",function(a){a.stopPropagation()}),"css"in d&&e.css(d.css),b.append(e),d.buttons){var n=d.buttons[l],h=$("<button>").text(n.label).data("opts",n);"css"in n&&h.css(n.css);if("classes"in n)for(var q in n.classes)h.addClass(n.classes[q]);
e.append(h);switch(n.type){case "cancel":h.addClass("cancel").click(n["function"]);break;case "save":h.addClass("save").click(function(){var a=$(this).closest(".input_container"),b=!1;a.find(".hasValidate").each(function(){if(b=$(this).data("validate")(this,!0))return!1});b||(a.find(".isSetting").each(function(){var a=$(this).getval(),b=$(this).data("pointer");if(""==a)if("default"in $(this).data("opts"))a=$(this).data("opts")["default"];else return delete b.main[b.index],!0;b.main[b.index]=a}),(a=
$(this).data("opts")["function"])&&a(this))});break;default:h.click(n["function"])}}else{n=$("<label>").addClass("UIelement");b.append(n);"css"in d&&n.css(d.css);n.append($("<span>").addClass("label").html("label"in d?d.label+":":""));h=$("<span>").addClass("field_container");n.append(h);switch(d.type){case "password":e=$("<input>").attr("type","password");break;case "int":e=$("<input>").attr("type","number");"min"in d&&e.attr("min",d.min);"max"in d&&e.attr("max",d.min);"validate"in d?d.validate.push("int"):
d)for(var k in d.classes)e.addClass(d.classes[k])}else if("text"==d.type)b.append($("<span>").addClass("text_container").append($("<span>").addClass("text").append(d.text)));else if("custom"==d.type)b.append(d.custom);else if("buttons"==d.type)for(k in e=$("<span>").addClass("button_container").on("keydown",function(a){a.stopPropagation()}),"css"in d&&e.css(d.css),b.append(e),d.buttons){var m=d.buttons[k],f=$("<button>").text(m.label).data("opts",m);"css"in m&&f.css(m.css);if("classes"in m)for(var q in m.classes)f.addClass(m.classes[q]);
e.append(f);switch(m.type){case "cancel":f.addClass("cancel").click(m["function"]);break;case "save":f.addClass("save").click(function(){var a=$(this).closest(".input_container"),b=!1;a.find(".hasValidate").each(function(){if(b=$(this).data("validate")(this,!0))return!1});b||(a.find(".isSetting").each(function(){var a=$(this).getval(),b=$(this).data("pointer");if(""==a)if("default"in $(this).data("opts"))a=$(this).data("opts")["default"];else return delete b.main[b.index],!0;b.main[b.index]=a}),(a=
$(this).data("opts")["function"])&&a(this))});break;default:f.click(m["function"])}}else{m=$("<label>").addClass("UIelement");b.append(m);"css"in d&&m.css(d.css);m.append($("<span>").addClass("label").html("label"in d?d.label+":":""));f=$("<span>").addClass("field_container");m.append(f);switch(d.type){case "password":e=$("<input>").attr("type","password");break;case "int":e=$("<input>").attr("type","number");"min"in d&&e.attr("min",d.min);"max"in d&&e.attr("max",d.min);"validate"in d?d.validate.push("int"):
d.validate=["int"];break;case "span":e=$("<span>");break;case "debug":d.select=[["","Default"],[0,"0 - All debugging messages disabled"],[1,"1 - Messages about failed operations"],[2,"2 - Previous level, and error messages"],[3,"3 - Previous level, and warning messages"],[4,"4 - Previous level, and status messages for development"],[5,"5 - Previous level, and more status messages for development"],[6,"6 - Previous level, and verbose debugging messages"],[7,"7 - Previous level, and very verbose debugging messages"],
[8,"8 - Report everything in extreme detail"],[9,"9 - Report everything in insane detail"],[10,"10 - All messages enabled"]];case "select":e=$("<select>");for(l in d.select){var p=$("<option>");"string"==typeof d.select[l]?p.text(d.select[l]):p.val(d.select[l][0]).text(d.select[l][1]);e.append(p)}break;case "textarea":e=$("<textarea>").on("keydown",function(a){a.stopPropagation()});break;case "checkbox":e=$("<input>").attr("type","checkbox");break;case "hidden":e=$("<input>").attr("type","hidden");
n.hide();break;case "email":e=$("<input>").attr("type","email").attr("autocomplete","on").attr("required","");break;case "browse":e=$("<input>").attr("type","text");"filetypes"in d&&e.data("filetypes",d.filetypes);break;case "geolimited":case "hostlimited":e=$("<input>").attr("type","hidden");break;case "radioselect":e=$("<div>").addClass("radioselect");for(c in d.radioselect){var f=$("<input>").attr("type","radio").val(d.radioselect[c][0]).attr("name",d.label);("LTSonly"in d&&!mist.data.LTS||d.readonly)&&
f.prop("disabled",!0);p=$("<label>").append(f).append($("<span>").html(d.radioselect[c][1]));e.append(p);if(2<d.radioselect[c].length)for(l in f=$("<select>").change(function(){$(this).parent().find("input[type=radio]:enabled").prop("checked","true")}),p.append(f),("LTSonly"in d&&!mist.data.LTS||d.readonly)&&f.prop("disabled",!0),d.radioselect[c][2])p=$("<option>"),f.append(p),d.radioselect[c][2][l]instanceof Array?p.val(d.radioselect[c][2][l][0]).html(d.radioselect[c][2][l][1]):p.html(d.radioselect[c][2][l])}break;
[8,"8 - Report everything in extreme detail"],[9,"9 - Report everything in insane detail"],[10,"10 - All messages enabled"]];case "select":e=$("<select>");for(k in d.select){var p=$("<option>");"string"==typeof d.select[k]?p.text(d.select[k]):p.val(d.select[k][0]).text(d.select[k][1]);e.append(p)}break;case "textarea":e=$("<textarea>").on("keydown",function(a){a.stopPropagation()});break;case "checkbox":e=$("<input>").attr("type","checkbox");break;case "hidden":e=$("<input>").attr("type","hidden");
m.hide();break;case "email":e=$("<input>").attr("type","email").attr("autocomplete","on").attr("required","");break;case "browse":e=$("<input>").attr("type","text");"filetypes"in d&&e.data("filetypes",d.filetypes);break;case "geolimited":case "hostlimited":e=$("<input>").attr("type","hidden");break;case "radioselect":e=$("<div>").addClass("radioselect");for(c in d.radioselect){var l=$("<input>").attr("type","radio").val(d.radioselect[c][0]).attr("name",d.label);("LTSonly"in d&&!mist.data.LTS||d.readonly)&&
l.prop("disabled",!0);p=$("<label>").append(l).append($("<span>").html(d.radioselect[c][1]));e.append(p);if(2<d.radioselect[c].length)for(k in l=$("<select>").change(function(){$(this).parent().find("input[type=radio]:enabled").prop("checked","true")}),p.append(l),("LTSonly"in d&&!mist.data.LTS||d.readonly)&&l.prop("disabled",!0),d.radioselect[c][2])p=$("<option>"),l.append(p),d.radioselect[c][2][k]instanceof Array?p.val(d.radioselect[c][2][k][0]).html(d.radioselect[c][2][k][1]):p.html(d.radioselect[c][2][k])}break;
case "checklist":e=$("<div>").addClass("checkcontainer");$controls=$("<div>").addClass("controls");$checklist=$("<div>").addClass("checklist");e.append($controls).append($checklist);$controls.append($("<label>").text("All").prepend($("<input>").attr("type","checkbox").click(function(){$(this).is(":checked")?$(this).closest(".checkcontainer").find("input[type=checkbox]").prop("checked",!0):$(this).closest(".checkcontainer").find("input[type=checkbox]").prop("checked",!1)})));for(c in d.checklist)"string"==
typeof d.checklist[c]&&(d.checklist[c]=[d.checklist[c],d.checklist[c]]),$checklist.append($("<label>").text(d.checklist[c][1]).prepend($("<input>").attr("type","checkbox").attr("name",d.checklist[c][0])));break;case "DOMfield":e=d.DOMfield;break;default:e=$("<input>").attr("type","text")}e.addClass("field").data("opts",d);"pointer"in d&&e.attr("name",d.pointer.index);h.append(e);if("classes"in d)for(l in d.classes)e.addClass(d.classes[l]);"placeholder"in d&&e.attr("placeholder",d.placeholder);"default"in
d&&e.attr("placeholder",d["default"]);"unit"in d&&h.append($("<span>").addClass("unit").html(d.unit));"readonly"in d&&(e.attr("readonly","readonly"),e.click(function(){$(this).select()}));"qrcode"in d&&h.append($("<span>").addClass("unit").html($("<button>").text("QR").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=$("<div>").addClass("qrcode");UI.popup.show($("<span>").addClass("qr_container").append($("<p>").text(a)).append(b));
b.qrcode({text:a,size:Math.min(b.width(),b.height())})})));"clipboard"in d&&document.queryCommandSupported("copy")&&h.append($("<span>").addClass("unit").html($("<button>").text("Copy").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=document.createElement("textarea");b.value=a;document.body.appendChild(b);b.select();var c=false;try{c=document.execCommand("copy")}catch(d){}if(c){$(this).text("Copied to clipboard!");
document.body.removeChild(b);var f=$(this);setTimeout(function(){f.text("Copy")},5E3)}else{document.body.removeChild(b);alert("Failed to copy:\n"+a)}})));"rows"in d&&e.attr("rows",d.rows);"LTSonly"in d&&!mist.data.LTS&&(h.addClass("LTSonly"),e.prop("disabled",!0));switch(d.type){case "browse":f=$("<div>").addClass("grouper").append(n);b.append(f);f=$("<button>").text("Browse").on("keydown",function(a){a.stopPropagation()});h.append(f);f.click(function(){function a(b){n.text("Loading..");mist.send(function(a){e.text(a.browse.path[0]);
mist.data.LTS&&d.setval(a.browse.path[0]+"/");n.html(l.clone(true).text("..").attr("title","Folder up"));if(a.browse.subdirectories){a.browse.subdirectories.sort();for(var b in a.browse.subdirectories){var g=a.browse.subdirectories[b];n.append(l.clone(true).attr("title",e.text()+q+g).text(g))}}if(a.browse.files){a.browse.files.sort();for(b in a.browse.files){var g=a.browse.files[b],h=e.text()+q+g,g=$("<a>").text(g).addClass("file").attr("title",h);n.append(g);if(p){var v=true,r;for(r in p)if(typeof p[r]!=
"undefined"&&mist.inputMatch(p[r],h)){v=false;break}v&&g.hide()}g.click(function(){var a=$(this).attr("title");d.setval(a).removeAttr("readonly").css("opacity",1);f.show();c.remove()})}}},{browse:b})}var b=$(this).closest(".grouper"),c=$("<div>").addClass("browse_container"),d=b.find(".field").attr("readonly","readonly").css("opacity",0.5),f=$(this),h=$("<button>").text("Stop browsing").click(function(){f.show();c.remove();d.removeAttr("readonly").css("opacity",1)}),e=$("<span>").addClass("field"),
n=$("<div>").addClass("browse_contents"),l=$("<a>").addClass("folder"),p=d.data("filetypes");b.append(c);c.append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Current folder:")).append($("<span>").addClass("field_container").append(e).append(h))).append(n);var q="/";mist.data.config.version.indexOf("indows")>-1&&(q="\\");l.click(function(){var b=e.text()+q+$(this).text();a(b)});b=d.getval();h=b.split("://");h.length>1&&(b=h[0]=="file"?h[1]:"");b=b.split(q);b.pop();
b=b.join(q);f.hide();a(b)});break;case "geolimited":case "hostlimited":f={field:e};f.blackwhite=$("<select>").append($("<option>").val("-").text("Blacklist")).append($("<option>").val("+").text("Whitelist"));f.values=$("<span>").addClass("limit_value_list");switch(d.type){case "geolimited":f.prototype=$("<select>").append($("<option>").val("").text("[Select a country]"));for(c in UI.countrylist)f.prototype.append($("<option>").val(c).html(UI.countrylist[c]));break;case "hostlimited":f.prototype=$("<input>").attr("type",
"text").attr("placeholder","type a host")}f.prototype.on("change keyup",function(){$(this).closest(".field_container").data("subUI").blackwhite.trigger("change")});f.blackwhite.change(function(){var a=$(this).closest(".field_container").data("subUI"),b=[],c=false;a.values.children().each(function(){c=$(this).val();c!=""?b.push(c):$(this).remove()});a.values.append(a.prototype.clone(true));b.length>0?a.field.val($(this).val()+b.join(" ")):a.field.val("");a.field.trigger("change")});"LTSonly"in d&&
!mist.data.LTS&&(f.blackwhite.prop("disabled",!0),f.prototype.prop("disabled",!0));f.values.append(f.prototype.clone(!0));h.data("subUI",f).addClass("limit_list").append(f.blackwhite).append(f.values)}"pointer"in d&&(e.data("pointer",d.pointer).addClass("isSetting"),f=d.pointer.main[d.pointer.index],"undefined"!=f&&e.setval(f));"value"in d&&e.setval(d.value);if("datalist"in d)for(c in f="datalist_"+c+MD5(e[0].outerHTML),e.attr("list",f),f=$("<datalist>").attr("id",f),h.append(f),d.datalist)f.append($("<option>").val(d.datalist[c]));
h=$("<span>").addClass("help_container");n.append(h);"help"in d&&(h.append($("<span>").addClass("ih_balloon").html(d.help)),e.on("focus mouseover",function(){$(this).closest("label").addClass("active")}).on("blur mouseout",function(){$(this).closest("label").removeClass("active")}));if("validate"in d){n=[];for(l in d.validate){f=d.validate[l];if("function"!=typeof f)switch(f){case "required":f=function(a){return a==""?{msg:"This is a required field.",classes:["red"]}:false};break;case "int":f=function(a,
b){var c=$(b).data("opts");if(!$(b)[0].validity.valid){var d=[];"min"in c&&d.push(" greater than or equal to "+c.min);"max"in c&&d.push(" smaller than or equal to "+c.max);return{msg:"Please enter an integer"+d.join(" and")+".",classes:["red"]}}if(parseInt(Number(a))!=a)return{msg:"Please enter an integer.",classes:["red"]}};break;case "streamname":f=function(a,b){if(!isNaN(a.charAt(0)))return{msg:"The first character may not be a number.",classes:["red"]};if(a.toLowerCase()!=a)return{msg:"Uppercase letters are not allowed.",
classes:["red"]};if(a.replace(/[^\da-z_]/g,"")!=a)return{msg:"Special characters (except for underscores) are not allowed.",classes:["red"]};if("streams"in mist.data&&a in mist.data.streams&&$(b).data("pointer").main.name!=a)return{msg:"This streamname already exists.<br>If you want to edit an existing stream, please click edit on the the streams tab.",classes:["red"]}};break;default:f=function(){}}n.push(f)}e.data("validate_functions",n).data("help_container",h).data("validate",function(a,b){var c=
$(a).getval(),d=$(a).data("validate_functions"),f=$(a).data("help_container");f.find(".err_balloon").remove();for(var h in d){var e=d[h](c,a);if(e){$err=$("<span>").addClass("err_balloon").html(e.msg);for(var n in e.classes)$err.addClass(e.classes[n]);f.prepend($err);b&&$(a).focus();return true}}return false}).addClass("hasValidate").on("change keyup",function(){$(this).data("validate")($(this))});""!=e.getval()&&e.trigger("change")}"function"in d&&(e.on("change keyup",d["function"]),e.trigger("change"))}}b.on("keydown",
typeof d.checklist[c]&&(d.checklist[c]=[d.checklist[c],d.checklist[c]]),$checklist.append($("<label>").text(d.checklist[c][1]).prepend($("<input>").attr("type","checkbox").attr("name",d.checklist[c][0])));break;case "DOMfield":e=d.DOMfield;break;default:e=$("<input>").attr("type","text")}e.addClass("field").data("opts",d);"pointer"in d&&e.attr("name",d.pointer.index);f.append(e);if("classes"in d)for(k in d.classes)e.addClass(d.classes[k]);"placeholder"in d&&e.attr("placeholder",d.placeholder);"default"in
d&&e.attr("placeholder",d["default"]);"unit"in d&&f.append($("<span>").addClass("unit").html(d.unit));"readonly"in d&&(e.attr("readonly","readonly"),e.click(function(){$(this).select()}));"qrcode"in d&&f.append($("<span>").addClass("unit").html($("<button>").text("QR").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=$("<div>").addClass("qrcode");UI.popup.show($("<span>").addClass("qr_container").append($("<p>").text(a)).append(b));
b.qrcode({text:a,size:Math.min(b.width(),b.height())})})));"clipboard"in d&&document.queryCommandSupported("copy")&&f.append($("<span>").addClass("unit").html($("<button>").text("Copy").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=document.createElement("textarea");b.value=a;document.body.appendChild(b);b.select();var c=false;try{c=document.execCommand("copy")}catch(d){}if(c){$(this).text("Copied to clipboard!");
document.body.removeChild(b);var f=$(this);setTimeout(function(){f.text("Copy")},5E3)}else{document.body.removeChild(b);alert("Failed to copy:\n"+a)}})));"rows"in d&&e.attr("rows",d.rows);"LTSonly"in d&&!mist.data.LTS&&(f.addClass("LTSonly"),e.prop("disabled",!0));switch(d.type){case "browse":l=$("<div>").addClass("grouper").append(m);b.append(l);l=$("<button>").text("Browse").on("keydown",function(a){a.stopPropagation()});f.append(l);l.click(function(){function a(b){k.text("Loading..");mist.send(function(a){m.text(a.browse.path[0]);
mist.data.LTS&&d.setval(a.browse.path[0]+"/");k.html(l.clone(true).text("..").attr("title","Folder up"));if(a.browse.subdirectories){a.browse.subdirectories.sort();for(var b in a.browse.subdirectories){var e=a.browse.subdirectories[b];k.append(l.clone(true).attr("title",m.text()+p+e).text(e))}}if(a.browse.files){a.browse.files.sort();for(b in a.browse.files){var e=a.browse.files[b],h=m.text()+p+e,e=$("<a>").text(e).addClass("file").attr("title",h);k.append(e);if(n){var v=true,q;for(q in n)if(typeof n[q]!=
"undefined"&&mist.inputMatch(n[q],h)){v=false;break}v&&e.hide()}e.click(function(){var a=$(this).attr("title");d.setval(a).removeAttr("readonly").css("opacity",1);f.show();c.remove()})}}},{browse:b})}var b=$(this).closest(".grouper"),c=$("<div>").addClass("browse_container"),d=b.find(".field").attr("readonly","readonly").css("opacity",0.5),f=$(this),e=$("<button>").text("Stop browsing").click(function(){f.show();c.remove();d.removeAttr("readonly").css("opacity",1)}),m=$("<span>").addClass("field"),
k=$("<div>").addClass("browse_contents"),l=$("<a>").addClass("folder"),n=d.data("filetypes");b.append(c);c.append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Current folder:")).append($("<span>").addClass("field_container").append(m).append(e))).append(k);var p="/";mist.data.config.version.indexOf("indows")>-1&&(p="\\");l.click(function(){var b=m.text()+p+$(this).text();a(b)});b=d.getval();e=b.split("://");e.length>1&&(b=e[0]=="file"?e[1]:"");b=b.split(p);b.pop();
b=b.join(p);f.hide();a(b)});break;case "geolimited":case "hostlimited":l={field:e};l.blackwhite=$("<select>").append($("<option>").val("-").text("Blacklist")).append($("<option>").val("+").text("Whitelist"));l.values=$("<span>").addClass("limit_value_list");switch(d.type){case "geolimited":l.prototype=$("<select>").append($("<option>").val("").text("[Select a country]"));for(c in UI.countrylist)l.prototype.append($("<option>").val(c).html(UI.countrylist[c]));break;case "hostlimited":l.prototype=$("<input>").attr("type",
"text").attr("placeholder","type a host")}l.prototype.on("change keyup",function(){$(this).closest(".field_container").data("subUI").blackwhite.trigger("change")});l.blackwhite.change(function(){var a=$(this).closest(".field_container").data("subUI"),b=[],c=false;a.values.children().each(function(){c=$(this).val();c!=""?b.push(c):$(this).remove()});a.values.append(a.prototype.clone(true));b.length>0?a.field.val($(this).val()+b.join(" ")):a.field.val("");a.field.trigger("change")});"LTSonly"in d&&
!mist.data.LTS&&(l.blackwhite.prop("disabled",!0),l.prototype.prop("disabled",!0));l.values.append(l.prototype.clone(!0));f.data("subUI",l).addClass("limit_list").append(l.blackwhite).append(l.values)}"pointer"in d&&(e.data("pointer",d.pointer).addClass("isSetting"),l=d.pointer.main[d.pointer.index],"undefined"!=l&&e.setval(l));"value"in d&&e.setval(d.value);if("datalist"in d)for(c in l="datalist_"+c+MD5(e[0].outerHTML),e.attr("list",l),l=$("<datalist>").attr("id",l),f.append(l),d.datalist)l.append($("<option>").val(d.datalist[c]));
f=$("<span>").addClass("help_container");m.append(f);"help"in d&&(f.append($("<span>").addClass("ih_balloon").html(d.help)),e.on("focus mouseover",function(){$(this).closest("label").addClass("active")}).on("blur mouseout",function(){$(this).closest("label").removeClass("active")}));if("validate"in d){m=[];for(k in d.validate){l=d.validate[k];if("function"!=typeof l)switch(l){case "required":l=function(a){return a==""?{msg:"This is a required field.",classes:["red"]}:false};break;case "int":l=function(a,
b){var c=$(b).data("opts");if(!$(b)[0].validity.valid){var d=[];"min"in c&&d.push(" greater than or equal to "+c.min);"max"in c&&d.push(" smaller than or equal to "+c.max);return{msg:"Please enter an integer"+d.join(" and")+".",classes:["red"]}}if(parseInt(Number(a))!=a)return{msg:"Please enter an integer.",classes:["red"]}};break;case "streamname":l=function(a,b){if(!isNaN(a.charAt(0)))return{msg:"The first character may not be a number.",classes:["red"]};if(a.toLowerCase()!=a)return{msg:"Uppercase letters are not allowed.",
classes:["red"]};if(a.replace(/[^\da-z_]/g,"")!=a)return{msg:"Special characters (except for underscores) are not allowed.",classes:["red"]};if("streams"in mist.data&&a in mist.data.streams&&$(b).data("pointer").main.name!=a)return{msg:"This streamname already exists.<br>If you want to edit an existing stream, please click edit on the the streams tab.",classes:["red"]}};break;default:l=function(){}}m.push(l)}e.data("validate_functions",m).data("help_container",f).data("validate",function(a,b){var c=
$(a).getval(),d=$(a).data("validate_functions"),f=$(a).data("help_container");f.find(".err_balloon").remove();for(var e in d){var m=d[e](c,a);if(m){$err=$("<span>").addClass("err_balloon").html(m.msg);for(var k in m.classes)$err.addClass(m.classes[k]);f.prepend($err);b&&$(a).focus();return true}}return false}).addClass("hasValidate").on("change keyup",function(){$(this).data("validate")($(this))});""!=e.getval()&&e.trigger("change")}"function"in d&&(e.on("change keyup",d["function"]),e.trigger("change"))}}b.on("keydown",
function(a){switch(a.which){case 13:$(this).find("button.save").first().trigger("click");break;case 27:$(this).find("button.cancel").first().trigger("click")}});return b},buildVheaderTable:function(a){var b=$("<table>").css("margin","0.2em"),c=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",a.labels.length+1).append($("<span>").text(a.vheader))),d=[];c.append($("<td>"));for(var e in a.labels)d.push($("<tr>").append($("<td>").html(""==a.labels[e]?"&nbsp;":a.labels[e]+
":")));for(var l in a.content)for(e in c.append($("<td>").html(a.content[l].header)),a.content[l].body)d[e].append($("<td>").html(a.content[l].body[e]));b.append($("<tbody>").append(c).append(d));return b},plot:{addGraph:function(a,b){var c={id:a.id,xaxis:a.xaxis,datasets:[],elements:{cont:$("<div>").addClass("graph"),plot:$("<div>").addClass("plot"),legend:$("<div>").addClass("legend").attr("draggable","true")}};UI.draggable(c.elements.legend);c.elements.cont.append(c.elements.plot).append(c.elements.legend);
":")));for(var k in a.content)for(e in c.append($("<td>").html(a.content[k].header)),a.content[k].body)d[e].append($("<td>").html(a.content[k].body[e]));b.append($("<tbody>").append(c).append(d));return b},plot:{addGraph:function(a,b){var c={id:a.id,xaxis:a.xaxis,datasets:[],elements:{cont:$("<div>").addClass("graph"),plot:$("<div>").addClass("plot"),legend:$("<div>").addClass("legend").attr("draggable","true")}};UI.draggable(c.elements.legend);c.elements.cont.append(c.elements.plot).append(c.elements.legend);
b.append(c.elements.cont);return c},go:function(a){if(!(1>Object.keys(a).length)){var b={totals:[],clients:[]},c;for(c in a)for(var d in a[c].datasets){var e=a[c].datasets[d];switch(e.datatype){case "clients":case "upbps":case "downbps":switch(e.origin[0]){case "total":b.totals.push({fields:[e.datatype],end:-15});break;case "stream":b.totals.push({fields:[e.datatype],streams:[e.origin[1]],end:-15});break;case "protocol":b.totals.push({fields:[e.datatype],protocols:[e.origin[1]],end:-15})}break;case "cpuload":case "memload":b.capabilities=
{}}}0==b.totals.length&&delete b.totals;0==b.clients.length&&delete b.clients;mist.send(function(){for(var b in a){var c=a[b];if(1>c.datasets.length){c.elements.plot.html("");c.elements.legend.html("");break}switch(c.xaxis){case "time":var d=[];c.yaxes={};var e=[],p;for(p in c.datasets){var f=c.datasets[p];f.display&&(f.getdata(),f.yaxistype in c.yaxes||(d.push(UI.plot.yaxes[f.yaxistype]),c.yaxes[f.yaxistype]=d.length),f.yaxis=c.yaxes[f.yaxistype],e.push(f))}d[0]&&(d[0].color=0);c.plot=$.plot(c.elements.plot,
{}}}0==b.totals.length&&delete b.totals;0==b.clients.length&&delete b.clients;mist.send(function(){for(var b in a){var c=a[b];if(1>c.datasets.length){c.elements.plot.html("");c.elements.legend.html("");break}switch(c.xaxis){case "time":var d=[];c.yaxes={};var e=[],p;for(p in c.datasets){var l=c.datasets[p];l.display&&(l.getdata(),l.yaxistype in c.yaxes||(d.push(UI.plot.yaxes[l.yaxistype]),c.yaxes[l.yaxistype]=d.length),l.yaxis=c.yaxes[l.yaxistype],e.push(l))}d[0]&&(d[0].color=0);c.plot=$.plot(c.elements.plot,
e,{legend:{show:!1},xaxis:UI.plot.xaxes[c.xaxis],yaxes:d,grid:{hoverable:!0,borderWidth:{top:0,right:0,bottom:1,left:1},color:"black",backgroundColor:{colors:["rgba(0,0,0,0)","rgba(0,0,0,0.025)"]}},crosshair:{mode:"x"}});d=$("<table>").addClass("legend-list").addClass("nolay").html($("<tr>").html($("<td>").html($("<h3>").text(c.id))).append($("<td>").css("padding-right","2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").data("opts",c).text("X").addClass("close").click(function(){var b=
$(this).data("opts");if(confirm("Are you sure you want to remove "+b.id+"?")){b.elements.cont.remove();var c=$(".graph_ids option:contains("+b.id+")"),d=c.parent();c.remove();UI.plot.del(b.id);delete a[b.id];d.trigger("change");UI.plot.go(a)}}))));c.elements.legend.html(d);var v=function(a){var b=c.elements.legend.find(".value"),d=1;if(typeof a=="undefined")b.eq(0).html("Latest:");else{var f=c.plot.getXAxes()[0],a=Math.min(f.max,a),a=Math.max(f.min,a);b.eq(0).html(UI.format.time(a/1E3))}for(var e in c.datasets){var g=
"&nbsp;";if(c.datasets[e].display){var f=UI.plot.yaxes[c.datasets[e].yaxistype].tickFormatter,h=c.datasets[e].data;if(a)for(var l in h){if(h[l][0]==a){g=f(h[l][1]);break}if(h[l][0]>a){if(l!=0){g=h[l];h=h[l-1];g=f(g[1]+(a-g[0])*(h[1]-g[1])/(h[0]-g[0]))}break}}else g=f(c.datasets[e].data[c.datasets[e].data.length-1][1])}b.eq(d).html(g);d++}};c.plot.getOptions();for(p in c.datasets)e=$("<input>").attr("type","checkbox").data("index",p).data("graph",c).click(function(){var a=$(this).data("graph");$(this).is(":checked")?
$(this).data("opts");if(confirm("Are you sure you want to remove "+b.id+"?")){b.elements.cont.remove();var c=$(".graph_ids option:contains("+b.id+")"),d=c.parent();c.remove();UI.plot.del(b.id);delete a[b.id];d.trigger("change");UI.plot.go(a)}}))));c.elements.legend.html(d);var v=function(a){var b=c.elements.legend.find(".value"),d=1;if(typeof a=="undefined")b.eq(0).html("Latest:");else{var e=c.plot.getXAxes()[0],a=Math.min(e.max,a),a=Math.max(e.min,a);b.eq(0).html(UI.format.time(a/1E3))}for(var f in c.datasets){var h=
"&nbsp;";if(c.datasets[f].display){var e=UI.plot.yaxes[c.datasets[f].yaxistype].tickFormatter,k=c.datasets[f].data;if(a)for(var l in k){if(k[l][0]==a){h=e(k[l][1]);break}if(k[l][0]>a){if(l!=0){h=k[l];k=k[l-1];h=e(h[1]+(a-h[0])*(k[1]-h[1])/(k[0]-h[0]))}break}}else h=e(c.datasets[f].data[c.datasets[f].data.length-1][1])}b.eq(d).html(h);d++}};c.plot.getOptions();for(p in c.datasets)e=$("<input>").attr("type","checkbox").data("index",p).data("graph",c).click(function(){var a=$(this).data("graph");$(this).is(":checked")?
a.datasets[$(this).data("index")].display=true:a.datasets[$(this).data("index")].display=false;var b={};b[a.id]=a;UI.plot.go(b)}),c.datasets[p].display&&e.attr("checked","checked"),d.append($("<tr>").html($("<td>").html($("<label>").html(e).append($("<div>").addClass("series-color").css("background-color",c.datasets[p].color)).append(c.datasets[p].label))).append($("<td>").css("padding-right","2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").text("X").addClass("close").data("index",
p).data("graph",c).click(function(){var b=$(this).data("index"),c=$(this).data("graph");if(confirm("Are you sure you want to remove "+c.datasets[b].label+" from "+c.id+"?")){c.datasets.splice(b,1);if(c.datasets.length==0){c.elements.cont.remove();var b=$(".graph_ids option:contains("+c.id+")"),d=b.parent();b.remove();d.trigger("change");UI.plot.del(c.id);delete a[c.id];UI.plot.go(a)}else{UI.plot.save(c);b={};b[c.id]=c;UI.plot.go(b)}}}))));v();var g=!1;c.elements.plot.on("plothover",function(a,b,c){if(b.x!=
g){v(b.x);g=b.x}if(c){a=$("<span>").append($("<h3>").text(c.series.label).prepend($("<div>").addClass("series-color").css("background-color",c.series.color))).append($("<table>").addClass("nolay").html($("<tr>").html($("<td>").text("Time:")).append($("<td>").html(UI.format.dateTime(c.datapoint[0]/1E3,"long")))).append($("<tr>").html($("<td>").text("Value:")).append($("<td>").html(c.series.yaxis.tickFormatter(c.datapoint[1],c.series.yaxis)))));UI.tooltip.show(b,a.children())}else UI.tooltip.hide()}).on("mouseout",
p).data("graph",c).click(function(){var b=$(this).data("index"),c=$(this).data("graph");if(confirm("Are you sure you want to remove "+c.datasets[b].label+" from "+c.id+"?")){c.datasets.splice(b,1);if(c.datasets.length==0){c.elements.cont.remove();var b=$(".graph_ids option:contains("+c.id+")"),d=b.parent();b.remove();d.trigger("change");UI.plot.del(c.id);delete a[c.id];UI.plot.go(a)}else{UI.plot.save(c);b={};b[c.id]=c;UI.plot.go(b)}}}))));v();var h=!1;c.elements.plot.on("plothover",function(a,b,c){if(b.x!=
h){v(b.x);h=b.x}if(c){a=$("<span>").append($("<h3>").text(c.series.label).prepend($("<div>").addClass("series-color").css("background-color",c.series.color))).append($("<table>").addClass("nolay").html($("<tr>").html($("<td>").text("Time:")).append($("<td>").html(UI.format.dateTime(c.datapoint[0]/1E3,"long")))).append($("<tr>").html($("<td>").text("Value:")).append($("<td>").html(c.series.yaxis.tickFormatter(c.datapoint[1],c.series.yaxis)))));UI.tooltip.show(b,a.children())}else UI.tooltip.hide()}).on("mouseout",
function(){v()})}}},b)}},save:function(a){var b={id:a.id,xaxis:a.xaxis,datasets:[]},c;for(c in a.datasets)b.datasets.push({origin:a.datasets[c].origin,datatype:a.datasets[c].datatype});a=mist.stored.get().graphs||{};a[b.id]=b;mist.stored.set("graphs",a)},del:function(a){var b=mist.stored.get().graphs||{};delete b[a];mist.stored.set("graphs",b)},datatype:{getOptions:function(a){var b=$.extend(!0,{},UI.plot.datatype.templates.general),c=$.extend(!0,{},UI.plot.datatype.templates[a.datatype]),a=$.extend(!0,
c,a),a=$.extend(!0,b,a);switch(a.origin[0]){case "total":switch(a.datatype){case "cpuload":case "memload":break;default:a.label+=" (total)"}break;case "stream":case "protocol":a.label+=" ("+a.origin[1]+")"}var b=[],d;for(d in a.basecolor)c=a.basecolor[d],c+=50*(0.5-Math.random()),c=Math.round(c),c=Math.min(255,Math.max(0,c)),b.push(c);a.color="rgb("+b.join(",")+")";return a},templates:{general:{display:!0,datatype:"general",label:"",yaxistype:"amount",data:[],lines:{show:!0},points:{show:!1},getdata:function(){var a=
mist.data.totals["stream"==this.origin[0]?this.origin[1]:"all_streams"]["protocol"==this.origin[0]?this.origin[1]:"all_protocols"][this.datatype];return this.data=a}},cpuload:{label:"CPU use",yaxistype:"percentage",basecolor:[237,194,64],cores:1,getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time-600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,mist.data.capabilities.cpu_use/10]);return this.data}},memload:{label:"Memory load",
yaxistype:"percentage",basecolor:[175,216,248],getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time-600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,mist.data.capabilities.load.memory]);return this.data}},clients:{label:"Connections",basecolor:[203,75,75]},upbps:{label:"Bandwidth up",yaxistype:"bytespersec",basecolor:[77,167,77]},downbps:{label:"Bandwidth down",yaxistype:"bytespersec",basecolor:[148,64,237]}}},yaxes:{percentage:{name:"percentage",
color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.addUnit(UI.format.number(a),"%")},tickLength:0,min:0,max:100},amount:{name:"amount",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.number(a)},tickLength:0,min:0},bytespersec:{name:"bytespersec",color:"black",tickColor:0,tickDecimals:1,tickFormatter:function(a){return UI.format.bytes(a,!0)},tickLength:0,ticks:function(a){var b=0.3*Math.sqrt($(".graph").first().height()),b=(a.max-
a.min)/b,c=Math.floor(Math.log(Math.abs(b))/Math.log(1024)),d=b/Math.pow(1024,c),e=-Math.floor(Math.log(d)/Math.LN10),l=a.tickDecimals;null!=l&&e>l&&(e=l);var n=Math.pow(10,-e),d=d/n,h;if(1.5>d)h=1;else if(3>d){if(h=2,2.25<d&&(null==l||e+1<=l))h=2.5,++e}else h=7.5>d?5:10;h=h*n*Math.pow(1024,c);null!=a.minTickSize&&h<a.minTickSize&&(h=a.minTickSize);a.delta=b;a.tickDecimals=Math.max(0,null!=l?l:e);a.tickSize=h;b=[];c=a.tickSize*Math.floor(a.min/a.tickSize);e=0;l=Number.NaN;do n=l,l=c+e*a.tickSize,
b.push(l),++e;while(l<a.max&&l!=n);return b},min:0}},xaxes:{time:{name:"time",mode:"time",timezone:"browser",ticks:5}}},draggable:function(a){a.attr("draggable",!0);a.on("dragstart",function(a){$(this).css("opacity",0.4).data("dragstart",{click:{x:a.originalEvent.pageX,y:a.originalEvent.pageY},ele:{x:this.offsetLeft,y:this.offsetTop}})}).on("dragend",function(a){var c=$(this).data("dragstart"),d=c.ele.x-c.click.x+a.originalEvent.pageX,a=c.ele.y-c.click.y+a.originalEvent.pageY;$(this).css({opacity:1,
a.min)/b,c=Math.floor(Math.log(Math.abs(b))/Math.log(1024)),d=b/Math.pow(1024,c),e=-Math.floor(Math.log(d)/Math.LN10),k=a.tickDecimals;null!=k&&e>k&&(e=k);var m=Math.pow(10,-e),d=d/m,f;if(1.5>d)f=1;else if(3>d){if(f=2,2.25<d&&(null==k||e+1<=k))f=2.5,++e}else f=7.5>d?5:10;f=f*m*Math.pow(1024,c);null!=a.minTickSize&&f<a.minTickSize&&(f=a.minTickSize);a.delta=b;a.tickDecimals=Math.max(0,null!=k?k:e);a.tickSize=f;b=[];c=a.tickSize*Math.floor(a.min/a.tickSize);e=0;k=Number.NaN;do m=k,k=c+e*a.tickSize,
b.push(k),++e;while(k<a.max&&k!=m);return b},min:0}},xaxes:{time:{name:"time",mode:"time",timezone:"browser",ticks:5}}},draggable:function(a){a.attr("draggable",!0);a.on("dragstart",function(a){$(this).css("opacity",0.4).data("dragstart",{click:{x:a.originalEvent.pageX,y:a.originalEvent.pageY},ele:{x:this.offsetLeft,y:this.offsetTop}})}).on("dragend",function(a){var c=$(this).data("dragstart"),d=c.ele.x-c.click.x+a.originalEvent.pageX,a=c.ele.y-c.click.y+a.originalEvent.pageY;$(this).css({opacity:1,
top:a,left:d,right:"auto",bottom:"auto"})});a.parent().on("dragleave",function(){})},format:{time:function(a,b){var c=new Date(1E3*a),d=[];d.push(("0"+c.getHours()).slice(-2));d.push(("0"+c.getMinutes()).slice(-2));"short"!=b&&d.push(("0"+c.getSeconds()).slice(-2));return d.join(":")},date:function(a,b){var c=new Date(1E3*a),d="Sun Mon Tue Wed Thu Fri Sat".split(" "),e=[];"long"==b&&e.push(d[c.getDay()]);e.push(("0"+c.getDate()).slice(-2));e.push("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")[c.getMonth()]);
"short"!=b&&e.push(c.getFullYear());return e.join(" ")},dateTime:function(a,b){return UI.format.date(a,b)+", "+UI.format.time(a,b)},duration:function(a){var b=[0.001,1E3,60,60,24,7,1E9],c="ms sec min hr day week".split(" "),d={},e;for(e in c){var a=a/b[e],l=Math.round(a%b[Number(e)+1]);d[c[e]]=l;a-=l}var n;for(e=c.length-1;0<=e;e--)if(0<d[c[e]]){n=c[e];break}b=$("<span>");switch(n){case "week":b.append(UI.format.addUnit(d.week,"wks, ")).append(UI.format.addUnit(d.day,"days"));break;case "day":b.append(UI.format.addUnit(d.day,
"short"!=b&&e.push(c.getFullYear());return e.join(" ")},dateTime:function(a,b){return UI.format.date(a,b)+", "+UI.format.time(a,b)},duration:function(a){var b=[0.001,1E3,60,60,24,7,1E9],c="ms sec min hr day week".split(" "),d={},e;for(e in c){var a=a/b[e],k=Math.round(a%b[Number(e)+1]);d[c[e]]=k;a-=k}var m;for(e=c.length-1;0<=e;e--)if(0<d[c[e]]){m=c[e];break}b=$("<span>");switch(m){case "week":b.append(UI.format.addUnit(d.week,"wks, ")).append(UI.format.addUnit(d.day,"days"));break;case "day":b.append(UI.format.addUnit(d.day,
"days, ")).append(UI.format.addUnit(d.hr,"hrs"));break;default:b.append([("0"+d.hr).slice(-2),("0"+d.min).slice(-2),("0"+d.sec).slice(-2)+(d.ms?"."+d.ms:"")].join(":"))}return b[0].innerHTML},number:function(a){if(isNaN(Number(a))||0==a)return a;var b=Math.pow(10,3-Math.floor(Math.log(a)/Math.LN10)-1),a=Math.round(a*b)/b;if(1E4<a){number=a.toString().split(".");for(a=/(\d+)(\d{3})/;a.test(number[0]);)number[0]=number[0].replace(a,"$1 $2");a=number.join(".")}return a},status:function(a){var b=$("<span>");
if("undefined"==typeof a.online)return b.text("Unknown, checking.."),"undefined"!=typeof a.error&&b.text(a.error),b;switch(a.online){case -1:b.text("Enabling");break;case 0:b.text("Unavailable").addClass("red");break;case 1:b.text("Active").addClass("green");break;case 2:b.text("Standby").addClass("orange");break;default:b.text(a.online)}"error"in a&&b.text(a.error);return b},capital:function(a){return a.charAt(0).toUpperCase()+a.substring(1)},addUnit:function(a,b){var c=$("<span>").html(a);c.append($("<span>").addClass("unit").html(b));
return c[0].innerHTML},bytes:function(a,b){var c="bytes KiB MiB GiB TiB PiB".split(" ");if(0==a)unit=c[0];else{var d=Math.floor(Math.log(Math.abs(a))/Math.log(1024));0>d?unit=c[0]:(a/=Math.pow(1024,d),unit=c[d])}return UI.format.addUnit(UI.format.number(a),unit+(b?"/s":""))}},navto:function(a,b){var c=location.hash,d=c.split("@");d[0]=[mist.user.name,mist.user.host].join("&");d[1]=[a,b].join("&");"undefined"!=typeof screenlog&&screenlog.navto(d[1]);location.hash=d.join("@");location.hash==c&&$(window).trigger("hashchange")},
showTab:function(a,b){var c=UI.elements.main;if(mist.user.loggedin&&!("ui_settings"in mist.data))c.html("Loading.."),mist.send(function(){UI.showTab(a,b)},{ui_settings:!0});else{var d=UI.elements.menu.removeClass("hide").find('.plain:contains("'+a+'")').closest(".button");0<d.length&&(UI.elements.menu.find(".button.active").removeClass("active"),d.addClass("active"));UI.interval.clear();c.html($("<h2>").text(a));switch(a){case "Login":if(mist.user.loggedin){UI.navto("Overview");break}UI.elements.menu.addClass("hide");
showTab:function(a,b){var c=UI.elements.main;if(mist.user.loggedin&&!("ui_settings"in mist.data))c.html("Loading.."),mist.send(function(){UI.showTab(a,b)},{ui_settings:!0});else{var d=UI.elements.menu.removeClass("hide").find('.plain:contains("'+a+'")').closest(".button");0<d.length&&(UI.elements.menu.find(".button.active").removeClass("active"),d.addClass("active"));UI.interval.clear();c.html($("<h2>").text(a));switch(a){case "Login":if(mist.user.loggedin){UI.navto("Overview");return}UI.elements.menu.addClass("hide");
UI.elements.connection.status.text("Disconnected").removeClass("green").addClass("red");c.append(UI.buildUI([{type:"help",help:"Please provide your account details.<br>You were asked to set these when MistController was started for the first time. If you did not yet set any account details, log in with your desired credentials to create a new account."},{label:"Host",help:"Url location of the MistServer API. Generally located at http://MistServerIP:4242/api","default":"http://localhost:4242/api",
pointer:{main:mist.user,index:"host"}},{label:"Username",help:"Please enter your username here.",validate:["required"],pointer:{main:mist.user,index:"name"}},{label:"Password",type:"password",help:"Please enter your password here.",validate:["required"],pointer:{main:mist.user,index:"rawpassword"}},{type:"buttons",buttons:[{label:"Login",type:"save","function":function(){mist.user.password=MD5(mist.user.rawpassword);delete mist.user.rawpassword;mist.send(function(){UI.navto("Overview")})}}]}]));break;
case "Create a new account":UI.elements.menu.addClass("hide");c.append($("<p>").text("No account has been created yet in the MistServer at ").append($("<i>").text(mist.user.host)).append("."));c.append(UI.buildUI([{type:"buttons",buttons:[{label:"Select other host",type:"cancel",css:{"float":"left"},"function":function(){UI.navto("Login")}}]},{type:"custom",custom:$("<br>")},{label:"Desired username",type:"str",validate:["required"],help:"Enter your desired username. In the future, you will need this to access the Management Interface.",
pointer:{main:mist.user,index:"name"}},{label:"Desired password",type:"password",validate:["required",function(a,b){$(".match_password").not($(b)).trigger("change");return false}],help:"Enter your desired password. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"password"},classes:["match_password"]},{label:"Repeat password",type:"password",validate:["required",function(a,b){return a!=$(".match_password").not($(b)).val()?{msg:'The fields "Desired password" and "Repeat password" do not match.',
classes:["red"]}:false}],help:"Repeat your desired password.",classes:["match_password"]},{type:"buttons",buttons:[{type:"save",label:"Create new account","function":function(){mist.send(function(){UI.navto("Account created")},{authorize:{new_username:mist.user.name,new_password:mist.user.password}})}}]}]));break;case "Account created":UI.elements.menu.addClass("hide");c.append($("<p>").text("Your account has been created succesfully.")).append(UI.buildUI([{type:"text",text:"Would you like to enable all (currently) available protocols with their default settings?"},
{type:"buttons",buttons:[{label:"Enable protocols",type:"save","function":function(){if(mist.data.config.protocols)c.append("Unable to enable all protocols as protocol settings already exist.<br>");else{c.append("Retrieving available protocols..<br>");mist.send(function(a){var b=[],d;for(d in a.capabilities.connectors)if(a.capabilities.connectors[d].required)c.append('Could not enable protocol "'+d+'" because it has required settings.<br>');else{b.push({connector:d});c.append('Enabled protocol "'+
d+'".<br>')}c.append("Saving protocol settings..<br>");mist.send(function(){c.append("Protocols enabled. Redirecting..");setTimeout(function(){UI.navto("Overview")},5E3)},{config:{protocols:b}})},{capabilities:true})}}},{label:"Skip",type:"cancel","function":function(){UI.navto("Overview")}}]}]));break;case "Overview":var e=$("<span>").text("Loading.."),l=$("<span>"),n=$("<span>"),h=$("<span>");c.append(UI.buildUI([{type:"help",help:"You can find most basic information about your MistServer here.<br>You can also set the debug level and force a save to the config.json file that MistServer uses to save your settings. "},
{type:"span",label:"Version",pointer:{main:mist.data.config,index:"version"}},{type:"span",label:"Version check",value:e,LTSonly:!0},{type:"span",label:"Server time",value:h},{type:"span",label:"Current streams",value:l},{type:"span",label:"Current connections",value:n},$("<br>"),{type:"str",label:"Human readable name",pointer:{main:mist.data.config,index:"name"},help:"You can name your MistServer here for personal use. You'll still need to set host name within your network yourself."},{type:"debug",
label:"Debug level",pointer:{main:mist.data.config,index:"debug"},help:"You can set the amount of debug information MistServer saves in the log. A full reboot of MistServer is required before some components of MistServer can post debug information."},{type:"checkbox",label:"Force configurations save",pointer:{main:mist.data,index:"save"},help:"Tick the box in order to force an immediate save to the config.json MistServer uses to save your settings. Saving will otherwise happen upon closing MistServer. Don't forget to press save after ticking the box."},
{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={config:mist.data.config};if(mist.data.save)a.save=mist.data.save;mist.send(function(){UI.navto("Overview")},a)}}]}]));if(mist.data.LTS){var q=function(){var a=mist.stored.get().update||{};"uptodate"in a?a.error?e.addClass("red").text(a.error):a.uptodate?e.text("Your version is up to date.").addClass("green"):e.addClass("red").text("Version outdated!").append($("<button>").text("Update").css({"font-size":"1em","margin-left":"1em"}).click(function(){if(confirm("Are you sure you want to execute a rolling update?")){e.addClass("orange").removeClass("red").text("Rolling update command sent..");
mist.stored.del("update");mist.send(function(){UI.navto("Overview")},{autoupdate:true})}})):e.text("Unknown")};if(!mist.stored.get().update||36E5<(new Date).getTime()-mist.stored.get().update.lastchecked){var p=mist.stored.get().update||{};p.lastchecked=(new Date).getTime();mist.send(function(a){mist.stored.set("update",$.extend(true,p,a.update));q()},{checkupdate:!0})}else q()}else e.text("");var f=function(){mist.send(function(){v()},{totals:{fields:["clients"],start:-10},active_streams:true})},
v=function(){l.text(("active_streams"in mist.data?mist.data.active_streams?mist.data.active_streams.length:0:"?")+" active, "+(mist.data.streams?Object.keys(mist.data.streams).length:0)+" configured");if("totals"in mist.data&&"all_streams"in mist.data.totals)var a=mist.data.totals.all_streams.all_protocols.clients,a=a.length?UI.format.number(a[a.length-1][1]):0;else a="Loading..";n.text(a);h.text(UI.format.dateTime(mist.data.config.time,"long"))};f();v();UI.interval.set(f,3E4);break;case "Protocols":if("undefined"==
typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},{capabilities:!0});c.append("Loading..");break}var g=$("<tbody>");c.append(UI.buildUI([{type:"help",help:"You can find an overview of all the protocols and their relevant information here. You can add, edit or delete protocols."}])).append($("<button>").text("New protocol").click(function(){UI.navto("Edit Protocol")})).append($("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Protocol")).append($("<th>").text("Status")).append($("<th>").text("Settings")).append($("<th>")))).append(g));
var i=function(){function a(b){var c=mist.data.capabilities.connectors[b.connector];if(!c)return"";var d=[],f=["required","optional"],g;for(g in f)for(var e in c[f[g]])b[e]&&b[e]!=""?d.push(e+": "+b[e]):c[f[g]][e]["default"]&&d.push(e+": "+c[f[g]][e]["default"]);return $("<span>").addClass("description").text(d.join(", "))}g.html("");for(var b in mist.data.config.protocols){var c=mist.data.config.protocols[b];g.append($("<tr>").data("index",b).append($("<td>").text(c.connector)).append($("<td>").html(UI.format.status(c))).append($("<td>").html(a(c))).append($("<td>").css("text-align",
"right").html($("<button>").text("Edit").click(function(){UI.navto("Edit Protocol",$(this).closest("tr").data("index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").data("index");if(confirm('Are you sure you want to delete the protocol "'+mist.data.config.protocols[a].connector+'"?')){mist.data.config.protocols.splice(a,1);mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}}))))}};i();UI.interval.set(function(){mist.send(function(){i()})},
3E4);break;case "Edit Protocol":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");break}var j=!1;""!=b&&0<=b&&(j=!0);var k={};for(f in mist.data.config.protocols)k[mist.data.config.protocols[f].connector]=1;var aa=function(a){var c=mist.data.capabilities.connectors[a],d=mist.convertBuildOptions(c,m);d.push({type:"hidden",pointer:{main:m,index:"connector"},value:a});d.push({type:"buttons",buttons:[{type:"save",label:"Save","function":function(){if(j)mist.data.config.protocols[b]=
m;else{if(!mist.data.config.protocols)mist.data.config.protocols=[];mist.data.config.protocols.push(m)}mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}},{type:"cancel",label:"Cancel","function":function(){UI.navto("Protocols")}}]});if("deps"in c&&c.deps!=""){$t=$("<span>").text("Dependencies:");$ul=$("<ul>");$t.append($ul);if(typeof c.deps=="string")c.deps=c.deps.split(", ");for(var f in c.deps){a=$("<li>").text(c.deps[f]+" ");$ul.append(a);typeof k[c.deps[f]]!="undefined"||
typeof k[c.deps[f]+".exe"]!="undefined"?a.append($("<span>").addClass("green").text("(Configured)")):a.append($("<span>").addClass("red").text("(Not yet configured)"))}d.unshift({type:"text",text:$t[0].innerHTML})}return UI.buildUI(d)},k={};for(f in mist.data.config.protocols)k[mist.data.config.protocols[f].connector]=1;if(j)m=d=mist.data.config.protocols[b],c.find("h2").append(' "'+d.connector+'"'),c.append(aa(d.connector));else{c.html($("<h2>").text("New Protocol"));var m={},t=[];for(f in mist.data.capabilities.connectors)t.push([f,
f]);var F=$("<span>");c.append(UI.buildUI([{label:"Protocol",type:"select",select:t,"function":function(){F.html(aa($(this).getval()))}}])).append(F)}break;case "Streams":if(!("capabilities"in mist.data)){c.html("Loading..");mist.send(function(){UI.navto(a)},{capabilities:!0});break}var f=$("<button>"),C=$("<span>").text("Loading..");c.append(UI.buildUI([{type:"help",help:"Here you can create, edit or delete new and existing streams. Go to stream preview or embed a video player on your website."},
$("<div>").css({width:"45.25em",display:"flex","justify-content":"flex-end"}).append(f).append($("<button>").text("Create a new stream").click(function(){UI.navto("Edit")}))])).append(C);if(""==b){var s=mist.stored.get();"viewmode"in s&&(b=s.viewmode)}f.text("Switch to "+("thumbnails"==b?"list":"thumbnail")+" view").click(function(){mist.stored.set("viewmode",b=="thumbnails"?"list":"thumbnails");UI.navto("Streams",b=="thumbnails"?"list":"thumbnails")});var y=$.extend(!0,{},mist.data.streams),P=function(a,
b){var c=$.extend({},b);delete c.meta;delete c.error;c.online=2;c.name=a;c.ischild=true;return c},Q=function(b,d,f){C.remove();switch(b){case "thumbnails":var e=$("<div>").addClass("preview_icons"),g;g=f||[];d.sort();d.unshift("");C.remove();c.append($("<h2>").text(a)).append(UI.buildUI([{label:"Filter the streams",type:"datalist",datalist:d,pointer:{main:{},index:"stream"},help:"If you type something here, the box below will only show streams with names that contain your text.","function":function(){var a=
$(this).val();e.children().each(function(){$(this).hide();$(this).attr("data-stream").indexOf(a)>-1&&$(this).show()})}}]));d.shift();c.append($("<span>").addClass("description").text("Choose a stream below.")).append(e);for(var h in d){var b=d[h],i="",j=$("<button>").text("Delete").click(function(){var a=$(this).closest("div").attr("data-stream");if(confirm('Are you sure you want to delete the stream "'+a+'"?')){delete mist.data.streams[a];var b={};mist.data.LTS?b.deletestream=[a]:b.streams=mist.data.streams;
mist.send(function(){UI.navto("Streams")},b)}}),l=$("<button>").text("Settings").click(function(){UI.navto("Edit",$(this).closest("div").attr("data-stream"))}),f=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("div").attr("data-stream"))}),k=$("<button>").text("Embed").click(function(){UI.navto("Embed",$(this).closest("div").attr("data-stream"))}),n=$("<span>").addClass("image");if(b.indexOf("+")>-1){i=b.split("+");i=mist.data.streams[i[0]].source+i[1];l=j="";n.addClass("wildcard")}else{i=
mist.data.streams[b].source;if(g.indexOf(b)>-1){k=f="";n.addClass("folder")}}e.append($("<div>").append($("<span>").addClass("streamname").text(b)).append(n).append($("<span>").addClass("description").text(i)).append($("<span>").addClass("button_container").append(l).append(j).append(f).append(k)).attr("title",b).attr("data-stream",b))}break;default:var m=$("<tbody>").append($("<tr>").append("<td>").attr("colspan",6).text("Loading.."));h=$("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Stream name").attr("data-sort-type",
"string").addClass("sorting-asc")).append($("<th>").text("Source").attr("data-sort-type","string")).append($("<th>").text("Status").attr("data-sort-type","int")).append($("<th>").css("text-align","right").text("Connections").attr("data-sort-type","int")).append($("<th>")).append($("<th>")))).append(m);c.append(h);h.stupidtable();var o=function(){var a=[],b;for(b in mist.data.active_streams)a.push({streams:[mist.data.active_streams[b]],fields:["clients"],start:-2});mist.send(function(){$.extend(true,
y,mist.data.streams);var a=0;m.html("");d.sort();for(var b in d){var c=d[b],f;f=c in mist.data.streams?mist.data.streams[c]:y[c];var g=$("<td>").css("text-align","right").html($("<span>").addClass("description").text("Loading..")),e=0;if(typeof mist.data.totals!="undefined"&&typeof mist.data.totals[c]!="undefined"){var h=mist.data.totals[c].all_protocols.clients,e=0;if(h.length){for(a in h)e=e+h[a][1];e=Math.round(e/h.length)}}g.html(UI.format.number(e));if(e==0&&f.online==1)f.online=2;e=$("<td>").css("text-align",
"right").css("white-space","nowrap");(!("ischild"in f)||!f.ischild)&&e.html($("<button>").text("Settings").click(function(){UI.navto("Edit",$(this).closest("tr").data("index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").data("index");if(confirm('Are you sure you want to delete the stream "'+a+'"?')){delete mist.data.streams[a];var b={};mist.data.LTS?b.deletestream=[a]:b.streams=mist.data.streams;mist.send(function(){UI.navto("Streams")},b)}}));h=$("<span>").text(c);
f.ischild&&h.css("padding-left","1em");var da=UI.format.status(f),i=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("tr").data("index"))}),j=$("<button>").text("Embed").click(function(){UI.navto("Embed",$(this).closest("tr").data("index"))});if("filesfound"in y[c]){da.html("");i="";g.html("");j=""}m.append($("<tr>").data("index",c).html($("<td>").html(h).attr("title",c).addClass("overflow_ellipsis")).append($("<td>").text(f.source).attr("title",f.source).addClass("description").addClass("overflow_ellipsis").css("max-width",
"20em")).append($("<td>").data("sort-value",f.online).html(da)).append(g).append($("<td>").css("white-space","nowrap").html(i).append(j)).append(e));a++}},{totals:a,active_streams:true})};if(mist.data.LTS){var p=0,q=0;for(g in mist.data.streams){h=mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"];if(!h)break;if(mist.inputMatch(h.source_match,mist.data.streams[g].source)){y[g].source=y[g].source+"*";y[g].filesfound=null;mist.send(function(a,b){var c=b.stream,d;for(d in a.browse.files)for(var f in mist.data.capabilities.inputs)if(!(f.indexOf("Buffer")>=
0||f.indexOf("Folder")>=0)&&mist.inputMatch(mist.data.capabilities.inputs[f].source_match,"/"+a.browse.files[d])){var e=c+"+"+a.browse.files[d];y[e]=P(e,mist.data.streams[c]);y[e].source=mist.data.streams[c].source+a.browse.files[d]}"files"in a.browse&&a.browse.files.length?y[c].filesfound=true:mist.data.streams[c].filesfound=false;q++;if(p==q){mist.send(function(){o()},{active_streams:true});UI.interval.set(function(){o()},5E3)}},{browse:mist.data.streams[g].source},{stream:g});p++}}if(p==0){mist.send(function(){o()},
{active_streams:true});UI.interval.set(function(){o()},5E3)}}else{mist.send(function(){o()},{active_streams:true});UI.interval.set(function(){o()},5E3)}}};if(mist.data.LTS){var R=0,ba=0,t={},ca=[];for(s in mist.data.streams)if(mist.inputMatch((mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"]).source_match,mist.data.streams[s].source))ca.push(s),mist.send(function(a,c){var d=c.stream,f;for(f in a.browse.files)for(var e in mist.data.capabilities.inputs)e.indexOf("Buffer")>=
0||e.indexOf("Folder")>=0||mist.inputMatch(mist.data.capabilities.inputs[e].source_match,"/"+a.browse.files[f])&&(t[d+"+"+a.browse.files[f]]=true);ba++;R==ba&&mist.send(function(){for(var a in mist.data.active_streams){var c=mist.data.active_streams[a].split("+");if(c.length>1&&c[0]in mist.data.streams){t[mist.data.active_streams[a]]=true;y[mist.data.active_streams[a]]=P(mist.data.active_streams[a],mist.data.streams[c[0]])}}t=Object.keys(t);t=t.concat(Object.keys(mist.data.streams));t.sort();Q(b,
t,ca)},{active_streams:true})},{browse:mist.data.streams[s].source},{stream:s}),R++;0==R&&mist.send(function(){for(var a in mist.data.active_streams){var c=mist.data.active_streams[a].split("+");if(c.length>1&&c[0]in mist.data.streams){t[mist.data.active_streams[a]]=true;y[mist.data.active_streams[a]]=P(mist.data.active_streams[a],mist.data.streams[c[0]])}}t=Object.keys(t);mist.data.streams&&(t=t.concat(Object.keys(mist.data.streams)));t.sort();Q(b,t)},{active_streams:!0})}else Q(b,Object.keys(mist.data.streams));
break;case "Edit":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");break}j=!1;""!=b&&(j=!0);if(j){var r=b,m=mist.data.streams[r];c.find("h2").append(' "'+r+'"')}else c.html($("<h2>").text("New Stream")),m={};r=[];for(f in mist.data.capabilities.inputs)r.push(mist.data.capabilities.inputs[f].source_match);var K=$("<div>"),ea=function(a){if(!mist.data.streams)mist.data.streams={};mist.data.streams[m.name]=m;b!=m.name&&delete mist.data.streams[b];
var c={};if(mist.data.LTS){c.addstream={};c.addstream[m.name]=m;if(b!=m.name)c.deletestream=[b]}else c.streams=mist.data.streams;if(m.stop_sessions&&b!=""){c.stop_sessions=b;delete m.stop_sessions}mist.send(function(){delete mist.data.streams[m.name].online;delete mist.data.streams[m.name].error;UI.navto(a,a=="Preview"?m.name:"")},c)},fa=$("<style>").text("button.saveandpreview { display: none; }");c.append(UI.buildUI([{label:"Stream name",type:"str",validate:["required","streamname"],pointer:{main:m,
index:"name"},help:"Set the name this stream will be recognised by for players and/or stream pushing."},{label:"Source",type:"browse",filetypes:r,pointer:{main:m,index:"source"},help:"<p>Below is the explanation of the input methods for MistServer. Anything between brackets () will go to default settings if not specified.</p><table><tr><td>Input</td><td>Syntax</td><td>Explanation</td></tr> <tr><th>File</th><td>Linux/MacOS:&nbsp;/PATH/FILE<br>Windows:&nbsp;/cygdrive/DRIVE/PATH/FILE</td><td>For file input please specify the proper path and file.<br>Supported inputs are: DTSC, FLV, MP3. MistServer Pro has TS, MP4, ISMV added as input.</td></tr><th>Folder<br>(Pro&nbsp;only)</th><td>Linux/MacOS:&nbsp;/PATH/<br>Windows:&nbsp;/cygdrive/DRIVE/PATH/</td><td>A folder stream makes all the recognised files in the selected folder available as a stream.</td></tr><tr><th>RTMP</th><td>push://(IP)(@PASSWORD)</td><td>IP is white listed IP for pushing towards MistServer, if left empty all are white listed.<br>Password is the application under which to push to MistServer, if it doesn't match the stream will be rejected. Password is MistServer Pro only. <tr><th>RTSP<br>(Pro&nbsp;only)</th><td>push://(IP)(@PASSWORD)</td><td>IP is white listed IP for pushing towards MistServer, if left empty all are white listed.</td></tr> <tr><th>TS<br>(Pro&nbsp;only)</th><td>tsudp://(IP):PORT(/INTERFACE)</td><td>IP is the IP address used to listen for this stream, multi-cast IP range is: 224.0.0.0 - 239.255.255.255. If IP is not set all addresses will listened to.<br>PORT is the port you reserve for this stream on the chosen IP.<br>INTERFACE is the interface used, if left all interfaces will be used.</td></tr></table>",
"function":function(){var a=$(this).val();fa.remove();if(a!=""){var b=null,d;for(d in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[d].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[d].source_match,a)){b=d;break}if(b===null)K.html($("<h3>").text("Unrecognized input").addClass("red")).append($("<span>").text("Please edit the stream source.").addClass("red"));else{b=mist.data.capabilities.inputs[b];K.html($("<h3>").text(b.name+" Input options"));var f=
mist.convertBuildOptions(b,m);"always_match"in mist.data.capabilities.inputs[d]&&mist.inputMatch(mist.data.capabilities.inputs[d].always_match,a)&&f.push({label:"Always on",type:"checkbox",help:"Keep this input available at all times, even when there are no active viewers.",pointer:{main:m,index:"always_on"}});K.append(UI.buildUI(f));b.name=="Folder"&&c.append(fa)}}}},{label:"Stop sessions",type:"checkbox",help:"When saving these stream settings, kill this stream's current connections.",LTSonly:!0,
pointer:{main:m,index:"stop_sessions"}},$("<br>"),{type:"custom",custom:K},$("<br>"),$("<h3>").text("Encryption"),{type:"help",help:"To enable encryption, the licence acquisition url must be entered, as well as either the content key or the key ID and seed.<br>Unsure how you should fill in your encryption or missing your preferred encryption? Please contact us."},{label:"License acquisition url",type:"str",LTSonly:!0,pointer:{main:m,index:"la_url"}},$("<br>"),{label:"Content key",type:"str",LTSonly:!0,
pointer:{main:m,index:"contentkey"}},{type:"text",text:" - or - "},{label:"Key ID",type:"str",LTSonly:!0,pointer:{main:m,index:"keyid"}},{label:"Key seed",type:"str",LTSonly:!0,pointer:{main:m,index:"keyseed"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Streams")}},{type:"save",label:"Save","function":function(){ea("Streams")}},{type:"save",label:"Save and Preview","function":function(){ea("Preview")},classes:["saveandpreview"]}]}]));break;case "Preview":""==
b&&UI.navto("Streams");s=":8080";for(f in mist.data.config.protocols)if(d=mist.data.config.protocols[f],"HTTP"==d.connector||"HTTP.exe"==d.connector)s=d.port?":"+d.port:":8080";var r=parseURL(mist.user.host),L=r.protocol+r.host+s+"/",F=$("<div>").css({display:"flex","flex-flow":"row wrap"}),r="";-1==b.indexOf("+")&&(r=$("<button>").text("Settings").addClass("settings").click(function(){UI.navto("Edit",b)}));c.html($("<div>").addClass("bigbuttons").append(r).append($("<button>").text("Embed").addClass("embed").click(function(){UI.navto("Embed",
b)})).append($("<button>").addClass("cancel").addClass("return").text("Return").click(function(){UI.navto("Streams")}))).append($("<h2>").text('Preview of "'+b+'"')).append(F);var D=encodeURIComponent(b),f=$("<div>");F.append(f);var S=$("<div>"),M=$("<select>").append($("<option>").text("Automatic").val("")).change(function(){T()}),I=$("<select>").append($("<option>").text("Automatic").val("")).change(function(){T()}),r=UI.buildUI([{label:"Use player",type:"DOMfield",DOMfield:M,help:"Choose a player to preview"},
{label:"Use source",type:"DOMfield",DOMfield:I,help:"Choose an output type to preview"}]),G=$("<div>").addClass("mistvideo").text("Loading player..");f.append(G).append(S).append(r);var T=function(){G.html("");A.html("");var a={target:G[0],maxheight:window.innerHeight-$("header").height(),maxwidth:window.innerWidth-UI.elements.menu.width()-100,loop:true};if(M.val()!="")a.forcePlayer=M.val();if(I.val()!="")a.forceType=I.val();mistPlay(b,a)},A=$("<div>").addClass("player_log");f.append($("<div>").append($("<h3>").text("Player log:")).append(A));
G.on("log error",function(a){var b=false;A.height()+A.scrollTop()==A[0].scrollHeight&&(b=true);A.append($("<div>").append($("<span>").text("["+UI.format.time((new Date).getTime()/1E3)+"]").css("margin-right","0.5em")).append($("<span>").text(a.originalEvent.message)).addClass(a.type=="error"?"red":""));b&&A.scrollTop(A[0].scrollHeight)});var ga=function(){S.text("");var a=document.createElement("script");c.append(a);a.src=L+"player.js";a.onerror=function(){G.html("Failed to load player.js").append($("<button>").text("Reload").css("display",
"block").click(function(){ga()}))};a.onload=function(){for(var d in mistplayers)M.append($("<option>").text(mistplayers[d].name).val(d));T();G.on("initialized",function(){if(I.children().length<=1)for(var a in mistvideo[b].source){var c=UI.humanMime(mistvideo[b].source[a].type);I.append($("<option>").val(mistvideo[b].source[a].type).text(c?c+" ("+mistvideo[b].source[a].type+")":UI.format.capital(mistvideo[b].source[a].type)))}a=mistvideo[b].embedded[mistvideo[b].embedded.length-1];c=UI.humanMime(a.player.options.source.type);
S.html("You're watching "+(c?c+" <span class=description>("+a.player.options.source.type+")</span>":UI.format.capital(a.player.options.source.type))+" through "+mistplayers[a.selectedPlayer].name+".")});c[0].removeChild(a)}};ga();var f=$("<div>").append($("<h3>").text("Meta information")),N=$("<span>").text("Loading..");f.append(N);F.append(f);$.ajax({type:"GET",url:L+"json_"+D+".js",success:function(a){var b=a.meta;if(b){a=[];a.push({label:"Type",type:"span",value:b.live?"Live":"Pre-recorded (VoD)"});
"format"in b&&a.push({label:"Format",type:"span",value:b.format});b.live&&a.push({label:"Buffer window",type:"span",value:UI.format.addUnit(b.buffer_window,"ms")});var c={audio:{vheader:"Audio",labels:["Codec","Duration","Peak bitrate","Channels","Samplerate","Language"],content:[]},video:{vheader:"Video",labels:["Codec","Duration","Peak bitrate","Size","Framerate","Language"],content:[]},subtitle:{vheader:"Subtitles",labels:["Codec","Duration","Peak bitrate","Language"],content:[]}},d=Object.keys(b.tracks);
d.sort(function(a,b){a=a.split("_").pop();b=b.split("_").pop();return a-b});for(var f in d){var e=d[f],g=b.tracks[e];switch(g.type){case "audio":c.audio.content.push({header:"Track "+e.split("_").pop(),body:[g.codec,UI.format.duration((g.lastms-g.firstms)/1E3)+"<br><span class=description>"+UI.format.duration(g.firstms/1E3)+" to "+UI.format.duration(g.lastms/1E3)+"</span>",UI.format.bytes(g.bps,1),g.channels,UI.format.addUnit(UI.format.number(g.rate),"Hz"),"lang"in g?g.lang:"unknown"]});break;case "video":c.video.content.push({header:"Track "+
e.split("_").pop(),body:[g.codec,UI.format.duration((g.lastms-g.firstms)/1E3)+"<br><span class=description>"+UI.format.duration(g.firstms/1E3)+" to "+UI.format.duration(g.lastms/1E3)+"</span>",UI.format.bytes(g.bps,1),UI.format.addUnit(g.width,"x ")+UI.format.addUnit(g.height,"px"),UI.format.addUnit(UI.format.number(g.fpks/1E3),"fps"),"lang"in g?g.lang:"unknown"]});break;case "subtitle":c.subtitle.content.push({header:"Track "+e.split("_").pop(),body:[g.codec,UI.format.duration((g.lastms-g.firstms)/
1E3)+"<br><span class=description>"+UI.format.duration(g.firstms/1E3)+" to "+UI.format.duration(g.lastms/1E3)+"</span>",UI.format.bytes(g.bps,1),"lang"in g?g.lang:"unknown"]})}}f=["audio","video","subtitle"];b=$("<div>").css({display:"flex","flex-flow":"row wrap","font-size":"0.9em"});for(e in f)c[f[e]].content.length&&b.append(UI.buildVheaderTable(c[f[e]]).css("width","auto"));a.push($("<span>").text("Tracks:"));a.push(b);N.html(UI.buildUI(a))}else N.html("No meta information available.")},error:function(){N.html("Error while retrieving stream info.")}});
break;case "Embed":""==b&&UI.navTo("Streams");r="";-1==b.indexOf("+")&&(r=$("<button>").addClass("settings").text("Settings").click(function(){UI.navto("Edit",b)}));c.html($("<div>").addClass("bigbuttons").append(r).append($("<button>").text("Preview").addClass("preview").click(function(){UI.navto("Preview",b)})).append($("<button>").addClass("cancel").addClass("return").text("Return").click(function(){UI.navto("Streams")}))).append($("<h2>").text('Embed "'+b+'"'));var O=$("<span>");c.append(O);D=
encodeURIComponent(b);r=parseURL(mist.user.host);s=":8080";for(f in mist.data.config.protocols)if(d=mist.data.config.protocols[f],"HTTP"==d.connector||"HTTP.exe"==d.connector)s=d.port?":"+d.port:":8080";var E=L=r.protocol+r.host+s+"/";otherhost&&(f=parseURL(otherhost),E=f.protocol+f.host+s+"/");var U={forcePlayer:"",forceType:"",controls:!0,autoplay:!0,loop:!1,width:"",height:"",maxwidth:"",maxheight:"",poster:"",urlappend:"",setTracks:{}},o=$.extend({},U),f=UI.stored.getOpts();"embedoptions"in f&&
(o=$.extend(o,f.embedoptions,!0),"object"!=typeof o.setTracks&&(o.setTracks={}));f={};switch(o.controls){case "stock":f.controls="stock";break;case !0:f.controls=1;break;case !1:f.controls=0}var w=function(){function a(b){switch(typeof b){case "string":return $.isNumeric(b)?b:'"'+b+'"';case "object":return JSON.stringify(b);default:return b}}UI.stored.saveOpt("embedoptions",o);for(var c=b+"_",d=12,f="";d--;){var g;g=Math.floor(Math.random()*62);g=g<10?g:g<36?String.fromCharCode(g+55):String.fromCharCode(g+
61);f=f+g}var c=c+f,d=['target: document.getElementById("'+c+'")'],e;for(e in o)o[e]!=U[e]&&(typeof o[e]!="object"||JSON.stringify(o[e])!=JSON.stringify(U[e]))&&d.push(e+": "+a(o[e]));e=[];e.push('<div class="mistvideo" id="'+c+'">');e.push(" <noscript>");e.push(' <a href="'+E+D+'.html" target="_blank">');e.push(" Click here to play this video");e.push(" </a>");e.push(" </noscript>");e.push(" <script>");e.push(" var a = function(){");e.push(' mistPlay("'+b+'",{');e.push(" "+
d.join(",\n "));e.push(" });");e.push(" };");e.push(" if (!window.mistplayers) {");e.push(' var p = document.createElement("script");');e.push(' p.src = "'+E+'player.js"');e.push(" document.head.appendChild(p);");e.push(" p.onload = a;");e.push(" }");e.push(" else { a(); }");e.push(" <\/script>");e.push("</div>");return e.join("\n")},V=$("<span>").text("Loading.."),s=w(o),H=$("<div>").text("Loading..").css("display","flex");O.append($("<span>").addClass("input_container").append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Use a different host:")).append($("<span>").addClass("field_container").append($("<input>").attr("type",
"text").addClass("field").val(otherhost?otherhost:r.protocol+r.host)).append($("<span>").addClass("unit").append($("<button>").text("Apply").click(function(){otherhost=$(this).closest("label").find("input").val();UI.navto("Embed",b)})))))).append(UI.buildUI([$("<h3>").text("Urls"),{label:"Stream info json",type:"str",value:E+"json_"+D+".js",readonly:!0,clipboard:!0,help:"Information about this stream as a json page."},{label:"Stream info script",type:"str",value:E+"info_"+D+".js",readonly:!0,clipboard:!0,
help:"This script loads information about this stream into a mistvideo javascript object."},{label:"HTML page",type:"str",value:E+D+".html",readonly:!0,qrcode:!0,clipboard:!0,help:"A basic html containing the embedded stream."},$("<h3>").text("Embed code"),{label:"Embed code",type:"textarea",value:s,rows:s.split("\n").length+3,readonly:!0,classes:["embed_code"],clipboard:!0,help:"Include this code on your webpage to embed the stream. The options below can be used to configure how your content is displayed."},
$("<h4>").text("Embed code options (optional)").css("margin-top",0),{type:"help",help:"Use these controls to customise what this embedded video will look like.<br>Not all players have all of these options."},{label:"Force player",type:"select",select:[["","Automatic"]],pointer:{main:o,index:"forcePlayer"},classes:["forcePlayer"],"function":function(){o.forcePlayer=$(this).getval();$(".embed_code").setval(w(o))},help:"Only use this particular player."},{label:"Force source",type:"select",select:[["",
"Automatic"]],pointer:{main:o,index:"forceType"},classes:["forceType"],"function":function(){o.forceType=$(this).getval();$(".embed_code").setval(w(o))},help:"Only use this particular source."},{label:"Controls",type:"select",select:[["1","MistServer Controls"],["stock","Player controls"],["0","None"]],pointer:{main:f,index:"controls"},"function":function(){o.controls=$(this).getval()==1;switch($(this).getval()){case 0:o.controls=false;break;case 1:o.controls=true;break;case "stock":o.controls="stock"}$(".embed_code").setval(w(o))},
help:"The type of controls that should be shown."},{label:"Autoplay",type:"checkbox",pointer:{main:o,index:"autoplay"},"function":function(){o.autoplay=$(this).getval();$(".embed_code").setval(w(o))},help:"Whether or not the video should play as the page is loaded."},{label:"Loop",type:"checkbox",pointer:{main:o,index:"loop"},"function":function(){o.loop=$(this).getval();$(".embed_code").setval(w(o))},help:"If the video should restart when the end is reached."},{label:"Force width",type:"int",min:0,
unit:"px",pointer:{main:o,index:"width"},"function":function(){o.width=$(this).getval();$(".embed_code").setval(w(o))},help:"Enforce a fixed width."},{label:"Force height",type:"int",min:0,unit:"px",pointer:{main:o,index:"height"},"function":function(){o.height=$(this).getval();$(".embed_code").setval(w(o))},help:"Enforce a fixed height."},{label:"Maximum width",type:"int",min:0,unit:"px",pointer:{main:o,index:"maxwidth"},"function":function(){o.maxwidth=$(this).getval();$(".embed_code").setval(w(o))},
help:"The maximum width this video can use."},{label:"Maximum height",type:"int",min:0,unit:"px",pointer:{main:o,index:"maxheight"},"function":function(){o.maxheight=$(this).getval();$(".embed_code").setval(w(o))},help:"The maximum height this video can use."},{label:"Poster",type:"str",pointer:{main:o,index:"poster"},"function":function(){o.poster=$(this).getval();$(".embed_code").setval(w(o))},help:"URL to an image that is displayed when the video is not playing."},{label:"Video URL addition",type:"str",
pointer:{main:o,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(){o.urlappend=$(this).getval();$(".embed_code").setval(w(o))}},{label:"Preselect tracks",type:"DOMfield",DOMfield:H,help:"Pre-select these tracks."},$("<h3>").text("Protocol stream urls"),V]));$.ajax({type:"GET",url:E+"json_"+D+".js",success:function(a){var b=[],c=O.find(".forceType"),d;for(d in a.source){var e=
a.source[d],f=UI.humanMime(e.type);b.push({label:f?f+" <span class=description>("+e.type+")</span>":UI.format.capital(e.type),type:"str",value:e.url,readonly:true,qrcode:true,clipboard:true});f=UI.humanMime(e.type);c.append($("<option>").text(f?f+" ("+e.type+")":UI.format.capital(e.type)).val(e.type))}V.html(UI.buildUI(b));H.html("");b={};for(d in a.meta.tracks){c=a.meta.tracks[d];c.type!="audio"&&c.type!="video"||(c.type in b?b[c.type].push([c.trackid,UI.format.capital(c.type)+" track "+(b[c.type].length+
1)]):b[c.type]=[["",UI.format.capital(c.type)+" track 1"]])}if(Object.keys(b).length){H.closest("label").show();for(d in b){a=$("<select>").attr("data-type",d).css("flex-grow","1").change(function(){$(this).val()==""?delete o.setTracks[$(this).attr("data-type")]:o.setTracks[$(this).attr("data-type")]=$(this).val();$(".embed_code").setval(w(o))});H.append(a);b[d].push([-1,"No "+d]);for(var g in b[d])a.append($("<option>").val(b[d][g][0]).text(b[d][g][1]));if(d in o.setTracks){a.val(o.setTracks[d]);
if(a.val()==null){a.val("");delete o.setTracks[d];$(".embed_code").setval(w(o))}}}}else H.closest("label").hide()},error:function(){V.html("Error while retrieving stream info.");H.closest("label").hide();o.setTracks={}}});f=document.createElement("script");f.src=L+"player.js";document.head.appendChild(f);f.onload=function(){var a=O.find(".forcePlayer"),b;for(b in mistplayers)a.append($("<option>").text(mistplayers[b].name).val(b));document.head.removeChild(this)};f.onerror=function(){document.head.removeChild(this)};
break;case "Push":var z=$("<div>").text("Loading..");c.append(z);mist.send(function(a){function b(a){setTimeout(function(){mist.send(function(c){var d=false;if("push_list"in c&&c.push_list&&c.push_list.length){var d=true,f;for(f in c.push_list)if(a.indexOf(c.push_list[f][0])>-1){d=false;break}}else d=true;if(d)for(f in a)e.find("tr[data-pushid="+a[f]+"]").remove();else b()},{push_list:1})},1E3)}function c(d,f){var g=$("<span>");d.length>=4&&d[2]!=d[3]?g.append($("<span>").text(d[2])).append($("<span>").html("&#187").addClass("unit").css("margin",
"0 0.5em")).append($("<span>").text(d[3])):g.append($("<span>").text(d[2]));var h=$("<td>").append($("<button>").text(f=="Automatic"?"Remove":"Stop").click(function(){if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+d[1]+" to "+d[2])){var a=$(this).closest("tr");a.html($("<td colspan=99>").html($("<span>").addClass("red").text(f=="Automatic"?"Removing..":"Stopping..")));f=="Automatic"?mist.send(function(){a.remove()},{push_auto_remove:{stream:d[1],target:d[2]}}):
mist.send(function(){b([d[0]])},{push_stop:[d[0]]})}}));f=="Automatic"&&h.append($("<button>").text("Remove and stop pushes").click(function(){if(confirm("Are you sure you want to remove this automatic push, and also stop all pushes matching it?\n"+d[1]+" to "+d[2])){var c=$(this).closest("tr");c.html($("<td colspan=99>").html($("<span>").addClass("red").text("Removing and stopping..")));var f=[],g;for(g in a.push_list)if(d[1]==a.push_list[g][1]&&d[2]==a.push_list[g][2]){f.push(a.push_list[g][0]);
e.find("tr[data-pushid="+a.push_list[g][0]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}mist.send(function(){c.remove();b(f)},{push_auto_remove:{stream:d[1],target:d[2]},push_stop:f})}}));return $("<tr>").attr("data-pushid",d[0]).append($("<td>").text(d[1])).append($("<td>").append(g.children())).append(h)}z.html("");var d=a.push_settings;d||(d={});z.append(UI.buildUI([{type:"help",help:"You can push streams to files or other servers, allowing them to broadcast your stream as well."},
$("<h3>").text("Settings"),{label:"Delay before retry",unit:"s",type:"int",min:0,help:"How long the delay should be before MistServer retries an automatic push.<br>If set to 0, it does not retry.","default":0,pointer:{main:d,index:"wait"},LTSonly:1},{label:"Maximum retries",unit:"/s",type:"int",min:0,help:"The maximum amount of retries per second (for all automatic pushes).<br>If set to 0, there is no limit.","default":0,pointer:{main:d,index:"maxspeed"},LTSonly:1},{type:"buttons",buttons:[{type:"save",
label:"Save","function":function(){mist.send(function(){UI.navto("Push")},{push_settings:d})}}]}]));var e=$("<table>").append($("<tr>").append($("<th>").text("Stream")).append($("<th>").text("Target")).append($("<th>"))),f=e.clone();if("push_list"in a)for(var g in a.push_list)e.append(c(a.push_list[g],"Manual"));if("push_auto_list"in a)for(g in a.push_auto_list)f.append(c([-1,a.push_auto_list[g][0],a.push_auto_list[g][1]],"Automatic"));z.append($("<h3>").text("Automatic pushes")).append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push",
"auto")}));f.find("tr").length==1?z.append($("<div>").text("No automatic pushes have been configured.").addClass("text").css("margin-top","0.5em")):z.append(f);z.append($("<h3>").text("Pushes")).append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));if(e.find("tr").length==1)z.append($("<div>").text("No pushes are active.").addClass("text").css("margin-top","0.5em"));else{var f=[],h=[],i=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any stream").val("")),
j=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any target").val(""));for(g in a.push_list){f.indexOf(a.push_list[g][1])==-1&&f.push(a.push_list[g][1]);h.indexOf(a.push_list[g][2])==-1&&h.push(a.push_list[g][2])}f.sort();h.sort();for(g in f)i.append($("<option>").text(f[g]));for(g in h)j.append($("<option>").text(h[g]));z.append($("<button>").text("Stop all pushes").click(function(){var c=[],d;for(d in a.push_list)c.push(a.push_list[d][0]);if(c.length!=0&&confirm("Are you sure you want to stop all pushes?")){mist.send(function(){b(c)},
{push_stop:c});e.find("tr:not(:first-child)").html($("<td colspan=99>").append($("<span>").addClass("red").text("Stopping..")));$(this).remove()}})).append($("<label>").css("margin-left","1em").append($("<span>").text("Stop all pushes that match: ").css("font-size","0.9em")).append(i).append($("<span>").css("margin-left","0.5em").text("and").css("font-size","0.9em")).append(j).append($("<button>").css("margin-left","0.5em").text("Apply").click(function(){var c=i.val(),d=j.val();if(c==""&&d=="")return alert("Looks like you want to stop all pushes. Maybe you should use that button?");
var f={},g;for(g in a.push_list)if((c==""||a.push_list[g][1]==c)&&(d==""||a.push_list[g][2]==d))f[a.push_list[g][0]]=a.push_list[g];if(Object.keys(f).length==0)return alert("No matching pushes.");c="Are you sure you want to stop these pushes?\n\n";for(g in f)c=c+(f[g][1]+" to "+f[g][2]+"\n");if(confirm(c)){f=Object.keys(f);mist.send(function(){b(f)},{push_stop:f});for(g in f)e.find("tr[data-pushid="+f[g]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}}))).append(e)}},
{push_settings:1,push_list:1,push_auto_list:1});break;case "Start Push":if(!("capabilities"in mist.data)){c.append("Loading Mist capabilities..");mist.send(function(){UI.navto("Start Push",b)},{capabilities:1});break}var u,W=function(){var a=[],d;for(d in mist.data.capabilities.connectors){var f=mist.data.capabilities.connectors[d];"push_urls"in f&&(a=a.concat(f.push_urls))}b=="auto"&&c.find("h2").text("Add automatic push");var g={};c.append(UI.buildUI([{label:"Stream name",type:"str",help:"This may either be a full stream name, a partial wildcard stream name, or a full wildcard stream name.<br>For example, given the stream <i>a</i> you can use:<ul><li><i>a</i>: the stream configured as <i>a</i></li><li><i>a+</i>: all streams configured as <i>a</i> with a wildcard behind it, but not <i>a</i> itself</li><li><i>a+b</i>: only the version of stream <i>a</i> that has wildcard <i>b</i></li></ul>",
pointer:{main:mist.user,index:"name"}},{label:"Desired password",type:"password",validate:["required",function(a,b){$(".match_password").not($(b)).trigger("change");return false}],help:"Enter your desired password. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"rawpassword"},classes:["match_password"]},{label:"Repeat password",type:"password",validate:["required",function(a,b){return a!=$(".match_password").not($(b)).val()?{msg:'The fields "Desired password" and "Repeat password" do not match.',
classes:["red"]}:false}],help:"Repeat your desired password.",classes:["match_password"]},{type:"buttons",buttons:[{type:"save",label:"Create new account","function":function(){mist.send(function(){UI.navto("Account created")},{authorize:{new_username:mist.user.name,new_password:mist.user.rawpassword}});mist.user.password=MD5(mist.user.rawpassword);delete mist.user.rawpassword}}]}]));break;case "Account created":UI.elements.menu.addClass("hide");c.append($("<p>").text("Your account has been created succesfully.")).append(UI.buildUI([{type:"text",
text:"Would you like to enable all (currently) available protocols with their default settings?"},{type:"buttons",buttons:[{label:"Enable protocols",type:"save","function":function(){if(mist.data.config.protocols)c.append("Unable to enable all protocols as protocol settings already exist.<br>");else{c.append("Retrieving available protocols..<br>");mist.send(function(a){var b=[],d;for(d in a.capabilities.connectors)if(a.capabilities.connectors[d].required)c.append('Could not enable protocol "'+d+'" because it has required settings.<br>');
else{b.push({connector:d});c.append('Enabled protocol "'+d+'".<br>')}c.append("Saving protocol settings..<br>");mist.send(function(){c.append("Protocols enabled. Redirecting..");setTimeout(function(){UI.navto("Overview")},5E3)},{config:{protocols:b}})},{capabilities:true})}}},{label:"Skip",type:"cancel","function":function(){UI.navto("Overview")}}]}]));break;case "Overview":var e=$("<span>").text("Loading.."),k=$("<span>"),m=$("<span>").addClass("logs"),f=$("<span>"),q=$("<span>"),p=$("<span>"),l=
$("<span>");c.append(UI.buildUI([{type:"help",help:"You can find most basic information about your MistServer here.<br>You can also set the debug level and force a save to the config.json file that MistServer uses to save your settings. "},{type:"span",label:"Version",pointer:{main:mist.data.config,index:"version"}},{type:"span",label:"Version check",value:e,LTSonly:!0},{type:"span",label:"Server time",value:q},{type:"span",label:"Configured streams",value:mist.data.streams?Object.keys(mist.data.streams).length:
0},{type:"span",label:"Active streams",value:k},{type:"span",label:"Current connections",value:f},{type:"span",label:"Enabled protocols",value:p},{type:"span",label:"Disabled protocols",value:l},{type:"span",label:"Recent problems",value:m},$("<br>"),{type:"str",label:"Human readable name",pointer:{main:mist.data.config,index:"name"},help:"You can name your MistServer here for personal use. You'll still need to set host name within your network yourself."},{type:"debug",label:"Debug level",pointer:{main:mist.data.config,
index:"debug"},help:"You can set the amount of debug information MistServer saves in the log. A full reboot of MistServer is required before some components of MistServer can post debug information."},{type:"checkbox",label:"Force configurations save",pointer:{main:mist.data,index:"save"},help:"Tick the box in order to force an immediate save to the config.json MistServer uses to save your settings. Saving will otherwise happen upon closing MistServer. Don't forget to press save after ticking the box."},
{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={config:mist.data.config};if(mist.data.save)a.save=mist.data.save;mist.send(function(){UI.navto("Overview")},a)}}]}]));if(mist.data.LTS){var v=function(){var a=mist.stored.get().update||{};"uptodate"in a?a.error?e.addClass("red").text(a.error):a.uptodate?e.text("Your version is up to date.").addClass("green"):e.addClass("red").text("Version outdated!").append($("<button>").text("Update").css({"font-size":"1em","margin-left":"1em"}).click(function(){if(confirm("Are you sure you want to execute a rolling update?")){e.addClass("orange").removeClass("red").text("Rolling update command sent..");
mist.stored.del("update");mist.send(function(){UI.navto("Overview")},{autoupdate:true})}})):e.text("Unknown")};if(!mist.stored.get().update||36E5<(new Date).getTime()-mist.stored.get().update.lastchecked){var h=mist.stored.get().update||{};h.lastchecked=(new Date).getTime();mist.send(function(a){mist.stored.set("update",$.extend(true,h,a.update));v()},{checkupdate:!0})}else v()}else e.text("");var g=function(){var a={totals:{fields:["clients"],start:-10},active_streams:true};if(!("cabailities"in mist.data))a.capabilities=
true;mist.send(function(){i()},a)},i=function(){k.text("active_streams"in mist.data?mist.data.active_streams?mist.data.active_streams.length:0:"?");if("totals"in mist.data&&"all_streams"in mist.data.totals)var a=mist.data.totals.all_streams.all_protocols.clients,a=a.length?UI.format.number(a[a.length-1][1]):0;else a="Loading..";f.text(a);q.text(UI.format.dateTime(mist.data.config.time,"long"));m.html("");var a=0,b;for(b in mist.data.log){var c=mist.data.log[b];if(["FAIL","ERROR"].indexOf(c[1])>-1){a++;
var d=$("<span>").addClass("content").addClass("red"),g=c[2].split("|");for(b in g)d.append($("<span>").text(g[b]));m.append($("<div>").append($("<span>").append(UI.format.time(c[0]))).append(d));if(a==5)break}}a==0&&m.html("None.");a=[];c=[];for(b in mist.data.config.protocols){d=mist.data.config.protocols[b];a.indexOf(d.connector)>-1||a.push(d.connector)}p.text(a.length?a.join(", "):"None.");if("capabilities"in mist.data){for(b in mist.data.capabilities.connectors)a.indexOf(b)==-1&&c.push(b);l.text(c.length?
c.join(", "):"None.")}else l.text("Loading..")};g();i();UI.interval.set(g,3E4);break;case "Protocols":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},{capabilities:!0});c.append("Loading..");return}var j=$("<tbody>");c.append(UI.buildUI([{type:"help",help:"You can find an overview of all the protocols and their relevant information here. You can add, edit or delete protocols."}])).append($("<button>").text("Delete all protocols").click(function(){if(confirm("Are you sure you want to delete all currently configured protocols?")){mist.data.config.protocols=
[];mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}})).append($("<button>").text("Enable default protocols").click(function(){var a=Object.keys(mist.data.capabilities.connectors),b;for(b in mist.data.config.protocols){var c=a.indexOf(mist.data.config.protocols[b].connector);c>-1&&a.splice(c,1)}var d=[];for(b in a)(!("required"in mist.data.capabilities.connectors[a[b]])||Object.keys(mist.data.capabilities.connectors[a[b]].required).length==0)&&d.push(a[b]);c="Click OK to enable disabled protocols with their default settings:\n ";
c=d.length?c+d.join(", "):c+"None.";if(d.length!=a.length){a=a.filter(function(a){return d.indexOf(a)<0});c=c+("\n\nThe following protocols can only be set manually:\n "+a.join(", "))}if(confirm(c)&&d.length){for(b in d)mist.data.config.protocols.push({connector:d[b]});mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}})).append("<br>").append($("<button>").text("New protocol").click(function(){UI.navto("Edit Protocol")}).css("clear","both")).append($("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Protocol")).append($("<th>").text("Status")).append($("<th>").text("Settings")).append($("<th>")))).append(j));
var fa=function(){function a(b){var c=mist.data.capabilities.connectors[b.connector];if(!c)return"";var d=[],g=["required","optional"],y;for(y in g)for(var e in c[g[y]])b[e]&&b[e]!=""?d.push(e+": "+b[e]):c[g[y]][e]["default"]&&d.push(e+": "+c[g[y]][e]["default"]);return $("<span>").addClass("description").text(d.join(", "))}j.html("");for(var b in mist.data.config.protocols){var c=mist.data.config.protocols[b];j.append($("<tr>").data("index",b).append($("<td>").text(c.connector)).append($("<td>").html(UI.format.status(c))).append($("<td>").html(a(c))).append($("<td>").css("text-align",
"right").html($("<button>").text("Edit").click(function(){UI.navto("Edit Protocol",$(this).closest("tr").data("index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").data("index");if(confirm('Are you sure you want to delete the protocol "'+mist.data.config.protocols[a].connector+'"?')){mist.data.config.protocols.splice(a,1);mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}}))))}};fa();UI.interval.set(function(){mist.send(function(){fa()})},
3E4);break;case "Edit Protocol":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}var H=!1;""!=b&&0<=b&&(H=!0);var K={};for(g in mist.data.config.protocols)K[mist.data.config.protocols[g].connector]=1;var ga=function(a){var c=mist.data.capabilities.connectors[a],d=mist.convertBuildOptions(c,n);d.push({type:"hidden",pointer:{main:n,index:"connector"},value:a});d.push({type:"buttons",buttons:[{type:"save",label:"Save",
"function":function(){if(H)mist.data.config.protocols[b]=n;else{if(!mist.data.config.protocols)mist.data.config.protocols=[];mist.data.config.protocols.push(n)}mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}},{type:"cancel",label:"Cancel","function":function(){UI.navto("Protocols")}}]});if("deps"in c&&c.deps!=""){$t=$("<span>").text("Dependencies:");$ul=$("<ul>");$t.append($ul);if(typeof c.deps=="string")c.deps=c.deps.split(", ");for(var g in c.deps){a=$("<li>").text(c.deps[g]+
" ");$ul.append(a);typeof K[c.deps[g]]!="undefined"||typeof K[c.deps[g]+".exe"]!="undefined"?a.append($("<span>").addClass("green").text("(Configured)")):a.append($("<span>").addClass("red").text("(Not yet configured)"))}d.unshift({type:"text",text:$t[0].innerHTML})}return UI.buildUI(d)},K={};for(g in mist.data.config.protocols)K[mist.data.config.protocols[g].connector]=1;if(H)n=d=mist.data.config.protocols[b],c.find("h2").append(' "'+d.connector+'"'),c.append(ga(d.connector));else{c.html($("<h2>").text("New Protocol"));
var n={},t=[["",""]];for(g in mist.data.capabilities.connectors)t.push([g,g]);var I=$("<span>");c.append(UI.buildUI([{label:"Protocol",type:"select",select:t,"function":function(){$(this).getval()!=""&&I.html(ga($(this).getval()))}}])).append(I)}break;case "Streams":if(!("capabilities"in mist.data)){c.html("Loading..");mist.send(function(){UI.navto(a)},{capabilities:!0});return}var g=$("<button>"),D=$("<span>").text("Loading..");c.append(UI.buildUI([{type:"help",help:"Here you can create, edit or delete new and existing streams. Go to stream preview or embed a video player on your website."},
$("<div>").css({width:"45.25em",display:"flex","justify-content":"flex-end"}).append(g).append($("<button>").text("Create a new stream").click(function(){UI.navto("Edit")}))])).append(D);if(""==b){var r=mist.stored.get();"viewmode"in r&&(b=r.viewmode)}g.text("Switch to "+("thumbnails"==b?"list":"thumbnail")+" view").click(function(){mist.stored.set("viewmode",b=="thumbnails"?"list":"thumbnails");UI.navto("Streams",b=="thumbnails"?"list":"thumbnails")});var z=$.extend(!0,{},mist.data.streams),T=function(a,
b){var c=$.extend({},b);delete c.meta;delete c.error;c.online=2;c.name=a;c.ischild=true;return c},U=function(b,d,g){D.remove();switch(b){case "thumbnails":var e=$("<div>").addClass("preview_icons"),f;f=g||[];d.sort();d.unshift("");D.remove();c.append($("<h2>").text(a)).append(UI.buildUI([{label:"Filter the streams",type:"datalist",datalist:d,pointer:{main:{},index:"stream"},help:"If you type something here, the box below will only show streams with names that contain your text.","function":function(){var a=
$(this).val();e.children().each(function(){$(this).hide();$(this).attr("data-stream").indexOf(a)>-1&&$(this).show()})}}]));d.shift();c.append($("<span>").addClass("description").text("Choose a stream below.")).append(e);for(var h in d){var b=d[h],i="",k=$("<button>").text("Delete").click(function(){var a=$(this).closest("div").attr("data-stream");if(confirm('Are you sure you want to delete the stream "'+a+'"?')){delete mist.data.streams[a];var b={};mist.data.LTS?b.deletestream=[a]:b.streams=mist.data.streams;
mist.send(function(){UI.navto("Streams")},b)}}),j=$("<button>").text("Settings").click(function(){UI.navto("Edit",$(this).closest("div").attr("data-stream"))}),g=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("div").attr("data-stream"))}),m=$("<button>").text("Embed").click(function(){UI.navto("Embed",$(this).closest("div").attr("data-stream"))}),l=$("<span>").addClass("image");if(b.indexOf("+")>-1){i=b.split("+");i=mist.data.streams[i[0]].source+i[1];j=k="";l.addClass("wildcard")}else{i=
mist.data.streams[b].source;if(f.indexOf(b)>-1){m=g="";l.addClass("folder")}}e.append($("<div>").append($("<span>").addClass("streamname").text(b)).append(l).append($("<span>").addClass("description").text(i)).append($("<span>").addClass("button_container").append(j).append(k).append(g).append(m)).attr("title",b).attr("data-stream",b))}break;default:var n=$("<tbody>").append($("<tr>").append("<td>").attr("colspan",6).text("Loading.."));h=$("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Stream name").attr("data-sort-type",
"string").addClass("sorting-asc")).append($("<th>").text("Source").attr("data-sort-type","string")).append($("<th>").text("Status").attr("data-sort-type","int")).append($("<th>").css("text-align","right").text("Connections").attr("data-sort-type","int")).append($("<th>")).append($("<th>")))).append(n);c.append(h);h.stupidtable();var o=function(){var a=[],b;for(b in mist.data.active_streams)a.push({streams:[mist.data.active_streams[b]],fields:["clients"],start:-2});mist.send(function(){$.extend(true,
z,mist.data.streams);var a=0;n.html("");d.sort();for(var b in d){var c=d[b],g;g=c in mist.data.streams?mist.data.streams[c]:z[c];var e=$("<td>").css("text-align","right").html($("<span>").addClass("description").text("Loading..")),f=0;if(typeof mist.data.totals!="undefined"&&typeof mist.data.totals[c]!="undefined"){var y=mist.data.totals[c].all_protocols.clients,f=0;if(y.length){for(a in y)f=f+y[a][1];f=Math.round(f/y.length)}}e.html(UI.format.number(f));if(f==0&&g.online==1)g.online=2;f=$("<td>").css("text-align",
"right").css("white-space","nowrap");(!("ischild"in g)||!g.ischild)&&f.html($("<button>").text("Settings").click(function(){UI.navto("Edit",$(this).closest("tr").data("index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").data("index");if(confirm('Are you sure you want to delete the stream "'+a+'"?')){delete mist.data.streams[a];var b={};mist.data.LTS?b.deletestream=[a]:b.streams=mist.data.streams;mist.send(function(){UI.navto("Streams")},b)}}));y=$("<span>").text(c);
g.ischild&&y.css("padding-left","1em");var h=UI.format.status(g),i=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("tr").data("index"))}),k=$("<button>").text("Embed").click(function(){UI.navto("Embed",$(this).closest("tr").data("index"))});if("filesfound"in z[c]){h.html("");i="";e.html("");k=""}n.append($("<tr>").data("index",c).html($("<td>").html(y).attr("title",c).addClass("overflow_ellipsis")).append($("<td>").text(g.source).attr("title",g.source).addClass("description").addClass("overflow_ellipsis").css("max-width",
"20em")).append($("<td>").data("sort-value",g.online).html(h)).append(e).append($("<td>").css("white-space","nowrap").html(i).append(k)).append(f));a++}},{totals:a,active_streams:true})};if(mist.data.LTS){var p=0,q=0;for(f in mist.data.streams){h=mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"];if(!h)break;if(mist.inputMatch(h.source_match,mist.data.streams[f].source)){z[f].source=z[f].source+"*";z[f].filesfound=null;mist.send(function(a,b){var c=b.stream,d;for(d in a.browse.files)for(var g in mist.data.capabilities.inputs)if(!(g.indexOf("Buffer")>=
0||g.indexOf("Buffer.exe")>=0||g.indexOf("Folder")>=0||g.indexOf("Folder.exe")>=0)&&mist.inputMatch(mist.data.capabilities.inputs[g].source_match,"/"+a.browse.files[d])){var e=c+"+"+a.browse.files[d];z[e]=T(e,mist.data.streams[c]);z[e].source=mist.data.streams[c].source+a.browse.files[d]}"files"in a.browse&&a.browse.files.length?z[c].filesfound=true:mist.data.streams[c].filesfound=false;q++;if(p==q){mist.send(function(){o()},{active_streams:true});UI.interval.set(function(){o()},5E3)}},{browse:mist.data.streams[f].source},
{stream:f});p++}}if(p==0){mist.send(function(){o()},{active_streams:true});UI.interval.set(function(){o()},5E3)}}else{mist.send(function(){o()},{active_streams:true});UI.interval.set(function(){o()},5E3)}}};if(mist.data.LTS){var V=0,ha=0,t={},ia=[];for(r in mist.data.streams)if(mist.inputMatch((mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"]).source_match,mist.data.streams[r].source))ia.push(r),mist.send(function(a,c){var d=c.stream,g;for(g in a.browse.files)for(var e in mist.data.capabilities.inputs)e.indexOf("Buffer")>=
0||e.indexOf("Folder")>=0||mist.inputMatch(mist.data.capabilities.inputs[e].source_match,"/"+a.browse.files[g])&&(t[d+"+"+a.browse.files[g]]=true);ha++;V==ha&&mist.send(function(){for(var a in mist.data.active_streams){var c=mist.data.active_streams[a].split("+");if(c.length>1&&c[0]in mist.data.streams){t[mist.data.active_streams[a]]=true;z[mist.data.active_streams[a]]=T(mist.data.active_streams[a],mist.data.streams[c[0]])}}t=Object.keys(t);t=t.concat(Object.keys(mist.data.streams));t.sort();U(b,
t,ia)},{active_streams:true})},{browse:mist.data.streams[r].source},{stream:r}),V++;0==V&&mist.send(function(){for(var a in mist.data.active_streams){var c=mist.data.active_streams[a].split("+");if(c.length>1&&c[0]in mist.data.streams){t[mist.data.active_streams[a]]=true;z[mist.data.active_streams[a]]=T(mist.data.active_streams[a],mist.data.streams[c[0]])}}t=Object.keys(t);mist.data.streams&&(t=t.concat(Object.keys(mist.data.streams)));t.sort();U(b,t)},{active_streams:!0})}else U(b,Object.keys(mist.data.streams));
break;case "Edit":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}H=!1;""!=b&&(H=!0);if(H){var s=b,n=mist.data.streams[s];c.find("h2").append(' "'+s+'"')}else c.html($("<h2>").text("New Stream")),n={};s=[];for(g in mist.data.capabilities.inputs)s.push(mist.data.capabilities.inputs[g].source_match);var O=$("<div>"),ja=function(a){if(!mist.data.streams)mist.data.streams={};mist.data.streams[n.name]=n;b!=n.name&&delete mist.data.streams[b];
var c={};if(mist.data.LTS){c.addstream={};c.addstream[n.name]=n;if(b!=n.name)c.deletestream=[b]}else c.streams=mist.data.streams;if(n.stop_sessions&&b!=""){c.stop_sessions=b;delete n.stop_sessions}mist.send(function(){delete mist.data.streams[n.name].online;delete mist.data.streams[n.name].error;UI.navto(a,a=="Preview"?n.name:"")},c)},ka=$("<style>").text("button.saveandpreview { display: none; }"),E=$("<span>"),W=function(){var a=c.find("[name=name]").val();if(a){var b=parseURL(mist.user.host),d=
c.find("[name=source]").val().match(/@.*/);d&&(d=d[0].substring(1));var g=c.find("[name=source]").val().replace(/(?:.+?):\/\//,""),g=g.split("/"),g=g[0],g=g.split(":"),g=g[0],e={},f=["RTMP","RTSP","TS","RTMP.exe","RTSP.exe","TS.exe"],h;for(h in f)f[h]in mist.data.capabilities.connectors&&(e[f[h]]=mist.data.capabilities.connectors[f[h]].optional.port["default"]);var f={RTMP:1935,"RTMP.exe":1935,RTSP:554,"RTSP.exe":554,TS:-1,"TS.exe":-1},i;for(i in e){for(h in mist.data.config.protocols){var k=mist.data.config.protocols[h];
if(k.connector==i){if("port"in k)e[i]=k.port;break}}e[i]=e[i]==f[i]?"":":"+e[i]}E.find(".field").closest("label").hide();for(h in e){var j;switch(h){case "RTMP":case "RTMP.exe":j="rtmp://"+b.host+e[h]+"/"+(d?d:"live")+"/";E.find(".field.RTMPurl").setval(j).closest("label").show();E.find(".field.RTMPkey").setval(a==""?"STREAMNAME":a).closest("label").show();j=j+(a==""?"STREAMNAME":a);break;case "RTSP":case "RTSP.exe":j="rtsp://"+b.host+e[h]+"/"+(a==""?"STREAMNAME":a)+(d?"?pass="+d:"");break;case "TS":case "TS.exe":j=
"udp://"+(g==""?b.host:g)+e[h]+"/"}E.find(".field."+h.replace(".exe","")).setval(j).closest("label").show()}}};c.append(UI.buildUI([{label:"Stream name",type:"str",validate:["required","streamname"],pointer:{main:n,index:"name"},help:"Set the name this stream will be recognised by for players and/or stream pushing."},{label:"Source",type:"browse",filetypes:s,pointer:{main:n,index:"source"},help:"<p>Below is the explanation of the input methods for MistServer. Anything between brackets () will go to default settings if not specified.</p><table><tr><td>Input</td><td>Syntax</td><td>Explanation</td></tr> <tr><th>File</th><td>Linux/MacOS:&nbsp;/PATH/FILE<br>Windows:&nbsp;/cygdrive/DRIVE/PATH/FILE</td><td>For file input please specify the proper path and file.<br>Supported inputs are: DTSC, FLV, MP3. MistServer Pro has TS, MP4, ISMV added as input.</td></tr><th>Folder<br>(Pro&nbsp;only)</th><td>Linux/MacOS:&nbsp;/PATH/<br>Windows:&nbsp;/cygdrive/DRIVE/PATH/</td><td>A folder stream makes all the recognised files in the selected folder available as a stream.</td></tr><tr><th>RTMP</th><td>push://(IP)(@PASSWORD)</td><td>IP is white listed IP for pushing towards MistServer, if left empty all are white listed.<br>Password is the application under which to push to MistServer, if it doesn't match the stream will be rejected. Password is MistServer Pro only. <tr><th>RTSP<br>(Pro&nbsp;only)</th><td>push://(IP)(@PASSWORD)</td><td>IP is white listed IP for pushing towards MistServer, if left empty all are white listed.</td></tr> <tr><th>TS<br>(Pro&nbsp;only)</th><td>tsudp://(IP):PORT(/INTERFACE)</td><td>IP is the IP address used to listen for this stream, multi-cast IP range is: 224.0.0.0 - 239.255.255.255. If IP is not set all addresses will listened to.<br>PORT is the port you reserve for this stream on the chosen IP.<br>INTERFACE is the interface used, if left all interfaces will be used.</td></tr></table>",
"function":function(){var a=$(this).val();ka.remove();E.html("");if(a!=""){var b=null,d;for(d in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[d].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[d].source_match,a)){b=d;break}if(b===null)O.html($("<h3>").text("Unrecognized input").addClass("red")).append($("<span>").text("Please edit the stream source.").addClass("red"));else{b=mist.data.capabilities.inputs[b];O.html($("<h3>").text(b.name+" Input options"));
var g=mist.convertBuildOptions(b,n);"always_match"in mist.data.capabilities.inputs[d]&&mist.inputMatch(mist.data.capabilities.inputs[d].always_match,a)&&g.push({label:"Always on",type:"checkbox",help:"Keep this input available at all times, even when there are no active viewers.",pointer:{main:n,index:"always_on"}});O.append(UI.buildUI(g));if(b.name=="Folder")c.append(ka);else if(["Buffer","Buffer.exe","TS","TS.exe"].indexOf(b.name)>-1){a=[$("<span>").text("Configure your source to push to:")];switch(b.name){case "Buffer":case "Buffer.exe":a.push({label:"RTMP full url",
type:"span",clipboard:true,readonly:true,classes:["RTMP"],help:"Use this RTMP url if your client doesn't ask for a stream key"});a.push({label:"RTMP url",type:"span",clipboard:true,readonly:true,classes:["RTMPurl"],help:"Use this RTMP url if your client also asks for a stream key"});a.push({label:"RTMP stream key",type:"span",clipboard:true,readonly:true,classes:["RTMPkey"],help:"Use this key if your client asks for a stream key"});a.push({label:"RTSP",type:"span",clipboard:true,readonly:true,classes:["RTSP"]});
break;case "TS":case "TS.exe":a.push({label:"TS",type:"span",clipboard:true,readonly:true,classes:["TS"]})}E.html("<br>").append(UI.buildUI(a));W()}}}}},{label:"Stop sessions",type:"checkbox",help:"When saving these stream settings, kill this stream's current connections.",LTSonly:!0,pointer:{main:n,index:"stop_sessions"}},E,$("<br>"),{type:"custom",custom:O},$("<br>"),$("<h3>").text("Encryption"),{type:"help",help:"To enable encryption, the licence acquisition url must be entered, as well as either the content key or the key ID and seed.<br>Unsure how you should fill in your encryption or missing your preferred encryption? Please contact us."},
{label:"License acquisition url",type:"str",LTSonly:!0,pointer:{main:n,index:"la_url"}},$("<br>"),{label:"Content key",type:"str",LTSonly:!0,pointer:{main:n,index:"contentkey"}},{type:"text",text:" - or - "},{label:"Key ID",type:"str",LTSonly:!0,pointer:{main:n,index:"keyid"}},{label:"Key seed",type:"str",LTSonly:!0,pointer:{main:n,index:"keyseed"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Streams")}},{type:"save",label:"Save","function":function(){ja("Streams")}},
{type:"save",label:"Save and Preview","function":function(){ja("Preview")},classes:["saveandpreview"]}]}]));c.find("[name=name]").keyup(function(){W()});W();break;case "Preview":""==b&&UI.navto("Streams");r=":8080";for(g in mist.data.config.protocols)if(d=mist.data.config.protocols[g],"HTTP"==d.connector||"HTTP.exe"==d.connector)r=d.port?":"+d.port:":8080";var s=parseURL(mist.user.host),P=s.protocol+s.host+r+"/",I=$("<div>").css({display:"flex","flex-flow":"row wrap"}),s="";-1==b.indexOf("+")&&(s=
$("<button>").text("Settings").addClass("settings").click(function(){UI.navto("Edit",b)}));c.html($("<div>").addClass("bigbuttons").append(s).append($("<button>").text("Embed").addClass("embed").click(function(){UI.navto("Embed",b)})).append($("<button>").addClass("cancel").addClass("return").text("Return").click(function(){UI.navto("Streams")}))).append($("<h2>").text('Preview of "'+b+'"')).append(I);var F=encodeURIComponent(b),g=$("<div>");I.append(g);var X=$("<div>"),Q=$("<select>").append($("<option>").text("Automatic").val("")).change(function(){Y()}),
L=$("<select>").append($("<option>").text("Automatic").val("")).change(function(){Y()}),s=UI.buildUI([{label:"Use player",type:"DOMfield",DOMfield:Q,help:"Choose a player to preview"},{label:"Use source",type:"DOMfield",DOMfield:L,help:"Choose an output type to preview"}]),M=$("<div>").addClass("mistvideo").text("Loading player..");g.append(M).append(X).append(s);var Y=function(){C.html("");var a={target:M[0],maxheight:window.innerHeight-$("header").height(),maxwidth:window.innerWidth-UI.elements.menu.width()-
100,loop:true};if(Q.val()!="")a.forcePlayer=Q.val();if(L.val()!="")a.forceSource=L.val();mistPlay(b,a)},C=$("<div>").addClass("player_log");g.append($("<div>").append($("<h3>").text("Player log:")).append(C));M.on("log error",function(a){var b=false;C.height()+C.scrollTop()==C[0].scrollHeight&&(b=true);C.append($("<div>").append($("<span>").text("["+UI.format.time((new Date).getTime()/1E3)+"]").css("margin-right","0.5em")).append($("<span>").text(a.originalEvent.message)).addClass(a.type=="error"?
"red":""));b&&C.scrollTop(C[0].scrollHeight)});var la=function(){X.text("");var a=document.createElement("script");c.append(a);a.src=P+"player.js";a.onerror=function(){M.html("Failed to load player.js").append($("<button>").text("Reload").css("display","block").click(function(){la()}))};a.onload=function(){for(var d in mistplayers)Q.append($("<option>").text(mistplayers[d].name).val(d));Y();M.on("initialized",function(){if(L.children().length<=1)for(var a in mistvideo[b].source){var c=mistvideo[b].source[a],
d=UI.humanMime(c.type);L.append($("<option>").val(a).text(d?d+" @ "+c.url.substring(c.url.length-c.relurl.length,0):UI.format.capital(c.type)+" @ "+c.url.substring(c.url.length-c.relurl.length,0)))}a=mistvideo[b].embedded[mistvideo[b].embedded.length-1];d=UI.humanMime(a.player.options.source.type);X.html("You're watching "+(d?d+" <span class=description>("+a.player.options.source.type+")</span>":UI.format.capital(a.player.options.source.type))+" through "+mistplayers[a.selectedPlayer].name+".")});
c[0].removeChild(a)}};la();var g=$("<div>").append($("<h3>").text("Meta information")),R=$("<span>").text("Loading..");g.append(R);I.append(g);$.ajax({type:"GET",url:P+"json_"+F+".js",success:function(a){var b=a.meta;if(b){a=[];a.push({label:"Type",type:"span",value:b.live?"Live":"Pre-recorded (VoD)"});"format"in b&&a.push({label:"Format",type:"span",value:b.format});b.live&&a.push({label:"Buffer window",type:"span",value:UI.format.addUnit(b.buffer_window,"ms")});var c={audio:{vheader:"Audio",labels:["Codec",
"Duration","Peak bitrate","Channels","Samplerate","Language"],content:[]},video:{vheader:"Video",labels:["Codec","Duration","Peak bitrate","Size","Framerate","Language"],content:[]},subtitle:{vheader:"Subtitles",labels:["Codec","Duration","Peak bitrate","Language"],content:[]}},d=Object.keys(b.tracks);d.sort(function(a,b){a=a.split("_").pop();b=b.split("_").pop();return a-b});for(var g in d){var e=d[g],f=b.tracks[e];switch(f.type){case "audio":c.audio.content.push({header:"Track "+e.split("_").pop(),
body:[f.codec,UI.format.duration((f.lastms-f.firstms)/1E3)+"<br><span class=description>"+UI.format.duration(f.firstms/1E3)+" to "+UI.format.duration(f.lastms/1E3)+"</span>",UI.format.bytes(f.bps,1),f.channels,UI.format.addUnit(UI.format.number(f.rate),"Hz"),"lang"in f?f.lang:"unknown"]});break;case "video":c.video.content.push({header:"Track "+e.split("_").pop(),body:[f.codec,UI.format.duration((f.lastms-f.firstms)/1E3)+"<br><span class=description>"+UI.format.duration(f.firstms/1E3)+" to "+UI.format.duration(f.lastms/
1E3)+"</span>",UI.format.bytes(f.bps,1),UI.format.addUnit(f.width,"x ")+UI.format.addUnit(f.height,"px"),UI.format.addUnit(UI.format.number(f.fpks/1E3),"fps"),"lang"in f?f.lang:"unknown"]});break;case "subtitle":c.subtitle.content.push({header:"Track "+e.split("_").pop(),body:[f.codec,UI.format.duration((f.lastms-f.firstms)/1E3)+"<br><span class=description>"+UI.format.duration(f.firstms/1E3)+" to "+UI.format.duration(f.lastms/1E3)+"</span>",UI.format.bytes(f.bps,1),"lang"in f?f.lang:"unknown"]})}}g=
["audio","video","subtitle"];b=$("<div>").css({display:"flex","flex-flow":"row wrap","font-size":"0.9em"});for(e in g)c[g[e]].content.length&&b.append(UI.buildVheaderTable(c[g[e]]).css("width","auto"));a.push($("<span>").text("Tracks:"));a.push(b);R.html(UI.buildUI(a))}else R.html("No meta information available.")},error:function(){R.html("Error while retrieving stream info.")}});break;case "Embed":""==b&&UI.navTo("Streams");s="";-1==b.indexOf("+")&&(s=$("<button>").addClass("settings").text("Settings").click(function(){UI.navto("Edit",
b)}));c.html($("<div>").addClass("bigbuttons").append(s).append($("<button>").text("Preview").addClass("preview").click(function(){UI.navto("Preview",b)})).append($("<button>").addClass("cancel").addClass("return").text("Return").click(function(){UI.navto("Streams")}))).append($("<h2>").text('Embed "'+b+'"'));var S=$("<span>");c.append(S);F=encodeURIComponent(b);s=parseURL(mist.user.host);r={"":{port:":8080"}};for(g in mist.data.config.protocols){d=mist.data.config.protocols[g];if("HTTP"==d.connector||
"HTTP.exe"==d.connector)r[""].port=d.port?":"+d.port:":8080";if("HTTPS"==d.connector||"HTTPS.exe"==d.connector)r.s={},r.s.port=d.port?":"+d.port:":4433"}var G=P="http://"+s.host+r[""].port+"/";if(otherhost.host||otherhost.https)G=(otherhost.https&&"s"in r?"https://":"http://")+(otherhost.host?otherhost.host:s.host)+(otherhost.https&&"s"in r?r.s.port:r[""].port)+"/";var Z={forcePlayer:"",forceType:"",controls:!0,autoplay:!0,loop:!1,width:"",height:"",maxwidth:"",maxheight:"",poster:"",urlappend:"",
setTracks:{}},o=$.extend({},Z),g=UI.stored.getOpts();"embedoptions"in g&&(o=$.extend(o,g.embedoptions,!0),"object"!=typeof o.setTracks&&(o.setTracks={}));g={};switch(o.controls){case "stock":g.controls="stock";break;case !0:g.controls=1;break;case !1:g.controls=0}var w=function(){function a(b){switch(typeof b){case "string":return $.isNumeric(b)?b:'"'+b+'"';case "object":return JSON.stringify(b);default:return b}}UI.stored.saveOpt("embedoptions",o);for(var c=b+"_",d=12,g="";d--;){var f;f=Math.floor(Math.random()*
62);f=f<10?f:f<36?String.fromCharCode(f+55):String.fromCharCode(f+61);g=g+f}var c=c+g,d=['target: document.getElementById("'+c+'")'],e;for(e in o)o[e]!=Z[e]&&(typeof o[e]!="object"||JSON.stringify(o[e])!=JSON.stringify(Z[e]))&&d.push(e+": "+a(o[e]));e=[];e.push('<div class="mistvideo" id="'+c+'">');e.push(" <noscript>");e.push(' <a href="'+G+F+'.html" target="_blank">');e.push(" Click here to play this video");e.push(" </a>");e.push(" </noscript>");e.push(" <script>");e.push(" var a = function(){");
e.push(' mistPlay("'+b+'",{');e.push(" "+d.join(",\n "));e.push(" });");e.push(" };");e.push(" if (!window.mistplayers) {");e.push(' var p = document.createElement("script");');e.push(' p.src = "'+G+'player.js"');e.push(" document.head.appendChild(p);");e.push(" p.onload = a;");e.push(" }");e.push(" else { a(); }");e.push(" <\/script>");e.push("</div>");return e.join("\n")},aa=$("<span>").text("Loading.."),d=w(o),J=$("<div>").text("Loading..").css("display",
"flex"),ma="";"s"in r&&(ma=UI.buildUI([{label:"Use HTTPS",type:"checkbox","function":function(){if($(this).getval()!=otherhost.https){otherhost.https=$(this).getval();UI.navto("Embed",b)}},value:otherhost.https}]).find("label"));S.append($("<span>").addClass("input_container").append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Use a different host:")).append($("<span>").addClass("field_container").append($("<input>").attr("type","text").addClass("field").val(otherhost.host?
otherhost.host:s.host)).append($("<span>").addClass("unit").append($("<button>").text("Apply").click(function(){otherhost.host=$(this).closest("label").find("input").val();UI.navto("Embed",b)}))))).append(ma)).append(UI.buildUI([$("<h3>").text("Urls"),{label:"Stream info json",type:"str",value:G+"json_"+F+".js",readonly:!0,clipboard:!0,help:"Information about this stream as a json page."},{label:"Stream info script",type:"str",value:G+"info_"+F+".js",readonly:!0,clipboard:!0,help:"This script loads information about this stream into a mistvideo javascript object."},
{label:"HTML page",type:"str",value:G+F+".html",readonly:!0,qrcode:!0,clipboard:!0,help:"A basic html containing the embedded stream."},$("<h3>").text("Embed code"),{label:"Embed code",type:"textarea",value:d,rows:d.split("\n").length+3,readonly:!0,classes:["embed_code"],clipboard:!0,help:"Include this code on your webpage to embed the stream. The options below can be used to configure how your content is displayed."},$("<h4>").text("Embed code options (optional)").css("margin-top",0),{type:"help",
help:"Use these controls to customise what this embedded video will look like.<br>Not all players have all of these options."},{label:"Force player",type:"select",select:[["","Automatic"]],pointer:{main:o,index:"forcePlayer"},classes:["forcePlayer"],"function":function(){o.forcePlayer=$(this).getval();$(".embed_code").setval(w(o))},help:"Only use this particular player."},{label:"Force source",type:"select",select:[["","Automatic"]],pointer:{main:o,index:"forceType"},classes:["forceType"],"function":function(){o.forceType=
$(this).getval();$(".embed_code").setval(w(o))},help:"Only use this particular source."},{label:"Controls",type:"select",select:[["1","MistServer Controls"],["stock","Player controls"],["0","None"]],pointer:{main:g,index:"controls"},"function":function(){o.controls=$(this).getval()==1;switch($(this).getval()){case 0:o.controls=false;break;case 1:o.controls=true;break;case "stock":o.controls="stock"}$(".embed_code").setval(w(o))},help:"The type of controls that should be shown."},{label:"Autoplay",
type:"checkbox",pointer:{main:o,index:"autoplay"},"function":function(){o.autoplay=$(this).getval();$(".embed_code").setval(w(o))},help:"Whether or not the video should play as the page is loaded."},{label:"Loop",type:"checkbox",pointer:{main:o,index:"loop"},"function":function(){o.loop=$(this).getval();$(".embed_code").setval(w(o))},help:"If the video should restart when the end is reached."},{label:"Force width",type:"int",min:0,unit:"px",pointer:{main:o,index:"width"},"function":function(){o.width=
$(this).getval();$(".embed_code").setval(w(o))},help:"Enforce a fixed width."},{label:"Force height",type:"int",min:0,unit:"px",pointer:{main:o,index:"height"},"function":function(){o.height=$(this).getval();$(".embed_code").setval(w(o))},help:"Enforce a fixed height."},{label:"Maximum width",type:"int",min:0,unit:"px",pointer:{main:o,index:"maxwidth"},"function":function(){o.maxwidth=$(this).getval();$(".embed_code").setval(w(o))},help:"The maximum width this video can use."},{label:"Maximum height",
type:"int",min:0,unit:"px",pointer:{main:o,index:"maxheight"},"function":function(){o.maxheight=$(this).getval();$(".embed_code").setval(w(o))},help:"The maximum height this video can use."},{label:"Poster",type:"str",pointer:{main:o,index:"poster"},"function":function(){o.poster=$(this).getval();$(".embed_code").setval(w(o))},help:"URL to an image that is displayed when the video is not playing."},{label:"Video URL addition",type:"str",pointer:{main:o,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(){o.urlappend=$(this).getval();$(".embed_code").setval(w(o))}},{label:"Preselect tracks",type:"DOMfield",DOMfield:J,help:"Pre-select these tracks."},$("<h3>").text("Protocol stream urls"),aa]));$.ajax({type:"GET",url:G+"json_"+F+".js",success:function(a){var b=[],c=S.find(".forceType"),d;for(d in a.source){var g=a.source[d],e=UI.humanMime(g.type);b.push({label:e?e+" <span class=description>("+g.type+")</span>":UI.format.capital(g.type),type:"str",
value:g.url,readonly:true,qrcode:true,clipboard:true});e=UI.humanMime(g.type);c.append($("<option>").text(e?e+" ("+g.type+")":UI.format.capital(g.type)).val(g.type))}aa.html(UI.buildUI(b));J.html("");b={};for(d in a.meta.tracks){c=a.meta.tracks[d];c.type!="audio"&&c.type!="video"||(c.type in b?b[c.type].push([c.trackid,UI.format.capital(c.type)+" track "+(b[c.type].length+1)]):b[c.type]=[["",UI.format.capital(c.type)+" track 1"]])}if(Object.keys(b).length){J.closest("label").show();for(d in b){a=
$("<select>").attr("data-type",d).css("flex-grow","1").change(function(){$(this).val()==""?delete o.setTracks[$(this).attr("data-type")]:o.setTracks[$(this).attr("data-type")]=$(this).val();$(".embed_code").setval(w(o))});J.append(a);b[d].push([-1,"No "+d]);for(var f in b[d])a.append($("<option>").val(b[d][f][0]).text(b[d][f][1]));if(d in o.setTracks){a.val(o.setTracks[d]);if(a.val()==null){a.val("");delete o.setTracks[d];$(".embed_code").setval(w(o))}}}}else J.closest("label").hide()},error:function(){aa.html("Error while retrieving stream info.");
J.closest("label").hide();o.setTracks={}}});g=document.createElement("script");g.src=P+"player.js";document.head.appendChild(g);g.onload=function(){var a=S.find(".forcePlayer"),b;for(b in mistplayers)a.append($("<option>").text(mistplayers[b].name).val(b));document.head.removeChild(this)};g.onerror=function(){document.head.removeChild(this)};break;case "Push":var A=$("<div>").text("Loading..");c.append(A);mist.send(function(a){function b(a){setTimeout(function(){mist.send(function(c){var d=false;
if("push_list"in c&&c.push_list&&c.push_list.length){var d=true,e;for(e in c.push_list)if(a.indexOf(c.push_list[e][0])>-1){d=false;break}}else d=true;if(d)for(e in a)g.find("tr[data-pushid="+a[e]+"]").remove();else b()},{push_list:1})},1E3)}function c(e,f){var h=$("<span>");e.length>=4&&e[2]!=e[3]?h.append($("<span>").text(e[2])).append($("<span>").html("&#187").addClass("unit").css("margin","0 0.5em")).append($("<span>").text(e[3])):h.append($("<span>").text(e[2]));var i=$("<td>").append($("<button>").text(f==
"Automatic"?"Remove":"Stop").click(function(){if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+e[1]+" to "+e[2])){var a=$(this).closest("tr");a.html($("<td colspan=99>").html($("<span>").addClass("red").text(f=="Automatic"?"Removing..":"Stopping..")));f=="Automatic"?mist.send(function(){a.remove()},{push_auto_remove:{stream:e[1],target:e[2]}}):mist.send(function(){b([e[0]])},{push_stop:[e[0]]})}}));f=="Automatic"&&i.append($("<button>").text("Stop pushes").click(function(){if(confirm('Are you sure you want to stop all pushes matching \n"'+
e[1]+" to "+e[2]+'"?'+(d.wait!=0?"\n\nRetrying is enabled. You'll probably want to set that to 0.":""))){var c=$(this);c.text("Stopping pushes..");var f=[],h;for(h in a.push_list)if(e[1]==a.push_list[h][1]&&e[2]==a.push_list[h][2]){f.push(a.push_list[h][0]);g.find("tr[data-pushid="+a.push_list[h][0]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}mist.send(function(){c.text("Stop pushes");b(f)},{push_stop:f,push_settings:{wait:0}})}}));return $("<tr>").attr("data-pushid",
e[0]).append($("<td>").text(e[1])).append($("<td>").append(h.children())).append(i)}A.html("");var d=a.push_settings;d||(d={});A.append(UI.buildUI([{type:"help",help:"You can push streams to files or other servers, allowing them to broadcast your stream as well."},$("<h3>").text("Settings"),{label:"Delay before retry",unit:"s",type:"int",min:0,help:"How long the delay should be before MistServer retries an automatic push.<br>If set to 0, it does not retry.","default":0,pointer:{main:d,index:"wait"},
LTSonly:1},{label:"Maximum retries",unit:"/s",type:"int",min:0,help:"The maximum amount of retries per second (for all automatic pushes).<br>If set to 0, there is no limit.","default":0,pointer:{main:d,index:"maxspeed"},LTSonly:1},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){mist.send(function(){UI.navto("Push")},{push_settings:d})}}]}]));var g=$("<table>").append($("<tr>").append($("<th>").text("Stream")).append($("<th>").text("Target")).append($("<th>"))),e=g.clone();
if("push_list"in a)for(var f in a.push_list)g.append(c(a.push_list[f],"Manual"));if("push_auto_list"in a)for(f in a.push_auto_list)e.append(c([-1,a.push_auto_list[f][0],a.push_auto_list[f][1]],"Automatic"));A.append($("<h3>").text("Automatic pushes")).append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push","auto")}));e.find("tr").length==1?A.append($("<div>").text("No automatic pushes have been configured.").addClass("text").css("margin-top","0.5em")):A.append(e);
A.append($("<h3>").text("Pushes")).append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));if(g.find("tr").length==1)A.append($("<div>").text("No pushes are active.").addClass("text").css("margin-top","0.5em"));else{var e=[],h=[],i=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any stream").val("")),k=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any target").val(""));for(f in a.push_list){e.indexOf(a.push_list[f][1])==-1&&e.push(a.push_list[f][1]);
h.indexOf(a.push_list[f][2])==-1&&h.push(a.push_list[f][2])}e.sort();h.sort();for(f in e)i.append($("<option>").text(e[f]));for(f in h)k.append($("<option>").text(h[f]));A.append($("<button>").text("Stop all pushes").click(function(){var c=[],d;for(d in a.push_list)c.push(a.push_list[d][0]);if(c.length!=0&&confirm("Are you sure you want to stop all pushes?")){mist.send(function(){b(c)},{push_stop:c});g.find("tr:not(:first-child)").html($("<td colspan=99>").append($("<span>").addClass("red").text("Stopping..")));
$(this).remove()}})).append($("<label>").css("margin-left","1em").append($("<span>").text("Stop all pushes that match: ").css("font-size","0.9em")).append(i).append($("<span>").css("margin-left","0.5em").text("and").css("font-size","0.9em")).append(k).append($("<button>").css("margin-left","0.5em").text("Apply").click(function(){var c=i.val(),d=k.val();if(c==""&&d=="")return alert("Looks like you want to stop all pushes. Maybe you should use that button?");var e={},f;for(f in a.push_list)if((c==""||
a.push_list[f][1]==c)&&(d==""||a.push_list[f][2]==d))e[a.push_list[f][0]]=a.push_list[f];if(Object.keys(e).length==0)return alert("No matching pushes.");c="Are you sure you want to stop these pushes?\n\n";for(f in e)c=c+(e[f][1]+" to "+e[f][2]+"\n");if(confirm(c)){e=Object.keys(e);mist.send(function(){b(e)},{push_stop:e});for(f in e)g.find("tr[data-pushid="+e[f]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}}))).append(g)}},{push_settings:1,push_list:1,push_auto_list:1});
break;case "Start Push":if(!("capabilities"in mist.data)){c.append("Loading Mist capabilities..");mist.send(function(){UI.navto("Start Push",b)},{capabilities:1});return}var u,ba=function(){var a=[],d;for(d in mist.data.capabilities.connectors){var e=mist.data.capabilities.connectors[d];"push_urls"in e&&(a=a.concat(e.push_urls))}b=="auto"&&c.find("h2").text("Add automatic push");var g={};c.append(UI.buildUI([{label:"Stream name",type:"str",help:"This may either be a full stream name, a partial wildcard stream name, or a full wildcard stream name.<br>For example, given the stream <i>a</i> you can use:<ul><li><i>a</i>: the stream configured as <i>a</i></li><li><i>a+</i>: all streams configured as <i>a</i> with a wildcard behind it, but not <i>a</i> itself</li><li><i>a+b</i>: only the version of stream <i>a</i> that has wildcard <i>b</i></li></ul>",
pointer:{main:g,index:"stream"},validate:["required",function(a){a=a.split("+");a=a[0];return a in mist.data.streams?false:{msg:"'"+a+"' is not a stream name.",classes:["red"]}}],datalist:u,LTSonly:1},{label:"Target",type:"str",help:"Where the stream will be pushed to.<br>Valid formats:<ul><li>"+a.join("</li><li>")+"</li></ul> Valid text replacements:<ul><li>$stream - inserts the stream name used to push to MistServer</li><li>$day - inserts the current day number</li><li>$month - inserts the current month number</li><li>$year - inserts the current year number</li><li>$hour - inserts the hour timestamp when stream was received</li><li>$minute - inserts the minute timestamp the stream was received</li><li>$seconds - inserts the seconds timestamp when the stream was received</li><li>$datetime - inserts $year.$month.$day.$hour.$minute.$seconds timestamp when the stream was received</li>",
pointer:{main:g,index:"target"},validate:["required",function(b){for(var c in a)if(mist.inputMatch(a[c],b))return false;return{msg:"Does not match a valid target.<br>Valid formats:<ul><li>"+a.join("</li><li>")+"</li></ul>",classes:["red"]}}],LTSonly:1},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Push")}},{type:"save",label:"Save","function":function(){var a={};a[b=="auto"?"push_auto_add":"push_start"]=g;mist.send(function(){UI.navto("Push")},a)}}]}]))};mist.data.LTS?
mist.send(function(a){(u=a.active_streams)||(u=[]);var a=[],b;for(b in u)u[b].indexOf("+")!=-1&&a.push(u[b].replace(/\+.*/,"")+"+");u=u.concat(a);var c=0,d=0;for(b in mist.data.streams){u.push(b);if(mist.inputMatch(mist.data.capabilities.inputs.Folder.source_match,mist.data.streams[b].source)){u.push(b+"+");mist.send(function(a,b){var f=b.stream,g;for(g in a.browse.files)for(var e in mist.data.capabilities.inputs)e.indexOf("Buffer")>=0||e.indexOf("Folder")>=0||mist.inputMatch(mist.data.capabilities.inputs[e].source_match,
"/"+a.browse.files[g])&&u.push(f+"+"+a.browse.files[g]);d++;if(c==d){u=u.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();W()}},{browse:mist.data.streams[b].source},{stream:b});c++}}if(c==d){u=u.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();W()}},{active_streams:1}):(u=Object.keys(mist.data.streams),W());break;case "Triggers":"triggers"in mist.data.config||(mist.data.config.triggers={});g=$("<tbody>");s=$("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Trigger on").attr("data-sort-type",
"string").addClass("sorting-asc")).append($("<th>").text("Applies to").attr("data-sort-type","string")).append($("<th>").text("Handler").attr("data-sort-type","string")).append($("<th>")))).append(g);c.append(UI.buildUI([{type:"help",help:"Triggers are the system you can use to react to events that occur inside MistServer. These allow you to block specific users, redirect streams, keep tabs on what is being pushed where, etcetera. For full documentation, please refer to the developer documentation section on the MistServer website."}])).append($("<button>").text("New trigger").click(function(){UI.navto("Edit Trigger")})).append(s);
s.stupidtable();s=mist.data.config.triggers;for(f in s)for(r in s[f])g.append($("<tr>").attr("data-index",f+","+r).append($("<td>").text(f)).append($("<td>").text(s[f][r][2].join(", "))).append($("<td>").text(s[f][r][0])).append($("<td>").html($("<button>").text("Edit").click(function(){UI.navto("Edit Trigger",$(this).closest("tr").attr("data-index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").attr("data-index").split(",");if(confirm("Are you sure you want to delete this "+
a[0]+" trigger?")){mist.data.config.triggers[a[0]].splice(a[1],1);mist.data.config.triggers[a[0]].length==0&&delete mist.data.config.triggers[a[0]];mist.send(function(){UI.navto("Triggers")},{config:mist.data.config})}}))));break;case "Edit Trigger":"triggers"in mist.data.config||(mist.data.config.triggers={});b?(b=b.split(","),f=mist.data.config.triggers[b[0]][b[1]],m={triggeron:b[0],appliesto:f[2],url:f[0],async:f[1],"default":f[3]}):(c.html($("<h2>").text("New Trigger")),m={});c.append(UI.buildUI([{label:"Trigger on",
pointer:{main:m,index:"triggeron"},help:"For what event this trigger should activate.",type:"select",select:[["SYSTEM_START","SYSTEM_START: after MistServer boot"],["SYSTEM_STOP","SYSTEM_STOP: right before MistServer shutdown"],["SYSTEM_CONFIG","SYSTEM_CONFIG: after MistServer configurations have changed"],["OUTPUT_START","OUTPUT_START: right after the start command has been send to a protocol"],["OUTPUT_STOP","OUTPUT_STOP: right after the close command has been send to a protocol "],["STREAM_ADD",
mist.send(function(a){(u=a.active_streams)||(u=[]);var a=[],b;for(b in u)u[b].indexOf("+")!=-1&&a.push(u[b].replace(/\+.*/,"")+"+");u=u.concat(a);var c=0,d=0;for(b in mist.data.streams){u.push(b);if(mist.inputMatch(mist.data.capabilities.inputs.Folder.source_match,mist.data.streams[b].source)){u.push(b+"+");mist.send(function(a,b){var e=b.stream,g;for(g in a.browse.files)for(var f in mist.data.capabilities.inputs)f.indexOf("Buffer")>=0||f.indexOf("Folder")>=0||mist.inputMatch(mist.data.capabilities.inputs[f].source_match,
"/"+a.browse.files[g])&&u.push(e+"+"+a.browse.files[g]);d++;if(c==d){u=u.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();ba()}},{browse:mist.data.streams[b].source},{stream:b});c++}}if(c==d){u=u.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();ba()}},{active_streams:1}):(u=Object.keys(mist.data.streams),ba());break;case "Triggers":"triggers"in mist.data.config||(mist.data.config.triggers={});j=$("<tbody>");r=$("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Trigger on").attr("data-sort-type",
"string").addClass("sorting-asc")).append($("<th>").text("Applies to").attr("data-sort-type","string")).append($("<th>").text("Handler").attr("data-sort-type","string")).append($("<th>")))).append(j);c.append(UI.buildUI([{type:"help",help:"Triggers are the system you can use to react to events that occur inside MistServer. These allow you to block specific users, redirect streams, keep tabs on what is being pushed where, etcetera. For full documentation, please refer to the developer documentation section on the MistServer website."}])).append($("<button>").text("New trigger").click(function(){UI.navto("Edit Trigger")})).append(r);
r.stupidtable();r=mist.data.config.triggers;for(g in r)for(s in r[g])j.append($("<tr>").attr("data-index",g+","+s).append($("<td>").text(g)).append($("<td>").text(r[g][s][2].join(", "))).append($("<td>").text(r[g][s][0])).append($("<td>").html($("<button>").text("Edit").click(function(){UI.navto("Edit Trigger",$(this).closest("tr").attr("data-index"))})).append($("<button>").text("Delete").click(function(){var a=$(this).closest("tr").attr("data-index").split(",");if(confirm("Are you sure you want to delete this "+
a[0]+" trigger?")){mist.data.config.triggers[a[0]].splice(a[1],1);mist.data.config.triggers[a[0]].length==0&&delete mist.data.config.triggers[a[0]];mist.send(function(){UI.navto("Triggers")},{config:mist.data.config})}}))));break;case "Edit Trigger":"triggers"in mist.data.config||(mist.data.config.triggers={});b?(b=b.split(","),g=mist.data.config.triggers[b[0]][b[1]],n={triggeron:b[0],appliesto:g[2],url:g[0],async:g[1],"default":g[3]}):(c.html($("<h2>").text("New Trigger")),n={});c.append(UI.buildUI([{label:"Trigger on",
pointer:{main:n,index:"triggeron"},help:"For what event this trigger should activate.",type:"select",select:[["SYSTEM_START","SYSTEM_START: after MistServer boot"],["SYSTEM_STOP","SYSTEM_STOP: right before MistServer shutdown"],["SYSTEM_CONFIG","SYSTEM_CONFIG: after MistServer configurations have changed"],["OUTPUT_START","OUTPUT_START: right after the start command has been send to a protocol"],["OUTPUT_STOP","OUTPUT_STOP: right after the close command has been send to a protocol "],["STREAM_ADD",
"STREAM_ADD: right before new stream configured"],["STREAM_CONFIG","STREAM_CONFIG: right before a stream configuration has changed"],["STREAM_REMOVE","STREAM_REMOVE: right before a stream has been deleted"],["STREAM_SOURCE","STREAM_SOURCE: right before stream source is loaded"],["STREAM_LOAD","STREAM_LOAD: right before stream input is loaded in memory"],["STREAM_READY","STREAM_READY: when the stream input is loaded and ready for playback"],["STREAM_UNLOAD","STREAM_UNLOAD: right before the stream input is removed from memory"],
["STREAM_PUSH","STREAM_PUSH: right before an incoming push is accepted"],["STREAM_TRACK_ADD","STREAM_TRACK_ADD: right before a track will be added to a stream; e.g.: additional push received"],["STREAM_TRACK_REMOVE","STREAM_TRACK_REMOVE: right before a track will be removed track from a stream; e.g.: push timeout"],["STREAM_BUFFER","STREAM_BUFFER: when a buffer changes between mostly full or mostly empty"],["RTMP_PUSH_REWRITE","RTMP_PUSH_REWRITE: allows rewriting of RTMP push URLs from external to internal representation before further parsing"],
["PUSH_OUT_START","PUSH_OUT_START: before recording/pushing, allow target changes."],["CONN_OPEN","CONN_OPEN: right after a new incoming connection has been received"],["CONN_CLOSE","CONN_CLOSE: right after a connection has been closed"],["CONN_PLAY","CONN_PLAY: right before a stream playback of a connection"],["USER_NEW","USER_NEW: A new user connects that hasn't been allowed or denied access before"]],LTSonly:!0,"function":function(){switch($(this).getval()){case "SYSTEM_START":case "SYSTEM_STOP":case "SYSTEM_CONFIG":case "OUTPUT_START":case "OUTPUT_STOP":case "RTMP_PUSH_REWRITE":$("[name=appliesto]").setval([]).closest(".UIelement").hide();
break;default:$("[name=appliesto]").closest(".UIelement").show()}}},{label:"Applies to",pointer:{main:m,index:"appliesto"},help:"For triggers that can apply to specific streams, this value decides what streams they are triggered for. (none checked = always triggered)",type:"checklist",checklist:Object.keys(mist.data.streams),LTSonly:!0},$("<br>"),{label:"Handler (URL or executable)",help:"This can be either an HTTP URL or a full path to an executable.",pointer:{main:m,index:"url"},validate:["required"],
type:"str",LTSonly:!0},{label:"Blocking",type:"checkbox",help:"If checked, pauses processing and uses the response of the handler. If the response does not start with 1, true, yes or cont, further processing is aborted. If unchecked, processing is never paused and the response is not checked.",pointer:{main:m,index:"async"},LTSonly:!0},{label:"Default response",type:"str",help:"For blocking requests, the default response in case the handler cannot be executed for any reason.",pointer:{main:m,index:"default"},
LTSonly:!0},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Triggers")}},{type:"save",label:"Save","function":function(){b&&mist.data.config.triggers[b[0]].splice(b[1],1);var a=[m.url,m.async?true:false,typeof m.appliesto!="undefined"?m.appliesto:[]];typeof m["default"]!="undefined"&&a.push(m["default"]);m.triggeron in mist.data.config.triggers||(mist.data.config.triggers[m.triggeron]=[]);mist.data.config.triggers[m.triggeron].push(a);mist.send(function(){UI.navto("Triggers")},
{config:mist.data.config})}}]}]));$("[name=triggeron]").trigger("change");break;case "Logs":var ha=$("<button>").text("Refresh now").click(function(){$(this).text("Loading..");mist.send(function(){X();ha.text("Refresh now")})}).css("padding","0.2em 0.5em").css("flex-grow",0);c.append(UI.buildUI([{type:"help",help:"Here you have an overview of all edited settings within MistServer and possible warnings or errors MistServer has encountered. MistServer stores up to 100 logs at a time."},{label:"Refresh every",
type:"select",select:[[10,"10 seconds"],[30,"30 seconds"],[60,"minute"],[300,"5 minutes"]],value:30,"function":function(){UI.interval.clear();UI.interval.set(function(){mist.send(function(){X()})},$(this).val()*1E3)},help:"How often the table below should be updated."},{label:"..or",type:"DOMfield",DOMfield:ha,help:"Instantly refresh the table below."}]));c.append($("<button>").text("Purge logs").click(function(){mist.send(function(){mist.data.log=[];UI.navto("Logs")},{clearstatlogs:true})}));g=$("<tbody>").css("font-size",
"0.9em");c.append($("<table>").append(g));var ja=function(a){var b=$("<span>").text(a);switch(a){case "WARN":b.addClass("orange");break;case "ERROR":case "FAIL":b.addClass("red")}return b},X=function(){var a=mist.data.log;if(a){a.length>=2&&a[0][0]<a[a.length-1][0]&&a.reverse();g.html("");for(var b in a)g.append($("<tr>").html($("<td>").text(UI.format.dateTime(a[b][0],"long")).css("white-space","nowrap")).append($("<td>").html(ja(a[b][1])).css("text-align","center")).append($("<td>").text(a[b][2]).css("text-align",
"left")))}};X();break;case "Statistics":var B=$("<span>").text("Loading..");c.append(B);var m={},x=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},J={};for(f in mist.data.streams)J[f]=!0;for(f in mist.data.active_streams)J[mist.data.active_streams[f]]=!0;var J=Object.keys(J).sort(),Y=[];for(f in mist.data.config.protocols)Y.push(mist.data.config.protocols[f].connector);Y.sort();mist.send(function(){UI.plot.datatype.templates.cpuload.cores=0;for(var a in mist.data.capabilities.cpu)UI.plot.datatype.templates.cpuload.cores=
UI.plot.datatype.templates.cpuload.cores+mist.data.capabilities.cpu[a].cores;B.html(UI.buildUI([{type:"help",help:"Here you will find the MistServer stream statistics, you can select various categories yourself. All statistics are live: up to five minutes are saved."},$("<h3>").text("Select the data to display"),{label:"Add to",type:"select",select:[["new","New graph"]],pointer:{main:m,index:"graph"},classes:["graph_ids"],"function":function(){if($(this).val()){var a=B.find(".graph_xaxis"),b=B.find(".graph_id");
if($(this).val()=="new"){a.children("option").prop("disabled",false);b.setval("Graph "+(Object.keys(x).length+1)).closest("label").show()}else{var c=x[$(this).val()].xaxis;a.children("option").prop("disabled",true).filter('[value="'+c+'"]').prop("disabled",false);b.closest("label").hide()}a.children('option[value="'+a.val()+'"]:disabled').length&&a.val(a.children("option:enabled").first().val());a.trigger("change")}}},{label:"Graph id",type:"str",pointer:{main:m,index:"id"},classes:["graph_id"],validate:[function(a){return a in
x?{msg:"This graph id has already been used. Please enter something else.",classes:["red"]}:false}]},{label:"Axis type",type:"select",select:[["time","Time line"]],pointer:{main:m,index:"xaxis"},value:"time",classes:["graph_xaxis"],"function":function(){$s=B.find(".graph_datatype");switch($(this).getval()){case "coords":$s.children("option").prop("disabled",true).filter('[value="coords"]').prop("disabled",false);break;case "time":$s.children("option").prop("disabled",false).filter('[value="coords"]').prop("disabled",
true)}if(!$s.val()||$s.children('option[value="'+$s.val()+'"]:disabled').length){$s.val($s.children("option:enabled").first().val());$s.trigger("change")}}},{label:"Data type",type:"select",select:[["clients","Connections"],["upbps","Bandwidth (up)"],["downbps","Bandwidth (down)"],["cpuload","CPU use"],["memload","Memory load"],["coords","Client location"]],pointer:{main:m,index:"datatype"},classes:["graph_datatype"],"function":function(){$s=B.find(".graph_origin");switch($(this).getval()){case "cpuload":case "memload":$s.find("input[type=radio]").not('[value="total"]').prop("disabled",
true);$s.find('input[type=radio][value="total"]').prop("checked",true);break;default:$s.find("input[type=radio]").prop("disabled",false)}}},{label:"Data origin",type:"radioselect",radioselect:[["total","All"],["stream","The stream:",J],["protocol","The protocol:",Y]],pointer:{main:m,index:"origin"},value:["total"],classes:["graph_origin"]},{type:"buttons",buttons:[{label:"Add data set",type:"save","function":function(){var a;if(m.graph=="new"){a=UI.plot.addGraph(m,b);x[a.id]=a;B.find("select.graph_ids").append($("<option>").text(a.id)).val(a.id).trigger("change")}else a=
x[m.graph];var c=UI.plot.datatype.getOptions({datatype:m.datatype,origin:m.origin});a.datasets.push(c);UI.plot.save(a);UI.plot.go(x)}}]}]));var b=$("<div>").addClass("graph_container");c.append(b);var d=B.find("select.graph_ids");for(a in x){var f=UI.plot.addGraph(x[a],b);d.append($("<option>").text(f.id)).val(f.id);var g=[],e;for(e in x[a].datasets){var h=UI.plot.datatype.getOptions({datatype:x[a].datasets[e].datatype,origin:x[a].datasets[e].origin});g.push(h)}f.datasets=g;x[f.id]=f}d.trigger("change");
UI.plot.go(x);UI.interval.set(function(){UI.plot.go(x)},1E4)},{active_streams:!0,capabilities:!0});break;case "Server Stats":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},{capabilities:!0});c.append("Loading..");break}var Z=$("<table>"),C=$("<table>"),r={vheader:"CPUs",labels:["Model","Processor speed","Amount of cores","Amount of threads"],content:[]};for(f in mist.data.capabilities.cpu)s=mist.data.capabilities.cpu[f],r.content.push({header:"CPU #"+(Number(f)+1),
body:[s.model,UI.format.addUnit(UI.format.number(s.mhz),"MHz"),s.cores,s.threads]});var f=UI.buildVheaderTable(r),ia=function(){var a=mist.data.capabilities.mem,b=mist.data.capabilities.load,a={vheader:"Memory",labels:["Used","Cached","Available","Total"],content:[{header:"Physical memory",body:[UI.format.bytes(a.used*1048576)+" ("+UI.format.addUnit(b.memory,"%")+")",UI.format.bytes(a.cached*1048576),UI.format.bytes(a.free*1048576),UI.format.bytes(a.total*1048576)]},{header:"Swap memory",body:[UI.format.bytes((a.swaptotal-
a.swapfree)*1048576),UI.format.addUnit("","N/A"),UI.format.bytes(a.swapfree*1048576),UI.format.bytes(a.swaptotal*1048576)]}]},a=UI.buildVheaderTable(a);Z.replaceWith(a);Z=a;b={vheader:"Load average",labels:["CPU use","1 minute","5 minutes","15 minutes"],content:[{header:"&nbsp;",body:[UI.format.addUnit(UI.format.number(mist.data.capabilities.cpu_use/10),"%"),UI.format.number(b.one/100),UI.format.number(b.five/100),UI.format.number(b.fifteen/100)]}]};b=UI.buildVheaderTable(b);C.replaceWith(b);C=b};
ia();c.append(UI.buildUI([{type:"help",help:"You can find general server statistics here. Note that memory and CPU usage is for your entire machine, not just MistServer."}])).append($("<table>").css("width","auto").addClass("nolay").append($("<tr>").append($("<td>").append(Z)).append($("<td>").append(C))).append($("<tr>").append($("<td>").append(f).attr("colspan",2))));UI.interval.set(function(){mist.send(function(){ia()},{capabilities:true})},3E4);break;case "Email for Help":f=$.extend({},mist.data);
delete f.statistics;delete f.totals;delete f.clients;delete f.capabilities;f=JSON.stringify(f);f="Version: "+mist.data.config.version+"\n\nConfig:\n"+f;m={};c.append(UI.buildUI([{type:"help",help:"You can use this form to email MistServer support if you're having difficulties.<br>A copy of your server config file will automatically be included."},{type:"str",label:"Your name",validate:["required"],pointer:{main:m,index:"name"},value:mist.user.name},{type:"email",label:"Your email address",validate:["required"],
pointer:{main:m,index:"email"}},{type:"hidden",value:"Integrated Help",pointer:{main:m,index:"subject"}},{type:"hidden",value:"-",pointer:{main:m,index:"company"}},{type:"textarea",rows:20,label:"Your message",validate:["required"],pointer:{main:m,index:"message"}},{type:"textarea",rows:20,label:"Your config file",readonly:!0,value:f,pointer:{main:m,index:"configfile"}},{type:"buttons",buttons:[{type:"save",label:"Send","function":function(a){$(a).text("Sending..");$.ajax({type:"POST",url:"http://mistserver.org/contact?skin=plain",
data:m,success:function(a){a=$("<span>").html(a);a.find("script").remove();c.html(a[0].innerHTML)}})}}]}]));break;case "Disconnect":mist.user.password="";delete mist.user.authstring;delete mist.user.loggedin;sessionStorage.removeItem("mistLogin");UI.navto("Login");break;default:c.append($("<p>").text("This tab does not exist."))}}}};"origin"in location||(location.origin=location.protocol+"//"+location.hostname+(location.port?":"+location.port:""));
break;default:$("[name=appliesto]").closest(".UIelement").show()}}},{label:"Applies to",pointer:{main:n,index:"appliesto"},help:"For triggers that can apply to specific streams, this value decides what streams they are triggered for. (none checked = always triggered)",type:"checklist",checklist:Object.keys(mist.data.streams),LTSonly:!0},$("<br>"),{label:"Handler (URL or executable)",help:"This can be either an HTTP URL or a full path to an executable.",pointer:{main:n,index:"url"},validate:["required"],
type:"str",LTSonly:!0},{label:"Blocking",type:"checkbox",help:"If checked, pauses processing and uses the response of the handler. If the response does not start with 1, true, yes or cont, further processing is aborted. If unchecked, processing is never paused and the response is not checked.",pointer:{main:n,index:"async"},LTSonly:!0},{label:"Default response",type:"str",help:"For blocking requests, the default response in case the handler cannot be executed for any reason.",pointer:{main:n,index:"default"},
LTSonly:!0},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Triggers")}},{type:"save",label:"Save","function":function(){b&&mist.data.config.triggers[b[0]].splice(b[1],1);var a=[n.url,n.async?true:false,typeof n.appliesto!="undefined"?n.appliesto:[]];typeof n["default"]!="undefined"&&a.push(n["default"]);n.triggeron in mist.data.config.triggers||(mist.data.config.triggers[n.triggeron]=[]);mist.data.config.triggers[n.triggeron].push(a);mist.send(function(){UI.navto("Triggers")},
{config:mist.data.config})}}]}]));$("[name=triggeron]").trigger("change");break;case "Logs":var na=$("<button>").text("Refresh now").click(function(){$(this).text("Loading..");mist.send(function(){ca();na.text("Refresh now")})}).css("padding","0.2em 0.5em").css("flex-grow",0);c.append(UI.buildUI([{type:"help",help:"Here you have an overview of all edited settings within MistServer and possible warnings or errors MistServer has encountered. MistServer stores up to 100 logs at a time."},{label:"Refresh every",
type:"select",select:[[10,"10 seconds"],[30,"30 seconds"],[60,"minute"],[300,"5 minutes"]],value:30,"function":function(){UI.interval.clear();UI.interval.set(function(){mist.send(function(){ca()})},$(this).val()*1E3)},help:"How often the table below should be updated."},{label:"..or",type:"DOMfield",DOMfield:na,help:"Instantly refresh the table below."}]));c.append($("<button>").text("Purge logs").click(function(){mist.send(function(){mist.data.log=[];UI.navto("Logs")},{clearstatlogs:true})}));j=
$("<tbody>").css("font-size","0.9em");c.append($("<table>").addClass("logs").append(j));var pa=function(a){var b=$("<span>").text(a);switch(a){case "WARN":b.addClass("orange");break;case "ERROR":case "FAIL":b.addClass("red")}return b},ca=function(){var a=mist.data.log;if(a){a.length>=2&&a[0][0]<a[a.length-1][0]&&a.reverse();j.html("");for(var b in a){var c=$("<span>").addClass("content"),d=a[b][2].split("|"),e;for(e in d)c.append($("<span>").text(d[e]));j.append($("<tr>").html($("<td>").text(UI.format.dateTime(a[b][0],
"long")).css("white-space","nowrap")).append($("<td>").html(pa(a[b][1])).css("text-align","center")).append($("<td>").html(c).css("text-align","left")))}}};ca();break;case "Statistics":var B=$("<span>").text("Loading..");c.append(B);var n={graph:"new"},x=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},N={};for(g in mist.data.streams)N[g]=!0;for(g in mist.data.active_streams)N[mist.data.active_streams[g]]=!0;var N=Object.keys(N).sort(),da=[];for(g in mist.data.config.protocols)da.push(mist.data.config.protocols[g].connector);
da.sort();mist.send(function(){UI.plot.datatype.templates.cpuload.cores=0;for(var a in mist.data.capabilities.cpu)UI.plot.datatype.templates.cpuload.cores=UI.plot.datatype.templates.cpuload.cores+mist.data.capabilities.cpu[a].cores;B.html(UI.buildUI([{type:"help",help:"Here you will find the MistServer stream statistics, you can select various categories yourself. All statistics are live: up to five minutes are saved."},$("<h3>").text("Select the data to display"),{label:"Add to",type:"select",select:[["new",
"New graph"]],pointer:{main:n,index:"graph"},classes:["graph_ids"],"function":function(){if($(this).val()){var a=B.find(".graph_xaxis"),b=B.find(".graph_id");if($(this).val()=="new"){a.children("option").prop("disabled",false);b.setval("Graph "+(Object.keys(x).length+1)).closest("label").show()}else{var c=x[$(this).val()].xaxis;a.children("option").prop("disabled",true).filter('[value="'+c+'"]').prop("disabled",false);b.closest("label").hide()}a.children('option[value="'+a.val()+'"]:disabled').length&&
a.val(a.children("option:enabled").first().val());a.trigger("change")}}},{label:"Graph id",type:"str",pointer:{main:n,index:"id"},classes:["graph_id"],validate:[function(a){return a in x?{msg:"This graph id has already been used. Please enter something else.",classes:["red"]}:false}]},{label:"Axis type",type:"select",select:[["time","Time line"]],pointer:{main:n,index:"xaxis"},value:"time",classes:["graph_xaxis"],"function":function(){$s=B.find(".graph_datatype");switch($(this).getval()){case "coords":$s.children("option").prop("disabled",
true).filter('[value="coords"]').prop("disabled",false);break;case "time":$s.children("option").prop("disabled",false).filter('[value="coords"]').prop("disabled",true)}if(!$s.val()||$s.children('option[value="'+$s.val()+'"]:disabled').length){$s.val($s.children("option:enabled").first().val());$s.trigger("change")}}},{label:"Data type",type:"select",select:[["clients","Connections"],["upbps","Bandwidth (up)"],["downbps","Bandwidth (down)"],["cpuload","CPU use"],["memload","Memory load"],["coords",
"Client location"]],pointer:{main:n,index:"datatype"},classes:["graph_datatype"],"function":function(){$s=B.find(".graph_origin");switch($(this).getval()){case "cpuload":case "memload":$s.find("input[type=radio]").not('[value="total"]').prop("disabled",true);$s.find('input[type=radio][value="total"]').prop("checked",true);break;default:$s.find("input[type=radio]").prop("disabled",false)}}},{label:"Data origin",type:"radioselect",radioselect:[["total","All"],["stream","The stream:",N],["protocol",
"The protocol:",da]],pointer:{main:n,index:"origin"},value:["total"],classes:["graph_origin"]},{type:"buttons",buttons:[{label:"Add data set",type:"save","function":function(){var a;if(n.graph=="new"){a=UI.plot.addGraph(n,b);x[a.id]=a;B.find("input.graph_id").val("");B.find("select.graph_ids").append($("<option>").text(a.id)).val(a.id).trigger("change")}else a=x[n.graph];var c=UI.plot.datatype.getOptions({datatype:n.datatype,origin:n.origin});a.datasets.push(c);UI.plot.save(a);UI.plot.go(x)}}]}]));
var b=$("<div>").addClass("graph_container");c.append(b);var d=B.find("select.graph_ids");for(a in x){var e=UI.plot.addGraph(x[a],b);d.append($("<option>").text(e.id)).val(e.id);var g=[],f;for(f in x[a].datasets){var h=UI.plot.datatype.getOptions({datatype:x[a].datasets[f].datatype,origin:x[a].datasets[f].origin});g.push(h)}e.datasets=g;x[e.id]=e}d.trigger("change");UI.plot.go(x);UI.interval.set(function(){UI.plot.go(x)},1E4)},{active_streams:!0,capabilities:!0});break;case "Server Stats":if("undefined"==
typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},{capabilities:!0});c.append("Loading..");return}var ea=$("<table>"),D=$("<table>"),s={vheader:"CPUs",labels:["Model","Processor speed","Amount of cores","Amount of threads"],content:[]};for(g in mist.data.capabilities.cpu)r=mist.data.capabilities.cpu[g],s.content.push({header:"CPU #"+(Number(g)+1),body:[r.model,UI.format.addUnit(UI.format.number(r.mhz),"MHz"),r.cores,r.threads]});var g=UI.buildVheaderTable(s),oa=function(){var a=mist.data.capabilities.mem,
b=mist.data.capabilities.load,a={vheader:"Memory",labels:["Used","Cached","Available","Total"],content:[{header:"Physical memory",body:[UI.format.bytes(a.used*1048576)+" ("+UI.format.addUnit(b.memory,"%")+")",UI.format.bytes(a.cached*1048576),UI.format.bytes(a.free*1048576),UI.format.bytes(a.total*1048576)]},{header:"Swap memory",body:[UI.format.bytes((a.swaptotal-a.swapfree)*1048576),UI.format.addUnit("","N/A"),UI.format.bytes(a.swapfree*1048576),UI.format.bytes(a.swaptotal*1048576)]}]},a=UI.buildVheaderTable(a);
ea.replaceWith(a);ea=a;b={vheader:"Load average",labels:["CPU use","1 minute","5 minutes","15 minutes"],content:[{header:"&nbsp;",body:[UI.format.addUnit(UI.format.number(mist.data.capabilities.cpu_use/10),"%"),UI.format.number(b.one/100),UI.format.number(b.five/100),UI.format.number(b.fifteen/100)]}]};b=UI.buildVheaderTable(b);D.replaceWith(b);D=b};oa();c.append(UI.buildUI([{type:"help",help:"You can find general server statistics here. Note that memory and CPU usage is for your entire machine, not just MistServer."}])).append($("<table>").css("width",
"auto").addClass("nolay").append($("<tr>").append($("<td>").append(ea)).append($("<td>").append(D))).append($("<tr>").append($("<td>").append(g).attr("colspan",2))));UI.interval.set(function(){mist.send(function(){oa()},{capabilities:true})},3E4);break;case "Email for Help":g=$.extend({},mist.data);delete g.statistics;delete g.totals;delete g.clients;delete g.capabilities;g=JSON.stringify(g);g="Version: "+mist.data.config.version+"\n\nConfig:\n"+g;n={};c.append(UI.buildUI([{type:"help",help:"You can use this form to email MistServer support if you're having difficulties.<br>A copy of your server config file will automatically be included."},
{type:"str",label:"Your name",validate:["required"],pointer:{main:n,index:"name"},value:mist.user.name},{type:"email",label:"Your email address",validate:["required"],pointer:{main:n,index:"email"}},{type:"hidden",value:"Integrated Help",pointer:{main:n,index:"subject"}},{type:"hidden",value:"-",pointer:{main:n,index:"company"}},{type:"textarea",rows:20,label:"Your message",validate:["required"],pointer:{main:n,index:"message"}},{type:"textarea",rows:20,label:"Your config file",readonly:!0,value:g,
pointer:{main:n,index:"configfile"}},{type:"buttons",buttons:[{type:"save",label:"Send","function":function(a){$(a).text("Sending..");$.ajax({type:"POST",url:"http://mistserver.org/contact?skin=plain",data:n,success:function(a){a=$("<span>").html(a);a.find("script").remove();c.html(a[0].innerHTML)}})}}]}]));break;case "Disconnect":mist.user.password="";delete mist.user.authstring;delete mist.user.loggedin;sessionStorage.removeItem("mistLogin");UI.navto("Login");break;default:c.append($("<p>").text("This tab does not exist."))}c.find(".field").filter(function(){return $(this).getval()==
""}).each(function(){var a=[];$(this).is("input, select, textarea")?a.push($(this)):a=$(this).find("input, select, textarea");if(a.length){$(a[0]).focus();return false}})}}};"origin"in location||(location.origin=location.protocol+"//"+location.hostname+(location.port?":"+location.port:""));
var mist={data:{},user:{name:"",password:"",host:location.origin+location.pathname.replace(/\/+$/,"")+"/api"},send:function(a,b,c){var b=b||{},c=c||{},c=$.extend(true,{timeOut:3E4,sendData:b},c),d={authorize:{password:mist.user.authstring?MD5(mist.user.password+mist.user.authstring):"",username:mist.user.name}};$.extend(true,d,b);log("Send",$.extend(true,{},b));d={url:mist.user.host,type:"POST",data:{command:JSON.stringify(d)},dataType:"jsonp",crossDomain:true,timeout:c.timeout*1E3,async:true,error:function(d,
e){delete mist.user.loggedin;if(!c.hide){switch(e){case "timeout":e=$("<i>").text("The connection timed out. ");break;case "abort":e=$("<i>").text("The connection was aborted. ");break;default:e=$("<i>").text(e+". ").css("text-transform","capitalize")}$("#message").addClass("red").text("An error occurred while attempting to communicate with MistServer:").append($("<br>")).append(e).append($("<a>").text("Send server request again").click(function(){mist.send(a,b,c)}))}UI.navto("Login")},success:function(d){log("Receive",
$.extend(true,{},d),"as reply to",c.sendData);delete mist.user.loggedin;switch(d.authorize.status){case "OK":if("streams"in d)if(d.streams)if("incomplete list"in d.streams){delete d.streams["incomplete list"];$.extend(mist.data.streams,d.streams)}else mist.data.streams=d.streams;else mist.data.streams={};var e=$.extend({},d),h=["config","capabilities","ui_settings","LTS","active_streams","browse","log","totals"],q;for(q in e)h.indexOf(q)==-1&&delete e[q];$.extend(true,mist.data,e);mist.user.loggedin=
$.extend(true,{},d),"as reply to",c.sendData);delete mist.user.loggedin;switch(d.authorize.status){case "OK":if("streams"in d)if(d.streams)if("incomplete list"in d.streams){delete d.streams["incomplete list"];$.extend(mist.data.streams,d.streams)}else mist.data.streams=d.streams;else mist.data.streams={};var e=$.extend({},d),f=["config","capabilities","ui_settings","LTS","active_streams","browse","log","totals"],q;for(q in e)f.indexOf(q)==-1&&delete e[q];$.extend(true,mist.data,e);mist.user.loggedin=
true;UI.elements.connection.status.text("Connected").removeClass("red").addClass("green");UI.elements.connection.user_and_host.text(mist.user.name+" @ "+mist.user.host);UI.elements.connection.msg.removeClass("red").text("Last communication with the server at "+UI.format.time((new Date).getTime()/1E3));d.LTS&&UI.elements.menu.find(".LTSonly").removeClass("LTSonly");if(d.log){e=d.log[d.log.length-1];UI.elements.connection.msg.append($("<br>")).append("Last log entry: "+UI.format.time(e[0])+" ["+e[1]+
"] "+e[2])}if("totals"in d){e=function(a,b,c){var d;d=function(){for(var a in c.fields)e[c.fields[a]].push([l,0])};var e={},h;for(h in c.fields)e[c.fields[h]]=[];var k=0,l;if(c.data){if(c.start>mist.data.config.time-600){l=(mist.data.config.time-600)*1E3;d();l=c.start*1E3;d()}else l=c.start*1E3;for(h in c.data){if(h==0){l=c.start*1E3;var m=0}else{l=l+c.interval[m][1]*1E3;c.interval[m][0]--;if(c.interval[m][0]<=0){m++;m<c.interval.length-1&&(k=k+2)}}if(k%2==1){d();k--}for(var n in c.data[h])e[c.fields[n]].push([l,
c.data[h][n]]);if(k){d();k--}}if(mist.data.config.time-c.end>20){d();l=(mist.data.config.time-15)*1E3;d()}}else{l=(mist.data.config.time-600)*1E3;d();l=(mist.data.config.time-15)*1E3;d()}d=e;stream=a?a.join(" "):"all_streams";protocol=b?b.join("_"):"all_protocols";stream in mist.data.totals||(mist.data.totals[stream]={});protocol in mist.data.totals[stream]||(mist.data.totals[stream][protocol]={});$.extend(mist.data.totals[stream][protocol],d)};mist.data.totals={};if("fields"in d.totals)e(b.totals.streams,
"] "+e[2])}if("totals"in d){e=function(a,b,c){var d;d=function(){for(var a in c.fields)e[c.fields[a]].push([k,0])};var e={},f;for(f in c.fields)e[c.fields[f]]=[];var j=0,k;if(c.data){if(c.start>mist.data.config.time-600){k=(mist.data.config.time-600)*1E3;d();k=c.start*1E3;d()}else k=c.start*1E3;for(f in c.data){if(f==0){k=c.start*1E3;var m=0}else{k=k+c.interval[m][1]*1E3;c.interval[m][0]--;if(c.interval[m][0]<=0){m++;m<c.interval.length-1&&(j=j+2)}}if(j%2==1){d();j--}for(var q in c.data[f])e[c.fields[q]].push([k,
c.data[f][q]]);if(j){d();j--}}if(mist.data.config.time-c.end>20){d();k=(mist.data.config.time-15)*1E3;d()}}else{k=(mist.data.config.time-600)*1E3;d();k=(mist.data.config.time-15)*1E3;d()}d=e;stream=a?a.join(" "):"all_streams";protocol=b?b.join("_"):"all_protocols";stream in mist.data.totals||(mist.data.totals[stream]={});protocol in mist.data.totals[stream]||(mist.data.totals[stream][protocol]={});$.extend(mist.data.totals[stream][protocol],d)};mist.data.totals={};if("fields"in d.totals)e(b.totals.streams,
b.totals.protocols,d.totals);else for(q in d.totals)e(b.totals[q].streams,b.totals[q].protocols,d.totals[q])}a&&a(d,c);break;case "CHALL":if(d.authorize.challenge==mist.user.authstring){mist.user.password!=""&&UI.elements.connection.msg.text("The credentials you provided are incorrect.").addClass("red");UI.navto("Login")}else if(mist.user.password=="")UI.navto("Login");else{mist.user.authstring=d.authorize.challenge;mist.send(a,b,c);sessionStorage.setItem("mistLogin",JSON.stringify({host:mist.user.host,
name:mist.user.name,password:mist.user.password}))}break;case "NOACC":UI.navto("Create a new account");break;case "ACC_MADE":delete b.authorize;mist.send(a,b,c);break;default:UI.navto("Login")}}};c.hide||UI.elements.connection.msg.removeClass("red").text("Data sent, waiting for a reply..").append($("<br>")).append($("<a>").text("Cancel request").click(function(){e.abort()}));var e=$.ajax(d)},inputMatch:function(a,b){if(typeof a=="undefined")return false;typeof a=="string"&&(a=[a]);for(var c in a){var d=
a[c].replace(/[^\w\s]/g,"\\$&"),d=d.replace(/\\\?/g,".").replace(/\\\*/g,"(?:.)*");if(RegExp("^(?:[a-zA-Z]:)?"+d+"$","i").test(b))return true}return false},convertBuildOptions:function(a,b){var c=[],d=["required","optional"];"desc"in a&&c.push({type:"help",help:a.desc});for(var e in d)if(a[d[e]]){c.push($("<h4>").text(UI.format.capital(d[e])+" parameters"));for(var l in a[d[e]]){var n=a[d[e]][l],h={label:UI.format.capital(n.name),pointer:{main:b,index:l},validate:[]};d[e]=="required"&&!("default"in
n)&&h.validate.push("required");if("default"in n)h.placeholder=n["default"];if("help"in n)h.help=n.help;if("unit"in n)h.unit=n.unit;switch(n.type){case "int":h.type="int";break;case "uint":h.type="int";h.min=0;break;case "debug":h.type="debug";break;case "select":h.type="select";h.select=n.select;break;default:h.type="str"}c.push(h)}}return c},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,b){var c=this.get();c[a]=b;mist.send(function(){},{ui_settings:c})},del:function(a){delete mist.data.ui_settings[a];
mist.send(function(){},{ui_settings:mist.data.ui_settings})}}};function log(){try{UI.debug&&[].push.call(arguments,Error().stack);[].unshift.call(arguments,"["+UI.format.time((new Date).getTime()/1E3)+"]");console.log.apply(console,arguments)}catch(a){}}
a[c].replace(/[^\w\s]/g,"\\$&"),d=d.replace(/\\\?/g,".").replace(/\\\*/g,"(?:.)*");if(RegExp("^(?:[a-zA-Z]:)?"+d+"$","i").test(b))return true}return false},convertBuildOptions:function(a,b){var c=[],d=["required","optional"];"desc"in a&&c.push({type:"help",help:a.desc});for(var e in d)if(a[d[e]]){c.push($("<h4>").text(UI.format.capital(d[e])+" parameters"));for(var k in a[d[e]]){var m=a[d[e]][k],f={label:UI.format.capital(m.name),pointer:{main:b,index:k},validate:[]};d[e]=="required"&&(!("default"in
m)||m["default"]=="")&&f.validate.push("required");if("default"in m)f.placeholder=m["default"];if("help"in m)f.help=m.help;if("unit"in m)f.unit=m.unit;switch(m.type){case "int":f.type="int";break;case "uint":f.type="int";f.min=0;break;case "debug":f.type="debug";break;case "select":f.type="select";f.select=m.select;break;default:f.type="str"}c.push(f)}}return c},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,b){var c=this.get();c[a]=b;mist.send(function(){},{ui_settings:c})},
del:function(a){delete mist.data.ui_settings[a];mist.send(function(){},{ui_settings:mist.data.ui_settings})}}};function log(){try{UI.debug&&[].push.call(arguments,Error().stack);[].unshift.call(arguments,"["+UI.format.time((new Date).getTime()/1E3)+"]");console.log.apply(console,arguments)}catch(a){}}
$.fn.getval=function(){var a=$(this).data("opts"),b=$(this).val();if(a&&"type"in a)switch(a.type){case "span":b=$(this).html();break;case "checkbox":b=$(this).prop("checked");break;case "radioselect":a=$(this).find("label > input[type=radio]:checked").parent();if(a.length){b=[];b.push(a.children("input[type=radio]").val());a=a.children("select");a.length&&b.push(a.val())}else b="";break;case "checklist":b=[];$(this).find(".checklist input[type=checkbox]:checked").each(function(){b.push($(this).attr("name"))})}return b};
$.fn.setval=function(a){var b=$(this).data("opts");$(this).val(a);if(b&&"type"in b)switch(b.type){case "span":$(this).html(a);break;case "checkbox":$(this).prop("checked",a);break;case "geolimited":case "hostlimited":b=$(this).closest(".field_container").data("subUI");if(typeof a=="undefined"||a.length==0)a="-";b.blackwhite.val(a.charAt(0));var a=a.substr(1).split(" "),c;for(c in a)b.values.append(b.prototype.clone(true).val(a[c]));b.blackwhite.trigger("change");break;case "radioselect":if(typeof a==
"undefined")return $(this);c=$(this).find('label > input[type=radio][value="'+a[0]+'"]').prop("checked",true).parent();a.length>1&&c.children("select").val(a[1]);break;case "checklist":b=$(this).find(".checklist input[type=checkbox]").prop("checked",false);for(c in a)b.filter('[name="'+a[c]+'"]').prop("checked",true)}$(this).trigger("change");return $(this)};function parseURL(a){var b=document.createElement("a");b.href=a;return{protocol:b.protocol+"//",host:b.hostname,port:b.port?":"+b.port:""}};

View file

@ -56,7 +56,10 @@ $(window).on('hashchange', function(e) {
UI.showTab(tab[0],tab[1]);
});
var otherhost = false;
var otherhost = {
host: false,
https: false
};
var UI = {
debug: false,
elements: {},
@ -1909,7 +1912,7 @@ var UI = {
help: 'Enter your desired password. In the future, you will need this to access the Management Interface.',
pointer: {
main: mist.user,
index: 'password'
index: 'rawpassword'
},
classes: ['match_password']
},{
@ -1937,9 +1940,11 @@ var UI = {
},{
authorize: {
new_username: mist.user.name,
new_password: mist.user.password
new_password: mist.user.rawpassword
}
});
mist.user.password = MD5(mist.user.rawpassword);
delete mist.user.rawpassword;
}
}]
}]));
@ -2004,9 +2009,13 @@ var UI = {
break;
case 'Overview':
var $versioncheck = $('<span>').text('Loading..');
var $streamsonline = $('<span>');
var $streamsactive = $('<span>');
var $errors = $('<span>').addClass('logs');
var $viewers = $('<span>');
var $servertime = $('<span>');
var $protocols_on = $('<span>');
var $protocols_off = $('<span>');
$main.append(UI.buildUI([
{
type: 'help',
@ -2029,12 +2038,28 @@ var UI = {
value: $servertime
},{
type: 'span',
label: 'Current streams',
value: $streamsonline
label: 'Configured streams',
value: (mist.data.streams ? Object.keys(mist.data.streams).length : 0)
},{
type: 'span',
label: 'Active streams',
value: $streamsactive
},{
type: 'span',
label: 'Current connections',
value: $viewers
},{
type: 'span',
label: 'Enabled protocols',
value: $protocols_on
},{
type: 'span',
label: 'Disabled protocols',
value: $protocols_off
},{
type: 'span',
label: 'Recent problems',
value: $errors
},$('<br>'),{
type: 'str',
label: 'Human readable name',
@ -2122,15 +2147,19 @@ var UI = {
$versioncheck.text('');
}
function updateViewers() {
mist.send(function(d){
enterStats()
},{
var request = {
totals:{
fields: ['clients'],
start: -10
},
active_streams: true
});
};
if (!('cabailities' in mist.data)) {
request.capabilities = true;
}
mist.send(function(d){
enterStats()
},request);
}
function enterStats() {
if ('active_streams' in mist.data) {
@ -2139,7 +2168,7 @@ var UI = {
else {
var active = '?';
}
$streamsonline.text(active+' active, '+(mist.data.streams ? Object.keys(mist.data.streams).length : 0)+' configured');
$streamsactive.text(active);
if (('totals' in mist.data) && ('all_streams' in mist.data.totals)) {
var clients = mist.data.totals.all_streams.all_protocols.clients;
clients = (clients.length ? UI.format.number(clients[clients.length-1][1]) : 0);
@ -2149,6 +2178,55 @@ var UI = {
}
$viewers.text(clients);
$servertime.text(UI.format.dateTime(mist.data.config.time,'long'));
$errors.html('');
var n = 0;
for (var i in mist.data.log) {
var l = mist.data.log[i];
if (['FAIL','ERROR'].indexOf(l[1]) > -1) {
n++;
var $content = $('<span>').addClass('content').addClass('red');
var split = l[2].split('|');
for (var i in split) {
$content.append(
$('<span>').text(split[i])
);
}
$errors.append(
$('<div>').append(
$('<span>').append(UI.format.time(l[0]))
).append(
$content
)
);
if (n == 5) { break; }
}
}
if (n == 0) {
$errors.html('None.');
}
var protocols = {
on: [],
off: []
};
for (var i in mist.data.config.protocols) {
var p = mist.data.config.protocols[i];
if (protocols.on.indexOf(p.connector) > -1) { continue; }
protocols.on.push(p.connector);
}
$protocols_on.text((protocols.on.length ? protocols.on.join(', ') : 'None.'));
if ('capabilities' in mist.data) {
for (var i in mist.data.capabilities.connectors) {
if (protocols.on.indexOf(i) == -1) {
protocols.off.push(i);
}
}
$protocols_off.text((protocols.off.length ? protocols.off.join(', ') : 'None.'));
}
else {
$protocols_off.text('Loading..')
}
}
updateViewers();
enterStats();
@ -2171,9 +2249,57 @@ var UI = {
help: 'You can find an overview of all the protocols and their relevant information here. You can add, edit or delete protocols.'
}])
).append(
$('<button>').text('Delete all protocols').click(function(){
if (confirm('Are you sure you want to delete all currently configured protocols?')) {
mist.data.config.protocols = [];
mist.send(function(d){
UI.navto('Protocols');
},{config: mist.data.config});
}
})
).append(
$('<button>').text('Enable default protocols').click(function(){
var toenable = Object.keys(mist.data.capabilities.connectors);
for (var i in mist.data.config.protocols) {
var p = mist.data.config.protocols[i];
var index = toenable.indexOf(p.connector)
if (index > -1) {
toenable.splice(index,1);
}
}
var dontskip = [];
for (var i in toenable) {
if ((!('required' in mist.data.capabilities.connectors[toenable[i]])) || (Object.keys(mist.data.capabilities.connectors[toenable[i]].required).length == 0)) {
dontskip.push(toenable[i]);
}
}
var msg = 'Click OK to enable disabled protocols with their default settings:'+"\n ";
if (dontskip.length) {
msg += dontskip.join(', ');
}
else {
msg += 'None.';
}
if (dontskip.length != toenable.length) {
var skip = toenable.filter(function(ele){
return dontskip.indexOf(ele) < 0;
});
msg += "\n\n"+'The following protocols can only be set manually:'+"\n "+skip.join(', ');
}
if (confirm(msg) && dontskip.length) {
for (var i in dontskip) {
mist.data.config.protocols.push({connector: dontskip[i]});
}
mist.send(function(d){
UI.navto('Protocols');
},{config: mist.data.config});
}
})
).append('<br>').append(
$('<button>').text('New protocol').click(function(){
UI.navto('Edit Protocol');
})
}).css('clear','both')
).append(
$('<table>').html(
$('<thead>').html(
@ -2346,7 +2472,7 @@ var UI = {
$('<h2>').text('New Protocol')
);
var saveas = {};
var select = [];
var select = [['','']];
for (var i in mist.data.capabilities.connectors) {
select.push([i,i]);
}
@ -2356,6 +2482,7 @@ var UI = {
type: 'select',
select: select,
'function': function(){
if ($(this).getval() == '') { return; }
$cont.html(buildProtocolSettings($(this).getval()));
}
}])).append(
@ -2695,7 +2822,7 @@ var UI = {
var s = opts.stream;
for (var i in d.browse.files) {
for (var j in mist.data.capabilities.inputs) {
if ((j.indexOf('Buffer') >= 0) || (j.indexOf('Folder') >= 0)) { continue; }
if ((j.indexOf('Buffer') >= 0) || (j.indexOf('Buffer.exe') >= 0) || (j.indexOf('Folder') >= 0) || (j.indexOf('Folder.exe') >= 0)) { continue; }
if (mist.inputMatch(mist.data.capabilities.inputs[j].source_match,'/'+d.browse.files[i])) {
var streamname = s+'+'+d.browse.files[i];
allstreams[streamname] = createWcStreamObject(streamname,mist.data.streams[s]);
@ -2876,8 +3003,73 @@ var UI = {
}
var $style = $('<style>').text('button.saveandpreview { display: none; }');
var $livestreamhint = $('<span>');
function updateLiveStreamHint() {
var streamname = $main.find('[name=name]').val();
if (!streamname) { return; }
var host = parseURL(mist.user.host);
var passw = $main.find('[name=source]').val().match(/@.*/);
if (passw) { passw = passw[0].substring(1); }
var ip = $main.find('[name=source]').val().replace(/(?:.+?):\/\//,'');
ip = ip.split('/');
ip = ip[0];
ip = ip.split(':');
ip = ip[0];
var port = {};
var trythese = ['RTMP','RTSP','TS','RTMP.exe','RTSP.exe','TS.exe'];
for (var i in trythese) {
if (trythese[i] in mist.data.capabilities.connectors) {
port[trythese[i]] = mist.data.capabilities.connectors[trythese[i]].optional.port['default'];
}
}
var defport = {
RTMP: 1935,
'RTMP.exe': 1935,
RTSP: 554,
'RTSP.exe': 554,
TS: -1,
'TS.exe': -1
};
for (var protocol in port) {
for (var i in mist.data.config.protocols) {
var p = mist.data.config.protocols[i];
if (p.connector == protocol) {
if ('port' in p) {
port[protocol] = p.port;
}
break;
}
}
if (port[protocol] == defport[protocol]) { port[protocol] = ''; }
else { port[protocol] = ':'+port[protocol]; }
}
$livestreamhint.find('.field').closest('label').hide();
for (var i in port) {
var str;
switch(i) {
case 'RTMP':
case 'RTMP.exe':
str = 'rtmp://'+host.host+port[i]+'/'+(passw ? passw : 'live')+'/';
$livestreamhint.find('.field.RTMPurl').setval(str).closest('label').show();
$livestreamhint.find('.field.RTMPkey').setval((streamname == '' ? 'STREAMNAME' : streamname)).closest('label').show();
str += (streamname == '' ? 'STREAMNAME' : streamname);
break;
case 'RTSP':
case 'RTSP.exe':
str = 'rtsp://'+host.host+port[i]+'/'+(streamname == '' ? 'STREAMNAME' : streamname)+(passw ? '?pass='+passw : '');
break;
case 'TS':
case 'TS.exe':
str = 'udp://'+(ip == '' ? host.host : ip)+port[i]+'/';
break;
}
$livestreamhint.find('.field.'+i.replace('.exe','')).setval(str).closest('label').show();
}
}
$main.append(UI.buildUI([
{
label: 'Stream name',
@ -2900,6 +3092,7 @@ var UI = {
'function': function(){
var source = $(this).val();
$style.remove();
$livestreamhint.html('');
if (source == '') { return; }
var type = null;
for (var i in mist.data.capabilities.inputs) {
@ -2937,6 +3130,57 @@ var UI = {
if (input.name == 'Folder') {
$main.append($style);
}
else if (['Buffer','Buffer.exe','TS','TS.exe'].indexOf(input.name) > -1) {
var fields = [$('<span>').text('Configure your source to push to:')];
switch (input.name) {
case 'Buffer':
case 'Buffer.exe':
fields.push({
label: 'RTMP full url',
type: 'span',
clipboard: true,
readonly: true,
classes: ['RTMP'],
help: 'Use this RTMP url if your client doesn\'t ask for a stream key'
});
fields.push({
label: 'RTMP url',
type: 'span',
clipboard: true,
readonly: true,
classes: ['RTMPurl'],
help: 'Use this RTMP url if your client also asks for a stream key'
});
fields.push({
label: 'RTMP stream key',
type: 'span',
clipboard: true,
readonly: true,
classes: ['RTMPkey'],
help: 'Use this key if your client asks for a stream key'
});
fields.push({
label: 'RTSP',
type: 'span',
clipboard: true,
readonly: true,
classes: ['RTSP']
});
break;
case 'TS':
case 'TS.exe':
fields.push({
label: 'TS',
type: 'span',
clipboard: true,
readonly: true,
classes: ['TS']
});
break;
}
$livestreamhint.html('<br>').append(UI.buildUI(fields));
updateLiveStreamHint();
}
}
},{
label: 'Stop sessions',
@ -2947,7 +3191,7 @@ var UI = {
main: saveas,
index: 'stop_sessions'
}
},$('<br>'),{
},$livestreamhint,$('<br>'),{
type: 'custom',
custom: $inputoptions
},$('<br>'),$('<h3>').text('Encryption'),{
@ -3015,6 +3259,11 @@ var UI = {
}
]));
$main.find('[name=name]').keyup(function(){
updateLiveStreamHint();
});
updateLiveStreamHint();
break;
case 'Preview':
@ -3074,7 +3323,7 @@ var UI = {
var $video = $('<div>').addClass('mistvideo').text('Loading player..');
$preview_cont.append($video).append($title).append($switches);
function initPlayer() {
$video.html('');
//$video.html('');
$log.html('');
var options = {
target: $video[0],
@ -3086,7 +3335,7 @@ var UI = {
options.forcePlayer = $s_players.val()
}
if ($s_mimes.val() != '') {
options.forceType = $s_mimes.val()
options.forceSource = $s_mimes.val()
}
mistPlay(other,options);
}
@ -3139,10 +3388,11 @@ var UI = {
$video.on('initialized',function(){
if ($s_mimes.children().length <= 1) {
for (var i in mistvideo[other].source) {
var human = UI.humanMime(mistvideo[other].source[i].type);
var s = mistvideo[other].source[i];
var human = UI.humanMime(s.type);
$s_mimes.append(
$('<option>').val(mistvideo[other].source[i].type).text(
(human ? human+' ('+mistvideo[other].source[i].type+')' : UI.format.capital(mistvideo[other].source[i].type))
$('<option>').val(i).text(
(human ? human+' @ '+s.url.substring(s.url.length - s.relurl.length,0) : UI.format.capital(s.type)+' @ '+s.url.substring(s.url.length - s.relurl.length,0))
)
);
}
@ -3318,19 +3568,26 @@ var UI = {
var escapedstream = encodeURIComponent(other);
var parsed = parseURL(mist.user.host);
var http_port = ':8080';
var http = {
'': {
port: ':8080'
}
};
for (var i in mist.data.config.protocols) {
var protocol = mist.data.config.protocols[i];
if ((protocol.connector == 'HTTP') || (protocol.connector == 'HTTP.exe')) {
http_port = (protocol.port ? ':'+protocol.port : ':8080');
http[''].port = (protocol.port ? ':'+protocol.port : ':8080');
}
if ((protocol.connector == 'HTTPS') || (protocol.connector == 'HTTPS.exe')) {
http.s = {};
http.s.port = (protocol.port ? ':'+protocol.port : ':4433');
}
}
var embedbase = parsed.protocol+parsed.host+http_port+'/';
var embedbase = 'http://'+parsed.host+http[''].port+'/';
var otherbase = embedbase;
if (otherhost) {
var otherparse = parseURL(otherhost);
otherbase = otherparse.protocol+otherparse.host+http_port+'/';
if ((otherhost.host) || (otherhost.https)) {
otherbase = (otherhost.https && ('s' in http) ? 'https://' : 'http://')+(otherhost.host ? otherhost.host : parsed.host)+(otherhost.https && ('s' in http) ? http.s.port : http[''].port)+'/';
}
var defaultembedoptions = {
@ -3437,23 +3694,40 @@ var UI = {
var $protocolurls = $('<span>').text('Loading..');
var emhtml = embedhtml(embedoptions);
var $setTracks = $('<div>').text('Loading..').css('display','flex');
var $usehttps = '';
if ('s' in http) {
$usehttps = UI.buildUI([{
label: 'Use HTTPS',
type: 'checkbox',
'function': function(){
if ($(this).getval() != otherhost.https) {
otherhost.https = $(this).getval();
UI.navto('Embed',other);
}
},
value: otherhost.https
}]).find('label');
}
$embedlinks.append(
$('<span>').addClass('input_container').append(
$('<label>').addClass('UIelement').append(
$('<span>').addClass('label').text('Use a different host:')
).append(
$('<span>').addClass('field_container').append(
$('<input>').attr('type','text').addClass('field').val((otherhost ? otherhost : parsed.protocol+parsed.host))
$('<input>').attr('type','text').addClass('field').val((otherhost.host ? otherhost.host : parsed.host))
).append(
$('<span>').addClass('unit').append(
$('<button>').text('Apply').click(function(){
otherhost = $(this).closest('label').find('input').val();
otherhost.host = $(this).closest('label').find('input').val();
UI.navto('Embed',other);
})
)
)
)
)
).append($usehttps)
).append(UI.buildUI([
$('<h3>').text('Urls'),
{
@ -3891,14 +4165,10 @@ var UI = {
);
if (type == 'Automatic') {
$buttons.append(
$('<button>').text('Remove and stop pushes').click(function(){
if (confirm("Are you sure you want to remove this automatic push, and also stop all pushes matching it?\n"+push[1]+' to '+push[2])) {
var $tr = $(this).closest('tr');
$tr.html(
$('<td colspan=99>').html(
$('<span>').addClass('red').text('Removing and stopping..')
)
);
$('<button>').text('Stop pushes').click(function(){
if (confirm("Are you sure you want to stop all pushes matching \n\""+push[1]+' to '+push[2]+"\"?"+(push_settings.wait != 0 ? "\n\nRetrying is enabled. You'll probably want to set that to 0." : ''))) {
var $button = $(this);
$button.text('Stopping pushes..');
//also stop the matching pushes
var pushIds = [];
for (var i in d.push_list) {
@ -3914,14 +4184,11 @@ var UI = {
}
mist.send(function(){
$tr.remove();
$button.text('Stop pushes');
checkgone(pushIds);
},{
push_auto_remove:{
stream: push[1],
target: push[2]
},
push_stop: pushIds
push_stop: pushIds,
push_settings: {wait: 0}
});
}
})
@ -4503,7 +4770,7 @@ var UI = {
);
var $tbody = $('<tbody>').css('font-size','0.9em');
$main.append(
$('<table>').append($tbody)
$('<table>').addClass('logs').append($tbody)
);
function color(string){
@ -4529,13 +4796,21 @@ var UI = {
$tbody.html('');
for (var index in logs) {
var $content = $('<span>').addClass('content');
var split = logs[index][2].split('|');
for (var i in split) {
$content.append(
$('<span>').text(split[i])
);
}
$tbody.append(
$('<tr>').html(
$('<td>').text(UI.format.dateTime(logs[index][0],'long')).css('white-space','nowrap')
).append(
$('<td>').html(color(logs[index][1])).css('text-align','center')
).append(
$('<td>').text(logs[index][2]).css('text-align','left')
$('<td>').html($content).css('text-align','left')
)
);
}
@ -4547,7 +4822,9 @@ var UI = {
var $UI = $('<span>').text('Loading..');
$main.append($UI);
var saveas = {};
var saveas = {
graph: 'new'
};
var graphs = (mist.stored.get().graphs ? $.extend(true,{},mist.stored.get().graphs) : {});
var thestreams = {};
@ -4700,6 +4977,7 @@ var UI = {
if (saveas.graph == 'new') {
graph = UI.plot.addGraph(saveas,$graph_c);
graphs[graph.id] = graph;
$UI.find('input.graph_id').val('');
$UI.find('select.graph_ids').append(
$('<option>').text(graph.id)
).val(graph.id).trigger('change');
@ -4962,6 +5240,23 @@ var UI = {
$main.append($('<p>').text('This tab does not exist.'));
break;
}
//focus on first empty field
$main.find('.field').filter(function(){
return $(this).getval() == '';
}).each(function(){
var a = [];
if ($(this).is('input, select, textarea')) {
a.push($(this));
}
else {
a = $(this).find('input, select, textarea');
}
if (a.length) {
$(a[0]).focus();
return false;
}
})
}
};
@ -5280,7 +5575,7 @@ var mist = {
},
validate: []
};
if ((type[j] == 'required') && (!('default' in ele))) {
if ((type[j] == 'required') && ((!('default' in ele)) || (ele['default'] == ''))) {
obj.validate.push('required');
}
if ('default' in ele) {

View file

@ -1,381 +0,0 @@
if (typeof mistplayers == 'undefined') {
//no need to define this if it's already there
var mistplayers = {};
//create prototype with empty functions the player should have, so that any that have not been defined return false
function MistPlayer() {
//return true if this player is to be used for this mimetype
this.formimetype = function (fullmimetype){ return false; };
this.name = 'Generic player';
//mimetype: e.g. 'video/mp4'; that is withouth the html5, flash, or whatever first part.
this.supported = function(mimetype){ return false; };
/*
shape of build options:
{
container: html DOM element,
width: (int) video width,
height: (int) video height,
name: (string) the stream name,
src: (string) the video source string,
mimetype: (string) the mimetype,
islive: (boolean) whether or not this is a live video,
autoplay: (boolean) whether or not to enable autoplay
}
*/
this.build = function(options){ return false; };
//creates the player element, including custom functions
this.element = function(tag){
var ele = document.createElement(tag);
ele.mistplay = function(){ return false; };
ele.mistpause = function(){ return false; };
//(double) value: 0 for muted, 1 for max
ele.mistsetvolume = function(value){ return false; };
//return the current position, in seconds
ele.mistposition = function(){ return false; };
return ele;
};
}
///////////////////////////////////////////////////
//ADD AVAILABLE PLAYERS TO THE MISTPLAYERS OBJECT//
///////////////////////////////////////////////////
////HTML5////////////////////////////////////////////
var html5 = new MistPlayer();
mistplayers.html5 = html5;
html5.name = 'HTML5 video element';
html5.formimetype = function(fullmimetype){
var t = fullmimetype.split('/');
return ((t[0] == 'html5') && (t[1] == 'video'));
};
html5.supported = function(mimetype) {
var support = false;
try {
var v = document.createElement('video');
if ((v) && (v.canPlayType(mimetype) != "")) {
support = v.canPlayType(mimetype);
}
} catch(e){}
return support;
}
html5.build = function(options){
var ele = this.element('video');
ele.setAttribute('width',options.width);
ele.setAttribute('height',options.height);
ele.setAttribute('src',encodeURI(options.src));
ele.setAttribute('controls','controls');
if (options.autoplay) {
ele.setAttribute('autoplay','controls');
}
ele.mistplay = function(){
this.play();
};
ele.mistpause = function(){
this.pause();
};
ele.mistsetvolume = function(value){
this.volume = value;
};
ele.mistposition = function(){
return this.currentTime;
}
options.container.appendChild(ele);
return ele;
}
////FLASH////////////////////////////////////////////
var flash = new MistPlayer();
mistplayers.flash = flash;
flash.name = 'Flash object';
flash.formimetype = function(fullmimetype){
var t = fullmimetype.split('/');
return (t[0] == 'flash');
};
flash.supported = function(mimetype) {
var version = 0;
try {
// check in the mimeTypes
version = navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin.description.replace(/([^0-9\.])/g, '').split('.')[0];
} catch(e){}
try {
// for our special friend IE
version = new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable("$version").replace(/([^0-9\,])/g, '').split(',')[0];
} catch(e){}
version = parseInt(version);
return version >= parseInt(mimetype);
}
flash.build = function(options){
var ele = this.element('object');
ele.setAttribute('id',options.name);
ele.setAttribute('width',options.width);
ele.setAttribute('height',options.height);
//set flashvars
var flashvars = {
src: encodeURIComponent(options.src),
controlBarMode: 'floating',
initialBufferTime: 5,
expandedBufferTime: 5,
minContinuousPlaybackTime: 3
};
//set param elements
var params = {
movie: 'http://fpdownload.adobe.com/strobe/FlashMediaPlayback.swf',
flashvars: [],
allowFullScreen: 'true',
allowscriptaccess: 'always',
wmode: 'direct'
};
if (options.autoplay) {
params.autoPlay = 'true';
flashvars.autoPlay = 'true';
}
if (options.islive) {
flashvars.streamType = 'live';
}
if (parseInt(options.mimetype) >= 10) {
params.movie = 'http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf';
}
for (var i in flashvars) {
params.flashvars.push(i+'='+flashvars[i]);
}
params.flashvars = params.flashvars.join('&');
for (var i in params) {
var param = document.createElement('param');
ele.appendChild(param);
param.setAttribute('name',i);
param.setAttribute('value',params[i]);
}
var embed = document.createElement('embed');
embed.setAttribute('name',options.name);
embed.setAttribute('src',params.movie);
embed.setAttribute('type','application/x-shockwave-flash');
embed.setAttribute('allowscriptaccess','always');
embed.setAttribute('allowfullscreen','true');
embed.setAttribute('width',options.width);
embed.setAttribute('height',options.height);
embed.setAttribute('flashvars',params.flashvars);
ele.appendChild(embed);
options.container.appendChild(ele);
return ele;
}
////SILVERLIGHT//////////////////////////////////////
var silverlight = new MistPlayer();
mistplayers.silverlight = silverlight;
silverlight.name = 'Silverlight';
silverlight.formimetype = function(fullmimetype){
return (fullmimetype == 'silverlight');
};
silverlight.supported = function(mimetype) {
var plugin;
try {
// check in the mimeTypes
plugin = navigator.plugins["Silverlight Plug-In"];
return !!plugin;
} catch(e){}
try {
// for our special friend IE
plugin = new ActiveXObject('AgControl.AgControl');
return true;
} catch(e){}
return false;
}
silverlight.build = function(options){
var ele = this.element('object');
ele.setAttribute('data','data:application/x-silverlight,'); //yes that comma needs to be there
ele.setAttribute('type','application/x-silverlight');
ele.setAttribute('width',options.width);
ele.setAttribute('height',options.height);
var params = {
source: encodeURI(options.src),
onerror: 'onSilverlightError',
autoUpgrade: 'true',
background: 'black',
enableHtmlAccess: 'true',
minRuntimeVersion: '3.0.40624.0',
initparams: []
};
var initparams = {
autoload: 'false',
enablecaptions: 'true',
joinLive: 'true',
muted: 'false',
playlist: document.createElement('playList')
};
if (options.autoplay) {
initparams.autoplay = 'true';
}
var playitems = document.createElement('playListItems');
initparams.playlist.appendChild(playitems);
var playitem = document.createElement('playListItem');
playitems.appendChild(playitem);
playitems.setAttribute('mediaSource',encodeURI(options.src));
playitems.setAttribute('adaptiveStreaming','true');
initparams.playlist = initparams.playlist.outerHTML;
for (var i in initparams) {
params.initparams.push(i+'='+initparams[i]);
}
params.initparams = params.initparams.join(',');
for (var i in params) {
var param = document.createElement('param');
ele.appendChild(param);
param.setAttribute('name',i);
param.setAttribute('value',params[i]);
}
ele.innerHTML += '<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none" /></a>';
options.container.appendChild(ele);
return ele;
}
} //end of player definitions
function mistembed(streamname) {
function findPlayer(fullmimetype) {
for (var i in mistplayers) {
if (mistplayers[i].formimetype(fullmimetype)) {
return mistplayers[i];
}
}
return false;
}
var video = mistvideo[streamname];
container = document.createElement('div'),
scripts = document.getElementsByTagName('script'),
me = scripts[scripts.length - 1];
if (me.parentNode.hasAttribute('data-forcetype')) {
var forceType = me.parentNode.getAttribute('data-forcetype');
}
if (me.parentNode.hasAttribute('data-forcesupportcheck')) {
var forceSupportCheck = true;
}
if (me.parentNode.hasAttribute('data-autoplay')) {
var autoplay = true;
}
// create the container
me.parentNode.insertBefore(container, me);
// set the class to 'mistvideo'
container.setAttribute('class', 'mistvideo');
// remove script tag
me.parentNode.removeChild(me);
if(video.error) {
// there was an error; display it
container.innerHTML = '<strong>Error: '+video.error+'</strong>';
}
else if ((typeof video.source == 'undefined') || (video.source.length < 1)) {
// no stream sources
container.innerHTML = '<strong>Error: no protocols found</strong>';
}
else {
// no error, and sources found. Check the video types and output the best
// available video player.
var foundPlayer = false;
for (var i in video.source) {
if ((forceType) && (video.source[i].type.indexOf(forceType) < 0)) {
video.source[i].rejected = 'This source type is not the one being forced.';
continue;
}
var player = findPlayer(video.source[i].type);
var shortmime = video.source[i].type.split('/');
shortmime.shift();
shortmime = shortmime.join('/');
video.source[i].browser_support = false;
if (player) {
var support = player.supported(shortmime);
if ((support) || (forceType)) {
//either the player is supported by the browser, or this source type is being enforced
video.source[i].browser_support = Boolean(support);
if (foundPlayer === false) {
foundPlayer = {
protocol: video.source[i],
player: player,
shortmime: shortmime
};
}
if (!forceSupportCheck) {
break;
}
}
else {
video.source[i].rejected = 'The player for this source type ('+player.name+') is not supported by your browser.';
}
}
else {
video.source[i].rejected = 'No compatible player found for this source type.';
}
}
}
if (foundPlayer) {
// we support this kind of video, so build it.
//calculations for the size
videowidth = video.width || 250;
videoheight = video.height || 250;
var ratio;
var containerwidth = parseInt(container.scrollWidth);
var containerheight = parseInt(container.scrollHeight);
if(videowidth > containerwidth && containerwidth > 0) {
ratio = videowidth / containerwidth;
videowidth /= ratio;
videoheight /= ratio;
}
if(videoheight > containerheight && containerheight > 0) {
ratio = videoheight / containerheight;
videowidth /= ratio;
videoheight /= ratio;
}
video.embedded = foundPlayer.player.build({
container: container,
width: videowidth,
height: videoheight,
src: foundPlayer.protocol.url,
name: streamname,
mimetype: foundPlayer.shortmime,
islive: (video.type == 'live'),
autoplay: autoplay
});
return foundPlayer.protocol.type;
}
else {
// of all the source types given, none was supported (eg. no flash and HTML5 video). Display error
container.innerHTML = '<strong>No support for any player found</strong>';
}
return false;
}

View file

@ -1,139 +0,0 @@
<html>
<head>
<title></title>
<meta content="">
<style>
#vidcontainer {
display: flex;
flex-flow: row wrap;
justify-content: space-around;
}
#vidcontainer .track {
overflow: hidden;
display: flex;
flex-flow: column nowrap;
align-items: center;
}
#vidcontainer .track .trackname {
flex-shrink: 0;
display: none; /* comment this to show trackname */
}
</style>
</head>
<body>
<div id=vidcontainer>
</div>
<script>
var vidname = 'multibitrate'; // change this to the appropriate stream name
var embedbase = 'http://localhost:8080/'; //change this to the appropriate host (with http port)
//load the info script
var script = document.createElement('script');
script.src = embedbase+'info_'+vidname+'.js';
script.onerror = function(){
document.getElementById('vidcontainer').innerHTML = 'Error loading "'+script.src+'".';
};
script.onload = function(){
multitrack(vidname);
}
document.getElementById('vidcontainer').appendChild(script);
function multitrack(vidname) {
if (typeof mistvideo[vidname] != 'undefined') {
var vid = mistvideo[vidname];
var audio = false;
vid.elements = [];
if (typeof vid.meta.tracks != 'undefined') {
var cont = document.getElementById('vidcontainer');
var n = 0;
var width = cont.offsetWidth * .49;
for (var i in vid.meta.tracks) {
var track = vid.meta.tracks[i];
n++;
if (track.type != 'video') {
continue;
}
var child = document.createElement('div');
child.className = 'track';
child.innerHTML = '<span class=trackname>'+i+'</span>';
var sources = [];
var rtmp = '';
for (var j in vid.source) {
if (vid.source[j].type == 'flash/10') {
rtmp = vid.source[j].url+'?video='+n+'&audio='+(audio ? '0' : '-1');
}
else {
sources.push('<source src="'+vid.source[j].url+'?video='+n+'&audio='+(audio ? '0' : '-1')+'">');
}
}
//check html mp4 support
var support = false;
/*try {
var v = document.createElement('video');
if( v && v.canPlayType('video/mp4') != "" ){
support = true;
}
} catch(e){}*/
var height = width / track.width * track.height;
if (support) {
//HTML5 MP4 embed
var video = document.createElement('video');
video.setAttribute('style','width:'+width+'px; height:'+height+'px;');
if (!audio) {
video.setAttribute('controls','');
video.addEventListener('play',function(){
for (var i in vid.elements) {
if (vid.elements[i].paused) {
vid.elements[i].play();
}
}
});
video.addEventListener('pause',function(){
for (var i in vid.elements) {
if (!vid.elements[i].paused) {
vid.elements[i].pause();
}
}
});
audio = true;
}
else {
//just in case..
video.volume = 0;
}
video.innerHTML = sources.join('');
}
else {
//go for RTMP (Flash/10) instead
var video = document.createElement('object');
video.setAttribute('width',width);
video.setAttribute('height',height);
var url = encodeURIComponent(rtmp)+'&controlBarMode=floating&initialBufferTime=0.5&expandedBufferTime=5&autoPlay=true&minContinuousPlaybackTime=3' + (vid.type == 'live' ? "&streamType=live" : "");
var params = [];
params.push('<param name="movie" value="http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf"></param>');
params.push('<param name="flashvars" value="src='+url+'"></param>');
params.push('<param name="allowFullScreen" value="true"></param>');
params.push('<param name="allowscriptaccess" value="always"></param>');
params.push('<param name="wmode" value="direct"></param>');
params.push('<param name="autoPlay" value="true">');
params.push('<embed src="http://fpdownload.adobe.com/strobe/FlashMediaPlayback_101.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'" flashvars="src='+url+'"></embed>');
video.innerHTML = params.join('');
}
child.appendChild(video);
vid.elements.push(video);
cont.appendChild(child);
}
}
}
};
</script>
</body>
</html>

View file

@ -1,49 +0,0 @@
<html>
<head>
<title>Test the stream embedding</title>
<style></style>
<script src=plugins/jquery.js></script>
<!--<script src='../src/embed.js'></script>-->
<script src='newembed.js'></script>
<script>
var embed_settings = {};
$(function(){
$('button#embed').click(function(){
$('#embedcontainer, #button_container').html('');
var streamName = $('input[name=streamName]').val();
var embedtype = $('input[name=force]').val();
var info = document.createElement('script');
info.src = 'http://localhost:8080/info_'+streamName+'.js';
document.getElementById('embedcontainer').appendChild(info);
info.onload = function(){
if (embedtype == '') {
$('#embedcontainer').removeAttr('data-forcetype');
}
else {
$('#embedcontainer').attr('data-forcetype',embedtype);
}
$('#embedcontainer').append(
$('<div>').text('Embedded: '+mistembed(streamName))
);
console.log(mistvideo[streamName]);
};
});
});
</script>
</head>
<body>
<label>
Enter the streamname: <input type=text value=bunny name=streamName>
</label><br>
<label>
Force embed type: <input type=text name=force> (blank for auto)
</label><br>
<button id=embed>Embed</button>
<div id=button_container></div>
<div id=embedcontainer style="width: 100%; height: 35em;" data-forcesupportcheck data-autoplay>
</div>
</body>
</html>

View file

@ -1,48 +0,0 @@
<html>
<head>
<title>Test the stream embedding</title>
<style></style>
<script src=plugins/jquery.js></script>
<script src='../src/embed.js?video=0'></script>
<script>
var embed_settings = {};
$(function(){
$('button#embed').click(function(){
$('#embedcontainer, #button_container').html('');
var streamName = $('input[name=streamName]').val();
var embedtype = $('input[name=force]').val();
var info = document.createElement('script');
info.src = 'http://'+(window.location.hostname == '' ? 'localhost' : window.location.hostname)+':8080/info_'+encodeURIComponent(streamName)+'.js';
document.getElementById('embedcontainer').appendChild(info);
info.onload = function(){
if (embedtype == '') {
$('#embedcontainer').removeAttr('data-forcetype');
}
else {
$('#embedcontainer').attr('data-forcetype',embedtype);
}
$('#embedcontainer').append(
$('<div>').text('Embedded: '+mistembed(streamName))
);
console.log(mistvideo[streamName]);
};
});
});
</script>
</head>
<body>
<label>
Enter the streamname: <input type=text value=bunny name=streamName>
</label><br>
<label>
Force embed type: <input type=text name=force> (blank for auto)
</label><br>
<button id=embed>Embed</button>
<div id=button_container></div>
<div id=embedcontainer style="width: 100%; height: 35em;" data-forcesupportcheck data-autoplay>
</div>
</body>
</html>

View file

@ -377,14 +377,14 @@ namespace Mist{
break;
}
}
}
if (!found){
jsonForEach(*itb, itc){
for (std::map<unsigned int, DTSC::Track>::iterator trit = myMeta.tracks.begin(); trit != myMeta.tracks.end(); trit++){
if (trit->second.codec == (*itc).asStringRef() || (*itc).asStringRef() == "*"){
genCounter++;
found = true;
if ((*itc).asStringRef() != "*"){
break;
}
if ((*itc).asStringRef() != "*"){break;}
}
}
}
@ -411,23 +411,21 @@ namespace Mist{
if ((*itb).size() && myMeta.tracks.size()){
bool found = false;
jsonForEach((*itb), itc){
if (found){
break;
}
for (std::set<unsigned long>::iterator itd = selectedTracks.begin(); itd != selectedTracks.end(); itd++){
if (myMeta.tracks[*itd].codec == (*itc).asStringRef()){
found = true;
break;
}
}
}
if (!found){
jsonForEach((*itb), itc){
if (found){break;}
for (std::map<unsigned int, DTSC::Track>::iterator trit = myMeta.tracks.begin(); trit != myMeta.tracks.end(); trit++){
if (trit->second.codec == (*itc).asStringRef() || (*itc).asStringRef() == "*"){
selectedTracks.insert(trit->first);
found = true;
if ((*itc).asStringRef() != "*"){
break;
}
if ((*itc).asStringRef() != "*"){break;}
}
}
}

View file

@ -422,7 +422,6 @@ namespace Mist {
}
}
H.Clean();
H.SetHeader("Content-Type", "video/mp2t");
H.setCORSHeaders();
if(method == "OPTIONS" || method == "HEAD"){