LSP: Edit stream: settings that aren't compatible with the input are now sanitized before submitting

This commit is contained in:
Thulinma 2023-12-14 09:51:39 +01:00
parent 1873e0ea38
commit a3521a992d
2 changed files with 101 additions and 79 deletions

View file

@ -1,10 +1,10 @@
var MD5=function(a){function b(a,b){var c,d,g,f,e;g=a&2147483648;f=b&2147483648;c=a&1073741824;d=b&1073741824;e=(a&1073741823)+(b&1073741823);return c&d?e^2147483648^g^f:c|d?e&1073741824?e^3221225472^g^f:e^1073741824^g^f:e^g^f}function c(a,c,d,g,f,e,h){a=b(a,b(b(c&d|~c&g,f),h));return b(a<<e|a>>>32-e,c)}function d(a,c,d,g,f,e,h){a=b(a,b(b(c&g|d&~g,f),h));return b(a<<e|a>>>32-e,c)}function e(a,c,d,g,f,e,h){a=b(a,b(b(c^d^g,f),h));return b(a<<e|a>>>32-e,c)}function j(a,c,d,g,f,e,h){a=b(a,b(b(d^(c|~g),
f),h));return b(a<<e|a>>>32-e,c)}function m(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=[],t,o,l,x,i,g,f,k,h=a.replace(/\r\n/g,"\n"),a="";for(t=0;t<h.length;t++)o=h.charCodeAt(t),128>o?a+=String.fromCharCode(o):(127<o&&2048>o?a+=String.fromCharCode(o>>6|192):(a+=String.fromCharCode(o>>12|224),a+=String.fromCharCode(o>>6&63|128)),a+=String.fromCharCode(o&63|128));h=a;a=h.length;t=a+8;o=16*((t-t%64)/64+1);l=Array(o-1);for(i=x=0;i<a;)t=
(i-i%4)/4,x=8*(i%4),l[t]|=h.charCodeAt(i)<<x,i++;t=(i-i%4)/4;l[t]|=128<<8*(i%4);l[o-2]=a<<3;l[o-1]=a>>>29;h=l;i=1732584193;g=4023233417;f=2562383102;k=271733878;for(a=0;a<h.length;a+=16)t=i,o=g,l=f,x=k,i=c(i,g,f,k,h[a+0],7,3614090360),k=c(k,i,g,f,h[a+1],12,3905402710),f=c(f,k,i,g,h[a+2],17,606105819),g=c(g,f,k,i,h[a+3],22,3250441966),i=c(i,g,f,k,h[a+4],7,4118548399),k=c(k,i,g,f,h[a+5],12,1200080426),f=c(f,k,i,g,h[a+6],17,2821735955),g=c(g,f,k,i,h[a+7],22,4249261313),i=c(i,g,f,k,h[a+8],7,1770035416),
f),h));return b(a<<e|a>>>32-e,c)}function m(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=[],t,p,l,x,i,g,f,k,h=a.replace(/\r\n/g,"\n"),a="";for(t=0;t<h.length;t++)p=h.charCodeAt(t),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;t=a+8;p=16*((t-t%64)/64+1);l=Array(p-1);for(i=x=0;i<a;)t=
(i-i%4)/4,x=8*(i%4),l[t]|=h.charCodeAt(i)<<x,i++;t=(i-i%4)/4;l[t]|=128<<8*(i%4);l[p-2]=a<<3;l[p-1]=a>>>29;h=l;i=1732584193;g=4023233417;f=2562383102;k=271733878;for(a=0;a<h.length;a+=16)t=i,p=g,l=f,x=k,i=c(i,g,f,k,h[a+0],7,3614090360),k=c(k,i,g,f,h[a+1],12,3905402710),f=c(f,k,i,g,h[a+2],17,606105819),g=c(g,f,k,i,h[a+3],22,3250441966),i=c(i,g,f,k,h[a+4],7,4118548399),k=c(k,i,g,f,h[a+5],12,1200080426),f=c(f,k,i,g,h[a+6],17,2821735955),g=c(g,f,k,i,h[a+7],22,4249261313),i=c(i,g,f,k,h[a+8],7,1770035416),
k=c(k,i,g,f,h[a+9],12,2336552879),f=c(f,k,i,g,h[a+10],17,4294925233),g=c(g,f,k,i,h[a+11],22,2304563134),i=c(i,g,f,k,h[a+12],7,1804603682),k=c(k,i,g,f,h[a+13],12,4254626195),f=c(f,k,i,g,h[a+14],17,2792965006),g=c(g,f,k,i,h[a+15],22,1236535329),i=d(i,g,f,k,h[a+1],5,4129170786),k=d(k,i,g,f,h[a+6],9,3225465664),f=d(f,k,i,g,h[a+11],14,643717713),g=d(g,f,k,i,h[a+0],20,3921069994),i=d(i,g,f,k,h[a+5],5,3593408605),k=d(k,i,g,f,h[a+10],9,38016083),f=d(f,k,i,g,h[a+15],14,3634488961),g=d(g,f,k,i,h[a+4],20,3889429448),
i=d(i,g,f,k,h[a+9],5,568446438),k=d(k,i,g,f,h[a+14],9,3275163606),f=d(f,k,i,g,h[a+3],14,4107603335),g=d(g,f,k,i,h[a+8],20,1163531501),i=d(i,g,f,k,h[a+13],5,2850285829),k=d(k,i,g,f,h[a+2],9,4243563512),f=d(f,k,i,g,h[a+7],14,1735328473),g=d(g,f,k,i,h[a+12],20,2368359562),i=e(i,g,f,k,h[a+5],4,4294588738),k=e(k,i,g,f,h[a+8],11,2272392833),f=e(f,k,i,g,h[a+11],16,1839030562),g=e(g,f,k,i,h[a+14],23,4259657740),i=e(i,g,f,k,h[a+1],4,2763975236),k=e(k,i,g,f,h[a+4],11,1272893353),f=e(f,k,i,g,h[a+7],16,4139469664),
g=e(g,f,k,i,h[a+10],23,3200236656),i=e(i,g,f,k,h[a+13],4,681279174),k=e(k,i,g,f,h[a+0],11,3936430074),f=e(f,k,i,g,h[a+3],16,3572445317),g=e(g,f,k,i,h[a+6],23,76029189),i=e(i,g,f,k,h[a+9],4,3654602809),k=e(k,i,g,f,h[a+12],11,3873151461),f=e(f,k,i,g,h[a+15],16,530742520),g=e(g,f,k,i,h[a+2],23,3299628645),i=j(i,g,f,k,h[a+0],6,4096336452),k=j(k,i,g,f,h[a+7],10,1126891415),f=j(f,k,i,g,h[a+14],15,2878612391),g=j(g,f,k,i,h[a+5],21,4237533241),i=j(i,g,f,k,h[a+12],6,1700485571),k=j(k,i,g,f,h[a+3],10,2399980690),
f=j(f,k,i,g,h[a+10],15,4293915773),g=j(g,f,k,i,h[a+1],21,2240044497),i=j(i,g,f,k,h[a+8],6,1873313359),k=j(k,i,g,f,h[a+15],10,4264355552),f=j(f,k,i,g,h[a+6],15,2734768916),g=j(g,f,k,i,h[a+13],21,1309151649),i=j(i,g,f,k,h[a+4],6,4149444226),k=j(k,i,g,f,h[a+11],10,3174756917),f=j(f,k,i,g,h[a+2],15,718787259),g=j(g,f,k,i,h[a+9],21,3951481745),i=b(i,t),g=b(g,o),f=b(f,l),k=b(k,x);return(m(i)+m(g)+m(f)+m(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==t)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=
f=j(f,k,i,g,h[a+10],15,4293915773),g=j(g,f,k,i,h[a+1],21,2240044497),i=j(i,g,f,k,h[a+8],6,1873313359),k=j(k,i,g,f,h[a+15],10,4264355552),f=j(f,k,i,g,h[a+6],15,2734768916),g=j(g,f,k,i,h[a+13],21,1309151649),i=j(i,g,f,k,h[a+4],6,4149444226),k=j(k,i,g,f,h[a+11],10,3174756917),f=j(f,k,i,g,h[a+2],15,718787259),g=j(g,f,k,i,h[a+9],21,3951481745),i=b(i,t),g=b(g,p),f=b(f,l),k=b(k,x);return(m(i)+m(g)+m(f)+m(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==t)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"),j=e.children("tr"),m=c.attr("data-sort-type");if(m){var h=!0;c.hasClass("sorting-asc")&&(h=!1);var t=0;c.prevAll().each(function(){var b=a(this).attr("colspan");t+=b?Number(b):1});j.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(j);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=
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 MistVideoObject={},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.");
@ -29,11 +29,11 @@ b.append(e),d.buttons){var m=d.buttons[j],h=$("<button>").text(m.label).data("op
!0))return!1});(a=$(this).data("opts").failedValidate)&&a.call(this);c||(b.find('.isSetting:visible, input[type="hidden"].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 b.main[b.index]=null,!0;b.main[b.index]=a;(a=$(this).data("opts").postSave)&&a.call(this)}),(a=$(this).data("opts")["function"])&&a(this))});break;default:h.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+":":""));if("classes"in d)for(t in d.classes)m.addClass(d.classes[t]);h=$("<span>").addClass("field_container");m.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.max);"step"in d&&e.attr("step",d.step);"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(j in d.select){var o=$("<option>");"string"==typeof d.select[j]?o.text(d.select[j]):o.val(d.select[j][0]).text(d.select[j][1]);e.append(o)}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);d.readonly&&l.prop("disabled",!0);o=
$("<label>").append(l).append($("<span>").html(d.radioselect[c][1]));e.append(o);if(2<d.radioselect[c].length)for(j in l=$("<select>").change(function(){$(this).parent().find("input[type=radio]:enabled").prop("checked","true")}),o.append(l),d.readonly&&l.prop("disabled",!0),d.radioselect[c][2])o=$("<option>"),l.append(o),d.radioselect[c][2][j]instanceof Array?o.val(d.radioselect[c][2][j][0]).html(d.radioselect[c][2][j][1]):o.html(d.radioselect[c][2][j])}break;case "checklist":e=$("<div>").addClass("checkcontainer");
[8,"8 - Report everything in extreme detail"],[9,"9 - Report everything in insane detail"],[10,"10 - All messages enabled"]];case "select":e=$("<select>");for(j in d.select){var p=$("<option>");"string"==typeof d.select[j]?p.text(d.select[j]):p.val(d.select[j][0]).text(d.select[j][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);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(j in l=$("<select>").change(function(){$(this).parent().find("input[type=radio]:enabled").prop("checked","true")}),p.append(l),d.readonly&&l.prop("disabled",!0),d.radioselect[c][2])p=$("<option>"),l.append(p),d.radioselect[c][2][j]instanceof Array?p.val(d.radioselect[c][2][j][0]).html(d.radioselect[c][2][j][1]):p.html(d.radioselect[c][2][j])}break;case "checklist":e=$("<div>").addClass("checkcontainer");
$controls=$("<div>").addClass("controls");$checklist=$("<div>").addClass("checklist");e.append($checklist);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;case "unix":e=$("<input>").attr("type","datetime-local").attr("step",1);d.unit=$("<button>").text("Now").click(function(){$(this).closest(".field_container").find(".field").setval((new Date).getTime()/
1E3)});break;case "selectinput":e=$("<div>").addClass("selectinput");l=$("<select>");e.append(l);l.data("input",!1);for(c in d.selectinput)o=$("<option>"),l.append(o),"string"==typeof d.selectinput[c]?o.text(d.selectinput[c]):(o.text(d.selectinput[c][1]),"string"==typeof d.selectinput[c][0]?o.val(d.selectinput[c][0]):(o.val("CUSTOM"),l.data("input")||l.data("input",UI.buildUI([d.selectinput[c][0]]).children())));l.data("input")&&e.append(l.data("input"));l.change(function(){"CUSTOM"==$(this).val()?
1E3)});break;case "selectinput":e=$("<div>").addClass("selectinput");l=$("<select>");e.append(l);l.data("input",!1);for(c in d.selectinput)p=$("<option>"),l.append(p),"string"==typeof d.selectinput[c]?p.text(d.selectinput[c]):(p.text(d.selectinput[c][1]),"string"==typeof d.selectinput[c][0]?p.val(d.selectinput[c][0]):(p.val("CUSTOM"),l.data("input")||l.data("input",UI.buildUI([d.selectinput[c][0]]).children())));l.data("input")&&e.append(l.data("input"));l.change(function(){"CUSTOM"==$(this).val()?
$(this).data("input").css("display","flex"):$(this).data("input").hide()});l.trigger("change");break;case "inputlist":e=$("<div>").addClass("inputlist");e.data("newitem",function(){var a;if("input"in d)a=UI.buildUI([d.input]).find(".field_container");else{var b=Object.assign({},d);delete b.validate;delete b.pointer;b.type="str";a=UI.buildUI([b]).find(".field_container")}a.removeClass("isSetting");a.addClass("listitem");var c=function(b){$(this).is(":last-child")?""!=$(this).find(".field").getval()?
(b=a.clone().keyup(c),b.find(".field").setval(""),$(this).after(b)):8==b.which&&$(this).prev().find(".field").focus():""==$(this).find(".field").getval()&&(b=$(this).prev(),b.length||(b=$(this).next()),b.find(".field").focus(),$(this).remove())};a.keyup(c);return a});e.append(e.data("newitem"));break;case "sublist":e=$("<div>").addClass("sublist");l=$("<div>").addClass("curvals");l.append($("<span>").text("None."));var x=$("<div>").addClass("itemsettings"),i=$("<button>").text("New "+d.itemLabel),
g=d.sublist,f=d,k=e,r=m;e.data("build",function(a,b){for(var c in f.saveas)c in a||delete f.saveas[c];f.saveas=Object.assign(f.saveas,a);c="New";"undefined"!=typeof b&&(c="Edit");c=UI.buildUI([$("<h4>").text(c+" "+f.itemLabel)].concat(g).concat([{label:"Save first",type:"str",classes:["onlyshowhelp"],validate:[function(){return{msg:"Did you want to save this "+f.itemLabel+"?",classes:["red"]}}]},{type:"buttons",buttons:[{label:"Cancel",type:"cancel","function":function(){x.html("");i.show();r.show()}},
@ -44,7 +44,7 @@ g.unshift({type:"str",label:"Human readable name",placeholder:"none",help:"A con
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 g=$(this);setTimeout(function(){g.text("Copy")},5E3)}else{document.body.removeChild(b);
alert("Failed to copy:\n"+a)}})));"rows"in d&&e.attr("rows",d.rows);if("dependent"in d)for(c in d.dependent)m.attr("data-dependent-"+c,d.dependent[c]);switch(d.type){case "browse":l=$("<div>").addClass("grouper").append(m);b.append(l);l=$("<button>").text("Browse").on("keydown",function(a){a.stopPropagation()});h.append(l);l.click(function(){function a(b){h.text("Loading..");mist.send(function(a){e.text(a.browse.path[0]);mist.data.LTS&&d.setval(a.browse.path[0]+"/");h.html(i.clone(true).text("..").attr("title",
"Folder up"));if(a.browse.subdirectories){a.browse.subdirectories.sort();for(var b in a.browse.subdirectories){var f=a.browse.subdirectories[b];h.append(i.clone(true).attr("title",e.text()+m+f).text(f))}}if(a.browse.files){a.browse.files.sort();for(b in a.browse.files){var f=a.browse.files[b],l=e.text()+m+f,f=$("<a>").text(f).addClass("file").attr("title",l);h.append(f);if(k){var j=true,r;for(r in k)if(typeof k[r]!="undefined"&&mist.inputMatch(k[r],l)){j=false;break}j&&f.hide()}f.click(function(){var a=
"Folder up"));if(a.browse.subdirectories){a.browse.subdirectories.sort();for(var b in a.browse.subdirectories){var f=a.browse.subdirectories[b];h.append(i.clone(true).attr("title",e.text()+m+f).text(f))}}if(a.browse.files){a.browse.files.sort();for(b in a.browse.files){var f=a.browse.files[b],l=e.text()+m+f,f=$("<a>").text(f).addClass("file").attr("title",l);h.append(f);if(k){var j=true,n;for(n in k)if(typeof k[n]!="undefined"&&mist.inputMatch(k[n],l)){j=false;break}j&&f.hide()}f.click(function(){var a=
$(this).attr("title");d.setval(a).removeAttr("readonly").css("opacity",1);g.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),g=$(this),f=$("<button>").text("Stop browsing").click(function(){g.show();c.remove();d.removeAttr("readonly").css("opacity",1)}),e=$("<span>").addClass("field"),h=$("<div>").addClass("browse_contents"),i=$("<a>").addClass("folder"),k=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(f))).append(h);var m="/";mist.data.config.version.indexOf("indows")>-1&&(m="\\");i.click(function(){var b=e.text()+m+$(this).text();a(b)});b=d.getval();f=b.split("://");f.length>1&&(b=f[0]=="file"?f[1]:"");b=b.split(m);b.pop();b=b.join(m);g.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",
@ -60,11 +60,11 @@ for(var h in e.classes)$err.addClass(e.classes[h]);g.prepend($err);b&&$(a).focus
b.length&&(b.trigger("click"),a.stopPropagation())});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 j in a.content)for(e in c.append($("<td>").html(a.content[j].header)),a.content[j].body)d[e].append($("<td>").html(a.content[j].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":case "perc_lost":case "perc_retrans":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=[],o;for(o in c.datasets){var l=c.datasets[o];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,
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 x=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 h in c.datasets){var i="&nbsp;";if(c.datasets[h].display){var e=UI.plot.yaxes[c.datasets[h].yaxistype].tickFormatter,
l=c.datasets[h].data;if(a)for(var j in l){if(l[j][0]==a){i=e(l[j][1]);break}if(l[j][0]>a){if(j!=0){i=l[j];l=l[j-1];i=e(i[1]+(a-i[0])*(l[1]-i[1])/(l[0]-i[0]))}break}}else i=e(c.datasets[h].data[c.datasets[h].data.length-1][1])}b.eq(d).html(i);d++}};c.plot.getOptions();for(o in c.datasets)e=$("<input>").attr("type","checkbox").data("index",o).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[o].display&&e.attr("checked","checked"),d.append($("<tr>").html($("<td>").html($("<label>").html(e).append($("<div>").addClass("series-color").css("background-color",c.datasets[o].color)).append(c.datasets[o].label))).append($("<td>").css("padding-right","2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").text("X").addClass("close").data("index",o).data("graph",c).click(function(){var b=$(this).data("index"),
l=c.datasets[h].data;if(a)for(var j in l){if(l[j][0]==a){i=e(l[j][1]);break}if(l[j][0]>a){if(j!=0){i=l[j];l=l[j-1];i=e(i[1]+(a-i[0])*(l[1]-i[1])/(l[0]-i[0]))}break}}else i=e(c.datasets[h].data[c.datasets[h].data.length-1][1])}b.eq(d).html(i);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)}}}))));x();var i=!1;c.elements.plot.on("plothover",function(a,b,c){if(b.x!=i){x(b.x);i=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(){x()})}}},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;
@ -88,14 +88,14 @@ return false}],help:"Enter your desired password. In the future, you will need t
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":if("undefined"==typeof mist.data.bandwidth){mist.send(function(){UI.navto(a)},{bandwidth:!0});c.append("Loading..");return}var e=$("<span>").text("Loading.."),j=$("<span>"),m=$("<span>").addClass("logs"),
h=$("<span>"),t=$("<span>"),o=$("<span>").text("Unknown"),l=$("<span>"),x=$("<span>"),i=parseURL(mist.user.host),i=i.protocol+i.host+i.port,g={};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},{type:"span",
label:"Server time",value:t},{type:"span",label:"Licensed to",value:"license"in mist.data.config?mist.data.config.license.user:""},{type:"span",label:"Active licenses",value:o},{type:"span",label:"Configured streams",value:mist.data.streams?Object.keys(mist.data.streams).length:0},{type:"span",label:"Active streams",value:j},{type:"span",label:"Current connections",value:h},{type:"span",label:"Enabled protocols",value:l},{type:"span",label:"Disabled protocols",value:x},{type:"span",label:"Recent problems",
h=$("<span>"),t=$("<span>"),p=$("<span>").text("Unknown"),l=$("<span>"),x=$("<span>"),i=parseURL(mist.user.host),i=i.protocol+i.host+i.port,g={};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},{type:"span",
label:"Server time",value:t},{type:"span",label:"Licensed to",value:"license"in mist.data.config?mist.data.config.license.user:""},{type:"span",label:"Active licenses",value:p},{type:"span",label:"Configured streams",value:mist.data.streams?Object.keys(mist.data.streams).length:0},{type:"span",label:"Active streams",value:j},{type:"span",label:"Current connections",value:h},{type:"span",label:"Enabled protocols",value:l},{type:"span",label:"Disabled protocols",value:x},{type:"span",label:"Recent problems",
value:m},$("<br>"),$("<h3>").text("Write config now"),{type:"help",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:"checkbox",label:"Force configurations save",pointer:{main:g,index:"save"}},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};if(g.save)a.save=g.save;delete g.save;mist.send(function(){UI.navto("Overview")},
a)}}]}]));if(mist.data.LTS){var f=function(a){function b(a){if(a.update){var d="";"progress"in a.update&&(d=" ("+a.update.progress+"%)");e.text("Updating.."+d);c(a.log);setTimeout(function(){mist.send(function(a){b(a)},{update:true})},1E3)}else UI.showTab("Overview")}function c(a){a=a.filter(function(a){return a[1]=="UPDR"});if(a.length){var b=$("<div>");e.append(b);for(var d in a)b.append($("<div>").text(a[d][2]))}}if(!a.update||!("uptodate"in a.update)){e.text("Unknown, checking..");setTimeout(function(){mist.send(function(a){"update"in
a&&f(a)},{checkupdate:true})},5E3)}else if(a.update.error)e.addClass("red").text(a.update.error);else if(a.update.uptodate)e.text("Your version is up to date.").addClass("green");else{if(a.update.progress){e.addClass("orange").removeClass("red").text("Updating..");b(a)}else{e.text("");e.append($("<span>").addClass("red").text("On "+(new Date(a.update.date)).toLocaleDateString()+" version "+a.update.version+" became available."));(!a.update.url||a.update.url.slice(-4)!=".zip")&&e.append($("<button>").text("Rolling 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.send(function(a){b(a)},{autoupdate:true})}}));var d=$("<a>").attr("href",a.update.url).attr("target","_blank").text("Manual download");d[0].protocol="https:";e.append($("<div>").append(d))}c(a.log)}};f(mist.data);if("license"in mist.data.config){if("active_products"in mist.data.config.license&&Object.keys(mist.data.config.license.active_products).length){var k=
$("<table>").css("text-indent","0");o.html(k);k.append($("<tr>").append($("<th>").append("Product")).append($("<th>").append("Updates until")).append($("<th>").append("Use until")).append($("<th>").append("Max. simul. instances")));for(var r in mist.data.config.license.active_products){var G=mist.data.config.license.active_products[r];k.append($("<tr>").append($("<td>").append(G.name)).append($("<td>").append(G.updates_final?G.updates_final:"&infin;")).append($("<td>").append(G.use_final?G.use_final:
"&infin;")).append($("<td>").append(G.amount?G.amount:"&infin;")))}}else o.text("None. ");o.append($("<a>").text("More details").attr("href","https://shop.mistserver.org/myinvoices").attr("target","_blank"))}}else e.text("");var Da=function(){var a={totals:{fields:["clients"],start:-10},active_streams:true};if(!("cabailities"in mist.data))a.capabilities=true;mist.send(function(){Ea()},a)},Ea=function(){j.text("active_streams"in mist.data?mist.data.active_streams?mist.data.active_streams.length:0:
$("<table>").css("text-indent","0");p.html(k);k.append($("<tr>").append($("<th>").append("Product")).append($("<th>").append("Updates until")).append($("<th>").append("Use until")).append($("<th>").append("Max. simul. instances")));for(var r in mist.data.config.license.active_products){var G=mist.data.config.license.active_products[r];k.append($("<tr>").append($("<td>").append(G.name)).append($("<td>").append(G.updates_final?G.updates_final:"&infin;")).append($("<td>").append(G.use_final?G.use_final:
"&infin;")).append($("<td>").append(G.amount?G.amount:"&infin;")))}}else p.text("None. ");p.append($("<a>").text("More details").attr("href","https://shop.mistserver.org/myinvoices").attr("target","_blank"))}}else e.text("");var Da=function(){var a={totals:{fields:["clients"],start:-10},active_streams:true};if(!("cabailities"in mist.data))a.capabilities=true;mist.send(function(){Ea()},a)},Ea=function(){j.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..";h.text(a);t.text(UI.format.dateTime(mist.data.config.time,"long"));m.html("");a=0;"license"in mist.data.config&&"user_msg"in mist.data.config.license&&mist.data.log.unshift([mist.data.config.license.time,"ERROR",mist.data.config.license.user_msg]);for(var 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"),e=c[2].split("|");for(b in e)d.append($("<span>").text(e[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)}l.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);
x.text(c.length?c.join(", "):"None.")}else x.text("Loading..")};Da();Ea();UI.interval.set(Da,3E4);break;case "General":var M={serverid:mist.data.config.serverid,debug:mist.data.config.debug,accesslog:mist.data.config.accesslog,prometheus:mist.data.config.prometheus,defaultStream:mist.data.config.defaultStream,trustedproxy:mist.data.config.trustedproxy},N={sessionViewerMode:mist.data.config.sessionViewerMode,sessionInputMode:mist.data.config.sessionInputMode,sessionOutputMode:mist.data.config.sessionOutputMode,
@ -131,9 +131,9 @@ c=d.length?c+d.join(", "):c+"None.";if(d.length!=a.length){a=a.filter(function(a
"both")).append($("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Protocol")).append($("<th>").text("Status")).append($("<th>").text("Settings")).append($("<th>")))).append(F));var Ha=function(){function a(b){var c=mist.data.capabilities.connectors[b.connector];if(!c)return"";var d=[],e=["required","optional"],w;for(w in e)for(var g in c[e[w]])b[g]&&b[g]!=""?d.push(g+": "+b[g]):c[e[w]][g]["default"]&&d.push(g+": "+c[e[w]][g]["default"]);return $("<span>").addClass("description").text(d.join(", "))}
F.html("");for(var b in mist.data.config.protocols){var c=mist.data.config.protocols[b],d=mist.data.capabilities.connectors[c.connector];F.append($("<tr>").data("index",b).append($("<td>").text(d&&d.friendly?d.friendly: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.send(function(){UI.navto("Protocols")},{deleteprotocol:mist.data.config.protocols[a]});mist.data.config.protocols.splice(a,1)}}))))}};Ha();UI.interval.set(function(){mist.send(function(){Ha()})},1E4);break;case "Edit Protocol":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}z=
!1;""!=b&&0<=b&&(z=!0);var V={};for(r in mist.data.config.protocols)V[mist.data.config.protocols[r].connector]=1;var Ja=function(a){var b=mist.data.capabilities.connectors[a],c=mist.convertBuildOptions(b,p);if(z)var d=$.extend({},p);c.push({type:"hidden",pointer:{main:p,index:"connector"},value:a});c.push({type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};z?a.updateprotocol=[d,p]:a.addprotocol=p;mist.send(function(){UI.navto("Protocols")},a)}},{type:"cancel",label:"Cancel",
!1;""!=b&&0<=b&&(z=!0);var V={};for(r in mist.data.config.protocols)V[mist.data.config.protocols[r].connector]=1;var Ja=function(a){var b=mist.data.capabilities.connectors[a],c=mist.convertBuildOptions(b,n);if(z)var d=$.extend({},n);c.push({type:"hidden",pointer:{main:n,index:"connector"},value:a});c.push({type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};z?a.updateprotocol=[d,n]:a.addprotocol=n;mist.send(function(){UI.navto("Protocols")},a)}},{type:"cancel",label:"Cancel",
"function":function(){UI.navto("Protocols")}}]});if("deps"in b&&b.deps!=""){k=$("<span>").text("Dependencies:");$ul=$("<ul>");k.append($ul);if(typeof b.deps=="string")b.deps=b.deps.split(", ");for(var e in b.deps){a=$("<li>").text(b.deps[e]+" ");$ul.append(a);typeof V[b.deps[e]]!="undefined"||typeof V[b.deps[e]+".exe"]!="undefined"?a.append($("<span>").addClass("green").text("(Configured)")):a.append($("<span>").addClass("red").text("(Not yet configured)"))}c.unshift({type:"text",text:k[0].innerHTML})}return UI.buildUI(c)},
V={};for(r in mist.data.config.protocols)V[mist.data.config.protocols[r].connector]=1;if(z){var s=mist.data.config.protocols[b],p=s;c.find("h2").append(' "'+s.connector+'"');c.append(Ja(s.connector))}else{c.html($("<h2>").text("New Protocol"));var p={},u=[["",""]];for(r in mist.data.capabilities.connectors)u.push([r,mist.data.capabilities.connectors[r].friendly?mist.data.capabilities.connectors[r].friendly:r]);var S=$("<span>");c.append(UI.buildUI([{label:"Protocol",type:"select",select:u,"function":function(){$(this).getval()!=
V={};for(r in mist.data.config.protocols)V[mist.data.config.protocols[r].connector]=1;if(z){var s=mist.data.config.protocols[b],n=s;c.find("h2").append(' "'+s.connector+'"');c.append(Ja(s.connector))}else{c.html($("<h2>").text("New Protocol"));var n={},u=[["",""]];for(r in mist.data.capabilities.connectors)u.push([r,mist.data.capabilities.connectors[r].friendly?mist.data.capabilities.connectors[r].friendly:r]);var S=$("<span>");c.append(UI.buildUI([{label:"Protocol",type:"select",select:u,"function":function(){$(this).getval()!=
""&&S.html(Ja($(this).getval()))}}])).append(S)}break;case "Streams":if(!("capabilities"in mist.data)){c.html("Loading..");mist.send(function(){UI.navto(a)},{capabilities:!0});return}var La=$("<button>"),O=$("<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(La).append($("<button>").text("Create a new stream").click(function(){UI.navto("Edit")}))])).append(O);
""==b&&(g=mist.stored.get(),"viewmode"in g&&(b=g.viewmode));La.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 C=$.extend(!0,{},mist.data.streams),oa=function(a,b){var c=$.extend({},b);delete c.meta;delete c.error;c.online=2;c.name=a;c.ischild=true;return c},pa=function(b,d,e){O.remove();switch(b){case "thumbnails":var g=$("<div>").addClass("preview_icons"),
f;f=e||[];d.sort();d.unshift("");O.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();g.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(g);
@ -143,24 +143,25 @@ b).attr("data-stream",b))}break;default:var j=$("<tbody>").append($("<tr>").appe
c.append(h);h.stupidtable();var m=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,C,mist.data.streams);var a=0;j.html("");d.sort();for(var b in d){var c=d[b],e;e=c in mist.data.streams?mist.data.streams[c]:C[c];var g=$("<td>").css("text-align","right").html($("<span>").addClass("description").text("Loading..")),w=0;if(typeof mist.data.totals!="undefined"&&typeof mist.data.totals[c]!=
"undefined"){var f=mist.data.totals[c].all_protocols.clients,w=0;if(f.length){for(a in f)w=w+f[a][1];w=Math.round(w/f.length)}}g.html(UI.format.number(w));if(w==0&&e.online==1)e.online=2;w=$("<td>").css("text-align","right").css("white-space","nowrap");(!("ischild"in e)||!e.ischild)&&w.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)}}));f=$("<span>").text(e.name);e.ischild&&f.css("padding-left","1em");var h=UI.format.status(e),i=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("tr").data("index"))}),q=$("<button>").text("Embed").click(function(){UI.navto("Embed",$(this).closest("tr").data("index"))});if("filesfound"in C[c]||e.online<0){h.html("");
i="";g.html("");q=""}j.append($("<tr>").data("index",c).html($("<td>").html(f).attr("title",e.name=="..."?"The results were truncated":e.name).addClass("overflow_ellipsis")).append($("<td>").text(e.source).attr("title",e.source).addClass("description").addClass("overflow_ellipsis").css("max-width","20em")).append($("<td>").data("sort-value",e.online).html(h)).append(g).append($("<td>").css("white-space","nowrap").html(i).append(q)).append(w));a++}},{totals:a,active_streams:true})};if(mist.data.LTS){var r=
i="";g.html("");q=""}j.append($("<tr>").data("index",c).html($("<td>").html(f).attr("title",e.name=="..."?"The results were truncated":e.name).addClass("overflow_ellipsis")).append($("<td>").text(e.source).attr("title",e.source).addClass("description").addClass("overflow_ellipsis").css("max-width","20em")).append($("<td>").data("sort-value",e.online).html(h)).append(g).append($("<td>").css("white-space","nowrap").html(i).append(q)).append(w));a++}},{totals:a,active_streams:true})};if(mist.data.LTS){var n=
0,Ma=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)){C[f].source=C[f].source+"*";C[f].filesfound=null;mist.send(function(a,b){var c=b.stream,d=0,e;a:for(e in a.browse.files){var w;for(w in mist.data.capabilities.inputs)if(!(w.indexOf("Buffer")>=0||w.indexOf("Buffer.exe")>=0||w.indexOf("Folder")>=0||w.indexOf("Folder.exe")>=0)&&mist.inputMatch(mist.data.capabilities.inputs[w].source_match,
"/"+a.browse.files[e])){var g=c+"+"+a.browse.files[e];C[g]=oa(g,mist.data.streams[c]);C[g].source=mist.data.streams[c].source+a.browse.files[e];d++;if(d>=500){C[c+"+zzzzzzzzz"]={ischild:true,name:"...",online:-1};break a}}}"files"in a.browse&&a.browse.files.length?C[c].filesfound=true:mist.data.streams[c].filesfound=false;Ma++;if(r==Ma){mist.send(function(){m()},{active_streams:true});UI.interval.set(function(){m()},5E3)}},{browse:mist.data.streams[f].source},{stream:f});r++}}if(r==0){mist.send(function(){m()},
"/"+a.browse.files[e])){var g=c+"+"+a.browse.files[e];C[g]=oa(g,mist.data.streams[c]);C[g].source=mist.data.streams[c].source+a.browse.files[e];d++;if(d>=500){C[c+"+zzzzzzzzz"]={ischild:true,name:"...",online:-1};break a}}}"files"in a.browse&&a.browse.files.length?C[c].filesfound=true:mist.data.streams[c].filesfound=false;Ma++;if(n==Ma){mist.send(function(){m()},{active_streams:true});UI.interval.set(function(){m()},5E3)}},{browse:mist.data.streams[f].source},{stream:f});n++}}if(n==0){mist.send(function(){m()},
{active_streams:true});UI.interval.set(function(){m()},5E3)}}else{mist.send(function(){m()},{active_streams:true});UI.interval.set(function(){m()},5E3)}}};if(mist.data.LTS){var qa=0,Na=0,u={},Oa=[];for(g in mist.data.streams)if(mist.inputMatch((mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"]).source_match,mist.data.streams[g].source))Oa.push(g),mist.send(function(a,c){var d=c.stream,e=0,g;a:for(g in a.browse.files){var f;for(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[g])){u[d+"+"+a.browse.files[g]]=true;e++;if(e>=500){u[d+"+zzzzzzzzz"]=true;break a}}}Na++;qa==Na&&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){u[mist.data.active_streams[a]]=true;C[mist.data.active_streams[a]]=oa(mist.data.active_streams[a],mist.data.streams[c[0]])}}u=Object.keys(u);u=u.concat(Object.keys(mist.data.streams));
u.sort();pa(b,u,Oa)},{active_streams:true})},{browse:mist.data.streams[g].source},{stream:g}),qa++;0==qa&&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){u[mist.data.active_streams[a]]=true;C[mist.data.active_streams[a]]=oa(mist.data.active_streams[a],mist.data.streams[c[0]])}}u=Object.keys(u);mist.data.streams&&(u=u.concat(Object.keys(mist.data.streams)));u.sort();pa(b,u)},{active_streams:!0})}else pa(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}z=!1;""!=b&&(z=!0);if(z){var Pa=b,p=mist.data.streams[Pa];c.find("h2").append(' "'+Pa+'"')}else c.html($("<h2>").text("New Stream")),p={};var Qa=[];for(r in mist.data.capabilities.inputs)Qa.push(mist.data.capabilities.inputs[r].source_match);var fa=$("<div>"),Ra=function(a){var c={};if(!mist.data.streams)mist.data.streams=
{};mist.data.streams[p.name]=p;b!=p.name&&delete mist.data.streams[b];c.addstream={};c.addstream[p.name]=p;if(b!=p.name)c.deletestream=[b];if(p.stop_sessions&&b!=""){c.stop_sessions=b;delete p.stop_sessions}mist.send(function(){delete mist.data.streams[p.name].online;delete mist.data.streams[p.name].error;UI.navto(a,a=="Preview"?p.name:"")},c)},Sa=$("<style>").text("button.saveandpreview { display: none; }"),P=$("<span>"),ra=function(){var a=c.find("[name=name]").val();if(a){var b=parseURL(mist.user.host),
d=c.find("[name=source]").val(),e=d.match(/@.*/);e&&(e=e[0].substring(1));var g=d.replace(/(?:.+?):\/\//,""),g=g.split("/"),g=g[0],g=g.split(":"),g=g[0];(d=d.match(/:\d+/))&&(d=d[0]);var f={},h=["RTMP","RTSP","RTMP.exe","RTSP.exe","TSSRT","TSSRT.exe"],i;for(i in h)h[i]in mist.data.capabilities.connectors&&(f[h[i]]=mist.data.capabilities.connectors[h[i]].optional.port["default"]);var h={RTMP:1935,"RTMP.exe":1935,RTSP:554,"RTSP.exe":554,TSSRT:-1,"TSSRT.exe":-1,TS:-1,"TS.exe":-1},k;for(k in f){for(i in mist.data.config.protocols){var l=
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}z=!1;""!=b&&(z=!0);if(z){var Pa=b,n=mist.data.streams[Pa];c.find("h2").append(' "'+Pa+'"')}else c.html($("<h2>").text("New Stream")),n={};var Qa=[];for(r in mist.data.capabilities.inputs)Qa.push(mist.data.capabilities.inputs[r].source_match);var fa=$("<div>"),Ra=function(a){var c={};if(!mist.data.streams)mist.data.streams=
{};mist.data.streams[n.name]=n;b!=n.name&&delete mist.data.streams[b];c.addstream={};c.addstream[n.name]=n;if(b!=n.name)c.deletestream=[b];if(n.stop_sessions&&b!=""){c.stop_sessions=b;delete n.stop_sessions}var d=null,e;for(e in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[e].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[e].source_match,n.source)){d=e;break}if(d){d=mist.data.capabilities.inputs[d];for(e in n)e=="name"||e=="source"||e=="stop_sessions"||
e=="processes"||"optional"in d&&e in d.optional||"required"in d&&e in d.required||e=="always_on"&&"always_match"in d&&mist.inputMatch(d.always_match,n.source)||delete n[e]}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)},Sa=$("<style>").text("button.saveandpreview { display: none; }"),P=$("<span>"),ra=function(){var a=c.find("[name=name]").val();if(a){var b=parseURL(mist.user.host),d=c.find("[name=source]").val(),
e=d.match(/@.*/);e&&(e=e[0].substring(1));var g=d.replace(/(?:.+?):\/\//,""),g=g.split("/"),g=g[0],g=g.split(":"),g=g[0];(d=d.match(/:\d+/))&&(d=d[0]);var f={},h=["RTMP","RTSP","RTMP.exe","RTSP.exe","TSSRT","TSSRT.exe"],i;for(i in h)h[i]in mist.data.capabilities.connectors&&(f[h[i]]=mist.data.capabilities.connectors[h[i]].optional.port["default"]);var h={RTMP:1935,"RTMP.exe":1935,RTSP:554,"RTSP.exe":554,TSSRT:-1,"TSSRT.exe":-1,TS:-1,"TS.exe":-1},k;for(k in f){for(i in mist.data.config.protocols){var l=
mist.data.config.protocols[i];if(l.connector==k){if("port"in l)f[k]=l.port;break}}f[k]=f[k]==h[k]?"":":"+f[k]}f.TS="";f["TS.exe"]="";P.find(".field").closest("label").hide();for(i in f){var q;k=d?d:f[i];switch(i){case "RTMP":case "RTMP.exe":q="rtmp://"+b.host+k+"/"+(e?e:"live")+"/";P.find(".field.RTMPurl").setval(q).closest("label").show();P.find(".field.RTMPkey").setval(a==""?"STREAMNAME":a).closest("label").show();q=q+(a==""?"STREAMNAME":a);break;case "TSSRT":case "TSSRT.exe":q="srt://"+b.host+
k+"?streamname="+(a==""?"STREAMNAME":a);break;case "RTSP":case "RTSP.exe":q="rtsp://"+b.host+k+"/"+(a==""?"STREAMNAME":a)+(e?"?pass="+e:"");break;case "TS":case "TS.exe":q="udp://"+(g==""?b.host:g)+k+"/"}P.find(".field."+i.replace(".exe","")).setval(q).closest("label").show()}}},Ta=$("<div>"),sa={},u=[],Ua=$("<div>");for(r in mist.data.capabilities.processes)u.push([r,mist.data.capabilities.processes[r].hrn?mist.data.capabilities.processes[r].hrn:mist.data.capabilities.processes[r].name]);if(u.length){var jb=
[{label:"New process",type:"select",select:u,value:u[0][0],pointer:{main:sa,index:"process"},"function":function(){var a=$(this).getval();if(a!=null){var a=mist.data.capabilities.processes[a],b=[$("<h4>").text(a.name+" Process options")];Ua.html(UI.buildUI(b.concat(mist.convertBuildOptions(a,sa))))}}},Ua];Ta.append(UI.buildUI([$("<br>"),$("<h3>").text("Stream processes"),{label:"Stream processes",itemLabel:"stream process",type:"sublist",sublist:jb,saveas:sa,pointer:{main:p,index:"processes"}}]))}c.append(UI.buildUI([{label:"Stream name",
type:"str",validate:["required","streamname"],pointer:{main:p,index:"name"},help:"Set the name this stream will be recognised by for players and/or stream pushing."},{label:"Source",type:"browse",filetypes:Qa,pointer:{main:p,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 class=valigntop> <tr> <th colspan=3><b>File inputs</b></th> </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 </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><td colspan=3>&nbsp;</td></tr> <tr> <th colspan=3><b>Push inputs</b></th> </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. </td> </tr> <tr> <th>SRT</th> <td>push://(IP)</td> <td> IP is white listed IP for pushing towards MistServer, if left empty all are white listed.<br> </td> </tr> <tr> <th>RTSP</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</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> <tr><td colspan=3>&nbsp;</td></tr> <tr> <th colspan=3><b>Pull inputs</b></th> </tr> <tr> <th>DTSC</th> <td>dtsc://MISTSERVER_IP:PORT/(STREAMNAME)</td> <td>MISTSERVER_IP is the IP of another MistServer to pull from.<br> PORT is the DTSC port of the other MistServer. (default is 4200)<br> STREAMNAME is the name of the target stream on the other MistServer. If left empty, the name of this stream will be used. </td> </tr> <tr> <th>HLS</th> <td>http://URL/TO/STREAM.m3u8</td> <td>The URL where the HLS stream is available to MistServer.</td> </tr> <tr> <th>RTSP</th> <td>rtsp://(USER:PASSWORD@)IP(:PORT)(/path)</td> <td> USER:PASSWORD is the account used if authorization is required.<br> IP is the IP address used to pull this stream from.<br> PORT is the port used to connect through.<br> PATH is the path to be used to identify the correct stream. </td> </tr> </table>",
[{label:"New process",type:"select",select:u,value:u[0][0],pointer:{main:sa,index:"process"},"function":function(){var a=$(this).getval();if(a!=null){var a=mist.data.capabilities.processes[a],b=[$("<h4>").text(a.name+" Process options")];Ua.html(UI.buildUI(b.concat(mist.convertBuildOptions(a,sa))))}}},Ua];Ta.append(UI.buildUI([$("<br>"),$("<h3>").text("Stream processes"),{label:"Stream processes",itemLabel:"stream process",type:"sublist",sublist:jb,saveas:sa,pointer:{main:n,index:"processes"}}]))}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:Qa,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 class=valigntop> <tr> <th colspan=3><b>File inputs</b></th> </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 </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><td colspan=3>&nbsp;</td></tr> <tr> <th colspan=3><b>Push inputs</b></th> </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. </td> </tr> <tr> <th>SRT</th> <td>push://(IP)</td> <td> IP is white listed IP for pushing towards MistServer, if left empty all are white listed.<br> </td> </tr> <tr> <th>RTSP</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</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> <tr><td colspan=3>&nbsp;</td></tr> <tr> <th colspan=3><b>Pull inputs</b></th> </tr> <tr> <th>DTSC</th> <td>dtsc://MISTSERVER_IP:PORT/(STREAMNAME)</td> <td>MISTSERVER_IP is the IP of another MistServer to pull from.<br> PORT is the DTSC port of the other MistServer. (default is 4200)<br> STREAMNAME is the name of the target stream on the other MistServer. If left empty, the name of this stream will be used. </td> </tr> <tr> <th>HLS</th> <td>http://URL/TO/STREAM.m3u8</td> <td>The URL where the HLS stream is available to MistServer.</td> </tr> <tr> <th>RTSP</th> <td>rtsp://(USER:PASSWORD@)IP(:PORT)(/path)</td> <td> USER:PASSWORD is the account used if authorization is required.<br> IP is the IP address used to pull this stream from.<br> PORT is the port used to connect through.<br> PATH is the path to be used to identify the correct stream. </td> </tr> </table>",
"function":function(){var a=$(this).val();Sa.remove();P.html("");if(a!=""){var d=null,e;for(e in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[e].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[e].source_match,a)){d=e;break}if(d===null)fa.html($("<h3>").text("Unrecognized input").addClass("red")).append($("<span>").text("Please edit the stream source.").addClass("red"));else{d=mist.data.capabilities.inputs[d];fa.html($("<h3>").text(d.name+" Input options"));
var g=mist.convertBuildOptions(d,p);"always_match"in mist.data.capabilities.inputs[e]&&mist.inputMatch(mist.data.capabilities.inputs[e].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:p,index:"always_on"},value:b==""&&(e=="TSSRT"||e=="TSRIST")?true:false});fa.append(UI.buildUI(g));if(d.name=="Folder")c.append(Sa);else if(["Buffer","Buffer.exe","TS","TS.exe"].indexOf(d.name)>-1){e=[$("<br>"),
var g=mist.convertBuildOptions(d,n);"always_match"in mist.data.capabilities.inputs[e]&&mist.inputMatch(mist.data.capabilities.inputs[e].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"},value:b==""&&(e=="TSSRT"||e=="TSRIST")?true:false});fa.append(UI.buildUI(g));if(d.name=="Folder")c.append(Sa);else if(["Buffer","Buffer.exe","TS","TS.exe"].indexOf(d.name)>-1){e=[$("<br>"),
$("<span>").text("Configure your source to push to:")];switch(d.name){case "Buffer":case "Buffer.exe":e.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"});e.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"});e.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"});e.push({label:"SRT",type:"span",clipboard:true,readonly:true,classes:["TSSRT"]});e.push({label:"RTSP",type:"span",clipboard:true,readonly:true,classes:["RTSP"]});break;case "TS":case "TS.exe":a.charAt(0)=="/"?e=[]:e.push({label:"TS",type:"span",clipboard:true,readonly:true,classes:["TS"]})}P.html(UI.buildUI(e));ra()}}}}},{label:"Stop sessions",type:"checkbox",help:"When saving these stream settings, kill this stream's current connections.",
pointer:{main:p,index:"stop_sessions"}},P,$("<br>"),{type:"custom",custom:fa},Ta,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Streams")}},{type:"save",label:"Save","function":function(){Ra("Streams")}},{type:"save",label:"Save and Preview","function":function(){Ra("Preview")},classes:["saveandpreview"]}]}]));c.find("[name=name]").keyup(function(){ra()});ra();break;case "Preview":""==b&&UI.navto("Streams");var Q=parseURL(mist.user.host),W=Q.protocol,T=Q.host,
pointer:{main:n,index:"stop_sessions"}},P,$("<br>"),{type:"custom",custom:fa},Ta,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Streams")}},{type:"save",label:"Save","function":function(){Ra("Streams")}},{type:"save",label:"Save and Preview","function":function(){Ra("Preview")},classes:["saveandpreview"]}]}]));c.find("[name=name]").keyup(function(){ra()});ra();break;case "Preview":""==b&&UI.navto("Streams");var Q=parseURL(mist.user.host),W=Q.protocol,T=Q.host,
J=":8080",v=W+T+J+"/";for(r in mist.data.config.protocols)if(s=mist.data.config.protocols[r],"HTTP"==s.connector||"HTTP.exe"==s.connector){s.pubaddr&&s.pubaddr.length?"string"==typeof s.pubaddr?v=s.pubaddr.replace(/\/$/,"")+"/":s.pubaddr.length&&(v=s.pubaddr[0].replace(/\/$/,"")+"/"):(J=s.port?":"+s.port:":8080",v=W+T+J+"/");break}var S=$("<div>").css({display:"flex","flex-flow":"row wrap","flex-shrink":1,"min-width":"auto"}),X="";-1==b.indexOf("+")&&(X=$("<button>").text("Settings").addClass("settings").click(function(){UI.navto("Edit",
b)}));c.html($("<div>").addClass("bigbuttons").append(X).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(S);var K=encodeURIComponent(b),Va=$("<div>").css("flex-shrink","1").css("min-width","auto").css("max-width","100%");S.append(Va);var Wa=$("<div>"),Y=$("<div>").text("Loading player..").css("max-width",
"100%").css("flex-shrink","1").css("min-width","auto"),ta=$("<div>").addClass("controls");Va.append(Y).append(Wa).append(ta);$("link#devcss").length||c.append($("<link>").attr("rel","stylesheet").attr("type","text/css").attr("href",v+"skins/dev.css").attr("id","devcss"));var Xa=function(){Wa.text("");var d=document.createElement("script");c.append(d);d.src=v+"player.js";d.onerror=function(){Y.html($("<p>").append('Failed to load <a href="'+v+'player.js">'+v+"player.js</a>.")).append($("<p>").append("Please check if you've activated the HTTP protocol, if your http port is blocked, or if you're trying to load HTTPS on an HTTP page.")).append($("<button>").text("Reload").css("display",
@ -180,24 +181,24 @@ $("<span>").text(a.source);a.source_tracks&&a.source_tracks.length&&b.append($("
$("<tr>");b.append(e);e.append($("<th>").text(d).css("vertical-align","top"));for(var g in a.proc_list){$out=c[d](a.proc_list[g],g);e.append($("<td>").html($out).css("vertical-align","top"))}}}},a)};UI.interval.set(function(){Za()},5E3);Za()}break;case "Embed":""==b&&UI.navTo("Streams");X="";-1==b.indexOf("+")&&(X=$("<button>").addClass("settings").text("Settings").click(function(){UI.navto("Edit",b)}));c.html($("<div>").addClass("bigbuttons").append(X).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 Z=$("<span>");c.append(Z);var K=encodeURIComponent(b),Q=parseURL(mist.user.host),W=Q.protocol,T=Q.host,J=":8080",aa,ha={},v={http:W+T+J+"/"};for(r in mist.data.config.protocols)if(s=mist.data.config.protocols[r],"HTTP"==s.connector||"HTTP.exe"==s.connector)s.pubaddr?("string"==typeof s.pubaddr?v.http=s.pubaddr.replace(/\/$/,"")+"/":s.pubaddr.length&&
(v.http=s.pubaddr[0].replace(/\/$/,"")+"/"),ha.http=s.pubaddr):(J=s.port?":"+s.port:":8080",v.http=W+T+J+"/");else if("HTTPS"==s.connector||"HTTPS.exe"==s.connector)s.pubaddr&&s.pubaddr.length?("string"==typeof s.pubaddr?v.https=s.pubaddr.replace(/\/$/,"")+"/":s.pubaddr.length&&(v.https=s.pubaddr[0].replace(/\/$/,"")+"/"),ha.https=s.pubaddr):(aa=s.port?":"+s.port:":4433",v.https="https://"+T+aa+"/");var R=v.http,D={http:v.http};"https"in v&&(D.https=v.https);if(otherhost.host||otherhost.https){R=
(otherhost.https&&aa?"https://":"http://")+(otherhost.host?otherhost.host:Q.host)+(otherhost.https&&aa?aa:J)+"/";if(otherhost.host&&("http"in ha||(D.http=parseURL(D.http,{hostname:otherhost.host}).full),"https"in D&&!("https"in ha)))D.https=parseURL(D.https,{hostname:otherhost.host}).full;R=otherhost.https?D.https:D.http}var ba=!1,va={forcePlayer:"",forceType:"",controls:!0,autoplay:!0,loop:!1,muted:!1,fillSpace:!1,poster:"",urlappend:"",setTracks:{}},n=$.extend({},va),$a=UI.stored.getOpts();"embedoptions"in
$a&&(n=$.extend(n,$a.embedoptions,!0),"object"!=typeof n.setTracks&&(n.setTracks={}));var ia={};switch(n.controls){case "stock":ia.controls="stock";break;case !0:ia.controls=1;break;case !1:ia.controls=0}var A=function(){function a(b){switch(typeof b){case "string":return $.isNumeric(b)?b:'"'+b+'"';case "object":return JSON.stringify(b);default:return b}}ba&&UI.stored.saveOpt("embedoptions",n);for(var c=b+"_",d=12,e="";d--;){var g;g=Math.floor(Math.random()*62);g=g<10?g:g<36?String.fromCharCode(g+
55):String.fromCharCode(g+61);e=e+g}var c=c+e,d=['target: document.getElementById("'+c+'")'],f;for(f in n)f=="prioritize_type"?n[f]&&n[f]!=""&&d.push("forcePriority: "+JSON.stringify({source:[["type",[n[f]]]]})):f=="monitor_action"?n[f]&&n[f]!=""&&n[f]=="nextCombo"&&d.push('monitor: {\n action: function(){\n this.MistVideo.log("Switching to nextCombo because of poor playback in "+this.MistVideo.source.type+" ("+Math.round(this.vars.score*1000)/10+"%)");\n this.MistVideo.nextCombo();\n }\n }'):
n[f]!=va[f]&&(n[f]!=null&&(typeof n[f]!="object"||JSON.stringify(n[f])!=JSON.stringify(va[f])))&&d.push(f+": "+a(n[f]));f=[];f.push('<div class="mistvideo" id="'+c+'">');f.push(" <noscript>");f.push(' <a href="'+(otherhost.https?D.https:D.http)+K+'.html" target="_blank">');f.push(" Click here to play this video");f.push(" </a>");f.push(" </noscript>");f.push(" <script>");f.push(" var a = function(){");f.push(' mistPlay("'+b+'",{');f.push(" "+d.join(",\n "));f.push(" });");
(otherhost.https&&aa?"https://":"http://")+(otherhost.host?otherhost.host:Q.host)+(otherhost.https&&aa?aa:J)+"/";if(otherhost.host&&("http"in ha||(D.http=parseURL(D.http,{hostname:otherhost.host}).full),"https"in D&&!("https"in ha)))D.https=parseURL(D.https,{hostname:otherhost.host}).full;R=otherhost.https?D.https:D.http}var ba=!1,va={forcePlayer:"",forceType:"",controls:!0,autoplay:!0,loop:!1,muted:!1,fillSpace:!1,poster:"",urlappend:"",setTracks:{}},o=$.extend({},va),$a=UI.stored.getOpts();"embedoptions"in
$a&&(o=$.extend(o,$a.embedoptions,!0),"object"!=typeof o.setTracks&&(o.setTracks={}));var ia={};switch(o.controls){case "stock":ia.controls="stock";break;case !0:ia.controls=1;break;case !1:ia.controls=0}var A=function(){function a(b){switch(typeof b){case "string":return $.isNumeric(b)?b:'"'+b+'"';case "object":return JSON.stringify(b);default:return b}}ba&&UI.stored.saveOpt("embedoptions",o);for(var c=b+"_",d=12,e="";d--;){var g;g=Math.floor(Math.random()*62);g=g<10?g:g<36?String.fromCharCode(g+
55):String.fromCharCode(g+61);e=e+g}var c=c+e,d=['target: document.getElementById("'+c+'")'],f;for(f in o)f=="prioritize_type"?o[f]&&o[f]!=""&&d.push("forcePriority: "+JSON.stringify({source:[["type",[o[f]]]]})):f=="monitor_action"?o[f]&&o[f]!=""&&o[f]=="nextCombo"&&d.push('monitor: {\n action: function(){\n this.MistVideo.log("Switching to nextCombo because of poor playback in "+this.MistVideo.source.type+" ("+Math.round(this.vars.score*1000)/10+"%)");\n this.MistVideo.nextCombo();\n }\n }'):
o[f]!=va[f]&&(o[f]!=null&&(typeof o[f]!="object"||JSON.stringify(o[f])!=JSON.stringify(va[f])))&&d.push(f+": "+a(o[f]));f=[];f.push('<div class="mistvideo" id="'+c+'">');f.push(" <noscript>");f.push(' <a href="'+(otherhost.https?D.https:D.http)+K+'.html" target="_blank">');f.push(" Click here to play this video");f.push(" </a>");f.push(" </noscript>");f.push(" <script>");f.push(" var a = function(){");f.push(' mistPlay("'+b+'",{');f.push(" "+d.join(",\n "));f.push(" });");
f.push(" };");f.push(" if (!window.mistplayers) {");f.push(' var p = document.createElement("script");');if("https"in v&&parseURL(v.http).protocol!="https://"){f.push(' if (location.protocol == "https:") { p.src = "'+D.https+'player.js" } ');f.push(' else { p.src = "'+D.http+'player.js" } ')}else f.push(' p.src = "'+R+'player.js"');f.push(" document.head.appendChild(p);");f.push(" p.onload = a;");f.push(" }");f.push(" else { a(); }");f.push(" <\/script>");
f.push("</div>");return f.join("\n")},wa=$("<span>").text("Loading.."),ab=A(n),U=$("<div>").text("Loading..").css("display","flex").css("flex-flow","column nowrap"),bb="";"https"in v&&(bb=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"));Z.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",
f.push("</div>");return f.join("\n")},wa=$("<span>").text("Loading.."),ab=A(o),U=$("<div>").text("Loading..").css("display","flex").css("flex-flow","column nowrap"),bb="";"https"in v&&(bb=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"));Z.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:Q.host)).append($("<span>").addClass("unit").append($("<button>").text("Apply").click(function(){otherhost.host=$(this).closest("label").find("input").val();UI.navto("Embed",b)}))))).append(bb)).append(UI.buildUI([$("<h3>").text("Urls"),{label:"Stream info json",type:"str",value:R+"json_"+K+".js",readonly:!0,clipboard:!0,help:"Information about this stream as a json page."},{label:"Stream info script",type:"str",value:R+"info_"+K+".js",readonly:!0,
clipboard:!0,help:"This script loads information about this stream into a mistvideo javascript object."},{label:"HTML page",type:"str",value:R+K+".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:ab,rows:ab.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:"Prioritize type",type:"select",select:[["","Automatic"]],pointer:{main:n,index:"prioritize_type"},classes:["prioritize_type"],"function":function(){if(ba){n.prioritize_type=$(this).getval();$(".embed_code").setval(A(n))}},help:"Try to use this source type first, but full back to something else if it is not available."},
{label:"Force type",type:"select",select:[["","Automatic"]],pointer:{main:n,index:"forceType"},classes:["forceType"],"function":function(){if(ba){n.forceType=$(this).getval();$(".embed_code").setval(A(n))}},help:"Only use this particular source."},{label:"Force player",type:"select",select:[["","Automatic"]],pointer:{main:n,index:"forcePlayer"},classes:["forcePlayer"],"function":function(){if(ba){n.forcePlayer=$(this).getval();$(".embed_code").setval(A(n))}},help:"Only use this particular player."},
{label:"Controls",type:"select",select:[["1","MistServer Controls"],["stock","Player controls"],["0","None"]],pointer:{main:ia,index:"controls"},"function":function(){n.controls=$(this).getval()==1;switch($(this).getval()){case 0:n.controls=false;break;case 1:n.controls=true;break;case "stock":n.controls="stock"}$(".embed_code").setval(A(n))},help:"The type of controls that should be shown."},{label:"Autoplay",type:"checkbox",pointer:{main:n,index:"autoplay"},"function":function(){n.autoplay=$(this).getval();
$(".embed_code").setval(A(n))},help:"Whether or not the video should play as the page is loaded."},{label:"Loop",type:"checkbox",pointer:{main:n,index:"loop"},"function":function(){n.loop=$(this).getval();$(".embed_code").setval(A(n))},help:"If the video should restart when the end is reached."},{label:"Start muted",type:"checkbox",pointer:{main:n,index:"muted"},"function":function(){n.muted=$(this).getval();$(".embed_code").setval(A(n))},help:"If the video should restart when the end is reached."},
{label:"Fill available space",type:"checkbox",pointer:{main:n,index:"fillSpace"},"function":function(){n.fillSpace=$(this).getval();$(".embed_code").setval(A(n))},help:"The video will fit the available space in its container, even if the video stream has a smaller resolution."},{label:"Poster",type:"str",pointer:{main:n,index:"poster"},"function":function(){n.poster=$(this).getval();$(".embed_code").setval(A(n))},help:"URL to an image that is displayed when the video is not playing."},{label:"Video URL addition",
type:"str",pointer:{main:n,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(){n.urlappend=$(this).getval();$(".embed_code").setval(A(n))}},{label:"Preselect tracks",type:"DOMfield",DOMfield:U,help:"Pre-select these tracks."},{label:"Monitoring action",type:"select",select:[["","Ask the viewer what to do"],["nextCombo","Try the next source / player combination"]],pointer:{main:n,
index:"monitor_action"},"function":function(){n.monitor_action=$(this).getval();$(".embed_code").setval(A(n))},help:"What the player should do when playback is poor."},$("<h3>").text("Protocol stream urls"),wa]));$.ajax({type:"GET",url:R+"json_"+K+".js?inclzero=1",success:function(a){var b=[],c=Z.find(".field.forceType"),d=Z.find(".field.prioritize_type"),e;for(e in a.source){var f=a.source[e],g=UI.humanMime(f.type);b.push({label:g?g+" <span class=description>("+f.type+")</span>":UI.format.capital(f.type),
type:"str",value:f.url,readonly:true,qrcode:true,clipboard:true});g=UI.humanMime(f.type);if(c.children('option[value="'+f.type+'"]').length==0){c.append($("<option>").text(g?g+" ("+f.type+")":UI.format.capital(f.type)).val(f.type));d.append($("<option>").text(g?g+" ("+f.type+")":UI.format.capital(f.type)).val(f.type))}}c.val(n.forceType);d.val(n.prioritize_type);wa.html(UI.buildUI(b));U.html("");b={};if(a.meta)for(e in a.meta.tracks){c=a.meta.tracks[e];if(c.codec=="subtitle")c.type="subtitle";if(!(c.type!=
"audio"&&c.type!="video"&&c.type!="subtitle")){c.type in b||(b[c.type]=c.type=="subtitle"?[]:[["","Autoselect "+c.type]]);b[c.type].push([c.trackid,UI.format.capital(c.type)+" track "+(b[c.type].length+(c.type=="subtitle"?1:0))])}}if(Object.keys(b).length){U.closest("label").show();var a=["audio","video","subtitle"],h;for(h in a){e=a[h];if(b[e]&&b[e].length){c=$("<select>").attr("data-type",e).css("flex-grow","1").change(function(){$(this).val()==""?delete n.setTracks[$(this).attr("data-type")]:n.setTracks[$(this).attr("data-type")]=
$(this).val();$(".embed_code").setval(A(n))});U.append(c);e=="subtitle"?b[e].unshift(["","No "+e]):b[e].push([-1,"No "+e]);for(var i in b[e])c.append($("<option>").val(b[e][i][0]).text(b[e][i][1]));if(e in n.setTracks){c.val(n.setTracks[e]);if(c.val()==null){c.val("");delete n.setTracks[e];$(".embed_code").setval(A(n))}}}}}else U.closest("label").hide();ba=true},error:function(){wa.html("Error while retrieving stream info.");U.closest("label").hide();n.setTracks={}}});var ja=document.createElement("script");
$("<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:"Prioritize type",type:"select",select:[["","Automatic"]],pointer:{main:o,index:"prioritize_type"},classes:["prioritize_type"],"function":function(){if(ba){o.prioritize_type=$(this).getval();$(".embed_code").setval(A(o))}},help:"Try to use this source type first, but full back to something else if it is not available."},
{label:"Force type",type:"select",select:[["","Automatic"]],pointer:{main:o,index:"forceType"},classes:["forceType"],"function":function(){if(ba){o.forceType=$(this).getval();$(".embed_code").setval(A(o))}},help:"Only use this particular source."},{label:"Force player",type:"select",select:[["","Automatic"]],pointer:{main:o,index:"forcePlayer"},classes:["forcePlayer"],"function":function(){if(ba){o.forcePlayer=$(this).getval();$(".embed_code").setval(A(o))}},help:"Only use this particular player."},
{label:"Controls",type:"select",select:[["1","MistServer Controls"],["stock","Player controls"],["0","None"]],pointer:{main:ia,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(A(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(A(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(A(o))},help:"If the video should restart when the end is reached."},{label:"Start muted",type:"checkbox",pointer:{main:o,index:"muted"},"function":function(){o.muted=$(this).getval();$(".embed_code").setval(A(o))},help:"If the video should restart when the end is reached."},
{label:"Fill available space",type:"checkbox",pointer:{main:o,index:"fillSpace"},"function":function(){o.fillSpace=$(this).getval();$(".embed_code").setval(A(o))},help:"The video will fit the available space in its container, even if the video stream has a smaller resolution."},{label:"Poster",type:"str",pointer:{main:o,index:"poster"},"function":function(){o.poster=$(this).getval();$(".embed_code").setval(A(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(A(o))}},{label:"Preselect tracks",type:"DOMfield",DOMfield:U,help:"Pre-select these tracks."},{label:"Monitoring action",type:"select",select:[["","Ask the viewer what to do"],["nextCombo","Try the next source / player combination"]],pointer:{main:o,
index:"monitor_action"},"function":function(){o.monitor_action=$(this).getval();$(".embed_code").setval(A(o))},help:"What the player should do when playback is poor."},$("<h3>").text("Protocol stream urls"),wa]));$.ajax({type:"GET",url:R+"json_"+K+".js?inclzero=1",success:function(a){var b=[],c=Z.find(".field.forceType"),d=Z.find(".field.prioritize_type"),e;for(e in a.source){var f=a.source[e],g=UI.humanMime(f.type);b.push({label:g?g+" <span class=description>("+f.type+")</span>":UI.format.capital(f.type),
type:"str",value:f.url,readonly:true,qrcode:true,clipboard:true});g=UI.humanMime(f.type);if(c.children('option[value="'+f.type+'"]').length==0){c.append($("<option>").text(g?g+" ("+f.type+")":UI.format.capital(f.type)).val(f.type));d.append($("<option>").text(g?g+" ("+f.type+")":UI.format.capital(f.type)).val(f.type))}}c.val(o.forceType);d.val(o.prioritize_type);wa.html(UI.buildUI(b));U.html("");b={};if(a.meta)for(e in a.meta.tracks){c=a.meta.tracks[e];if(c.codec=="subtitle")c.type="subtitle";if(!(c.type!=
"audio"&&c.type!="video"&&c.type!="subtitle")){c.type in b||(b[c.type]=c.type=="subtitle"?[]:[["","Autoselect "+c.type]]);b[c.type].push([c.trackid,UI.format.capital(c.type)+" track "+(b[c.type].length+(c.type=="subtitle"?1:0))])}}if(Object.keys(b).length){U.closest("label").show();var a=["audio","video","subtitle"],h;for(h in a){e=a[h];if(b[e]&&b[e].length){c=$("<select>").attr("data-type",e).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(A(o))});U.append(c);e=="subtitle"?b[e].unshift(["","No "+e]):b[e].push([-1,"No "+e]);for(var i in b[e])c.append($("<option>").val(b[e][i][0]).text(b[e][i][1]));if(e in o.setTracks){c.val(o.setTracks[e]);if(c.val()==null){c.val("");delete o.setTracks[e];$(".embed_code").setval(A(o))}}}}}else U.closest("label").hide();ba=true},error:function(){wa.html("Error while retrieving stream info.");U.closest("label").hide();o.setTracks={}}});var ja=document.createElement("script");
ja.src=v.http+"player.js";document.head.appendChild(ja);ja.onload=function(){var a=Z.find(".field.forcePlayer"),b;for(b in mistplayers)a.append($("<option>").text(mistplayers[b].name).val(b));document.head.removeChild(this)};ja.onerror=function(){document.head.removeChild(this)};break;case "Push":var L=$("<div>").text("Loading..");c.append(L);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(f,g){var h=$("<span>"),i=$("<span>");if(g=="Automatic"&&f.length>=4){var k=function(a,b,c){a=""+("$"+a+" ");switch(Number(b)){case 0:a=a+"is true";break;case 1:a=a+"is false";break;case 2:a=a+("== "+c);break;case 3:a=a+("!= "+c);break;case 10:a=a+("> (numerical) "+c);break;case 11:a=a+(">= (numerical) "+c);break;
case 12:a=a+("< (numerical) "+c);break;case 13:a=a+("<= (numerical) "+c);break;case 20:a=a+("> (lexical) "+c);break;case 21:a=a+(">= (lexical) "+c);break;case 22:a=a+("< (lexical) "+c);break;case 23:a=a+("<= (lexical) "+c);break;default:a=a+"comparison operator unknown"}return a};h.append($("<span>").text(f[2]));f[3]&&h.append($("<span>").text(", schedule on "+(new Date(f[3]*1E3)).toLocaleString()));f.length>=5&&f[4]&&h.append($("<span>").text(", complete on "+(new Date(f[4]*1E3)).toLocaleString()));
@ -212,64 +213,64 @@ min:0,help:"How long the delay should be before MistServer retries an automatic
k=$("<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)k.append($("<option>").text(h[g]));L.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(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 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)}UI.interval.set(function(){mist.send(function(a){var b=
e.find("tr").first();e.empty();e.append(b);for(var d in a.push_list)e.append(c(a.push_list[d]))},{push_list:1})},5E3)},{push_settings:1,push_list:1,push_auto_list:1});break;case "Start Push":if(!("capabilities"in mist.data)||!("variable_list"in mist.data)||!("external_writer_list"in mist.data)){c.append("Loading Mist capabilities..");mist.send(function(){UI.navto("Start Push",b)},{capabilities:1,variable_list:!0,external_writer_list:!0});return}var y,ka=function(a){var d=false,f=b.split("_");b=f[0];
f.length==2&&(d=f[1]);if(d!==false&&typeof a=="undefined")mist.send(function(a){ka(a.push_auto_list[d])},{push_auto_list:1});else{var e=[],g=[],h={},i=[],k;for(k in mist.data.capabilities.connectors){f=mist.data.capabilities.connectors[k];if("push_urls"in f){h[k]=f.push_urls;for(var l in f.push_urls)f.push_urls[l][0]=="/"?e.push(f.push_urls[l]):g.push(f.push_urls[l])}}if(mist.data.external_writer_list)for(k in mist.data.external_writer_list){f=mist.data.external_writer_list[k];if(f.length>=3)for(l in f[2])i.push(f[2][l]+
"://")}e.sort();g.sort();b=="auto"&&c.find("h2").text("Add automatic push");var j={params:{}},m=[];if(b=="auto"&&typeof a!="undefined"){j={stream:a[0],target:a[1],params:{}};l=j.target.split("?");if(l.length>1){m=l.pop();j.target=l.join("?");m=m.split("&");for(k in m){l=m[k].split("=");j.params[l.shift()]=l.join("=")}}if(a.length>=3)j.scheduletime=a[2]!=0?a[2]:null;if(a.length>=4)j.completetime=a[3]!=0?a[3]:null;if(a.length>=5)j.startVariableName=a[4]!=""?a[4]:null;if(a.length>=6)j.startVariableOperator=
a[5]!=""?a[5]:null;if(a.length>=7)j.startVariableValue=a[6]!=""?a[6]:null;if(a.length>=8)j.endVariableName=a[7]!=""?a[7]:null;if(a.length>=9)j.endVariableOperator=a[8]!=""?a[8]:null;if(a.length>=10)j.endVariableValue=a[9]!=""?a[9]:null}var r=$("<div>").css("margin","1em 0"),n=$("<div>"),o;if(b=="auto"){n.css("margin","1em 0").html(UI.buildUI([{label:"This push should be active",help:"When 'based on server time' is selected, a start and/or end timestamp can be configured. When it's 'based on a variable', the push will be activated while the specified variable matches the specified value.",
type:"select",select:[["time","Based on server time"],["variable","Based on a variable"]],value:j.startVariableName||j.endVariableName?"variable":"time",classes:["activewhen"],"function":function(){var a=n.find(".varbased").closest(".UIelement"),b=n.find(".timebased").closest(".UIelement");if($(this).getval()=="time"){a.hide();b.css("display","")}else{b.hide();a.css("display","");n.find('[name="startVariableOperator"]').trigger("change");n.find('[name="endVariableOperator"]').trigger("change")}}},
e.find("tr").first();e.empty();e.append(b);for(var d in a.push_list)e.append(c(a.push_list[d]))},{push_list:1})},5E3)},{push_settings:1,push_list:1,push_auto_list:1});break;case "Start Push":if(!("capabilities"in mist.data)||!("variable_list"in mist.data)||!("external_writer_list"in mist.data)){c.append("Loading Mist capabilities..");mist.send(function(){UI.navto("Start Push",b)},{capabilities:1,variable_list:!0,external_writer_list:!0});return}var y,ka=function(a){var d=false,e=b.split("_");b=e[0];
e.length==2&&(d=e[1]);if(d!==false&&typeof a=="undefined")mist.send(function(a){ka(a.push_auto_list[d])},{push_auto_list:1});else{var f=[],g=[],h={},i=[],k;for(k in mist.data.capabilities.connectors){e=mist.data.capabilities.connectors[k];if("push_urls"in e){h[k]=e.push_urls;for(var l in e.push_urls)e.push_urls[l][0]=="/"?f.push(e.push_urls[l]):g.push(e.push_urls[l])}}if(mist.data.external_writer_list)for(k in mist.data.external_writer_list){e=mist.data.external_writer_list[k];if(e.length>=3)for(l in e[2])i.push(e[2][l]+
"://")}f.sort();g.sort();b=="auto"&&c.find("h2").text("Add automatic push");var j={params:{}},m=[];if(b=="auto"&&typeof a!="undefined"){j={stream:a[0],target:a[1],params:{}};l=j.target.split("?");if(l.length>1){m=l.pop();j.target=l.join("?");m=m.split("&");for(k in m){l=m[k].split("=");j.params[l.shift()]=l.join("=")}}if(a.length>=3)j.scheduletime=a[2]!=0?a[2]:null;if(a.length>=4)j.completetime=a[3]!=0?a[3]:null;if(a.length>=5)j.startVariableName=a[4]!=""?a[4]:null;if(a.length>=6)j.startVariableOperator=
a[5]!=""?a[5]:null;if(a.length>=7)j.startVariableValue=a[6]!=""?a[6]:null;if(a.length>=8)j.endVariableName=a[7]!=""?a[7]:null;if(a.length>=9)j.endVariableOperator=a[8]!=""?a[8]:null;if(a.length>=10)j.endVariableValue=a[9]!=""?a[9]:null}var n=$("<div>").css("margin","1em 0"),o=$("<div>"),p;if(b=="auto"){o.css("margin","1em 0").html(UI.buildUI([{label:"This push should be active",help:"When 'based on server time' is selected, a start and/or end timestamp can be configured. When it's 'based on a variable', the push will be activated while the specified variable matches the specified value.",
type:"select",select:[["time","Based on server time"],["variable","Based on a variable"]],value:j.startVariableName||j.endVariableName?"variable":"time",classes:["activewhen"],"function":function(){var a=o.find(".varbased").closest(".UIelement"),b=o.find(".timebased").closest(".UIelement");if($(this).getval()=="time"){a.hide();b.css("display","")}else{b.hide();a.css("display","");o.find('[name="startVariableOperator"]').trigger("change");o.find('[name="endVariableOperator"]').trigger("change")}}},
$("<br>"),$("<span>").addClass("UIelement").append($("<h3>").text("Start the push").addClass("varbased")),{classes:["varbased"],label:"Use this variable",type:"str",help:"This variable should be used to determine if this push should be started.",prefix:"$",datalist:Object.keys(mist.data.variable_list||[]),pointer:{main:j,index:"startVariableName"}},{classes:["varbased"],label:"Comparison operator",type:"select",select:[[0,"is true"],[1,"is false"],[2,"=="],[3,"!="],[10,"> (numerical)"],[11,">= (numerical)"],
[12,"< (numerical)"],[13,"<= (numerical)"],[20,"> (lexical)"],[21,">= (lexical)"],[22,"< (lexical)"],[23,"<= (lexical)"]],value:2,css:{display:"none"},help:"How would you like to compare this variable?",pointer:{main:j,index:"startVariableOperator"},"function":function(){var a=n.find('[name="startVariableValue"]').closest(".UIelement");Number($(this).getval())<2?a.hide():a.css("display","")}},{classes:["varbased"],label:"Variable value",type:"str",help:"The variable will be compared with this value to determine if this push should be started.<br>You can also enter another variable here!",
[12,"< (numerical)"],[13,"<= (numerical)"],[20,"> (lexical)"],[21,">= (lexical)"],[22,"< (lexical)"],[23,"<= (lexical)"]],value:2,css:{display:"none"},help:"How would you like to compare this variable?",pointer:{main:j,index:"startVariableOperator"},"function":function(){var a=o.find('[name="startVariableValue"]').closest(".UIelement");Number($(this).getval())<2?a.hide():a.css("display","")}},{classes:["varbased"],label:"Variable value",type:"str",help:"The variable will be compared with this value to determine if this push should be started.<br>You can also enter another variable here!",
datalist:Object.values(mist.data.variable_list||[]).map(function(a){return typeof a=="string"?a:a[3]}).concat(Object.keys(mist.data.variable_list||[]).map(function(a){return"$"+a})),pointer:{main:j,index:"startVariableValue"}},$("<span>").addClass("UIelement").append($("<h3>").text("Stop the push").addClass("varbased")),{classes:["varbased"],label:"Use this variable",type:"str",help:"This variable should be used to determine if this push should be stopped.<br>You can leave this field blank if you do not want to have a stop condition. (You can always stop the push manually)",
prefix:"$",datalist:Object.keys(mist.data.variable_list||[]),pointer:{main:j,index:"endVariableName"}},{classes:["varbased"],label:"Comparison operator",type:"select",select:[[0,"is true"],[1,"is false"],[2,"=="],[3,"!="],[10,"> (numerical)"],[11,">= (numerical)"],[12,"< (numerical)"],[13,"<= (numerical)"],[20,"> (lexical)"],[21,">= (lexical)"],[22,"< (lexical)"],[23,"<= (lexical)"]],value:2,help:"How would you like to compare this variable?",pointer:{main:j,index:"endVariableOperator"},"function":function(){var a=
n.find('[name="endVariableValue"]').closest(".UIelement");Number($(this).getval())<2?a.hide():a.css("display","")}},{classes:["varbased"],label:"Variable value",type:"str",help:"The variable will be compared with this value to determine if this push should be stopped.<br>You can also enter another variable here!",datalist:Object.values(mist.data.variable_list||[]).map(function(a){return typeof a=="string"?a:a[3]}).concat(Object.keys(mist.data.variable_list||[]).map(function(a){return"$"+a})),pointer:{main:j,
index:"endVariableValue"}},{classes:["timebased"],type:"unix",label:"Start time",min:0,help:"The time where the push will become active. The default is to start immediately.",pointer:{main:j,index:"scheduletime"}},{classes:["timebased"],type:"unix",label:"End time",min:0,help:"The time where the push will stop. Defaults to never stop automatically.<br>Only makes sense for live streams.",pointer:{main:j,index:"completetime"}}],j));n.find(".activewhen").trigger("change")}k=[{label:"Stream name",type:"str",
o.find('[name="endVariableValue"]').closest(".UIelement");Number($(this).getval())<2?a.hide():a.css("display","")}},{classes:["varbased"],label:"Variable value",type:"str",help:"The variable will be compared with this value to determine if this push should be stopped.<br>You can also enter another variable here!",datalist:Object.values(mist.data.variable_list||[]).map(function(a){return typeof a=="string"?a:a[3]}).concat(Object.keys(mist.data.variable_list||[]).map(function(a){return"$"+a})),pointer:{main:j,
index:"endVariableValue"}},{classes:["timebased"],type:"unix",label:"Start time",min:0,help:"The time where the push will become active. The default is to start immediately.",pointer:{main:j,index:"scheduletime"}},{classes:["timebased"],type:"unix",label:"End time",min:0,help:"The time where the push will stop. Defaults to never stop automatically.<br>Only makes sense for live streams.",pointer:{main:j,index:"completetime"}}],j));o.find(".activewhen").trigger("change")}k=[{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:j,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:["orange"],"break":false}}],datalist:y},{label:"Target",type:"str",help:"Where the stream will be pushed to.<br> Valid push formats: <ul> <li>"+g.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+e.join("</li><li>")+
pointer:{main:j,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:["orange"],"break":false}}],datalist:y},{label:"Target",type:"str",help:"Where the stream will be pushed to.<br> Valid push formats: <ul> <li>"+g.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+
"</li> </ul> "+(i.length?"Additionally, the following protocols (from generic writers) may be used in combination with any of the above file formats:<ul><li>"+i.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> </ul>",
pointer:{main:j,index:"target"},validate:["required",function(a){for(var b in g)if(mist.inputMatch(g[b],a))return false;for(b in e){if(mist.inputMatch(e[b],a))return false;for(var c in i)if(mist.inputMatch(i[c]+e[b].slice(1),a))return false}return{msg:"Does not match a valid target.<br>Valid push formats: <ul> <li>"+g.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+e.join("</li><li>")+
"</li> </ul> "+(i.length?"Additionally, the following protocols may be used in combination with any of the above file formats:<ul><li>"+i.join("</li><li>")+"</li></ul>":""),classes:["red"]}}],"function":function(){var a=false,b=$(this).getval();for(connector in h)for(var c in h[connector]){if(mist.inputMatch(h[connector][c],b)){a=connector;break}if(h[connector][c][0]=="/")for(var d in i)if(mist.inputMatch(i[d]+h[connector][c].slice(1),b)){a=connector;break}}if(a){r.html($("<h3>").text(mist.data.capabilities.connectors[a].friendly.replace("over HTTP",
"")));o={};for(c in mist.data.capabilities.connectors[a].push_parameters){d=mist.data.capabilities.connectors[a].push_parameters[c];if(!d.prot_only||!(String().match&&b.match(/.+\:\/\/.+/)===null))d.file_only&&b[0]!="/"||(o[c]=d)}a={desc:mist.data.capabilities.connectors[a].desc.replace("over HTTP",""),optional:o,sort:"sort"};a=mist.convertBuildOptions(a,j.params);b=[];for(c in m){d=m[c].split("=");var f=d[0];f in o||b.push(f+(d.length>1?"="+d.slice(1).join("="):""))}a.push($("<br>"));a.push({type:"inputlist",
label:"Custom url parameters",value:b,classes:["custom_url_parameters"],input:{type:"str",placeholder:"name=value",prefix:""},help:"Any custom url parameters not covered by the parameters configurable above.",pointer:{main:j,index:"custom_url_params"}});r.append(UI.buildUI(a))}else r.html($("<h4>").addClass("red").text("Unrecognized target.")).append($("<span>").text("Please edit the push target."))}},n,r];k.push({type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Push")}},
{type:"save",label:"Save",preSave:function(){delete j.startVariableName;delete j.startVariableOperator;delete j.startVariableValue;delete j.endVariableName;delete j.endVariableOperator;delete j.endVariableValue;delete j.completetime;delete j.scheduletime},"function":function(){var c=j.params,d;for(d in c)c[d]===null?delete c[d]:d in o||delete c[d];if(j.startVariableName||j.endVariableName){j.scheduletime=0;j.completetime=0}if(j.startVariableName===null){delete j.startVariableName;delete j.startVariableOperator;
delete j.startVariableValue}if(j.endVariableName===null){delete j.endVariableName;delete j.endVariableOperator;delete j.endVariableValue}if(j.scheduletime)c.recstartunix=j.scheduletime;if(Object.keys(c).length||j.custom_url_params&&j.custom_url_params.length){var f="?",e=j.target.split("?");if(e.length>1){f="&";e=e[e.length-1];e=e.split("&");for(d in e){var g=e[d].split("=")[0];g in c&&delete c[g]}}if(Object.keys(c).length||j.custom_url_params&&j.custom_url_params.length){e=[];for(d in c)e.push(d+
"="+c[d]);for(d in j.custom_url_params)e.push(j.custom_url_params[d]);f=f+e.join("&");j.target=j.target+f}}delete j.params;delete j.custom_url_params;c={};c[b=="auto"?"push_auto_add":"push_start"]=j;if(typeof a!="undefined"&&(a[0]!=j.stream||a[1]!=j.target))c.push_auto_remove=[a];mist.send(function(){UI.navto("Push")},c)}}]});c.append(UI.buildUI(k))}};mist.data.LTS?mist.send(function(a){(y=a.active_streams)||(y=[]);var a=[],b;for(b in y)y[b].indexOf("+")!=-1&&a.push(y[b].replace(/\+.*/,"")+"+");y=
y.concat(a);var c=0,d=0;for(b in mist.data.streams){y.push(b);if(mist.inputMatch(UI.findInput("Folder").source_match,mist.data.streams[b].source)){y.push(b+"+");mist.send(function(a,b){var f=b.stream,e;for(e in a.browse.files)for(var g in mist.data.capabilities.inputs)g.indexOf("Buffer")>=0||(g.indexOf("Folder")>=0||g.indexOf("Buffer.exe")>=0||g.indexOf("Folder.exe")>=0)||mist.inputMatch(mist.data.capabilities.inputs[g].source_match,"/"+a.browse.files[e])&&y.push(f+"+"+a.browse.files[e]);d++;if(c==
pointer:{main:j,index:"target"},validate:["required",function(a){for(var b in g)if(mist.inputMatch(g[b],a))return false;for(b in f){if(mist.inputMatch(f[b],a))return false;for(var c in i)if(mist.inputMatch(i[c]+f[b].slice(1),a))return false}return{msg:"Does not match a valid target.<br>Valid push formats: <ul> <li>"+g.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+
"</li> </ul> "+(i.length?"Additionally, the following protocols may be used in combination with any of the above file formats:<ul><li>"+i.join("</li><li>")+"</li></ul>":""),classes:["red"]}}],"function":function(){var a=false,b=$(this).getval();for(connector in h)for(var c in h[connector]){if(mist.inputMatch(h[connector][c],b)){a=connector;break}if(h[connector][c][0]=="/")for(var d in i)if(mist.inputMatch(i[d]+h[connector][c].slice(1),b)){a=connector;break}}if(a){n.html($("<h3>").text(mist.data.capabilities.connectors[a].friendly.replace("over HTTP",
"")));p={};for(c in mist.data.capabilities.connectors[a].push_parameters){d=mist.data.capabilities.connectors[a].push_parameters[c];if(!d.prot_only||!(String().match&&b.match(/.+\:\/\/.+/)===null))d.file_only&&b[0]!="/"||(p[c]=d)}a={desc:mist.data.capabilities.connectors[a].desc.replace("over HTTP",""),optional:p,sort:"sort"};a=mist.convertBuildOptions(a,j.params);b=[];for(c in m){d=m[c].split("=");var e=d[0];e in p||b.push(e+(d.length>1?"="+d.slice(1).join("="):""))}a.push($("<br>"));a.push({type:"inputlist",
label:"Custom url parameters",value:b,classes:["custom_url_parameters"],input:{type:"str",placeholder:"name=value",prefix:""},help:"Any custom url parameters not covered by the parameters configurable above.",pointer:{main:j,index:"custom_url_params"}});n.append(UI.buildUI(a))}else n.html($("<h4>").addClass("red").text("Unrecognized target.")).append($("<span>").text("Please edit the push target."))}},o,n];k.push({type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Push")}},
{type:"save",label:"Save",preSave:function(){delete j.startVariableName;delete j.startVariableOperator;delete j.startVariableValue;delete j.endVariableName;delete j.endVariableOperator;delete j.endVariableValue;delete j.completetime;delete j.scheduletime},"function":function(){var c=j.params,d;for(d in c)c[d]===null?delete c[d]:d in p||delete c[d];if(j.startVariableName||j.endVariableName){j.scheduletime=0;j.completetime=0}if(j.startVariableName===null){delete j.startVariableName;delete j.startVariableOperator;
delete j.startVariableValue}if(j.endVariableName===null){delete j.endVariableName;delete j.endVariableOperator;delete j.endVariableValue}if(j.scheduletime)c.recstartunix=j.scheduletime;if(Object.keys(c).length||j.custom_url_params&&j.custom_url_params.length){var e="?",f=j.target.split("?");if(f.length>1){e="&";f=f[f.length-1];f=f.split("&");for(d in f){var g=f[d].split("=")[0];g in c&&delete c[g]}}if(Object.keys(c).length||j.custom_url_params&&j.custom_url_params.length){f=[];for(d in c)f.push(d+
"="+c[d]);for(d in j.custom_url_params)f.push(j.custom_url_params[d]);e=e+f.join("&");j.target=j.target+e}}delete j.params;delete j.custom_url_params;c={};c[b=="auto"?"push_auto_add":"push_start"]=j;if(typeof a!="undefined"&&(a[0]!=j.stream||a[1]!=j.target))c.push_auto_remove=[a];mist.send(function(){UI.navto("Push")},c)}}]});c.append(UI.buildUI(k))}};mist.data.LTS?mist.send(function(a){(y=a.active_streams)||(y=[]);var a=[],b;for(b in y)y[b].indexOf("+")!=-1&&a.push(y[b].replace(/\+.*/,"")+"+");y=
y.concat(a);var c=0,d=0;for(b in mist.data.streams){y.push(b);if(mist.inputMatch(UI.findInput("Folder").source_match,mist.data.streams[b].source)){y.push(b+"+");mist.send(function(a,b){var e=b.stream,f;for(f in a.browse.files)for(var g in mist.data.capabilities.inputs)g.indexOf("Buffer")>=0||(g.indexOf("Folder")>=0||g.indexOf("Buffer.exe")>=0||g.indexOf("Folder.exe")>=0)||mist.inputMatch(mist.data.capabilities.inputs[g].source_match,"/"+a.browse.files[f])&&y.push(e+"+"+a.browse.files[f]);d++;if(c==
d){y=y.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();ka()}},{browse:mist.data.streams[b].source},{stream:b});c++}}if(c==d){y=y.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();ka()}},{active_streams:1}):(y=Object.keys(mist.data.streams),ka());break;case "Triggers":if(!("triggers"in mist.data.config)||!mist.data.config.triggers)mist.data.config.triggers={};var F=$("<tbody>"),cb=$("<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(F);c.append(UI.buildUI([{type:"help",help:"Triggers are a way 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(cb);
cb.stupidtable();var xa=mist.data.config.triggers;for(r in xa)for(var db in xa[r]){var ya=triggerRewrite(xa[r][db]);F.append($("<tr>").attr("data-index",r+","+db).append($("<td>").text(r)).append($("<td>").text("streams"in ya?ya.streams.join(", "):"")).append($("<td>").text(ya.handler)).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":if(!("triggers"in mist.data.config)||!mist.data.config.triggers)mist.data.config.triggers={};if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");
return}if(b)var b=b.split(","),ca=triggerRewrite(mist.data.config.triggers[b[0]][b[1]]),p={triggeron:b[0],appliesto:ca.streams,url:ca.handler,async:ca.sync,"default":ca["default"],params:ca.params};else c.html($("<h2>").text("New Trigger")),p={};var eb=[];for(r in mist.data.capabilities.triggers)eb.push([r,r+": "+mist.data.capabilities.triggers[r].when]);var za=$("<div>").addClass("desc"),fb=$("<div>");c.append(UI.buildUI([{label:"Trigger on",pointer:{main:p,index:"triggeron"},help:"For what event this trigger should activate.",
return}if(b)var b=b.split(","),ca=triggerRewrite(mist.data.config.triggers[b[0]][b[1]]),n={triggeron:b[0],appliesto:ca.streams,url:ca.handler,async:ca.sync,"default":ca["default"],params:ca.params};else c.html($("<h2>").text("New Trigger")),n={};var eb=[];for(r in mist.data.capabilities.triggers)eb.push([r,r+": "+mist.data.capabilities.triggers[r].when]);var za=$("<div>").addClass("desc"),fb=$("<div>");c.append(UI.buildUI([{label:"Trigger on",pointer:{main:n,index:"triggeron"},help:"For what event this trigger should activate.",
type:"select",select:eb,validate:["required"],"function":function(){var a=$(this).getval(),b=mist.data.capabilities.triggers[a];za.html("");if(b){a=[$("<h4>").text("Trigger properties"),{type:"help",help:'The trigger "<i>'+a+'</i>" has the following properties:'},{type:"span",label:"Triggers",value:b.when,help:"When this trigger is activated"}];b.payload!=""&&a.push({label:"Payload",type:"textarea",value:b.payload,rows:b.payload.split("\n").length,readonly:true,clipboard:true,help:"The information this trigger sends to the handler."});
a.push({type:"span",label:"Requires response",value:function(a){switch(a){case "ignored":return"No. The trigger will ignore the response of the handler.";case "always":return"Yes. The trigger needs a response to proceed.";case "when-blocking":return"The trigger needs a response to proceed if it is configured to be blocking.";default:return a}}(b.response),help:"Whether this trigger requires a response from the trigger handler"});a.push({type:"span",label:"Response action",value:b.response_action,
help:"What this trigger will do with its handler's response"});za.append(UI.buildUI(a));b.stream_specific?$("[name=appliesto]").closest(".UIelement").show():$("[name=appliesto]").setval([]).closest(".UIelement").hide();if(b.argument){$("[name=params]").closest(".UIelement").show();fb.text(b.argument)}else $("[name=params]").setval("").closest(".UIelement").hide()}}},za,$("<h4>").text("Trigger settings"),{label:"Applies to",pointer:{main:p,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)},$("<br>"),{label:"Handler (URL or executable)",help:"This can be either an HTTP URL or a full path to an executable.",pointer:{main:p,index:"url"},validate:["required"],type:"str"},{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:p,index:"async"}},{label:"Parameters",type:"str",help:$("<div>").text("The extra data you want this trigger to use.").append(fb),pointer:{main:p,index:"params"}},{label:"Default response",type:"str",help:"The default response in case the handler fails or is set to non-blocking.",placeholder:"true",pointer:{main:p,index:"default"}},{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={handler:p.url,sync:p.async?true:false,streams:typeof p.appliesto=="undefined"?[]:p.appliesto,params:p.params,"default":p["default"]};if(!("triggers"in mist.data.config))mist.data.config.triggers={};p.triggeron in mist.data.config.triggers||(mist.data.config.triggers[p.triggeron]=[]);mist.data.config.triggers[p.triggeron].push(a);mist.send(function(){UI.navto("Triggers")},{config:mist.data.config})}}]}]));$("[name=triggeron]").trigger("change");break;case "Logs":var gb=$("<button>").text("Refresh now").click(function(){$(this).text("Loading..");
help:"What this trigger will do with its handler's response"});za.append(UI.buildUI(a));b.stream_specific?$("[name=appliesto]").closest(".UIelement").show():$("[name=appliesto]").setval([]).closest(".UIelement").hide();if(b.argument){$("[name=params]").closest(".UIelement").show();fb.text(b.argument)}else $("[name=params]").setval("").closest(".UIelement").hide()}}},za,$("<h4>").text("Trigger settings"),{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)},$("<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"},{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"}},{label:"Parameters",type:"str",help:$("<div>").text("The extra data you want this trigger to use.").append(fb),pointer:{main:n,index:"params"}},{label:"Default response",type:"str",help:"The default response in case the handler fails or is set to non-blocking.",placeholder:"true",pointer:{main:n,index:"default"}},{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={handler:n.url,sync:n.async?true:false,streams:typeof n.appliesto=="undefined"?[]:n.appliesto,params:n.params,"default":n["default"]};if(!("triggers"in mist.data.config))mist.data.config.triggers={};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 gb=$("<button>").text("Refresh now").click(function(){$(this).text("Loading..");
mist.send(function(){Aa();gb.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(){Aa()})},
$(this).val()*1E3)},help:"How often the table below should be updated."},{label:"..or",type:"DOMfield",DOMfield:gb,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})}));F=$("<tbody>").css("font-size","0.9em");c.append($("<table>").addClass("logs").append(F));var kb=function(a){var b=$("<span>").text(a);switch(a){case "WARN":b.addClass("orange");break;case "ERROR":case "FAIL":b.addClass("red")}return b},
Aa=function(){var a=mist.data.log;if(a){a.length>=2&&a[0][0]<a[a.length-1][0]&&a.reverse();F.html("");for(var b in a){var c=$("<span>").addClass("content"),d=a[b][2].split("|"),f;for(f in d)c.append($("<span>").text(d[f]));F.append($("<tr>").html($("<td>").text(UI.format.dateTime(a[b][0],"long")).css("white-space","nowrap")).append($("<td>").html(kb(a[b][1])).css("text-align","center")).append($("<td>").html(c).css("text-align","left")))}}};Aa();break;case "Statistics":var H=$("<span>").text("Loading..");
c.append(H);var p={graph:"new"},B=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},da={};for(r in mist.data.streams)da[r]=!0;for(r in mist.data.active_streams)da[mist.data.active_streams[r]]=!0;var da=Object.keys(da).sort(),Ba=[];for(r in mist.data.config.protocols)Ba.push(mist.data.config.protocols[r].connector);Ba.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;H.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:p,index:"graph"},classes:["graph_ids"],"function":function(){if($(this).val()){var a=H.find(".graph_xaxis"),b=H.find(".graph_id");if($(this).val()=="new"){a.children("option").prop("disabled",
false);b.setval("Graph "+(Object.keys(B).length+1)).closest("label").show()}else{var c=B[$(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:p,index:"id"},classes:["graph_id"],validate:[function(a){return a in B?{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:p,index:"xaxis"},value:"time",classes:["graph_xaxis"],"function":function(){$s=H.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"],["perc_lost","Lost packages"],["perc_retrans","Re-transmitted packages"]],pointer:{main:p,index:"datatype"},classes:["graph_datatype"],"function":function(){$s=H.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:",da],["protocol","The protocol:",Ba]],pointer:{main:p,index:"origin"},value:["total"],classes:["graph_origin"]},{type:"buttons",buttons:[{label:"Add data set",type:"save","function":function(){var a;if(p.graph=="new"){a=UI.plot.addGraph(p,b);B[a.id]=a;H.find("input.graph_id").val("");
H.find("select.graph_ids").append($("<option>").text(a.id)).val(a.id).trigger("change")}else a=B[p.graph];var c=UI.plot.datatype.getOptions({datatype:p.datatype,origin:p.origin});a.datasets.push(c);UI.plot.save(a);UI.plot.go(B)}}]}]));var b=$("<div>").addClass("graph_container");c.append(b);var d=H.find("select.graph_ids");for(a in B){var f=UI.plot.addGraph(B[a],b);d.append($("<option>").text(f.id)).val(f.id);var e=[],g;for(g in B[a].datasets){var h=UI.plot.datatype.getOptions({datatype:B[a].datasets[g].datatype,
origin:B[a].datasets[g].origin});e.push(h)}f.datasets=e;B[f.id]=f}d.trigger("change");UI.plot.go(B);UI.interval.set(function(){UI.plot.go(B)},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 Ca=$("<table>"),O=$("<table>"),hb={vheader:"CPUs",labels:["Model","Processor speed","Amount of cores","Amount of threads"],content:[]};for(r in mist.data.capabilities.cpu){var la=
Aa=function(){var a=mist.data.log;if(a){a.length>=2&&a[0][0]<a[a.length-1][0]&&a.reverse();F.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]));F.append($("<tr>").html($("<td>").text(UI.format.dateTime(a[b][0],"long")).css("white-space","nowrap")).append($("<td>").html(kb(a[b][1])).css("text-align","center")).append($("<td>").html(c).css("text-align","left")))}}};Aa();break;case "Statistics":var H=$("<span>").text("Loading..");
c.append(H);var n={graph:"new"},B=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},da={};for(r in mist.data.streams)da[r]=!0;for(r in mist.data.active_streams)da[mist.data.active_streams[r]]=!0;var da=Object.keys(da).sort(),Ba=[];for(r in mist.data.config.protocols)Ba.push(mist.data.config.protocols[r].connector);Ba.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;H.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=H.find(".graph_xaxis"),b=H.find(".graph_id");if($(this).val()=="new"){a.children("option").prop("disabled",
false);b.setval("Graph "+(Object.keys(B).length+1)).closest("label").show()}else{var c=B[$(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 B?{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=H.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"],["perc_lost","Lost packages"],["perc_retrans","Re-transmitted packages"]],pointer:{main:n,index:"datatype"},classes:["graph_datatype"],"function":function(){$s=H.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:",da],["protocol","The protocol:",Ba]],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);B[a.id]=a;H.find("input.graph_id").val("");
H.find("select.graph_ids").append($("<option>").text(a.id)).val(a.id).trigger("change")}else a=B[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(B)}}]}]));var b=$("<div>").addClass("graph_container");c.append(b);var d=H.find("select.graph_ids");for(a in B){var e=UI.plot.addGraph(B[a],b);d.append($("<option>").text(e.id)).val(e.id);var f=[],g;for(g in B[a].datasets){var h=UI.plot.datatype.getOptions({datatype:B[a].datasets[g].datatype,
origin:B[a].datasets[g].origin});f.push(h)}e.datasets=f;B[e.id]=e}d.trigger("change");UI.plot.go(B);UI.interval.set(function(){UI.plot.go(B)},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 Ca=$("<table>"),O=$("<table>"),hb={vheader:"CPUs",labels:["Model","Processor speed","Amount of cores","Amount of threads"],content:[]};for(r in mist.data.capabilities.cpu){var la=
mist.data.capabilities.cpu[r];hb.content.push({header:"CPU #"+(Number(r)+1),body:[la.model,UI.format.addUnit(UI.format.number(la.mhz),"MHz"),la.cores,la.threads]})}var lb=UI.buildVheaderTable(hb),ib=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);Ca.replaceWith(a);Ca=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);O.replaceWith(b);O=b};ib();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(Ca)).append($("<td>").append(O))).append($("<tr>").append($("<td>").append(lb).attr("colspan",2))));UI.interval.set(function(){mist.send(function(){ib()},
{capabilities:true})},3E4);break;case "Email for Help":var I=$.extend({},mist.data);delete I.statistics;delete I.totals;delete I.clients;delete I.capabilities;I=JSON.stringify(I);I="Version: "+mist.data.config.version+"\n\nConfig:\n"+I;p={};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:p,
index:"name"},value:mist.user.name},{type:"email",label:"Your email address",validate:["required"],pointer:{main:p,index:"email"}},{type:"hidden",value:"Integrated Help",pointer:{main:p,index:"subject"}},{type:"hidden",value:"-",pointer:{main:p,index:"company"}},{type:"textarea",rows:20,label:"Your message",validate:["required"],pointer:{main:p,index:"message"}},{type:"textarea",rows:20,label:"Your config file",readonly:!0,value:I,pointer:{main:p,index:"configfile"}},{type:"buttons",buttons:[{type:"save",
label:"Send","function":function(a){$(a).text("Sending..");$.ajax({type:"POST",url:"https://mistserver.org/contact?skin=plain",data:p,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(){var a=$(this).getval();
{capabilities:true})},3E4);break;case "Email for Help":var I=$.extend({},mist.data);delete I.statistics;delete I.totals;delete I.clients;delete I.capabilities;I=JSON.stringify(I);I="Version: "+mist.data.config.version+"\n\nConfig:\n"+I;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:I,pointer:{main:n,index:"configfile"}},{type:"buttons",buttons:[{type:"save",
label:"Send","function":function(a){$(a).text("Sending..");$.ajax({type:"POST",url:"https://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(){var a=$(this).getval();
return a==""||a==null?true:false}).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+"//");var host;host="file://"==location.origin?"http://localhost:4242/api":location.origin+location.pathname.replace(/\/+$/,"")+"/api";
var mist={data:{},user:{name:"",password:"",host:host},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));var e={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,j){console.warn("connection failed :(",
j);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($("<span>").text(e)).append($("<a>").text("Send server request again").click(function(){mist.send(a,b,c)}))}UI.navto("Login")},
success:function(e){log("Receive",$.extend(true,{},e),"as reply to",c.sendData);delete mist.user.loggedin;switch(e.authorize.status){case "OK":if("streams"in e)if(e.streams)if("incomplete list"in e.streams){delete e.streams["incomplete list"];$.extend(mist.data.streams,e.streams)}else mist.data.streams=e.streams;else mist.data.streams={};var h=$.extend({},e),j=["config","capabilities","ui_settings","LTS","active_streams","browse","log","totals","bandwidth","variable_list","external_writer_list"],
o;for(o in h)j.indexOf(o)==-1&&delete h[o];if("bandwidth"in d&&!("bandwidth"in e))h.bandwidth=null;$.extend(mist.data,h);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));if(e.log){h=e.log[e.log.length-1];UI.elements.connection.msg.append($("<br>")).append($("<span>").text("Last log entry: "+
UI.format.time(h[0])+" ["+h[1]+"] "+h[2]))}if("totals"in e){h=function(a,b,c){var d;d=function(){for(var a in c.fields)e[c.fields[a]].push([m,0])};var e={},h;for(h in c.fields)e[c.fields[h]]=[];var j=0,m;if(c.data){if(c.start>mist.data.config.time-600){m=(mist.data.config.time-600)*1E3;d();m=c.start*1E3;d()}else m=c.start*1E3;for(h in c.data){if(h==0){m=c.start*1E3;var o=0}else{m=m+c.interval[o][1]*1E3;c.interval[o][0]--;if(c.interval[o][0]<=0){o++;o<c.interval.length-1&&(j=j+2)}}if(j%2==1){d();j--}for(var t in c.data[h])e[c.fields[t]].push([m,
p;for(p in h)j.indexOf(p)==-1&&delete h[p];if("bandwidth"in d&&!("bandwidth"in e))h.bandwidth=null;$.extend(mist.data,h);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));if(e.log){h=e.log[e.log.length-1];UI.elements.connection.msg.append($("<br>")).append($("<span>").text("Last log entry: "+
UI.format.time(h[0])+" ["+h[1]+"] "+h[2]))}if("totals"in e){h=function(a,b,c){var d;d=function(){for(var a in c.fields)e[c.fields[a]].push([m,0])};var e={},h;for(h in c.fields)e[c.fields[h]]=[];var j=0,m;if(c.data){if(c.start>mist.data.config.time-600){m=(mist.data.config.time-600)*1E3;d();m=c.start*1E3;d()}else m=c.start*1E3;for(h in c.data){if(h==0){m=c.start*1E3;var p=0}else{m=m+c.interval[p][1]*1E3;c.interval[p][0]--;if(c.interval[p][0]<=0){p++;p<c.interval.length-1&&(j=j+2)}}if(j%2==1){d();j--}for(var t in c.data[h])e[c.fields[t]].push([m,
c.data[h][t]]);if(j){d();j--}}if(mist.data.config.time-c.end>20){d();m=(mist.data.config.time-15)*1E3;d()}}else{m=(mist.data.config.time-600)*1E3;d();m=(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 e.totals)h(b.totals.streams,
b.totals.protocols,e.totals);else for(o in e.totals)h(b.totals[o].streams,b.totals[o].protocols,e.totals[o])}a&&a(e,c);break;case "CHALL":if(e.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=e.authorize.challenge;mist.send(a,b,c);sessionStorage.setItem("mistLogin",JSON.stringify({host:mist.user.host,
b.totals.protocols,e.totals);else for(p in e.totals)h(b.totals[p].streams,b.totals[p].protocols,e.totals[p])}a&&a(e,c);break;case "CHALL":if(e.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=e.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(){j.abort()}));var j=$.ajax(e)},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,".*");if(RegExp("^(?:[a-zA-Z]:)?"+d+"(?:\\?[^\\?]*)?$","i").test(b))return true}return false},convertBuildOptions:function(a,b){function c(a,c,d){var f={label:UI.format.capital(d.name?d.name:c),pointer:{main:b,index:c},validate:[]};e[a]=="required"&&(!("default"in d)||d["default"]=="")&&f.validate.push("required");if("default"in d){f.placeholder=d["default"];if(d.type=="select")for(var h in d.select)if(d.select[h][0]==d["default"]){f.placeholder=
d.select[h][1];break}}if("help"in d)f.help=d.help;if("unit"in d)f.unit=d.unit;if("placeholder"in d)f.placeholder=d.placeholder;if("type"in d)switch(d.type){case "int":f.type="int";if("max"in d)f.max=d.max;if("min"in d)f.min=d.min;break;case "uint":f.type="int";f.min=0;if("max"in d)f.max=d.max;if("min"in d)f.min=Math.max(f.min,d.min);break;case "radioselect":f.type="radioselect";f.radioselect=d.radioselect;break;case "select":f.type="select";f.select=d.select.slice(0);f.validate.indexOf("required")>=
@ -277,7 +278,7 @@ d.select[h][1];break}}if("help"in d)f.help=d.help;if("unit"in d)f.unit=d.unit;if
delete a.main[a.index]}}"influences"in d?f["function"]=function(){var a=$(this).closest(".UIelement"),b=a.find("style");if(b.length)b=b[0];else{b=$("<style>").addClass("dependencies")[0];a.append(b)}b.innerHTML=".UIelement[data-dependent-"+c+"]:not([data-dependent-"+c+'~="'+$(this).getval()+'"]) { display: none; }\n';$(b).data("content",b.innerHTML);$("style.dependencies.hidden").each(function(){$(this).html($(this).data("content")).removeClass("hidden")});$(".UIelement:not(:visible) style.dependencies:not(.hidden)").each(function(){$(this).addClass("hidden");
$(this).html("")})}:"disable"in d&&(f["function"]=function(){for(var a=$(this).closest(".input_container"),b=$(this).getval(),c=0;c<d.disable.length;c++){var e=a.find('.field[name="'+d.disable[c]+'"]').closest(".UIelement");if(e.length)b==""?e[0].style.display="":e.hide()}});if("dependent"in d)f.dependent=d.dependent;if("value"in d)f.value=d.value;if("validate"in d){f.validate=f.validate.concat(d.validate);if(d.validate.indexOf("track_selector_parameter")>-1)f.help="<div>"+d.help+"</div><p>Track selector parameters consist of a string value which may be any of the following:</p> <ul><li><code>selector,selector</code>: Selects the union of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,!selector</code>: Selects the difference of the given selectors. Specifically, all tracks part of the first selector that are not part of the second selector. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,|selector</code>: Selects the intersection of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>none</code> or <code>-1</code>: Selects no tracks of this type.</li> <li><code>all</code> or <code>*</code>: Selects all tracks of this type.</li> <li>Any positive integer: Select this specific track ID. Does not apply if the given track ID does not exist or is of the wrong type. <strong>Does</strong> apply if the given track ID is incompatible with the currently active protocol or container format.</li> <li>ISO 639-1/639-3 language code: Select all tracks marked as the given language. Case insensitive.</li> <li>Codec string (e.g. <code>h264</code>): Select all tracks of the given codec. Case insensitive.</li> <li><code>highbps</code>, <code>maxbps</code> or <code>bestbps</code>: Select the track of this type with the highest bit rate.</li> <li><code>lowbps</code>, <code>minbps</code> or <code>worstbps</code>: Select the track of this type with the lowest bit rate.</li> <li><code>Xbps</code> or <code>Xkbps</code> or <code>Xmbps</code>: Select the single of this type which has a bit rate closest to the given number X. This number is in bits, not bytes.</li> <li><code>&gt;Xbps</code> or <code>&gt;Xkbps</code> or <code>&gt;Xmbps</code>: Select all tracks of this type which have a bit rate greater than the given number X. This number is in bits, not bytes.</li> <li><code>&lt;Xbps</code> or <code>&lt;Xkbps</code> or <code>&lt;Xmbps</code>: Select all tracks of this type which have a bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>max&lt;Xbps</code> or <code>max&lt;Xkbps</code> or <code>max&lt;Xmbps</code>: Select the one track of this type which has the highest bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>highres</code>, <code>maxres</code> or <code>bestres</code>: Select the track of this type with the highest pixel surface area. Only applied when the track type is video.</li> <li><code>lowres</code>, <code>minres</code> or <code>worstres</code>: Select the track of this type with the lowest pixel surface area. Only applied when the track type is video.</li> <li><code>XxY</code>: Select all tracks of this type with the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>~XxY</code>: Select the single track of this type closest to the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>&gt;XxY</code>: Select all tracks of this type with a pixel surface area greater than X by Y pixels. Only applied when the track type is video.</li> <li><code>&lt;XxY</code>: Select all tracks of this type with a pixel surface area less than X by Y pixels. Only applied when the track type is video.</li> <li><code>720p</code>, <code>1080p</code>, <code>1440p</code>, <code>2k</code>, <code>4k</code>, <code>5k</code>, or <code>8k</code>: Select all tracks of this type with the given pixel surface area. Only applied when the track type is video.</li> <li><code>surround</code>, <code>mono</code>, <code>stereo</code>, <code>Xch</code>: Select all tracks of this type with the given channel count. The 'Xch' variant can use any positive integer for 'X'. Only applied when the track type is audio.</li></ul>";
if(d.validate.indexOf("track_selector")>-1)f.help="<div>"+d.help+"</div><p>A track selector is at least one track type (audio, video or subtitle) combined with a track selector parameter. For example: <code>audio=none&video=maxres</code>.<p>Track selector parameters consist of a string value which may be any of the following:</p> <ul><li><code>selector,selector</code>: Selects the union of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,!selector</code>: Selects the difference of the given selectors. Specifically, all tracks part of the first selector that are not part of the second selector. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>selector,|selector</code>: Selects the intersection of the given selectors. Any number of comma-separated selector combinations may be used, they are evaluated one by one from left to right.</li> <li><code>none</code> or <code>-1</code>: Selects no tracks of this type.</li> <li><code>all</code> or <code>*</code>: Selects all tracks of this type.</li> <li>Any positive integer: Select this specific track ID. Does not apply if the given track ID does not exist or is of the wrong type. <strong>Does</strong> apply if the given track ID is incompatible with the currently active protocol or container format.</li> <li>ISO 639-1/639-3 language code: Select all tracks marked as the given language. Case insensitive.</li> <li>Codec string (e.g. <code>h264</code>): Select all tracks of the given codec. Case insensitive.</li> <li><code>highbps</code>, <code>maxbps</code> or <code>bestbps</code>: Select the track of this type with the highest bit rate.</li> <li><code>lowbps</code>, <code>minbps</code> or <code>worstbps</code>: Select the track of this type with the lowest bit rate.</li> <li><code>Xbps</code> or <code>Xkbps</code> or <code>Xmbps</code>: Select the single of this type which has a bit rate closest to the given number X. This number is in bits, not bytes.</li> <li><code>&gt;Xbps</code> or <code>&gt;Xkbps</code> or <code>&gt;Xmbps</code>: Select all tracks of this type which have a bit rate greater than the given number X. This number is in bits, not bytes.</li> <li><code>&lt;Xbps</code> or <code>&lt;Xkbps</code> or <code>&lt;Xmbps</code>: Select all tracks of this type which have a bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>max&lt;Xbps</code> or <code>max&lt;Xkbps</code> or <code>max&lt;Xmbps</code>: Select the one track of this type which has the highest bit rate less than the given number X. This number is in bits, not bytes.</li> <li><code>highres</code>, <code>maxres</code> or <code>bestres</code>: Select the track of this type with the highest pixel surface area. Only applied when the track type is video.</li> <li><code>lowres</code>, <code>minres</code> or <code>worstres</code>: Select the track of this type with the lowest pixel surface area. Only applied when the track type is video.</li> <li><code>XxY</code>: Select all tracks of this type with the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>~XxY</code>: Select the single track of this type closest to the given pixel surface area in X by Y pixels. Only applied when the track type is video.</li> <li><code>&gt;XxY</code>: Select all tracks of this type with a pixel surface area greater than X by Y pixels. Only applied when the track type is video.</li> <li><code>&lt;XxY</code>: Select all tracks of this type with a pixel surface area less than X by Y pixels. Only applied when the track type is video.</li> <li><code>720p</code>, <code>1080p</code>, <code>1440p</code>, <code>2k</code>, <code>4k</code>, <code>5k</code>, or <code>8k</code>: Select all tracks of this type with the given pixel surface area. Only applied when the track type is video.</li> <li><code>surround</code>, <code>mono</code>, <code>stereo</code>, <code>Xch</code>: Select all tracks of this type with the given channel count. The 'Xch' variant can use any positive integer for 'X'. Only applied when the track type is audio.</li></ul>"}return f}
var d=[],e=["required","optional"];"desc"in a&&d.push({type:"help",help:a.desc});for(var j in e)if(a[e[j]]){d.push($("<h4>").text(UI.format.capital(e[j])+" parameters"));var m=Object.keys(a[e[j]]);"sort"in a&&m.sort(function(b,c){return(""+a[e[j]][b][a.sort]).localeCompare(a[e[j]][c][a.sort])});for(var h in m){var t=m[h],o=a[e[j]][t];if(Array.isArray(o))for(var l in o)d.push(c(j,t,o[l]));else d.push(c(j,t,o))}}return d},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,b){var c=
var d=[],e=["required","optional"];"desc"in a&&d.push({type:"help",help:a.desc});for(var j in e)if(a[e[j]]){d.push($("<h4>").text(UI.format.capital(e[j])+" parameters"));var m=Object.keys(a[e[j]]);"sort"in a&&m.sort(function(b,c){return(""+a[e[j]][b][a.sort]).localeCompare(a[e[j]][c][a.sort])});for(var h in m){var t=m[h],p=a[e[j]][t];if(Array.isArray(p))for(var l in p)d.push(c(j,t,p[l]));else d.push(c(j,t,p))}}return d},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 "int":b!=""&&(b=Number(b));break;case "span":b=$(this).html();break;case "debug":b=$(this).val()==""?null:Number($(this).val());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"))});break;case "unix":b!=""&&(b=Math.round(new Date($(this).val())/1E3));break;case "selectinput":b=$(this).children("select").first().val();b=="CUSTOM"&&(b=$(this).children("label").first().find(".field_container").children().first().getval());break;case "inputlist":b=[];$(this).find(".field").each(function(){$(this).getval()!=""&&b.push($(this).getval())});break;case "sublist":b=$(this).data("savelist");

View file

@ -4325,6 +4325,27 @@ var UI = {
send.stop_sessions = other;
delete saveas.stop_sessions;
}
var type = null;
for (var i in mist.data.capabilities.inputs) {
if (typeof mist.data.capabilities.inputs[i].source_match == 'undefined') { continue; }
if (mist.inputMatch(mist.data.capabilities.inputs[i].source_match,saveas.source)) {
type = i;
break;
}
}
if (type) {
//sanatize saveas, remove options not in capabilities
var input = mist.data.capabilities.inputs[type];
for (var i in saveas) {
if ((i == "name") || (i == "source") || (i == "stop_sessions") || (i == "processes")) { continue; }
if (("optional" in input) && (i in input.optional)) { continue; }
if (("required" in input) && (i in input.required)) { continue; }
if ((i == "always_on") && ("always_match" in input) && (mist.inputMatch(input.always_match,saveas.source))) { continue; }
delete saveas[i];
}
}
mist.send(function(){
delete mist.data.streams[saveas.name].online;
delete mist.data.streams[saveas.name].error;