Compare commits

..

10 commits

Author SHA1 Message Date
Cat
bae853e0c0 LSP Stream status page:
- reCSSification
- added tablike navigation instead of big buttons, created header module
- embed page: use findMist module and improve url calculation
- clean up streams page, don't erase selection on readonly fields, fix minify errors ;_;
- Tags: listen to Enter, fix remove button
- General: make dashboard items claim the full line, even when empty
- Active pushes: removed log messages
- Auto pushes: removed stop all button; don't set retry to 0
- Processes: do not justify logs; fix old process removal
- Logs: added "view raw" buttons that open new window
- pushes are now in a table
- finished? maybe?
- push stats now update
- added track timing graph
- restructure: dashboard sections are reusable modules that work independently
- most issues ironed out
- also use module for bigbuttons and more cleanup
- horizontal automatic push table
- added right click menu
- (browse) folder support
- overview looks okay with new dark skin
- page improvements and dark skin tweaks
- overview: paginization, thumbnail mode
- page: remove old streams page
- store prefered page size
- streams page: added text to explain left click action
- add stream source as title
LSP: add long press = right click converter
LSP: pagecontrols: add 'jump to' select box, skin tweaks
LSP: stream names can start with a number :)
LSP: thumbnail module: open the (non moving) jpeg source by default, switch to mjpeg on hover
LSP: active streams websocket: repeatedly send messages to poke MistServer to send updates. Very ugly patch - backend should be updated so this is not needed.
Embed: chromecast: remove error message when cast is not supported
2024-11-21 16:14:42 +01:00
Cat
8737392b51 LSP:
- Forward min/maxlength for strings in convertBuildOptions
- Input validation: added default html5 validation when available + bugfix for onchange validation
TSSRT: added minlength and maxlength to passphrase setting
2024-11-21 15:49:20 +01:00
Cat
13845ca4fc LSP:
- Bugfix for input options categories in checking if there are custom parameters in a push url
- Option groups now have an ability to expand/collapse. When collapsed a summary of non-default configured options is shown.
- Question marks in the target should be kept as part of the target url. Additional params should always be added after an additional ?.
- Improved (mostly SRT) push param options layout
- Fixed option groups:
  - 1: Typing in PUSH TARGET will reset all settings set up below
  - 2: If you hide settings the settings do not propogate
  - 3: Sublist and option categories share the same container class name, causing CSS collisions
2024-11-21 15:30:18 +01:00
Thulinma
e981e26100 Update libsrt wrap to target v1.5.3 2024-11-11 15:17:21 +01:00
Thulinma
9f18c39ada Rewrite SRT implementation to use generic UDP sockets for listeners, then only init the SRT library post-fork so that we can use a process per connection like everywhere else 2024-11-11 15:13:36 +01:00
Thulinma
3d62b9b35d Prevent AAC and FLV input keepRunning overrides from hiding generic functions 2024-09-24 15:28:36 +02:00
Marco van Dijk
ee853b1ffb Change Input::keepRunning to be more generic, override it in MistInBuffer and MistInHLS 2024-09-24 15:18:01 +02:00
Marco van Dijk
8830a87642 Fixes to SegmentReader: do not call tsStream.finish() early, fix stopping early 2024-09-24 15:17:39 +02:00
Marco van Dijk
c379a9e686 Fixes to urireader: continue without range request support if HEAD request fails; close socket on error 2024-09-24 15:17:39 +02:00
Marco van Dijk
acea07e3ec Util: add fstream import, which was removed from urireader 2024-09-24 15:17:39 +02:00
66 changed files with 4012 additions and 2143 deletions

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
mistplayers.dashjs={name:"Dash.js player",mimes:["dash/video/mp4"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return MistUtil.array.indexOf(this.mimes,e)==-1?false:true},isBrowserSupported:function(e,t,i){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(location.protocol=="file:"){i.log("This source ("+e+") won't load if the page is run via file://");return false}if(!("MediaSource"in window)){return false}if(!MediaSource.isTypeSupported){return true}var r={};var a=false;for(var s in i.info.meta.tracks){if(i.info.meta.tracks[s].type=="meta"){if(i.info.meta.tracks[s].codec=="subtitle"){a=true}continue}if(!(i.info.meta.tracks[s].type in r)){r[i.info.meta.tracks[s].type]={}}r[i.info.meta.tracks[s].type][MistUtil.tracks.translateCodec(i.info.meta.tracks[s])]=1}var o=[];for(var n in r){var l=false;for(var f in r[n]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+f+'"')){l=true;break}}if(l){o.push(n)}}if(a){for(var s in i.info.source){if(i.info.source[s].type=="html5/text/vtt"){o.push("subtitle");break}}}return o.length?o:false},player:function(){this.onreadylist=[]},scriptsrc:function(e){return e+"/dashjs.js"}};var p=mistplayers.dashjs.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var i=this;this.onDashLoad=function(){if(e.destroyed){return}e.log("Building DashJS player..");var r=document.createElement("video");if("Proxy"in window){var a={get:{},set:{}};e.player.api=new Proxy(r,{get:function(e,t,i){if(t in a.get){return a.get[t].apply(e,arguments)}var r=e[t];if(typeof r==="function"){return function(){return r.apply(e,arguments)}}return r},set:function(e,t,i){if(t in a.set){return a.set[t].call(e,i)}return e[t]=i}});if(e.info.type=="live"){a.get.duration=function(){var t=0;if(this.buffered.length){t=this.buffered.end(this.buffered.length-1)}var i=((new Date).getTime()-e.player.api.lastProgress.getTime())*.001;return t+i+-1*e.player.api.liveOffset+45};a.set.currentTime=function(t){var i=t-e.player.api.duration;e.log("Seeking to "+MistUtil.format.time(t)+" ("+Math.round(i*-10)/10+"s from live)");e.video.currentTime=t};MistUtil.event.addListener(r,"progress",function(){e.player.api.lastProgress=new Date});e.player.api.lastProgress=new Date;e.player.api.liveOffset=0}}else{i.api=r}if(e.options.autoplay){r.setAttribute("autoplay","")}if(e.options.loop&&e.info.type!="live"){r.setAttribute("loop","")}if(e.options.poster){r.setAttribute("poster",e.options.poster)}if(e.options.muted){r.muted=true}if(e.options.controls=="stock"){r.setAttribute("controls","")}var s=dashjs.MediaPlayer().create();s.initialize(r,e.source.url,e.options.autoplay);i.dash=s;var o=["METRIC_ADDED","METRIC_UPDATED","METRIC_CHANGED","METRICS_CHANGED","FRAGMENT_LOADING_STARTED","FRAGMENT_LOADING_COMPLETED","LOG","PLAYBACK_TIME_UPDATED","PLAYBACK_PROGRESS"];for(var n in dashjs.MediaPlayer.events){if(o.indexOf(n)<0){i.dash.on(dashjs.MediaPlayer.events[n],function(t){e.log("Player event fired: "+t.type)})}}e.player.setSize=function(e){this.api.style.width=e.width+"px";this.api.style.height=e.height+"px"};e.player.api.setSource=function(t){e.player.dash.attachSource(t)};if(e.options.controls!="stock"){i.dash.updateSettings({streaming:{text:{defaultEnabled:false}}})}var l=false;i.dash.on("allTextTracksAdded",function(){l=true});e.player.api.setSubtitle=function(t){if(!l){var r=function(){e.player.api.setSubtitle(t);i.dash.off("allTextTracksAdded",r)};i.dash.on("allTextTracksAdded",r);return}if(!t){i.dash.enableText(false);return}var a=i.dash.getTracksFor("text");for(var s in a){var o="idx"in t?t.idx:t.trackid;if(a[s].id==o){i.dash.setTextTrack(s);if(!i.dash.isTextEnabled()){i.dash.enableText()}return true}}return false};MistUtil.event.addListener(r,"progress",function(t){if(e.container.getAttribute("data-loading")=="stalled"){e.container.removeAttribute("data-loading")}});i.api.unload=function(){i.dash.reset()};e.log("Built html");t(r)};if("dashjs"in window){this.onDashLoad()}else{var r=MistUtil.scripts.insert(e.urlappend(mistplayers.dashjs.scriptsrc(e.options.host)),{onerror:function(t){var i="Failed to load dashjs.js";if(t.message){i+=": "+t.message}e.showError(i)},onload:i.onDashLoad},e)}}; mistplayers.dashjs={name:"Dash.js player",mimes:["dash/video/mp4"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return MistUtil.array.indexOf(this.mimes,e)==-1?false:true},isBrowserSupported:function(e,t,i){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(location.protocol=="file:"){i.log("This source ("+e+") won't load if the page is run via file://");return false}if(!("MediaSource"in window)){return false}if(!MediaSource.isTypeSupported){return true}var r={};var a=false;for(var s in i.info.meta.tracks){if(i.info.meta.tracks[s].type=="meta"){if(i.info.meta.tracks[s].codec=="subtitle"){a=true}continue}if(!(i.info.meta.tracks[s].type in r)){r[i.info.meta.tracks[s].type]={}}r[i.info.meta.tracks[s].type][MistUtil.tracks.translateCodec(i.info.meta.tracks[s])]=1}var o=[];for(var n in r){var l=false;for(var f in r[n]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+f+'"')){l=true;break}}if(l){o.push(n)}}if(a){for(var s in i.info.source){if(i.info.source[s].type=="html5/text/vtt"){o.push("subtitle");break}}}return o.length?o:false},player:function(){this.onreadylist=[]},scriptsrc:function(e){return e+"/dashjs.js"}};var p=mistplayers.dashjs.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var i=this;this.onDashLoad=function(){if(e.destroyed){return}e.log("Building DashJS player..");var r=document.createElement("video");if("Proxy"in window){var a={get:{},set:{}};e.player.api=new Proxy(r,{get:function(e,t,i){if(t in a.get){return a.get[t].apply(e,arguments)}var r=e[t];if(typeof r==="function"){return function(){return r.apply(e,arguments)}}return r},set:function(e,t,i){if(t in a.set){return a.set[t].call(e,i)}return e[t]=i}});if(e.info.type=="live"){a.get.duration=function(){var t=0;if(this.buffered.length){t=this.buffered.end(this.buffered.length-1)}var i=((new Date).getTime()-e.player.api.lastProgress.getTime())*.001;return t+i+-1*e.player.api.liveOffset+45};a.set.currentTime=function(t){var i=t-e.player.api.duration;e.log("Seeking to "+MistUtil.format.time(t)+" ("+Math.round(i*-10)/10+"s from live)");e.video.currentTime=t};MistUtil.event.addListener(r,"progress",(function(){e.player.api.lastProgress=new Date}));e.player.api.lastProgress=new Date;e.player.api.liveOffset=0}}else{i.api=r}if(e.options.autoplay){r.setAttribute("autoplay","")}if(e.options.loop&&e.info.type!="live"){r.setAttribute("loop","")}if(e.options.poster){r.setAttribute("poster",e.options.poster)}if(e.options.muted){r.muted=true}if(e.options.controls=="stock"){r.setAttribute("controls","")}var s=dashjs.MediaPlayer().create();s.initialize(r,e.source.url,e.options.autoplay);i.dash=s;var o=["METRIC_ADDED","METRIC_UPDATED","METRIC_CHANGED","METRICS_CHANGED","FRAGMENT_LOADING_STARTED","FRAGMENT_LOADING_COMPLETED","LOG","PLAYBACK_TIME_UPDATED","PLAYBACK_PROGRESS"];for(var n in dashjs.MediaPlayer.events){if(o.indexOf(n)<0){i.dash.on(dashjs.MediaPlayer.events[n],(function(t){e.log("Player event fired: "+t.type)}))}}e.player.setSize=function(e){this.api.style.width=e.width+"px";this.api.style.height=e.height+"px"};e.player.api.setSource=function(t){e.player.dash.attachSource(t)};if(e.options.controls!="stock"){i.dash.updateSettings({streaming:{text:{defaultEnabled:false}}})}var l=false;i.dash.on("allTextTracksAdded",(function(){l=true}));e.player.api.setSubtitle=function(t){if(!l){var r=function(){e.player.api.setSubtitle(t);i.dash.off("allTextTracksAdded",r)};i.dash.on("allTextTracksAdded",r);return}if(!t){i.dash.enableText(false);return}var a=i.dash.getTracksFor("text");for(var s in a){var o="idx"in t?t.idx:t.trackid;if(a[s].id==o){i.dash.setTextTrack(s);if(!i.dash.isTextEnabled()){i.dash.enableText()}return true}}return false};MistUtil.event.addListener(r,"progress",(function(t){if(e.container.getAttribute("data-loading")=="stalled"){e.container.removeAttribute("data-loading")}}));i.api.unload=function(){i.dash.reset()};e.log("Built html");t(r)};if("dashjs"in window){this.onDashLoad()}else{var r=MistUtil.scripts.insert(e.urlappend(mistplayers.dashjs.scriptsrc(e.options.host)),{onerror:function(t){var i="Failed to load dashjs.js";if(t.message){i+=": "+t.message}e.showError(i)},onload:i.onDashLoad},e)}};

View file

@ -1 +1 @@
mistplayers.flash_strobe={name:"Strobe Flash media playback",mimes:["flash/10","flash/11","flash/7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return this.mimes.indexOf(t)==-1?false:true},isBrowserSupported:function(t,e,i){if(MistUtil.http.url.split(e.url).protocol.slice(0,4)=="http"&&location.protocol!=MistUtil.http.url.split(e.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}var r=0;try{var a=navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;if(a.version){r=a.version.split(".")[0]}else{r=a.description.replace(/([^0-9\.])/g,"").split(".")[0]}}catch(t){}try{r=new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").replace(/([^0-9\,])/g,"").split(",")[0]}catch(t){}if(!r){return false}var l=t.split("/");return Number(r)>=Number(l[l.length-1])},player:function(){this.onreadylist=[]}};var p=mistplayers.flash_strobe.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var i=document.createElement("object");var r=document.createElement("embed");i.appendChild(r);function a(e){var a=t.options;function l(t,e){var i=document.createElement("param");i.setAttribute("name",t);i.setAttribute("value",e);return i}MistUtil.empty(i);i.appendChild(l("movie",t.urlappend(a.host+t.source.player_url)));var o="src="+encodeURIComponent(e)+"&controlBarMode="+(a.controls?"floating":"none")+"&initialBufferTime=0.5&expandedBufferTime=5&minContinuousPlaybackTime=3"+(a.live?"&streamType=live":"")+(a.autoplay?"&autoPlay=true":"")+(a.loop?"&loop=true":"")+(a.poster?"&poster="+a.poster:"")+(a.muted?"&muted=true":"");i.appendChild(l("flashvars",o));i.appendChild(l("allowFullScreen","true"));i.appendChild(l("wmode","direct"));if(a.autoplay){i.appendChild(l("autoPlay","true"))}if(a.loop){i.appendChild(l("loop","true"))}if(a.poster){i.appendChild(l("poster",a.poster))}if(a.muted){i.appendChild(l("muted","true"))}r.setAttribute("src",t.urlappend(t.source.player_url));r.setAttribute("type","application/x-shockwave-flash");r.setAttribute("allowfullscreen","true");r.setAttribute("flashvars",o)}a(t.source.url);this.api={};this.setSize=function(t){i.setAttribute("width",t.width);i.setAttribute("height",t.height);r.setAttribute("width",t.width);r.setAttribute("height",t.height)};this.setSize(t.calcSize());this.onready(function(){if(t.container){t.container.removeAttribute("data-loading")}});this.api.setSource=function(t){a(t)};t.log("Built html");e(i)}; mistplayers.flash_strobe={name:"Strobe Flash media playback",mimes:["flash/10","flash/11","flash/7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return this.mimes.indexOf(t)==-1?false:true},isBrowserSupported:function(t,e,i){if(MistUtil.http.url.split(e.url).protocol.slice(0,4)=="http"&&location.protocol!=MistUtil.http.url.split(e.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}var r=0;try{var a=navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin;if(a.version){r=a.version.split(".")[0]}else{r=a.description.replace(/([^0-9\.])/g,"").split(".")[0]}}catch(t){}try{r=new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").replace(/([^0-9\,])/g,"").split(",")[0]}catch(t){}if(!r){return false}var l=t.split("/");return Number(r)>=Number(l[l.length-1])},player:function(){this.onreadylist=[]}};var p=mistplayers.flash_strobe.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var i=document.createElement("object");var r=document.createElement("embed");i.appendChild(r);function a(e){var a=t.options;function l(t,e){var i=document.createElement("param");i.setAttribute("name",t);i.setAttribute("value",e);return i}MistUtil.empty(i);i.appendChild(l("movie",t.urlappend(a.host+t.source.player_url)));var o="src="+encodeURIComponent(e)+"&controlBarMode="+(a.controls?"floating":"none")+"&initialBufferTime=0.5&expandedBufferTime=5&minContinuousPlaybackTime=3"+(a.live?"&streamType=live":"")+(a.autoplay?"&autoPlay=true":"")+(a.loop?"&loop=true":"")+(a.poster?"&poster="+a.poster:"")+(a.muted?"&muted=true":"");i.appendChild(l("flashvars",o));i.appendChild(l("allowFullScreen","true"));i.appendChild(l("wmode","direct"));if(a.autoplay){i.appendChild(l("autoPlay","true"))}if(a.loop){i.appendChild(l("loop","true"))}if(a.poster){i.appendChild(l("poster",a.poster))}if(a.muted){i.appendChild(l("muted","true"))}r.setAttribute("src",t.urlappend(t.source.player_url));r.setAttribute("type","application/x-shockwave-flash");r.setAttribute("allowfullscreen","true");r.setAttribute("flashvars",o)}a(t.source.url);this.api={};this.setSize=function(t){i.setAttribute("width",t.width);i.setAttribute("height",t.height);r.setAttribute("width",t.width);r.setAttribute("height",t.height)};this.setSize(t.calcSize());this.onready((function(){if(t.container){t.container.removeAttribute("data-loading")}}));this.api.setSource=function(t){a(t)};t.log("Built html");e(i)};

View file

@ -1 +1 @@
mistplayers.flv={name:"HTML5 FLV Player",mimes:["flash/7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return MistUtil.array.indexOf(this.mimes,e)==-1?false:true},isBrowserSupported:function(e,t,r){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){if(location.protocol=="file:"&&MistUtil.http.url.split(t.url).protocol=="http:"){r.log("This page was loaded over file://, the player might not behave as intended.")}else{r.log("HTTP/HTTPS mismatch for this source");return false}}if(!window.MediaSource){return false}if(!MediaSource.isTypeSupported){return true}try{var o={};for(var a in r.info.meta.tracks){if(r.info.meta.tracks[a].type=="meta"){continue}if(!(r.info.meta.tracks[a].type in o)){o[r.info.meta.tracks[a].type]={}}o[r.info.meta.tracks[a].type][MistUtil.tracks.translateCodec(r.info.meta.tracks[a])]=1}var i=[];for(var l in o){var n=false;for(var s in o[l]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+s+'"')){n=true;break}}if(n){i.push(l)}}t.supportedCodecs=i;return i.length?i:false}catch(e){}return false},player:function(){this.onreadylist=[]},scriptsrc:function(e){return e+"/flv.js"}};var p=mistplayers.flv.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){this.onFLVLoad=function(){if(e.destroyed){return}e.log("Building flv.js player..");var r=document.createElement("video");r.setAttribute("playsinline","");var o=["autoplay","loop","poster"];for(var a in o){var i=o[a];if(e.options[i]){r.setAttribute(i,e.options[i]===true?"":e.options[i])}}if(e.options.muted){r.muted=true}if(e.options.controls=="stock"){r.setAttribute("controls","")}if(e.info.type=="live"){r.loop=false}flvjs.LoggingControl.applyConfig({enableVerbose:false});flvjs.LoggingControl.addLogListener(function(t,r){e.log("[flvjs] "+r)});var l={type:"flv",url:e.source.url,hasAudio:false,hasVideo:false};for(var a in e.source.supportedCodecs){l["has"+e.source.supportedCodecs[a].charAt(0).toUpperCase()+e.source.supportedCodecs[a].slice(1)]=true}e.player.create=function(t){t=MistUtil.object.extend({},t);e.player.flvPlayer=flvjs.createPlayer(t,{lazyLoad:false});e.player.flvPlayer.attachMediaElement(r);e.player.flvPlayer.load();e.player.flvPlayer.play();if(!e.options.autoplay){r.pause()}};e.player.create(l);e.player.api={};function n(t){Object.defineProperty(e.player.api,t,{get:function(){return r[t]},set:function(e){return r[t]=e}})}var s=["volume","buffered","muted","loop","paused",,"error","textTracks","webkitDroppedFrameCount","webkitDecodedFrameCount"];if(e.info.type!="live"){s.push("duration")}else{Object.defineProperty(e.player.api,"duration",{get:function(){if(!r.buffered.length){return 0}return r.buffered.end(r.buffered.length-1)}})}for(var a in s){n(s[a])}function f(t){if(t in r){e.player.api[t]=function(){return r[t].call(r,arguments)}}}var s=["load","getVideoPlaybackQuality","play","pause"];for(var a in s){f(s[a])}e.player.api.setSource=function(t){if(t!=l.url&&t!=""){e.player.flvPlayer.unload();e.player.flvPlayer.detachMediaElement();e.player.flvPlayer.destroy();l.url=t;e.player.create(l)}};e.player.api.unload=function(){e.player.flvPlayer.unload();e.player.flvPlayer.detachMediaElement();e.player.flvPlayer.destroy()};e.player.setSize=function(e){r.style.width=e.width+"px";r.style.height=e.height+"px"};Object.defineProperty(e.player.api,"currentTime",{get:function(){return r.currentTime},set:function(t){var o=.5;for(var a=0;a<r.buffered.length;a++){if(t>=r.buffered.start(a)&&t<=r.buffered.end(a)-o){return r.currentTime=t}}e.log("Seek attempted outside of buffer, but MistServer does not support seeking in progressive flash. Setting to closest available instead");return r.currentTime=r.buffered.length?r.buffered.end(r.buffered.length-1)-o:0}});t(r)};if("flvjs"in window){this.onFLVLoad()}else{var r=MistUtil.scripts.insert(e.urlappend(mistplayers.flv.scriptsrc(e.options.host)),{onerror:function(t){var r="Failed to load flv.js";if(t.message){r+=": "+t.message}e.showError(r)},onload:e.player.onFLVLoad},e)}}; mistplayers.flv={name:"HTML5 FLV Player",mimes:["flash/7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return MistUtil.array.indexOf(this.mimes,e)==-1?false:true},isBrowserSupported:function(e,t,r){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){if(location.protocol=="file:"&&MistUtil.http.url.split(t.url).protocol=="http:"){r.log("This page was loaded over file://, the player might not behave as intended.")}else{r.log("HTTP/HTTPS mismatch for this source");return false}}if(!window.MediaSource){return false}if(!MediaSource.isTypeSupported){return true}try{var o={};for(var a in r.info.meta.tracks){if(r.info.meta.tracks[a].type=="meta"){continue}if(!(r.info.meta.tracks[a].type in o)){o[r.info.meta.tracks[a].type]={}}o[r.info.meta.tracks[a].type][MistUtil.tracks.translateCodec(r.info.meta.tracks[a])]=1}var i=[];for(var l in o){var n=false;for(var s in o[l]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+s+'"')){n=true;break}}if(n){i.push(l)}}t.supportedCodecs=i;return i.length?i:false}catch(e){}return false},player:function(){this.onreadylist=[]},scriptsrc:function(e){return e+"/flv.js"}};var p=mistplayers.flv.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){this.onFLVLoad=function(){if(e.destroyed){return}e.log("Building flv.js player..");var r=document.createElement("video");r.setAttribute("playsinline","");var o=["autoplay","loop","poster"];for(var a in o){var i=o[a];if(e.options[i]){r.setAttribute(i,e.options[i]===true?"":e.options[i])}}if(e.options.muted){r.muted=true}if(e.options.controls=="stock"){r.setAttribute("controls","")}if(e.info.type=="live"){r.loop=false}flvjs.LoggingControl.applyConfig({enableVerbose:false});flvjs.LoggingControl.addLogListener((function(t,r){e.log("[flvjs] "+r)}));var l={type:"flv",url:e.source.url,hasAudio:false,hasVideo:false};for(var a in e.source.supportedCodecs){l["has"+e.source.supportedCodecs[a].charAt(0).toUpperCase()+e.source.supportedCodecs[a].slice(1)]=true}e.player.create=function(t){t=MistUtil.object.extend({},t);e.player.flvPlayer=flvjs.createPlayer(t,{lazyLoad:false});e.player.flvPlayer.attachMediaElement(r);e.player.flvPlayer.load();e.player.flvPlayer.play();if(!e.options.autoplay){r.pause()}};e.player.create(l);e.player.api={};function n(t){Object.defineProperty(e.player.api,t,{get:function(){return r[t]},set:function(e){return r[t]=e}})}var s=["volume","buffered","muted","loop","paused",,"error","textTracks","webkitDroppedFrameCount","webkitDecodedFrameCount"];if(e.info.type!="live"){s.push("duration")}else{Object.defineProperty(e.player.api,"duration",{get:function(){if(!r.buffered.length){return 0}return r.buffered.end(r.buffered.length-1)}})}for(var a in s){n(s[a])}function f(t){if(t in r){e.player.api[t]=function(){return r[t].call(r,arguments)}}}var s=["load","getVideoPlaybackQuality","play","pause"];for(var a in s){f(s[a])}e.player.api.setSource=function(t){if(t!=l.url&&t!=""){e.player.flvPlayer.unload();e.player.flvPlayer.detachMediaElement();e.player.flvPlayer.destroy();l.url=t;e.player.create(l)}};e.player.api.unload=function(){e.player.flvPlayer.unload();e.player.flvPlayer.detachMediaElement();e.player.flvPlayer.destroy()};e.player.setSize=function(e){r.style.width=e.width+"px";r.style.height=e.height+"px"};Object.defineProperty(e.player.api,"currentTime",{get:function(){return r.currentTime},set:function(t){var o=.5;for(var a=0;a<r.buffered.length;a++){if(t>=r.buffered.start(a)&&t<=r.buffered.end(a)-o){return r.currentTime=t}}e.log("Seek attempted outside of buffer, but MistServer does not support seeking in progressive flash. Setting to closest available instead");return r.currentTime=r.buffered.length?r.buffered.end(r.buffered.length-1)-o:0}});t(r)};if("flvjs"in window){this.onFLVLoad()}else{var r=MistUtil.scripts.insert(e.urlappend(mistplayers.flv.scriptsrc(e.options.host)),{onerror:function(t){var r="Failed to load flv.js";if(t.message){r+=": "+t.message}e.showError(r)},onload:e.player.onFLVLoad},e)}};

View file

@ -1 +1 @@
mistplayers.hlsjs={name:"HLS.js player",mimes:["html5/application/vnd.apple.mpegurl","html5/application/vnd.apple.mpegurl;version=7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return this.mimes.indexOf(t)==-1?false:true},isBrowserSupported:function(t,e,r){if(location.protocol!=MistUtil.http.url.split(e.url).protocol){r.log("HTTP/HTTPS mismatch for this source");return false}if(!("MediaSource"in window)){return false}if(!MediaSource.isTypeSupported){return true}var i={};var s=false;for(var o in r.info.meta.tracks){if(r.info.meta.tracks[o].type=="meta"){if(r.info.meta.tracks[o].codec=="subtitle"){s=true}continue}if(!(r.info.meta.tracks[o].type in i)){i[r.info.meta.tracks[o].type]={}}i[r.info.meta.tracks[o].type][MistUtil.tracks.translateCodec(r.info.meta.tracks[o])]=1}var a=[];for(var l in i){var n=false;for(var p in i[l]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+p+'"')){n=true;break}}if(n){a.push(l)}}if(s){for(var o in r.info.source){if(r.info.source[o].type=="html5/text/vtt"){a.push("subtitle");break}}}return a.length?a:false},player:function(){},scriptsrc:function(t){return t+"/hlsjs.js"}};var p=mistplayers.hlsjs.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var r=this;var i=document.createElement("video");i.setAttribute("playsinline","");var s=["autoplay","loop","poster"];for(var o in s){var a=s[o];if(t.options[a]){i.setAttribute(a,t.options[a]===true?"":t.options[a])}}if(t.options.muted){i.muted=true}if(t.info.type=="live"){i.loop=false}if(t.options.controls=="stock"){i.setAttribute("controls","")}i.setAttribute("crossorigin","anonymous");this.setSize=function(t){i.style.width=t.width+"px";i.style.height=t.height+"px"};this.api=i;t.player.api.unload=function(){if(t.player.hls){t.player.hls.destroy();t.player.hls=false;t.log("hls.js instance disposed")}};function l(e){t.player.hls=new Hls({maxBufferLength:15,maxMaxBufferLength:60});t.player.hls.attachMedia(i);t.player.hls.on(Hls.Events.MEDIA_ATTACHED,function(){t.player.hls.loadSource(e)})}t.player.api.setSource=function(e){if(!t.player.hls){return}if(t.player.hls.url!=e){t.player.hls.destroy();l(e)}};t.player.api.setSubtitle=function(t){var e=i.getElementsByTagName("track");for(var r=e.length-1;r>=0;r--){i.removeChild(e[r])}if(t){var s=document.createElement("track");i.appendChild(s);s.kind="subtitles";s.label=t.label;s.srclang=t.lang;s.src=t.src;s.setAttribute("default","")}};function n(){l(t.source.url)}if("Hls"in window){n()}else{var p=t.urlappend(mistplayers.hlsjs.scriptsrc(t.options.host));MistUtil.scripts.insert(p,{onerror:function(e){var r="Failed to load hlsjs.js";if(e.message){r+=": "+e.message}t.showError(r)},onload:n},t)}e(i)}; mistplayers.hlsjs={name:"HLS.js player",mimes:["html5/application/vnd.apple.mpegurl","html5/application/vnd.apple.mpegurl;version=7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(t){return this.mimes.indexOf(t)==-1?false:true},isBrowserSupported:function(t,e,r){if(location.protocol!=MistUtil.http.url.split(e.url).protocol){r.log("HTTP/HTTPS mismatch for this source");return false}if(!("MediaSource"in window)){return false}if(!MediaSource.isTypeSupported){return true}var i={};var s=false;for(var o in r.info.meta.tracks){if(r.info.meta.tracks[o].type=="meta"){if(r.info.meta.tracks[o].codec=="subtitle"){s=true}continue}if(!(r.info.meta.tracks[o].type in i)){i[r.info.meta.tracks[o].type]={}}i[r.info.meta.tracks[o].type][MistUtil.tracks.translateCodec(r.info.meta.tracks[o])]=1}var a=[];for(var l in i){var n=false;for(var p in i[l]){if(MediaSource.isTypeSupported('video/mp4;codecs="'+p+'"')){n=true;break}}if(n){a.push(l)}}if(s){for(var o in r.info.source){if(r.info.source[o].type=="html5/text/vtt"){a.push("subtitle");break}}}return a.length?a:false},player:function(){},scriptsrc:function(t){return t+"/hlsjs.js"}};var p=mistplayers.hlsjs.player;p.prototype=new MistPlayer;p.prototype.build=function(t,e){var r=this;var i=document.createElement("video");i.setAttribute("playsinline","");var s=["autoplay","loop","poster"];for(var o in s){var a=s[o];if(t.options[a]){i.setAttribute(a,t.options[a]===true?"":t.options[a])}}if(t.options.muted){i.muted=true}if(t.info.type=="live"){i.loop=false}if(t.options.controls=="stock"){i.setAttribute("controls","")}i.setAttribute("crossorigin","anonymous");this.setSize=function(t){i.style.width=t.width+"px";i.style.height=t.height+"px"};this.api=i;t.player.api.unload=function(){if(t.player.hls){t.player.hls.destroy();t.player.hls=false;t.log("hls.js instance disposed")}};function l(e){t.player.hls=new Hls({maxBufferLength:15,maxMaxBufferLength:60});t.player.hls.attachMedia(i);t.player.hls.on(Hls.Events.MEDIA_ATTACHED,(function(){t.player.hls.loadSource(e)}))}t.player.api.setSource=function(e){if(!t.player.hls){return}if(t.player.hls.url!=e){t.player.hls.destroy();l(e)}};t.player.api.setSubtitle=function(t){var e=i.getElementsByTagName("track");for(var r=e.length-1;r>=0;r--){i.removeChild(e[r])}if(t){var s=document.createElement("track");i.appendChild(s);s.kind="subtitles";s.label=t.label;s.srclang=t.lang;s.src=t.src;s.setAttribute("default","")}};function n(){l(t.source.url)}if("Hls"in window){n()}else{var p=t.urlappend(mistplayers.hlsjs.scriptsrc(t.options.host));MistUtil.scripts.insert(p,{onerror:function(e){var r="Failed to load hlsjs.js";if(e.message){r+=": "+e.message}t.showError(r)},onload:n},t)}e(i)};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -2555,7 +2555,6 @@ MistSkins["default"] = {
if (!window.chrome || !window.chrome.cast || !window.chrome.cast.isAvailable || (tries > 5)) { if (!window.chrome || !window.chrome.cast || !window.chrome.cast.isAvailable || (tries > 5)) {
if (ele.parentNode) { ele.parentNode.removeChild(ele); } if (ele.parentNode) { ele.parentNode.removeChild(ele); }
MistVideo.log("Chromecast is not supported"); MistVideo.log("Chromecast is not supported");
console.warn(chrome,chrome.cast,chrome.cast ? chrome.cast.isAvailable : undefined,cast);
return; return;
} }

View file

@ -213,7 +213,7 @@ namespace Secure{
} }
/// Calculates a SHA256 digest as per NSAs SHA-2, returning it as binary. /// Calculates a SHA256 digest as per NSAs SHA-2, returning it as binary.
/// Assumes output is big enough to contain 16 bytes of data. /// Assumes output is big enough to contain 32 bytes of data.
void sha256bin(const char *input, const unsigned int in_len, char *output){ void sha256bin(const char *input, const unsigned int in_len, char *output){
// Initialize the hash, according to MD5 spec. // Initialize the hash, according to MD5 spec.
uint32_t hash[] ={0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, uint32_t hash[] ={0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,

View file

@ -36,7 +36,7 @@
bool Util::Config::is_active = false; bool Util::Config::is_active = false;
bool Util::Config::is_restarting = false; bool Util::Config::is_restarting = false;
static Socket::Server *serv_sock_pointer = 0; static int serv_sock_fd = -1;
uint32_t Util::printDebugLevel = DEBUG; uint32_t Util::printDebugLevel = DEBUG;
__thread char Util::streamName[256] = {0}; __thread char Util::streamName[256] = {0};
__thread char Util::exitReason[256] = {0}; __thread char Util::exitReason[256] = {0};
@ -521,7 +521,7 @@ int Util::Config::serveThreadedSocket(int (*callback)(Socket::Connection &)){
return 1; return 1;
} }
Socket::getSocketName(server_socket.getSocket(), Util::listenInterface, Util::listenPort); Socket::getSocketName(server_socket.getSocket(), Util::listenInterface, Util::listenPort);
serv_sock_pointer = &server_socket; serv_sock_fd = server_socket.getSocket();
activate(); activate();
if (server_socket.getSocket()){ if (server_socket.getSocket()){
int oldSock = server_socket.getSocket(); int oldSock = server_socket.getSocket();
@ -531,7 +531,7 @@ int Util::Config::serveThreadedSocket(int (*callback)(Socket::Connection &)){
} }
} }
int r = threadServer(server_socket, callback); int r = threadServer(server_socket, callback);
serv_sock_pointer = 0; serv_sock_fd = -1;
return r; return r;
} }
@ -549,7 +549,7 @@ int Util::Config::serveForkedSocket(int (*callback)(Socket::Connection &S)){
return 1; return 1;
} }
Socket::getSocketName(server_socket.getSocket(), Util::listenInterface, Util::listenPort); Socket::getSocketName(server_socket.getSocket(), Util::listenInterface, Util::listenPort);
serv_sock_pointer = &server_socket; serv_sock_fd = server_socket.getSocket();
activate(); activate();
if (server_socket.getSocket()){ if (server_socket.getSocket()){
int oldSock = server_socket.getSocket(); int oldSock = server_socket.getSocket();
@ -559,7 +559,7 @@ int Util::Config::serveForkedSocket(int (*callback)(Socket::Connection &S)){
} }
} }
int r = forkServer(server_socket, callback); int r = forkServer(server_socket, callback);
serv_sock_pointer = 0; serv_sock_fd = -1;
return r; return r;
} }
@ -601,6 +601,10 @@ void Util::Config::setMutexAborter(void * mutex){
mutabort = (tthread::mutex*)mutex; mutabort = (tthread::mutex*)mutex;
} }
void Util::Config::setServerFD(int fd){
serv_sock_fd = fd;
}
/// Basic signal handler. Sets is_active to false if it receives /// Basic signal handler. Sets is_active to false if it receives
/// a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD /// a SIGINT, SIGHUP or SIGTERM signal, reaps children for the SIGCHLD
/// signal, and ignores all other signals. /// signal, and ignores all other signals.
@ -610,7 +614,7 @@ void Util::Config::signal_handler(int signum, siginfo_t *sigInfo, void *ignore){
case SIGHUP: case SIGHUP:
case SIGTERM: case SIGTERM:
if (!mutabort || mutabort->try_lock()){ if (!mutabort || mutabort->try_lock()){
if (serv_sock_pointer){serv_sock_pointer->close();} if (serv_sock_fd != -1){close(serv_sock_fd);}
if (mutabort){mutabort->unlock();} if (mutabort){mutabort->unlock();}
} }
#if DEBUG >= DLVL_DEVEL #if DEBUG >= DLVL_DEVEL
@ -759,6 +763,7 @@ void Util::Config::addStandardPushCapabilities(JSON::Value &cap){
pp["track_selectors"]["type"] = "group"; pp["track_selectors"]["type"] = "group";
pp["track_selectors"]["name"] = "Track selectors"; pp["track_selectors"]["name"] = "Track selectors";
pp["track_selectors"]["help"] = "Control which tracks are part of the output"; pp["track_selectors"]["help"] = "Control which tracks are part of the output";
pp["track_selectors"]["sort"] = "v";
{ {
JSON::Value & o = pp["track_selectors"]["options"]; JSON::Value & o = pp["track_selectors"]["options"];
o["audio"]["name"] = "Audio track(s)"; o["audio"]["name"] = "Audio track(s)";
@ -783,6 +788,7 @@ void Util::Config::addStandardPushCapabilities(JSON::Value &cap){
pp["trackwait_opts"]["type"] = "group"; pp["trackwait_opts"]["type"] = "group";
pp["trackwait_opts"]["name"] = "Wait for tracks"; pp["trackwait_opts"]["name"] = "Wait for tracks";
pp["trackwait_opts"]["help"] = "Before starting, ensure the available tracks satisfy certain conditions"; pp["trackwait_opts"]["help"] = "Before starting, ensure the available tracks satisfy certain conditions";
pp["trackwait_opts"]["sort"] = "w";
{ {
JSON::Value & o = pp["trackwait_opts"]["options"]; JSON::Value & o = pp["trackwait_opts"]["options"];
o["waittrackcount"]["name"] = "Wait for tracks count"; o["waittrackcount"]["name"] = "Wait for tracks count";
@ -819,37 +825,10 @@ void Util::Config::addStandardPushCapabilities(JSON::Value &cap){
o["maxwaittrackms"]["sort"] = "bdad"; o["maxwaittrackms"]["sort"] = "bdad";
} }
pp["pls_opts"]["type"] = "group";
pp["pls_opts"]["name"] = "Playlist writing options";
pp["pls_opts"]["help"] = "Control the writing of a playlist file when recording to a segmented format";
{
JSON::Value & o = pp["pls_opts"]["options"];
o["noendlist"]["name"] = "Don't end playlist";
o["noendlist"]["help"] = "If set, does not write #X-EXT-ENDLIST when finalizing the playlist on exit";
o["noendlist"]["type"] = "bool";
o["noendlist"]["format"] = "set_or_unset";
o["noendlist"]["sort"] = "bfa";
o["m3u8"]["name"] = "Playlist path (relative to segments)";
o["m3u8"]["help"] = "If set, will write a m3u8 playlist file for the segments to the given path (relative from the first segment path). When this parameter is used, at least one of the variables $segmentCounter or $currentMediaTime must be part of the segment path (to keep segments from overwriting each other). The \"Split interval\" parameter will default to 60 seconds when using this option.";
o["m3u8"]["type"] = "string";
o["m3u8"]["sort"] = "apa";
o["targetAge"]["name"] = "Playlist target age";
o["targetAge"]["help"] = "When writing a playlist, delete segment entries that are more than this many seconds old from the playlist (and, if possible, also delete said segments themselves). When set to 0 or left empty, does not delete.";
o["targetAge"]["type"] = "int";
o["targetAge"]["unit"] = "s";
o["targetAge"]["sort"] = "apb";
o["maxEntries"]["name"] = "Playlist max entries";
o["maxEntries"]["help"] = "When writing a playlist, delete oldest segment entries once this entry count has been reached (and, if possible, also delete said segments themselves). When set to 0 or left empty, does not delete.";
o["maxEntries"]["type"] = "int";
o["maxEntries"]["sort"] = "apc";
}
pp["time_opts"]["type"] = "group"; pp["time_opts"]["type"] = "group";
pp["time_opts"]["name"] = "Timing options"; pp["time_opts"]["name"] = "Timing options";
pp["time_opts"]["help"] = "Control speed and the start/stop timing"; pp["time_opts"]["help"] = "Control speed and the start/stop timing";
pp["time_opts"]["sort"] = "x";
{ {
JSON::Value & o = pp["time_opts"]["options"]; JSON::Value & o = pp["time_opts"]["options"];
o["rate"]["name"] = "Playback rate"; o["rate"]["name"] = "Playback rate";
@ -913,17 +892,55 @@ void Util::Config::addStandardPushCapabilities(JSON::Value &cap){
o["split"]["sort"] = "bh"; o["split"]["sort"] = "bh";
} }
pp["unmask"]["name"] = "Unmask tracks"; pp["pls_opts"]["type"] = "group";
pp["unmask"]["help"] = "If set to any value, removes any applied track masking before selecting tracks, acting as if no mask was applied at all"; pp["pls_opts"]["name"] = "Playlist writing options";
pp["unmask"]["type"] = "bool"; pp["pls_opts"]["help"] = "Control the writing of a playlist file when recording to a segmented format";
pp["unmask"]["format"] = "set_or_unset"; pp["pls_opts"]["sort"] = "y";
pp["unmask"]["sort"] = "bc"; {
JSON::Value & o = pp["pls_opts"]["options"];
o["noendlist"]["name"] = "Don't end playlist";
o["noendlist"]["help"] = "If set, does not write #X-EXT-ENDLIST when finalizing the playlist on exit";
o["noendlist"]["type"] = "bool";
o["noendlist"]["format"] = "set_or_unset";
o["noendlist"]["sort"] = "bfa";
pp["append"]["name"] = "Append to file"; o["m3u8"]["name"] = "Playlist path (relative to segments)";
pp["append"]["help"] = "If set to any value, will (if possible) append to an existing file, rather than overwriting it"; o["m3u8"]["help"] = "If set, will write a m3u8 playlist file for the segments to the given path (relative from the first segment path). When this parameter is used, at least one of the variables $segmentCounter or $currentMediaTime must be part of the segment path (to keep segments from overwriting each other). The \"Split interval\" parameter will default to 60 seconds when using this option.";
pp["append"]["type"] = "bool"; o["m3u8"]["type"] = "string";
pp["append"]["format"] = "set_or_unset"; o["m3u8"]["sort"] = "apa";
pp["append"]["sort"] = "bf";
o["targetAge"]["name"] = "Playlist target age";
o["targetAge"]["help"] = "When writing a playlist, delete segment entries that are more than this many seconds old from the playlist (and, if possible, also delete said segments themselves). When set to 0 or left empty, does not delete.";
o["targetAge"]["type"] = "int";
o["targetAge"]["unit"] = "s";
o["targetAge"]["sort"] = "apb";
o["maxEntries"]["name"] = "Playlist max entries";
o["maxEntries"]["help"] = "When writing a playlist, delete oldest segment entries once this entry count has been reached (and, if possible, also delete said segments themselves). When set to 0 or left empty, does not delete.";
o["maxEntries"]["type"] = "int";
o["maxEntries"]["sort"] = "apc";
}
pp["misc_genopts"]["type"] = "group";
pp["misc_genopts"]["name"] = "Miscellaneous options";
pp["misc_genopts"]["sort"] = "z";
{
JSON::Value & o = pp["misc_genopts"]["options"];
o["unmask"]["name"] = "Unmask tracks";
o["unmask"]["help"] = "If set to any value, removes any applied track masking before selecting tracks, acting as if no mask was applied at all";
o["unmask"]["type"] = "bool";
o["unmask"]["format"] = "set_or_unset";
o["unmask"]["sort"] = "bc";
o["append"]["name"] = "Append to file";
o["append"]["help"] = "If set to any value, will (if possible) append to an existing file, rather than overwriting it";
o["append"]["type"] = "bool";
o["append"]["format"] = "set_or_unset";
o["append"]["sort"] = "bf";
}
} }

View file

@ -38,6 +38,7 @@ namespace Util{
public: public:
static void setMutexAborter(void * mutex); static void setMutexAborter(void * mutex);
static void wipeShm(); static void wipeShm();
static void setServerFD(int fd);
// variables // variables
static bool is_active; ///< Set to true by activate(), set to false by the signal handler. static bool is_active; ///< Set to true by activate(), set to false by the signal handler.
static bool is_restarting; ///< Set to true when restarting, set to false on boot. static bool is_restarting; ///< Set to true when restarting, set to false on boot.

View file

@ -142,8 +142,8 @@ namespace Mist{
} }
if (parser == STRM_TS){ if (parser == STRM_TS){
if (currBuf->size() == currBuf->rsize()){tsStream.finish();} if (currBuf->size() == currBuf->rsize() && offset + 188 > currBuf->size()){tsStream.finish();}
if (tsStream.hasPacketOnEachTrack() || currBuf->size() == currBuf->rsize()){ if (tsStream.hasPacketOnEachTrack() || (currBuf->size() == currBuf->rsize() && offset + 188 > currBuf->size())){
if (!tsStream.hasPacket()){return false;} if (!tsStream.hasPacket()){return false;}
tsStream.getEarliestPacket(thisPacket); tsStream.getEarliestPacket(thisPacket);
return true; return true;

View file

@ -44,6 +44,14 @@ static const char *gai_strmagic(int errcode){
} }
} }
std::string Socket::sockaddrToString(const sockaddr* A){
char addressBuffer[INET6_ADDRSTRLEN];
if (inet_ntop(AF_INET, A, addressBuffer, INET6_ADDRSTRLEN)){
return addressBuffer;
}
return "";
}
static std::string getIPv6BinAddr(const struct sockaddr_in6 &remoteaddr){ static std::string getIPv6BinAddr(const struct sockaddr_in6 &remoteaddr){
char tmpBuffer[17] = "\000\000\000\000\000\000\000\000\000\000\377\377\000\000\000\000"; char tmpBuffer[17] = "\000\000\000\000\000\000\000\000\000\000\377\377\000\000\000\000";
switch (remoteaddr.sin6_family){ switch (remoteaddr.sin6_family){
@ -130,6 +138,44 @@ bool Socket::matchIPv6Addr(const std::string &A, const std::string &B, uint8_t p
return true; return true;
} }
bool Socket::compareAddress(const sockaddr* A, const sockaddr* B){
if (!A || !B){return false;}
bool aSix = false, bSix = false;
char *aPtr = 0, *bPtr = 0;
uint16_t aPort = 0, bPort = 0;
if (A->sa_family == AF_INET){
aPtr = (char*)&((sockaddr_in*)A)->sin_addr;
aPort = ((sockaddr_in*)A)->sin_port;
}else if(A->sa_family == AF_INET6){
aPtr = (char*)&((sockaddr_in6*)A)->sin6_addr;
aPort = ((sockaddr_in6*)A)->sin6_port;
if (!memcmp("\000\000\000\000\000\000\000\000\000\000\377\377", aPtr, 12)){
aPtr += 12;
}else{
aSix = true;
}
}else{
return false;
}
if (B->sa_family == AF_INET){
bPtr = (char*)&((sockaddr_in*)B)->sin_addr;
bPort = ((sockaddr_in*)B)->sin_port;
}else if(B->sa_family == AF_INET6){
bPtr = (char*)&((sockaddr_in6*)B)->sin6_addr;
bPort = ((sockaddr_in6*)B)->sin6_port;
if (!memcmp("\000\000\000\000\000\000\000\000\000\000\377\377", bPtr, 12)){
bPtr += 12;
}else{
bSix = true;
}
}else{
return false;
}
if (aPort != bPort){return false;}
if (aSix != bSix){return false;}
return !memcmp(aPtr, bPtr, aSix?16:4);
}
/// Attempts to match the given address with optional subnet to the given binary-form IPv6 address. /// Attempts to match the given address with optional subnet to the given binary-form IPv6 address.
/// Returns true if match could be made, false otherwise. /// Returns true if match could be made, false otherwise.
bool Socket::isBinAddress(const std::string &binAddr, std::string addr){ bool Socket::isBinAddress(const std::string &binAddr, std::string addr){
@ -180,7 +226,7 @@ std::string Socket::getBinForms(std::string addr){
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM; hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED; hints.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED | AI_ALL;
hints.ai_protocol = 0; hints.ai_protocol = 0;
hints.ai_canonname = NULL; hints.ai_canonname = NULL;
hints.ai_addr = NULL; hints.ai_addr = NULL;
@ -200,6 +246,45 @@ std::string Socket::getBinForms(std::string addr){
return ret; return ret;
} }
std::deque<std::string> Socket::getAddrs(std::string addr, uint16_t port, int family){
std::deque<std::string> ret;
struct addrinfo *result, *rp, hints;
if (addr.substr(0, 7) == "::ffff:"){addr = addr.substr(7);}
std::stringstream ss;
ss << port;
memset(&hints, 0, sizeof(struct addrinfo));
// For unspecified, we do IPv6, then do IPv4 separately after
hints.ai_family = family==AF_UNSPEC?AF_INET6:family;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE | AI_V4MAPPED | AI_ALL;
hints.ai_protocol = IPPROTO_UDP;
int s = getaddrinfo(addr.c_str(), ss.str().c_str(), &hints, &result);
if (!s){
// Store each address in a string and put it in the deque.
for (rp = result; rp != NULL; rp = rp->ai_next){
ret.push_back(std::string((char*)rp->ai_addr, rp->ai_addrlen));
}
freeaddrinfo(result);
}
// If failed or unspecified, (also) try IPv4
if (s || family==AF_UNSPEC){
hints.ai_family = AF_INET;
s = getaddrinfo(addr.c_str(), ss.str().c_str(), &hints, &result);
if (!s){
// Store each address in a string and put it in the deque.
for (rp = result; rp != NULL; rp = rp->ai_next){
ret.push_back(std::string((char*)rp->ai_addr, rp->ai_addrlen));
}
freeaddrinfo(result);
}
}
// Return all we found
return ret;
}
/// Checks bytes (length len) containing a binary-encoded IPv4 or IPv6 IP address, and writes it in /// Checks bytes (length len) containing a binary-encoded IPv4 or IPv6 IP address, and writes it in
/// human-readable notation to target. Writes "unknown" if it cannot decode to a sensible value. /// human-readable notation to target. Writes "unknown" if it cannot decode to a sensible value.
void Socket::hostBytesToStr(const char *bytes, size_t len, std::string &target){ void Socket::hostBytesToStr(const char *bytes, size_t len, std::string &target){
@ -1679,6 +1764,7 @@ void Socket::UDPConnection::init(bool _nonblock, int _family){
isConnected = false; isConnected = false;
wasEncrypted = false; wasEncrypted = false;
pretendReceive = false; pretendReceive = false;
ignoreSendErrors = false;
sock = socket(family, SOCK_DGRAM, 0); sock = socket(family, SOCK_DGRAM, 0);
if (sock == -1 && family == AF_INET6){ if (sock == -1 && family == AF_INET6){
sock = socket(AF_INET, SOCK_DGRAM, 0); sock = socket(AF_INET, SOCK_DGRAM, 0);
@ -1700,10 +1786,6 @@ void Socket::UDPConnection::init(bool _nonblock, int _family){
up = 0; up = 0;
down = 0; down = 0;
destAddr = 0;
destAddr_size = 0;
recvAddr = 0;
recvAddr_size = 0;
hasReceiveData = false; hasReceiveData = false;
#ifdef __CYGWIN__ #ifdef __CYGWIN__
data.allocate(SOCKETSIZE); data.allocate(SOCKETSIZE);
@ -1712,6 +1794,23 @@ void Socket::UDPConnection::init(bool _nonblock, int _family){
#endif #endif
} }
void Socket::UDPConnection::assimilate(int _sock){
if (sock != -1){close();}
sock = _sock;
{ // Extract socket family
struct sockaddr_storage fin_addr;
socklen_t alen = sizeof(fin_addr);
if (getsockname(sock, (struct sockaddr *)&fin_addr, &alen) == 0){
family = fin_addr.ss_family;
if (family == AF_INET6){
boundPort = ntohs(((struct sockaddr_in6 *)&fin_addr)->sin6_port);
}else{
boundPort = ntohs(((struct sockaddr_in *)&fin_addr)->sin_port);
}
}
}
}
#if HAVE_UPSTREAM_MBEDTLS_SRTP #if HAVE_UPSTREAM_MBEDTLS_SRTP
#if MBEDTLS_VERSION_MAJOR > 2 #if MBEDTLS_VERSION_MAJOR > 2
static void dtlsExtractKeyData( void *user, mbedtls_ssl_key_export_type type, const unsigned char *ms, size_t, const unsigned char client_random[32], const unsigned char server_random[32], mbedtls_tls_prf_types tls_prf_type){ static void dtlsExtractKeyData( void *user, mbedtls_ssl_key_export_type type, const unsigned char *ms, size_t, const unsigned char client_random[32], const unsigned char server_random[32], mbedtls_tls_prf_types tls_prf_type){
@ -1927,18 +2026,10 @@ void Socket::UDPConnection::checkRecvBuf(){
Socket::UDPConnection::UDPConnection(const UDPConnection &o){ Socket::UDPConnection::UDPConnection(const UDPConnection &o){
init(!o.isBlocking, o.family); init(!o.isBlocking, o.family);
INFO_MSG("Copied socket of type %s", addrFam(o.family)); INFO_MSG("Copied socket of type %s", addrFam(o.family));
if (o.destAddr && o.destAddr_size){ if (o.destAddr.size()){destAddr = o.destAddr;}
destAddr = malloc(o.destAddr_size); if (o.recvAddr.size()){recvAddr = o.recvAddr;}
destAddr_size = o.destAddr_size;
if (destAddr){memcpy(destAddr, o.destAddr, o.destAddr_size);}
}
if (o.recvAddr && o.recvAddr_size){
recvAddr = malloc(o.recvAddr_size);
recvAddr_size = o.recvAddr_size;
if (recvAddr){memcpy(recvAddr, o.recvAddr, o.recvAddr_size);}
}
if (o.data.size()){ if (o.data.size()){
data.assign(o.data, o.data.size()); data = o.data;
pretendReceive = true; pretendReceive = true;
} }
hasReceiveData = o.hasReceiveData; hasReceiveData = o.hasReceiveData;
@ -1956,14 +2047,6 @@ void Socket::UDPConnection::close(){
/// Closes the UDP socket, cleans up any memory allocated by the socket. /// Closes the UDP socket, cleans up any memory allocated by the socket.
Socket::UDPConnection::~UDPConnection(){ Socket::UDPConnection::~UDPConnection(){
close(); close();
if (destAddr){
free(destAddr);
destAddr = 0;
}
if (recvAddr){
free(recvAddr);
recvAddr = 0;
}
#ifdef SSL #ifdef SSL
deinitDTLS(); deinitDTLS();
#endif #endif
@ -1975,10 +2058,10 @@ bool Socket::UDPConnection::operator==(const Socket::UDPConnection& b) const{
if (sock == b.sock){return true;} if (sock == b.sock){return true;}
// If either is closed (and the other is not), not equal. // If either is closed (and the other is not), not equal.
if (sock == -1 || b.sock == -1){return false;} if (sock == -1 || b.sock == -1){return false;}
size_t recvSize = recvAddr_size; size_t recvSize = recvAddr.size();
if (b.recvAddr_size < recvSize){recvSize = b.recvAddr_size;} if (b.recvAddr.size() < recvSize){recvSize = b.recvAddr.size();}
size_t destSize = destAddr_size; size_t destSize = destAddr.size();
if (b.destAddr_size < destSize){destSize = b.destAddr_size;} if (b.destAddr.size() < destSize){destSize = b.destAddr.size();}
// They are equal if they hold the same local and remote address. // They are equal if they hold the same local and remote address.
if (recvSize && destSize && destAddr && b.destAddr && recvAddr && b.recvAddr){ if (recvSize && destSize && destAddr && b.destAddr && recvAddr && b.recvAddr){
if (!memcmp(recvAddr, b.recvAddr, recvSize) && !memcmp(destAddr, b.destAddr, destSize)){ if (!memcmp(recvAddr, b.recvAddr, recvSize) && !memcmp(destAddr, b.destAddr, destSize)){
@ -1999,128 +2082,108 @@ void Socket::UDPConnection::setSocketFamily(int AF_TYPE){\
/// Allocates enough space for the largest type of address we support, so that receive calls can write to it. /// Allocates enough space for the largest type of address we support, so that receive calls can write to it.
void Socket::UDPConnection::allocateDestination(){ void Socket::UDPConnection::allocateDestination(){
if (destAddr && destAddr_size < sizeof(sockaddr_in6)){ if (!destAddr.size()){
free(destAddr); destAddr.truncate(0);
destAddr = 0; destAddr.allocate(sizeof(sockaddr_in6));
}
if (!destAddr){
destAddr = malloc(sizeof(sockaddr_in6));
if (destAddr){
destAddr_size = sizeof(sockaddr_in6);
memset(destAddr, 0, sizeof(sockaddr_in6)); memset(destAddr, 0, sizeof(sockaddr_in6));
((struct sockaddr_in *)destAddr)->sin_family = AF_UNSPEC; ((struct sockaddr *)(char*)destAddr)->sa_family = AF_UNSPEC;
destAddr.append(0, sizeof(sockaddr_in6));
} }
} if (!recvAddr.size()){
if (recvAddr && recvAddr_size < sizeof(sockaddr_in6)){ recvAddr.truncate(0);
free(recvAddr); recvAddr.allocate(sizeof(sockaddr_in6));
recvAddr = 0;
}
if (!recvAddr){
recvAddr = malloc(sizeof(sockaddr_in6));
if (recvAddr){
recvAddr_size = sizeof(sockaddr_in6);
memset(recvAddr, 0, sizeof(sockaddr_in6)); memset(recvAddr, 0, sizeof(sockaddr_in6));
((struct sockaddr_in *)recvAddr)->sin_family = AF_UNSPEC; ((struct sockaddr *)(char*)recvAddr)->sa_family = AF_UNSPEC;
recvAddr.append(0, sizeof(sockaddr_in6));
} }
#ifdef HASPKTINFO
const int opt = 1; const int opt = 1;
if (setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt))){ if (setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &opt, sizeof(opt))){
WARN_MSG("Could not set PKTINFO to 1!"); WARN_MSG("Could not set IPv4 packet info receiving enabled!");
}
if (family == AF_INET6){
if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &opt, sizeof(opt))){
WARN_MSG("Could not set IPv6 packet info receiving enabled!");
} }
} }
#endif
} }
/// Stores the properties of the receiving end of this UDP socket. /// Stores the properties of the receiving end of this UDP socket.
/// This will be the receiving end for all SendNow calls. /// This will be the receiving end for all SendNow calls.
void Socket::UDPConnection::SetDestination(std::string destIp, uint32_t port){ void Socket::UDPConnection::SetDestination(std::string destIp, uint32_t port){
DONTEVEN_MSG("Setting destination to %s:%u", destIp.c_str(), port); DONTEVEN_MSG("Setting destination to %s:%u", destIp.c_str(), port);
// UDP sockets can switch between IPv4 and IPv6 on demand.
// We change IPv4-mapped IPv6 addresses into IPv4 addresses for Windows-sillyness reasons.
if (destIp.substr(0, 7) == "::ffff:"){destIp = destIp.substr(7);}
struct addrinfo *result, *rp, hints;
std::stringstream ss;
ss << port;
memset(&hints, 0, sizeof(struct addrinfo)); std::deque<std::string> addrs = getAddrs(destIp, port, family);
hints.ai_family = family; for (std::deque<std::string>::iterator it = addrs.begin(); it != addrs.end(); ++it){
hints.ai_socktype = SOCK_DGRAM; if (setDestination((sockaddr*)it->data(), it->size())){return;}
hints.ai_flags = AI_ADDRCONFIG | AI_ALL;
hints.ai_protocol = IPPROTO_UDP;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
int s = getaddrinfo(destIp.c_str(), ss.str().c_str(), &hints, &result);
if (s != 0){
hints.ai_family = AF_UNSPEC;
s = getaddrinfo(destIp.c_str(), ss.str().c_str(), &hints, &result);
if (s != 0){
FAIL_MSG("Could not connect UDP socket to %s:%i! Error: %s", destIp.c_str(), port, gai_strmagic(s));
return;
}
} }
destAddr.truncate(0);
allocateDestination();
FAIL_MSG("Could not set destination for UDP socket: %s:%d", destIp.c_str(), port);
}// Socket::UDPConnection SetDestination
for (rp = result; rp != NULL; rp = rp->ai_next){ bool Socket::UDPConnection::setDestination(sockaddr * addr, size_t size){
// assume success // UDP sockets can on-the-fly switch between IPv4/IPv6 if necessary
if (destAddr){ if (family != addr->sa_family){
free(destAddr); if (ignoreSendErrors){return false;}
destAddr = 0; WARN_MSG("Switching UDP socket from %s to %s", addrFam(family), addrFam(((sockaddr*)(char*)destAddr)->sa_family));
}
destAddr_size = rp->ai_addrlen;
destAddr = malloc(destAddr_size);
if (!destAddr){return;}
memcpy(destAddr, rp->ai_addr, rp->ai_addrlen);
if (family != rp->ai_family){
INFO_MSG("Switching UDP socket from %s to %s", addrFam(family), addrFam(rp->ai_family));
close(); close();
family = rp->ai_family; family = addr->sa_family;
sock = socket(family, SOCK_DGRAM, 0); sock = socket(family, SOCK_DGRAM, 0);
{ {
// Allow address re-use // Allow address re-use
int on = 1; int on = 1;
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
} }
if (family == AF_INET6){
const int optval = 0;
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)) < 0){
WARN_MSG("Could not set IPv6 UDP socket to be dual-stack! %s", strerror(errno));
}
}
checkRecvBuf(); checkRecvBuf();
if (boundPort){ if (boundPort){
INFO_MSG("Rebinding to %s:%d %s", boundAddr.c_str(), boundPort, boundMulti.c_str()); INFO_MSG("Rebinding to %s:%d %s", boundAddr.c_str(), boundPort, boundMulti.c_str());
bind(boundPort, boundAddr, boundMulti); bind(boundPort, boundAddr, boundMulti);
} }
} }
hasReceiveData = false;
destAddr.assign(addr, size);
{ {
std::string trueDest; std::string trueDest;
uint32_t truePort; uint32_t truePort;
GetDestination(trueDest, truePort); GetDestination(trueDest, truePort);
HIGH_MSG("Set UDP destination: %s:%d => %s:%d (%s)", destIp.c_str(), port, trueDest.c_str(), truePort, addrFam(family)); HIGH_MSG("Set UDP destination to %s:%d (%s)", trueDest.c_str(), truePort, addrFam(family));
} }
freeaddrinfo(result); return true;
return; }
//\todo Possibly detect and handle failure
} const Util::ResizeablePointer & Socket::UDPConnection::getRemoteAddr() const{
freeaddrinfo(result); return destAddr;
free(destAddr); }
destAddr = 0;
FAIL_MSG("Could not set destination for UDP socket: %s:%d", destIp.c_str(), port);
}// Socket::UDPConnection SetDestination
/// Gets the properties of the receiving end of this UDP socket. /// Gets the properties of the receiving end of this UDP socket.
/// This will be the receiving end for all SendNow calls. /// This will be the receiving end for all SendNow calls.
void Socket::UDPConnection::GetDestination(std::string &destIp, uint32_t &port){ void Socket::UDPConnection::GetDestination(std::string &destIp, uint32_t &port){
if (!destAddr || !destAddr_size){ if (!destAddr.size()){
destIp = ""; destIp = "";
port = 0; port = 0;
return; return;
} }
char addr_str[INET6_ADDRSTRLEN + 1]; char addr_str[INET6_ADDRSTRLEN + 1];
addr_str[INET6_ADDRSTRLEN] = 0; // set last byte to zero, to prevent walking out of the array addr_str[INET6_ADDRSTRLEN] = 0; // set last byte to zero, to prevent walking out of the array
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET6){ if (((struct sockaddr *)(char*)destAddr)->sa_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)destAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){ if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)(char*)destAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str; destIp = addr_str;
port = ntohs(((struct sockaddr_in6 *)destAddr)->sin6_port); port = ntohs(((struct sockaddr_in6 *)(char*)destAddr)->sin6_port);
return; return;
} }
} }
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET){ if (((struct sockaddr_in *)(char*)destAddr)->sin_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)destAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){ if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(char*)destAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str; destIp = addr_str;
port = ntohs(((struct sockaddr_in *)destAddr)->sin_port); port = ntohs(((struct sockaddr_in *)(char*)destAddr)->sin_port);
return; return;
} }
} }
@ -2132,24 +2195,24 @@ void Socket::UDPConnection::GetDestination(std::string &destIp, uint32_t &port){
/// Gets the properties of the receiving end of the local UDP socket. /// Gets the properties of the receiving end of the local UDP socket.
/// This will be the sending end for all SendNow calls. /// This will be the sending end for all SendNow calls.
void Socket::UDPConnection::GetLocalDestination(std::string &destIp, uint32_t &port){ void Socket::UDPConnection::GetLocalDestination(std::string &destIp, uint32_t &port){
if (!recvAddr || !recvAddr_size){ if (!recvAddr.size()){
destIp = ""; destIp = "";
port = 0; port = 0;
return; return;
} }
char addr_str[INET6_ADDRSTRLEN + 1]; char addr_str[INET6_ADDRSTRLEN + 1];
addr_str[INET6_ADDRSTRLEN] = 0; // set last byte to zero, to prevent walking out of the array addr_str[INET6_ADDRSTRLEN] = 0; // set last byte to zero, to prevent walking out of the array
if (((struct sockaddr_in *)recvAddr)->sin_family == AF_INET6){ if (((struct sockaddr *)(char*)recvAddr)->sa_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)recvAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){ if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)(char*)recvAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str; destIp = addr_str;
port = ntohs(((struct sockaddr_in6 *)recvAddr)->sin6_port); port = ntohs(((struct sockaddr_in6 *)(char*)recvAddr)->sin6_port);
return; return;
} }
} }
if (((struct sockaddr_in *)recvAddr)->sin_family == AF_INET){ if (((struct sockaddr *)(char*)recvAddr)->sa_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)recvAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){ if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(char*)recvAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str; destIp = addr_str;
port = ntohs(((struct sockaddr_in *)recvAddr)->sin_port); port = ntohs(((struct sockaddr_in *)(char*)recvAddr)->sin_port);
return; return;
} }
} }
@ -2162,7 +2225,7 @@ void Socket::UDPConnection::GetLocalDestination(std::string &destIp, uint32_t &p
/// This will be the receiving end for all SendNow calls. /// This will be the receiving end for all SendNow calls.
std::string Socket::UDPConnection::getBinDestination(){ std::string Socket::UDPConnection::getBinDestination(){
std::string binList; std::string binList;
if (destAddr && destAddr_size){binList = getIPv6BinAddr(*(sockaddr_in6*)destAddr);} if (destAddr.size()){binList = getIPv6BinAddr(*(sockaddr_in6*)(char*)destAddr);}
if (binList.size() < 16){return std::string("\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 16);} if (binList.size() < 16){return std::string("\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 16);}
return binList.substr(0, 16); return binList.substr(0, 16);
}// Socket::UDPConnection GetDestination }// Socket::UDPConnection GetDestination
@ -2170,12 +2233,12 @@ std::string Socket::UDPConnection::getBinDestination(){
/// Returns the port number of the receiving end of this socket. /// Returns the port number of the receiving end of this socket.
/// Returns 0 on error. /// Returns 0 on error.
uint32_t Socket::UDPConnection::getDestPort() const{ uint32_t Socket::UDPConnection::getDestPort() const{
if (!destAddr || !destAddr_size){return 0;} if (!destAddr.size()){return 0;}
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET6){ if (((const struct sockaddr *)(const char*)destAddr)->sa_family == AF_INET6){
return ntohs(((struct sockaddr_in6 *)destAddr)->sin6_port); return ntohs(((const struct sockaddr_in6 *)(const char*)destAddr)->sin6_port);
} }
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET){ if (((const struct sockaddr *)(const char*)destAddr)->sa_family == AF_INET){
return ntohs(((struct sockaddr_in *)destAddr)->sin_port); return ntohs(((const struct sockaddr_in *)(const char*)destAddr)->sin_port);
} }
return 0; return 0;
} }
@ -2189,6 +2252,10 @@ void Socket::UDPConnection::setBlocking(bool blocking){
} }
} }
void Socket::UDPConnection::setIgnoreSendErrors(bool ign){
ignoreSendErrors = ign;
}
/// Sends a UDP datagram using the buffer sdata. /// Sends a UDP datagram using the buffer sdata.
/// This function simply calls SendNow(const char*, size_t) /// This function simply calls SendNow(const char*, size_t)
void Socket::UDPConnection::SendNow(const std::string &sdata){ void Socket::UDPConnection::SendNow(const std::string &sdata){
@ -2207,7 +2274,7 @@ void Socket::UDPConnection::SendNow(const char *sdata){
/// Does not do anything if len < 1. /// Does not do anything if len < 1.
/// Prints an DLVL_FAIL level debug message if sending failed. /// Prints an DLVL_FAIL level debug message if sending failed.
void Socket::UDPConnection::SendNow(const char *sdata, size_t len){ void Socket::UDPConnection::SendNow(const char *sdata, size_t len){
SendNow(sdata, len, (sockaddr*)destAddr, destAddr_size); SendNow(sdata, len, (sockaddr*)(char*)destAddr, destAddr.size());
} }
/// Sends a UDP datagram using the buffer sdata of length len. /// Sends a UDP datagram using the buffer sdata of length len.
@ -2220,6 +2287,7 @@ void Socket::UDPConnection::SendNow(const char *sdata, size_t len, sockaddr * dA
if (r > 0){ if (r > 0){
up += r; up += r;
}else{ }else{
if (ignoreSendErrors){return;}
if (errno == EDESTADDRREQ){ if (errno == EDESTADDRREQ){
close(); close();
return; return;
@ -2228,8 +2296,8 @@ void Socket::UDPConnection::SendNow(const char *sdata, size_t len, sockaddr * dA
} }
return; return;
} }
#if !defined(__CYGWIN__) && !defined(_WIN32) #ifdef HASPKTINFO
if (hasReceiveData && recvAddr){ if (hasReceiveData && recvAddr.size()){
msghdr mHdr; msghdr mHdr;
char msg_control[0x100]; char msg_control[0x100];
iovec iovec; iovec iovec;
@ -2244,22 +2312,34 @@ void Socket::UDPConnection::SendNow(const char *sdata, size_t len, sockaddr * dA
mHdr.msg_flags = 0; mHdr.msg_flags = 0;
int cmsg_space = 0; int cmsg_space = 0;
cmsghdr * cmsg = CMSG_FIRSTHDR(&mHdr); cmsghdr * cmsg = CMSG_FIRSTHDR(&mHdr);
if (family == AF_INET){
cmsg->cmsg_level = IPPROTO_IP; cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_PKTINFO; cmsg->cmsg_type = IP_PKTINFO;
struct in_pktinfo in_pktinfo; struct in_pktinfo in_pktinfo;
memcpy(&(in_pktinfo.ipi_spec_dst), &(((sockaddr_in*)recvAddr)->sin_family), sizeof(in_pktinfo.ipi_spec_dst)); memcpy(&(in_pktinfo.ipi_spec_dst), &(((sockaddr_in*)(char*)recvAddr)->sin_family), sizeof(in_pktinfo.ipi_spec_dst));
in_pktinfo.ipi_ifindex = recvInterface; in_pktinfo.ipi_ifindex = recvInterface;
cmsg->cmsg_len = CMSG_LEN(sizeof(in_pktinfo)); cmsg->cmsg_len = CMSG_LEN(sizeof(in_pktinfo));
*(struct in_pktinfo*)CMSG_DATA(cmsg) = in_pktinfo; *(struct in_pktinfo*)CMSG_DATA(cmsg) = in_pktinfo;
cmsg_space += CMSG_SPACE(sizeof(in_pktinfo)); cmsg_space += CMSG_SPACE(sizeof(in_pktinfo));
}else if (family == AF_INET6){
cmsg->cmsg_level = IPPROTO_IPV6;
cmsg->cmsg_type = IPV6_PKTINFO;
struct in6_pktinfo in6_pktinfo;
memcpy(&(in6_pktinfo.ipi6_addr), &(((sockaddr_in6*)(char*)recvAddr)->sin6_addr), sizeof(in6_pktinfo.ipi6_addr));
in6_pktinfo.ipi6_ifindex = recvInterface;
cmsg->cmsg_len = CMSG_LEN(sizeof(in6_pktinfo));
*(struct in6_pktinfo*)CMSG_DATA(cmsg) = in6_pktinfo;
cmsg_space += CMSG_SPACE(sizeof(in6_pktinfo));
}
mHdr.msg_controllen = cmsg_space; mHdr.msg_controllen = cmsg_space;
int r = sendmsg(sock, &mHdr, 0); int r = sendmsg(sock, &mHdr, 0);
if (r > 0){ if (r > 0){
up += r; up += r;
}else{ }else{
if (errno != ENETUNREACH){ if (errno != ENETUNREACH && !ignoreSendErrors){
FAIL_MSG("Could not send UDP data through %d: %s", sock, strerror(errno)); FAIL_MSG("Could not send UDP data through %d: %s", sock, strerror(errno));
} }
} }
@ -2270,11 +2350,11 @@ void Socket::UDPConnection::SendNow(const char *sdata, size_t len, sockaddr * dA
if (r > 0){ if (r > 0){
up += r; up += r;
}else{ }else{
if (errno != ENETUNREACH){ if (errno != ENETUNREACH && !ignoreSendErrors){
FAIL_MSG("Could not send UDP data through %d: %s", sock, strerror(errno)); FAIL_MSG("Could not send UDP data through %d: %s", sock, strerror(errno));
} }
} }
#if !defined(__CYGWIN__) && !defined(_WIN32) #ifdef HASPKTINFO
} }
#endif #endif
} }
@ -2372,6 +2452,10 @@ std::string Socket::UDPConnection::getBoundAddress(){
return boundaddr; return boundaddr;
} }
uint16_t Socket::UDPConnection::getBoundPort() const{
return boundPort;
}
/// Bind to a port number, returning the bound port. /// Bind to a port number, returning the bound port.
/// If that fails, returns zero. /// If that fails, returns zero.
/// \arg port Port to bind to, required. /// \arg port Port to bind to, required.
@ -2383,13 +2467,15 @@ uint16_t Socket::UDPConnection::bind(int port, std::string iface, const std::str
close(); // we open a new socket for each attempt close(); // we open a new socket for each attempt
int addr_ret; int addr_ret;
bool multicast = false; bool multicast = false;
bool repeatWithIPv4 = false;
struct addrinfo hints, *addr_result, *rp; struct addrinfo hints, *addr_result, *rp;
memset(&hints, 0, sizeof(hints)); memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE | AI_V4MAPPED; hints.ai_flags = AI_ADDRCONFIG | AI_PASSIVE | AI_V4MAPPED;
if (destAddr && destAddr_size){ if (destAddr.size()){
hints.ai_family = ((struct sockaddr_in *)destAddr)->sin_family; hints.ai_family = ((struct sockaddr *)(char*)destAddr)->sa_family;
}else{ }else{
hints.ai_family = AF_UNSPEC; hints.ai_family = AF_INET6;
repeatWithIPv4 = true;
} }
hints.ai_socktype = SOCK_DGRAM; hints.ai_socktype = SOCK_DGRAM;
@ -2398,14 +2484,24 @@ uint16_t Socket::UDPConnection::bind(int port, std::string iface, const std::str
std::stringstream ss; std::stringstream ss;
ss << port; ss << port;
repeatAddressFinding:
if (iface == "0.0.0.0" || iface.length() == 0){ if (iface == "0.0.0.0" || iface.length() == 0){
if ((addr_ret = getaddrinfo(0, ss.str().c_str(), &hints, &addr_result)) != 0){ if ((addr_ret = getaddrinfo(0, ss.str().c_str(), &hints, &addr_result)) != 0){
FAIL_MSG("Could not resolve %s for UDP: %s", iface.c_str(), gai_strmagic(addr_ret)); FAIL_MSG("Could not resolve %s for UDP: %s", iface.c_str(), gai_strmagic(addr_ret));
if (repeatWithIPv4 && hints.ai_family != AF_INET){
hints.ai_family = AF_INET;
goto repeatAddressFinding;
}
return 0; return 0;
} }
}else{ }else{
if ((addr_ret = getaddrinfo(iface.c_str(), ss.str().c_str(), &hints, &addr_result)) != 0){ if ((addr_ret = getaddrinfo(iface.c_str(), ss.str().c_str(), &hints, &addr_result)) != 0){
FAIL_MSG("Could not resolve %s for UDP: %s", iface.c_str(), gai_strmagic(addr_ret)); FAIL_MSG("Could not resolve %s for UDP: %s", iface.c_str(), gai_strmagic(addr_ret));
if (repeatWithIPv4 && hints.ai_family != AF_INET){
hints.ai_family = AF_INET;
goto repeatAddressFinding;
}
return 0; return 0;
} }
} }
@ -2422,7 +2518,7 @@ uint16_t Socket::UDPConnection::bind(int port, std::string iface, const std::str
} }
if (rp->ai_family == AF_INET6){ if (rp->ai_family == AF_INET6){
const int optval = 0; const int optval = 0;
if (setsockopt(sock, SOL_SOCKET, IPV6_V6ONLY, &optval, sizeof(optval)) < 0){ if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &optval, sizeof(optval)) < 0){
WARN_MSG("Could not set IPv6 UDP socket to be dual-stack! %s", strerror(errno)); WARN_MSG("Could not set IPv6 UDP socket to be dual-stack! %s", strerror(errno));
} }
} }
@ -2483,6 +2579,10 @@ uint16_t Socket::UDPConnection::bind(int port, std::string iface, const std::str
freeaddrinfo(addr_result); freeaddrinfo(addr_result);
if (sock == -1){ if (sock == -1){
FAIL_MSG("Could not open %s for UDP: %s", iface.c_str(), err_str.c_str()); FAIL_MSG("Could not open %s for UDP: %s", iface.c_str(), err_str.c_str());
if (repeatWithIPv4 && hints.ai_family != AF_INET){
hints.ai_family = AF_INET;
goto repeatAddressFinding;
}
return 0; return 0;
} }
@ -2570,7 +2670,7 @@ uint16_t Socket::UDPConnection::bind(int port, std::string iface, const std::str
} }
bool Socket::UDPConnection::connect(){ bool Socket::UDPConnection::connect(){
if (!recvAddr || !recvAddr_size || !destAddr || !destAddr_size){ if (!recvAddr.size() || !destAddr.size()){
WARN_MSG("Attempting to connect a UDP socket without local and/or remote address!"); WARN_MSG("Attempting to connect a UDP socket without local and/or remote address!");
return false; return false;
} }
@ -2579,27 +2679,23 @@ bool Socket::UDPConnection::connect(){
std::string destIp; std::string destIp;
uint32_t port = 0; uint32_t port = 0;
char addr_str[INET6_ADDRSTRLEN + 1]; char addr_str[INET6_ADDRSTRLEN + 1];
if (((struct sockaddr_in *)recvAddr)->sin_family == AF_INET6){ if (((struct sockaddr *)(char*)recvAddr)->sa_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)recvAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){ if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)(char*)recvAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str; destIp = addr_str;
port = ntohs(((struct sockaddr_in6 *)recvAddr)->sin6_port); port = ntohs(((struct sockaddr_in6 *)(char*)recvAddr)->sin6_port);
} }
} }
if (((struct sockaddr_in *)recvAddr)->sin_family == AF_INET){ if (((struct sockaddr *)(char*)recvAddr)->sa_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)recvAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){ if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(char*)recvAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str; destIp = addr_str;
port = ntohs(((struct sockaddr_in *)recvAddr)->sin_port); port = ntohs(((struct sockaddr_in *)(char*)recvAddr)->sin_port);
} }
} }
int ret = ::bind(sock, (const struct sockaddr*)recvAddr, recvAddr_size); int ret = ::bind(sock, (const struct sockaddr*)(char*)recvAddr, recvAddr.size());
if (!ret){ if (!ret){
INFO_MSG("Bound socket %d to %s:%" PRIu32, sock, destIp.c_str(), port); INFO_MSG("Bound socket %d to %s:%" PRIu32, sock, destIp.c_str(), port);
}else{ }else{
FAIL_MSG("Failed to bind socket %d (%s) %s:%" PRIu32 ": %s", sock, addrFam(((struct sockaddr_in *)recvAddr)->sin_family), destIp.c_str(), port, strerror(errno)); FAIL_MSG("Failed to bind socket %d (%s) %s:%" PRIu32 ": %s", sock, addrFam(((struct sockaddr *)(char*)recvAddr)->sa_family), destIp.c_str(), port, strerror(errno));
std::ofstream bleh("/tmp/socket_recv");
bleh.write((const char*)recvAddr, recvAddr_size);
bleh.write((const char*)destAddr, destAddr_size);
bleh.close();
return false; return false;
} }
} }
@ -2608,19 +2704,19 @@ bool Socket::UDPConnection::connect(){
std::string destIp; std::string destIp;
uint32_t port; uint32_t port;
char addr_str[INET6_ADDRSTRLEN + 1]; char addr_str[INET6_ADDRSTRLEN + 1];
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET6){ if (((struct sockaddr *)(char*)destAddr)->sa_family == AF_INET6){
if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)destAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){ if (inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)(char*)destAddr)->sin6_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str; destIp = addr_str;
port = ntohs(((struct sockaddr_in6 *)destAddr)->sin6_port); port = ntohs(((struct sockaddr_in6 *)(char*)destAddr)->sin6_port);
} }
} }
if (((struct sockaddr_in *)destAddr)->sin_family == AF_INET){ if (((struct sockaddr *)(char*)destAddr)->sa_family == AF_INET){
if (inet_ntop(AF_INET, &(((struct sockaddr_in *)destAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){ if (inet_ntop(AF_INET, &(((struct sockaddr_in *)(char*)destAddr)->sin_addr), addr_str, INET6_ADDRSTRLEN) != 0){
destIp = addr_str; destIp = addr_str;
port = ntohs(((struct sockaddr_in *)destAddr)->sin_port); port = ntohs(((struct sockaddr_in *)(char*)destAddr)->sin_port);
} }
} }
int ret = ::connect(sock, (const struct sockaddr*)destAddr, destAddr_size); int ret = ::connect(sock, (const struct sockaddr*)(char*)destAddr, destAddr.size());
if (!ret){ if (!ret){
INFO_MSG("Connected socket to %s:%" PRIu32, destIp.c_str(), port); INFO_MSG("Connected socket to %s:%" PRIu32, destIp.c_str(), port);
}else{ }else{
@ -2685,19 +2781,38 @@ bool Socket::UDPConnection::Receive(){
if (errno != EAGAIN){INFO_MSG("UDP receive: %d (%s)", errno, strerror(errno));} if (errno != EAGAIN){INFO_MSG("UDP receive: %d (%s)", errno, strerror(errno));}
return false; return false;
} }
if (destAddr && destsize && destAddr_size >= destsize){memcpy(destAddr, &addr, destsize);} if (destAddr.size() && destsize){destAddr.assign(&addr, destsize);}
#if !defined(__CYGWIN__) && !defined(_WIN32) #ifdef HASPKTINFO
if (recvAddr){ if (recvAddr.size()){
for ( struct cmsghdr *cmsg = CMSG_FIRSTHDR(&mHdr); cmsg != NULL; cmsg = CMSG_NXTHDR(&mHdr, cmsg)){ for ( struct cmsghdr *cmsg = CMSG_FIRSTHDR(&mHdr); cmsg != NULL; cmsg = CMSG_NXTHDR(&mHdr, cmsg)){
if (cmsg->cmsg_level != IPPROTO_IP || cmsg->cmsg_type != IP_PKTINFO){continue;} if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type == IP_PKTINFO){
struct in_pktinfo* pi = (in_pktinfo*)CMSG_DATA(cmsg); struct in_pktinfo* pi = (in_pktinfo*)CMSG_DATA(cmsg);
struct sockaddr_in * recvCast = (sockaddr_in*)recvAddr; if (family == AF_INET6){
recvCast->sin_family = family; struct sockaddr_in6 * recvCast = (sockaddr_in6*)(char*)recvAddr;
recvCast->sin6_port = htons(boundPort);
recvCast->sin6_family = AF_INET6;
memcpy(((char*)&(recvCast->sin6_addr)) + 12, &(pi->ipi_spec_dst), sizeof(pi->ipi_spec_dst));
memset((void*)&(recvCast->sin6_addr), 0, 10);
memset((char*)&(recvCast->sin6_addr) + 10, 255, 2);
}else{
struct sockaddr_in * recvCast = (sockaddr_in*)(char*)recvAddr;
recvCast->sin_port = htons(boundPort); recvCast->sin_port = htons(boundPort);
recvCast->sin_family = AF_INET;
memcpy(&(recvCast->sin_addr), &(pi->ipi_spec_dst), sizeof(pi->ipi_spec_dst)); memcpy(&(recvCast->sin_addr), &(pi->ipi_spec_dst), sizeof(pi->ipi_spec_dst));
}
recvInterface = pi->ipi_ifindex; recvInterface = pi->ipi_ifindex;
hasReceiveData = true; hasReceiveData = true;
} }
if (cmsg->cmsg_level == IPPROTO_IPV6 && cmsg->cmsg_type == IPV6_PKTINFO){
struct in6_pktinfo* pi = (in6_pktinfo*)CMSG_DATA(cmsg);
struct sockaddr_in6 * recvCast = (sockaddr_in6*)(char*)recvAddr;
recvCast->sin6_family = AF_INET6;
recvCast->sin6_port = htons(boundPort);
memcpy(&(recvCast->sin6_addr), &(pi->ipi6_addr), sizeof(pi->ipi6_addr));
recvInterface = pi->ipi6_ifindex;
hasReceiveData = true;
}
}
} }
#endif #endif
data.append(0, r); data.append(0, r);

View file

@ -51,10 +51,13 @@ namespace Buffer{
/// Holds Socket tools. /// Holds Socket tools.
namespace Socket{ namespace Socket{
std::string sockaddrToString(const sockaddr* A);
void hostBytesToStr(const char *bytes, size_t len, std::string &target); void hostBytesToStr(const char *bytes, size_t len, std::string &target);
bool isBinAddress(const std::string &binAddr, std::string matchTo); bool isBinAddress(const std::string &binAddr, std::string matchTo);
bool matchIPv6Addr(const std::string &A, const std::string &B, uint8_t prefix); bool matchIPv6Addr(const std::string &A, const std::string &B, uint8_t prefix);
bool compareAddress(const sockaddr* A, const sockaddr* B);
std::string getBinForms(std::string addr); std::string getBinForms(std::string addr);
std::deque<std::string> getAddrs(std::string addr, uint16_t port, int family = AF_UNSPEC);
/// Returns true if given human-readable address (address, not hostname) is a local address. /// Returns true if given human-readable address (address, not hostname) is a local address.
bool isLocal(const std::string &host); bool isLocal(const std::string &host);
/// Returns true if given human-readable hostname is a local address. /// Returns true if given human-readable hostname is a local address.
@ -215,14 +218,12 @@ namespace Socket{
class UDPConnection{ class UDPConnection{
private: private:
void init(bool nonblock, int family = AF_INET6); void init(bool nonblock, int family = AF_INET6);
int sock; ///< Internally saved socket number. int sock; ///< Internally saved socket number
std::string remotehost; ///< Stores remote host address std::string remotehost; ///< Stores remote host address
void *destAddr; ///< Destination address pointer. Util::ResizeablePointer destAddr; ///< Destination address
unsigned int destAddr_size; ///< Size of the destination address pointer. Util::ResizeablePointer recvAddr; ///< Local address
void *recvAddr; ///< Destination address pointer. unsigned int up; ///< Amount of bytes transferred up
unsigned int recvAddr_size; ///< Size of the destination address pointer. unsigned int down; ///< Amount of bytes transferred down
unsigned int up; ///< Amount of bytes transferred up.
unsigned int down; ///< Amount of bytes transferred down.
int family; ///< Current socket address family int family; ///< Current socket address family
std::string boundAddr, boundMulti; std::string boundAddr, boundMulti;
int boundPort; int boundPort;
@ -233,6 +234,7 @@ namespace Socket{
bool hasReceiveData; bool hasReceiveData;
bool isBlocking; bool isBlocking;
bool isConnected; bool isConnected;
bool ignoreSendErrors;
bool pretendReceive; ///< If true, will pretend to have just received the current data buffer on new Receive() call bool pretendReceive; ///< If true, will pretend to have just received the current data buffer on new Receive() call
bool onData(); bool onData();
@ -254,6 +256,7 @@ namespace Socket{
UDPConnection(const UDPConnection &o); UDPConnection(const UDPConnection &o);
UDPConnection(bool nonblock = false); UDPConnection(bool nonblock = false);
~UDPConnection(); ~UDPConnection();
void assimilate(int sock);
bool operator==(const UDPConnection& b) const; bool operator==(const UDPConnection& b) const;
operator bool() const; operator bool() const;
#ifdef SSL #ifdef SSL
@ -269,14 +272,18 @@ namespace Socket{
uint16_t bind(int port, std::string iface = "", const std::string &multicastAddress = ""); uint16_t bind(int port, std::string iface = "", const std::string &multicastAddress = "");
bool connect(); bool connect();
void setBlocking(bool blocking); void setBlocking(bool blocking);
void setIgnoreSendErrors(bool ign);
void allocateDestination(); void allocateDestination();
void SetDestination(std::string hostname, uint32_t port); void SetDestination(std::string hostname, uint32_t port);
bool setDestination(sockaddr * addr, size_t size);
const Util::ResizeablePointer & getRemoteAddr() const;
void GetDestination(std::string &hostname, uint32_t &port); void GetDestination(std::string &hostname, uint32_t &port);
void GetLocalDestination(std::string &hostname, uint32_t &port); void GetLocalDestination(std::string &hostname, uint32_t &port);
std::string getBinDestination(); std::string getBinDestination();
const void * getDestAddr(){return destAddr;} const void * getDestAddr(){return destAddr;}
size_t getDestAddrLen(){return destAddr_size;} size_t getDestAddrLen(){return destAddr.size();}
std::string getBoundAddress(); std::string getBoundAddress();
uint16_t getBoundPort() const;
uint32_t getDestPort() const; uint32_t getDestPort() const;
bool Receive(); bool Receive();
void SendNow(const std::string &data); void SendNow(const std::string &data);

View file

@ -1,5 +1,5 @@
#include "defines.h" #include "defines.h"
#include "lib/http_parser.h" #include "http_parser.h"
#include "socket_srt.h" #include "socket_srt.h"
#include "json.h" #include "json.h"
#include "timing.h" #include "timing.h"
@ -9,6 +9,15 @@
#define INVALID_SRT_SOCKET -1 #define INVALID_SRT_SOCKET -1
/// Calls gai_strerror with the given argument, calling regular strerror on the global errno as needed
static const char *gai_strmagic(int errcode){
if (errcode == EAI_SYSTEM){
return strerror(errno);
}else{
return gai_strerror(errcode);
}
}
namespace Socket{ namespace Socket{
namespace SRT{ namespace SRT{
bool isInited = false; bool isInited = false;
@ -26,6 +35,7 @@ namespace Socket{
bool libraryCleanup(){ bool libraryCleanup(){
if (isInited){ if (isInited){
alarm(2);
srt_cleanup(); srt_cleanup();
isInited = false; isInited = false;
} }
@ -41,17 +51,36 @@ namespace Socket{
sockaddr_in createInetAddr(const std::string &_host, int _port){ sockaddr_in createInetAddr(const std::string &_host, int _port){
sockaddr_in res; sockaddr_in res;
memset(&res, 9, sizeof res); memset(&res, 0, sizeof res);
res.sin_family = AF_INET; struct addrinfo *result, *rp, hints;
res.sin_port = htons(_port); std::stringstream ss;
ss << _port;
if (_host != ""){ memset(&hints, 0, sizeof(struct addrinfo));
if (inet_pton(AF_INET, _host.c_str(), &res.sin_addr) == 1){return res;} hints.ai_family = AF_INET6;
hostent *he = gethostbyname(_host.c_str()); hints.ai_socktype = SOCK_DGRAM;
if (!he || he->h_addrtype != AF_INET){ERROR_MSG("Host not found %s", _host.c_str());} hints.ai_flags = AI_ADDRCONFIG | AI_ALL;
res.sin_addr = *(in_addr *)he->h_addr_list[0]; hints.ai_protocol = IPPROTO_UDP;
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
int s = getaddrinfo(_host.c_str(), ss.str().c_str(), &hints, &result);
if (s != 0){
hints.ai_family = AF_UNSPEC;
s = getaddrinfo(_host.c_str(), ss.str().c_str(), &hints, &result);
if (s != 0){
FAIL_MSG("Could not connect SRT socket to %s:%i! Error: %s", _host.c_str(), _port, gai_strmagic(s));
return res;
}
} }
for (rp = result; rp != NULL; rp = rp->ai_next){
size_t maxSize = rp->ai_addrlen;
if (maxSize > sizeof(res)){maxSize = sizeof(res);}
memcpy(&res, rp->ai_addr, maxSize);
break;
}
freeaddrinfo(result);
return res; return res;
} }
@ -91,9 +120,9 @@ namespace Socket{
direction = rhs.direction; direction = rhs.direction;
remotehost = rhs.remotehost; remotehost = rhs.remotehost;
sock = rhs.sock; sock = rhs.sock;
HIGH_MSG("COPIED SRT socket %d", sock);
performanceMonitor = rhs.performanceMonitor; performanceMonitor = rhs.performanceMonitor;
host = rhs.host; host = rhs.host;
outgoing_port = rhs.outgoing_port;
prev_pktseq = rhs.prev_pktseq; prev_pktseq = rhs.prev_pktseq;
lastGood = rhs.lastGood; lastGood = rhs.lastGood;
chunkTransmitSize = rhs.chunkTransmitSize; chunkTransmitSize = rhs.chunkTransmitSize;
@ -110,17 +139,94 @@ namespace Socket{
SRTConnection::SRTConnection(const std::string &_host, int _port, const std::string &_direction, SRTConnection::SRTConnection(const std::string &_host, int _port, const std::string &_direction,
const std::map<std::string, std::string> &_params){ const std::map<std::string, std::string> &_params){
initializeEmpty();
connect(_host, _port, _direction, _params); connect(_host, _port, _direction, _params);
} }
SRTConnection::SRTConnection(Socket::UDPConnection & _udpsocket, const std::string &_direction, const paramList &_params){
initializeEmpty();
direction = "output";
handleConnectionParameters("", _params);
HIGH_MSG("Opening SRT connection in %s mode (%s) on socket %d", modeName.c_str(), direction.c_str(), _udpsocket.getSock());
// Copy address from UDP socket
memcpy(&remoteaddr, _udpsocket.getDestAddr(), _udpsocket.getDestAddrLen());
static char addrconv[INET6_ADDRSTRLEN];
if (remoteaddr.sin6_family == AF_INET6){
remotehost = inet_ntop(AF_INET6, &(remoteaddr.sin6_addr), addrconv, INET6_ADDRSTRLEN);
HIGH_MSG("IPv6 addr [%s]", remotehost.c_str());
}
if (remoteaddr.sin6_family == AF_INET){
remotehost = inet_ntop(AF_INET, &(((sockaddr_in *)&remoteaddr)->sin_addr), addrconv, INET6_ADDRSTRLEN);
HIGH_MSG("IPv4 addr [%s]", remotehost.c_str());
}
sock = srt_create_socket();
HIGH_MSG("Opened SRT socket %d", sock);
if (_direction == "rendezvous"){
bool v = true;
srt_setsockopt(sock, 0, SRTO_RENDEZVOUS, &v, sizeof v);
}
if (preConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error configuring SRT socket");
return;
}
srt_bind_acquire(sock, _udpsocket.getSock());
if (sock == SRT_INVALID_SOCK){
ERROR_MSG("Error creating an SRT socket from bound UDP socket");
return;
}
lastGood = Util::bootMS();
if (_direction == "rendezvous"){return;}
srt_listen(sock, 1);
SRTSOCKET tmpSock = srt_accept_bond(&sock, 1, 10000);
HIGH_MSG("Opened SRT socket %d", tmpSock);
close();
sock = tmpSock;
if (sock == SRT_INVALID_SOCK){
FAIL_MSG("SRT error: %s", srt_getlasterror_str());
return;
}
if (postConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error during postconfigure socket");
return;
}
HIGH_MSG("UDP to SRT socket conversion %" PRId32 ": %s", sock, getStateStr());
}
const char * SRTConnection::getStateStr(){
if (sock == INVALID_SRT_SOCKET){return "invalid / closed";}
int state = srt_getsockstate(sock);
switch (state){
case SRTS_INIT: return "init";
case SRTS_OPENED: return "opened";
case SRTS_LISTENING: return "listening";
case SRTS_CONNECTING: return "connecting";
case SRTS_CONNECTED: return "connected";
case SRTS_BROKEN: return "broken";
case SRTS_CLOSING: return "closing";
case SRTS_CLOSED: return "closed";
case SRTS_NONEXIST: return "does not exist";
}
return "unknown";
}
SRTConnection::SRTConnection(SRTSOCKET alreadyConnected){ SRTConnection::SRTConnection(SRTSOCKET alreadyConnected){
initializeEmpty(); initializeEmpty();
sock = alreadyConnected; sock = alreadyConnected;
HIGH_MSG("COPIED SRT socket %d", sock);
} }
std::string SRTConnection::getStreamName(){ std::string SRTConnection::getStreamName(){
int sNameLen = 512; int sNameLen = 512;
char sName[sNameLen]; char sName[512];
int optRes = srt_getsockflag(sock, SRTO_STREAMID, (void *)sName, &sNameLen); int optRes = srt_getsockflag(sock, SRTO_STREAMID, (void *)sName, &sNameLen);
if (optRes != -1 && sNameLen){return sName;} if (optRes != -1 && sNameLen){return sName;}
return ""; return "";
@ -158,8 +264,8 @@ namespace Socket{
} }
if (err == SRT_ENOCONN){ if (err == SRT_ENOCONN){
if (Util::bootMS() > lastGood + 5000){ if (Util::bootMS() > lastGood + 5000){
ERROR_MSG("SRT connection timed out - closing"); ERROR_MSG("SRT connection timed out");
close(); timedOut = true;
} }
return 0; return 0;
} }
@ -169,6 +275,7 @@ namespace Socket{
} }
if (receivedBytes == 0){ if (receivedBytes == 0){
close(); close();
return 0;
}else{ }else{
lastGood = Util::bootMS(); lastGood = Util::bootMS();
} }
@ -188,13 +295,14 @@ namespace Socket{
int err = srt_getlasterror(0); int err = srt_getlasterror(0);
if (err == SRT_EASYNCRCV){return 0;} if (err == SRT_EASYNCRCV){return 0;}
if (err == SRT_ECONNLOST){ if (err == SRT_ECONNLOST){
INFO_MSG("SRT connection %d lost", sock);
close(); close();
return 0; return 0;
} }
if (err == SRT_ENOCONN){ if (err == SRT_ENOCONN){
if (Util::bootMS() > lastGood + 5000){ if (Util::bootMS() > lastGood + 5000){
ERROR_MSG("SRT connection timed out - closing"); ERROR_MSG("SRT connection timed out - closing");
close(); timedOut = true;
} }
return 0; return 0;
} }
@ -203,7 +311,9 @@ namespace Socket{
return 0; return 0;
} }
if (receivedBytes == 0){ if (receivedBytes == 0){
INFO_MSG("SRT connection %d closed", sock);
close(); close();
return 0;
}else{ }else{
lastGood = Util::bootMS(); lastGood = Util::bootMS();
} }
@ -213,53 +323,45 @@ namespace Socket{
void SRTConnection::connect(const std::string &_host, int _port, const std::string &_direction, void SRTConnection::connect(const std::string &_host, int _port, const std::string &_direction,
const std::map<std::string, std::string> &_params){ const std::map<std::string, std::string> &_params){
initializeEmpty();
direction = _direction; direction = _direction;
timedOut = false;
handleConnectionParameters(_host, _params); handleConnectionParameters(_host, _params);
HIGH_MSG("Opening SRT connection %s in %s mode on %s:%d", modeName.c_str(), direction.c_str(), HIGH_MSG("Opening SRT connection %s in %s mode on %s:%d", modeName.c_str(), direction.c_str(),
_host.c_str(), _port); _host.c_str(), _port);
if (sock == SRT_INVALID_SOCK){
sock = srt_create_socket(); sock = srt_create_socket();
if (sock == SRT_ERROR){ HIGH_MSG("Opened SRT socket %d", sock);
if (sock == SRT_INVALID_SOCK){
ERROR_MSG("Error creating an SRT socket"); ERROR_MSG("Error creating an SRT socket");
return; return;
} }
if (modeName == "rendezvous"){
bool v = true;
srt_setsockopt(sock, 0, SRTO_RENDEZVOUS, &v, sizeof v);
}
if (preConfigureSocket() == SRT_ERROR){ if (preConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error configuring SRT socket"); ERROR_MSG("Error configuring SRT socket");
return; return;
} }
}
if (modeName == "caller"){ if (modeName == "caller"){
if (outgoing_port){setupAdapter("", outgoing_port);} std::deque<std::string> addrs = Socket::getAddrs(_host, _port);
for (std::deque<std::string>::iterator it = addrs.begin(); it != addrs.end(); ++it){
sockaddr_in sa = createInetAddr(_host, _port); size_t maxSize = it->size();
memcpy(&remoteaddr, &sa, sizeof(sockaddr_in)); if (maxSize > sizeof(remoteaddr)){maxSize = sizeof(remoteaddr);}
sockaddr *psa = (sockaddr *)&sa; memcpy(&remoteaddr, it->data(), maxSize);
sockaddr *psa = (sockaddr *)&remoteaddr;
HIGH_MSG("Going to connect sock %d", sock); HIGH_MSG("Going to connect sock %d", sock);
if (srt_connect(sock, psa, sizeof sa) == SRT_ERROR){ if (srt_connect(sock, psa, sizeof remoteaddr) != SRT_ERROR){
srt_close(sock); if (postConfigureSocket() == SRT_ERROR){ERROR_MSG("Error during postconfigure socket");}
sock = -1;
ERROR_MSG("Can't connect SRT Socket");
return;
}
HIGH_MSG("Connected sock %d", sock);
if (postConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error during postconfigure socket");
return;
}
INFO_MSG("Caller SRT socket %" PRId32 " success targetting %s:%u", sock, _host.c_str(), _port); INFO_MSG("Caller SRT socket %" PRId32 " success targetting %s:%u", sock, _host.c_str(), _port);
lastGood = Util::bootMS(); lastGood = Util::bootMS();
return; return;
} }
}
close();
ERROR_MSG("Can't connect SRT socket to any address for %s", _host.c_str());
return;
}
if (modeName == "listener"){ if (modeName == "listener"){
HIGH_MSG("Going to bind a server on %s:%u", _host.c_str(), _port); HIGH_MSG("Going to bind a server on %s:%u", _host.c_str(), _port);
@ -267,61 +369,19 @@ namespace Socket{
sockaddr *psa = (sockaddr *)&sa; sockaddr *psa = (sockaddr *)&sa;
if (srt_bind(sock, psa, sizeof sa) == SRT_ERROR){ if (srt_bind(sock, psa, sizeof sa) == SRT_ERROR){
srt_close(sock); close();
sock = -1;
ERROR_MSG("Can't connect SRT Socket: %s", srt_getlasterror_str()); ERROR_MSG("Can't connect SRT Socket: %s", srt_getlasterror_str());
return; return;
} }
if (srt_listen(sock, 100) == SRT_ERROR){ if (srt_listen(sock, 100) == SRT_ERROR){
srt_close(sock); close();
sock = -1;
ERROR_MSG("Can not listen on Socket"); ERROR_MSG("Can not listen on Socket");
} }
INFO_MSG("Listener SRT socket success @ %s:%u", _host.c_str(), _port); INFO_MSG("Listener SRT socket success @ %s:%u", _host.c_str(), _port);
lastGood = Util::bootMS(); lastGood = Util::bootMS();
return; return;
} }
if (modeName == "rendezvous"){ ERROR_MSG("Invalid mode parameter. Use 'caller' or 'listener'");
int outport = (outgoing_port ? outgoing_port : _port);
HIGH_MSG("Going to bind a server on %s:%u", _host.c_str(), _port);
sockaddr_in sa = createInetAddr(_host, outport);
sockaddr *psa = (sockaddr *)&sa;
if (srt_bind(sock, psa, sizeof sa) == SRT_ERROR){
srt_close(sock);
sock = -1;
ERROR_MSG("Can't connect SRT Socket");
return;
}
sockaddr_in sb = createInetAddr(_host, outport);
sockaddr *psb = (sockaddr *)&sb;
if (srt_connect(sock, psb, sizeof sb) == SRT_ERROR){
srt_close(sock);
sock = -1;
ERROR_MSG("Can't connect SRT Socket");
return;
}
if (postConfigureSocket() == SRT_ERROR){
ERROR_MSG("Error during postconfigure socket");
return;
}
INFO_MSG("Rendezvous SRT socket success @ %s:%u", _host.c_str(), _port);
lastGood = Util::bootMS();
return;
}
ERROR_MSG("Invalid mode parameter. Use 'client' or 'server'");
}
void SRTConnection::setupAdapter(const std::string &_host, int _port){
sockaddr_in localsa = createInetAddr(_host, _port);
sockaddr *psa = (sockaddr *)&localsa;
if (srt_bind(sock, psa, sizeof localsa) == SRT_ERROR){
ERROR_MSG("Unable to bind socket to %s:%u", _host.c_str(), _port);
}
} }
void SRTConnection::SendNow(const std::string &data){SendNow(data.data(), data.size());} void SRTConnection::SendNow(const std::string &data){SendNow(data.data(), data.size());}
@ -338,14 +398,17 @@ namespace Socket{
return; return;
} }
if (err == SRT_ENOCONN){ if (err == SRT_ENOCONN){
if (Util::bootMS() > lastGood + 5000){ if (Util::bootMS() > lastGood + 10000){
ERROR_MSG("SRT connection timed out - closing"); ERROR_MSG("SRT connection timed out - closing");
close(); timedOut = true;
} }
return; return;
} }
// ERROR_MSG("Unable to send data over socket %" PRId32 ": %s", sock, srt_getlasterror_str()); // ERROR_MSG("Unable to send data over socket %" PRId32 ": %s", sock, srt_getlasterror_str());
if (srt_getsockstate(sock) != SRTS_CONNECTED){close();} if (srt_getsockstate(sock) != SRTS_CONNECTED){
close();
return;
}
}else{ }else{
lastGood = Util::bootMS(); lastGood = Util::bootMS();
} }
@ -378,9 +441,9 @@ namespace Socket{
memset(&performanceMonitor, 0, sizeof(performanceMonitor)); memset(&performanceMonitor, 0, sizeof(performanceMonitor));
prev_pktseq = 0; prev_pktseq = 0;
sock = SRT_INVALID_SOCK; sock = SRT_INVALID_SOCK;
outgoing_port = 0;
chunkTransmitSize = 1316; chunkTransmitSize = 1316;
blocking = false; blocking = false;
timedOut = false;
timeout = 0; timeout = 0;
} }
@ -397,9 +460,9 @@ namespace Socket{
void SRTConnection::handleConnectionParameters(const std::string &_host, void SRTConnection::handleConnectionParameters(const std::string &_host,
const std::map<std::string, std::string> &_params){ const std::map<std::string, std::string> &_params){
params = _params; params = _params;
DONTEVEN_MSG("SRT Received parameters: "); VERYHIGH_MSG("SRT Received parameters: ");
for (std::map<std::string, std::string>::const_iterator it = params.begin(); it != params.end(); it++){ for (std::map<std::string, std::string>::const_iterator it = params.begin(); it != params.end(); it++){
DONTEVEN_MSG(" %s: %s", it->first.c_str(), it->second.c_str()); VERYHIGH_MSG(" %s: %s", it->first.c_str(), it->second.c_str());
} }
adapter = (params.count("adapter") ? params.at("adapter") : ""); adapter = (params.count("adapter") ? params.at("adapter") : "");
@ -417,8 +480,6 @@ namespace Socket{
tsbpdMode = (params.count("tsbpd") && JSON::Value(params.at("tsbpd")).asBool()); tsbpdMode = (params.count("tsbpd") && JSON::Value(params.at("tsbpd")).asBool());
outgoing_port = (params.count("port") ? strtol(params.at("port").c_str(), 0, 0) : 0);
if ((!params.count("transtype") || params.at("transtype") != "file") && chunkTransmitSize > SRT_LIVE_DEF_PLSIZE){ if ((!params.count("transtype") || params.at("transtype") != "file") && chunkTransmitSize > SRT_LIVE_DEF_PLSIZE){
if (chunkTransmitSize > SRT_LIVE_MAX_PLSIZE){ if (chunkTransmitSize > SRT_LIVE_MAX_PLSIZE){
ERROR_MSG("Chunk size in live mode exceeds 1456 bytes!"); ERROR_MSG("Chunk size in live mode exceeds 1456 bytes!");
@ -439,12 +500,10 @@ namespace Socket{
} }
if (srt_setsockopt(sock, 0, SRTO_RCVSYN, &no, sizeof no) == -1){return -1;} if (srt_setsockopt(sock, 0, SRTO_RCVSYN, &no, sizeof no) == -1){return -1;}
if (params.count("linger")){
linger lin; linger lin;
lin.l_linger = atoi(params.at("linger").c_str()); lin.l_linger = params.count("linger") ? atoi(params.at("linger").c_str()) : 0;
lin.l_onoff = lin.l_linger > 0 ? 1 : 0; lin.l_onoff = lin.l_linger ? 1 : 0;
srt_setsockopt(sock, 0, SRTO_LINGER, &lin, sizeof(linger)); srt_setsockopt(sock, 0, SRTO_LINGER, &lin, sizeof(linger));
}
std::string errMsg = configureSocketLoop(SRT::SockOpt::PRE); std::string errMsg = configureSocketLoop(SRT::SockOpt::PRE);
if (errMsg.size()){ if (errMsg.size()){
@ -490,9 +549,11 @@ namespace Socket{
} }
void SRTConnection::close(){ void SRTConnection::close(){
if (sock != -1){ if (sock != INVALID_SRT_SOCKET){
HIGH_MSG("Closing SRT socket %d", sock);
setBlocking(true);
srt_close(sock); srt_close(sock);
sock = -1; sock = INVALID_SRT_SOCKET;
} }
} }

View file

@ -37,12 +37,14 @@ namespace Socket{
SRTConnection(SRTSOCKET alreadyConnected); SRTConnection(SRTSOCKET alreadyConnected);
SRTConnection(const std::string &_host, int _port, const std::string &_direction = "input", SRTConnection(const std::string &_host, int _port, const std::string &_direction = "input",
const paramList &_params = paramList()); const paramList &_params = paramList());
SRTConnection(Socket::UDPConnection & _udpsocket, const std::string &_direction, const paramList &_params);
void connect(const std::string &_host, int _port, const std::string &_direction = "input", void connect(const std::string &_host, int _port, const std::string &_direction = "input",
const paramList &_params = paramList()); const paramList &_params = paramList());
void close(); void close();
bool connected() const{return sock != -1;} bool connected() const{return (sock != -1) && !timedOut;}
operator bool() const{return connected();} operator bool() const{return connected();}
const char * getStateStr();
void setBlocking(bool blocking); ///< Set this socket to be blocking (true) or nonblocking (false). void setBlocking(bool blocking); ///< Set this socket to be blocking (true) or nonblocking (false).
bool isBlocking(); ///< Check if this socket is blocking (true) or nonblocking (false). bool isBlocking(); ///< Check if this socket is blocking (true) or nonblocking (false).
@ -77,9 +79,9 @@ namespace Socket{
CBytePerfMon performanceMonitor; CBytePerfMon performanceMonitor;
std::string host; std::string host;
int outgoing_port;
int32_t prev_pktseq; int32_t prev_pktseq;
uint64_t lastGood; uint64_t lastGood;
bool timedOut;
uint32_t chunkTransmitSize; uint32_t chunkTransmitSize;
@ -94,7 +96,6 @@ namespace Socket{
void handleConnectionParameters(const std::string &_host, const paramList &_params); void handleConnectionParameters(const std::string &_host, const paramList &_params);
int preConfigureSocket(); int preConfigureSocket();
std::string configureSocketLoop(SRT::SockOpt::Binding _binding); std::string configureSocketLoop(SRT::SockOpt::Binding _binding);
void setupAdapter(const std::string &_host, int _port);
bool blocking; bool blocking;
}; };

View file

@ -213,7 +213,6 @@ namespace HTTP{
downer.getSocket().close(); downer.getSocket().close();
downer.getSocket().Received().clear(); downer.getSocket().Received().clear();
allData.truncate(0); allData.truncate(0);
if (!downer.isOk()){return false;}
supportRangeRequest = false; supportRangeRequest = false;
totalSize = std::string::npos; totalSize = std::string::npos;
}else{ }else{
@ -334,7 +333,16 @@ namespace HTTP{
// Note: this function returns true if the full read was completed only. // Note: this function returns true if the full read was completed only.
// It's the reason this function returns void rather than bool. // It's the reason this function returns void rather than bool.
size_t prev = cb.getDataCallbackPos(); size_t prev = cb.getDataCallbackPos();
downer.continueNonBlocking(cb); if (downer.continueNonBlocking(cb)){
if (downer.getStatusCode() >= 400){
WARN_MSG("Received error response code %" PRIu32 " (%s)", downer.getStatusCode(), downer.getStatusText().c_str());
// cb.dataCallbackFlush();
downer.getSocket().close();
downer.getSocket().Received().clear();
allData.truncate(0);
return 0;
}
}
return cb.getDataCallbackPos() - prev; return cb.getDataCallbackPos() - prev;
} }
// Everything else uses the socket directly // Everything else uses the socket directly

View file

@ -20,6 +20,7 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <fstream>
#define RAXHDR_FIELDOFFSET p[1] #define RAXHDR_FIELDOFFSET p[1]
#define RAX_REQDFIELDS_LEN 36 #define RAX_REQDFIELDS_LEN 36
@ -360,6 +361,20 @@ namespace Util{
maxSize = 0; maxSize = 0;
} }
ResizeablePointer::ResizeablePointer(const ResizeablePointer & rhs){
currSize = 0;
ptr = 0;
maxSize = 0;
append(rhs, rhs.size());
}
ResizeablePointer& ResizeablePointer::operator= (const ResizeablePointer& rhs){
if (this == &rhs){return *this;}
truncate(0);
append(rhs, rhs.size());
return *this;
}
void ResizeablePointer::shift(size_t byteCount){ void ResizeablePointer::shift(size_t byteCount){
//Shifting the entire buffer is easy, we do nothing and set size to zero //Shifting the entire buffer is easy, we do nothing and set size to zero
if (byteCount >= currSize){ if (byteCount >= currSize){
@ -371,6 +386,20 @@ namespace Util{
currSize -= byteCount; currSize -= byteCount;
} }
/// Takes another ResizeablePointer as argument and swaps their pointers around,
/// thus exchanging them without needing to copy anything.
void ResizeablePointer::swap(ResizeablePointer & rhs){
void * tmpPtr = ptr;
size_t tmpCurrSize = currSize;
size_t tmpMaxSize = maxSize;
ptr = rhs.ptr;
currSize = rhs.currSize;
maxSize = rhs.maxSize;
rhs.ptr = tmpPtr;
rhs.currSize = tmpCurrSize;
rhs.maxSize = tmpMaxSize;
}
bool ResizeablePointer::assign(const void *p, uint32_t l){ bool ResizeablePointer::assign(const void *p, uint32_t l){
if (!allocate(l)){return false;} if (!allocate(l)){return false;}
memcpy(ptr, p, l); memcpy(ptr, p, l);
@ -405,12 +434,7 @@ namespace Util{
bool ResizeablePointer::allocate(uint32_t l){ bool ResizeablePointer::allocate(uint32_t l){
if (l > maxSize){ if (l > maxSize){
void *tmp = 0; void *tmp = realloc(ptr, l);
if (!ptr){
tmp = malloc(l);
}else{
tmp = realloc(ptr, l);
}
if (!tmp){ if (!tmp){
FAIL_MSG("Could not allocate %" PRIu32 " bytes of memory", l); FAIL_MSG("Could not allocate %" PRIu32 " bytes of memory", l);
return false; return false;

View file

@ -48,6 +48,8 @@ namespace Util{
class ResizeablePointer{ class ResizeablePointer{
public: public:
ResizeablePointer(); ResizeablePointer();
ResizeablePointer(const ResizeablePointer & rhs);
ResizeablePointer& operator= (const ResizeablePointer& rhs);
~ResizeablePointer(); ~ResizeablePointer();
inline size_t &size(){return currSize;} inline size_t &size(){return currSize;}
inline const size_t size() const{return currSize;} inline const size_t size() const{return currSize;}
@ -57,6 +59,7 @@ namespace Util{
bool append(const std::string &str); bool append(const std::string &str);
bool allocate(uint32_t l); bool allocate(uint32_t l);
void shift(size_t byteCount); void shift(size_t byteCount);
void swap(ResizeablePointer & rhs);
uint32_t rsize(); uint32_t rsize();
void truncate(const size_t newLen); void truncate(const size_t newLen);
inline operator char *(){return (char *)ptr;} inline operator char *(){return (char *)ptr;}

View file

@ -1,12 +1,14 @@
</head> </head>
<body> <body>
<nav> <nav>
<div class="textures"></div>
<a href='#' class=logo>MistServer</a> <a href='#' class=logo>MistServer</a>
<div class=menu> <div class=menu>
</div> </div>
</nav> </nav>
<div class=filler> <div class=filler>
<header> <header>
<div class="texture"></div>
<h1>Management Interface</h1> <h1>Management Interface</h1>
<aside id=status> <aside id=status>
<span id='connection' class='red'>Disconnected</span> <span id='connection' class='red'>Disconnected</span>

View file

@ -0,0 +1,4 @@
<svg viewBox="0 0 202.52 150" version="1.1" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid meet">
<path d="m53.406 10.557-5.0488 3.3223 42.061 63.951c-1.0569 1.2973-1.8786 2.7896-2.418 4.4121h-70.115v6.0449h69.498c0.81169 6.9508 6.713 12.344 13.879 12.344 7.1658 0 13.064-5.393 13.875-12.344h69.5v-6.0449h-70.117c-0.53924-1.6225-1.3594-3.1148-2.416-4.4121l42.061-63.951-5.0508-3.3223-41.777 63.518c-1.8391-0.89026-3.894-1.4043-6.0742-1.4043-2.1814 0-4.238 0.51505-6.0781 1.4062z" fill="#b5d3e2"/>
<path d="m49.875 0c-7.0953 0-12.848 5.7519-12.848 12.846 0 3.7198 1.5899 7.0604 4.1152 9.4062l-20.535 46.447c-1.0469-0.19686-2.1225-0.31055-3.2266-0.31055-9.5991 0-17.381 7.783-17.381 17.381 0 9.5997 7.7817 17.381 17.381 17.381 5.3445 0 10.122-2.4174 13.311-6.2129l54.49 29.096c-0.83369 2.0328-1.3008 4.2547-1.3008 6.5879 0 9.5997 7.7811 17.379 17.379 17.379 9.5997 0 17.381-7.7792 17.381-17.379 0-2.3333-0.46899-4.5551-1.3027-6.5879l54.492-29.098c3.1877 3.796 7.963 6.2148 13.309 6.2148 9.5997 0 17.381-7.7812 17.381-17.381 0-9.5978-7.7812-17.381-17.381-17.381-1.1042 0-2.1796 0.11369-3.2266 0.31055l-20.535-46.447c2.5256-2.3459 4.1152-5.6861 4.1152-9.4062 0-7.0938-5.7519-12.846-12.846-12.846-5.9165 0-10.885 4.0056-12.377 9.4473h-78.018c-1.4922-5.4418-6.4613-9.4473-12.377-9.4473zm13.406 15.492h75.957l-24.789 11.568c-3.1173-3.8293-7.8647-6.2793-13.188-6.2793-5.3228 0-10.072 2.45-13.189 6.2793zm-3.498 5.5312 24.967 12.77c-0.30913 1.2822-0.49218 2.6131-0.49218 3.9902 0 1.6082 0.23907 3.1582 0.65625 4.6328l-54.004 32.453c-1.2919-1.6017-2.8674-2.9575-4.6426-4.0176l20.174-45.635c1.0944 0.30322 2.2426 0.47851 3.4336 0.47851 3.9887 0 7.552-1.819 9.9082-4.6719zm82.953 0c2.3561 2.8528 5.9208 4.6719 9.9102 4.6719 1.1903 0 2.3377-0.17551 3.4316-0.47851l20.176 45.635c-1.7754 1.0602-3.3507 2.4157-4.6426 4.0176l-54.004-32.453c0.41706-1.4746 0.6543-3.0247 0.6543-4.6328 0-1.377-0.18122-2.7081-0.49024-3.9902zm-54.041 28.186c2.2766 2.5025 5.2868 4.3206 8.6894 5.1211v61.355c-3.5044 0.80386-6.605 2.6644-8.9492 5.2324l-54.734-29.225c0.67236-1.8515 1.0605-3.8399 1.0605-5.9238 0-1.8275-0.28752-3.5875-0.81055-5.2422zm25.131 2e-3 54.742 31.316c-0.52293 1.6547-0.80859 3.4147-0.80859 5.2422 0 2.0838 0.38643 4.0724 1.0586 5.9238l-54.734 29.225c-2.3448-2.5682-5.4441-4.4287-8.9492-5.2324v-61.354c3.4038-0.79961 6.4143-2.6181 8.6914-5.1211z" fill="#8cb3cf"/>
</svg>

After

Width:  |  Height:  |  Size: 2.3 KiB

8
lsp/images/bin.svg Normal file
View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-linecap:round;stroke-linejoin:round;stroke-width:2;stroke:black">
<path d="m37.911 25.289v29.464m5.912-30.901v29.464m-11.823-27.378v29.464m-5.911-30.113v29.464m-5.912-30.901v29.464m-6.09-34.372 2.0832 35.971c8.8845 3.9794 18.734 5.7595 31.761.29565l2.1104-36.298" />
<path d="m13.099 12.895c7.7397-4.6876 30.017-4.6844 37.926-.09329l-.06132 5.8224c-9.8599 4.1879-26.296 4.0174-37.855-.24019z"/>
<path d="m38.84 11.832v-3.4648c0-1.5465-1.2445-2.791-2.791-2.791h-7.793c-1.5465 0-2.791 1.2445-2.791 2.791v3.4648" style="fill:none;"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 745 B

2
lsp/images/embed.svg Normal file
View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0,1.599)" style="fill:#fff;stroke-linejoin:round;stroke-width:2;stroke:#000"><path id="embed_a" d="m41.235 15.244v7.4431l12.655 7.6678-12.655 7.7982v7.4043l19.765-12.669v-5.1286z"/><path d="m25.809 45.827h5.2092l7.1731-30.852h-5.1407z" style="fill:#bbb"/><use transform="matrix(-1,0,0,1,64,0)" href="#embed_a"/></g></svg>

After

Width:  |  Height:  |  Size: 503 B

2
lsp/images/folder.svg Normal file
View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m3 24.95v38.05h58v-45.308l-20.045.13815-7.412 7.2845z" style="fill:none;stroke-linejoin:round;stroke-width:2;stroke:black"/></svg>

After

Width:  |  Height:  |  Size: 297 B

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="55.3" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<path id="a" d="m41.5 82-27.7-16v-32l27.7-16" style="fill:#ccc"/>
<use transform="translate(-27.7 -48)" xlink:href="#a"/>
<use transform="translate(-27.7 48)" xlink:href="#a"/>
<use transform="translate(27.7,-48)" xlink:href="#a"/>
<use transform="translate(27.7,48)" xlink:href="#a"/>
</svg>

After

Width:  |  Height:  |  Size: 524 B

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-width:2;stroke:black;stroke-linejoin:round">
<path d="m26.76 5.6635c-7.5343 0-13.601 6.0188-13.601 13.497v11.019h-1.3072c-1.5978 0-2.884 1.2767-2.884 2.8627v23.508c0 1.586 1.2862 2.8627 2.884 2.8627h31.152c1.5978 0 2.884-1.2767 2.884-2.8627v-23.508c0-1.586-1.2862-2.8627-2.884-2.8627h-1.3072v-11.019c0-7.4787-6.067-13.497-13.601-13.497h-1.3342zm.66709 5.5315c4.9411 0 8.9181 3.9476 8.9181 8.8523v10.133h-17.836v-10.133c0-4.9046 3.977-8.8523 8.9181-8.8523zm0 24.955a5.3965 5.3567 0 015.3973 5.3575 5.3965 5.3567 0 01-1.1084 3.1737l.78501 9.18h-10.148l.78501-9.18a5.3965 5.3567 0 01-1.1084-3.1737 5.3965 5.3567 0 015.3973-5.3575z"/>
<path d="m46.396 3.3457a12.774 12.774 0 00-12.773 12.773 12.774 12.774 0 007.9375 11.795l.13086 27.883 3.9941 4.2812 4.0762-4.2812v-2.582l.93359-1.0742-.93359-1.0059v-2.0195l1.1309-1.2285-2.3105-2.8203 1.9492-2.0469-.76953-.77734v-1.6406l1.1387-1.6445-1.1387-1.6309v-2.8945h.58203v-2.5293h.88867v-3.9883a12.774 12.774 0 007.9375-11.795 12.774 12.774 0 00-12.773-12.773zm0 4.6367a2.7302 2.7302 0 012.7305 2.7305 2.7302 2.7302 0 01-2.7305 2.7305 2.7302 2.7302 0 01-2.7305-2.7305 2.7302 2.7302 0 012.7305-2.7305z" style="fill:#bbb"/></g>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

13
lsp/images/nuke.svg Normal file
View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill:white;stroke-linejoin:round;stroke-width:2;stroke:#000">
<circle cx="32" cy="32" r="25.82"/>
<g style="fill:#bbb">
<circle cx="32" cy="32" r="3.1649" />
<path id="nuke_a" d="m35.089 26.907c1.7185 1.0445 2.8663 2.9346 2.866 5.0926h15.059c3.2e-5-7.7385-4.183-14.5-10.411-18.147z" />
<use transform="rotate(120 32 32)" href="#nuke_a"/>
<use transform="rotate(240 32 32)" href="#nuke_a"/>
</g></g>
</svg>

After

Width:  |  Height:  |  Size: 619 B

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" xmlns="http://www.w3.org/2000/svg">
<path d="m17.449 8.781a4.3899 4.3892 0 00-2.0138 3.6931l.02568 42.198a4.3899 4.3892 0 006.5995 3.782l36.55-21.099a4.3899 4.3892 0 00-.01639-7.5822l-36.576-21.099a4.3899 4.3892 0 00-4.5693.107z" style="fill:#fff;stroke-width:2;stroke:#000"/>
</svg>

After

Width:  |  Height:  |  Size: 367 B

9
lsp/images/preview.svg Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-linejoin:round;stroke-width:2;stroke:black">
<rect x="3" y="11.068" width="58" height="41.864" rx="4.3702" ry="4.3702" style="fill:#999"/>
<rect x="3" y="46.094" width="58" height="6.8374" rx="0" ry="0" style="fill:#888"/>
<path d="m28.168 21.579c-.32531.20939-.52183.56983-.52162.95671l.0067 10.931c.00099.40652.21892.78159.57162.98374.3527.20215.78648.20062 1.1377-.004l9.4671-5.4658c.34883-.20454.56278-.57894.5619-.98331-.000891-.40437-.21644-.77785-.56615-.98087l-9.4738-5.4654c-.36858-.21304-.8253-.20233-1.1835.02774v0"/>
<rect x="3" y="46.094" width="18.513" height="6.8374" rx="0" ry="0"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 797 B

7
lsp/images/prompt.ignore Normal file
View file

@ -0,0 +1,7 @@
https://ai-generator.livepeer.cloud/
Create a simple icon. The subject is <subbject>. The background is bright white. Make the subject as simple as possible, instead fill large areas with black.
resolution: 512x512
steps: 50
guidance scale: 3.5

2
lsp/images/return.svg Normal file
View file

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><path d="m23.281 40.259 1.6271-4.0733-21.419 6.9038 20.588 8.0913-1.2718-3.8278c39.218 0 62.256-18.891.9224-18.891 39.996 0 40.549 11.797-.44748 11.797z" style="fill:white;stroke-linejoin:round;stroke-width:2;stroke:#000"/></svg>

After

Width:  |  Height:  |  Size: 387 B

7
lsp/images/settings.svg Normal file
View file

@ -0,0 +1,7 @@
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-linejoin:round;stroke-linecap:round;stroke-width:2;stroke:#000">
<path d="m4.4688 12.736s-2.0621 7.6884 2.2158 12.786c4.2779 5.0979 11.307 4.6211 11.307 4.6211s27.012 25.587 29.406 27.869 8.5275 2.1674 11.066-.90518c2.5384-3.0726 2.2306-7.4614-.46845-10.211s-27.997-27.545-27.997-27.545.6011-8.1225-4.8868-12.408c-5.4879-4.2856-13.415-1.7504-13.415-1.7504s8.7811 7.3913 8.762 9.4592c-.01913 2.0679-3.916 6.2966-6.3076 6.4202s-9.681-8.3364-9.681-8.3364z"/>
<path d="m22.633 38.006s-6.736 7.5891-8.0449 8.4199c-1.3089.83085-3.5855-.2392-4.4648.80469-.87936 1.0439-6.5742 9.1207-6.5742 10.383l2.4688 2.377c1.2622 0 9.3389-5.6949 10.383-6.5742s-.02812-3.1559.80273-4.4648c.64227-1.0118 2.3172-1.885 8.4219-8.0449z"/>
<path d="m40.861 26.306 14.533-14.533m-17.375 11.694 14.533-14.533m-2.3952-3.6008-15.215 15.059 8.6584 8.6493 15.449-14.514c2.7285-2.5225 2.4789-6.8937.16099-8.9833-2.318-2.0896-6.1056-2.7806-9.0534-.21097z" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

20
lsp/images/status.svg Normal file
View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g style="fill:#ccc;stroke-linecap:round;stroke-linejoin:round;stroke-width:2;stroke:#000">
<path d="m26.816 7.4258v.87305h-1.0586v1.4805h-.99805v42.021h1.498v1.2207h11.484v-1.2207h1.498v-42.021h-.99805v-1.4805h-1.0586v-.87305h-10.367z"/>
<path d="m28.678 60.63v-7.6083h6.6448v7.6083"/>
<path id="status_a" d="m39.24 37.375h8.6066c0 3.302-.4732 4.3899-3.0278 5.5674s-3.5266 3.5141-4.0095 5.1494.05917 2.6733-1.5693 2.6733z"/>
<use id="status_b" transform="translate(0 -26.03)" href="#status_a"/>
<use id="status_c" transform="translate(0,-13.015)" href="#status_a"/>
<use transform="matrix(-1 0 0 1 63.892 0)" href="#status_a"/>
<use transform="matrix(-1,0,0,1,63.892,0)" href="#status_c"/>
<use transform="matrix(-1 0 0 1 63.892 0)" href="#status_b"/>
<g style="fill:#fff;stroke-width:1.5">
<path d="m29.228 12.969c-.21726.14276-.3485.3885-.34836.65228l.0045 7.4528c.000662.27716.1462.53288.38175.67071.23554.13782.52525.13678.75984-.0027l6.3225-3.7265c.23296-.13945.37584-.39472.37526-.67042-.000662-.2757-.14455-.53033-.3781-.66875l-6.327-3.7262c-.24616-.14525-.55117-.13795-.79038.01891"/>
<path d="m28.631 33.591a.91153.69906 0 00.8543.69339h.51971a.91153.69906 0 00.90415-.65518v-5.6399a.91153.69906 0 00-.8543-.6934h-.51971a.91153.69906 0 00-.90412.65518z"/>
<path d="m33.188 33.591a.91153.69906 0 00.8543.69339h.51969a.91153.69906 0 00.90415-.65518v-5.6399a.91153.69906 0 00-.8543-.6934h-.51969a.91153.69906 0 00-.90415.65518z"/>
<rect x="28.5" y="40.855" width="7" height="7"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

7
lsp/images/stop.svg Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="64" height="64" version="1.1" viewBox="0 0 64 64" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
<g style="fill:white;stroke-linecap:round;stroke-linejoin:round;stroke-width:2;stroke:#000">
<path d="m16.564 58.246s.27018-3.0341-.47957-4.5114-3.7331-1.0108-5.1198-6.5631c-1.5007-6.0087-1.1589-11.304.08641-16.021.03329-.1261.42694-13.37.64983-15.41.20442-1.8708 3.537-2.2802 4.3239-.96699.78927 1.3172 1.1392 14.198 1.1392 14.198s-.58395-17.69.65463-21.119c.93458-2.5873 4.348-1.9673 4.8895-.50415 1.1377 3.0744 1.2248 21.386 1.486 21.358 2e-6 0-.28989-15.948.47589-23.456.27165-2.6633 5.7062-3.3332 5.8418.38078.6057 16.6.71775 22.883.71775 22.883s-.18809-13.139.77038-19.004c.48999-2.9982 4.0818-4.0291 5.2626.12132.94806 3.3323.83166 25.886.83166 25.886 3.9578-.31514 6.126-4.0335 9.4217-4.9206 3.2958-.88712 7.4839-.88189 7.7241 2.5082.24024 3.3901-6.2486 2.079-8.9921 8.9748s-7.7062 10.483-9.724 11.538c-2.0178 1.0559-1.3502 4.9943-1.3502 4.9943-3.1568.52358-15.602.68533-18.61-.36635z"/>
<path d="m16.196 29.234c.68211-.37578 1.3442-.30741 1.998-.05263m4.9785-.13114c.73722-.55467 1.4554-.37523 1.9592-.0516m5.1708-.1362c.58432-.51144 1.32-.39807 2.1111-.05561m-17.211 24.02c1.2363.71309 2.742 1.3089 4.3832 1.7712m12.704.7217c2.096-.42638 3.3585-1.2068 4.7751-2.0055m-11.456-2.3503c-.29197-8.4288 3.6119-12.731 9.5389-15.044" style="fill:none;stroke-width:1.5"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

File diff suppressed because one or more lines are too long

View file

@ -1,14 +1,16 @@
var MD5=function(a){function b(a,b){var c,h,d,e,g;d=a&2147483648;e=b&2147483648;c=a&1073741824;h=b&1073741824;g=(a&1073741823)+(b&1073741823);return c&h?g^2147483648^d^e:c|h?g&1073741824?g^3221225472^d^e:g^1073741824^d^e:g^d^e}function d(a,c,h,d,e,g,f){a=b(a,b(b(c&h|~c&d,e),f));return b(a<<g|a>>>32-g,c)}function c(a,c,h,d,e,g,f){a=b(a,b(b(c&d|h&~d,e),f));return b(a<<g|a>>>32-g,c)}function e(a,c,h,d,e,g,f){a=b(a,b(b(c^h^d,e),f));return b(a<<g|a>>>32-g,c)}function l(a,c,h,d,g,e,f){a=b(a,b(b(h^(c|~d), var MD5=function(a){function b(a,b){var d,c,e,g,f;e=a&2147483648;g=b&2147483648;d=a&1073741824;c=b&1073741824;f=(a&1073741823)+(b&1073741823);return d&c?f^2147483648^e^g:d|c?f&1073741824?f^3221225472^e^g:f^1073741824^e^g:f^e^g}function e(a,d,c,e,g,f,h){a=b(a,b(b(d&c|~d&e,g),h));return b(a<<f|a>>>32-f,d)}function c(a,d,c,e,g,f,h){a=b(a,b(b(d&e|c&~e,g),h));return b(a<<f|a>>>32-f,d)}function d(a,d,c,e,g,f,h){a=b(a,b(b(d^c^e,g),h));return b(a<<f|a>>>32-f,d)}function j(a,d,c,e,g,f,h){a=b(a,b(b(c^(d|~e),
g),f));return b(a<<e|a>>>32-e,c)}function i(a){var b="",c="",h;for(h=0;3>=h;h++)c=a>>>8*h&255,c="0"+c.toString(16),b+=c.substr(c.length-2,2);return b}var f=[],m,n,j,q,g,h,k,o,f=a.replace(/\r\n/g,"\n"),a="";for(m=0;m<f.length;m++)n=f.charCodeAt(m),128>n?a+=String.fromCharCode(n):(127<n&&2048>n?a+=String.fromCharCode(n>>6|192):(a+=String.fromCharCode(n>>12|224),a+=String.fromCharCode(n>>6&63|128)),a+=String.fromCharCode(n&63|128));f=a;a=f.length;m=a+8;n=16*((m-m%64)/64+1);j=Array(n-1);for(g=q=0;g<a;)m= g),h));return b(a<<f|a>>>32-f,d)}function i(a){var b="",d="",c;for(c=0;3>=c;c++)d=a>>>8*c&255,d="0"+d.toString(16),b+=d.substr(d.length-2,2);return b}var f=[],m,n,k,q,h,g,l,o,f=a.replace(/\r\n/g,"\n"),a="";for(m=0;m<f.length;m++)n=f.charCodeAt(m),128>n?a+=String.fromCharCode(n):(127<n&&2048>n?a+=String.fromCharCode(n>>6|192):(a+=String.fromCharCode(n>>12|224),a+=String.fromCharCode(n>>6&63|128)),a+=String.fromCharCode(n&63|128));f=a;a=f.length;m=a+8;n=16*((m-m%64)/64+1);k=Array(n-1);for(h=q=0;h<a;)m=
(g-g%4)/4,q=8*(g%4),j[m]|=f.charCodeAt(g)<<q,g++;m=(g-g%4)/4;j[m]|=128<<8*(g%4);j[n-2]=a<<3;j[n-1]=a>>>29;f=j;g=1732584193;h=4023233417;k=2562383102;o=271733878;for(a=0;a<f.length;a+=16)m=g,n=h,j=k,q=o,g=d(g,h,k,o,f[a+0],7,3614090360),o=d(o,g,h,k,f[a+1],12,3905402710),k=d(k,o,g,h,f[a+2],17,606105819),h=d(h,k,o,g,f[a+3],22,3250441966),g=d(g,h,k,o,f[a+4],7,4118548399),o=d(o,g,h,k,f[a+5],12,1200080426),k=d(k,o,g,h,f[a+6],17,2821735955),h=d(h,k,o,g,f[a+7],22,4249261313),g=d(g,h,k,o,f[a+8],7,1770035416), (h-h%4)/4,q=8*(h%4),k[m]|=f.charCodeAt(h)<<q,h++;m=(h-h%4)/4;k[m]|=128<<8*(h%4);k[n-2]=a<<3;k[n-1]=a>>>29;f=k;h=1732584193;g=4023233417;l=2562383102;o=271733878;for(a=0;a<f.length;a+=16)m=h,n=g,k=l,q=o,h=e(h,g,l,o,f[a+0],7,3614090360),o=e(o,h,g,l,f[a+1],12,3905402710),l=e(l,o,h,g,f[a+2],17,606105819),g=e(g,l,o,h,f[a+3],22,3250441966),h=e(h,g,l,o,f[a+4],7,4118548399),o=e(o,h,g,l,f[a+5],12,1200080426),l=e(l,o,h,g,f[a+6],17,2821735955),g=e(g,l,o,h,f[a+7],22,4249261313),h=e(h,g,l,o,f[a+8],7,1770035416),
o=d(o,g,h,k,f[a+9],12,2336552879),k=d(k,o,g,h,f[a+10],17,4294925233),h=d(h,k,o,g,f[a+11],22,2304563134),g=d(g,h,k,o,f[a+12],7,1804603682),o=d(o,g,h,k,f[a+13],12,4254626195),k=d(k,o,g,h,f[a+14],17,2792965006),h=d(h,k,o,g,f[a+15],22,1236535329),g=c(g,h,k,o,f[a+1],5,4129170786),o=c(o,g,h,k,f[a+6],9,3225465664),k=c(k,o,g,h,f[a+11],14,643717713),h=c(h,k,o,g,f[a+0],20,3921069994),g=c(g,h,k,o,f[a+5],5,3593408605),o=c(o,g,h,k,f[a+10],9,38016083),k=c(k,o,g,h,f[a+15],14,3634488961),h=c(h,k,o,g,f[a+4],20,3889429448), o=e(o,h,g,l,f[a+9],12,2336552879),l=e(l,o,h,g,f[a+10],17,4294925233),g=e(g,l,o,h,f[a+11],22,2304563134),h=e(h,g,l,o,f[a+12],7,1804603682),o=e(o,h,g,l,f[a+13],12,4254626195),l=e(l,o,h,g,f[a+14],17,2792965006),g=e(g,l,o,h,f[a+15],22,1236535329),h=c(h,g,l,o,f[a+1],5,4129170786),o=c(o,h,g,l,f[a+6],9,3225465664),l=c(l,o,h,g,f[a+11],14,643717713),g=c(g,l,o,h,f[a+0],20,3921069994),h=c(h,g,l,o,f[a+5],5,3593408605),o=c(o,h,g,l,f[a+10],9,38016083),l=c(l,o,h,g,f[a+15],14,3634488961),g=c(g,l,o,h,f[a+4],20,3889429448),
g=c(g,h,k,o,f[a+9],5,568446438),o=c(o,g,h,k,f[a+14],9,3275163606),k=c(k,o,g,h,f[a+3],14,4107603335),h=c(h,k,o,g,f[a+8],20,1163531501),g=c(g,h,k,o,f[a+13],5,2850285829),o=c(o,g,h,k,f[a+2],9,4243563512),k=c(k,o,g,h,f[a+7],14,1735328473),h=c(h,k,o,g,f[a+12],20,2368359562),g=e(g,h,k,o,f[a+5],4,4294588738),o=e(o,g,h,k,f[a+8],11,2272392833),k=e(k,o,g,h,f[a+11],16,1839030562),h=e(h,k,o,g,f[a+14],23,4259657740),g=e(g,h,k,o,f[a+1],4,2763975236),o=e(o,g,h,k,f[a+4],11,1272893353),k=e(k,o,g,h,f[a+7],16,4139469664), h=c(h,g,l,o,f[a+9],5,568446438),o=c(o,h,g,l,f[a+14],9,3275163606),l=c(l,o,h,g,f[a+3],14,4107603335),g=c(g,l,o,h,f[a+8],20,1163531501),h=c(h,g,l,o,f[a+13],5,2850285829),o=c(o,h,g,l,f[a+2],9,4243563512),l=c(l,o,h,g,f[a+7],14,1735328473),g=c(g,l,o,h,f[a+12],20,2368359562),h=d(h,g,l,o,f[a+5],4,4294588738),o=d(o,h,g,l,f[a+8],11,2272392833),l=d(l,o,h,g,f[a+11],16,1839030562),g=d(g,l,o,h,f[a+14],23,4259657740),h=d(h,g,l,o,f[a+1],4,2763975236),o=d(o,h,g,l,f[a+4],11,1272893353),l=d(l,o,h,g,f[a+7],16,4139469664),
h=e(h,k,o,g,f[a+10],23,3200236656),g=e(g,h,k,o,f[a+13],4,681279174),o=e(o,g,h,k,f[a+0],11,3936430074),k=e(k,o,g,h,f[a+3],16,3572445317),h=e(h,k,o,g,f[a+6],23,76029189),g=e(g,h,k,o,f[a+9],4,3654602809),o=e(o,g,h,k,f[a+12],11,3873151461),k=e(k,o,g,h,f[a+15],16,530742520),h=e(h,k,o,g,f[a+2],23,3299628645),g=l(g,h,k,o,f[a+0],6,4096336452),o=l(o,g,h,k,f[a+7],10,1126891415),k=l(k,o,g,h,f[a+14],15,2878612391),h=l(h,k,o,g,f[a+5],21,4237533241),g=l(g,h,k,o,f[a+12],6,1700485571),o=l(o,g,h,k,f[a+3],10,2399980690), g=d(g,l,o,h,f[a+10],23,3200236656),h=d(h,g,l,o,f[a+13],4,681279174),o=d(o,h,g,l,f[a+0],11,3936430074),l=d(l,o,h,g,f[a+3],16,3572445317),g=d(g,l,o,h,f[a+6],23,76029189),h=d(h,g,l,o,f[a+9],4,3654602809),o=d(o,h,g,l,f[a+12],11,3873151461),l=d(l,o,h,g,f[a+15],16,530742520),g=d(g,l,o,h,f[a+2],23,3299628645),h=j(h,g,l,o,f[a+0],6,4096336452),o=j(o,h,g,l,f[a+7],10,1126891415),l=j(l,o,h,g,f[a+14],15,2878612391),g=j(g,l,o,h,f[a+5],21,4237533241),h=j(h,g,l,o,f[a+12],6,1700485571),o=j(o,h,g,l,f[a+3],10,2399980690),
k=l(k,o,g,h,f[a+10],15,4293915773),h=l(h,k,o,g,f[a+1],21,2240044497),g=l(g,h,k,o,f[a+8],6,1873313359),o=l(o,g,h,k,f[a+15],10,4264355552),k=l(k,o,g,h,f[a+6],15,2734768916),h=l(h,k,o,g,f[a+13],21,1309151649),g=l(g,h,k,o,f[a+4],6,4149444226),o=l(o,g,h,k,f[a+11],10,3174756917),k=l(k,o,g,h,f[a+2],15,718787259),h=l(h,k,o,g,f[a+9],21,3951481745),g=b(g,m),h=b(h,n),k=b(k,j),o=b(o,q);return(i(g)+i(h)+i(k)+i(o)).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==m)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(i){case "string":case "string-ins":b=String(b).toLowerCase();break;case "int":b= l=j(l,o,h,g,f[a+10],15,4293915773),g=j(g,l,o,h,f[a+1],21,2240044497),h=j(h,g,l,o,f[a+8],6,1873313359),o=j(o,h,g,l,f[a+15],10,4264355552),l=j(l,o,h,g,f[a+6],15,2734768916),g=j(g,l,o,h,f[a+13],21,1309151649),h=j(h,g,l,o,f[a+4],6,4149444226),o=j(o,h,g,l,f[a+11],10,3174756917),l=j(l,o,h,g,f[a+2],15,718787259),g=j(g,l,o,h,f[a+9],21,3951481745),h=b(h,m),g=b(g,n),l=b(l,k),o=b(o,q);return(i(h)+i(g)+i(l)+i(o)).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 d=0,c;a(b).children("td,th").each(function(){if(d==m)return c=a(this),!1;var b=a(this).attr("colspan");d+=b?Number(b):1});b="undefined"!=typeof c.data("sort-value")?c.data("sort-value"):"undefined"!=typeof c.attr("data-sort-value")?c.attr("data-sort-value"):c.text();switch(i){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 d=a(this),c=d.closest("table"),e=c.children("tbody"),l=e.children("tr"),i=d.attr("data-sort-type");if(i){var f=!0;d.hasClass("sorting-asc")&&(f=!1);var m=0;d.prevAll().each(function(){var b=a(this).attr("colspan");m+=b?Number(b):1});l.sort(function(a,c){var d=f?1:-1,a=b(a),c=b(c);return a>c?1*d:a<c?-1*d:0});e.append(l);c.find("thead th").removeClass("sorting-asc").removeClass("sorting-desc");d.addClass(f?"sorting-asc":"sorting-desc")}}})(jQuery);$(function(){UI.elements={menu:$("nav > .menu"),main:$("main"),header:$("header"),connection:{status:$("#connection"),user_and_host:$("#user_and_host"),msg:$("#message")}};UI.buildMenu();UI.stored.getOpts();try{if("mistLogin"in sessionStorage){var a=JSON.parse(sessionStorage.mistLogin);mist.user.name=a.name;mist.user.password=a.password;mist.user.host=a.host}}catch(b){}location.hash&&(a=decodeURIComponent(location.hash).substring(1).split("@")[0].split("&"),mist.user.name=a[0],a[1]&&(mist.user.host= parseInt(Number(b));break;case "float":b=Number(b)}return b}var e=a(this),c=e.closest("table"),d=c.children("tbody"),j=d.children("tr"),i=e.attr("data-sort-type");if(i){var f=!0;e.hasClass("sorting-asc")&&(f=!1);var m=0;e.prevAll().each(function(){var b=a(this).attr("colspan");m+=b?Number(b):1});j.sort(function(a,d){var c=f?1:-1,a=b(a),d=b(d);return a>d?1*c:a<d?-1*c:0});d.append(j);c.find("thead th").removeClass("sorting-asc").removeClass("sorting-desc");e.addClass(f?"sorting-asc":"sorting-desc")}}})(jQuery);$(function(){UI.elements={menu:$("nav > .menu"),main:$("main"),header:$("header"),connection:{status:$("#connection"),user_and_host:$("#user_and_host"),msg:$("#message")}};UI.buildMenu();UI.stored.getOpts();$("body").on("keydown",function(a){switch(a.key){case "Escape":UI.elements.context_menu&&UI.elements.context_menu.hide()}});UI.elements.main.click(function(a){UI.elements.context_menu&&!a.isDefaultPrevented()&&UI.elements.context_menu.hide()});var a=!1;UI.elements.main.on("mousedown",function(b){var c=
a[1]));mist.send(function(){$(window).trigger("hashchange")},{},{timeout:5,hide:!0});var d=0;$("body > div.filler").on("scroll",function(){var a=$(this).scrollLeft();a!=d&&UI.elements.header.css("margin-right",-1*a+"px");d=a})});var lastpage=[];$(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],lastpage);if(lastpage[0]!=a[0]||lastpage[1]!=a[1])lastpage=[a[0],a[1]]}); b.target;a=setTimeout(function(){function e(a){a.preventDefault()}function f(){window.removeEventListener("click",e,!0);document.removeEventListener("mouseup",f)}a=!1;var m=new Event("contextmenu",{bubbles:!0});m.pageX=b.pageX;m.pageY=b.pageY;c.dispatchEvent(m);window.addEventListener("click",e,!0);document.addEventListener("mouseup",function(){requestAnimationFrame(f)})},1500)});UI.elements.main.on("mouseleave",function(){a&&(clearTimeout(a),a=!1)});UI.elements.main.on("mouseup",function(){a&&(clearTimeout(a),
a=!1)});try{if("mistLogin"in sessionStorage){var b=JSON.parse(sessionStorage.mistLogin);mist.user.name=b.name;mist.user.password=b.password;mist.user.host=b.host}}catch(e){}location.hash&&(b=decodeURIComponent(location.hash).substring(1).split("@")[0].split("&"),mist.user.name=b[0],b[1]&&(mist.user.host=b[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})});var lastpage=[];$(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],lastpage);if(lastpage[0]!=a[0]||lastpage[1]!=a[1])lastpage=[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:{list:{},clear:function(){for(var a in this.list)clearInterval(this.list[a].id);this.list={}},set:function(a,b){this.opts&&log("[interval]","Set called on interval, but an interval is already active."); 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:{list:{},clear:function(){for(var a in this.list)clearInterval(this.list[a].id);this.list={}},set:function(a,b){this.opts&&log("[interval]","Set called on interval, but an interval is already active.");
var d={delay:b,callback:a,id:setInterval(a,b)};this.list[d.id]=d;return d.id}},websockets:{list:[],clear:function(){for(var a in this.list)this.list[a].close()},create:function(a){var b=new WebSocket(a),d=this;this.list.push(b);b.addEventListener("close",function(){for(var a=d.list.length-1;0<=a;a--)d.list[a]==b&&d.list.splice(a,1)});return b}},countrylist:{AF:"Afghanistan",AX:"&Aring;land Islands",AL:"Albania",DZ:"Algeria",AS:"American Samoa",AD:"Andorra",AO:"Angola",AI:"Anguilla",AQ:"Antarctica", var e={delay:b,callback:a,id:setInterval(a,b)};this.list[e.id]=e;return e.id}},websockets:{list:[],clear:function(){for(var a in this.list)this.list[a].close()},create:function(a){var b=new WebSocket(a),e=this;this.list.push(b);b.addEventListener("close",function(){for(var a=e.list.length-1;0<=a;a--)e.list[a]==b&&e.list.splice(a,1)});return b}},countrylist:{AF:"Afghanistan",AX:"&Aring;land Islands",AL:"Albania",DZ:"Algeria",AS:"American Samoa",AD:"Andorra",AO:"Angola",AI:"Anguilla",AQ:"Antarctica",
AG:"Antigua and Barbuda",AR:"Argentina",AM:"Armenia",AW:"Aruba",AU:"Australia",AT:"Austria",AZ:"Azerbaijan",BS:"Bahamas",BH:"Bahrain",BD:"Bangladesh",BB:"Barbados",BY:"Belarus",BE:"Belgium",BZ:"Belize",BJ:"Benin",BM:"Bermuda",BT:"Bhutan",BO:"Bolivia, Plurinational State of",BQ:"Bonaire, Sint Eustatius and Saba",BA:"Bosnia and Herzegovina",BW:"Botswana",BV:"Bouvet Island",BR:"Brazil",IO:"British Indian Ocean Territory",BN:"Brunei Darussalam",BG:"Bulgaria",BF:"Burkina Faso",BI:"Burundi",KH:"Cambodia", AG:"Antigua and Barbuda",AR:"Argentina",AM:"Armenia",AW:"Aruba",AU:"Australia",AT:"Austria",AZ:"Azerbaijan",BS:"Bahamas",BH:"Bahrain",BD:"Bangladesh",BB:"Barbados",BY:"Belarus",BE:"Belgium",BZ:"Belize",BJ:"Benin",BM:"Bermuda",BT:"Bhutan",BO:"Bolivia, Plurinational State of",BQ:"Bonaire, Sint Eustatius and Saba",BA:"Bosnia and Herzegovina",BW:"Botswana",BV:"Bouvet Island",BR:"Brazil",IO:"British Indian Ocean Territory",BN:"Brunei Darussalam",BG:"Bulgaria",BF:"Burkina Faso",BI:"Burundi",KH:"Cambodia",
CM:"Cameroon",CA:"Canada",CV:"Cape Verde",KY:"Cayman Islands",CF:"Central African Republic",TD:"Chad",CL:"Chile",CN:"China",CX:"Christmas Island",CC:"Cocos (Keeling) Islands",CO:"Colombia",KM:"Comoros",CG:"Congo",CD:"Congo, the Democratic Republic of the",CK:"Cook Islands",CR:"Costa Rica",CI:"C&ocirc;te d'Ivoire",HR:"Croatia",CU:"Cuba",CW:"Cura&ccedil;ao",CY:"Cyprus",CZ:"Czech Republic",DK:"Denmark",DJ:"Djibouti",DM:"Dominica",DO:"Dominican Republic",EC:"Ecuador",EG:"Egypt",SV:"El Salvador",GQ:"Equatorial Guinea", CM:"Cameroon",CA:"Canada",CV:"Cape Verde",KY:"Cayman Islands",CF:"Central African Republic",TD:"Chad",CL:"Chile",CN:"China",CX:"Christmas Island",CC:"Cocos (Keeling) Islands",CO:"Colombia",KM:"Comoros",CG:"Congo",CD:"Congo, the Democratic Republic of the",CK:"Cook Islands",CR:"Costa Rica",CI:"C&ocirc;te d'Ivoire",HR:"Croatia",CU:"Cuba",CW:"Cura&ccedil;ao",CY:"Cyprus",CZ:"Czech Republic",DK:"Denmark",DJ:"Djibouti",DM:"Dominica",DO:"Dominican Republic",EC:"Ecuador",EG:"Egypt",SV:"El Salvador",GQ:"Equatorial Guinea",
ER:"Eritrea",EE:"Estonia",ET:"Ethiopia",FK:"Falkland Islands (Malvinas)",FO:"Faroe Islands",FJ:"Fiji",FI:"Finland",FR:"France",GF:"French Guiana",PF:"French Polynesia",TF:"French Southern Territories",GA:"Gabon",GM:"Gambia",GE:"Georgia",DE:"Germany",GH:"Ghana",GI:"Gibraltar",GR:"Greece",GL:"Greenland",GD:"Grenada",GP:"Guadeloupe",GU:"Guam",GT:"Guatemala",GG:"Guernsey",GN:"Guinea",GW:"Guinea-Bissau",GY:"Guyana",HT:"Haiti",HM:"Heard Island and McDonald Islands",VA:"Holy See (Vatican City State)",HN:"Honduras", ER:"Eritrea",EE:"Estonia",ET:"Ethiopia",FK:"Falkland Islands (Malvinas)",FO:"Faroe Islands",FJ:"Fiji",FI:"Finland",FR:"France",GF:"French Guiana",PF:"French Polynesia",TF:"French Southern Territories",GA:"Gabon",GM:"Gambia",GE:"Georgia",DE:"Germany",GH:"Ghana",GI:"Gibraltar",GR:"Greece",GL:"Greenland",GD:"Grenada",GP:"Guadeloupe",GU:"Guam",GT:"Guatemala",GG:"Guernsey",GN:"Guinea",GW:"Guinea-Bissau",GY:"Guyana",HT:"Haiti",HM:"Heard Island and McDonald Islands",VA:"Holy See (Vatican City State)",HN:"Honduras",
@ -17,346 +19,369 @@ MK:"Macedonia, the former Yugoslav Republic of",MG:"Madagascar",MW:"Malawi",MY:"
NU:"Niue",NF:"Norfolk Island",MP:"Northern Mariana Islands",NO:"Norway",OM:"Oman",PK:"Pakistan",PW:"Palau",PS:"Palestine, State of",PA:"Panama",PG:"Papua New Guinea",PY:"Paraguay",PE:"Peru",PH:"Philippines",PN:"Pitcairn",PL:"Poland",PT:"Portugal",PR:"Puerto Rico",QA:"Qatar",RE:"R&eacute;union",RO:"Romania",RU:"Russian Federation",RW:"Rwanda",BL:"Saint Barth&eacute;lemy",SH:"Saint Helena, Ascension and Tristan da Cunha",KN:"Saint Kitts and Nevis",LC:"Saint Lucia",MF:"Saint Martin (French part)",PM:"Saint Pierre and Miquelon", NU:"Niue",NF:"Norfolk Island",MP:"Northern Mariana Islands",NO:"Norway",OM:"Oman",PK:"Pakistan",PW:"Palau",PS:"Palestine, State of",PA:"Panama",PG:"Papua New Guinea",PY:"Paraguay",PE:"Peru",PH:"Philippines",PN:"Pitcairn",PL:"Poland",PT:"Portugal",PR:"Puerto Rico",QA:"Qatar",RE:"R&eacute;union",RO:"Romania",RU:"Russian Federation",RW:"Rwanda",BL:"Saint Barth&eacute;lemy",SH:"Saint Helena, Ascension and Tristan da Cunha",KN:"Saint Kitts and Nevis",LC:"Saint Lucia",MF:"Saint Martin (French part)",PM:"Saint Pierre and Miquelon",
VC:"Saint Vincent and the Grenadines",WS:"Samoa",SM:"San Marino",ST:"Sao Tome and Principe",SA:"Saudi Arabia",SN:"Senegal",RS:"Serbia",SC:"Seychelles",SL:"Sierra Leone",SG:"Singapore",SX:"Sint Maarten (Dutch part)",SK:"Slovakia",SI:"Slovenia",SB:"Solomon Islands",SO:"Somalia",ZA:"South Africa",GS:"South Georgia and the South Sandwich Islands",SS:"South Sudan",ES:"Spain",LK:"Sri Lanka",SD:"Sudan",SR:"Suriname",SJ:"Svalbard and Jan Mayen",SZ:"Swaziland",SE:"Sweden",CH:"Switzerland",SY:"Syrian Arab Republic", VC:"Saint Vincent and the Grenadines",WS:"Samoa",SM:"San Marino",ST:"Sao Tome and Principe",SA:"Saudi Arabia",SN:"Senegal",RS:"Serbia",SC:"Seychelles",SL:"Sierra Leone",SG:"Singapore",SX:"Sint Maarten (Dutch part)",SK:"Slovakia",SI:"Slovenia",SB:"Solomon Islands",SO:"Somalia",ZA:"South Africa",GS:"South Georgia and the South Sandwich Islands",SS:"South Sudan",ES:"Spain",LK:"Sri Lanka",SD:"Sudan",SR:"Suriname",SJ:"Svalbard and Jan Mayen",SZ:"Swaziland",SE:"Sweden",CH:"Switzerland",SY:"Syrian Arab Republic",
TW:"Taiwan, Province of China",TJ:"Tajikistan",TZ:"Tanzania, United Republic of",TH:"Thailand",TL:"Timor-Leste",TG:"Togo",TK:"Tokelau",TO:"Tonga",TT:"Trinidad and Tobago",TN:"Tunisia",TR:"Turkey",TM:"Turkmenistan",TC:"Turks and Caicos Islands",TV:"Tuvalu",UG:"Uganda",UA:"Ukraine",AE:"United Arab Emirates",GB:"United Kingdom",US:"United States",UM:"United States Minor Outlying Islands",UY:"Uruguay",UZ:"Uzbekistan",VU:"Vanuatu",VE:"Venezuela, Bolivarian Republic of",VN:"Viet Nam",VG:"Virgin Islands, British", TW:"Taiwan, Province of China",TJ:"Tajikistan",TZ:"Tanzania, United Republic of",TH:"Thailand",TL:"Timor-Leste",TG:"Togo",TK:"Tokelau",TO:"Tonga",TT:"Trinidad and Tobago",TN:"Tunisia",TR:"Turkey",TM:"Turkmenistan",TC:"Turks and Caicos Islands",TV:"Tuvalu",UG:"Uganda",UA:"Ukraine",AE:"United Arab Emirates",GB:"United Kingdom",US:"United States",UM:"United States Minor Outlying Islands",UY:"Uruguay",UZ:"Uzbekistan",VU:"Vanuatu",VE:"Venezuela, Bolivarian Republic of",VN:"Viet Nam",VG:"Virgin Islands, British",
VI:"Virgin Islands, U.S.",WF:"Wallis and Futuna",EH:"Western Sahara",YE:"Yemen",ZM:"Zambia",ZW:"Zimbabwe"},tooltip:{show:function(a,b){$tooltip=this.element;$.contains(document.body,$tooltip[0])||$("body").append($tooltip);$tooltip.html(b);clearTimeout(this.hiding);delete this.hiding;var d=$(document).height()-$tooltip.outerHeight(),c=$(document).width()-$tooltip.outerWidth();$tooltip.css("left",Math.min(a.pageX+10,c-10));$tooltip.css("top",Math.min(a.pageY+25,d-10));$tooltip.show().addClass("show")}, VI:"Virgin Islands, U.S.",WF:"Wallis and Futuna",EH:"Western Sahara",YE:"Yemen",ZM:"Zambia",ZW:"Zimbabwe"},tooltip:{show:function(a,b){$tooltip=this.element;$.contains(document.body,$tooltip[0])||$("body").append($tooltip);$tooltip.html(b);clearTimeout(this.hiding);delete this.hiding;var e=$(document).height()-$tooltip.outerHeight(),c=$(document).width()-$tooltip.outerWidth();$tooltip.css("left",Math.min(a.pageX+10,c-10));$tooltip.css("top",Math.min(a.pageY+25,e-10));$tooltip.show().addClass("show")},
hide:function(){$tooltip=this.element;$tooltip.removeClass("show");this.hiding=setTimeout(function(){$tooltip.hide()},500)},element:$("<div>").attr("id","tooltip")},humanMime:function(a){var b=!1;switch(a){case "html5/application/vnd.apple.mpegurl":b="HLS (TS)";break;case "html5/application/vnd.apple.mpegurl;version=7":b="HLS (CMAF)";break;case "html5/application/sdp":b="SDP";break;case "html5/video/webm":b="WebM";break;case "html5/video/raw":b="Raw";break;case "html5/video/mp4":b="MP4";break;case "ws/video/mp4":b= hide:function(){$tooltip=this.element;$tooltip.removeClass("show");this.hiding=setTimeout(function(){$tooltip.hide()},500)},element:$("<div>").attr("id","tooltip")},context_menu:function(){var a=$("<section>").attr("id","context_menu");a[0].style.display="none";this.ele=a;UI.elements.context_menu=this;this.pos=function(b){var e=a.parent(),c=e.height()-a.outerHeight(),d=e.width()-a.outerWidth();a.css("left",Math.min(b.pageX-e.position().left,d));a.css("top",Math.min(b.pageY-e.position().top,c))};this.show=
function(b,e){if("string"==typeof b||b instanceof jQuery)a.html(b);else if("object"==typeof b){a.html("");Array.isArray(b)||(b=[b]);for(var c in b){var d=b[c];if(d instanceof jQuery)a.children().last().remove(),a.append(d);else for(var j in d){var i=d[j],f=$("<div>");if("string"==typeof i)f.text(i);else if(i instanceof jQuery){a.append(i);continue}else 2<=i.length&&"function"==typeof i[1]&&(f.click(i[1]),f.on("keydown",function(a){switch(a.key){case "Enter":$(this).click()}}),f.attr("tabindex","0")),
3<=i.length&&(1<i[2].length?f.append($("<div>").addClass("icon").attr("data-icon",i[2])):f.attr("data-icon",i[2]),4<=i.length&&f.attr("title",i[3])),f.append(i[0]);a.append(f)}a.append($("<hr>"))}a.children().last().remove();a.find("[tabindex]").first().focus()}a.parent()||$("body").append(a);e&&this.pos(e);a[0].style.display=""};this.hide=function(){a[0].style.display="none"};this.remove=function(){delete UI.element.context_menu;a.remove()};a.on("keydown",function(b){function e(b){var d=a.find(":focus");
d.length?"down"==b?(b=d.nextAll("[tabindex]"),b.length?b.first().focus():a.find("[tabindex]").first().focus()):(b=d.prevAll("[tabindex]"),b.length?b.first().focus():a.find("[tabindex]").last().focus()):a.find("[tabindex]").first().focus()}switch(b.key){case "ArrowDown":e("down");break;case "ArrowUp":e("up")}});this.hide()},pagecontrol:function(a,b){function e(a){var b=document.createElement("button");b.appendChild(document.createTextNode(a));b.addEventListener("click",function(){c(a)});d.elements.page_buttons[a]=
b;d.elements.page_button_cont.append(b);return b}function c(b){perpage=d.vars.page_size;b||(b=d.vars.currentpage);"next"==b&&(b=d.vars.currentpage+1);"previous"==b&&(b=d.vars.currentpage-1);var c=a.querySelectorAll(":scope > :not(.hidden)");d.vars.entries=c.length;!j&&0<d.vars.entries&&(j=getComputedStyle(c[0]).getPropertyValue("display"));c=c.length;b instanceof HTMLElement&&(b=Array.from(a.children).indexOf(b),b=Math.floor(b/perpage)+1);b=Math.max(1,b);maxpage=Math.floor((c-1)/perpage)+1;b=Math.min(b,
maxpage);for(c=1;c<=maxpage;c++)switch(c in d.elements.page_buttons||e(c),c){case 1:case b-1:case b:case b+1:case maxpage:d.elements.page_buttons[c].classList.remove("hidden");break;default:d.elements.page_buttons[c].classList.add("hidden")}for(var m=Object.keys(d.elements.page_buttons),c=maxpage;c<m.length;c++)d.elements.page_buttons[m[c]].classList.add("hidden");d.vars.currentpage in d.elements.page_buttons&&d.elements.page_buttons[d.vars.currentpage].classList.remove("active");1==b?d.elements.prev.attr("disabled",
""):d.elements.prev.removeAttr("disabled");b==maxpage?d.elements.next.attr("disabled",""):d.elements.next.removeAttr("disabled");d.vars.currentpage=b;d.vars.currentpage in d.elements.page_buttons&&d.elements.page_buttons[b].classList.add("active");c="."+d.vars.uid+" > * { display: none !important; }\n";c+="."+d.vars.uid+" > *:not(.hidden) ";c+="~ *:not(.hidden) ".repeat(Math.max(0,perpage*(b-1)));c+="{ display: "+(j?j:"revert")+" !important; }\n";c+="."+d.vars.uid+"> *:not(.hidden) ";c+="~ *:not(.hidden) ".repeat(perpage*
b);d.elements.style.textContent=c+"{ display: none !important; }\n";d.elements.summary.update();d.elements.jumpto.val(b)}var d=$("<div>").addClass("page_control");d.elements={prev:$("<button>").text("Previous").click(function(){c("previous")}),next:$("<button>").text("Next").click(function(){c("next")}),page_buttons:{},page_button_cont:$("<div>").addClass("page_numbers"),pagelength:$("<select>").append($("<option>").text(5)).append($("<option>").text(10)).append($("<option>").text(25)).append($("<option>").text(50)).append($("<option>").text(100)).change(function(){d.vars.page_size=
$(this).val();c()}),jumpto:$("<select>").addClass("jump_to").change(function(){c($(this).val())}),summary:document.createElement("span"),style:document.createElement("style")};d.vars={currentpage:1,page_size:b||25,entries:0,uid:"paginated_"+(Math.random()+"").slice(2)};d.elements.pagelength.val(d.vars.page_size);d.elements.summary.className="summary";d.elements.summary.elements={start:document.createTextNode(""),end:document.createTextNode(""),total:document.createTextNode("")};d.elements.summary.appendChild(document.createTextNode("Showing "));
d.elements.summary.appendChild(d.elements.summary.elements.start);d.elements.summary.appendChild(document.createTextNode("-"));d.elements.summary.appendChild(d.elements.summary.elements.end);d.elements.summary.appendChild(document.createTextNode(" of "));d.elements.summary.appendChild(d.elements.summary.elements.total);d.elements.summary.appendChild(document.createTextNode(" items."));d.elements.summary.update=function(){this.elements.start.nodeValue=Math.max(0,(d.vars.currentpage-1)*d.vars.page_size+
1);this.elements.end.nodeValue=Math.min(d.vars.currentpage*d.vars.page_size,d.vars.entries);this.elements.total.nodeValue=d.vars.entries;for(var a=Math.floor((d.vars.entries-1)/d.vars.page_size)+1;d.elements.jumpto.children().length<a;)d.elements.jumpto.append($("<option>").text(d.elements.jumpto.children().length+1));for(;d.elements.jumpto.children().length>a;)d.elements.jumpto.children().last().remove()};a.classList.add(d.vars.uid);var j=!1;a.show_page=c;c();d.append($("<div>").addClass("pages").append(d.elements.prev).append(d.elements.page_button_cont).append(d.elements.next)).append(d.elements.summary).append($("<label>").addClass("input_container").append($("<span>").text("Jump to page:")).append(d.elements.jumpto)).append($("<label>").addClass("input_container").append($("<span>").text("Items per page:")).append(d.elements.pagelength)).append(d.elements.style);
return d},sortableItems:function(a,b,e){var c,d=1;e&&(c=e.getAttribute("data-sortby"),d=e.getAttribute("data-sortdir")?e.getAttribute("data-sortdir"):1);a.sort=function(a,i){if(!i){i=d;a==c&&(i=i*-1)}c=a=a?a:c;d=i;if(e){e.setAttribute("data-sortby",a);e.setAttribute("data-sortdir",i);var f=e.querySelector("[data-sorting]");f&&f.removeAttribute("data-sorting");e.querySelector('[data-index="'+a+'"]').setAttribute("data-sorting","")}for(var f=(new Intl.Collator("en",{numeric:true,sensitivity:"accent"})).compare,
m=0;m<this.children.length-1;m++){var n=this.children[m],k=this.children[m+1];if(i*f(b.call(n,a),b.call(k,a))>0){this.insertBefore(k,n);m>0&&(m=m-2)}}}},humanMime:function(a){var b=!1;switch(a){case "html5/application/vnd.apple.mpegurl":b="HLS (TS)";break;case "html5/application/vnd.apple.mpegurl;version=7":b="HLS (CMAF)";break;case "html5/application/sdp":b="SDP";break;case "html5/video/webm":b="WebM";break;case "html5/video/raw":b="Raw";break;case "html5/video/mp4":b="MP4";break;case "ws/video/mp4":b=
"MP4 (websocket)";break;case "ws/video/raw":b="Raw (websocket)";break;case "dtsc":b="DTSC";break;case "html5/audio/aac":b="AAC";break;case "html5/audio/flac":b="FLAC";break;case "html5/image/jpeg":b="JPG";break;case "dash/video/mp4":b="DASH";break;case "flash/11":b="HDS";break;case "flash/10":b="RTMP";break;case "flash/7":b="Progressive";break;case "html5/audio/mp3":b="MP3";break;case "html5/audio/wav":b="WAV";break;case "html5/video/mp2t":case "html5/video/mpeg":b="TS";break;case "html5/application/vnd.ms-sstr+xml":case "html5/application/vnd.ms-ss":b= "MP4 (websocket)";break;case "ws/video/raw":b="Raw (websocket)";break;case "dtsc":b="DTSC";break;case "html5/audio/aac":b="AAC";break;case "html5/audio/flac":b="FLAC";break;case "html5/image/jpeg":b="JPG";break;case "dash/video/mp4":b="DASH";break;case "flash/11":b="HDS";break;case "flash/10":b="RTMP";break;case "flash/7":b="Progressive";break;case "html5/audio/mp3":b="MP3";break;case "html5/audio/wav":b="WAV";break;case "html5/video/mp2t":case "html5/video/mpeg":b="TS";break;case "html5/application/vnd.ms-sstr+xml":case "html5/application/vnd.ms-ss":b=
"Smooth Streaming";break;case "html5/text/vtt":b="VTT Subtitles";break;case "html5/text/plain":b="SRT Subtitles";break;case "html5/text/javascript":b="JSON Subtitles";break;case "rtsp":b="RTSP";break;case "srt":b="SRT";break;case "webrtc":b="WebRTC (websocket)";break;case "whep":b="WebRTC (WHEP)"}return b},popup:{element:null,show:function(a){this.element=$("<div>").attr("id","popup").append($("<button>").text("Close").addClass("close").click(function(){UI.popup.element.fadeOut("fast",function(){UI.popup.element.remove(); "Smooth Streaming";break;case "html5/text/vtt":b="VTT Subtitles";break;case "html5/text/plain":b="SRT Subtitles";break;case "html5/text/javascript":b="JSON Subtitles";break;case "rtsp":b="RTSP";break;case "srt":b="SRT";break;case "webrtc":b="WebRTC (websocket)";break;case "whep":b="WebRTC (WHEP)"}return b},popup:{element:null,show:function(a){this.element=$("<div>").attr("id","popup").append($("<button>").text("Close").addClass("close").click(function(){UI.popup.element.fadeOut("fast",function(){UI.popup.element.remove();
UI.popup.element=null})})).append(a);$("body").append(this.element)}},menu:[{Overview:{},General:{hiddenmenu:{"Edit variable":{},"Edit external writer":{}}},Protocols:{},Streams:{keepParam:!0,hiddenmenu:{Edit:{},Status:{},Preview:{},Embed:{}}},Push:{},Triggers:{},Logs:{},Statistics:{},"Server Stats":{}},{Disconnect:{classes:["red"]}},{Documentation:{link:"https://docs.mistserver.org/"},Changelog:{link:"https://releases.mistserver.org/changelog"},"Email for Help":{}}],buildMenu:function(){function a(a, UI.popup.element=null})})).append(a);$("body").append(this.element)}},menu:[{Overview:{},General:{hiddenmenu:{"Edit variable":{},"Edit external writer":{}}},Protocols:{},Streams:{keepParam:!0,hiddenmenu:{Edit:{},Status:{},Preview:{},Embed:{}}},Push:{},Triggers:{},Logs:{},Statistics:{},"Server Stats":{}},{Disconnect:{classes:["red"]}},{Documentation:{link:"https://docs.mistserver.org/"},Changelog:{link:"https://releases.mistserver.org/changelog"},"Email for Help":{}}],buildMenu:function(){function a(a,
b){var c=$("<a>").addClass("button");c.html($("<span>").addClass("plain").text(a)).append($("<span>").addClass("highlighted").text(a));for(var d in b.classes)c.addClass(b.classes[d]);"link"in b?c.attr("href",b.link).attr("target","_blank"):"submenu"in b||c.click(function(b){if(!$(this).closest(".menu").hasClass("hide")){var c,d=$(this).closest(".hiddenmenu[data-param]");d.length&&(c=d.attr("data-param"));UI.navto(a,c);b.stopPropagation()}});return c}var b=UI.elements.menu,d;for(d in UI.menu){0<d&& b){var c=$("<a>").addClass("button");c.html($("<span>").addClass("plain").text(a)).append($("<span>").addClass("highlighted").text(a));for(var d in b.classes)c.addClass(b.classes[d]);"link"in b?c.attr("href",b.link).attr("target","_blank"):"submenu"in b||c.click(function(b){if(!$(this).closest(".menu").hasClass("hide")){var c,d=$(this).closest(".hiddenmenu[data-param]");d.length&&(c=d.attr("data-param"));UI.navto(a,c);b.stopPropagation()}});return c}var b=UI.elements.menu,e;for(e in UI.menu){0<e&&
b.append($("<br>"));for(var c in UI.menu[d]){var e=UI.menu[d][c],l=a(c,e);b.append(l);if("submenu"in e){var i=$("<span>").addClass("submenu");l.addClass("arrowdown").append(i);for(var f in e.submenu)i.append(a(f,e.submenu[f]))}else if("hiddenmenu"in e)for(f in i=$("<span>").addClass("hiddenmenu"),e.keepParam&&i.attr("data-param",""),l.append(i),e.hiddenmenu)i.append(a(f,e.hiddenmenu[f]))}}d=$("<div>").attr("id","ih_button").text("?").click(function(){$("body").toggleClass("helpme");UI.stored.saveOpt("helpme", b.append($("<br>"));for(var c in UI.menu[e]){var d=UI.menu[e][c],j=a(c,d);b.append(j);if("submenu"in d){var i=$("<span>").addClass("submenu");j.addClass("arrowdown").append(i);for(var f in d.submenu)i.append(a(f,d.submenu[f]))}else if("hiddenmenu"in d)for(f in i=$("<span>").addClass("hiddenmenu"),d.keepParam&&i.attr("data-param",""),j.append(i),d.hiddenmenu)i.append(a(f,d.hiddenmenu[f]))}}e=$("<div>").attr("id","ih_button").text("?").click(function(){$("body").toggleClass("helpme");UI.stored.saveOpt("helpme",
$("body").hasClass("helpme"))}).attr("title","Click to toggle the display of integrated help");UI.stored.getOpts().helpme&&$("body").addClass("helpme");b.after(d).after($("<div>").addClass("separator"))},findInput:function(a){return this.findInOutput("inputs",a)},findOutput:function(a){return this.findInOutput("connectors",a)},findInOutput:function(a,b){if("capabilities"in mist.data){var d=!1,c=mist.data.capabilities[a];b in c&&(d=c[b]);b+".exe"in c&&(d=c[b+".exe"]);return d}throw"Request capabilities first"; $("body").hasClass("helpme"))}).attr("title","Click to toggle the display of integrated help");UI.stored.getOpts().helpme&&$("body").addClass("helpme");b.after(e).after($("<div>").addClass("separator"))},findInput:function(a){return this.findInOutput("inputs",a)},findOutput:function(a){return this.findInOutput("connectors",a)},findInOutput:function(a,b){if("capabilities"in mist.data){var e=!1,c=mist.data.capabilities[a];b in c&&(e=c[b]);b+".exe"in c&&(e=c[b+".exe"]);return e}throw"Request capabilities first";
},updateLiveStreamHint:function(a,b,d){if(a){var c=parseURL(mist.user.host),e=b.match(/@.*/);e&&(e=e[0].substring(1));var l=b.replace(/(?:.+?):\/\//,""),l=l.split("/"),l=l[0],l=l.split(":"),l=l[0],i=b.match(/:\d+/);i&&(i=i[0]);var f={},m="RTMP RTSP RTMP.exe RTSP.exe TSSRT TSSRT.exe".split(" "),n;for(n in m)m[n]in mist.data.capabilities.connectors&&(f[m[n]]=mist.data.capabilities.connectors[m[n]].optional.port["default"]);var m={RTMP:1935,"RTMP.exe":1935,RTSP:554,"RTSP.exe":554,TSSRT:-1,"TSSRT.exe":-1, },findFolderSubstreams:function(a,b){mist.send(function(e){var c=a.name,d=0,j={},i;for(i in e.browse.files){var f;a:{f=e.browse.files[i];var m=void 0;for(m in mist.data.capabilities.inputs)if(!(0<=m.indexOf("Buffer")||0<=m.indexOf("Buffer.exe")||0<=m.indexOf("Folder")||0<=m.indexOf("Folder.exe"))&&mist.inputMatch(mist.data.capabilities.inputs[m].source_match,"/"+f)){f=!0;break a}f=!1}if(f){f=c+"+"+e.browse.files[i];var m=j,n=f,k=f,q=$.extend({},a);delete q.meta;delete q.error;q.online=2;q.name=k;
TS:-1,"TS.exe":-1},j;for(j in f){for(n in mist.data.config.protocols){var q=mist.data.config.protocols[n];if(q.connector==j){"port"in q&&(f[j]=q.port);break}}f[j]=f[j]==m[j]?"":":"+f[j]}f.TS="";f["TS.exe"]="";d.find(".field").closest("label").hide();for(n in f){var g;j=i?i:f[n];switch(n){case "RTMP":case "RTMP.exe":g="rtmp://"+c.host+j+"/"+(e?e:"live")+"/";j=d.find(".field.RTMPurl").setval(g).closest("label");j.length&&(j[0].style.display="");j=d.find(".field.RTMPkey").setval(""==a?"STREAMNAME":a).closest("label"); q.ischild=!0;m[n]=q;j[f].source=a.source+e.browse.files[i];d++}}a.filesfound="files"in e.browse&&e.browse.files.length?!0:!1;b(j)},{browse:a.source})},updateLiveStreamHint:function(a,b,e){if(a){var c=parseURL(mist.user.host),d=b.match(/@.*/);d&&(d=d[0].substring(1));var j=b.replace(/(?:.+?):\/\//,""),j=j.split("/"),j=j[0],j=j.split(":"),j=j[0],i=b.match(/:\d+/);i&&(i=i[0]);var f={},m="RTMP RTSP RTMP.exe RTSP.exe TSSRT TSSRT.exe".split(" "),n;for(n in m)m[n]in mist.data.capabilities.connectors&&(f[m[n]]=
j.length&&(j[0].style.display="");g+=""==a?"STREAMNAME":a;break;case "TSSRT":case "TSSRT.exe":"srt://"==b.slice(0,6)?i?(g=parseURL(b.replace()),""==g.host&&(g=parseURL(b.replace(/^srt:\/\//,"http://localhost")),g.host=g.host.replace(/^localhost/,"")),g=""!=g.host&&(!g.search||!g.searchParams||"listener"!=g.searchParams.get("mode"))?"Caller mode: you should push to the other side.":g.search&&g.searchParams&&"caller"==g.searchParams.get("mode")?"Caller mode: you should probably add an address.":"srt://"+ mist.data.capabilities.connectors[m[n]].optional.port["default"]);var m={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(n in mist.data.config.protocols){var q=mist.data.config.protocols[n];if(q.connector==k){"port"in q&&(f[k]=q.port);break}}f[k]=f[k]==m[k]?"":":"+f[k]}f.TS="";f["TS.exe"]="";e.find(".field").closest("label").hide();for(n in f){var h;k=i?i:f[n];switch(n){case "RTMP":case "RTMP.exe":h="rtmp://"+c.host+k+"/"+(d?d:"live")+
c.host+i):g="You must specify a port.":g="srt://"+c.host+j+"?streamid="+(""==a?"STREAMNAME":a);break;case "RTSP":case "RTSP.exe":g="rtsp://"+c.host+j+"/"+(""==a?"STREAMNAME":a)+(e?"?pass="+e:"");break;case "TS":case "TS.exe":g="udp://"+(""==l?c.host:l)+j+"/"}j=d.find(".field."+n.replace(".exe",""));j.length&&(j.setval(g).closest("label")[0].style.display="")}}},buildUI:function(a){var b=$("<div>").addClass("input_container"),d;for(d in a){var c=a[d];if(c instanceof jQuery)b.append(c);else if("help"== "/";k=e.find(".field.RTMPurl").setval(h).closest("label");k.length&&(k[0].style.display="");k=e.find(".field.RTMPkey").setval(""==a?"STREAMNAME":a).closest("label");k.length&&(k[0].style.display="");h+=""==a?"STREAMNAME":a;break;case "TSSRT":case "TSSRT.exe":"srt://"==b.slice(0,6)?i?(h=parseURL(b.replace()),""==h.host&&(h=parseURL(b.replace(/^srt:\/\//,"http://localhost")),h.host=h.host.replace(/^localhost/,"")),h=""!=h.host&&(!h.search||!h.searchParams||"listener"!=h.searchParams.get("mode"))?"Caller mode: you should push to the other side.":
c.type){var e=$("<span>").addClass("text_container").append($("<span>").addClass("description").append(c.help));b.append(e);if("classes"in c)for(var l in c.classes)e.addClass(c.classes[l])}else if("text"==c.type)b.append($("<span>").addClass("text_container").append($("<span>").addClass("text").append(c.text)));else if("custom"==c.type)b.append(c.custom);else if("buttons"==c.type)for(l in e=$("<span>").addClass("button_container").on("keydown",function(a){a.stopPropagation()}),"css"in c&&e.css(c.css), h.search&&h.searchParams&&"caller"==h.searchParams.get("mode")?"Caller mode: you should probably add an address.":"srt://"+c.host+i):h="You must specify a port.":h="srt://"+c.host+k+"?streamid="+(""==a?"STREAMNAME":a);break;case "RTSP":case "RTSP.exe":h="rtsp://"+c.host+k+"/"+(""==a?"STREAMNAME":a)+(d?"?pass="+d:"");break;case "TS":case "TS.exe":h="udp://"+(""==j?c.host:j)+k+"/"}k=e.find(".field."+n.replace(".exe",""));k.length&&(k.setval(h).closest("label")[0].style.display="")}}},buildUI:function(a){var b=
b.append(e),c.buttons){var i=c.buttons[l],f=$("<button>").text(i.label).data("opts",i);"css"in i&&f.css(i.css);if("classes"in i)for(var m in i.classes)f.addClass(i.classes[m]);e.append(f);switch(i.type){case "cancel":f.addClass("cancel").click(i["function"]);break;case "save":f.addClass("save").click(function(){var a=$(this).data("opts").preSave;a&&a.call(this);var b=$(this).closest(".input_container"),c=!1;b.find('.hasValidate:visible, input[type="hidden"].hasValidate').each(function(){if(c=$(this).data("validate")(this, $("<div>").addClass("input_container"),e;for(e in a){var c=a[e];if(c instanceof jQuery)b.append(c);else if("help"==c.type){var d=$("<span>").addClass("text_container").append($("<span>").addClass("description").append(c.help));b.append(d);if("classes"in c)for(var j in c.classes)d.addClass(c.classes[j])}else if("text"==c.type)b.append($("<span>").addClass("text_container").append($("<span>").addClass("text").append(c.text)));else if("custom"==c.type)b.append(c.custom);else if("buttons"==c.type)for(j in d=
!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:f.click(i["function"])}}else{i=$("<label>").addClass("UIelement"); $("<span>").addClass("button_container").on("keydown",function(a){a.stopPropagation()}),"css"in c&&d.css(c.css),b.append(d),c.buttons){var i=c.buttons[j],f=$("<button>").text(i.label).data("opts",i);"css"in i&&f.css(i.css);if("classes"in i)for(var m in i.classes)f.addClass(i.classes[m]);d.append(f);switch(i.type){case "cancel":f.addClass("cancel").click(i["function"]);break;case "save":f.addClass("save").click(function(){var a=$(this).data("opts").preSave;a&&a.call(this);var b=$(this).closest(".input_container"),
b.append(i);"css"in c&&i.css(c.css);i.append($("<span>").addClass("label").html("label"in c?c.label+":":""));if("classes"in c)for(m in c.classes)i.addClass(c.classes[m]);f=$("<span>").addClass("field_container");i.append(f);switch(c.type){case "password":e=$("<input>").attr("type","password");break;case "int":e=$("<input>").attr("type","number");"min"in c&&e.attr("min",c.min);"max"in c&&e.attr("max",c.max);"step"in c&&e.attr("step",c.step);"validate"in c?c.validate.push("int"):c.validate=["int"]; c=!1;b.find('.hasValidate:visible, input[type="hidden"].hasValidate').each(function(){if(c=$(this).data("validate")(this,!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)}),
break;case "span":e=$("<span>");break;case "debug":c.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"], (a=$(this).data("opts")["function"])&&a(this))});break;default:f.click(i["function"])}}else{i=$("<label>").addClass("UIelement");b.append(i);"css"in c&&i.css(c.css);i.append($("<span>").addClass("label").html("label"in c?c.label+":":""));if("classes"in c)for(m in c.classes)i.addClass(c.classes[m]);f=$("<span>").addClass("field_container");i.append(f);switch(c.type){case "password":d=$("<input>").attr("type","password");break;case "int":d=$("<input>").attr("type","number");"min"in c&&d.attr("min",
[8,"8 - Report everything in extreme detail"],[9,"9 - Report everything in insane detail"],[10,"10 - All messages enabled"]];case "select":e=$("<select>");for(l in c.select){var n=$("<option>");"string"==typeof c.select[l]?n.text(c.select[l]):n.val(c.select[l][0]).text(c.select[l][1]);e.append(n)}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"); c.min);"max"in c&&d.attr("max",c.max);"step"in c&&d.attr("step",c.step);"validate"in c?c.validate.push("int"):c.validate=["int"];break;case "span":d=$("<span>");break;case "debug":c.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"],
i.hide();break;case "email":e=$("<input>").attr("type","email").attr("autocomplete","on").attr("required","");break;case "browse":e=$("<input>").attr("type","text");"filetypes"in c&&e.data("filetypes",c.filetypes);break;case "geolimited":case "hostlimited":e=$("<input>").attr("type","hidden");break;case "radioselect":e=$("<div>").addClass("radioselect");for(d in c.radioselect){var j=$("<input>").attr("type","radio").val(c.radioselect[d][0]).attr("name",c.label);c.readonly&&j.prop("disabled",!0);n= [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":d=$("<select>");for(j in c.select){var n=$("<option>");"string"==typeof c.select[j]?n.text(c.select[j]):n.val(c.select[j][0]).text(c.select[j][1]);d.append(n)}break;case "textarea":d=$("<textarea>").on("keydown",function(a){a.stopPropagation()});
$("<label>").append(j).append($("<span>").html(c.radioselect[d][1]));e.append(n);if(2<c.radioselect[d].length)for(l in j=$("<select>").change(function(){$(this).parent().find("input[type=radio]:enabled").prop("checked","true")}),n.append(j),c.readonly&&j.prop("disabled",!0),c.radioselect[d][2])n=$("<option>"),j.append(n),c.radioselect[d][2][l]instanceof Array?n.val(c.radioselect[d][2][l][0]).html(c.radioselect[d][2][l][1]):n.html(c.radioselect[d][2][l])}break;case "checklist":e=$("<div>").addClass("checkcontainer"); break;case "checkbox":d=$("<input>").attr("type","checkbox");break;case "hidden":d=$("<input>").attr("type","hidden");i.hide();break;case "email":d=$("<input>").attr("type","email").attr("autocomplete","on").attr("required","");break;case "browse":d=$("<input>").attr("type","text");"filetypes"in c&&d.data("filetypes",c.filetypes);break;case "geolimited":case "hostlimited":d=$("<input>").attr("type","hidden");break;case "radioselect":d=$("<div>").addClass("radioselect");for(e in c.radioselect){var k=
$controls=$("<div>").addClass("controls");$checklist=$("<div>").addClass("checklist");e.append($checklist);for(d in c.checklist)"string"==typeof c.checklist[d]&&(c.checklist[d]=[c.checklist[d],c.checklist[d]]),$checklist.append($("<label>").text(c.checklist[d][1]).prepend($("<input>").attr("type","checkbox").attr("name",c.checklist[d][0])));break;case "DOMfield":e=c.DOMfield;break;case "unix":e=$("<input>").attr("type","datetime-local").attr("step",1);c.unit=$("<button>").text("Now").click(function(){$(this).closest(".field_container").find(".field").setval((new Date).getTime()/ $("<input>").attr("type","radio").val(c.radioselect[e][0]).attr("name",c.label);c.readonly&&k.prop("disabled",!0);n=$("<label>").append(k).append($("<span>").html(c.radioselect[e][1]));d.append(n);if(2<c.radioselect[e].length)for(j in k=$("<select>").change(function(){$(this).parent().find("input[type=radio]:enabled").prop("checked","true")}),n.append(k),c.readonly&&k.prop("disabled",!0),c.radioselect[e][2])n=$("<option>"),k.append(n),c.radioselect[e][2][j]instanceof Array?n.val(c.radioselect[e][2][j][0]).html(c.radioselect[e][2][j][1]):
1E3)});break;case "selectinput":e=$("<div>").addClass("selectinput");j=$("<select>");e.append(j);j.data("input",!1);for(d in c.selectinput)n=$("<option>"),j.append(n),"string"==typeof c.selectinput[d]?n.text(c.selectinput[d]):(n.text(c.selectinput[d][1]),"string"==typeof c.selectinput[d][0]?n.val(c.selectinput[d][0]):(n.val("CUSTOM"),j.data("input")||j.data("input",UI.buildUI([c.selectinput[d][0]]).children())));j.data("input")&&e.append(j.data("input"));j.change(function(){"CUSTOM"==$(this).val()? n.html(c.radioselect[e][2][j])}break;case "checklist":d=$("<div>").addClass("checkcontainer");$controls=$("<div>").addClass("controls");$checklist=$("<div>").addClass("checklist");d.append($checklist);for(e in c.checklist)"string"==typeof c.checklist[e]&&(c.checklist[e]=[c.checklist[e],c.checklist[e]]),$checklist.append($("<label>").text(c.checklist[e][1]).prepend($("<input>").attr("type","checkbox").attr("name",c.checklist[e][0])));break;case "DOMfield":d=c.DOMfield;break;case "unix":d=$("<input>").attr("type",
$(this).data("input").css("display","flex"):$(this).data("input").hide()});j.trigger("change");break;case "inputlist":e=$("<div>").addClass("inputlist");e.data("newitem",function(){var a;if("input"in c)a=UI.buildUI([c.input]).find(".field_container");else{var b=Object.assign({},c);delete b.validate;delete b.pointer;b.type="str";a=UI.buildUI([b]).find(".field_container")}a.removeClass("isSetting");a.addClass("listitem");var h=function(b){$(this).is(":last-child")?""!=$(this).find(".field").getval()? "datetime-local").attr("step",1);c.unit=$("<button>").text("Now").click(function(){$(this).closest(".field_container").find(".field").setval((new Date).getTime()/1E3)});break;case "selectinput":d=$("<div>").addClass("selectinput");k=$("<select>");d.append(k);k.data("input",!1);for(e in c.selectinput)n=$("<option>"),k.append(n),"string"==typeof c.selectinput[e]?n.text(c.selectinput[e]):(n.text(c.selectinput[e][1]),"string"==typeof c.selectinput[e][0]?n.val(c.selectinput[e][0]):(n.val("CUSTOM"),k.data("input")||
(b=a.clone().keyup(h),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(h);return a});e.append(e.data("newitem"));break;case "sublist":e=$("<div>").addClass("sublist");j=$("<div>").addClass("curvals");j.append($("<span>").text("None."));var q=$("<div>").addClass("itemsettings"),g=$("<button>").text("New "+c.itemLabel), k.data("input",UI.buildUI([c.selectinput[e][0]]).children())));k.data("input")&&d.append(k.data("input"));k.change(function(){"CUSTOM"==$(this).val()?$(this).data("input").css("display","flex"):$(this).data("input").hide()});k.trigger("change");break;case "inputlist":d=$("<div>").addClass("inputlist");d.data("newitem",function(){var a;if("input"in c)a=UI.buildUI([c.input]).find(".field_container");else{var b=Object.assign({},c);delete b.validate;delete b.pointer;b.type="str";a=UI.buildUI([b]).find(".field_container")}a.removeClass("isSetting");
h=c.sublist,k=c,o=e,s=i;e.data("build",function(a,b){for(var c in k.saveas)c in a||delete k.saveas[c];k.saveas=Object.assign(k.saveas,a);c="New";"undefined"!=typeof b&&(c="Edit");c=UI.buildUI([$("<h4>").text(c+" "+k.itemLabel)].concat(h).concat([{label:"Save first",type:"str",classes:["onlyshowhelp"],validate:[function(){return{msg:"Did you want to save this "+k.itemLabel+"?",classes:["red"]}}]},{type:"buttons",buttons:[{label:"Cancel",type:"cancel","function":function(){q.html("");g.show();s.show()}}, a.addClass("listitem");var d=function(b){$(this).is(":last-child")?""!=$(this).find(".field").getval()?(b=a.clone().keyup(d),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(d);return a});d.append(d.data("newitem"));break;case "sublist":d=$("<div>").addClass("sublist");k=$("<div>").addClass("curvals");k.append($("<span>").text("None."));
{label:"Save "+k.itemLabel,type:"save",preSave:function(){$(this).closest(".input_container").find(".onlyshowhelp").closest("label").hide()},failedValidate:function(){$(this).closest(".input_container").find(".onlyshowhelp").closest("label").show()},"function":function(){var a=o.getval(),c=Object.assign({},k.saveas),h;for(h in c)null===c[h]&&delete c[h];"undefined"==typeof b?a.push(c):a[b]=c;o.setval(a);q.html("");g.show();s.show()}}]}]));q.html(c);g.hide();s.hide()});var p=e;g.click(function(){p.data("build")({})}); var q=$("<div>").addClass("itemsettings"),h=$("<button>").text("New "+c.itemLabel),g=c.sublist,l=c,o=d,u=i;d.data("build",function(a,b){for(var c in l.saveas)c in a||delete l.saveas[c];l.saveas=Object.assign(l.saveas,a);c="New";"undefined"!=typeof b&&(c="Edit");c=UI.buildUI([$("<h4>").text(c+" "+l.itemLabel)].concat(g).concat([{label:"Save first",type:"str",classes:["onlyshowhelp"],validate:[function(){return{msg:"Did you want to save this "+l.itemLabel+"?",classes:["red"]}}]},{type:"buttons",buttons:[{label:"Cancel",
h.unshift({type:"str",label:"Human readable name",placeholder:"none",help:"A convenient name to describe this "+c.itemLabel+". It won't be used by MistServer.",pointer:{main:c.saveas,index:"x-LSP-name"}});e.data("savelist",[]);e.append(j).append(g);b.append(q);break;case "json":e=$("<textarea>").on("keydown",function(a){a.stopPropagation()}).on("keyup change",function(){this.style.height="";this.style.height=(this.scrollHeight?this.scrollHeight+20:14*this.value.split("\n").length+20)+"px"}).css("min-height", type:"cancel","function":function(){q.html("");h.show();u.show()}},{label:"Save "+l.itemLabel,type:"save",preSave:function(){$(this).closest(".input_container").find(".onlyshowhelp").closest("label").hide()},failedValidate:function(){$(this).closest(".input_container").find(".onlyshowhelp").closest("label").show()},"function":function(){var a=o.getval(),c=Object.assign({},l.saveas),d;for(d in c)null===c[d]&&delete c[d];"undefined"==typeof b?a.push(c):a[b]=c;o.setval(a);q.html("");h.show();u.show()}}]}]));
"3em");j=function(a,b){if(""!=$(b).val()&&null===a)return{msg:"Invalid json",classes:["red"]}};"validate"in c?c.validate.push(j):c.validate=[j];break;case "bitmask":e=$("<div>").addClass("bitmask");for(d in c.bitmask)e.append($("<label>").append($("<input>").attr("type","checkbox").attr("name","bitmask_"+("pointer"in c?c.pointer.index:"")).attr("value",c.bitmask[d][0]).addClass("field")).append($("<span>").text(c.bitmask[d][1])));i.attr("for","none");break;default:e=$("<input>").attr("type","text"), q.html(c);h.hide();u.hide()});var p=d;h.click(function(){p.data("build")({})});g.unshift({type:"str",label:"Human readable name",placeholder:"none",help:"A convenient name to describe this "+c.itemLabel+". It won't be used by MistServer.",pointer:{main:c.saveas,index:"x-LSP-name"}});d.data("savelist",[]);d.append(k).append(h);b.append(q);break;case "json":d=$("<textarea>").on("keydown",function(a){a.stopPropagation()}).on("keyup change",function(){this.style.height="";this.style.height=(this.scrollHeight?
"maxlength"in c&&e.attr("maxlength",c.maxlength),"minlength"in c&&e.attr("minlength",c.minlength)}e.addClass("field").data("opts",c);"pointer"in c&&e.attr("name",c.pointer.index);f.append(e);if("classes"in c)for(l in c.classes)e.addClass(c.classes[l]);"placeholder"in c&&e.attr("placeholder",c.placeholder);"default"in c&&e.attr("placeholder",c["default"]);"unit"in c&&f.append($("<span>").addClass("unit").html(c.unit));"prefix"in c&&f.prepend($("<span>").addClass("unit").html(c.prefix));"readonly"in this.scrollHeight+20:14*this.value.split("\n").length+20)+"px"}).css("min-height","3em");k=function(a,b){if(""!=$(b).val()&&null===a)return{msg:"Invalid json",classes:["red"]}};"validate"in c?c.validate.push(k):c.validate=[k];break;case "bitmask":d=$("<div>").addClass("bitmask");for(e in c.bitmask)d.append($("<label>").append($("<input>").attr("type","checkbox").attr("name","bitmask_"+("pointer"in c?c.pointer.index:"")).attr("value",c.bitmask[e][0]).addClass("field")).append($("<span>").text(c.bitmask[e][1])));
c&&(e.attr("readonly","readonly"),e.click(function(){this.selectionStart==this.selectionEnd&&$(this).select()}));"qrcode"in c&&f.append($("<span>").addClass("unit").html($("<button>").text("QR").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=$("<div>").addClass("qrcode");UI.popup.show($("<span>").addClass("qr_container").append($("<p>").text(a)).append(b));b.qrcode({text:a,size:Math.min(b.width(),b.height())})}))); i.attr("for","none");break;default:d=$("<input>").attr("type","text"),"maxlength"in c&&d.attr("maxlength",c.maxlength),"minlength"in c&&d.attr("minlength",c.minlength)}d.addClass("field").data("opts",c);"pointer"in c&&d.attr("name",c.pointer.index);f.append(d);if("classes"in c)for(j in c.classes)d.addClass(c.classes[j]);"placeholder"in c&&d.attr("placeholder",c.placeholder);"default"in c&&d.attr("placeholder",c["default"]);"unit"in c&&f.append($("<span>").addClass("unit").html(c.unit));"prefix"in
"clipboard"in c&&document.queryCommandSupported("copy")&&f.append($("<span>").addClass("unit").html($("<button>").text("Copy").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=document.createElement("textarea");b.value=a;document.body.appendChild(b);b.select();var c=false;try{c=document.execCommand("copy")}catch(h){}if(c){$(this).text("Copied to clipboard!");document.body.removeChild(b);var d=$(this);setTimeout(function(){d.text("Copy")}, c&&f.prepend($("<span>").addClass("unit").html(c.prefix));"readonly"in c&&(d.attr("readonly","readonly"),d.click(function(){this.selectionStart==this.selectionEnd&&$(this).select()}));"qrcode"in c&&f.append($("<span>").addClass("unit").html($("<button>").text("QR").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=$("<div>").addClass("qrcode");UI.popup.show($("<span>").addClass("qr_container").append($("<p>").text(a)).append(b));
5E3)}else{document.body.removeChild(b);alert("Failed to copy:\n"+a)}})));"rows"in c&&e.attr("rows",c.rows);if("dependent"in c)for(d in c.dependent)i.attr("data-dependent-"+d,c.dependent[d]);switch(c.type){case "browse":j=$("<div>").addClass("grouper").append(i);b.append(j);j=$("<button>").text("Browse").on("keydown",function(a){a.stopPropagation()});f.append(j);j.click(function(){function a(b){f.text("Loading..");mist.send(function(a){g.text(a.browse.path[0]);mist.data.LTS&&h.setval(a.browse.path[0]+ b.qrcode({text:a,size:Math.min(b.width(),b.height())})})));"clipboard"in c&&document.queryCommandSupported("copy")&&f.append($("<span>").addClass("unit").html($("<button>").text("Copy").on("keydown",function(a){a.stopPropagation()}).click(function(){var a=String($(this).closest(".field_container").find(".field").getval()),b=document.createElement("textarea");b.value=a;document.body.appendChild(b);b.select();var c=false;try{c=document.execCommand("copy")}catch(d){}if(c){$(this).text("Copied to clipboard!");
"/");f.html(m.clone(true).text("..").attr("title","Folder up"));if(a.browse.subdirectories){a.browse.subdirectories.sort();for(var b in a.browse.subdirectories){var e=a.browse.subdirectories[b];f.append(m.clone(true).attr("title",g.text()+q+e).text(e))}}if(a.browse.files){a.browse.files.sort();for(b in a.browse.files){var e=a.browse.files[b],j=g.text()+q+e,e=$("<a>").text(e).addClass("file").attr("title",j);f.append(e);if(k){var i=true,l;for(l in k)if(typeof k[l]!="undefined"&&mist.inputMatch(k[l], document.body.removeChild(b);var e=$(this);setTimeout(function(){e.text("Copy")},5E3)}else{document.body.removeChild(b);alert("Failed to copy:\n"+a)}})));"rows"in c&&d.attr("rows",c.rows);if("dependent"in c)for(e in c.dependent)i.attr("data-dependent-"+e,c.dependent[e]);switch(c.type){case "browse":k=$("<div>").addClass("grouper").append(i);b.append(k);k=$("<button>").text("Browse").on("keydown",function(a){a.stopPropagation()});f.append(k);k.click(function(){function a(b){h.text("Loading..");mist.send(function(a){f.text(a.browse.path[0]);
j)){i=false;break}i&&e.hide()}e.click(function(){var a=$(this).attr("title");h.setval(a).removeAttr("readonly").css("opacity",1);d.show();c.remove()})}}},{browse:b})}var b=$(this).closest(".grouper"),c=$("<div>").addClass("browse_container"),h=b.find(".field").attr("readonly","readonly").css("opacity",0.5),d=$(this),e=$("<button>").text("Stop browsing").click(function(){d.show();c.remove();h.removeAttr("readonly").css("opacity",1)}),g=$("<span>").addClass("field"),f=$("<div>").addClass("browse_contents"), mist.data.LTS&&d.setval(a.browse.path[0]+"/");h.html(m.clone(true).text("..").attr("title","Folder up"));if(a.browse.subdirectories){a.browse.subdirectories.sort();for(var b in a.browse.subdirectories){var g=a.browse.subdirectories[b];h.append(m.clone(true).attr("title",f.text()+k+g).text(g))}}if(a.browse.files){a.browse.files.sort();for(b in a.browse.files){var g=a.browse.files[b],q=f.text()+k+g,g=$("<a>").text(g).addClass("file").attr("title",q);h.append(g);if(i){var l=true,j;for(j in i)if(typeof i[j]!=
m=$("<a>").addClass("folder"),k=h.data("filetypes");b.append(c);c.append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Current folder:")).append($("<span>").addClass("field_container").append(g).append(e))).append(f);var q="/";mist.data.config.version.indexOf("indows")>-1&&(q="\\");m.click(function(){var b=g.text()+q+$(this).text();a(b)});b=h.getval();e=b.split("://");e.length>1&&(b=e[0]=="file"?e[1]:"");b=b.split(q);b.pop();b=b.join(q);d.hide();a(b)});break;case "geolimited":case "hostlimited":j= "undefined"&&mist.inputMatch(i[j],q)){l=false;break}l&&g.hide()}g.click(function(){var a=$(this).attr("title");d.setval(a).removeAttr("readonly").css("opacity",1);e.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),e=$(this),g=$("<button>").text("Stop browsing").click(function(){e.show();c.remove();d.removeAttr("readonly").css("opacity",1)}),f=$("<span>").addClass("field"),
{field:e};j.blackwhite=$("<select>").append($("<option>").val("-").text("Blacklist")).append($("<option>").val("+").text("Whitelist"));j.values=$("<span>").addClass("limit_value_list");switch(c.type){case "geolimited":j.prototype=$("<select>").append($("<option>").val("").text("[Select a country]"));for(d in UI.countrylist)j.prototype.append($("<option>").val(d).html(UI.countrylist[d]));break;case "hostlimited":j.prototype=$("<input>").attr("type","text").attr("placeholder","type a host")}j.prototype.on("change keyup", h=$("<div>").addClass("browse_contents"),m=$("<a>").addClass("folder"),i=d.data("filetypes");b.append(c);c.append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Current folder:")).append($("<span>").addClass("field_container").append(f).append(g))).append(h);var k="/";mist.data.config.version.indexOf("indows")>-1&&(k="\\");m.click(function(){var b=f.text()+k+$(this).text();a(b)});b=d.getval();g=b.split("://");g.length>1&&(b=g[0]=="file"?g[1]:"");b=b.split(k);b.pop();
function(){$(this).closest(".field_container").data("subUI").blackwhite.trigger("change")});j.blackwhite.change(function(){var a=$(this).closest(".field_container").data("subUI"),b=[],c=false;a.values.children().each(function(){c=$(this).val();c!=""?b.push(c):$(this).remove()});a.values.append(a.prototype.clone(true));b.length>0?a.field.val($(this).val()+b.join(" ")):a.field.val("");a.field.trigger("change")});j.values.append(j.prototype.clone(!0));f.data("subUI",j).addClass("limit_list").append(j.blackwhite).append(j.values)}"pointer"in b=b.join(k);e.hide();a(b)});break;case "geolimited":case "hostlimited":k={field:d};k.blackwhite=$("<select>").append($("<option>").val("-").text("Blacklist")).append($("<option>").val("+").text("Whitelist"));k.values=$("<span>").addClass("limit_value_list");switch(c.type){case "geolimited":k.prototype=$("<select>").append($("<option>").val("").text("[Select a country]"));for(e in UI.countrylist)k.prototype.append($("<option>").val(e).html(UI.countrylist[e]));break;case "hostlimited":k.prototype=$("<input>").attr("type",
c&&(e.data("pointer",c.pointer).addClass("isSetting"),c.pointer.main&&(j=c.pointer.main[c.pointer.index],"undefined"!=j&&e.setval(j)));(""==e.getval()||null==e.getval()||!("pointer"in c))&&"value"in c&&e.setval(c.value);if("datalist"in c)for(d in j="datalist_"+d+MD5(e[0].outerHTML),e.attr("list",j),j=$("<datalist>").attr("id",j),f.append(j),c.datalist)j.append($("<option>").val(c.datalist[d]));f=$("<span>").addClass("help_container");i.append(f);"help"in c&&(f.append($("<span>").addClass("ih_balloon").html(c.help)), "text").attr("placeholder","type a host")}k.prototype.on("change keyup",function(){$(this).closest(".field_container").data("subUI").blackwhite.trigger("change")});k.blackwhite.change(function(){var a=$(this).closest(".field_container").data("subUI"),b=[],c=false;a.values.children().each(function(){c=$(this).val();c!=""?b.push(c):$(this).remove()});a.values.append(a.prototype.clone(true));b.length>0?a.field.val($(this).val()+b.join(" ")):a.field.val("");a.field.trigger("change")});k.values.append(k.prototype.clone(!0));
e.on("focus mouseover",function(){$(this).closest("label").addClass("active")}).on("blur mouseout",function(){$(this).closest("label").removeClass("active")}));if("validate"in c){i=[];for(l in c.validate){j=c.validate[l];if("function"!=typeof j)switch(j){case "required":j=function(a){return a==""||a==null?{msg:"This is a required field.",classes:["red"]}:false};break;case "int":j=function(a,b){var c=$(b).data("opts");if(!$(b)[0].validity.valid){var h=[];"min"in c&&h.push(" greater than or equal to "+ f.data("subUI",k).addClass("limit_list").append(k.blackwhite).append(k.values)}"pointer"in c&&(d.data("pointer",c.pointer).addClass("isSetting"),c.pointer.main&&(k=c.pointer.main[c.pointer.index],"undefined"!=k&&d.setval(k)));(""==d.getval()||null==d.getval()||!("pointer"in c))&&"value"in c&&d.setval(c.value);if("datalist"in c)for(e in k="datalist_"+e+MD5(d[0].outerHTML),d.attr("list",k),k=$("<datalist>").attr("id",k),f.append(k),c.datalist)k.append($("<option>").val(c.datalist[e]));f=$("<span>").addClass("help_container");
c.min);"max"in c&&h.push(" smaller than or equal to "+c.max);return{msg:"Please enter an integer"+h.join(" and")+".",classes:["red"]}}};break;case "streamname":j=function(a,b){if(a!=""){if(!isNaN(a.charAt(0)))return{msg:"The first character may not be a number.",classes:["red"]};if(a.toLowerCase()!=a)return{msg:"Uppercase letters are not allowed.",classes:["red"]};if(a.replace(/[^\da-z_\-\.]/g,"")!=a)return{msg:"Special characters (except for underscores (_), periods (.) and dashes (-)) are not allowed.", i.append(f);"help"in c&&(f.append($("<span>").addClass("ih_balloon").html(c.help)),d.on("focusin mouseover",function(){$(this).closest("label").addClass("active")}).on("focusout mouseout",function(){$(this).closest("label").removeClass("active")}));if("validate"in c){i=[];for(j in c.validate){k=c.validate[j];if("function"!=typeof k)switch(k){case "required":k=function(a){return a==""||a==null?{msg:"This is a required field.",classes:["red"]}:false};break;case "int":k=function(a,b){var c=$(b).data("opts");
classes:["red"]};if("streams"in mist.data&&a in mist.data.streams&&$(b).data("pointer").main.name!=a)return{msg:"This streamname already exists.<br>If you want to edit an existing stream, please click edit on the the streams tab.",classes:["red"]}}};break;case "streamname_with_wildcard":j=function(a){if(a!=""){streampart=a.split("+");var b=streampart.slice(1).join("+");streampart=streampart[0];if(!isNaN(streampart.charAt(0)))return{msg:"The first character may not be a number.",classes:["red"]};if(streampart.toLowerCase()!= if(!$(b)[0].validity.valid){var d=[];"min"in c&&d.push(" greater than or equal to "+c.min);"max"in c&&d.push(" smaller than or equal to "+c.max);return{msg:"Please enter an integer"+d.join(" and")+".",classes:["red"]}}};break;case "streamname":k=function(a,b){if(a!=""){if(a.toLowerCase()!=a)return{msg:"Uppercase letters are not allowed.",classes:["red"]};if(a.replace(/[^\da-z_\-\.]/g,"")!=a)return{msg:"Special characters (except for underscores (_), periods (.) and dashes (-)) are not allowed.",classes:["red"]};
streampart)return{msg:"Uppercase letters are not allowed in a stream name.",classes:["red"]};if(streampart.replace(/[^\da-z_]/g,"")!=streampart)return{msg:"Special characters (except for underscores) are not allowed in a stream name.",classes:["red"]};if(streampart!=a&&b.replace(/[\00|\0|\/]/g,"")!=b)return{msg:"Slashes or null bytes are not allowed in wildcards.",classes:["red"]}}};break;case "streamname_with_wildcard_and_variables":j=function(a){if(a!=""){streampart=a.split("+");var b=streampart.slice(1).join("+"); if("streams"in mist.data&&a in mist.data.streams&&$(b).data("pointer").main.name!=a)return{msg:"This streamname already exists.<br>If you want to edit an existing stream, please click edit on the the streams tab.",classes:["red"]}}};break;case "streamname_with_wildcard":k=function(a){if(a!=""){streampart=a.split("+");var b=streampart.slice(1).join("+");streampart=streampart[0];if(streampart.toLowerCase()!=streampart)return{msg:"Uppercase letters are not allowed in a stream name.",classes:["red"]};
streampart=streampart[0];if(!isNaN(streampart.charAt(0)))return{msg:"The first character may not be a number.",classes:["red"]};if(streampart.toLowerCase()!=streampart)return{msg:"Uppercase letters are not allowed in a stream name.",classes:["red"]};if(streampart.replace(/[^\da-z_$]/g,"")!=streampart)return{msg:"Special characters (except for underscores) are not allowed in a stream name.",classes:["red"]};if(streampart!=a&&b.replace(/[\00|\0|\/]/g,"")!=b)return{msg:"Slashes or null bytes are not allowed in wildcards.", if(streampart.replace(/[^\da-z_]/g,"")!=streampart)return{msg:"Special characters (except for underscores) are not allowed in a stream name.",classes:["red"]};if(streampart!=a&&b.replace(/[\00|\0|\/]/g,"")!=b)return{msg:"Slashes or null bytes are not allowed in wildcards.",classes:["red"]}}};break;case "streamname_with_wildcard_and_variables":k=function(a){if(a!=""){streampart=a.split("+");var b=streampart.slice(1).join("+");streampart=streampart[0];if(streampart.toLowerCase()!=streampart)return{msg:"Uppercase letters are not allowed in a stream name.",
classes:["red"]}}};break;case "track_selector_parameter":j=function(){};break;case "track_selector":j=function(){};break;default:j=function(){}}i.push(j)}e.data("validate_functions",i).data("help_container",f).data("validate",function(a,b){if($(a).is(":visible")||$(a).is('input[type="hidden"]')){var c=$(a).getval(),h=$(a).data("validate_functions"),d=$(a).data("help_container");d.find(".err_balloon").remove();for(var e in h){var g=h[e](c,a);if(g){$err=$("<span>").addClass("err_balloon").html(g.msg); classes:["red"]};if(streampart.replace(/[^\da-z_$]/g,"")!=streampart)return{msg:"Special characters (except for underscores) are not allowed in a stream name.",classes:["red"]};if(streampart!=a&&b.replace(/[\00|\0|\/]/g,"")!=b)return{msg:"Slashes or null bytes are not allowed in wildcards.",classes:["red"]}}};break;case "track_selector_parameter":k=function(){};break;case "track_selector":k=function(){};break;default:k=function(){}}i.push(k)}d.data("validate_functions",i).data("help_container",f).data("validate",
for(var f in g.classes)$err.addClass(g.classes[f]);d.prepend($err);b&&$(a).focus();return typeof g=="object"&&"break"in g?g["break"]:true}}return false}}).addClass("hasValidate").on("change keyup",function(){$(this).data("validate")($(this))});""!=e.getval()&&e.trigger("change")}"function"in c&&(e.on("change keyup",c["function"]),e.trigger("change"))}}b.on("keydown",function(a){var b=!1;switch(a.which){case 13:b=$(this).find("button.save").first();break;case 27:b=$(this).find("button.cancel").first()}b&& function(a,b){if($(a).is(":visible")||$(a).is('input[type="hidden"]')){var c=$(a).getval(),d=$(a).data("validate_functions"),e=$(a).data("help_container");e.find(".err_balloon").remove();for(var g in d){var f=d[g](c,a);if(f){$err=$("<span>").addClass("err_balloon").html(f.msg);for(var h in f.classes)$err.addClass(f.classes[h]);e.prepend($err);b&&$(a).focus();return typeof f=="object"&&"break"in f?f["break"]:true}}return false}}).addClass("hasValidate").on("change keyup",function(){$(this).data("validate")($(this))});
b.length&&(b.trigger("click"),a.stopPropagation())});return b},buildVheaderTable:function(a){var b=$("<table>"),d=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",a.labels.length+1).append($("<span>").text(a.vheader))),c=[];d.append($("<td>"));for(var e in a.labels)c.push($("<tr>").append($("<td>").html(""==a.labels[e]?"&nbsp;":a.labels[e]+":")));for(var l in a.content)for(e in d.append($("<td>").html(a.content[l].header)),a.content[l].body)c[e].append($("<td>").html(a.content[l].body[e])); ""!=d.getval()&&d.trigger("change")}"function"in c&&(d.on("change keyup",c["function"]),d.trigger("change"))}}b.on("keydown",function(a){var b=!1;switch(a.which){case 13:b=$(this).find("button.save").first();break;case 27:b=$(this).find("button.cancel").first()}b&&b.length&&(b.trigger("click"),a.stopPropagation())});return b},buildVheaderTable:function(a){var b=$("<table>"),e=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",a.labels.length+1).append($("<span>").text(a.vheader))),
b.append($("<tbody>").append(d).append(c));return b},plot:{addGraph:function(a,b){var d={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(d.elements.legend);d.elements.cont.append(d.elements.plot).append(d.elements.legend);b.append(d.elements.cont);return d},go:function(a){if(!(1>Object.keys(a).length)){var b={totals:[],clients:[]},d;for(d in a)for(var c in a[d].datasets){var e= c=[];e.append($("<td>"));for(var d in a.labels)c.push($("<tr>").append($("<td>").html(""==a.labels[d]?"&nbsp;":a.labels[d]+":")));for(var j in a.content)for(d in e.append($("<td>").html(a.content[j].header)),a.content[j].body)c[d].append($("<td>").html(a.content[j].body[d]));b.append($("<tbody>").append(e).append(c));return b},plot:{addGraph:function(a,b){var e={id:a.id,xaxis:a.xaxis,datasets:[],elements:{cont:$("<div>").addClass("graph"),plot:$("<div>").addClass("plot"),legend:$("<div>").addClass("legend").attr("draggable",
a[d].datasets[c];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; "true")}};UI.draggable(e.elements.legend);e.elements.cont.append(e.elements.plot).append(e.elements.legend);b.append(e.elements.cont);return e},go:function(a){if(!(1>Object.keys(a).length)){var b={totals:[],clients:[]},e;for(e in a)for(var c in a[e].datasets){var d=a[e].datasets[c];switch(d.datatype){case "clients":case "upbps":case "downbps":case "perc_lost":case "perc_retrans":switch(d.origin[0]){case "total":b.totals.push({fields:[d.datatype],end:-15});break;case "stream":b.totals.push({fields:[d.datatype],
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=[],n;for(n in c.datasets){var j=c.datasets[n];j.display&&(j.getdata(),j.yaxistype in c.yaxes||(d.push(UI.plot.yaxes[j.yaxistype]),c.yaxes[j.yaxistype]=d.length),j.yaxis=c.yaxes[j.yaxistype],e.push(j))}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, streams:[d.origin[1]],end:-15});break;case "protocol":b.totals.push({fields:[d.datatype],protocols:[d.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=[],n;for(n in c.datasets){var k=c.datasets[n];k.display&&(k.getdata(),
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 "+ k.yaxistype in c.yaxes||(d.push(UI.plot.yaxes[k.yaxistype]),c.yaxes[k.yaxistype]=d.length),k.yaxis=c.yaxes[k.yaxistype],e.push(k))}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",
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 q=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 g in c.datasets){var f="&nbsp;";if(c.datasets[g].display){var e=UI.plot.yaxes[c.datasets[g].yaxistype].tickFormatter, "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 q=function(a){var b=c.elements.legend.find(".value"),d=1;if(typeof a==
m=c.datasets[g].data;if(a)for(var q in m){if(m[q][0]==a){f=e(m[q][1]);break}if(m[q][0]>a){if(q!=0){f=m[q];m=m[q-1];f=e(f[1]+(a-f[0])*(m[1]-f[1])/(m[0]-f[0]))}break}}else f=e(c.datasets[g].data[c.datasets[g].data.length-1][1])}b.eq(d).html(f);d++}};c.plot.getOptions();for(n in c.datasets)e=$("<input>").attr("type","checkbox").data("index",n).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= "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 f="&nbsp;";if(c.datasets[h].display){var e=UI.plot.yaxes[c.datasets[h].yaxistype].tickFormatter,m=c.datasets[h].data;if(a)for(var k in m){if(m[k][0]==a){f=e(m[k][1]);break}if(m[k][0]>a){if(k!=0){f=m[k];m=m[k-1];f=e(f[1]+(a-f[0])*(m[1]-f[1])/(m[0]-f[0]))}break}}else f=e(c.datasets[h].data[c.datasets[h].data.length-1][1])}b.eq(d).html(f);
false;var b={};b[a.id]=a;UI.plot.go(b)}),c.datasets[n].display&&e.attr("checked","checked"),d.append($("<tr>").html($("<td>").html($("<label>").html(e).append($("<div>").addClass("series-color").css("background-color",c.datasets[n].color)).append(c.datasets[n].label))).append($("<td>").css("padding-right","2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").text("X").addClass("close").data("index",n).data("graph",c).click(function(){var b=$(this).data("index"), d++}};c.plot.getOptions();for(n in c.datasets)e=$("<input>").attr("type","checkbox").data("index",n).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[n].display&&e.attr("checked","checked"),d.append($("<tr>").html($("<td>").html($("<label>").html(e).append($("<div>").addClass("series-color").css("background-color",c.datasets[n].color)).append(c.datasets[n].label))).append($("<td>").css("padding-right",
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)}}}))));q();var g=!1;c.elements.plot.on("plothover",function(a,b,c){if(b.x!=g){q(b.x);g=b.x}if(c){a=$("<span>").append($("<h3>").text(c.series.label).prepend($("<div>").addClass("series-color").css("background-color", "2em").css("text-align","right").html($("<span>").addClass("value")).append($("<button>").text("X").addClass("close").data("index",n).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];
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(){q()})}}},b)}},save:function(a){var b={id:a.id,xaxis:a.xaxis,datasets:[]},d;for(d in a.datasets)b.datasets.push({origin:a.datasets[d].origin, UI.plot.go(a)}else{UI.plot.save(c);b={};b[c.id]=c;UI.plot.go(b)}}}))));q();var h=!1;c.elements.plot.on("plothover",function(a,b,c){if(b.x!=h){q(b.x);h=b.x}if(c){a=$("<span>").append($("<h3>").text(c.series.label).prepend($("<div>").addClass("series-color").css("background-color",c.series.color))).append($("<table>").addClass("nolay").html($("<tr>").html($("<td>").text("Time:")).append($("<td>").html(UI.format.dateTime(c.datapoint[0]/1E3,"long")))).append($("<tr>").html($("<td>").text("Value:")).append($("<td>").html(c.series.yaxis.tickFormatter(c.datapoint[1],
datatype:a.datasets[d].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),d=$.extend(!0,{},UI.plot.datatype.templates[a.datatype]),a=$.extend(!0,d,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; c.series.yaxis)))));UI.tooltip.show(b,a.children())}else UI.tooltip.hide()}).on("mouseout",function(){q()})}}},b)}},save:function(a){var b={id:a.id,xaxis:a.xaxis,datasets:[]},e;for(e in a.datasets)b.datasets.push({origin:a.datasets[e].origin,datatype:a.datasets[e].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),
case "stream":case "protocol":a.label+=" ("+a.origin[1]+")"}var b=[],c;for(c in a.basecolor)d=a.basecolor[c],d+=50*(0.5-Math.random()),d=Math.round(d),d=Math.min(255,Math.max(0,d)),b.push(d);a.color="rgb("+b.join(",")+")";return a},templates:{general:{display:!0,datatype:"general",label:"",yaxistype:"amount",data:[],lines:{show:!0},points:{show:!1},getdata:function(){var a=mist.data.totals["stream"==this.origin[0]?this.origin[1]:"all_streams"]["protocol"==this.origin[0]?this.origin[1]:"all_protocols"][this.datatype]; e=$.extend(!0,{},UI.plot.datatype.templates[a.datatype]),a=$.extend(!0,e,a),a=$.extend(!0,b,a);switch(a.origin[0]){case "total":switch(a.datatype){case "cpuload":case "memload":break;default:a.label+=" (total)"}break;case "stream":case "protocol":a.label+=" ("+a.origin[1]+")"}var b=[],c;for(c in a.basecolor)e=a.basecolor[c],e+=50*(0.5-Math.random()),e=Math.round(e),e=Math.min(255,Math.max(0,e)),b.push(e);a.color="rgb("+b.join(",")+")";return a},templates:{general:{display:!0,datatype:"general",label:"",
return this.data=a}},cpuload:{label:"CPU use",yaxistype:"percentage",basecolor:[237,194,64],cores:1,getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time-600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,mist.data.capabilities.cpu_use/10]);return this.data}},memload:{label:"Memory load",yaxistype:"percentage",basecolor:[175,216,248],getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time- yaxistype:"amount",data:[],lines:{show:!0},points:{show:!1},getdata:function(){var a=mist.data.totals["stream"==this.origin[0]?this.origin[1]:"all_streams"]["protocol"==this.origin[0]?this.origin[1]:"all_protocols"][this.datatype];return this.data=a}},cpuload:{label:"CPU use",yaxistype:"percentage",basecolor:[237,194,64],cores:1,getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time-600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,
600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,mist.data.capabilities.load.memory]);return this.data}},clients:{label:"Connections",basecolor:[203,75,75]},upbps:{label:"Bandwidth up",yaxistype:"bytespersec",basecolor:[77,167,77]},downbps:{label:"Bandwidth down",yaxistype:"bytespersec",basecolor:[148,64,237]},perc_lost:{label:"Lost packages",yaxistype:"percentage",basecolor:[255,33,234]},perc_retrans:{label:"Re-transmitted packages",yaxistype:"percentage", mist.data.capabilities.cpu_use/10]);return this.data}},memload:{label:"Memory load",yaxistype:"percentage",basecolor:[175,216,248],getdata:function(){var a=!1,b;for(b in this.data)this.data[b][0]<1E3*(mist.data.config.time-600)&&(a=b);!1!==a&&this.data.splice(0,Number(a)+1);this.data.push([1E3*mist.data.config.time,mist.data.capabilities.load.memory]);return this.data}},clients:{label:"Connections",basecolor:[203,75,75]},upbps:{label:"Bandwidth up",yaxistype:"bytespersec",basecolor:[77,167,77]},downbps:{label:"Bandwidth down",
basecolor:[0,0,255]}}},yaxes:{percentage:{name:"percentage",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.addUnit(UI.format.number(a),"%")},tickLength:0,min:0,max:100},amount:{name:"amount",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.number(a)},tickLength:0,min:0},bytespersec:{name:"bytespersec",color:"black",tickColor:0,tickDecimals:1,tickFormatter:function(a){return UI.format.bytes(a,!0)},tickLength:0,ticks:function(a){var b= yaxistype:"bytespersec",basecolor:[148,64,237]},perc_lost:{label:"Lost packages",yaxistype:"percentage",basecolor:[255,33,234]},perc_retrans:{label:"Re-transmitted packages",yaxistype:"percentage",basecolor:[0,0,255]}}},yaxes:{percentage:{name:"percentage",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.addUnit(UI.format.number(a),"%")},tickLength:0,min:0,max:100},amount:{name:"amount",color:"black",tickColor:0,tickDecimals:0,tickFormatter:function(a){return UI.format.number(a)},
0.3*Math.sqrt($(".graph").first().height()),b=(a.max-a.min)/b,d=Math.floor(Math.log(Math.abs(b))/Math.log(1024)),c=b/Math.pow(1024,d),e=-Math.floor(Math.log(c)/Math.LN10),l=a.tickDecimals;null!=l&&e>l&&(e=l);var i=Math.pow(10,-e),c=c/i,f;if(1.5>c)f=1;else if(3>c){if(f=2,2.25<c&&(null==l||e+1<=l))f=2.5,++e}else f=7.5>c?5:10;f=f*i*Math.pow(1024,d);null!=a.minTickSize&&f<a.minTickSize&&(f=a.minTickSize);a.delta=b;a.tickDecimals=Math.max(0,null!=l?l:e);a.tickSize=f;b=[];d=a.tickSize*Math.floor(a.min/ tickLength:0,min:0},bytespersec:{name:"bytespersec",color:"black",tickColor:0,tickDecimals:1,tickFormatter:function(a){return UI.format.bytes(a,!0)},tickLength:0,ticks:function(a){var b=0.3*Math.sqrt($(".graph").first().height()),b=(a.max-a.min)/b,e=Math.floor(Math.log(Math.abs(b))/Math.log(1024)),c=b/Math.pow(1024,e),d=-Math.floor(Math.log(c)/Math.LN10),j=a.tickDecimals;null!=j&&d>j&&(d=j);var i=Math.pow(10,-d),c=c/i,f;if(1.5>c)f=1;else if(3>c){if(f=2,2.25<c&&(null==j||d+1<=j))f=2.5,++d}else f=7.5>
a.tickSize);e=0;l=Number.NaN;do i=l,l=d+e*a.tickSize,b.push(l),++e;while(l<a.max&&l!=i);return b},min:0}},xaxes:{time:{name:"time",mode:"time",timezone:"browser",ticks:5}}},draggable:function(a){a.attr("draggable",!0);a.on("dragstart",function(a){$(this).css("opacity",0.4).data("dragstart",{click:{x:a.originalEvent.pageX,y:a.originalEvent.pageY},ele:{x:this.offsetLeft,y:this.offsetTop}})}).on("dragend",function(a){var d=$(this).data("dragstart"),c=d.ele.x-d.click.x+a.originalEvent.pageX,a=d.ele.y- c?5:10;f=f*i*Math.pow(1024,e);null!=a.minTickSize&&f<a.minTickSize&&(f=a.minTickSize);a.delta=b;a.tickDecimals=Math.max(0,null!=j?j:d);a.tickSize=f;b=[];e=a.tickSize*Math.floor(a.min/a.tickSize);d=0;j=Number.NaN;do i=j,j=e+d*a.tickSize,b.push(j),++d;while(j<a.max&&j!=i);return b},min:0}},xaxes:{time:{name:"time",mode:"time",timezone:"browser",ticks:5}}},draggable:function(a){a.attr("draggable",!0);a.on("dragstart",function(a){$(this).css("opacity",0.4).data("dragstart",{click:{x:a.originalEvent.pageX,
d.click.y+a.originalEvent.pageY;$(this).css({opacity:1,top:a,left:c,right:"auto",bottom:"auto"})});a.parent().on("dragleave",function(){})},format:{time:function(a,b){var d=new Date(1E3*a),c=[];c.push(("0"+d.getHours()).slice(-2));c.push(("0"+d.getMinutes()).slice(-2));"short"!=b&&c.push(("0"+d.getSeconds()).slice(-2));return c.join(":")},date:function(a,b){var d=new Date(1E3*a),c="Sun Mon Tue Wed Thu Fri Sat".split(" "),e=[];"long"==b&&e.push(c[d.getDay()]);e.push(("0"+d.getDate()).slice(-2));e.push("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")[d.getMonth()]); y:a.originalEvent.pageY},ele:{x:this.offsetLeft,y:this.offsetTop}})}).on("dragend",function(a){var e=$(this).data("dragstart"),c=e.ele.x-e.click.x+a.originalEvent.pageX,a=e.ele.y-e.click.y+a.originalEvent.pageY;$(this).css({opacity:1,top:a,left:c,right:"auto",bottom:"auto"})});a.parent().on("dragleave",function(){})},format:{time:function(a,b){var e=new Date(1E3*a),c=[];c.push(("0"+e.getHours()).slice(-2));c.push(("0"+e.getMinutes()).slice(-2));"short"!=b&&c.push(("0"+e.getSeconds()).slice(-2));return c.join(":")},
"short"!=b&&e.push(d.getFullYear());return e.join(" ")},dateTime:function(a,b){return UI.format.date(a,b)+", "+UI.format.time(a,b)},duration:function(a,b){var d=[0.001,1E3,60,60,24,1E99],c=["ms","sec","min","hr","day"],e={},l=!!(0>a),i=Math.abs(a),f;for(f in c){var i=Math.round(i/d[f]),m=i%d[Number(f)+1];e[c[f]]=m;i-=m}var n;for(f=c.length-1;0<=f;f--)if(0<e[c[f]]){n=c[f];break}d=$("<span>");switch(n){case "day":if(b){d.append(UI.format.addUnit(e.day,"days, ")).append(UI.format.addUnit(e.hr,"hrs")); date:function(a,b){var e=new Date(1E3*a),c="Sun Mon Tue Wed Thu Fri Sat".split(" "),d=[];"long"==b&&d.push(c[e.getDay()]);d.push(("0"+e.getDate()).slice(-2));d.push("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")[e.getMonth()]);"short"!=b&&d.push(e.getFullYear());return d.join(" ")},dateTime:function(a,b){return UI.format.date(a,b)+", "+UI.format.time(a,b)},duration:function(a,b){var e=[0.001,1E3,60,60,24,1E99],c=["ms","sec","min","hr","day"],d={},j=!!(0>a),i=Math.abs(a),f;for(f in c){var i=
break}else d.append(UI.format.addUnit(e.day,"days, "));default:if(b)switch(n){case "hr":d.append(UI.format.addUnit(e.hr,"hrs, ")).append(UI.format.addUnit(e.min,"mins"));break;case "min":d.append(UI.format.addUnit(e.min,"mins, ")).append(UI.format.addUnit(e.sec,"s"));break;case "sec":e=Math.round(1E3*e.sec+e.ms)/1E3;d.append(UI.format.addUnit(e,"s"));break;case "ms":d.append(UI.format.addUnit(e.ms,"ms"))}else d.append([("0"+e.hr).slice(-2),("0"+e.min).slice(-2),("0"+e.sec).slice(-2)+(e.ms?"."+("00"+ Math.round(i/e[f]),m=i%e[Number(f)+1];d[c[f]]=m;i-=m}var n;for(f=c.length-1;0<=f;f--)if(0<d[c[f]]){n=c[f];break}e=$("<span>");switch(n){case "day":if(b){e.append(UI.format.addUnit(d.day,"days, ")).append(UI.format.addUnit(d.hr,"hrs"));break}else e.append(UI.format.addUnit(d.day,"days, "));default:if(b)switch(n){case "hr":e.append(UI.format.addUnit(d.hr,"hrs, ")).append(UI.format.addUnit(d.min,"mins"));break;case "min":e.append(UI.format.addUnit(d.min,"mins, ")).append(UI.format.addUnit(d.sec,"s"));
e.ms).slice(-3):"")].join(":"))}return(l?"- ":"")+d[0].innerHTML},number:function(a){if(isNaN(Number(a))||0==a)return a;var b=Math.pow(10,3-Math.floor(Math.log(a)/Math.LN10)-1),a=Math.round(a*b)/b;if(1E4<=a){number=a.toString().split(".");for(a=/(\d+)(\d{3})/;a.test(number[0]);)number[0]=number[0].replace(a,"$1 $2");a=number.join(".")}return a},status:function(a){var b=$("<span>");if("undefined"==typeof a.online)return b.text("Unknown, checking.."),"undefined"!=typeof a.error&&b.text(a.error),b;switch(a.online){case -1:b.text("Enabling"); break;case "sec":d=Math.round(1E3*d.sec+d.ms)/1E3;e.append(UI.format.addUnit(d,"s"));break;case "ms":e.append(UI.format.addUnit(d.ms,"ms"))}else e.append([("0"+d.hr).slice(-2),("0"+d.min).slice(-2),("0"+d.sec).slice(-2)+(d.ms?"."+("00"+d.ms).slice(-3):"")].join(":"))}return(j?"- ":"")+e[0].innerHTML},number:function(a){if(isNaN(Number(a))||0==a)return a;var b=Math.pow(10,3-Math.floor(Math.log(a)/Math.LN10)-1),a=Math.round(a*b)/b;if(1E4<=a){number=a.toString().split(".");for(a=/(\d+)(\d{3})/;a.test(number[0]);)number[0]=
break;case 0:b.text("Unavailable").addClass("red");break;case 1:b.text("Active").addClass("green");break;case 2:b.text("Standby").addClass("orange");break;default:b.text(a.online)}"error"in a&&b.text(a.error);return b},capital:function(a){return a.charAt(0).toUpperCase()+a.substring(1)},addUnit:function(a,b){var d=$("<span>").html(a);d.append($("<span>").addClass("unit").html(b));return d[0].innerHTML},bytes:function(a,b){var d="bytes KiB MiB GiB TiB PiB".split(" ");if(0==a)unit=d[0];else{var c=Math.floor(Math.log(Math.abs(a))/ number[0].replace(a,"$1 $2");a=number.join(".")}return a},status:function(a){var b=$("<span>");if("undefined"==typeof a.online)return b.text("Unknown, checking.."),"undefined"!=typeof a.error&&b.text(a.error),b;switch(a.online){case -1:b.text("Enabling");break;case 0:b.text("Unavailable").addClass("red");break;case 1:b.text("Active").addClass("green");break;case 2:b.text("Standby").addClass("orange");break;default:b.text(a.online)}"error"in a&&b.text(a.error);return b},capital:function(a){return a.charAt(0).toUpperCase()+
Math.log(1024));0>c?unit=d[0]:(a/=Math.pow(1024,c),unit=d[c])}return UI.format.addUnit(UI.format.number(a),unit+(b?"/s":""))},bits:function(a,b){var d="b Kib Mib Gib Tib Pib".split(" ");if(0==a)unit=d[0];else{var c=Math.floor(Math.log(Math.abs(a))/Math.log(1024));0>c?unit=d[0]:(a/=Math.pow(1024,c),unit=d[c])}return UI.format.addUnit(UI.format.number(a),unit+(b?"ps":""))}},navto:function(a,b){var d=location.hash,c=d.split("@");c[0]=[mist.user.name,mist.user.host].join("&");c[1]=[a,b].join("&");"undefined"!= a.substring(1)},addUnit:function(a,b){var e=$("<span>").html(a);e.append($("<span>").addClass("unit").html(b));return e[0].innerHTML},bytes:function(a,b){var e="bytes KiB MiB GiB TiB PiB".split(" ");if(0==a)unit=e[0];else{var c=Math.floor(Math.log(Math.abs(a))/Math.log(1024));0>c?unit=e[0]:(a/=Math.pow(1024,c),unit=e[c])}return UI.format.addUnit(UI.format.number(a),unit+(b?"/s":""))},bits:function(a,b){var e="b Kib Mib Gib Tib Pib".split(" ");if(0==a)unit=e[0];else{var c=Math.floor(Math.log(Math.abs(a))/
typeof screenlog&&screenlog.navto(c[1]);location.hash=c.join("@");location.hash==d&&$(window).trigger("hashchange")},showTab:function(a,b,d){var c=UI.elements.main;"undefined"==typeof d&&(d=[]);if(mist.user.loggedin){if(!("ui_settings"in mist.data)){c.html("Loading..");mist.send(function(){UI.showTab(a,b)},{ui_settings:!0});return}mist.data.config.serverid&&(document.title=mist.data.config.serverid+" - MistServer MI")}var e=UI.elements.menu.removeClass("hide").find('.plain:contains("'+a+'")').filter(function(){return $(this).text()=== Math.log(1024));0>c?unit=e[0]:(a/=Math.pow(1024,c),unit=e[c])}return UI.format.addUnit(UI.format.number(a),unit+(b?"ps":""))}},navto:function(a,b){var e=location.hash,c=e.split("@");c[0]=[mist.user.name,mist.user.host].join("&");c[1]=[a,b].join("&");"undefined"!=typeof screenlog&&screenlog.navto(c[1]);location.hash=c.join("@");location.hash==e&&$(window).trigger("hashchange")},showTab:function(a,b,e){var c=UI.elements.main;"undefined"==typeof e&&(e=[]);if(mist.user.loggedin){if(!("ui_settings"in mist.data)){c.html("Loading..");
a}).closest(".button");0<e.length&&(UI.elements.menu.find(".button.active").removeClass("active"),e.addClass("active"),$submenu=e.closest("[data-param]"),$submenu.length&&$submenu.attr("data-param",b));window.mv&&mv.reference&&mv.reference.unload();UI.interval.clear();UI.websockets.clear();c.attr("data-tab",a).html($("<h2>").text(a));switch(a){case "Login":if(mist.user.loggedin){UI.navto("Overview");return}document.title="MistServer MI";UI.elements.menu.addClass("hide");UI.elements.connection.status.text("Disconnected").removeClass("green").addClass("red"); mist.send(function(){UI.showTab(a,b)},{ui_settings:!0});return}mist.data.config.serverid&&(document.title=mist.data.config.serverid+" - MistServer MI")}var d=UI.elements.menu.removeClass("hide").find('.plain:contains("'+a+'")').filter(function(){return $(this).text()===a}).closest(".button");0<d.length&&(UI.elements.menu.find(".button.active").removeClass("active"),d.addClass("active"),$submenu=d.closest("[data-param]"),$submenu.length&&$submenu.attr("data-param",b));window.mv&&mv.reference&&mv.reference.unload();
c.append(UI.buildUI([{type:"help",help:"Please provide your account details.<br>You were asked to set these when MistController was started for the first time. If you did not yet set any account details, log in with your desired credentials to create a new account."},{label:"Host",help:"Url location of the MistServer API. Generally located at http://MistServerIP:4242/api","default":"http://localhost:4242/api",pointer:{main:mist.user,index:"host"}},{label:"Username",help:"Please enter your username here.", UI.interval.clear();UI.websockets.clear();c.attr("data-tab",a).html($("<h2>").text(a));switch(a){case "Login":if(mist.user.loggedin){UI.navto("Overview");return}document.title="MistServer MI";UI.elements.menu.addClass("hide");UI.elements.connection.status.text("Disconnected").removeClass("green").addClass("red");c.append(UI.buildUI([{type:"help",help:"Please provide your account details.<br>You were asked to set these when MistController was started for the first time. If you did not yet set any account details, log in with your desired credentials to create a new account."},
validate:["required"],pointer:{main:mist.user,index:"name"}},{label:"Password",type:"password",help:"Please enter your password here.",validate:["required"],pointer:{main:mist.user,index:"rawpassword"}},{type:"buttons",buttons:[{label:"Login",type:"save","function":function(){mist.user.password=MD5(mist.user.rawpassword);delete mist.user.rawpassword;mist.send(function(){UI.navto("Overview")})}}]}]));break;case "Create a new account":UI.elements.menu.addClass("hide");c.append($("<p>").text("No account has been created yet in the MistServer at ").append($("<i>").text(mist.user.host)).append(".")); {label:"Host",help:"Url location of the MistServer API. Generally located at http://MistServerIP:4242/api","default":"http://localhost:4242/api",pointer:{main:mist.user,index:"host"}},{label:"Username",help:"Please enter your username here.",validate:["required"],pointer:{main:mist.user,index:"name"}},{label:"Password",type:"password",help:"Please enter your password here.",validate:["required"],pointer:{main:mist.user,index:"rawpassword"}},{type:"buttons",buttons:[{label:"Login",type:"save","function":function(){mist.user.password=
c.append(UI.buildUI([{type:"buttons",buttons:[{label:"Select other host",type:"cancel",css:{"float":"left"},"function":function(){UI.navto("Login")}}]},{type:"custom",custom:$("<br>")},{label:"Desired username",type:"str",validate:["required"],help:"Enter your desired username. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"name"}},{label:"Desired password",type:"password",validate:["required",function(a,b){$(".match_password.field").not($(b)).trigger("change"); MD5(mist.user.rawpassword);delete mist.user.rawpassword;mist.send(function(){UI.navto("Overview")})}}]}]));break;case "Create a new account":UI.elements.menu.addClass("hide");c.append($("<p>").text("No account has been created yet in the MistServer at ").append($("<i>").text(mist.user.host)).append("."));c.append(UI.buildUI([{type:"buttons",buttons:[{label:"Select other host",type:"cancel",css:{"float":"left"},"function":function(){UI.navto("Login")}}]},{type:"custom",custom:$("<br>")},{label:"Desired username",
return false}],help:"Enter your desired password. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"rawpassword"},classes:["match_password"]},{label:"Repeat password",type:"password",validate:["required",function(a,b){return a!=$(".match_password.field").not($(b)).val()?{msg:'The fields "Desired password" and "Repeat password" do not match.',classes:["red"]}:false}],help:"Repeat your desired password.",classes:["match_password"]},{type:"buttons", type:"str",validate:["required"],help:"Enter your desired username. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"name"}},{label:"Desired password",type:"password",validate:["required",function(a,b){$(".match_password.field").not($(b)).trigger("change");return false}],help:"Enter your desired password. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"rawpassword"},classes:["match_password"]},
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?"}, {label:"Repeat password",type:"password",validate:["required",function(a,b){return a!=$(".match_password.field").not($(b)).val()?{msg:'The fields "Desired password" and "Repeat password" do not match.',classes:["red"]}:false}],help:"Repeat your desired password.",classes:["match_password"]},{type:"buttons",buttons:[{type:"save",label:"Create new account","function":function(){mist.send(function(){UI.navto("Account created")},{authorize:{new_username:mist.user.name,new_password:mist.user.rawpassword}});
{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 "'+ 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>");
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 l=$("<span>").text("Loading.."),i=$("<span>"),f=$("<span>").addClass("logs"), 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})}}},
m=$("<span>"),n=$("<span>"),j=$("<span>").text("Unknown"),q=$("<span>"),g=$("<span>"),h=parseURL(mist.user.host),h=h.protocol+h.host+h.port,k={};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:l},{type:"span", {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 j=$("<span>").text("Loading.."),i=$("<span>"),f=$("<span>").addClass("logs"),m=$("<span>"),n=$("<span>"),k=$("<span>").text("Unknown"),q=$("<span>"),h=$("<span>"),g=parseURL(mist.user.host),g=g.protocol+g.host+g.port,l={};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. "},
label:"Server time",value:n},{type:"span",label:"Licensed to",value:"license"in mist.data.config?mist.data.config.license.user:""},{type:"span",label:"Active licenses",value:j},{type:"span",label:"Configured streams",value:mist.data.streams?Object.keys(mist.data.streams).length:0},{type:"span",label:"Active streams",value:i},{type:"span",label:"Current connections",value:m},{type:"span",label:"Enabled protocols",value:q},{type:"span",label:"Disabled protocols",value:g},{type:"span",label:"Recent problems", {type:"span",label:"Version",pointer:{main:mist.data.config,index:"version"}},{type:"span",label:"Version check",value:j},{type:"span",label:"Server time",value:n},{type:"span",label:"Licensed to",value:"license"in mist.data.config?mist.data.config.license.user:""},{type:"span",label:"Active licenses",value:k},{type:"span",label:"Configured streams",value:mist.data.streams?Object.keys(mist.data.streams).length:0},{type:"span",label:"Active streams",value:i},{type:"span",label:"Current connections",
value:f},$("<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:k,index:"save"}},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};if(k.save)a.save=k.save;delete k.save;mist.send(function(){UI.navto("Overview")}, value:m},{type:"span",label:"Enabled protocols",value:q},{type:"span",label:"Disabled protocols",value:h},{type:"span",label:"Recent problems",value:f},$("<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:l,index:"save"}},
a)}}]}]));if(mist.data.LTS){var o=function(a){function b(a){if(a.update){var d="";"progress"in a.update&&(d=" ("+a.update.progress+"%)");l.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>");l.append(b);for(var d in a)b.append($("<div>").text(a[d][2]))}}if(!a.update||!("uptodate"in a.update)){l.text("Unknown, checking..");setTimeout(function(){mist.send(function(a){"update"in {type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};if(l.save)a.save=l.save;delete l.save;mist.send(function(){UI.navto("Overview")},a)}}]}]));if(mist.data.LTS){var o=function(a){function b(a){if(a.update){var d="";"progress"in a.update&&(d=" ("+a.update.progress+"%)");j.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=
a&&o(a)},{checkupdate:true})},5E3)}else if(a.update.error)l.addClass("red").text(a.update.error);else if(a.update.uptodate)l.text("Your version is up to date.").addClass("green");else{if(a.update.progress){l.addClass("orange").removeClass("red").text("Updating..");b(a)}else{l.text("");l.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")&&l.append($("<button>").text("Rolling update").css({"font-size":"1em", $("<div>");j.append(b);for(var d in a)b.append($("<div>").text(a[d][2]))}}if(!a.update||!("uptodate"in a.update)){j.text("Unknown, checking..");setTimeout(function(){mist.send(function(a){"update"in a&&o(a)},{checkupdate:true})},5E3)}else if(a.update.error)j.addClass("red").text(a.update.error);else if(a.update.uptodate)j.text("Your version is up to date.").addClass("green");else{if(a.update.progress){j.addClass("orange").removeClass("red").text("Updating..");b(a)}else{j.text("");j.append($("<span>").addClass("red").text("On "+
"margin-left":"1em"}).click(function(){if(confirm("Are you sure you want to execute a rolling update?")){l.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:";l.append($("<div>").append(d))}c(a.log)}};o(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 s= (new Date(a.update.date)).toLocaleDateString()+" version "+a.update.version+" became available."));(!a.update.url||a.update.url.slice(-4)!=".zip")&&j.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?")){j.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",
$("<table>").css("text-indent","0");j.html(s);s.append($("<tr>").append($("<th>").append("Product")).append($("<th>").append("Updates until")).append($("<th>").append("Use until")).append($("<th>").append("Max. simul. instances")));for(var p in mist.data.config.license.active_products)h=mist.data.config.license.active_products[p],s.append($("<tr>").append($("<td>").append(h.name)).append($("<td>").append(h.updates_final?h.updates_final:"&infin;")).append($("<td>").append(h.use_final?h.use_final:"&infin;")).append($("<td>").append(h.amount? "_blank").text("Manual download");d[0].protocol="https:";j.append($("<div>").append(d))}c(a.log)}};o(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 u=$("<table>").css("text-indent","0");k.html(u);u.append($("<tr>").append($("<th>").append("Product")).append($("<th>").append("Updates until")).append($("<th>").append("Use until")).append($("<th>").append("Max. simul. instances")));for(var p in mist.data.config.license.active_products){var s=
h.amount:"&infin;")))}else j.text("None. ");j.append($("<a>").text("More details").attr("href","https://shop.mistserver.org/myinvoices").attr("target","_blank"))}}else l.text("");p=function(){var a={totals:{fields:["clients"],start:-10},active_streams:true};if(!("capabilities"in mist.data))a.capabilities=true;mist.send(function(){ca()},a)};var ca=function(){i.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.config.license.active_products[p];u.append($("<tr>").append($("<td>").append(s.name)).append($("<td>").append(s.updates_final?s.updates_final:"&infin;")).append($("<td>").append(s.use_final?s.use_final:"&infin;")).append($("<td>").append(s.amount?s.amount:"&infin;")))}}else k.text("None. ");k.append($("<a>").text("More details").attr("href","https://shop.mistserver.org/myinvoices").attr("target","_blank"))}}else j.text("");p=function(){var a={totals:{fields:["clients"],start:-10},active_streams:true};
mist.data.totals.all_streams.all_protocols.clients,a=a.length?UI.format.number(a[a.length-1][1]):0;else a="Loading..";m.text(a);n.text(UI.format.dateTime(mist.data.config.time,"long"));f.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"), if(!("capabilities"in mist.data))a.capabilities=true;mist.send(function(){ga()},a)};var ga=function(){i.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..";m.text(a);n.text(UI.format.dateTime(mist.data.config.time,"long"));f.html("");a=0;"license"in mist.data.config&&"user_msg"in
h=c[2].split("|");for(b in h)d.append($("<span>").text(h[b]));f.append($("<div>").append($("<span>").append(UI.format.time(c[0]))).append(d));if(a==5)break}}a==0&&f.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)}q.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);g.text(c.length?c.join(", "):"None.")}else g.text("Loading..")}; 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]));f.append($("<div>").append($("<span>").append(UI.format.time(c[0])).css("margin-right","0.5em")).append(d));if(a==5)break}}a==0&&f.html("None.");a=[];c=[];for(b in mist.data.config.protocols){d=
p();ca();UI.interval.set(p,3E4);break;case "General":var G={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},H={sessionViewerMode:mist.data.config.sessionViewerMode,sessionInputMode:mist.data.config.sessionInputMode,sessionOutputMode:mist.data.config.sessionOutputMode,sessionUnspecifiedMode:mist.data.config.sessionUnspecifiedMode, mist.data.config.protocols[b];a.indexOf(d.connector)>-1||a.push(d.connector)}q.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);h.text(c.length?c.join(", "):"None.")}else h.text("Loading..")};p();ga();UI.interval.set(p,3E4);break;case "General":var L={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,
tknMode:mist.data.config.tknMode,sessionStreamInfoMode:mist.data.config.sessionStreamInfoMode},P={location:"location"in mist.data.config?mist.data.config.location:{}},x={limit:""};"bandwidth"in mist.data&&(x=mist.data.bandwidth,null==x&&(x={}),x.limit||(x.limit=""));var da=$("<select>").html($("<option>").val(1).text("bytes/s")).append($("<option>").val(1024).text("KiB/s")).append($("<option>").val(1048576).text("MiB/s")).append($("<option>").val(1073741824).text("GiB/s"));c.html(UI.buildUI([$("<h2>").text("General settings"), trustedproxy:mist.data.config.trustedproxy},M={sessionViewerMode:mist.data.config.sessionViewerMode,sessionInputMode:mist.data.config.sessionInputMode,sessionOutputMode:mist.data.config.sessionOutputMode,sessionUnspecifiedMode:mist.data.config.sessionUnspecifiedMode,tknMode:mist.data.config.tknMode,sessionStreamInfoMode:mist.data.config.sessionStreamInfoMode},U={location:"location"in mist.data.config?mist.data.config.location:{}},F={limit:""};"bandwidth"in mist.data&&(F=mist.data.bandwidth,null==
{type:"help",help:"These are settings that apply to your MistServer instance in general."},{type:"str",label:"Human readable name",pointer:{main:G,index:"serverid"},help:"You can name your MistServer here for personal use. You'll still need to set host name within your network yourself."},{type:"debug",label:"Debug level",pointer:{main:G,index:"debug"},help:"You can set the amount of debug information MistServer saves in the log. A full reboot of MistServer is required before some components of MistServer can post debug information."}, F&&(F={}),F.limit||(F.limit=""));var ha=$("<select>").html($("<option>").val(1).text("bytes/s")).append($("<option>").val(1024).text("KiB/s")).append($("<option>").val(1048576).text("MiB/s")).append($("<option>").val(1073741824).text("GiB/s"));c.html(UI.buildUI([$("<h2>").text("General settings"),{type:"help",help:"These are settings that apply to your MistServer instance in general."},{type:"str",label:"Human readable name",pointer:{main:L,index:"serverid"},help:"You can name your MistServer here for personal use. You'll still need to set host name within your network yourself."},
{type:"selectinput",label:"Access log",selectinput:[["","Do not track"],["LOG","Log to MistServer log"],[{type:"str",label:"Path",LTSonly:!0},"Log to file"]],pointer:{main:G,index:"accesslog"},help:"Enable access logs.",LTSonly:!0},{type:"selectinput",label:"Prometheus stats output",selectinput:[["","Disabled"],[{type:"str",label:"Passphrase",LTSonly:!0},"Enabled"]],pointer:{main:G,index:"prometheus"},help:"Make stats available in Prometheus format. These can be accessed via "+h+"/PASSPHRASE or "+ {type:"debug",label:"Debug level",pointer:{main:L,index:"debug"},help:"You can set the amount of debug information MistServer saves in the log. A full reboot of MistServer is required before some components of MistServer can post debug information."},{type:"selectinput",label:"Access log",selectinput:[["","Do not track"],["LOG","Log to MistServer log"],[{type:"str",label:"Path",LTSonly:!0},"Log to file"]],pointer:{main:L,index:"accesslog"},help:"Enable access logs.",LTSonly:!0},{type:"selectinput",
h+"/PASSPHRASE.json.",LTSonly:!0},{type:"inputlist",label:"Trusted proxies",help:"List of proxy server addresses that are allowed to override the viewer IP address to arbitrary values.<br>You may use a hostname or IP address.",pointer:{main:G,index:"trustedproxy"}},{type:"str",validate:["streamname_with_wildcard_and_variables"],label:"Fallback stream",pointer:{main:G,index:"defaultStream"},help:"When this is set, if someone attempts to view a stream that does not exist, or is offline, they will be redirected to this stream instead. $stream may be used to refer to the original stream name.", label:"Prometheus stats output",selectinput:[["","Disabled"],[{type:"str",label:"Passphrase",LTSonly:!0},"Enabled"]],pointer:{main:L,index:"prometheus"},help:"Make stats available in Prometheus format. These can be accessed via "+g+"/PASSPHRASE or "+g+"/PASSPHRASE.json.",LTSonly:!0},{type:"inputlist",label:"Trusted proxies",help:"List of proxy server addresses that are allowed to override the viewer IP address to arbitrary values.<br>You may use a hostname or IP address.",pointer:{main:L,index:"trustedproxy"}},
LTSonly:!0},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(a){$(a).text("Saving..");mist.send(function(){UI.navto("General")},{config:G})}}]}]));c.append(UI.buildUI([$("<h3>").text("Sessions"),{type:"bitmask",label:"Bundle viewer sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:H,index:"sessionViewerMode"},help:"Change the way viewer connections are bundled into sessions.<br>Default: stream name, viewer IP and token"},{type:"bitmask", {type:"str",validate:["streamname_with_wildcard_and_variables"],label:"Fallback stream",pointer:{main:L,index:"defaultStream"},help:"When this is set, if someone attempts to view a stream that does not exist, or is offline, they will be redirected to this stream instead. $stream may be used to refer to the original stream name.",LTSonly:!0},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(a){$(a).text("Saving..");mist.send(function(){UI.navto("General")},{config:L})}}]}]));c.append(UI.buildUI([$("<h3>").text("Sessions"),
label:"Bundle input sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:H,index:"sessionInputMode"},help:"Change the way input connections are bundled into sessions.<br>Default: stream name, input IP, token and protocol"},{type:"bitmask",label:"Bundle output sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:H,index:"sessionOutputMode"},help:"Change the way output connections are bundled into sessions.<br>Default: stream name, output IP, token and protocol"}, {type:"bitmask",label:"Bundle viewer sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:M,index:"sessionViewerMode"},help:"Change the way viewer connections are bundled into sessions.<br>Default: stream name, viewer IP and token"},{type:"bitmask",label:"Bundle input sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:M,index:"sessionInputMode"},help:"Change the way input connections are bundled into sessions.<br>Default: stream name, input IP, token and protocol"},
{type:"bitmask",label:"Bundle unspecified sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:H,index:"sessionUnspecifiedMode"},help:"Change the way unspecified connections are bundled into sessions.<br>Default: none"},{type:"select",label:"Treat HTTP-only sessions as",select:[[1,"A viewer session"],[2,"An output session: skip executing the USER_NEW and USER_END triggers"],[4,"A separate 'unspecified' session: skip executing the USER_NEW and USER_END triggers"], {type:"bitmask",label:"Bundle output sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:M,index:"sessionOutputMode"},help:"Change the way output connections are bundled into sessions.<br>Default: stream name, output IP, token and protocol"},{type:"bitmask",label:"Bundle unspecified sessions by",bitmask:[[8,"Stream name"],[4,"IP address"],[2,"Token"],[1,"Protocol"]],pointer:{main:M,index:"sessionUnspecifiedMode"},help:"Change the way unspecified connections are bundled into sessions.<br>Default: none"},
[3,"Do not start a session: skip executing the USER_NEW and USER_END triggers and do not count for statistics"]],pointer:{main:H,index:"sessionStreamInfoMode"},help:"Change the way the stream info connection gets treated.<br>Default: as a viewer session"},{type:"bitmask",label:"Communicate session token",bitmask:[[8,"Write to cookie"],[4,"Write to URL parameter"],[2,"Read from cookie"],[1,"Read from URL parameter"]],pointer:{main:H,index:"tknMode"},help:"Change the way the session token gets passed to and from MistServer, which can be set as a cookie or URL parameter named `tkn`. Reading the session token as a URL parameter takes precedence over reading from the cookie.<br>Default: all"}, {type:"select",label:"Treat HTTP-only sessions as",select:[[1,"A viewer session"],[2,"An output session: skip executing the USER_NEW and USER_END triggers"],[4,"A separate 'unspecified' session: skip executing the USER_NEW and USER_END triggers"],[3,"Do not start a session: skip executing the USER_NEW and USER_END triggers and do not count for statistics"]],pointer:{main:M,index:"sessionStreamInfoMode"},help:"Change the way the stream info connection gets treated.<br>Default: as a viewer session"},
{type:"buttons",buttons:[{type:"save",label:"Save","function":function(a){$(a).text("Saving..");mist.send(function(){UI.navto("General")},{config:H})}}]}]));var S=$("<div>").html("Loading..");mist.send(function(a){if(a.variable_list){var b=$("<tbody>");S.html($("<table>").html($("<thead>").html($("<tr>").append($("<th>").text("Variable")).append($("<th>").text("Latest value")).append($("<th>").text("Command")).append($("<th>").text("Check interval")).append($("<th>").text("Last checked")).append($("<th>")))).append(b)); {type:"bitmask",label:"Communicate session token",bitmask:[[8,"Write to cookie"],[4,"Write to URL parameter"],[2,"Read from cookie"],[1,"Read from URL parameter"]],pointer:{main:M,index:"tknMode"},help:"Change the way the session token gets passed to and from MistServer, which can be set as a cookie or URL parameter named `tkn`. Reading the session token as a URL parameter takes precedence over reading from the cookie.<br>Default: all"},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(a){$(a).text("Saving..");
for(var c in a.variable_list){var d=a.variable_list[c];b.append($("<tr>").addClass("variable").attr("data-name",c).html($("<td>").text("$"+c)).append($("<td>").html($("<code>").text(typeof d=="string"?JSON.stringify(d):d[2]>0?JSON.stringify(d[3]):""))).append($("<td>").text(typeof d=="string"?"":d[0])).append($("<td>").html(typeof d=="string"?"Never":d[1]==0?"Once":UI.format.duration(d[1]))).append($("<td>").attr("title",d[2]>0?typeof d=="string"?"":"At "+UI.format.dateTime(new Date(d[2]),"long"): mist.send(function(){UI.navto("General")},{config:M})}}]}]));var D=$("<div>").html("Loading..");mist.send(function(a){if(a.variable_list){var b=$("<tbody>");D.html($("<table>").html($("<thead>").html($("<tr>").append($("<th>").text("Variable")).append($("<th>").text("Latest value")).append($("<th>").text("Command")).append($("<th>").text("Check interval")).append($("<th>").text("Last checked")).append($("<th>")))).append(b));for(var c in a.variable_list){var d=a.variable_list[c];b.append($("<tr>").addClass("variable").attr("data-name",
"Not yet").html(typeof d=="string"?"":d[2]>0?UI.format.duration((new Date).getTime()*0.001-d[2])+" ago":"Not yet")).append($("<td>").html($("<button>").text("Edit").click(function(){var a=$(this).closest("tr").attr("data-name");UI.navto("Edit variable",a)})).append($("<button>").text("Remove").click(function(){var a=$(this).closest("tr").attr("data-name");confirm("Are you sure you want to remove the custom variable $"+a+"?")&&mist.send(function(){UI.showTab("General")},{variable_remove:a})}))))}}else S.html("None configured.")}, c).html($("<td>").text("$"+c)).append($("<td>").html($("<code>").text(typeof d=="string"?JSON.stringify(d):d[2]>0?JSON.stringify(d[3]):""))).append($("<td>").text(typeof d=="string"?"":d[0])).append($("<td>").html(typeof d=="string"?"Never":d[1]==0?"Once":UI.format.duration(d[1]))).append($("<td>").attr("title",d[2]>0?typeof d=="string"?"":"At "+UI.format.dateTime(new Date(d[2]),"long"):"Not yet").html(typeof d=="string"?"":d[2]>0?UI.format.duration((new Date).getTime()*0.001-d[2])+" ago":"Not yet")).append($("<td>").html($("<button>").text("Edit").click(function(){var a=
{variable_list:!0});c.append(UI.buildUI([$("<h3>").text("Custom variables"),{type:"help",help:"In certain places, like target URL's and pushes, variable substitution is applied in order to replace a $variable with their corresponding value. Here you can define your own constants and variables which will be used when variable substitution is applied. Variables can be used within variables but will not be reflected in their latest value on this page."},$("<div>").addClass("button_container").css("text-align", $(this).closest("tr").attr("data-name");UI.navto("Edit variable",a)})).append($("<button>").text("Remove").click(function(){var a=$(this).closest("tr").attr("data-name");confirm("Are you sure you want to remove the custom variable $"+a+"?")&&mist.send(function(){UI.showTab("General")},{variable_remove:a})}))))}}else D.html("None configured.")},{variable_list:!0});c.append(UI.buildUI([$("<h3>").text("Custom variables"),{type:"help",help:"In certain places, like target URL's and pushes, variable substitution is applied in order to replace a $variable with their corresponding value. Here you can define your own constants and variables which will be used when variable substitution is applied. Variables can be used within variables but will not be reflected in their latest value on this page."},
"right").html($("<button>").text("New variable").click(function(){UI.navto("Edit variable","")})),S]));c.append(UI.buildUI([$("<h3>").text("Load balancer"),{type:"help",help:"If you're using MistServer's load balancer, the information below is passed to it so that it can make informed decisions."},{type:"selectinput",label:"Server's bandwidth limit",selectinput:[["","Default (1 gbps)"],[{label:"Custom",type:"int",min:0,unit:da},"Custom"]],pointer:{main:x,index:"limit"},help:"This is the amount of traffic this server is willing to handle."}, $("<div>").addClass("button_container").css("text-align","right").html($("<button>").text("New variable").click(function(){UI.navto("Edit variable","")})),D]));c.append(UI.buildUI([$("<h3>").text("Load balancer"),{type:"help",help:"If you're using MistServer's load balancer, the information below is passed to it so that it can make informed decisions."},{type:"selectinput",label:"Server's bandwidth limit",selectinput:[["","Default (1 gbps)"],[{label:"Custom",type:"int",min:0,unit:ha},"Custom"]],pointer:{main:F,
{type:"inputlist",label:"Bandwidth exceptions",pointer:{main:x,index:"exceptions"},help:"Data sent to the hosts and subnets listed here will not count towards reported bandwidth usage.<br>Examples:<ul><li>192.168.0.0/16</li><li>localhost</li><li>10.0.0.0/8</li><li>fe80::/16</li></ul>"},{type:"int",step:1E-8,label:"Server latitude",pointer:{main:P.location,index:"lat"},help:"This setting is only useful when MistServer is combined with a load balancer. When this is set, the balancer can send users to a server close to them."}, index:"limit"},help:"This is the amount of traffic this server is willing to handle."},{type:"inputlist",label:"Bandwidth exceptions",pointer:{main:F,index:"exceptions"},help:"Data sent to the hosts and subnets listed here will not count towards reported bandwidth usage.<br>Examples:<ul><li>192.168.0.0/16</li><li>localhost</li><li>10.0.0.0/8</li><li>fe80::/16</li></ul>"},{type:"int",step:1E-8,label:"Server latitude",pointer:{main:U.location,index:"lat"},help:"This setting is only useful when MistServer is combined with a load balancer. When this is set, the balancer can send users to a server close to them."},
{type:"int",step:1E-8,label:"Server longitude",pointer:{main:P.location,index:"lon"},help:"This setting is only useful when MistServer is combined with a load balancer. When this is set, the balancer can send users to a server close to them."},{type:"str",label:"Server location name",pointer:{main:P.location,index:"name"},help:"This setting is only useful when MistServer is combined with a load balancer. This will be displayed as the server's location."},{type:"buttons",buttons:[{type:"save",label:"Save", {type:"int",step:1E-8,label:"Server longitude",pointer:{main:U.location,index:"lon"},help:"This setting is only useful when MistServer is combined with a load balancer. When this is set, the balancer can send users to a server close to them."},{type:"str",label:"Server location name",pointer:{main:U.location,index:"name"},help:"This setting is only useful when MistServer is combined with a load balancer. This will be displayed as the server's location."},{type:"buttons",buttons:[{type:"save",label:"Save",
"function":function(a){$(a).text("Saving..");var a={config:P},b={};b.limit=x.limit?da.val()*x.limit:0;b.exceptions=x.exceptions;if(b.exceptions===null)b.exceptions=[];a.bandwidth=b;mist.send(function(){UI.navto("Overview")},a)}}]}]));var C=$("<div>").html("Loading..");c.append(UI.buildUI([$("<h3>").text("External writers"),{type:"help",help:"When pushing a stream to a target unsupported by MistServer like S3 storage, an external writer can be provided which handles writing the media data to the target location. The writer will receive data over stdin and MistServer will print any info written to stdout and stderr as log messages."}, "function":function(a){$(a).text("Saving..");var a={config:U},b={};b.limit=F.limit?ha.val()*F.limit:0;b.exceptions=F.exceptions;if(b.exceptions===null)b.exceptions=[];a.bandwidth=b;mist.send(function(){UI.navto("Overview")},a)}}]}]));var G=$("<div>").html("Loading..");c.append(UI.buildUI([$("<h3>").text("External writers"),{type:"help",help:"When pushing a stream to a target unsupported by MistServer like S3 storage, an external writer can be provided which handles writing the media data to the target location. The writer will receive data over stdin and MistServer will print any info written to stdout and stderr as log messages."},
$("<div>").addClass("button_container").css("text-align","right").html($("<button>").text("New external writer").click(function(){UI.navto("Edit external writer","")})),C]));mist.send(function(a){if(a.external_writer_list){var b=$("<tbody>");C.html($("<table>").html($("<thead>").html($("<tr>").append($("<th>").text("Name")).append($("<th>").text("Command line")).append($("<th>").text("URI protocols handled")).append($("<th>")))).append(b));for(var c in a.external_writer_list){var d=a.external_writer_list[c]; $("<div>").addClass("button_container").css("text-align","right").html($("<button>").text("New external writer").click(function(){UI.navto("Edit external writer","")})),G]));mist.send(function(a){if(a.external_writer_list){var b=$("<tbody>");G.html($("<table>").html($("<thead>").html($("<tr>").append($("<th>").text("Name")).append($("<th>").text("Command line")).append($("<th>").text("URI protocols handled")).append($("<th>")))).append(b));for(var c in a.external_writer_list){var d=a.external_writer_list[c];
b.append($("<tr>").addClass("uploader").attr("data-name",c).html($("<td>").text(d[0])).append($("<td>").html($("<code>").html(d[1]))).append($("<td>").text(d[2]?d[2].join(", "):"none").addClass("desc")).append($("<td>").html($("<button>").text("Edit").click(function(){var a=$(this).closest("tr").attr("data-name");UI.navto("Edit external writer",a)})).append($("<button>").text("Remove").click(function(){var b=$(this).closest("tr").attr("data-name"),b=a.external_writer_list[b][0];confirm("Are you sure you want to remove the Uploader '"+ b.append($("<tr>").addClass("uploader").attr("data-name",c).html($("<td>").text(d[0])).append($("<td>").html($("<code>").html(d[1]))).append($("<td>").text(d[2]?d[2].join(", "):"none").addClass("desc")).append($("<td>").html($("<button>").text("Edit").click(function(){var a=$(this).closest("tr").attr("data-name");UI.navto("Edit external writer",a)})).append($("<button>").text("Remove").click(function(){var b=$(this).closest("tr").attr("data-name"),b=a.external_writer_list[b][0];confirm("Are you sure you want to remove the Uploader '"+
b+"'?")&&mist.send(function(){UI.showTab("General")},{external_writer_remove:b})}))))}}else C.html("None configured.")},{external_writer_list:!0});break;case "Edit external writer":var u=!1;""!=b&&(u=!0);var D=function(){u?c.html($("<h2>").text("Edit external writer '"+b+"'")):c.html($("<h2>").text("New external writer"));var a={};if(mist.data.external_writer_list&&b in mist.data.external_writer_list){var d=mist.data.external_writer_list[b];a.name=d[0];a.cmdline=d[1];a.protocols=d[2]}c.append(UI.buildUI([{type:"str", b+"'?")&&mist.send(function(){UI.showTab("General")},{external_writer_remove:b})}))))}}else G.html("None configured.")},{external_writer_list:!0});break;case "Edit external writer":var v=!1;""!=b&&(v=!0);var w=function(){v?c.html($("<h2>").text("Edit external writer '"+b+"'")):c.html($("<h2>").text("New external writer"));var a={};if(mist.data.external_writer_list&&b in mist.data.external_writer_list){var d=mist.data.external_writer_list[b];a.name=d[0];a.cmdline=d[1];a.protocols=d[2]}c.append(UI.buildUI([{type:"str",
label:"Human readable name",help:"A human readable name for the external writer.",validate:["required"],pointer:{main:a,index:"name"}},{type:"str",label:"Command line",help:"Command line for a local command (with optional arguments) which will write media data to the target.",validate:["required"],pointer:{main:a,index:"cmdline"}},{type:"inputlist",label:"URI protocols handled",help:"URI protocols which the external writer will be handling.",validate:["required",function(a){for(var b in a){var c= label:"Human readable name",help:"A human readable name for the external writer.",validate:["required"],pointer:{main:a,index:"name"}},{type:"str",label:"Command line",help:"Command line for a local command (with optional arguments) which will write media data to the target.",validate:["required"],pointer:{main:a,index:"cmdline"}},{type:"inputlist",label:"URI protocols handled",help:"URI protocols which the external writer will be handling.",validate:["required",function(a){for(var b in a){var c=
a[b];if(c.match(/^([a-z\d\+\-\.])+?$/)===null)return{classes:["red"],msg:"There was a problem with the protocol URI '"+$("<div>").text(c).html()+"':<br>A protocol URI may only contain lower case letters, digits, and the following special characters . + and -"}}}],input:{type:"str",unit:"://"},pointer:{main:a,index:"protocols"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("General")}},{type:"save",label:"Save","function":function(){var c={external_writer_add:a}, a[b];if(c.match(/^([a-z\d\+\-\.])+?$/)===null)return{classes:["red"],msg:"There was a problem with the protocol URI '"+$("<div>").text(c).html()+"':<br>A protocol URI may only contain lower case letters, digits, and the following special characters . + and -"}}}],input:{type:"str",unit:"://"},pointer:{main:a,index:"protocols"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("General")}},{type:"save",label:"Save","function":function(){var c={external_writer_add:a},
d=null;b!=""&&b in mist.data.external_writer_list&&(d=mist.data.external_writer_list[b][0]);if(d!==null&&a.name!=d)c.external_writer_remove=d;mist.send(function(){UI.navto("General")},c)}}]}]))};"external_writer_list"in mist.data?D():mist.send(function(){D()},{external_writer_list:!0});break;case "Edit variable":u=!1;""!=b&&(u=!0);var v=function(a,d){u?c.html($("<h2>").text('Edit Variable "$'+b+'"')):c.html($("<h2>").text("New Variable"));var h=$("<div>");c.append(UI.buildUI([{type:"str",maxlength:31, d=null;b!=""&&b in mist.data.external_writer_list&&(d=mist.data.external_writer_list[b][0]);if(d!==null&&a.name!=d)c.external_writer_remove=d;mist.send(function(){UI.navto("General")},c)}}]}]))};"external_writer_list"in mist.data?w():mist.send(function(){w()},{external_writer_list:!0});break;case "Edit variable":v=!1;""!=b&&(v=!0);var P=function(a,d){v?c.html($("<h2>").text('Edit Variable "$'+b+'"')):c.html($("<h2>").text("New Variable"));var e=$("<div>");c.append(UI.buildUI([{type:"str",maxlength:31,
label:"Variable name",prefix:"$",help:"What should the variable be called? A dollar sign will automatically be prepended.",pointer:{main:a,index:"name"},validate:["required",function(a){if(a.length&&a[0]=="$")return{msg:"The dollar sign will automatically be prepended. You don't need to type it here.",classes:["red"]};if(a.indexOf("{")!==-1||a.indexOf("}")!==-1||a.indexOf("$")!==-1)return{msg:'The following symbols are not permitted: "$ { }".',classes:["red"]}}]},{type:"select",label:"Type",help:"What kind of variable is this? It can either be a static value that you can enter below, or a dynamic one that is returned by a command.", label:"Variable name",prefix:"$",help:"What should the variable be called? A dollar sign will automatically be prepended.",pointer:{main:a,index:"name"},validate:["required",function(a){if(a.length&&a[0]=="$")return{msg:"The dollar sign will automatically be prepended. You don't need to type it here.",classes:["red"]};if(a.indexOf("{")!==-1||a.indexOf("}")!==-1||a.indexOf("$")!==-1)return{msg:'The following symbols are not permitted: "$ { }".',classes:["red"]}}]},{type:"select",label:"Type",help:"What kind of variable is this? It can either be a static value that you can enter below, or a dynamic one that is returned by a command.",
select:[["value","Static value"],["command","Dynamic through command"]],value:"value",pointer:{main:d,index:"type"},"function":function(){var a=[$("Invalid variable type")];switch($(this).val()){case "value":a=[{type:"str",label:"Value",pointer:{main:d,index:"value"},help:"The static value that this variable should be replaced with. There is a character limit of 63 characters.",validate:["required"]}];break;case "command":a=[{type:"str",label:"Command",help:"The command that should be executed to retrieve the value for this variable.<br>For example:<br><code>/usr/bin/date +%A</code><br>There is a character limit of 511 characters.", select:[["value","Static value"],["command","Dynamic through command"]],value:"value",pointer:{main:d,index:"type"},"function":function(){var a=[$("Invalid variable type")];switch($(this).val()){case "value":a=[{type:"str",label:"Value",pointer:{main:d,index:"value"},help:"The static value that this variable should be replaced with. There is a character limit of 63 characters.",validate:["required"]}];break;case "command":a=[{type:"str",label:"Command",help:"The command that should be executed to retrieve the value for this variable.<br>For example:<br><code>/usr/bin/date +%A</code><br>There is a character limit of 511 characters.",
validate:["required"],pointer:{main:d,index:"target"}},{type:"int",min:0,max:4294967295,"default":0,label:"Checking interval",unit:"s",help:"At what interval, in seconds, MistServer should execute the command and update the value.<br>To execute the command once when MistServer starts up (and then never update), set the interval to 0.",pointer:{main:d,index:"interval"}},{type:"int",min:0,max:4294967295,"default":1,label:"Wait time",unit:"s",help:"Specifies the maximum time, in seconds, MistServer should wait for data when executing the variable target. If set to 0 this variable takes on the same value as the interval.<br>MistServer only updates one variable at a time, so setting this value too high can block other variables from updating.", validate:["required"],pointer:{main:d,index:"target"}},{type:"int",min:0,max:4294967295,"default":0,label:"Checking interval",unit:"s",help:"At what interval, in seconds, MistServer should execute the command and update the value.<br>To execute the command once when MistServer starts up (and then never update), set the interval to 0.",pointer:{main:d,index:"interval"}},{type:"int",min:0,max:4294967295,"default":1,label:"Wait time",unit:"s",help:"Specifies the maximum time, in seconds, MistServer should wait for data when executing the variable target. If set to 0 this variable takes on the same value as the interval.<br>MistServer only updates one variable at a time, so setting this value too high can block other variables from updating.",
pointer:{main:d,index:"waitTime"}}]}h.html(UI.buildUI(a))}},h,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("General")}},{type:"save",label:"Save","function":function(){var c={variable_add:a};switch(d.type){case "value":a.value=d.value;break;case "command":a.target=d.target;a.interval=d.interval;a.waitTime=d.waitTime}if(a.name!=b)c.variable_remove=b;mist.send(function(){UI.navto("General")},c)}}]}]))};c.html("Loading..");u?mist.send(function(a){if(b in a.variable_list){a= pointer:{main:d,index:"waitTime"}}]}e.html(UI.buildUI(a))}},e,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("General")}},{type:"save",label:"Save","function":function(){var c={variable_add:a};switch(d.type){case "value":a.value=d.value;break;case "command":a.target=d.target;a.interval=d.interval;a.waitTime=d.waitTime}if(a.name!=b)c.variable_remove=b;mist.send(function(){UI.navto("General")},c)}}]}]))};c.html("Loading..");v?mist.send(function(a){if(b in a.variable_list){a=
a.variable_list[b];v({name:b},typeof a=="string"?{value:a,type:"value"}:{target:a[0],interval:a[1],waitTime:a[4],type:"command"})}else c.append('Variable "$'+b+'" does not exist.')},{variable_list:!0}):v({},{});break;case "Protocols":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},{capabilities:!0});c.append("Loading..");return}var A=$("<tbody>");c.append(UI.buildUI([{type:"help",help:"You can find an overview of all the protocols and their relevant information here. You can add, edit or delete protocols."}])).append($("<button>").text("Delete all protocols").click(function(){if(confirm("Are you sure you want to delete all currently configured protocols?")){mist.data.config.protocols= a.variable_list[b];P({name:b},typeof a=="string"?{value:a,type:"value"}:{target:a[0],interval:a[1],waitTime:a[4],type:"command"})}else c.append('Variable "$'+b+'" does not exist.')},{variable_list:!0}):P({},{});break;case "Protocols":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a)},{capabilities:!0});c.append("Loading..");return}var C=$("<tbody>");c.append(UI.buildUI([{type:"help",help:"You can find an overview of all the protocols and their relevant information here. You can add, edit or delete protocols."}])).append($("<button>").text("Delete all protocols").click(function(){if(confirm("Are you sure you want to delete all currently configured protocols?")){mist.data.config.protocols=
[];mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}})).append($("<button>").text("Enable default protocols").click(function(){var a=Object.keys(mist.data.capabilities.connectors),b;for(b in mist.data.config.protocols){var c=a.indexOf(mist.data.config.protocols[b].connector);c>-1&&a.splice(c,1)}var d=[];for(b in a)(!("required"in mist.data.capabilities.connectors[a[b]])||Object.keys(mist.data.capabilities.connectors[a[b]].required).length==0)&&d.push(a[b]);c="Click OK to enable disabled protocols with their default settings:\n "; [];mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}})).append($("<button>").text("Enable default protocols").click(function(){var a=Object.keys(mist.data.capabilities.connectors),b;for(b in mist.data.config.protocols){var c=a.indexOf(mist.data.config.protocols[b].connector);c>-1&&a.splice(c,1)}var d=[];for(b in a)(!("required"in mist.data.capabilities.connectors[a[b]])||Object.keys(mist.data.capabilities.connectors[a[b]].required).length==0)&&d.push(a[b]);c="Click OK to enable disabled protocols with their default settings:\n ";
c=d.length?c+d.join(", "):c+"None.";if(d.length!=a.length){a=a.filter(function(a){return d.indexOf(a)<0});c=c+("\n\nThe following protocols can only be set manually:\n "+a.join(", "))}if(confirm(c)&&d.length){if(mist.data.config.protocols===null)mist.data.config.protocols=[];for(b in d)mist.data.config.protocols.push({connector:d[b]});mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}})).append("<br>").append($("<button>").text("New protocol").click(function(){UI.navto("Edit Protocol")}).css("clear", c=d.length?c+d.join(", "):c+"None.";if(d.length!=a.length){a=a.filter(function(a){return d.indexOf(a)<0});c=c+("\n\nThe following protocols can only be set manually:\n "+a.join(", "))}if(confirm(c)&&d.length){if(mist.data.config.protocols===null)mist.data.config.protocols=[];for(b in d)mist.data.config.protocols.push({connector:d[b]});mist.send(function(){UI.navto("Protocols")},{config:mist.data.config})}})).append("<br>").append($("<button>").text("New protocol").click(function(){UI.navto("Edit Protocol")}).css("clear",
"both")).append($("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Protocol")).append($("<th>").text("Status")).append($("<th>").text("Settings")).append($("<th>")))).append(A));var L=function(){function a(b){var c=mist.data.capabilities.connectors[b.connector];if(!c)return"";var d=[],h=["required","optional"],e;for(e in h)for(var g in c[h[e]])b[g]&&b[g]!=""?d.push(g+": "+b[g]):c[h[e]][g]["default"]&&d.push(g+": "+c[h[e]][g]["default"]);return $("<span>").addClass("description").text(d.join(", "))} "both")).append($("<table>").html($("<thead>").addClass("sticky").html($("<tr>").html($("<th>").text("Protocol")).append($("<th>").text("Status")).append($("<th>").text("Settings")).append($("<th>")))).append(C));var ia=function(){function a(b){var c=mist.data.capabilities.connectors[b.connector];if(!c)return"";var d=[],e=["required","optional"],g;for(g in e)for(var f in c[e[g]])b[f]&&b[f]!=""?d.push(f+": "+b[f]):c[e[g]][f]["default"]&&d.push(f+": "+c[e[g]][f]["default"]);return $("<span>").addClass("description").text(d.join(", "))}
A.html("");for(var b in mist.data.config.protocols){var c=mist.data.config.protocols[b],d=mist.data.capabilities.connectors[c.connector];A.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= C.html("");for(var b in mist.data.config.protocols){var c=mist.data.config.protocols[b],d=mist.data.capabilities.connectors[c.connector];C.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)}}))))}};L();UI.interval.set(function(){mist.send(function(){L()})},1E4);break;case "Edit Protocol":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}u= $(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)}}))))}};ia();UI.interval.set(function(){mist.send(function(){ia()})},1E4);break;case "Edit Protocol":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}v=
!1;""!=b&&0<=b&&(u=!0);var M={};for(p in mist.data.config.protocols)M[mist.data.config.protocols[p].connector]=1;var ea=function(a){var b=mist.data.capabilities.connectors[a],c=mist.convertBuildOptions(b,r);if(u)var d=$.extend({},r);c.push({type:"hidden",pointer:{main:r,index:"connector"},value:a});c.push({type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};u?a.updateprotocol=[d,r]:a.addprotocol=r;mist.send(function(){UI.navto("Protocols")},a)}},{type:"cancel",label:"Cancel", !1;""!=b&&0<=b&&(v=!0);var Q={};for(p in mist.data.config.protocols)Q[mist.data.config.protocols[p].connector]=1;var ja=function(a){var b=mist.data.capabilities.connectors[a],c=mist.convertBuildOptions(b,r);if(v)var d=$.extend({},r);c.push({type:"hidden",pointer:{main:r,index:"connector"},value:a});c.push({type:"buttons",buttons:[{type:"save",label:"Save","function":function(){var a={};v?a.updateprotocol=[d,r]:a.addprotocol=r;mist.send(function(){UI.navto("Protocols")},a)}},{type:"cancel",label:"Cancel",
"function":function(){UI.navto("Protocols")}}]});if("deps"in b&&b.deps!=""){s=$("<span>").text("Dependencies:");$ul=$("<ul>");s.append($ul);if(typeof b.deps=="string")b.deps=b.deps.split(", ");for(var h in b.deps){a=$("<li>").text(b.deps[h]+" ");$ul.append(a);typeof M[b.deps[h]]!="undefined"||typeof M[b.deps[h]+".exe"]!="undefined"?a.append($("<span>").addClass("green").text("(Configured)")):a.append($("<span>").addClass("red").text("(Not yet configured)"))}c.unshift({type:"text",text:s[0].innerHTML})}return UI.buildUI(c)}, "function":function(){UI.navto("Protocols")}}]});if("deps"in b&&b.deps!=""){u=$("<span>").text("Dependencies:");$ul=$("<ul>");u.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 Q[b.deps[e]]!="undefined"||typeof Q[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:u[0].innerHTML})}return UI.buildUI(c)},
M={};for(p in mist.data.config.protocols)M[mist.data.config.protocols[p].connector]=1;if(u)r=p=mist.data.config.protocols[b],c.find("h2").append(' "'+p.connector+'"'),c.append(ea(p.connector));else{c.html($("<h2>").text("New Protocol"));var r={},t=[["",""]];for(p in mist.data.capabilities.connectors)t.push([p,mist.data.capabilities.connectors[p].friendly?mist.data.capabilities.connectors[p].friendly:p]);var fa=$("<span>");c.append(UI.buildUI([{label:"Protocol",type:"select",select:t,"function":function(){$(this).getval()!= Q={};for(p in mist.data.config.protocols)Q[mist.data.config.protocols[p].connector]=1;if(v)r=p=mist.data.config.protocols[b],c.find("h2").append(' "'+p.connector+'"'),c.append(ja(p.connector));else{c.html($("<h2>").text("New Protocol"));var r={},d=[["",""]];for(p in mist.data.capabilities.connectors)d.push([p,mist.data.capabilities.connectors[p].friendly?mist.data.capabilities.connectors[p].friendly:p]);var ka=$("<span>");c.append(UI.buildUI([{label:"Protocol",type:"select",select:d,"function":function(){$(this).getval()!=
""&&fa.html(ea($(this).getval()))}}])).append(fa)}break;case "Streams":if(!("capabilities"in mist.data)){c.html("Loading..");mist.send(function(){UI.navto(a)},{capabilities:!0});return}p=$("<button>");var I=$("<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(p).append($("<button>").text("Create a new stream").click(function(){UI.navto("Edit")}))])).append(I); ""&&ka.html(ja($(this).getval()))}}])).append(ka)}break;case "Streams":if(!("capabilities"in mist.data)){c.html("Loading..");mist.send(function(){UI.navto(a,b)},{capabilities:!0});return}var s=mist.stored.get(),z={by:name,dir:1};""==b&&"viewmode"in s&&(b=s.viewmode);"sortstreams"in s&&(z=s.sortstreams);"streams_pagesize"in s&&(k=s.streams_pagesize);var x,s=UI.buildUI([{type:"help",help:"This is an overview of the streams you've currently configured.<br>You can left click a stream to "+("thumbnails"==
""==b&&(k=mist.stored.get(),"viewmode"in k&&(b=k.viewmode));p.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 B=$.extend(!0,{},mist.data.streams),T=function(a,b){var c=$.extend({},b);delete c.meta;delete c.error;c.online=2;c.name=a;c.ischild=true;return c},ga=function(b,d,h){I.remove();switch(b){case "thumbnails":var e=$("<div>").addClass("preview_icons"), b?"edit":"preview")+" it"+("thumbnails"==b?", or its thumbnail to preview it":"")+". You can right click a stream for an action menu."},$("<div>").css({width:"45.25em",display:"flex","justify-content":"flex-end"}).append($("<button>").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")})).append($("<button>").text("Create a new stream").click(function(){UI.navto("Edit")})),
g;g=h||[];d.sort();d.unshift("");I.remove();c.append($("<h2>").text(a)).append(UI.buildUI([{label:"Filter the streams",type:"datalist",datalist:d,pointer:{main:{},index:"stream"},help:"If you type something here, the box below will only show streams with names that contain your text.","function":function(){var a=$(this).val();e.children().each(function(){$(this).hide();$(this).attr("data-stream").indexOf(a)>-1&&$(this).show()})}}]));d.shift();c.append($("<span>").addClass("description").text("Choose a stream below.")).append(e); {label:"Filter streams",help:"Stream names that do not contain the text you enter here will be hidden.","function":function(){var a=$(this).getval();x&&x.filter(a)},css:{"margin-top":"3em"}}]);c.append(s);var t=$.extend({},mist.data.streams);if("thumbnails"==b){x=UI.dynamic({create:function(){var a=document.createElement("div");a.className="streams thumbnails";UI.sortableItems(a,function(a){return this.sortValues[a]},false);return a},values:t,add:{create:function(a){var b=document.createElement("div");
b=false;if(UI.findOutput("JPG")){var f=false,m;for(m in mist.data.config.protocols){h=mist.data.config.protocols[m];if(h.connector=="HTTP"||h.connector=="HTTP.exe")f=h.port?":"+h.port:":8080";if(h.connector=="JPG"||h.connector=="JPG.exe")b=true}if(b&&f){f=parseURL(mist.user.host).host+f;b=function(a){return"http://"+f+"/"+encodeURIComponent(a)+".jpg"}}}for(m in d){var h=d[m],q="",j=$("<button>").text("Delete").click(function(){var a=$(this).closest("div").attr("data-stream");if(confirm('Are you sure you want to delete the stream "'+ b.className="stream";b.setAttribute("data-id",a);var c=["thumbnail","actions"];b.elements={};b.elements.header=document.createElement("a");b.elements.header.className="header";b.appendChild(b.elements.header);for(var d in c){var e=c[d];b.elements[e]=document.createElement("div");b.elements[e].className=e;b.elements[e].raw=false;b.appendChild(b.elements[e])}if(a.indexOf("+")>=0){b.setAttribute("data-iswildcardstream","yes");c=document.createElement("span");c.className="wildparent";d=a.split("+");c.appendChild(document.createTextNode(d.shift()+
a+'"?')){delete mist.data.streams[a];var b={};b.deletestream=[a];mist.send(function(){UI.navto("Streams")},b)}}),k=$("<button>").text("Settings").click(function(){UI.navto("Edit",$(this).closest("div").attr("data-stream"))}),l=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("div").attr("data-stream"))}),i=$("<button>").text("Embed").click(function(){UI.navto("Embed",$(this).closest("div").attr("data-stream"))}),n=$("<span>").addClass("image");b&&g.indexOf(h)==-1&& "+"));b.elements.header.appendChild(c);b.elements.header.appendChild(document.createTextNode(d.join("+")))}else{b.setAttribute("data-iswildcardstream","no");b.elements.header.innerText=a}b.elements.header.addEventListener("click",function(){UI.navto("Edit",a)});b.elements.thumbnail.addEventListener("click",function(){t[a].isfolderstream?t[a].filesfound?UI.navto("Edit",a):UI.findFolderSubstreams(t[a],function(c){$.extend(t,c);x.update(t);t[a].filesfound=true;b.setAttribute("data-showingsubstreams",
n.append($("<img>").attr("src",b(h)).error(function(){$(this).hide()}));if(h.indexOf("+")>-1){q=h.split("+");q=mist.data.streams[q[0]].source+q[1];k=j="";n.addClass("wildcard")}else{q=mist.data.streams[h].source;if(g.indexOf(h)>-1){i=l="";n.addClass("folder")}}e.append($("<div>").append($("<span>").addClass("streamname").text(h)).append(n).append($("<span>").addClass("description").text(q)).append($("<span>").addClass("button_container").append(k).append(j).append(l).append(i)).attr("title",h).attr("data-stream", "yes");b.setAttribute("title","This is a folder stream: it points to a folder with media files inside.")}):UI.navto("Preview",a)});b.elements.actions.appendChild($("<button>").text("Actions").click(function(b){var c=$(this).offset();I.fill(a,{pageX:c.left,pageY:c.top});b.stopPropagation()})[0]);b.insertBefore(UI.modules.stream.status(a,{thumbnail:false,tags:"readonly"})[0],b.children[1]);b.remove=function(){this.parentNode&&this.parentNode.removeChild(this)};b.addEventListener("contextmenu",function(b){b.preventDefault();
h))}break;default:var o=$("<tbody>").append($("<tr>").append("<td>").attr("colspan",6).text("Loading.."));m=$("<table>").html($("<thead>").html($("<tr>").html($("<th>").text("Stream name").attr("data-sort-type","string").addClass("sorting-asc")).append($("<th>")).append($("<th>").text("Source").attr("data-sort-type","string")).append($("<th>").text("Status").attr("data-sort-type","int")).append($("<th>").css("text-align","right").text("Connections").attr("data-sort-type","int")))).append(o);c.append(m); I.fill(a,b)});return b},update:function(a){if(a.online==1&&a.online!=this.elements.thumbnail.raw){var b=UI.modules.stream.thumbnail(a.name,{clone:true});this.elements.thumbnail.appendChild(b[0]);this.elements.thumbnail.raw=a.online}if(a.source!=this.raw_source){this.raw_source=a.source;b=UI.findInput("Folder");this.setAttribute("title",a.source);if(b)if(mist.inputMatch(b.source_match,a.source)){this.setAttribute("data-isfolderstream","yes");a.isfolderstream=true;this.setAttribute("title","This is a folder stream: it points to a folder with media files inside. Click to request its sub streams.")}else{this.setAttribute("data-isfolderstream",
m.stupidtable();var p=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,B,mist.data.streams);var a=0;o.html("");d.sort();for(var b in d){var c=d[b],h;h=c in mist.data.streams?mist.data.streams[c]:B[c];var e=$("<td>").css("text-align","right").html($("<span>").addClass("description").text("Loading..")),g=0;if(typeof mist.data.totals!="undefined"&&typeof mist.data.totals[c]!="undefined"){var f= "no");this.setAttribute("title",a.source);a.isfolderstream=false}}b=[0,1,2,3,5,4,0];this.sortValues={name:a.name,state:a.stats&&a.stats.length>=2?b.length>a.stats[1]?b[a.stats[1]]:0:0,viewers:a.stats&&a.stats.length>=3?a.stats[2]:0,inputs:a.stats&&a.stats.length>=4?a.stats[3]:0,outputs:a.stats&&a.stats.length>=5?a.stats[4]:0}}},update:function(){this.sort();this.show_page&&this.show_page()}});c.append(x);var J=z.by,V={name:1,viewers:-1,state:-1,inputs:-1,outputs:-1},R=V[J]*z.dir;s.append(UI.buildUI([{label:"Sort streams by",
mist.data.totals[c].all_protocols.clients,g=0;if(f.length){for(a in f)g=g+f[a][1];g=Math.round(g/f.length)}}e.html(UI.format.number(g));if(g==0&&h.online==1)h.online=2;g=$("<td>").css("white-space","nowrap");(!("ischild"in h)||!h.ischild)&&g.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 "'+ help:"Choose by which attribute the streams listed below should be sorted",type:"select",select:[["name","Stream name"],["state","State (Online, offline, waiting etc.)"],["viewers","Viewers"],["inputs","Inputs"],["outputs","Outputs"]],value:z.by,"function":function(){J=$(this).getval();z.by=J;mist.stored.set("sortstreams",z);x&&x.sort(J,V[J]*R)},unit:$("<label>").append($("<input>").attr("type","checkbox").prop("checked",-1==R).change(function(){R=$(this).is(":checked")?-1:1;z.dir=R*V[J];mist.stored.set("sortstreams",
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(h.name);h.ischild&&f.css("padding-left","1em");var m=UI.format.status(h),q=$("<button>").text("Status").click(function(){UI.navto("Status",$(this).closest("tr").data("index"))}),j=$("<button>").text("Preview").click(function(){UI.navto("Preview",$(this).closest("tr").data("index"))}),k=$("<button>").text("Embed").css("margin-right", z);x&&x.sort(J,V[J]*R)})).append($("<span>").text("Reverse"))}]).children())}else{var E=$("<table>").addClass("streams");c.append(E);E.layout={name:function(a,b){if(b!=this.raw){this.raw=b;var c=this,d=$("<a>").text(a.name).click(function(){$(c).attr("data-iswildcard")=="no"&&$(c).attr("data-isfolderstream")=="yes"?UI.navto("Edit",b):UI.navto("Preview",b)});if(b.indexOf("+")>=0){var e=b.split("+"),g=e.shift(),e=e.join("+");$(this).attr("data-iswildcard",g+"+");d.attr("title","This is a wildcard stream: its config is inherited from its parent: '"+
"1em").click(function(){UI.navto("Embed",$(this).closest("tr").data("index"))});if("filesfound"in B[c]||h.online<0){m.html("");e.html("");j.css({opacity:0,pointerEvents:"none"});k.css({opacity:0,pointerEvents:"none"})}g.prepend(k).prepend(q).prepend(j);o.append($("<tr>").data("index",c).html($("<td>").html(f).attr("title",h.name=="..."?"The results were truncated":h.name).addClass("overflow_ellipsis")).append(g).append($("<td>").text(h.source).attr("title",h.source).addClass("description").addClass("overflow_ellipsis").css("max-width", g+"'.").html($("<span>").addClass("wildparent").text(g+"+")).append(e)}else $(this).attr("data-iswildcard","no");$(this).html(d)}if(a.source!=this.raw_src){this.raw_src=a.source;if(mist.data.capabilities)if(d=UI.findInput("Folder"))if(mist.inputMatch(d.source_match,a.source)){$(this).attr("data-isfolderstream","yes").attr("title","This is a folder stream: it points to a folder with media files inside. Click the '\u2795' to request its sub streams.");a.isfolderstream=true}else{$(this).attr("data-isfolderstream",
"20em")).append($("<td>").data("sort-value",h.online).html(m)).append(e));a++}},{totals:a,active_streams:true})},U=0,r=0;for(g in mist.data.streams){m=mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"];if(!m)break;if(mist.inputMatch(m.source_match,mist.data.streams[g].source)){B[g].source=B[g].source+"*";B[g].filesfound=null;mist.send(function(a,b){var c=b.stream,d=0,h;a:for(h in a.browse.files){var g;for(g in mist.data.capabilities.inputs)if(!(g.indexOf("Buffer")>= "no").attr("title",a.source);a.isfolderstream=false}}},actions:function(a,b){if(!this.raw){$(this).html($("<button>").text("Actions").click(function(a){var c=$(this).offset();I.fill(b,{pageX:c.left,pageY:c.top});a.stopPropagation()}));this.raw=true}},state:function(a){var b=$("<div>").attr("data-streamstatus",0).text("Inactive");if("stats"in a){if(this.raw==a.stats[1])return;b=$("<div>").attr("data-streamstatus",a.stats[1]).text(["Offline","Initializing","Booting","Waiting for data","Available","Shutting down",
0||g.indexOf("Buffer.exe")>=0||g.indexOf("Folder")>=0||g.indexOf("Folder.exe")>=0)&&mist.inputMatch(mist.data.capabilities.inputs[g].source_match,"/"+a.browse.files[h])){var e=c+"+"+a.browse.files[h];B[e]=T(e,mist.data.streams[c]);B[e].source=mist.data.streams[c].source+a.browse.files[h];d++;if(d>=500){B[c+"+zzzzzzzzz"]={ischild:true,name:"...",online:-1};break a}}}"files"in a.browse&&a.browse.files.length?B[c].filesfound=true:mist.data.streams[c].filesfound=false;r++;if(U==r){mist.send(function(){p()}, "Invalid state"][a.stats[1]]);this.raw=a.stats[1]}$(this).html(b).addClass("activestream")},viewers:function(a){var b="";if("stats"in a){if(this.raw==a.stats[2])return;b=a.stats[2];this.raw=a.stats[2]}$(this).html(b)},inputs:function(a){var b="";if("stats"in a){if(this.raw==a.stats[3])return;b=a.stats[3];this.raw=a.stats[3]}$(this).html(b)},outputs:function(a){var b="";if("stats"in a){if(this.raw==a.stats[4])return;b=a.stats[4];this.raw=a.stats[4]}$(this).html(b)}};var Y=$("<tr>").attr("data-sortby",
{active_streams:true});UI.interval.set(function(){p()},5E3)}},{browse:mist.data.streams[g].source},{stream:g});U++}}if(U==0){mist.send(function(){p()},{active_streams:true});UI.interval.set(function(){p()},5E3)}}},V=0,ha=0,t={},ia=[];for(k in mist.data.streams)if(mist.inputMatch((mist.data.capabilities.inputs.Folder||mist.data.capabilities.inputs["Folder.exe"]).source_match,mist.data.streams[k].source))ia.push(k),mist.send(function(a,c){var d=c.stream,h=0,g;a:for(g in a.browse.files){var e;for(e in mist.data.capabilities.inputs)if(!(e.indexOf("Buffer")>= "name");E.append($("<thead>").addClass("sticky").append(Y));s={name:"Stream name",actions:""};for(p in E.layout)g=p in s?s[p]:UI.format.capital(p),d=$("<th>").text(g),""!=g&&d.attr("data-index",p).click(function(){var a=$(this).attr("data-index");if(z.by==a)z.dir=z.dir*-1;else{z.by=a;z.dir=1}mist.stored.set("sortstreams",z);x.sort($(this).attr("data-index"))}),Y.append(d);x=UI.dynamic({create:function(){var a=document.createElement("tbody");UI.sortableItems(a,function(a){return this._cells[a].raw},
0||e.indexOf("Folder")>=0)&&mist.inputMatch(mist.data.capabilities.inputs[e].source_match,"/"+a.browse.files[g])){t[d+"+"+a.browse.files[g]]=true;h++;if(h>=500){t[d+"+zzzzzzzzz"]=true;break a}}}ha++;V==ha&&mist.send(function(){for(var a in mist.data.active_streams){var c=mist.data.active_streams[a].split("+");if(c.length>1&&c[0]in mist.data.streams){t[mist.data.active_streams[a]]=true;B[mist.data.active_streams[a]]=T(mist.data.active_streams[a],mist.data.streams[c[0]])}}t=Object.keys(t);t=t.concat(Object.keys(mist.data.streams)); Y[0]);a.remove=function(){this.parentNode&&this.parentNode.removeChild(this)};return a},values:t,add:{create:function(a){var b=document.createElement("tr");b.setAttribute("data-id",a);b._cells={};for(var c in E.layout){var d=document.createElement("td");b._cells[c]=d;b.append(d)}b.addEventListener("contextmenu",function(b){b.preventDefault();I.fill(a,b)});b.addEventListener("click",function(){if(t[a].isfolderstream&&!("filesfound"in t[a])){UI.findFolderSubstreams(t[a],function(a){$.extend(t,a);x.update(t);
t.sort();ga(b,t,ia)},{active_streams:true})},{browse:mist.data.streams[k].source},{stream:k}),V++;0==V&&mist.send(function(){for(var a in mist.data.active_streams){var c=mist.data.active_streams[a].split("+");if(c.length>1&&c[0]in mist.data.streams){t[mist.data.active_streams[a]]=true;B[mist.data.active_streams[a]]=T(mist.data.active_streams[a],mist.data.streams[c[0]])}}t=Object.keys(t);mist.data.streams&&(t=t.concat(Object.keys(mist.data.streams)));t.sort();ga(b,t)},{active_streams:!0});break;case "Edit":if("undefined"== b.setAttribute("data-showingsubstreams","")});x.show_page(this)}});b.remove=function(){this.parentNode&&this.parentNode.removeChild(this)};return b},update:function(a){for(var b in E.layout)E.layout[b].call(this._cells[b],a,this._id)}},update:function(){this.sort();this.show_page&&this.show_page()}});E.append(x)}x.filter=function(a){for(var a=a.toLowerCase(),b=0;b<this.children.length;b++){var c=this.children[b];c.getAttribute("data-id").toLowerCase().indexOf(a)>=0?c.classList.remove("hidden"):c.classList.add("hidden")}x.show_page()};
typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}u=!1;""!=b&&(u=!0);u?(h=b.split("+")[0],r=mist.data.streams[h],c.find("h2").append(' "'+h+'"')):(c.html($("<h2>").text("New Stream")),r={});var h=[],e=$("<datalist>").attr("id","source_datalist"),J=$("<div>").addClass("source_info"),W=!1,N=!1;for(p in mist.data.capabilities.inputs)for(j in mist.data.capabilities.inputs[p].source_match)h.push(mist.data.capabilities.inputs[p].source_match[j]), var I=new UI.context_menu;c.append(I.ele);I.fill=function(a,b){var c=[$("<div>").addClass("header").text(a)],d=[["<span>Edit "+(a.indexOf("+")<0?"stream":"<b>"+a.split("+")[0]+"</b>")+"</span>",function(){UI.navto("Edit",a)},"Edit","Change the settings of this stream."],["Stream status",function(){UI.navto("Status",a)},"Status","See more details about the status of this stream."],["Preview stream",function(){UI.navto("Preview",a)},"Preview","Watch the stream."],["Embed stream",function(){UI.navto("Embed",
e.append($("<option>").val(mist.data.capabilities.inputs[p].source_match[j]));var Q=$("<div>"),ja=function(a){var c={};if(!mist.data.streams)mist.data.streams={};mist.data.streams[r.name]=r;b!=r.name&&delete mist.data.streams[b];c.addstream={};c.addstream[r.name]=r;if(b!=r.name)c.deletestream=[b];if(r.stop_sessions&&b!=""){c.stop_sessions=b;delete r.stop_sessions}var d=null,h;for(h in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[h].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[h].source_match, a)},"Embed","Get urls to this stream or get code to embed it on your website."]],e=[["Delete stream",function(){if(confirm('Are you sure you want to delete the stream "'+a+'"?')){delete mist.data.streams[a];mist.send(function(){delete t[a];x.update(t)},{deletestream:[a]})}},"trash","Remove this stream's settings."],["Stop sessions",function(){confirm("Are you sure you want to disconnect all sessions (viewers, pushes and possibly the input) for the stream '"+a+"'?")&&mist.send(function(){},{stop_sessions:a})},
r.source)){d=h;break}if(d){d=mist.data.capabilities.inputs[d];for(h in r)h=="name"||h=="source"||h=="stop_sessions"||h=="processes"||"optional"in d&&h in d.optional||"required"in d&&h in d.required||h=="always_on"&&"always_match"in d&&mist.inputMatch(d.always_match,r.source)||delete r[h]}mist.send(function(){delete mist.data.streams[r.name].online;delete mist.data.streams[r.name].error;UI.navto(a,a=="Preview"?r.name:"")},c)},ka=$("<style>").text("button.saveandpreview { display: none; }"),K=$("<span>"), "stop","Disconnect sessions for this stream. Disconnecting a session will kill any currently open connections (viewers, pushes and possibly the input). If the USER_NEW trigger is in use, it will be triggered again by any reconnecting connections."],["Invalidate sessions",function(){confirm("Are you sure you want to invalidate all sessions for the stream '"+a+"'?\nThis will re-trigger the USER_NEW trigger.")&&mist.send(function(){},{invalidate_sessions:a})},"invalidate","Invalidate all the currently active sessions for this stream. This has the effect of re-triggering the USER_NEW trigger, allowing you to selectively close some of the existing connections after they have been previously allowed. If you don't have a USER_NEW trigger configured, this will not have any effect."],
j=$("<div>"),X={},t=[],la=$("<div>");for(p in mist.data.capabilities.processes)t.push([p,mist.data.capabilities.processes[p].hrn?mist.data.capabilities.processes[p].hrn:mist.data.capabilities.processes[p].name]);t.length&&(p=[{label:"New process",type:"select",select:t,value:t[0][0],pointer:{main:X,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")];la.html(UI.buildUI(b.concat(mist.convertBuildOptions(a, ["Nuke stream",function(){confirm("Are you sure you want to completely shut down the stream '"+a+"'?\nAll viewers will be disconnected.")&&mist.send(function(){},{nuke_stream:a})},"nuke","Shut down a running stream completely and/or clean up any potentially left over stream data in memory. It attempts a clean shutdown of the running stream first, followed by a forced shut down, and then follows up by checking for left over data in memory and cleaning that up if any is found."]];if(t[a].isfolderstream){d.pop();
X))))}}},la],j.append(UI.buildUI([$("<br>"),$("<h3>").text("Stream processes"),{label:"Stream processes",itemLabel:"stream process",type:"sublist",sublist:p,saveas:X,pointer:{main:r,index:"processes"}}])));c.append(UI.buildUI([{label:"Stream name",type:"str",validate:["required","streamname"],pointer:{main:r,index:"name"},help:"Set the name this stream will be recognised by for players and/or stream pushing."},{label:"Source",type:"browse",filetypes:h,pointer:{main:r,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>", d.pop();e=[e[0]]}c=[c];t[a].isfolderstream&&!t[a].filesfound&&c.push([["Scan folder for sub streams",function(){UI.findFolderSubstreams(t[a],function(a){$.extend(t,a);x.update(t)})},"folder"]]);c.push(d);c.push(e);t[a].online==1&&c.push($("<aside>").append(UI.modules.stream.thumbnail(a)));I.show(c,b);I.ele.find("[tabindex]").first().focus()};UI.sockets.ws.active_streams.subscribe(function(a,b){if(a=="stream"){var c=b[0],d=c.split("+")[0];if(d in mist.data.streams){if(d!=c&&!(c in t)){t[c]=$.extend({},
"function":function(){function a(c){var d=$.extend({},f);if(f.dynamic_capa){d.desc="Loading dynamic capabilities..";if(!("dynamic_capa_results"in f)||!(c in f.dynamic_capa_results)){N=c;if(W)return;W=setTimeout(function(){if(!("dynamic_capa_results"in f))f.dynamic_capa_results={};f.dynamic_capa_results[N]=null;mist.send(function(b){W=false;f.dynamic_capa_results[N]=b.capabilities;a(N)},{capabilities:N})},1E3)}else{delete d.desc;f.dynamic_capa_results[c]&&(d=f.dynamic_capa_results[c])}}Q.html($("<h3>").text(f.name+ mist.data.streams[d]);t[c].name=c;if(t[d].isfolderstream)t[c].source=t[c].source+c.replace(d+"+")}t[c].stats=b;x.update(t)}else c in t?t[c].stats=b:console.log("Received information about unknown stream",c,b)}});p=UI.pagecontrol(x,k);c.append(p);p.elements.pagelength.change(function(){mist.stored.set("streams_pagesize",$(this).val())});break;case "Edit":if("undefined"==typeof mist.data.capabilities){mist.send(function(){UI.navto(a,b)},{capabilities:!0});c.append("Loading..");return}v=!1;""!=b&&(v=
" Input options"));d=mist.convertBuildOptions(d,r);"always_match"in mist.data.capabilities.inputs[e]&&mist.inputMatch(mist.data.capabilities.inputs[e].always_match,c)&&d.push({label:"Always on",type:"checkbox",help:"Keep this input available at all times, even when there are no active viewers.",pointer:{main:r,index:"always_on"},value:b==""&&(e=="TSSRT"||e=="TSRIST")?true:false});Q.append(UI.buildUI(d));J.html("");if(f.enum_static_prefix&&c.slice(0,f.enum_static_prefix.length)==f.enum_static_prefix){var g= !0);v?(k=b.split("+")[0],r=mist.data.streams[k],c.html(UI.modules.stream.header(b,a,k)),k!=b&&c.append($("<div>").addClass("err_balloon").addClass("orange").css({position:"static",width:"54.65em",margin:"2em 0 3em"}).html("Note:<br>You are editing the settings of <b>"+k+"</b>, which is the parent of wildcard stream <b>"+b+"</b>. This will also affect other children of <b>"+k+"</b>."))):(c.html($("<h2>").text("New Stream")),r={});var k=[],g=$("<datalist>").attr("id","source_datalist"),N=$("<div>").addClass("source_info"),
function(){J.html($("<p>").text("Possible sources for "+f.name+": (click to set)"));var a=f.enumerated_sources[f.enum_static_prefix],b;for(b in a){var d=a[b].split(" ")[0];J.append($("<div>").attr("data-source",d).text(a[b]).click(function(){var a=$(this).attr("data-source");h.val(a).trigger("change")}).addClass(d==c?"active":""))}};if(!("enumerated_sources"in f)||!(f.enum_static_prefix in f.enumerated_sources)){if(!("enumerated_sources"in f))f.enumerated_sources={};f.enumerated_sources[f.enum_static_prefix]= Z=!1,S=!1;for(p in mist.data.capabilities.inputs)for(s in mist.data.capabilities.inputs[p].source_match)k.push(mist.data.capabilities.inputs[p].source_match[s]),g.append($("<option>").val(mist.data.capabilities.inputs[p].source_match[s]));var W=$("<div>"),la=function(a){var c={};if(!mist.data.streams)mist.data.streams={};mist.data.streams[r.name]=r;b!=r.name&&delete mist.data.streams[b];c.addstream={};c.addstream[r.name]=r;if(b!=r.name)c.deletestream=[b];if(r.stop_sessions&&b!=""){c.stop_sessions=
[];setTimeout(function(){delete f.enumerated_sources[f.enum_static_prefix]},1E4);mist.send(function(a){if(!("enumerated_sources"in f))f.enumerated_sources={};f.enumerated_sources[f.enum_static_prefix]=a.enumerate_sources;g()},{enumerate_sources:c})}else g()}}var d=$(this).val(),h=$(this);ka.remove();K.html("");if(d!=""){var g=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, b;delete r.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,r.source)){d=e;break}if(d){d=mist.data.capabilities.inputs[d];for(e in r)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,r.source)||delete r[e]}mist.send(function(){delete mist.data.streams[r.name].online;
d)){g=e;break}if(g===null){Q.html($("<h3>").text("Unrecognized input").addClass("red")).append($("<span>").text("Please edit the stream source.").addClass("red"));J.html("")}else{var f=mist.data.capabilities.inputs[g],g=J.find("div");if(g.length){g.removeClass("active");g.filter('[data-source="'+d+'"]').addClass("active")}if(f.name=="Folder")c.append(ka);else if(["Buffer","Buffer.exe","TS","TS.exe","TSSRT","TSSRT.exe"].indexOf(f.name)>-1){g=[$("<br>"),$("<span>").text("Configure your source to push to:")]; delete mist.data.streams[r.name].error;UI.navto(a,a=="Preview"?b.indexOf("+")<0?r.name:b:"")},c)},ma=$("<style>").text("button.saveandpreview { display: none; }"),O=$("<span>"),s=$("<div>"),aa={},d=[],na=$("<div>");for(p in mist.data.capabilities.processes)d.push([p,mist.data.capabilities.processes[p].hrn?mist.data.capabilities.processes[p].hrn:mist.data.capabilities.processes[p].name]);d.length&&(p=[{label:"New process",type:"select",select:d,value:d[0][0],pointer:{main:aa,index:"process"},"function":function(){var a=
switch(f.name){case "Buffer":case "Buffer.exe":g.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"});g.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"});g.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"}); $(this).getval();if(a!=null){var a=mist.data.capabilities.processes[a],b=[$("<h4>").text(a.name+" Process options")];na.html(UI.buildUI(b.concat(mist.convertBuildOptions(a,aa))))}}},na],s.append(UI.buildUI([$("<br>"),$("<h3>").text("Stream processes"),{label:"Stream processes",itemLabel:"stream process",type:"sublist",sublist:p,saveas:aa,pointer:{main:r,index:"processes"}}])));s=UI.buildUI([{label:"Stream name",type:"str",validate:["required","streamname"],pointer:{main:r,index:"name"},help:"Set the name this stream will be recognised by for players and/or stream pushing."},
g.push({label:"SRT",type:"span",clipboard:true,readonly:true,classes:["TSSRT"]});g.push({label:"RTSP",type:"span",clipboard:true,readonly:true,classes:["RTSP"]});break;case "TS":case "TS.exe":d.charAt(0)=="/"||d.slice(0,7)=="ts-exec"?g=[]:g.push({label:"TS",type:"span",clipboard:true,readonly:true,classes:["TS"]});break;case "TSSRT":case "TSSRT.exe":g.push({label:"SRT",type:"span",clipboard:true,readonly:true,classes:["TSSRT"]})}K.html(UI.buildUI(g));UI.updateLiveStreamHint(c.find("[name=name]").val(), {label:"Source",type:"browse",filetypes:k,pointer:{main:r,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>",
c.find("[name=source]").val(),K)}a(d)}}}},e,J,{label:"Stop sessions",type:"checkbox",help:"When saving these stream settings, kill this stream's current connections.",pointer:{main:r,index:"stop_sessions"}},K,$("<br>"),{type:"custom",custom:Q},j,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Streams")}},{type:"save",label:"Save","function":function(){ja("Streams")}},{type:"save",label:"Save and Preview","function":function(){ja("Preview")},classes:["saveandpreview"]}]}])); "function":function(){function a(c){var d=$.extend({},h);if(h.dynamic_capa){d.desc="Loading dynamic capabilities..";if(!("dynamic_capa_results"in h)||!(c in h.dynamic_capa_results)){S=c;if(Z)return;Z=setTimeout(function(){if(!("dynamic_capa_results"in h))h.dynamic_capa_results={};h.dynamic_capa_results[S]=null;mist.send(function(b){Z=false;h.dynamic_capa_results[S]=b.capabilities;a(S)},{capabilities:S})},1E3)}else{delete d.desc;h.dynamic_capa_results[c]&&(d=h.dynamic_capa_results[c])}}W.html($("<h3>").text(h.name+
c.find("[name=name]").keyup(function(){UI.updateLiveStreamHint($(this).val(),c.find("[name=source]").val(),K)});UI.updateLiveStreamHint(c.find("[name=name]").val(),c.find("[name=source]").val(),K);c.find('[name="source"]').attr("list","source_datalist");break;case "Status":if(""==b){UI.navto("Streams");return}-1==b.indexOf("+")&&$("<button>").text("Settings").addClass("settings").click(function(){UI.navto("Edit",b)});var y=$("<div>").addClass("dashboard");c.html(UI.modules.stream.bigbuttons(b,a)).append($("<h2>").text('Status of "'+ " Input options"));d=mist.convertBuildOptions(d,r);"always_match"in mist.data.capabilities.inputs[f]&&mist.inputMatch(mist.data.capabilities.inputs[f].always_match,c)&&d.push({label:"Always on",type:"checkbox",help:"Keep this input available at all times, even when there are no active viewers.",pointer:{main:r,index:"always_on"},value:b==""&&(f=="TSSRT"||f=="TSRIST")?true:false});W.append(UI.buildUI(d));N.html("");if(h.enum_static_prefix&&c.slice(0,h.enum_static_prefix.length)==h.enum_static_prefix){var g=
b+'"')).append(y);p=UI.modules.stream.findMist(function(){y.append(UI.modules.stream.status(b));y.append(UI.modules.stream.metadata(b));y.append($("<section>").addClass("logcont").append(UI.modules.stream.logs(b)).append(UI.modules.stream.accesslogs(b)));y.append(UI.modules.stream.processes(b));y.append(UI.modules.stream.triggers(b,"Status"));y.append(UI.modules.stream.pushes(b))});y.append(p);y.append(UI.modules.stream.actions("Status",b));break;case "Preview":if(""==b){UI.navto("Streams");return}var y= function(){N.html($("<p>").text("Possible sources for "+h.name+": (click to set)"));var a=h.enumerated_sources[h.enum_static_prefix],b;for(b in a){var d=a[b].split(" ")[0];N.append($("<div>").attr("data-source",d).text(a[b]).click(function(){var a=$(this).attr("data-source");e.val(a).trigger("change")}).addClass(d==c?"active":""))}};if(!("enumerated_sources"in h)||!(h.enum_static_prefix in h.enumerated_sources)){if(!("enumerated_sources"in h))h.enumerated_sources={};h.enumerated_sources[h.enum_static_prefix]=
$("<div>").addClass("dashboard"),ma=$("<div>");c.html(UI.modules.stream.bigbuttons(b,a)).append($("<h2>").text('Preview of "'+b+'"')).append(ma).append(y);p=UI.modules.stream.findMist(function(){if(typeof mistplayers=="undefined")throw"Player.js was not applied properly.";ma.replaceWith(UI.modules.stream.status(b,{tags:false,thumbnail:false}));window.mv={};$preview=UI.modules.stream.preview(b,window.mv);y.append($preview);y.append(UI.modules.stream.playercontrols(window.mv,$preview)).append(UI.modules.stream.logs(b)).append(UI.modules.stream.metadata(b))}); [];setTimeout(function(){delete h.enumerated_sources[h.enum_static_prefix]},1E4);mist.send(function(a){if(!("enumerated_sources"in h))h.enumerated_sources={};h.enumerated_sources[h.enum_static_prefix]=a.enumerate_sources;g()},{enumerate_sources:c})}else g()}}var d=$(this).val(),e=$(this);ma.remove();O.html("");if(d!=""){var g=null,f;for(f in mist.data.capabilities.inputs)if(typeof mist.data.capabilities.inputs[f].source_match!="undefined"&&mist.inputMatch(mist.data.capabilities.inputs[f].source_match,
y.append(p);break;case "Embed":if(""==b){UI.navto("Streams");return}c.html(UI.modules.stream.bigbuttons(b,a)).append($("<h2>").text('Embed "'+b+'"'));$("<span>");c.append(UI.modules.stream.findMist(function(a){c.append(UI.modules.stream.embedurls(b,a,this.getUrls()))},!1,!0));break;case "Push":var F=$("<div>").text("Loading..");c.append(F);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,g;for(g in c.push_list)if(a.indexOf(c.push_list[g][0])> d)){g=f;break}if(g===null){W.html($("<h3>").text("Unrecognized input").addClass("red")).append($("<span>").text("Please edit the stream source.").addClass("red"));N.html("")}else{var h=mist.data.capabilities.inputs[g],g=N.find("div");if(g.length){g.removeClass("active");g.filter('[data-source="'+d+'"]').addClass("active")}if(h.name=="Folder")b.indexOf("+")<0&&c.append(ma);else if(["Buffer","Buffer.exe","TS","TS.exe","TSSRT","TSSRT.exe"].indexOf(h.name)>-1){g=[$("<br>"),$("<span>").text("Configure your source to push to:")];
-1){d=false;break}}else d=true;if(d)for(g in a)h.find("tr[data-pushid="+a[g]+"]").remove();else b()},{push_list:1})},1E3)}function c(g,e){var f=$("<span>"),m=$("<span>");if(e=="Automatic"&&g.length>=4){var q=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) "+ switch(h.name){case "Buffer":case "Buffer.exe":g.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"});g.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"});g.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"});
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};f.append($("<span>").text(g[2]));g[3]&&f.append($("<span>").text(", schedule on "+(new Date(g[3]*1E3)).toLocaleString()));g.length>=5&&g[4]&&f.append($("<span>").text(", complete on "+(new Date(g[4]*1E3)).toLocaleString()));g.length>=8&&g[5]&&f.append($("<span>").text(", starts if "+q(g[5], g.push({label:"SRT",type:"span",clipboard:true,readonly:true,classes:["TSSRT"]});g.push({label:"RTSP",type:"span",clipboard:true,readonly:true,classes:["RTSP"]});break;case "TS":case "TS.exe":d.charAt(0)=="/"||d.slice(0,7)=="ts-exec"?g=[]:g.push({label:"TS",type:"span",clipboard:true,readonly:true,classes:["TS"]});break;case "TSSRT":case "TSSRT.exe":g.push({label:"SRT",type:"span",clipboard:true,readonly:true,classes:["TSSRT"]})}O.html(UI.buildUI(g));UI.updateLiveStreamHint(c.find("[name=name]").val(),
g[6],g[7])));g.length>=11&&g[8]&&f.append($("<span>").text(", stops if "+q(g[8],g[9],g[10])))}else g.length>=4&&g[2]!=g[3]?f.append($("<span>").text(g[2])).append($("<span>").html("&#187").addClass("unit").css("margin","0 0.5em")).append($("<span>").text(g[3])):f.append($("<span>").text(g[2]));q=$("<td>").append($("<button>").text(e=="Automatic"?"Remove":"Stop").click(function(){if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+g[1]+" to "+g[2])){var a=$(this).closest("tr"); c.find("[name=source]").val(),O)}a(d)}}}},g,N,{label:"Stop sessions",type:"checkbox",help:"When saving these stream settings, kill this stream's current connections.",pointer:{main:r,index:"stop_sessions"}},O,$("<br>"),{type:"custom",custom:W},s,{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){UI.navto("Streams")}},{type:"save",label:"Save","function":function(){la("Streams")}},{type:"save",label:"Save and Preview","function":function(){la("Preview")},classes:["saveandpreview"]}]}]);
a.html($("<td colspan=99>").html($("<span>").addClass("red").text(e=="Automatic"?"Removing..":"Stopping..")));if(e=="Automatic"){var c=g.slice(1);mist.send(function(){a.remove()},{push_auto_remove:[c]})}else mist.send(function(){b([g[0]])},{push_stop:[g[0]]})}}));if(e=="Automatic"){q.prepend($("<button>").text("Edit").click(function(){UI.navto("Start Push","auto_"+($(this).closest("tr").index()-1))}));q.append($("<button>").text("Stop pushes").click(function(){if(confirm('Are you sure you want to stop all pushes matching \n"'+ c.append(s);s.change(function(){var a=c.find(".header");a.length&&a.attr("data-changed","yes")});c.find("[name=name]").keyup(function(){UI.updateLiveStreamHint($(this).val(),c.find("[name=source]").val(),O)});UI.updateLiveStreamHint(c.find("[name=name]").val(),c.find("[name=source]").val(),O);c.find('[name="source"]').attr("list","source_datalist");break;case "Status":if(""==b){UI.navto("Streams");return}var A=$("<div>").addClass("dashboard");c.html(UI.modules.stream.header(b,a)).append(A);p=UI.modules.stream.findMist(function(){A.append(UI.modules.stream.status(b,
g[1]+" to "+g[2]+'"?'+(d.wait!=0?"\n\nRetrying is enabled. That means the push will just restart. You'll probably want to set that to 0.":""))){var c=$(this);c.text("Stopping pushes..");var e=[],f;for(f in a.push_list)if(g[1]==a.push_list[f][1]&&g[2]==a.push_list[f][2]){e.push(a.push_list[f][0]);h.find("tr[data-pushid="+a.push_list[f][0]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}mist.send(function(){c.text("Stop pushes");b(e)},{push_stop:e})}}))}else{if(g.length>= {status:false,stats:false}));A.append(UI.modules.stream.metadata(b));A.append($("<section>").addClass("logcont").append(UI.modules.stream.logs(b)).append(UI.modules.stream.accesslogs(b)));A.append(UI.modules.stream.processes(b));A.append(UI.modules.stream.triggers(b,"Status"));A.append(UI.modules.stream.pushes(b))});A.append(p);A.append(UI.modules.stream.actions("Status",b));break;case "Preview":if(""==b){UI.navto("Streams");return}var A=$("<div>").addClass("dashboard"),oa=$("<div>").text("Loading..");
6){var j=g[5];m.append($("<div>").append("Active for: "+UI.format.duration(j.active_seconds))).append($("<div>").append("Data transferred: "+UI.format.bytes(j.bytes))).append($("<div>").append("Media time transferred: "+UI.format.duration(j.mediatime*0.001)));"pkt_retrans_count"in j&&m.append($("<div>").append("Packets retransmitted: "+UI.format.number(j.pkt_retrans_count||0)));"pkt_loss_count"in j&&m.append($("<div>").append("Packets lost: "+UI.format.number(j.pkt_loss_count||0)+" ("+UI.format.addUnit(UI.format.number(j.pkt_loss_perc|| c.html(UI.modules.stream.header(b,a)).append(oa).append(A);p=UI.modules.stream.findMist(function(){if(typeof mistplayers=="undefined")throw"Player.js was not applied properly.";oa.replaceWith(UI.modules.stream.status(b,{tags:false,thumbnail:false,status:false,stats:false}));window.mv={};$preview=UI.modules.stream.preview(b,window.mv);A.append($preview);A.append(UI.modules.stream.playercontrols(window.mv,$preview)).append(UI.modules.stream.logs(b)).append(UI.modules.stream.metadata(b))});A.append(p);
0),"%")+" over the last "+UI.format.addUnit(5,"s")+")"))}if(g.length>=5)for(var k in g[4]){j=g[4][k];m.append($("<div>").append(UI.format.time(j[0])+" ["+j[1]+"] "+j[2]))}}return $("<tr>").css("vertical-align","top").attr("data-pushid",g[0]).append($("<td>").text(g[1])).append($("<td>").append(f.children())).append($("<td>").addClass("logs").append(m.children())).append(q)}F.html(UI.buildUI([{type:"help",help:"You can push streams to files or other servers, allowing them to broadcast your stream as well."}])); break;case "Embed":if(""==b){UI.navto("Streams");return}c.html(UI.modules.stream.header(b,a));$("<span>");c.append(UI.modules.stream.findMist(function(a){c.append(UI.modules.stream.embedurls(b,a,this.getUrls()))},!1,!0));break;case "Push":var K=$("<div>").text("Loading..");c.append(K);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,g;for(g in c.push_list)if(a.indexOf(c.push_list[g][0])>-1){d=
var d=a.push_settings;d||(d={});var h=$("<table>").append($("<tr>").append($("<th>").text("Stream")).append($("<th>").text("Target")).append($("<th>")).append($("<th>"))),g=h.clone();if("push_list"in a)for(var e in a.push_list)h.append(c(a.push_list[e],"Manual"));if("push_auto_list"in a)for(e in a.push_auto_list){var f=a.push_auto_list[e].slice();f.unshift(-1);g.append(c(f,"Automatic"))}F.append($("<h3>").text("Automatic push settings")).append(UI.buildUI([{label:"Delay before retry",unit:"s",type:"int", false;break}}else d=true;if(d)for(g in a)e.find("tr[data-pushid="+a[g]+"]").remove();else b()},{push_list:1})},1E3)}function c(g,h){var f=$("<span>"),m=$("<span>");if(h=="Automatic"&&g.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};f.append($("<span>").text(g[2]));g[3]&&f.append($("<span>").text(", schedule on "+(new Date(g[3]*1E3)).toLocaleString()));g.length>=5&&g[4]&&f.append($("<span>").text(", complete on "+(new Date(g[4]*1E3)).toLocaleString()));g.length>=8&&g[5]&&f.append($("<span>").text(", starts if "+k(g[5],
g[6],g[7])));g.length>=11&&g[8]&&f.append($("<span>").text(", stops if "+k(g[8],g[9],g[10])))}else g.length>=4&&g[2]!=g[3]?f.append($("<span>").text(g[2])).append($("<span>").html("&#187").addClass("unit").css("margin","0 0.5em")).append($("<span>").text(g[3])):f.append($("<span>").text(g[2]));k=$("<td>").append($("<button>").text(h=="Automatic"?"Remove":"Stop").click(function(){if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+g[1]+" to "+g[2])){var a=$(this).closest("tr");
a.html($("<td colspan=99>").html($("<span>").addClass("red").text(h=="Automatic"?"Removing..":"Stopping..")));if(h=="Automatic"){var c=g.slice(1);mist.send(function(){a.remove()},{push_auto_remove:[c]})}else mist.send(function(){b([g[0]])},{push_stop:[g[0]]})}}));if(h=="Automatic"){k.prepend($("<button>").text("Edit").click(function(){UI.navto("Start Push","auto_"+($(this).closest("tr").index()-1))}));k.append($("<button>").text("Stop pushes").click(function(){if(confirm('Are you sure you want to stop all pushes matching \n"'+
g[1]+" to "+g[2]+'"?'+(d.wait!=0?"\n\nRetrying is enabled. That means the push will just restart. You'll probably want to set that to 0.":""))){var c=$(this);c.text("Stopping pushes..");var h=[],f;for(f in a.push_list)if(g[1]==a.push_list[f][1]&&g[2]==a.push_list[f][2]){h.push(a.push_list[f][0]);e.find("tr[data-pushid="+a.push_list[f][0]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}mist.send(function(){c.text("Stop pushes");b(h)},{push_stop:h})}}))}else{if(g.length>=
6){var q=g[5];m.append($("<div>").append("Active for: "+UI.format.duration(q.active_seconds))).append($("<div>").append("Data transferred: "+UI.format.bytes(q.bytes))).append($("<div>").append("Media time transferred: "+UI.format.duration(q.mediatime*0.001)));"pkt_retrans_count"in q&&m.append($("<div>").append("Packets retransmitted: "+UI.format.number(q.pkt_retrans_count||0)));"pkt_loss_count"in q&&m.append($("<div>").append("Packets lost: "+UI.format.number(q.pkt_loss_count||0)+" ("+UI.format.addUnit(UI.format.number(q.pkt_loss_perc||
0),"%")+" over the last "+UI.format.addUnit(5,"s")+")"))}if(g.length>=5)for(var i in g[4]){q=g[4][i];m.append($("<div>").append(UI.format.time(q[0])+" ["+q[1]+"] "+q[2]))}}return $("<tr>").css("vertical-align","top").attr("data-pushid",g[0]).append($("<td>").text(g[1])).append($("<td>").append(f.children())).append($("<td>").addClass("logs").append(m.children())).append(k)}K.html(UI.buildUI([{type:"help",help:"You can push streams to files or other servers, allowing them to broadcast your stream as well."}]));
var d=a.push_settings;d||(d={});var e=$("<table>").append($("<tr>").append($("<th>").text("Stream")).append($("<th>").text("Target")).append($("<th>")).append($("<th>"))),g=e.clone();if("push_list"in a)for(var h in a.push_list)e.append(c(a.push_list[h],"Manual"));if("push_auto_list"in a)for(h in a.push_auto_list){var f=a.push_auto_list[h].slice();f.unshift(-1);g.append(c(f,"Automatic"))}K.append($("<h3>").text("Automatic push settings")).append(UI.buildUI([{label:"Delay before retry",unit:"s",type:"int",
min:0,help:"How long the delay should be before MistServer retries an automatic push.<br>If set to 0, it does not retry.","default":3,pointer:{main:d,index:"wait"}},{label:"Maximum retries",unit:"/s",type:"int",min:0,help:"The maximum amount of retries per second (for all automatic pushes).<br>If set to 0, there is no limit.","default":0,pointer:{main:d,index:"maxspeed"}},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){mist.send(function(){UI.navto("Push")},{push_settings:d})}}]}])).append($("<h3>").text("Automatic push settings")).append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push", min:0,help:"How long the delay should be before MistServer retries an automatic push.<br>If set to 0, it does not retry.","default":3,pointer:{main:d,index:"wait"}},{label:"Maximum retries",unit:"/s",type:"int",min:0,help:"The maximum amount of retries per second (for all automatic pushes).<br>If set to 0, there is no limit.","default":0,pointer:{main:d,index:"maxspeed"}},{type:"buttons",buttons:[{type:"save",label:"Save","function":function(){mist.send(function(){UI.navto("Push")},{push_settings:d})}}]}])).append($("<h3>").text("Automatic push settings")).append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push",
"auto")}));g.find("tr").length==1?F.append($("<div>").text("No automatic pushes have been configured.").addClass("text").css("margin-top","0.5em")):F.append(g);F.append($("<h3>").text("Pushes")).append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));if(h.find("tr").length==1)F.append($("<div>").text("No pushes are active.").addClass("text").css("margin-top","0.5em"));else{var g=[],f=[],m=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any stream").val("")), "auto")}));g.find("tr").length==1?K.append($("<div>").text("No automatic pushes have been configured.").addClass("text").css("margin-top","0.5em")):K.append(g);K.append($("<h3>").text("Pushes")).append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));if(e.find("tr").length==1)K.append($("<div>").text("No pushes are active.").addClass("text").css("margin-top","0.5em"));else{var g=[],f=[],m=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any stream").val("")),
q=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any target").val(""));for(e in a.push_list){g.indexOf(a.push_list[e][1])==-1&&g.push(a.push_list[e][1]);f.indexOf(a.push_list[e][2])==-1&&f.push(a.push_list[e][2])}g.sort();f.sort();for(e in g)m.append($("<option>").text(g[e]));for(e in f)q.append($("<option>").text(f[e]));F.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)}, k=$("<select>").css("margin-left","0.5em").append($("<option>").text("Any target").val(""));for(h in a.push_list){g.indexOf(a.push_list[h][1])==-1&&g.push(a.push_list[h][1]);f.indexOf(a.push_list[h][2])==-1&&f.push(a.push_list[h][2])}g.sort();f.sort();for(h in g)m.append($("<option>").text(g[h]));for(h in f)k.append($("<option>").text(f[h]));K.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});h.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(m).append($("<span>").css("margin-left","0.5em").text("and").css("font-size","0.9em")).append(q).append($("<button>").css("margin-left","0.5em").text("Apply").click(function(){var c=m.val(),d=q.val();if(c==""&&d=="")return alert("Looks like you want to stop all pushes. Maybe you should use that button?"); {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(m).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=m.val(),d=k.val();if(c==""&&d=="")return alert("Looks like you want to stop all pushes. Maybe you should use that button?");
var g={},e;for(e in a.push_list)if((c==""||a.push_list[e][1]==c)&&(d==""||a.push_list[e][2]==d))g[a.push_list[e][0]]=a.push_list[e];if(Object.keys(g).length==0)return alert("No matching pushes.");c="Are you sure you want to stop these pushes?\n\n";for(e in g)c=c+(g[e][1]+" to "+g[e][2]+"\n");if(confirm(c)){g=Object.keys(g);mist.send(function(){b(g)},{push_stop:g});for(e in g)h.find("tr[data-pushid="+g[e]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}}))).append(h)}UI.interval.set(function(){mist.send(function(a){var b= var g={},h;for(h in a.push_list)if((c==""||a.push_list[h][1]==c)&&(d==""||a.push_list[h][2]==d))g[a.push_list[h][0]]=a.push_list[h];if(Object.keys(g).length==0)return alert("No matching pushes.");c="Are you sure you want to stop these pushes?\n\n";for(h in g)c=c+(g[h][1]+" to "+g[h][2]+"\n");if(confirm(c)){g=Object.keys(g);mist.send(function(){b(g)},{push_stop:g});for(h in g)e.find("tr[data-pushid="+g[h]+"]").html($("<td colspan=99>").html($("<span>").addClass("red").text("Stopping..")))}}))).append(e)}UI.interval.set(function(){mist.send(function(a){var b=
h.find("tr").first();h.empty();h.append(b);for(var d in a.push_list)h.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 MistServer capabilities..");mist.send(function(){UI.showTab("Start Push",b,d)},{capabilities:!0,variable_list:!0,external_writer_list:!0});return}var w,R=function(g){var h=false,e=b.split("_"); 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 MistServer capabilities..");mist.send(function(){UI.showTab("Start Push",b,e)},{capabilities:!0,variable_list:!0,external_writer_list:!0});return}var y,X=function(d){var g=false,h=b.split("_");
b=e[0];e.length==2&&(h=e[1]);if(h!==false&&typeof g=="undefined")mist.send(function(a){R(a.push_auto_list[h])},{push_auto_list:1});else{var f=[],m=[],q={},j=[],k;for(k in mist.data.capabilities.connectors){e=mist.data.capabilities.connectors[k];if("push_urls"in e){q[k]=e.push_urls;for(var l in e.push_urls)e.push_urls[l][0]=="/"?f.push(e.push_urls[l]):m.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>= b=h[0];h.length==2&&(g=h[1]);if(g!==false&&typeof d=="undefined")mist.send(function(a){X(a.push_auto_list[g])},{push_auto_list:1});else{var f=[],m=[],k={},q=[],i;for(i in mist.data.capabilities.connectors){h=mist.data.capabilities.connectors[i];if("push_urls"in h){k[i]=h.push_urls;for(var j in h.push_urls)h.push_urls[j][0]=="/"?f.push(h.push_urls[j]):m.push(h.push_urls[j])}}if(mist.data.external_writer_list)for(i in mist.data.external_writer_list){h=mist.data.external_writer_list[i];if(h.length>=
3)for(l in e[2])j.push(e[2][l]+"://")}f.sort();m.sort();b=="auto"&&c.find("h2").text("Add automatic push");var i={params:{}},n=[];if(b=="auto"&&typeof g!="undefined"){i={stream:g[0],target:g[1],params:{}};l=i.target.split("?");if(l.length>1){n=l.pop();i.target=l.join("?");n=n.split("&");for(k in n){l=n[k].split("=");i.params[l.shift()]=l.join("=")}}if(g.length>=3)i.scheduletime=g[2]!=0?g[2]:null;if(g.length>=4)i.completetime=g[3]!=0?g[3]:null;if(g.length>=5)i.startVariableName=g[4]!=""?g[4]:null; 3)for(j in h[2])q.push(h[2][j]+"://")}f.sort();m.sort();b=="auto"&&c.find("h2").text("Add automatic push");var l={params:{}},n=[];if(b=="auto"&&typeof d!="undefined"){l={stream:d[0],target:d[1],params:{}};j=l.target.split("?");if(j.length>1){n=j.pop();l.target=j.join("?");n=n.split("&");for(i in n){j=n[i].split("=");l.params[j.shift()]=j.join("=")}}if(d.length>=3)l.scheduletime=d[2]!=0?d[2]:null;if(d.length>=4)l.completetime=d[3]!=0?d[3]:null;if(d.length>=5)l.startVariableName=d[4]!=""?d[4]:null;
if(g.length>=6)i.startVariableOperator=g[5]!=""?g[5]:null;if(g.length>=7)i.startVariableValue=g[6]!=""?g[6]:null;if(g.length>=8)i.endVariableName=g[7]!=""?g[7]:null;if(g.length>=9)i.endVariableOperator=g[8]!=""?g[8]:null;if(g.length>=10)i.endVariableValue=g[9]!=""?g[9]:null}var o=$("<div>").css("margin","1em 0"),p=$("<div>"),r,x;if(b=="auto"){p.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.", if(d.length>=6)l.startVariableOperator=d[5]!=""?d[5]:null;if(d.length>=7)l.startVariableValue=d[6]!=""?d[6]:null;if(d.length>=8)l.endVariableName=d[7]!=""?d[7]:null;if(d.length>=9)l.endVariableOperator=d[8]!=""?d[8]:null;if(d.length>=10)l.endVariableValue=d[9]!=""?d[9]:null}var o=$("<div>").css("margin","1em 0"),p=$("<div>"),s,r;if(b=="auto"){p.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:i.startVariableName||i.endVariableName?"variable":"time",classes:["activewhen"],"function":function(){var a=p.find(".varbased").closest(".UIelement"),b=p.find(".timebased").closest(".UIelement");if($(this).getval()=="time"){a.hide();b.css("display","")}else{b.hide();a.css("display","");p.find('[name="startVariableOperator"]').trigger("change");p.find('[name="endVariableOperator"]').trigger("change")}}}, type:"select",select:[["time","Based on server time"],["variable","Based on a variable"]],value:l.startVariableName||l.endVariableName?"variable":"time",classes:["activewhen"],"function":function(){var a=p.find(".varbased").closest(".UIelement"),b=p.find(".timebased").closest(".UIelement");if($(this).getval()=="time"){a.hide();b.css("display","")}else{b.hide();a.css("display","");p.find('[name="startVariableOperator"]').trigger("change");p.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:i,index:"startVariableName"}},{classes:["varbased"],label:"Comparison operator",type:"select",select:[[0,"is true"],[1,"is false"],[2,"=="],[3,"!="],[10,"> (numerical)"],[11,">= (numerical)"], $("<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:l,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:i,index:"startVariableOperator"},"function":function(){var a=p.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:l,index:"startVariableOperator"},"function":function(){var a=p.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:i,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)", 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:l,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:i,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:i,index:"endVariableOperator"},"function":function(){var a= prefix:"$",datalist:Object.keys(mist.data.variable_list||[]),pointer:{main:l,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:l,index:"endVariableOperator"},"function":function(){var a=
p.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:i, p.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:l,
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:i,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:i,index:"completetime"}}],i));p.find(".activewhen").trigger("change")}k=[{label:"Stream name",type:"str", 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:l,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:l,index:"completetime"}}],l));p.find(".activewhen").trigger("change")}i=[{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:i,index:"stream"}, 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:l,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:w,value:d[1]!=""?d[1]:""},{label:"Target",type:"str",help:"Where the stream will be pushed to.<br> Valid push formats: <ul> <li>"+m.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+"</li> </ul> "+ 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,value:e[1]!=""?e[1]:""},{label:"Target",type:"str",help:"Where the stream will be pushed to.<br> Valid push formats: <ul> <li>"+m.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+"</li> </ul> "+
(j.length?"Additionally, the following protocols (from generic writers) may be used in combination with any of the above file formats:<ul><li>"+j.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>", (q.length?"Additionally, the following protocols (from generic writers) may be used in combination with any of the above file formats:<ul><li>"+q.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:i,index:"target"},validate:["required",function(a){for(var b in m)if(mist.inputMatch(m[b],a))return false;for(b in f){if(mist.inputMatch(f[b],a))return false;for(var c in j)if(mist.inputMatch(j[c]+f[b].slice(1),a))return false}return{msg:"Does not match a valid target.<br>Valid push formats: <ul> <li>"+m.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+ pointer:{main:l,index:"target"},validate:["required",function(a){for(var b in m)if(mist.inputMatch(m[b],a))return false;for(b in f){if(mist.inputMatch(f[b],a))return false;for(var c in q)if(mist.inputMatch(q[c]+f[b].slice(1),a))return false}return{msg:"Does not match a valid target.<br>Valid push formats: <ul> <li>"+m.join("</li><li>")+"</li> </ul> Valid file formats: <ul> <li>"+f.join("</li><li>")+
"</li> </ul> "+(j.length?"Additionally, the following protocols may be used in combination with any of the above file formats:<ul><li>"+j.join("</li><li>")+"</li></ul>":""),classes:["red"]}}],"function":function(){function a(b,d){if(b.prot_only&&String().match&&c.match(/.+\:\/\/.+/)===null)delete r[d];else if(b.file_only&&c[0]!="/")delete r[d];else if(b.type=="group")for(var g in b.options)a(b.options[g],g);else x[d]=b}var b=false,c=$(this).getval();for(connector in q)for(var d in q[connector]){if(mist.inputMatch(q[connector][d], "</li> </ul> "+(q.length?"Additionally, the following protocols may be used in combination with any of the above file formats:<ul><li>"+q.join("</li><li>")+"</li></ul>":""),classes:["red"]}}],"function":function(){function a(b,d){if(b.prot_only&&String().match&&c.match(/.+\:\/\/.+/)===null)delete s[d];else if(b.file_only&&c[0]!="/")delete s[d];else if(b.type=="group")for(var e in b.options)a(b.options[e],e);else r[d]=b}var b=false,c=$(this).getval();for(connector in k)for(var d in k[connector]){if(mist.inputMatch(k[connector][d],
c)){b=connector;break}if(q[connector][d][0]=="/")for(var g in j)if(mist.inputMatch(j[g]+q[connector][d].slice(1),c)){b=connector;break}}if(b){if(!("friendly"in mist.data.capabilities.connectors[b]))mist.data.capabilities.connectors[b].friendly=mist.data.capabilities.connectors[b].name;o.html($("<h3>").text(mist.data.capabilities.connectors[b].friendly.replace("over HTTP","")));r=$.extend({},mist.data.capabilities.connectors[b].push_parameters);x={};for(d in mist.data.capabilities.connectors[b].push_parameters)a(mist.data.capabilities.connectors[b].push_parameters[d], c)){b=connector;break}if(k[connector][d][0]=="/")for(var e in q)if(mist.inputMatch(q[e]+k[connector][d].slice(1),c)){b=connector;break}}if(b){if(!("friendly"in mist.data.capabilities.connectors[b]))mist.data.capabilities.connectors[b].friendly=mist.data.capabilities.connectors[b].name;o.html($("<h3>").text(mist.data.capabilities.connectors[b].friendly.replace("over HTTP","")));s=$.extend({},mist.data.capabilities.connectors[b].push_parameters);r={};for(d in mist.data.capabilities.connectors[b].push_parameters)a(mist.data.capabilities.connectors[b].push_parameters[d],
d);b={desc:mist.data.capabilities.connectors[b].desc.replace("over HTTP",""),optional:r,sort:"sort"};b=mist.convertBuildOptions(b,i.params);g=[];for(d in n){var h=n[d].split("="),e=h[0];e in r||g.push(e+(h.length>1?"="+h.slice(1).join("="):""))}b.push($("<br>"));b.push({type:"inputlist",label:"Custom url parameters",value:g,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:i, d);b={desc:mist.data.capabilities.connectors[b].desc.replace("over HTTP",""),optional:s,sort:"sort"};b=mist.convertBuildOptions(b,l.params);e=[];for(d in n){var g=n[d].split("="),h=g[0];h in s||e.push(h+(g.length>1?"="+g.slice(1).join("="):""))}b.push($("<br>"));b.push({type:"inputlist",label:"Custom url parameters",value:e,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:l,
index:"custom_url_params"}});o.append(UI.buildUI(b))}else o.html($("<h4>").addClass("red").text("Unrecognized target.")).append($("<span>").text("Please edit the push target."))}},p,o];k.push({type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){d[0]&&d[0]!=a?UI.navto(d[0],d[1]):UI.navto("Push")}},{type:"save",label:"Save",preSave:function(){delete i.startVariableName;delete i.startVariableOperator;delete i.startVariableValue;delete i.endVariableName;delete i.endVariableOperator; index:"custom_url_params"}});o.append(UI.buildUI(b))}else o.html($("<h4>").addClass("red").text("Unrecognized target.")).append($("<span>").text("Please edit the push target."))}},p,o];i.push({type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){e[0]&&e[0]!=a?UI.navto(e[0],e[1]):UI.navto("Push")}},{type:"save",label:"Save",preSave:function(){delete l.startVariableName;delete l.startVariableOperator;delete l.startVariableValue;delete l.endVariableName;delete l.endVariableOperator;
delete i.endVariableValue;delete i.completetime;delete i.scheduletime},"function":function(){var c=i.params,h;for(h in c)c[h]===null?delete c[h]:h in x||delete c[h];if(i.startVariableName||i.endVariableName){i.scheduletime=0;i.completetime=0}if(i.startVariableName===null){delete i.startVariableName;delete i.startVariableOperator;delete i.startVariableValue}if(i.endVariableName===null){delete i.endVariableName;delete i.endVariableOperator;delete i.endVariableValue}if(i.scheduletime)c.recstartunix= delete l.endVariableValue;delete l.completetime;delete l.scheduletime},"function":function(){var c=l.params,g;for(g in c)c[g]===null?delete c[g]:g in r||delete c[g];if(l.startVariableName||l.endVariableName){l.scheduletime=0;l.completetime=0}if(l.startVariableName===null){delete l.startVariableName;delete l.startVariableOperator;delete l.startVariableValue}if(l.endVariableName===null){delete l.endVariableName;delete l.endVariableOperator;delete l.endVariableValue}if(l.scheduletime)c.recstartunix=
i.scheduletime;if(Object.keys(c).length||i.custom_url_params&&i.custom_url_params.length){var e="?",f=i.target.split("?");if(f.length>1){e="&";f=f[f.length-1];f=f.split("&");for(h in f){var m=f[h].split("=")[0];m in c&&delete c[m]}}if(Object.keys(c).length||i.custom_url_params&&i.custom_url_params.length){f=[];for(h in c)f.push(h+"="+c[h]);for(h in i.custom_url_params)f.push(i.custom_url_params[h]);e=e+f.join("&");i.target=i.target+e}}delete i.params;delete i.custom_url_params;c={};c[b=="auto"?"push_auto_add": l.scheduletime;if(Object.keys(c).length||l.custom_url_params&&l.custom_url_params.length){var h="?",f=l.target.split("?");if(f.length>1){h="&";f=f[f.length-1];f=f.split("&");for(g in f){var m=f[g].split("=")[0];m in c&&delete c[m]}}if(Object.keys(c).length||l.custom_url_params&&l.custom_url_params.length){f=[];for(g in c)f.push(g+"="+c[g]);for(g in l.custom_url_params)f.push(l.custom_url_params[g]);h=h+f.join("&");l.target=l.target+h}}delete l.params;delete l.custom_url_params;c={};c[b=="auto"?"push_auto_add":
"push_start"]=i;if(typeof g!="undefined"&&(g[0]!=i.stream||g[1]!=i.target))c.push_auto_remove=[g];mist.send(function(){d[0]&&d[0]!=a?UI.navto(d[0],d[1]):UI.navto("Push")},c)}}]});c.append(UI.buildUI(k))}};mist.data.LTS?mist.send(function(a){(w=a.active_streams)||(w=[]);var a=[],b;for(b in w)w[b].indexOf("+")!=-1&&a.push(w[b].replace(/\+.*/,"")+"+");w=w.concat(a);var c=0,d=0;for(b in mist.data.streams){w.push(b);if(mist.inputMatch(UI.findInput("Folder").source_match,mist.data.streams[b].source)){w.push(b+ "push_start"]=l;if(typeof d!="undefined"&&(d[0]!=l.stream||d[1]!=l.target))c.push_auto_remove=[d];mist.send(function(){e[0]&&e[0]!=a?UI.navto(e[0],e[1]):UI.navto("Push")},c)}}]});c.append(UI.buildUI(i))}};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 g=b.stream,h;for(h in a.browse.files)for(var e in mist.data.capabilities.inputs)e.indexOf("Buffer")>=0||(e.indexOf("Folder")>=0||e.indexOf("Buffer.exe")>=0||e.indexOf("Folder.exe")>=0)||mist.inputMatch(mist.data.capabilities.inputs[e].source_match,"/"+a.browse.files[h])&&w.push(g+"+"+a.browse.files[h]);d++;if(c==d){w=w.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();R()}},{browse:mist.data.streams[b].source},{stream:b});c++}}if(c==d){w=w.filter(function(a, "+");mist.send(function(a,b){var e=b.stream,g;for(g in a.browse.files)for(var h in mist.data.capabilities.inputs)h.indexOf("Buffer")>=0||(h.indexOf("Folder")>=0||h.indexOf("Buffer.exe")>=0||h.indexOf("Folder.exe")>=0)||mist.inputMatch(mist.data.capabilities.inputs[h].source_match,"/"+a.browse.files[g])&&y.push(e+"+"+a.browse.files[g]);d++;if(c==d){y=y.filter(function(a,b,c){return c.lastIndexOf(a)===b}).sort();X()}},{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();R()}},{active_streams:1}):(w=Object.keys(mist.data.streams),R());break;case "Triggers":if(!("triggers"in mist.data.config)||!mist.data.config.triggers)mist.data.config.triggers={};A=$("<tbody>");h=$("<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(A); b,c){return c.lastIndexOf(a)===b}).sort();X()}},{active_streams:1}):(y=Object.keys(mist.data.streams),X());break;case "Triggers":if(!("triggers"in mist.data.config)||!mist.data.config.triggers)mist.data.config.triggers={};C=$("<tbody>");E=$("<table>").html($("<thead>").addClass("sticky").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",
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(h);h.stupidtable();h=mist.data.config.triggers;for(p in h)for(j in h[p])e=triggerRewrite(h[p][j]), "string")).append($("<th>")))).append(C);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(E);E.stupidtable();k=mist.data.config.triggers;
A.append($("<tr>").attr("data-index",p+","+j).append($("<td>").text(p)).append($("<td>").text("streams"in e?e.streams.join(", "):"")).append($("<td>").text(e.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], for(p in k)for(s in k[p])g=triggerRewrite(k[p][s]),C.append($("<tr>").attr("data-index",p+","+s).append($("<td>").text(p)).append($("<td>").text("streams"in g?g.streams.join(", "):"")).append($("<td>").text(g.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 "+
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.showTab(a,b,d)},{capabilities:!0});c.append("Loading..");return}b?(b=b.split(","),j=triggerRewrite(mist.data.config.triggers[b[0]][b[1]]),r={triggeron:b[0], 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.showTab(a,b,e)},{capabilities:!0});c.append("Loading..");return}b?(b=b.split(","),k=triggerRewrite(mist.data.config.triggers[b[0]][b[1]]),
appliesto:j.streams,url:j.handler,async:j.sync,"default":j["default"],params:j.params}):(c.html($("<h2>").text("New Trigger")),r={});j=[];for(p in mist.data.capabilities.triggers)j.push([p,p+": "+mist.data.capabilities.triggers[p].when]);var Y=$("<div>").addClass("desc"),na=$("<div>");c.append(UI.buildUI([{label:"Trigger on",pointer:{main:r,index:"triggeron"},help:"For what event this trigger should activate.",type:"select",select:j,validate:["required"],"function":function(){var a=$(this).getval(), r={triggeron:b[0],appliesto:k.streams,url:k.handler,async:k.sync,"default":k["default"],params:k.params}):(c.html($("<h2>").text("New Trigger")),r={});k=[];for(p in mist.data.capabilities.triggers)k.push([p,p+": "+mist.data.capabilities.triggers[p].when]);var ba=$("<div>").addClass("desc"),pa=$("<div>");c.append(UI.buildUI([{label:"Trigger on",pointer:{main:r,index:"triggeron"},help:"For what event this trigger should activate.",type:"select",select:k,validate:["required"],"function":function(){var a=
b=mist.data.capabilities.triggers[a];Y.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."; $(this).getval(),b=mist.data.capabilities.triggers[a];ba.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",
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"});Y.append(UI.buildUI(a));b.stream_specific?$("[name=appliesto]").closest(".UIelement").show(): 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"});
$("[name=appliesto]").setval([]).closest(".UIelement").hide();if(b.argument){$("[name=params]").closest(".UIelement").show();na.text(b.argument)}else $("[name=params]").setval("").closest(".UIelement").hide()}}},Y,$("<h4>").text("Trigger settings"),{label:"Applies to",pointer:{main:r,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), ba.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();pa.text(b.argument)}else $("[name=params]").setval("").closest(".UIelement").hide()}}},ba,$("<h4>").text("Trigger settings"),{label:"Applies to",pointer:{main:r,index:"appliesto"},help:"For triggers that can apply to specific streams, this value decides what streams they are triggered for. (none checked = always triggered)",
value:""!=d[1]?[d[1]]:[]},$("<br>"),{label:"Handler (URL or executable)",help:"This can be either an HTTP URL or a full path to an executable.",pointer:{main:r,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:r,index:"async"}}, type:"checklist",checklist:Object.keys(mist.data.streams),value:""!=e[1]?[e[1]]:[]},$("<br>"),{label:"Handler (URL or executable)",help:"This can be either an HTTP URL or a full path to an executable.",pointer:{main:r,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.",
{label:"Parameters",type:"str",help:$("<div>").text("The extra data you want this trigger to use.").append(na),pointer:{main:r,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:r,index:"default"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){d[0]&&d[0]!=a?UI.navto(d[0],d[1]):UI.navto("Triggers")}},{type:"save",label:"Save","function":function(){b&&mist.data.config.triggers[b[0]].splice(b[1], pointer:{main:r,index:"async"}},{label:"Parameters",type:"str",help:$("<div>").text("The extra data you want this trigger to use.").append(pa),pointer:{main:r,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:r,index:"default"}},{type:"buttons",buttons:[{type:"cancel",label:"Cancel","function":function(){e[0]&&e[0]!=a?UI.navto(e[0],e[1]):UI.navto("Triggers")}},{type:"save",label:"Save",
1);var c={handler:r.url,sync:r.async?true:false,streams:typeof r.appliesto=="undefined"?[]:r.appliesto,params:r.params,"default":r["default"]};if(!("triggers"in mist.data.config))mist.data.config.triggers={};r.triggeron in mist.data.config.triggers||(mist.data.config.triggers[r.triggeron]=[]);mist.data.config.triggers[r.triggeron].push(c);mist.send(function(){d[0]&&d[0]!=a?UI.navto(d[0],d[1]):UI.navto("Triggers")},{config:mist.data.config})}}]}]));$("[name=triggeron]").trigger("change");break;case "Logs":var oa= "function":function(){b&&mist.data.config.triggers[b[0]].splice(b[1],1);var c={handler:r.url,sync:r.async?true:false,streams:typeof r.appliesto=="undefined"?[]:r.appliesto,params:r.params,"default":r["default"]};if(!("triggers"in mist.data.config))mist.data.config.triggers={};r.triggeron in mist.data.config.triggers||(mist.data.config.triggers[r.triggeron]=[]);mist.data.config.triggers[r.triggeron].push(c);mist.send(function(){e[0]&&e[0]!=a?UI.navto(e[0],e[1]):UI.navto("Triggers")},{config:mist.data.config})}}]}]));
$("<button>").text("Refresh now").click(function(){$(this).text("Loading..");mist.send(function(){Z();oa.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"]], $("[name=triggeron]").trigger("change");break;case "Logs":var qa=$("<button>").text("Refresh now").click(function(){$(this).text("Loading..");mist.send(function(){ca();qa.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,
value:30,"function":function(){UI.interval.clear();UI.interval.set(function(){mist.send(function(){Z()})},$(this).val()*1E3)},help:"How often the table below should be updated."},{label:"..or",type:"DOMfield",DOMfield:oa,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})}));A=$("<tbody>").css("font-size","0.9em");c.append($("<table>").addClass("logs").append(A));var qa= "10 seconds"],[30,"30 seconds"],[60,"minute"],[300,"5 minutes"]],value:30,"function":function(){UI.interval.clear();UI.interval.set(function(){mist.send(function(){ca()})},$(this).val()*1E3)},help:"How often the table below should be updated."},{label:"..or",type:"DOMfield",DOMfield:qa,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})}));C=$("<tbody>").css("font-size",
function(a){var b=$("<span>").text(a);switch(a){case "WARN":b.addClass("orange");break;case "ERROR":case "FAIL":b.addClass("red")}return b},Z=function(){var a=mist.data.log;if(a){a.length>=2&&a[0][0]<a[a.length-1][0]&&a.reverse();A.html("");for(var b in a){var c=$("<span>").addClass("content"),d=a[b][2].split("|"),g;for(g in d)c.append($("<span>").text(d[g]));A.append($("<tr>").html($("<td>").text(UI.format.dateTime(a[b][0],"long")).css("white-space","nowrap")).append($("<td>").html(qa(a[b][1])).css("text-align", "0.9em");c.append($("<table>").addClass("logs").append(C));var sa=function(a){var b=$("<span>").text(a);switch(a){case "WARN":b.addClass("orange");break;case "ERROR":case "FAIL":b.addClass("red")}return b},ca=function(){var a=mist.data.log;if(a){a.length>=2&&a[0][0]<a[a.length-1][0]&&a.reverse();C.html("");for(var b in a){var c=$("<span>").addClass("content");a[b].length>=4&&a[b][3]!=""&&c.append($("<span>").text("["+a[b][3]+"] "));var d=a[b][2].split("|"),e;for(e in d)c.append($("<span>").text(d[e]));
"center")).append($("<td>").html(c).css("text-align","left")))}}};Z();break;case "Statistics":var E=$("<span>").text("Loading..");c.append(E);var r={graph:"new"},z=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},O={};for(p in mist.data.streams)O[p]=!0;for(p in mist.data.active_streams)O[mist.data.active_streams[p]]=!0;var O=Object.keys(O).sort(),aa=[];for(p in mist.data.config.protocols)aa.push(mist.data.config.protocols[p].connector);aa.sort();mist.send(function(){UI.plot.datatype.templates.cpuload.cores= C.append($("<tr>").html($("<td>").text(UI.format.dateTime(a[b][0],"long")).css("white-space","nowrap")).append($("<td>").html(sa(a[b][1])).css("text-:align","center")).append($("<td>").html(c).css("text-align","left")))}}};ca();break;case "Statistics":var H=$("<span>").text("Loading..");c.append(H);var r={graph:"new"},B=mist.stored.get().graphs?$.extend(!0,{},mist.stored.get().graphs):{},T={};for(p in mist.data.streams)T[p]=!0;for(p in mist.data.active_streams)T[mist.data.active_streams[p]]=!0;var T=
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;E.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:r,index:"graph"},classes:["graph_ids"], Object.keys(T).sort(),da=[];for(p in mist.data.config.protocols)da.push(mist.data.config.protocols[p].connector);da.sort();mist.send(function(){UI.plot.datatype.templates.cpuload.cores=0;for(var a in mist.data.capabilities.cpu)UI.plot.datatype.templates.cpuload.cores=UI.plot.datatype.templates.cpuload.cores+mist.data.capabilities.cpu[a].cores;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."},
"function":function(){if($(this).val()){var a=E.find(".graph_xaxis"),b=E.find(".graph_id");if($(this).val()=="new"){a.children("option").prop("disabled",false);b.setval("Graph "+(Object.keys(z).length+1)).closest("label").show()}else{var c=z[$(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")}}}, $("<h3>").text("Select the data to display"),{label:"Add to",type:"select",select:[["new","New graph"]],pointer:{main:r,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",
{label:"Graph id",type:"str",pointer:{main:r,index:"id"},classes:["graph_id"],validate:[function(a){return a in z?{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:r,index:"xaxis"},value:"time",classes:["graph_xaxis"],"function":function(){$s=E.find(".graph_datatype");switch($(this).getval()){case "coords":$s.children("option").prop("disabled",true).filter('[value="coords"]').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:r,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:r,index:"xaxis"},value:"time",classes:["graph_xaxis"],
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"], "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"],
["perc_retrans","Re-transmitted packages"]],pointer:{main:r,index:"datatype"},classes:["graph_datatype"],"function":function(){$s=E.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:", ["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:r,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",
O],["protocol","The protocol:",aa]],pointer:{main:r,index:"origin"},value:["total"],classes:["graph_origin"]},{type:"buttons",buttons:[{label:"Add data set",type:"save","function":function(){var a;if(r.graph=="new"){a=UI.plot.addGraph(r,b);z[a.id]=a;E.find("input.graph_id").val("");E.find("select.graph_ids").append($("<option>").text(a.id)).val(a.id).trigger("change")}else a=z[r.graph];var c=UI.plot.datatype.getOptions({datatype:r.datatype,origin:r.origin});a.datasets.push(c);UI.plot.save(a);UI.plot.go(z)}}]}])); true);break;default:$s.find("input[type=radio]").prop("disabled",false)}}},{label:"Data origin",type:"radioselect",radioselect:[["total","All"],["stream","The stream:",T],["protocol","The protocol:",da]],pointer:{main:r,index:"origin"},value:["total"],classes:["graph_origin"]},{type:"buttons",buttons:[{label:"Add data set",type:"save","function":function(){var a;if(r.graph=="new"){a=UI.plot.addGraph(r,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=
var b=$("<div>").addClass("graph_container");c.append(b);var d=E.find("select.graph_ids");for(a in z){var g=UI.plot.addGraph(z[a],b);d.append($("<option>").text(g.id)).val(g.id);var h=[],e;for(e in z[a].datasets){var f=UI.plot.datatype.getOptions({datatype:z[a].datasets[e].datatype,origin:z[a].datasets[e].origin});h.push(f)}g.datasets=h;z[g.id]=g}d.trigger("change");UI.plot.go(z);UI.interval.set(function(){UI.plot.go(z)},1E4)},{active_streams:!0,capabilities:!0});break;case "Server Stats":if("undefined"== B[r.graph];var c=UI.plot.datatype.getOptions({datatype:r.datatype,origin:r.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 g=[],h;for(h in B[a].datasets){var f=UI.plot.datatype.getOptions({datatype:B[a].datasets[h].datatype,origin:B[a].datasets[h].origin});g.push(f)}e.datasets=g;B[e.id]=e}d.trigger("change");
typeof mist.data.capabilities){mist.send(function(){UI.showTab(a)},{capabilities:!0});c.append("Loading..");return}var ba=$("<table>"),I=$("<table>"),j={vheader:"CPUs",labels:["Model","Processor speed","Amount of cores","Amount of threads"],content:[]};for(p in mist.data.capabilities.cpu)h=mist.data.capabilities.cpu[p],j.content.push({header:"CPU #"+(Number(p)+1),body:[h.model,UI.format.addUnit(UI.format.number(h.mhz),"MHz"),h.cores,h.threads]});p=UI.buildVheaderTable(j);var pa=function(){var a=mist.data.capabilities.mem, 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.showTab(a)},{capabilities:!0});c.append("Loading..");return}var ea=$("<table>"),fa=$("<table>"),k={vheader:"CPUs",labels:["Model","Processor speed","Amount of cores","Amount of threads"],content:[]};for(p in mist.data.capabilities.cpu)s=mist.data.capabilities.cpu[p],k.content.push({header:"CPU #"+(Number(p)+
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); 1),body:[s.model,UI.format.addUnit(UI.format.number(s.mhz),"MHz"),s.cores,s.threads]});p=UI.buildVheaderTable(k);var ra=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-
ba.replaceWith(a);ba=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);I.replaceWith(b);I=b};pa();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", a.swapfree)*1048576),UI.format.addUnit("","N/A"),UI.format.bytes(a.swapfree*1048576),UI.format.bytes(a.swaptotal*1048576)]}]},a=UI.buildVheaderTable(a);ea.replaceWith(a);ea=a;b={vheader:"Load average",labels:["CPU use","1 minute","5 minutes","15 minutes"],content:[{header:"&nbsp;",body:[UI.format.addUnit(UI.format.number(mist.data.capabilities.cpu_use/10),"%"),UI.format.number(b.one/100),UI.format.number(b.five/100),UI.format.number(b.fifteen/100)]}]};b=UI.buildVheaderTable(b);fa.replaceWith(b);fa=
"auto").addClass("nolay").append($("<tr>").append($("<td>").append(ba)).append($("<td>").append(I))).append($("<tr>").append($("<td>").append(p).attr("colspan",2))));UI.interval.set(function(){mist.send(function(){pa()},{capabilities:true})},3E4);break;case "Email for Help":p=$.extend({},mist.data);delete p.statistics;delete p.totals;delete p.clients;delete p.capabilities;p=JSON.stringify(p);p="Version: "+mist.data.config.version+"\n\nConfig:\n"+p;r={};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."}, b};ra();c.append(UI.buildUI([{type:"help",help:"You can find general server statistics here. Note that memory and CPU usage is for your entire machine, not just MistServer."}])).append($("<table>").css("width","auto").addClass("nolay").append($("<tr>").append($("<td>").append(ea)).append($("<td>").append(fa))).append($("<tr>").append($("<td>").append(p).attr("colspan",2))));UI.interval.set(function(){mist.send(function(){ra()},{capabilities:true})},3E4);break;case "Email for Help":p=$.extend({},mist.data);
{type:"str",label:"Your name",validate:["required"],pointer:{main:r,index:"name"},value:mist.user.name},{type:"email",label:"Your email address",validate:["required"],pointer:{main:r,index:"email"}},{type:"hidden",value:"Integrated Help",pointer:{main:r,index:"subject"}},{type:"hidden",value:"-",pointer:{main:r,index:"company"}},{type:"textarea",rows:20,label:"Your message",validate:["required"],pointer:{main:r,index:"message"}},{type:"textarea",rows:20,label:"Your config file",readonly:!0,value:p, delete p.statistics;delete p.totals;delete p.clients;delete p.capabilities;p=JSON.stringify(p);p="Version: "+mist.data.config.version+"\n\nConfig:\n"+p;r={};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:r,index:"name"},value:mist.user.name},{type:"email",label:"Your email address",validate:["required"],
pointer:{main:r,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:r,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= pointer:{main:r,index:"email"}},{type:"hidden",value:"Integrated Help",pointer:{main:r,index:"subject"}},{type:"hidden",value:"-",pointer:{main:r,index:"company"}},{type:"textarea",rows:20,label:"Your message",validate:["required"],pointer:{main:r,index:"message"}},{type:"textarea",rows:20,label:"Your config file",readonly:!0,value:p,pointer:{main:r,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",
$(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}})},dynamic:function(a,b){var a=Object.assign({},a),d=a.create(b);if(d){d.raw="";a.getEntry||(a.getEntry=function(a,b){return b in a?a[b]:!1});a.getEntries||(a.getEntries=function(a){return a});d.update&&(a.update=d.update);a.update||(a.update=function(){});if("object"==typeof a.add){var c= data:r,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;mist.data={};UI.sockets.http_host=null;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.add;a.add=function(a){return UI.dynamic(c,a)}}a.add&&(d._children={},d.add=function(b){var c=a.add.call(d,b);if(c){c.remove=function(){var a=this;a instanceof jQuery&&(a=a[0]);a.parentNode&&a.parentNode.removeChild(a);delete d._children[b]};c.id=b;d._children[b]=c;c.customAdd?c.customAdd(d):d.append(c)}});d.update=function(b,c){var i=a.getEntries(b,d.id),f=JSON.stringify(i);if(this.raw!=f){this.values=i;this.values_orig=b;if(a.add){for(var m in i){m in this._children||this.add(m);m in this._children&& a.push($(this)):a=$(this).find("input, select, textarea");if(a.length){$(a[0]).focus();return false}})},dynamic:function(a,b){var a=Object.assign({},a),e=a.create(b);if(e){e.raw="";a.getEntry||(a.getEntry=function(a,b){return b in a?a[b]:!1});a.getEntries||(a.getEntries=function(a){return a});e.update&&(a.update=e.update);a.update||(a.update=function(){});if("object"==typeof a.add){var c=a.add;a.add=function(a){return UI.dynamic(c,a)}}a.add&&(e._children={},e.add=function(b){var c=a.add.call(e,b);
this._children[m].update.call(this._children[m],i[m],i)}for(var n in this._children)n in i||this._children[n].remove()}a.update.call(d,i,c);this.raw=f}};a.values&&d.update.call(d,a.values);return d}},modules:{stream:{bigbuttons:function(a,b){var d=$("<div>").addClass("bigbuttons");d.append($("<button>").text("Settings").addClass("settings").click(function(){UI.navto("Edit",a)}));var c=!1;if(0>a.indexOf("+")){var e=mist.data.streams[a];if(e.source&&(e.source.match(/^\/.+\/$/)||e.source.match(/^folder:.+$/)))c= if(c){c.remove=function(){var a=this;a instanceof jQuery&&(a=a[0]);a.parentNode&&a.parentNode.removeChild(a);delete e._children[b]};c._id=b;e._children[b]=c;c.customAdd?c.customAdd(e):e.append(c)}});e.update=function(b,c){var i=a.getEntries(b,e._id),f=JSON.stringify(i);if(this.raw!=f){this.values=i;this.values_orig=b;if(a.add){for(var m in i){m in this._children||this.add(m);m in this._children&&this._children[m].update.call(this._children[m],i[m],i)}for(var n in this._children)n in i||this._children[n].remove()}a.update.call(e,
!0}"Status"!=b&&d.append($("<button>").text("Status").attr("data-icon","\ud83d\udea5").click(function(){UI.navto("Status",a)}));"Preview"!=b&&!c&&d.append($("<button>").text("Preview").addClass("preview").click(function(){UI.navto("Preview",a)}));"Embed"!=b&&!c&&d.append($("<button>").text("Embed").addClass("embed").click(function(){UI.navto("Embed",a)}));d.append($("<button>").addClass("cancel").addClass("return").text("Return").click(function(){UI.navto("Streams")}));return d},findMist:function(a, i,c);this.raw=f}};a.values&&e.update.call(e,a.values);return e}},modules:{stream:{header:function(a,b,e){function c(c){if(!c)return $("<span>").addClass("spacer");var e=c;"string"!=typeof c&&(e=c[0],c=c[1]);return $("<li>").addClass("tab").addClass(c==b?"active":!1).attr("tabindex",0).attr("data-icon",c).text(e).click(function(){if(!(b=="Edit"&&d.attr("data-changed"))||confirm("Your settings have not been saved. Are you sure you want to navigate away?"))UI.navto(c,c=="Streams"?"":a)})}var d=$("<div>").addClass("header"),
b,d){function c(a){function b(a){for(var c=[],d=0;d<a.length;d++)a.indexOf(a[d])==d&&c.push(a[d]);return c}var e={HTTP:[],HTTPS:[]},q=e.HTTP,g=e.HTTPS;if(UI.sockets.http_host)if(d)q.push(UI.sockets.http_host),g.push(UI.sockets.http_host);else return a([UI.sockets.http_host]);if(mist.data.capabilities){var h=mist.stored.get();"HTTPurl"in h&&("https"==h.HTTPurl.slice(0,5)?g.push(h.HTTPurl):q.push(h.HTTPurl));for(var i in mist.data.config.protocols){var h=mist.data.config.protocols[i],l=h.connector, j=$("<ul>").addClass("tabnav");d.append($("<div>").css("display","flex").css("align-items","baseline").append($("<h2>").text('Stream "'+a+'"')).append(UI.modules.stream.status(a,{tags:!1,thumbnail:!1,livestreamhint:!1}))).append(j).append($("<h2>").text("Edit"==b?'Edit "'+e+'"':b));var e=[["Settings","Edit"],"Status","Preview","Embed"],i=!1;if(0>a.indexOf("+")){var f=mist.data.streams[a];if(f.source&&(f.source.match(/^\/.+\/$/)||f.source.match(/^folder:.+$/)))i=!0}i&&(e.pop(),e.pop());e.push(!1);
l=(""+l).replace(".exe","");switch(h.connector){case "HTTP":case "HTTPS":if(h.pubaddr)for(var s in h.pubaddr){var p=h.pubaddr[s].split(":")[0].toUpperCase();e[p].push(h.pubaddr[s])}(p=h.port)||h.connector in mist.data.capabilities.connectors&&(p=mist.data.capabilities.connectors[h.connector].optional.port["default"]);p&&e[h.connector].push(parseURL(mist.user.host,{port:p,pathname:"",protocol:l.toLowerCase()+":"}).full)}}q.length||q.push(parseURL(mist.user.host,{port:8080,pathname:""}).full);g.length|| e.push(["Overview","Streams"]);j.append($("<span>").addClass("curtab-icon").attr("data-icon",b));for(var m in e)j.append(c(e[m]));return d},bigbuttons:function(a,b){var e=$("<div>").addClass("bigbuttons");e.append($("<button>").text("Settings").addClass("settings").click(function(){UI.navto("Edit",a)}));var c=!1;if(0>a.indexOf("+")){var d=mist.data.streams[a];if(d.source&&(d.source.match(/^\/.+\/$/)||d.source.match(/^folder:.+$/)))c=!0}"Status"!=b&&e.append($("<button>").text("Status").addClass("status").click(function(){UI.navto("Status",
(g=q);q=b(q);g=b(g);f.urls=e;return a("https:"==location.protocol?g:q)}mist.send(function(){c(a)},{capabilities:!0})}function e(a,c){if(c>=a.length)return l();try{if(b||(b=function(a){return a+"player.js"}),url=b(a[c]),"http"==url.slice(0,4))$.ajax({type:"GET",url:url,success:function(b){f.hide();i(a[c],b)},error:function(){e(a,c+1)}});else if("ws"==url.slice(0,2)){var d=UI.websockets.create(url);d.onopen=function(){d.onerror=function(){};f.hide();i(a[c],d)};d.onerror=function(){e(a,c+1)}}else throw"I'm not sure how to contact MistServer with this protocol. (at "+ a)}));"Preview"!=b&&!c&&e.append($("<button>").text("Preview").addClass("preview").click(function(){UI.navto("Preview",a)}));"Embed"!=b&&!c&&e.append($("<button>").text("Embed").addClass("embed").click(function(){UI.navto("Embed",a)}));e.append($("<button>").addClass("cancel").addClass("return").text("Return").click(function(){UI.navto("Streams")}));return e},findMist:function(a,b,e){function c(a){function b(a){for(var c=[],d=0;d<a.length;d++)a.indexOf(a[d])==d&&c.push(a[d]);return c}var d={HTTP:[],
url+")";}catch(q){l(a)}}function l(a){1==a.length&&a[0]==UI.sockets.http_host&&(UI.sockets.http_host=null,c(function(b){a=b;e(b,0)}));var b={};f.show().html($("<p>").text("Could not locate the MistHTTP output url. Where can it be reached?")).append($("<div>").addClass("description").append($("<p>").text("Attempts:")).append($("<ul>").html("<li>"+a.join("</li><li>")+"</li>"))).append(UI.buildUI([{label:"MistServer HTTP endpoint",type:"datalist",datalist:a,help:"Please specify the url at which MistServer's HTTP endpoint can be reached.", HTTPS:[]},q=d.HTTP,h=d.HTTPS;if(UI.sockets.http_host)if(e)q.push(UI.sockets.http_host),h.push(UI.sockets.http_host);else return a([UI.sockets.http_host]);if(mist.data.capabilities){var g=mist.stored.get();"HTTPurl"in g&&("https"==g.HTTPurl.slice(0,5)?h.push(g.HTTPurl):q.push(g.HTTPurl));for(var l in mist.data.config.protocols){var g=mist.data.config.protocols[l],i=g.connector,i=(""+i).replace(".exe","");switch(g.connector){case "HTTP":case "HTTPS":if(g.pubaddr)for(var j in g.pubaddr){var p=g.pubaddr[j].split(":")[0].toUpperCase();
pointer:{main:b,index:"url"}},{type:"buttons",buttons:[{type:"save",label:"Connect","function":function(){a.unshift(b.url);e(a,0)}}]}]))}function i(b,c){b!=UI.sockets.http_host&&(UI.sockets.http_host=b,mist.stored.set("HTTPUrl",b));a.call(f,b,c)}var f=$("<div>").addClass("findMist").hide();c(function(a){e(a,0)});f.getUrls=function(){return f.urls};return f},livestreamhint:function(a){var b=$("<div>").addClass("livestreamhint"),d=mist.data.streams[a.split("+")[0]];if(d.source&&"/"!=d.source.slice(0, d[p].push(g.pubaddr[j])}(p=g.port)||g.connector in mist.data.capabilities.connectors&&(p=mist.data.capabilities.connectors[g.connector].optional.port["default"]);p&&d[g.connector].push(parseURL(mist.user.host,{port:p,pathname:"",protocol:i.toLowerCase()+":"}).full)}}q.length||q.push(parseURL(mist.user.host,{port:8080,pathname:""}).full);h.length||(h=q);q=b(q);h=b(h);f.urls=d;return a("https:"==location.protocol?h:q)}mist.send(function(){c(a)},{capabilities:!0})}function d(a,c){if(c>=a.length)return j();
1)&&!d.source.match(/-exec:/)){var c=null,e;for(e in mist.data.capabilities.inputs)if("undefined"!=typeof mist.data.capabilities.inputs[e].source_match&&mist.inputMatch(mist.data.capabilities.inputs[e].source_match,d.source)){c=e;break}if(c){c=mist.data.capabilities.inputs[c];e=[$("<span>").text("Configure your source to push to:")];switch(c.name){case "Buffer":case "Buffer.exe":e.push({label:"RTMP full url",type:"span",clipboard:!0,readonly:!0,classes:["RTMP"],help:"Use this RTMP url if your client doesn't ask for a stream key"}); try{if(b||(b=function(a){return a+"player.js"}),url=b(a[c]),"http"==url.slice(0,4))$.ajax({type:"GET",url:url,success:function(b){f.hide();i(a[c],b)},error:function(){d(a,c+1)}});else if("ws"==url.slice(0,2)){var e=UI.websockets.create(url);e.onopen=function(){e.onerror=function(){};f.hide();i(a[c],e)};e.onerror=function(){d(a,c+1)}}else throw"I'm not sure how to contact MistServer with this protocol. (at "+url+")";}catch(q){j(a)}}function j(a){1==a.length&&a[0]==UI.sockets.http_host&&(UI.sockets.http_host=
e.push({label:"RTMP url",type:"span",clipboard:!0,readonly:!0,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:!0,readonly:!0,classes:["RTMPkey"],help:"Use this key if your client asks for a stream key"});e.push({label:"SRT",type:"span",clipboard:!0,readonly:!0,classes:["TSSRT"]});e.push({label:"RTSP",type:"span",clipboard:!0,readonly:!0,classes:["RTSP"]});break;case "TS":case "TS.exe":"/"==d.source.charAt(0)? null,c(function(b){a=b;d(b,0)}));var b={};f.show().html($("<p>").text("Could not locate the MistHTTP output url. Where can it be reached?")).append($("<div>").addClass("description").append($("<p>").text("Attempts:")).append($("<ul>").html("<li>"+a.join("</li><li>")+"</li>"))).append(UI.buildUI([{label:"MistServer HTTP endpoint",type:"datalist",datalist:a,help:"Please specify the url at which MistServer's HTTP endpoint can be reached.",pointer:{main:b,index:"url"}},{type:"buttons",buttons:[{type:"save",
e=[]:e.push({label:"TS",type:"span",clipboard:!0,readonly:!0,classes:["TS"]});break;case "TSSRT":case "TSSRT.exe":e.push({label:"SRT",type:"span",clipboard:!0,readonly:!0,classes:["TSSRT"]});break;default:e=[]}e.length&&(b.html(UI.buildUI(e)),UI.updateLiveStreamHint(a,d.source,b))}}else return!1;return b},status:function(a,b){b||(b={});var b=Object.assign({livestreamhint:!0,status:!0,stats:!0,tags:!0,thumbnail:!0},b),d=$("<div>").addClass("activestream"),c=b.status?$("<div>").attr("data-streamstatus", label:"Connect","function":function(){a.unshift(b.url);d(a,0)}}]}]))}function i(b,c){b!=UI.sockets.http_host&&(UI.sockets.http_host=b,mist.stored.set("HTTPUrl",b));a.call(f,b,c)}var f=$("<div>").addClass("findMist").hide();c(function(a){d(a,0)});f.getUrls=function(){return f.urls};return f},livestreamhint:function(a){var b=$("<div>").addClass("livestreamhint"),e=mist.data.streams[a.split("+")[0]];if(e.source&&"/"!=e.source.slice(0,1)&&!e.source.match(/-exec:/)){var c=null,d;for(d in mist.data.capabilities.inputs)if("undefined"!=
0).text("Offline"):!1,e=b.stats?$("<span>").attr("beforeifnotempty","Viewers: "):!1,l=b.stats?$("<span>").attr("beforeifnotempty","Inputs: "):!1,i=b.stats?$("<span>").attr("beforeifnotempty","Outputs: "):!1,f=b.tags?{cont:$("<div>").attr("beforeifnotempty","Tags: "),children:{},ele:function(b){var c=$("<span>").addClass("tag").text(b).append($("<button>").text("\ud83d\uddd9").attr("title","Remove tag").click(function(){var c=$(this),d={};d[a]=b;c.parent().text("Removing..");mist.send(function(){c.parent().remove()}, typeof mist.data.capabilities.inputs[d].source_match&&mist.inputMatch(mist.data.capabilities.inputs[d].source_match,e.source)){c=d;break}if(c){c=mist.data.capabilities.inputs[c];d=[$("<span>").text("Configure your source to push to:")];switch(c.name){case "Buffer":case "Buffer.exe":d.push({label:"RTMP full url",type:"span",clipboard:!0,readonly:!0,classes:["RTMP"],help:"Use this RTMP url if your client doesn't ask for a stream key"});d.push({label:"RTMP url",type:"span",clipboard:!0,readonly:!0,classes:["RTMPurl"],
{untag_stream:d})}));return this.children[b]=c},update:function(a){var a=""==a?[]:a.split(" "),b={},c;for(c in a){var d=a[c];b[d]=1;d in this.children||this.cont.append(this.ele(d))}for(c in this.children)c in b||(this.children[c].remove(),delete this.children[c])}}:!1,m=b.tags?$("<div>").html($("<input>").attr("placeholder","Tag name").on("keydown",function(a){switch(a.key){case " ":a.preventDefault();break;case "Enter":$(this).parent().find("button").click()}})).append($("<button>").text("Add tag").click(function(){var b= help:"Use this RTMP url if your client also asks for a stream key"});d.push({label:"RTMP stream key",type:"span",clipboard:!0,readonly:!0,classes:["RTMPkey"],help:"Use this key if your client asks for a stream key"});d.push({label:"SRT",type:"span",clipboard:!0,readonly:!0,classes:["TSSRT"]});d.push({label:"RTSP",type:"span",clipboard:!0,readonly:!0,classes:["RTSP"]});break;case "TS":case "TS.exe":"/"==e.source.charAt(0)?d=[]:d.push({label:"TS",type:"span",clipboard:!0,readonly:!0,classes:["TS"]});
{},c=$(this),d=c.parent().find("input");b[a]=d.val();c.text("Adding..");mist.send(function(){c.text("Add tag");d.val("")},{tag_stream:b})})):!1,n=b.livestreamhint?UI.modules.stream.livestreamhint(a):!1;d.html(c).append(e).append(l).append(i).append(f?f.cont:!1).append(m).append(b.thumbnail?UI.modules.stream.thumbnail(a):!1).append(n);UI.sockets.ws.active_streams.subscribe(function(d,m){if("stream"==d&&m[0]==a){var g="Offline;Initializing;Booting;Waiting for data;Ready;Shutting down;Invalid state".split(";"); break;case "TSSRT":case "TSSRT.exe":d.push({label:"SRT",type:"span",clipboard:!0,readonly:!0,classes:["TSSRT"]});break;default:d=[]}d.length&&(b.html(UI.buildUI(d)),UI.updateLiveStreamHint(a,e.source,b))}}else return!1;return b},status:function(a,b){b||(b={});var b=Object.assign({livestreamhint:!0,status:!0,stats:!0,tags:!0,thumbnail:!0},b),e=$("<div>").addClass("activestream"),c=b.status?$("<div>").attr("data-streamstatus",0).text("Offline").hide():!1,d=b.stats?$("<span>").attr("beforeifnotempty",
b.status&&c.attr("data-streamstatus",m[1]).text(g[m[1]]);b.stats&&(e.text(m[2]),l.text(0<m[3]?m[3]:""),i.text(0<m[4]?m[4]:""));b.tags&&f.update(m[5]);n&&(0==m[1]?n.show():n.hide())}});return $("<section>").addClass("activestream").append(d)},actions:function(a,b){return $("<section>").addClass("actions").addClass("bigbuttons").html($("<button>").text("Stop all sessions").attr("data-icon","\u270b").attr("title","Disconnect sessions for this stream. Disconnecting a session will kill any currently open connections (viewers, pushes and possibly the input). If the USER_NEW trigger is in use, it will be triggered again by any reconnecting connections.").click(function(){confirm("Are you sure you want to disconnect all sessions (viewers, pushes and possibly the input) from this stream?")&& "Viewers: "):!1,j=b.stats?$("<span>").attr("beforeifnotempty","Inputs: "):!1,i=b.stats?$("<span>").attr("beforeifnotempty","Outputs: "):!1,f=b.tags?{cont:$("<div>").attr("beforeifnotempty","Tags: "),children:{},ele:function(c){var d=$("<span>").addClass("tag").text(c);"readonly"!=b.tags&&d.append($("<button>").text("\ud83d\uddd9").attr("title","Remove tag").click(function(){var b=$(this),d={};d[a]=c;b.parent().text("Removing..");mist.send(function(){b.parent().remove()},{untag_stream:d})}));return this.children[c]=
mist.send(function(){},{stop_sessions:b})})).append($("<button>").text("Invalidate sessions").attr("data-icon","\ud83d\udd10").attr("title","Invalidate all the currently active sessions for this stream. This has the effect of re-triggering the USER_NEW trigger, allowing you to selectively close some of the existing connections after they have been previously allowed. If you don't have a USER_NEW trigger configured, this will not have any effect.").click(function(){confirm("Are you sure you want to invalidate all sessions for the stream '"+ d},update:function(a){var a=""==a?[]:a.split(" "),b={},c;for(c in a){var d=a[c];b[d]=1;d in this.children||this.cont.append(this.ele(d))}for(c in this.children)c in b||(this.children[c].remove(),delete this.children[c])}}:!1,m=b.tags&&"readonly"!=b.tags?$("<div>").addClass("input_container").css("display","block").html($("<input>").attr("placeholder","Tag name").on("keydown",function(a){switch(a.key){case " ":a.preventDefault();break;case "Enter":$(this).parent().find("button").click()}})).append($("<button>").text("Add tag").click(function(){var b=
b+"'?\nThis will re-trigger the USER_NEW trigger.")&&mist.send(function(){},{invalidate_sessions:b})})).append($("<button>").text("Nuke stream").attr("data-icon","\u2622\ufe0f").attr("title","Shut down a running stream completely and/or clean up any potentially left over stream data in memory. It attempts a clean shutdown of the running stream first, followed by a forced shut down, and then follows up by checking for left over data in memory and cleaning that up if any is found.").click(function(){confirm("Are you sure you want to completely shut down the stream '"+ {},c=$(this),d=c.parent().find("input");b[a]=d.val();c.text("Adding..");mist.send(function(){c.text("Add tag");d.val("")},{tag_stream:b})})):!1,n=b.livestreamhint?UI.modules.stream.livestreamhint(a):!1;e.html(c).append(d).append(j).append(i).append(f?f.cont:!1).append(m).append(b.thumbnail?UI.modules.stream.thumbnail(a):!1).append(n);UI.sockets.ws.active_streams.subscribe(function(e,m){b.status&&c.css("display","");if("stream"==e&&m[0]==a){var h="Offline;Initializing;Booting;Waiting for data;Available;Shutting down;Invalid state".split(";");
b+"'?\nAll viewers will be disconnected.")&&mist.send(function(){UI.showTab(a,b)},{nuke_stream:b})}))},thumbnail:function(a){if(UI.findOutput("JPG")){var b=$("<img>");UI.sockets.ws.info_json.subscribe(function(a){if(a.source)for(var c in a.source)if("html5/image/jpeg"==a.source[c].type){b.attr("src",a.source[c].url);break}},a);return $("<section>").addClass("thumbnail").html(b)}},metadata:function(a,b){function d(b){if(!e.freeze)if(b.error&&(!c.rawdata||"live"==c.rawdata.type))c.html("").attr("onempty", b.status&&c.attr("data-streamstatus",m[1]).text(h[m[1]]);b.stats&&(d.text(m[2]),j.text(0<m[3]?m[3]:""),i.text(0<m[4]?m[4]:""));b.tags&&f.update(m[5]);n&&(0==m[1]?n.show():n.hide())}});return $("<section>").addClass("activestream").append(e)},actions:function(a,b){return $("<section>").addClass("actions").addClass("bigbuttons").html($("<button>").text("Stop all sessions").attr("data-icon","stop").attr("title","Disconnect sessions for this stream. Disconnecting a session will kill any currently open connections (viewers, pushes and possibly the input). If the USER_NEW trigger is in use, it will be triggered again by any reconnecting connections.").click(function(){confirm("Are you sure you want to disconnect all sessions (viewers, pushes and possibly the input) from this stream?")&&
b.error+".");else{if(c.rawdata&&"live"==c.rawdata.type||!b.error)c.rawdata=b;e.parent().length||c.html($("<div>").append($("<button>").text("Open raw json").click(function(){var b=window.open(null,"Stream info json for "+a);b.document.write("<html><head><title>Raw stream metadata for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"></head><body><code><pre>'+JSON.stringify(c.rawdata,null,2)+"</pre></code></body></html>");b.document.close()})).append($("<button>").text("Freeze").attr("title", mist.send(function(){},{stop_sessions:b})})).append($("<button>").text("Invalidate sessions").attr("data-icon","invalidate").attr("title","Invalidate all the currently active sessions for this stream. This has the effect of re-triggering the USER_NEW trigger, allowing you to selectively close some of the existing connections after they have been previously allowed. If you don't have a USER_NEW trigger configured, this will not have any effect.").click(function(){confirm("Are you sure you want to invalidate all sessions for the stream '"+
"Pauze updating the stream metadata information below").click(function(){"Freeze"==$(this).text()?($(this).text("Frozen").css("background","#bbb"),e.freeze=!0):($(this).text("Freeze")[0].style.background="",e.freeze=!1)}))).append(e);e.freeze||e.update(b)}}b||(b={});var b=Object.assign({tracktable:!0,tracktiming:!0},b),c=$("<div>").addClass("meta").text("Loading.."),e=UI.dynamic({create:function(){var a=$("<span>");a.main=UI.dynamic({create:function(){var c=$("<div>").addClass("main");c.type=$("<span>"); b+"'?\nThis will re-trigger the USER_NEW trigger.")&&mist.send(function(){},{invalidate_sessions:b})})).append($("<button>").text("Nuke stream").attr("data-icon","nuke").attr("title","Shut down a running stream completely and/or clean up any potentially left over stream data in memory. It attempts a clean shutdown of the running stream first, followed by a forced shut down, and then follows up by checking for left over data in memory and cleaning that up if any is found.").click(function(){confirm("Are you sure you want to completely shut down the stream '"+
c.html($("<label>").append($("<span>").text("Type:")).append(c.type));c.buffer=$("<span>");c.append($("<label>").attr("data-liveonly","").append($("<span>").text("Buffer window:")).append(c.buffer));c.jitter=$("<span>");c.append($("<label>").attr("data-liveonly","").append($("<span>").text("Jitter:")).append(c.jitter));b.tracktiming&&(c.timing=UI.dynamic({create:function(){var a=$("<div>").addClass("tracktiming");a.box=$("<div>").addClass("boxcont");a.box.label=$("<span>").addClass("center");a.box.left= b+"'?\nAll viewers will be disconnected.")&&mist.send(function(){UI.showTab(a,b)},{nuke_stream:b})}))},thumbnail:function(a,b){if(UI.findOutput("JPG")){var e,c,d=$("<img>").hover(function(){e&&c&&$(this).attr("src",c)},function(){e&&c&&$(this).attr("src",e)});UI.sockets.ws.info_json.subscribe(function(a){if(a.source){for(var b in a.source)if("html5/image/jpeg"==a.source[b].type){var m=a.source[b].url;-1<m.indexOf(".mjpg")?c=m:e=m;if(e&&c)break}if(c||e)c?e||(e=c):c=e,d.attr("src",e),j&&j.attr("src",
$("<span>").addClass("left");a.box.right=$("<span>").addClass("right");a.box.append($("<div>").addClass("box")).append(a.box.label).append(a.box.left).append(a.box.right);a.append(a.box);a.bounds=null;a.mstopos=function(a){return!this.bounds?25:100*((a-this.bounds.firstms.min)/(this.bounds.lastms.max-this.bounds.firstms.min))};a.mstosize=function(a){return!this.bounds?10:100*(a/(this.bounds.lastms.max-this.bounds.firstms.min))};return a},add:{create:function(a){a=$("<div>").addClass("track").attr("data-track", e)}},a);var j;b&&b.clone&&(j=$("<img>").addClass("clone"));return $("<section>").addClass("thumbnail").html(d).append(j)}},metadata:function(a,b){function e(b){if(!d.freeze)if(b.error&&(!c.rawdata||"live"==c.rawdata.type))c.html("").attr("onempty",b.error+".");else{if(c.rawdata&&"live"==c.rawdata.type||!b.error)c.rawdata=b;d.parent().length||c.html($("<div>").append($("<button>").text("Open raw json").click(function(){var b=window.open(null,"Stream info json for "+a);b.document.write("<html><head><title>Raw stream metadata for '"+
a);a.label=$("<label>");a.box=$("<div>").addClass("box");a.jitter=$("<div>").addClass("jitter");a.box.append(a.jitter);a.left=$("<span>").addClass("left").attr("beforeifnotempty","-");a.right=$("<span>").addClass("right").attr("beforeifnotempty","+");a.box.append(a.left);a.box.append(a.right);a.append(a.box).append(a.label);return a},update:function(a){a.type!=this.raw_type&&this.attr("data-type",a.type);a.type!=this.raw_tracktype&&(this.attr("title",UI.format.capital(a.type)),this.raw_tracktype= a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"></head><body><code><pre>'+JSON.stringify(c.rawdata,null,2)+"</pre></code></body></html>");b.document.close()})).append($("<button>").text("Freeze").attr("title","Pauze updating the stream metadata information below").click(function(){"Freeze"==$(this).text()?($(this).text("Frozen").css("background","#bbb"),d.freeze=!0):($(this).text("Freeze")[0].style.background="",d.freeze=!1)}))).append(d);d.freeze||d.update(b)}}
a.type);this.label.raw!=a.idx+a.type+a.codec&&(this.label.text("Track "+a.idx+" ("+a.codec+")"),this.label.raw=a.idx+a.type+a.codec,this.css("order",a.idx));this.jitter.raw!=a.jitter&&(this.jitter.attr("title","Jitter: "+a.jitter+"ms"),this.jitter.raw=a.jitter);var b="nowms"in a?"nowms":"lastms",d=c.timing.bounds.firstms.max,e=c.timing.bounds.lastms.min;this.box.css("left",c.timing.mstopos(a.firstms)+"%");this.box.css("right",100-c.timing.mstopos(a[b])+"%");d>=e?(a.firstms>e?this.left.html(UI.format.duration(0.001* b||(b={});var b=Object.assign({tracktable:!0,tracktiming:!0},b),c=$("<div>").addClass("meta").text("Loading.."),d=UI.dynamic({create:function(){var a=$("<span>");a.main=UI.dynamic({create:function(){var c=$("<div>").addClass("main").addClass("input_container");c.type=$("<span>");c.html($("<label>").append($("<span>").text("Type:")).append(c.type));c.buffer=$("<span>");c.append($("<label>").attr("data-liveonly","").append($("<span>").text("Buffer window:")).append(c.buffer));c.jitter=$("<span>");c.append($("<label>").attr("data-liveonly",
(d-a.firstms),!0)):this.left.html(UI.format.duration(0.001*(e-a.firstms),!0)),a.lastms>d?this.right.html(UI.format.duration(0.001*(a[b]-d),!0)):this.right.html(UI.format.duration(0.001*(a[b]-e),!0))):(this.left.html(UI.format.duration(0.001*(d-a.firstms),!0)),this.right.html(UI.format.duration(0.001*(a[b]-e),!0)));this.jitter.width(100*(a.jitter/(a[b]-a.firstms))+"%")}},getEntries:function(a){var b={},d=!c.includemeta.is(":checked"),e;for(e in a)d&&"meta"==a[e].type||(b[e]=a[e]);a={firstms:{min:1E9, "").append($("<span>").text("Jitter:")).append(c.jitter));b.tracktiming&&(c.timing=UI.dynamic({create:function(){var a=$("<div>").addClass("tracktiming");a.box=$("<div>").addClass("boxcont");a.box.label=$("<span>").addClass("center");a.box.left=$("<span>").addClass("left");a.box.right=$("<span>").addClass("right");a.box.append($("<div>").addClass("box")).append(a.box.label).append(a.box.left).append(a.box.right);a.append(a.box);a.bounds=null;a.mstopos=function(a){return!this.bounds?25:100*((a-this.bounds.firstms.min)/
max:-1E9},lastms:{min:1E9,max:-1E9}};for(e in b)d="nowms"in b[e]?"nowms":"lastms",a.firstms.min=Math.min(a.firstms.min,b[e].firstms),a.firstms.max=Math.max(a.firstms.max,b[e].firstms),a.lastms.min=Math.min(a.lastms.min,b[e][d]),a.lastms.max=Math.max(a.lastms.max,b[e][d]);c.timing.bounds=a;for(e in b)b[e].bounds=a;return b},update:function(a){var b=c.timing.bounds.firstms.max,d=c.timing.bounds.lastms.min;this.box.label.html(UI.format.duration(0.001*Math.abs(b-d),!0));this.box[0].style.setProperty("--ntracks", (this.bounds.lastms.max-this.bounds.firstms.min))};a.mstosize=function(a){return!this.bounds?10:100*(a/(this.bounds.lastms.max-this.bounds.firstms.min))};return a},add:{create:function(a){a=$("<div>").addClass("track").attr("data-track",a);a.label=$("<label>");a.box=$("<div>").addClass("box");a.jitter=$("<div>").addClass("jitter");a.box.append(a.jitter);a.left=$("<span>").addClass("left").attr("beforeifnotempty","-");a.right=$("<span>").addClass("right").attr("beforeifnotempty","+");a.box.append(a.left);
Object.keys(a).length);b<d?(this.box.css("margin-left",c.timing.mstopos(b)+"%"),this.box.css("margin-right",100-c.timing.mstopos(d)+"%"),this.box.left.html(UI.format.duration(0.001*b)),this.box.right.html(UI.format.duration(0.001*d)),this.box.removeClass("gap")):(this.box.css("margin-left",c.timing.mstopos(d)+"%"),this.box.css("margin-right",100-c.timing.mstopos(b)+"%"),this.box.left.html(UI.format.duration(0.001*d)),this.box.right.html(UI.format.duration(0.001*b)),this.box.addClass("gap"));40>this.box.width()? a.box.append(a.right);a.append(a.box).append(a.label);return a},update:function(a){a.type!=this.raw_type&&this.attr("data-type",a.type);a.type!=this.raw_tracktype&&(this.attr("title",UI.format.capital(a.type)),this.raw_tracktype=a.type);this.label.raw!=a.idx+a.type+a.codec&&(this.label.text("Track "+a.idx+" ("+a.codec+")"),this.label.raw=a.idx+a.type+a.codec,this.css("order",a.idx));this.jitter.raw!=a.jitter&&(this.jitter.attr("title","Jitter: "+a.jitter+"ms"),this.jitter.raw=a.jitter);var b="nowms"in
this.box.addClass("toosmall"):this.box.removeClass("toosmall")}}),c.includemeta=$("<input>").attr("type","checkbox").click(function(){a.main.timing.update(a.main.timing.values_orig)}),c.append($("<label>").append($("<span>").text("Include metadata in graph:")).append(c.includemeta)).append($("<label>").append($("<span>").text("Track timing:"))).append(c.timing));b.tracktable&&(c.tracks=UI.dynamic({create:function(){return $("<div>").addClass("tracks")},getEntries:function(a){var b={audio:{},video:{}, a?"nowms":"lastms",d=c.timing.bounds.firstms.max,e=c.timing.bounds.lastms.min;this.box.css("left",c.timing.mstopos(a.firstms)+"%");this.box.css("right",100-c.timing.mstopos(a[b])+"%");d>=e?(a.firstms>e?this.left.html(UI.format.duration(0.001*(d-a.firstms),!0)):this.left.html(UI.format.duration(0.001*(e-a.firstms),!0)),a.lastms>d?this.right.html(UI.format.duration(0.001*(a[b]-d),!0)):this.right.html(UI.format.duration(0.001*(a[b]-e),!0))):(this.left.html(UI.format.duration(0.001*(d-a.firstms),!0)),
subtitle:{},meta:{}};if(a){var c=Object.keys(a).sort(function(b,c){return a[b].idx-a[c].idx}),d;for(d in c){var g=a[c[d]],h=g.codec=="subtitle"?"subtitle":g.type;b[h][c[d]]=g;g.nth=Object.values(b[h]).length}}return b},add:function(a){var b=UI.dynamic({create:function(a){var b=$("<table>").css("width","auto");b.rows=[];var c={audio:{vheader:"Audio",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate","Channels","Samplerate","Language","Track index"]},video:{vheader:"Video",labels:["Codec", this.right.html(UI.format.duration(0.001*(a[b]-e),!0)));this.jitter.width(100*(a.jitter/(a[b]-a.firstms))+"%")}},getEntries:function(a){var b={},d=!c.includemeta.is(":checked"),e;for(e in a)d&&"meta"==a[e].type||(b[e]=a[e]);a={firstms:{min:1E9,max:-1E9},lastms:{min:1E9,max:-1E9}};for(e in b)d="nowms"in b[e]?"nowms":"lastms",a.firstms.min=Math.min(a.firstms.min,b[e].firstms),a.firstms.max=Math.max(a.firstms.max,b[e].firstms),a.lastms.min=Math.min(a.lastms.min,b[e][d]),a.lastms.max=Math.max(a.lastms.max,
"Duration","Jitter","Avg bitrate","Peak bitrate","Size","Framerate","Language","Track index","Has B-Frames"]},subtitle:{vheader:"Subtitles",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate","Language"]},meta:{vheader:"Metadata",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate"]}};b.headers=c[a].labels;b.header=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",c[a].labels.length+1).html($("<span>").text(c[a].vheader))).append($("<td>")); b[e][d]);c.timing.bounds=a;for(e in b)b[e].bounds=a;return b},update:function(a){var b=c.timing.bounds.firstms.max,d=c.timing.bounds.lastms.min;this.box.label.html(UI.format.duration(0.001*Math.abs(b-d),!0));this.box[0].style.setProperty("--ntracks",Object.keys(a).length);b<d?(this.box.css("margin-left",c.timing.mstopos(b)+"%"),this.box.css("margin-right",100-c.timing.mstopos(d)+"%"),this.box.left.html(UI.format.duration(0.001*b)),this.box.right.html(UI.format.duration(0.001*d)),this.box.removeClass("gap")):
var d=$("<tbody>").append(b.header),e;for(e in c[a].labels){var f=$("<tr>").attr("data-label",c[a].labels[e]).append($("<td>").text(c[a].labels[e]+":"));b.rows.push(f);d.append(f)}b.append(d);return b},add:{create:function(){var a=$("<td>"),c=[],d;for(d in b.headers)c.push($("<td>"));return{header:a,cells:c,customAdd:function(a){a.header.append(this.header);for(var b in this.cells)a.rows[b].append(this.cells[b])}}},update:function(a){a=function(a){function b(a,c){return"maxbps"in a?UI.format.bits(a[c]* (this.box.css("margin-left",c.timing.mstopos(d)+"%"),this.box.css("margin-right",100-c.timing.mstopos(b)+"%"),this.box.left.html(UI.format.duration(0.001*d)),this.box.right.html(UI.format.duration(0.001*b)),this.box.addClass("gap"));40>this.box.width()?this.box.addClass("toosmall"):this.box.removeClass("toosmall")}}),c.includemeta=$("<input>").attr("type","checkbox").click(function(){a.main.timing.update(a.main.timing.values_orig)}),c.append($("<label>").append($("<span>").text("Include metadata in graph:")).append(c.includemeta)).append($("<label>").append($("<span>").text("Track timing:"))).append(c.timing));
8,1):c=="maxbps"?UI.format.bits(a.bps*8,1):"unknown"}function c(a){if(a.firstms==0&&a.lastms==0)return"\u00ab No data \u00bb";var b="lastms";"nowms"in a&&(b="nowms");var d;d=UI.format.duration((a.lastms-a.firstms)/1E3);return d=d+("<br><span class=description>"+UI.format.duration(a.firstms/1E3)+" to "+UI.format.duration(a[b]/1E3)+"</span>")}switch(a.codec=="subtitle"?"subtitle":a.type){case "audio":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"), b.tracktable&&(c.tracks=UI.dynamic({create:function(){return $("<div>").addClass("tracks")},getEntries:function(a){var b={audio:{},video:{},subtitle:{},meta:{}};if(a){var c=Object.keys(a).sort(function(b,c){return a[b].idx-a[c].idx}),d;for(d in c){var e=a[c[d]],g=e.codec=="subtitle"?"subtitle":e.type;b[g][c[d]]=e;e.nth=Object.values(b[g]).length}}return b},add:function(a){var b=UI.dynamic({create:function(a){var b=$("<table>").css("width","auto");b.rows=[];var c={audio:{vheader:"Audio",labels:["Codec",
b(a,"bps"),b(a,"maxbps"),a.channels,UI.format.addUnit(UI.format.number(a.rate),"Hz"),"language"in a?a.language:"unknown",a.nth]};case "video":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),UI.format.addUnit(a.width,"x ")+UI.format.addUnit(a.height,"px"),a.fpks==0?"variable":UI.format.addUnit(UI.format.number(a.fpks/1E3),"fps"),"language"in a?a.language:"unknown",a.nth,"bframes"in a?"yes":"no"]};case "subtitle":return{header:"Track "+ "Duration","Jitter","Avg bitrate","Peak bitrate","Channels","Samplerate","Language","Track index"]},video:{vheader:"Video",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate","Size","Framerate","Language","Track index","Has B-Frames"]},subtitle:{vheader:"Subtitles",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate","Language"]},meta:{vheader:"Metadata",labels:["Codec","Duration","Jitter","Avg bitrate","Peak bitrate"]}};b.headers=c[a].labels;b.header=$("<tr>").addClass("header").append($("<td>").addClass("vheader").attr("rowspan",
a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),"language"in a?a.language:"unknown",a.nth]};case "meta":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps")]}}}(a);if(this.header.raw!=a.header){this.header.text(a.header);this.header.raw=a.header}for(var b in this.cells)if(this.cells[b].raw!=a.body[b]){this.cells[b].html(a.body[b]);this.cells[b].raw=a.body[b]}}},update:function(){Object.values(this._children).length? c[a].labels.length+1).html($("<span>").text(c[a].vheader))).append($("<td>"));var d=$("<tbody>").append(b.header),e;for(e in c[a].labels){var f=$("<tr>").attr("data-label",c[a].labels[e]).append($("<td>").text(c[a].labels[e]+":"));b.rows.push(f);d.append(f)}b.append(d);return b},add:{create:function(){var a=$("<td>"),c=[],d;for(d in b.headers)c.push($("<td>"));return{header:a,cells:c,customAdd:function(a){a.header.append(this.header);for(var b in this.cells)a.rows[b].append(this.cells[b])}}},update:function(a){a=
this.show():this.hide()}},a);return b},update:function(){}}),c.append($("<label>").append($("<span>").text("Track metadata:"))).append(c.tracks));return c},update:function(a){this.type.raw!=a.type&&(this.type.text("live"==a.type?"Live":"Video on demand"),this.type.raw=a.type);a.meta&&(this.buffer.raw!=a.meta.buffer_window&&(this.buffer.html(a.meta.buffer_window?UI.format.addUnit(UI.format.number(0.001*a.meta.buffer_window),"s"):"N/A"),this.buffer.raw=a.meta.buffer_window),this.jitter.raw!=a.meta.jitter&& function(a){function b(a,c){return"maxbps"in a?UI.format.bits(a[c]*8,1):c=="maxbps"?UI.format.bits(a.bps*8,1):"unknown"}function c(a){if(a.firstms==0&&a.lastms==0)return"\u00ab No data \u00bb";var b="lastms";"nowms"in a&&(b="nowms");var d;d=UI.format.duration((a.lastms-a.firstms)/1E3);return d=d+("<br><span class=description>"+UI.format.duration(a.firstms/1E3)+" to "+UI.format.duration(a[b]/1E3)+"</span>")}switch(a.codec=="subtitle"?"subtitle":a.type){case "audio":return{header:"Track "+a.idx,body:[a.codec,
(this.jitter.html(a.meta.jitter?UI.format.addUnit(UI.format.number(a.meta.jitter),"ms"):"N/A"),this.jitter.raw=a.meta.jitter),this.tracks.update(a.meta.tracks),this.timing.update(a.meta.tracks))}});a.audio=$("<table>").hide();a.video=$("<table>").hide();a.subtitle=$("<table>").hide();a.metadata=$("<table>").hide();return a.append(a.main).append(a.audio).append(a.video).append(a.subtitle).append(a.metadata)},update:function(a){this.main.update(a);this.raw_type!=a.type&&(this.attr("data-type",a.type), c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),a.channels,UI.format.addUnit(UI.format.number(a.rate),"Hz"),"language"in a?a.language:"unknown",a.nth]};case "video":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),UI.format.addUnit(a.width,"x ")+UI.format.addUnit(a.height,"px"),a.fpks==0?"variable":UI.format.addUnit(UI.format.number(a.fpks/1E3),"fps"),"language"in a?a.language:"unknown",a.nth,
this.raw_type=a.type)}}),l=!0;UI.sockets.ws.info_json.subscribe(function(b){d(b);l&&!b.error&&(l=!1,"live"==b.type&&UI.interval.set(function(){$.ajax({type:"GET",url:UI.sockets.http_host+"json_"+a+".js",success:d})},5E3))},a);return $("<section>").addClass("meta").append($("<h3>").text("Stream metadata")).append(c)},processes:function(a){var b=$("<div>").attr("onempty","None.").addClass("processes"),d={"Process type:":function(a){return $("<b>").text(a.process)},"Source:":function(a){var b=$("<span>").text(a.source); "bframes"in a?"yes":"no"]};case "subtitle":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps"),"language"in a?a.language:"unknown",a.nth]};case "meta":return{header:"Track "+a.idx,body:[a.codec,c(a),UI.format.addUnit(UI.format.number(a.jitter),"ms"),b(a,"bps"),b(a,"maxbps")]}}}(a);if(this.header.raw!=a.header){this.header.text(a.header);this.header.raw=a.header}for(var b in this.cells)if(this.cells[b].raw!=a.body[b]){this.cells[b].html(a.body[b]);
a.source_tracks&&a.source_tracks.length&&b.append($("<span>").addClass("description").text(" track "+a.source_tracks.slice(0,-2).concat(a.source_tracks.slice(-2).join(" and ")).join(", ")));return b},"Sink:":function(a){var b=$("<span>").text(a.sink);a.sink_tracks&&a.sink_tracks.length&&b.append($("<span>").addClass("description").text(" track "+a.sink_tracks.slice(0,-2).concat(a.sink_tracks.slice(-2).join(" and ")).join(", ")));return b},"Active for:":function(a){var b=(new Date).setSeconds((new Date).getSeconds()- this.cells[b].raw=a.body[b]}}},update:function(){Object.values(this._children).length?this.show():this.hide()}},a);return b},update:function(){}}),c.append($("<label>").append($("<span>").text("Track metadata:"))).append(c.tracks));return c},update:function(a){this.type.raw!=a.type&&(this.type.text("live"==a.type?"Live":"Video on demand"),this.type.raw=a.type);a.meta&&(this.buffer.raw!=a.meta.buffer_window&&(this.buffer.html(a.meta.buffer_window?UI.format.addUnit(UI.format.number(0.001*a.meta.buffer_window),
a.active_seconds);return $("<span>").append($("<span>").text(UI.format.duration(a.active_seconds))).append($("<span>").addClass("description").text(" since "+UI.format.time(b/1E3)))},"Pid:":function(a,b){return b},"Logs:":function(a){var b=$("<div>").text("None.");if(a.logs&&a.logs.length){b.html("").addClass("description").addClass("logs").css({maxHeight:"6em",display:"flex",flexFlow:"column-reverse nowrap"});for(var c in a.logs){var d=a.logs[c];b.prepend($("<div>").append(UI.format.time(d[0])+" ["+ "s"):"N/A"),this.buffer.raw=a.meta.buffer_window),this.jitter.raw!=a.meta.jitter&&(this.jitter.html(a.meta.jitter?UI.format.addUnit(UI.format.number(a.meta.jitter),"ms"):"N/A"),this.jitter.raw=a.meta.jitter),this.tracks.update(a.meta.tracks),this.timing.update(a.meta.tracks))}});a.audio=$("<table>").hide();a.video=$("<table>").hide();a.subtitle=$("<table>").hide();a.metadata=$("<table>").hide();return a.append(a.main).append(a.audio).append(a.video).append(a.subtitle).append(a.metadata)},update:function(a){this.main.update(a);
d[1]+"] "+d[2]))}}return b},"Additional info:":function(a){var b;if("ainfo"in a&&a.ainfo&&Object.keys(a.ainfo).length){b=$("<table>");var c=!1;a.process in mist.data.capabilities.processes&&(c=mist.data.capabilities.processes[a.process]);a.process+".exe"in mist.data.capabilities.processes&&(c=mist.data.capabilities.processes[a.process+".exe"]);for(var d in a.ainfo){var m=!1;c&&(c.ainfo&&c.ainfo[d])&&(m=c.ainfo[d]);m||(m={name:d});b.append($("<tr>").append($("<th>").text(m.name+":")).append($("<td>").html(a.ainfo[d]).append(m.unit? this.raw_type!=a.type&&(this.attr("data-type",a.type),this.raw_type=a.type)}}),j=!0;UI.sockets.ws.info_json.subscribe(function(b){e(b);j&&!b.error&&(j=!1,"live"==b.type&&UI.interval.set(function(){$.ajax({type:"GET",url:UI.sockets.http_host+"json_"+a+".js",success:e})},5E3))},a);return $("<section>").addClass("meta").append($("<h3>").text("Stream metadata")).append(c)},processes:function(a){var b=$("<div>").attr("onempty","None.").addClass("processes"),e={"Process type:":function(a){return $("<b>").text(a.process)},
$("<span>").addClass("unit").text(m.unit):"")))}}else b=$("<span>").addClass("description").text("N/A");return b}},c=UI.dynamic({create:function(){var a=$("<table>");a.rows={};for(var b in d){var c=$("<tr>").append($("<th>").text(b).css("vertical-align","top"));a.append(c);a.rows[b]=c}return a},add:{create:function(){var a=$("<div>").hide();a.remove=function(){for(var a in this.children)this.children[a].remove()};return a},add:{create:function(){return $("<td>").css("vertical-align","top")},update:function(a){this.html(a)}}, "Source:":function(a){var b=$("<span>").text(a.source);a.source_tracks&&a.source_tracks.length&&b.append($("<span>").addClass("description").text(" track "+a.source_tracks.slice(0,-2).concat(a.source_tracks.slice(-2).join(" and ")).join(", ")));return b},"Sink:":function(a){var b=$("<span>").text(a.sink);a.sink_tracks&&a.sink_tracks.length&&b.append($("<span>").addClass("description").text(" track "+a.sink_tracks.slice(0,-2).concat(a.sink_tracks.slice(-2).join(" and ")).join(", ")));return b},"Active for:":function(a){var b=
getEntries:function(a,b){var c={},f;for(f in d){var m=d[f](a,b);"object"==typeof m&&(m=m.prop("outerHTML"));c[f]=m}return c},update:function(){for(var a in this._children)this._children[a].moved||(c.rows[a].append(this._children[a]),this._children[a].moved=!0)}},update:function(a){Object.keys(a).length?c.parent().length||(c.find("tr").first().addClass("header"),b.append(c)):c.remove()}});UI.sockets.http.api.subscribe(function(a){a.proc_list&&c.update(a.proc_list)},{proc_list:a});return $("<section>").addClass("processes").append($("<h3>").text("Processes")).append(b)}, (new Date).setSeconds((new Date).getSeconds()-a.active_seconds);return $("<span>").append($("<span>").text(UI.format.duration(a.active_seconds))).append($("<span>").addClass("description").text(" since "+UI.format.time(b/1E3)))},"Pid:":function(a,b){return b},"Logs:":function(a){var b=$("<div>").text("None.");if(a.logs&&a.logs.length){b.html("").addClass("description").addClass("logs").css({maxHeight:"6em",display:"flex",flexFlow:"column-reverse nowrap"});for(var c in a.logs){var e=a.logs[c];b.prepend($("<div>").append(UI.format.time(e[0])+
triggers:function(a,b){var d=$("<div>").attr("onempty","None.").addClass("triggers");if(mist.data.config.triggers&&Object.keys(mist.data.config.triggers).length){var c=$("<table>").append($("<tbody>").append($("<tr>").addClass("header type").append($("<th>").text("Trigger name:"))).append($("<tr>").addClass("streams").append($("<th>").text("Applies to:"))).append($("<tr>").addClass("handler").append($("<th>").text("Handler:"))).append($("<tr>").addClass("blocking").append($("<th>").text("Blocking:"))).append($("<tr>").addClass("response").append($("<th>").text("Default response:"))).append($("<tr>").addClass("actions").append($("<th>").text("Actions:")))); " ["+e[1]+"] "+e[2]))}}return b},"Additional info:":function(a){var b;if("ainfo"in a&&a.ainfo&&Object.keys(a.ainfo).length){b=$("<table>");var c=!1;a.process in mist.data.capabilities.processes&&(c=mist.data.capabilities.processes[a.process]);a.process+".exe"in mist.data.capabilities.processes&&(c=mist.data.capabilities.processes[a.process+".exe"]);for(var e in a.ainfo){var m=!1;c&&(c.ainfo&&c.ainfo[e])&&(m=c.ainfo[e]);m||(m={name:e});b.append($("<tr>").append($("<th>").text(m.name+":")).append($("<td>").html(a.ainfo[e]).append(m.unit?
d.append(c);var e=0,l;for(l in mist.data.config.triggers){var i=mist.data.config.triggers[l],f;for(f in i){var m=i[f];if(!m.streams.length||!(0>m.streams.indexOf(a)&&0>m.streams.indexOf(a.split("+")[0]))){e++;for(var n=c.find("tr"),j=0;j<n.length;j++){var q=$("<td>");switch(j){case 0:q.append($("<b>").text(l));break;case 1:q.text(m.streams.length?m.streams.join(", "):"All streams");break;case 2:q.text(m.handler);break;case 3:q.text(m.sync?"Blocking":"Non-blocking");break;case 4:q.text(m["default"]? $("<span>").addClass("unit").text(m.unit):"")))}}else b=$("<span>").addClass("description").text("N/A");return b}},c=UI.dynamic({create:function(){var a=$("<table>");a.rows={};for(var b in e){var c=$("<tr>").append($("<th>").text(b).css("vertical-align","top"));a.append(c);a.rows[b]=c}return a},add:{create:function(){var a=$("<div>").hide();a.remove=function(){for(var a in this.children)this.children[a].remove()};return a},add:{create:function(){return $("<td>").css("vertical-align","top")},update:function(a){this.html(a)}},
m["default"]:"true");break;case 5:q.addClass("buttons").attr("data-index",f).attr("data-type",l).append($("<button>").text("Edit").click(function(){var a=$(this).closest(".buttons");UI.navto("Edit Trigger",a.attr("data-type")+","+a.attr("data-index"))})).append(1<m.streams.length?$("<button>").text("Remove from stream").click(function(){var c=$(this).closest(".buttons"),d=c.attr("data-type"),c=mist.data.config.triggers[d][c.attr("data-index")].streams,d=c.indexOf(a);0<=d?c.splice(d,1):(d=c.indexOf(a.split("+")[0]), getEntries:function(a,b){var c={},f;for(f in e){var m=e[f](a,b);"object"==typeof m&&(m=m.prop("outerHTML"));c[f]=m}return c},update:function(){for(var a in this._children)this._children[a].moved||(c.rows[a].append(this._children[a]),this._children[a].moved=!0)}},update:function(a){Object.keys(a).length?c.parent().length||(c.find("tr").first().addClass("header"),b.append(c)):c.remove()}});UI.sockets.http.api.subscribe(function(a){a.proc_list&&c.update(a.proc_list)},{proc_list:a});return $("<section>").addClass("processes").append($("<h3>").text("Processes")).append(b)},
0<=d&&c.splice(d,1));mist.send(function(){UI.navto(b,a)},{config:mist.data.config})}):$("<button>").text("Remove").click(function(){var c=$(this).closest(".buttons"),d=c.attr("data-type");confirm("Are you sure you want to delete this "+d+" trigger?")&&(mist.data.config.triggers[d].splice(c.attr("data-index"),1),0==mist.data.config.triggers[d].length&&delete mist.data.config.triggers[d],mist.send(function(){UI.navto(b,a)},{config:mist.data.config}))}))}n.eq(j).append(q)}}}}0==e&&c.remove()}return $("<section>").addClass("triggers").append($("<h3>").text("Triggers")).append($("<button>").text("Add a trigger").click(function(){UI.navto("Edit Trigger")})).append(d)}, triggers:function(a,b){var e=$("<div>").attr("onempty","None.").addClass("triggers");if(mist.data.config.triggers&&Object.keys(mist.data.config.triggers).length){var c=$("<table>").append($("<tbody>").append($("<tr>").addClass("header type").append($("<th>").text("Trigger name:"))).append($("<tr>").addClass("streams").append($("<th>").text("Applies to:"))).append($("<tr>").addClass("handler").append($("<th>").text("Handler:"))).append($("<tr>").addClass("blocking").append($("<th>").text("Blocking:"))).append($("<tr>").addClass("response").append($("<th>").text("Default response:"))).append($("<tr>").addClass("actions").append($("<th>").text("Actions:"))));
pushes:function(a){var b=$("<div>").addClass("pushes");b.html("Loading..");mist.send(function(d){function c(b,c){function d(a,b,c){a=""+("$"+a+" ");switch(Number(b)){case 0:a+="is true";break;case 1:a+="is false";break;case 2:a+="== "+c;break;case 3:a+="!= "+c;break;case 10:a+="> (numerical) "+c;break;case 11:a+=">= (numerical) "+c;break;case 12:a+="< (numerical) "+c;break;case 13:a+="<= (numerical) "+c;break;case 20:a+="> (lexical) "+c;break;case 21:a+=">= (lexical) "+c;break;case 22:a+="< (lexical) "+ e.append(c);var d=0,j;for(j in mist.data.config.triggers){var i=mist.data.config.triggers[j],f;for(f in i){var m=i[f];if(!m.streams.length||!(0>m.streams.indexOf(a)&&0>m.streams.indexOf(a.split("+")[0]))){d++;for(var n=c.find("tr"),k=0;k<n.length;k++){var q=$("<td>");switch(k){case 0:q.append($("<b>").text(j));break;case 1:q.text(m.streams.length?m.streams.join(", "):"All streams");break;case 2:q.text(m.handler);break;case 3:q.text(m.sync?"Blocking":"Non-blocking");break;case 4:q.text(m["default"]?
m["default"]:"true");break;case 5:q.addClass("buttons").attr("data-index",f).attr("data-type",j).append($("<button>").text("Edit").click(function(){var a=$(this).closest(".buttons");UI.navto("Edit Trigger",a.attr("data-type")+","+a.attr("data-index"))})).append(1<m.streams.length?$("<button>").text("Remove from stream").click(function(){var c=$(this).closest(".buttons"),d=c.attr("data-type"),c=mist.data.config.triggers[d][c.attr("data-index")].streams,d=c.indexOf(a);0<=d?c.splice(d,1):(d=c.indexOf(a.split("+")[0]),
0<=d&&c.splice(d,1));mist.send(function(){UI.navto(b,a)},{config:mist.data.config})}):$("<button>").text("Remove").click(function(){var c=$(this).closest(".buttons"),d=c.attr("data-type");confirm("Are you sure you want to delete this "+d+" trigger?")&&(mist.data.config.triggers[d].splice(c.attr("data-index"),1),0==mist.data.config.triggers[d].length&&delete mist.data.config.triggers[d],mist.send(function(){UI.navto(b,a)},{config:mist.data.config}))}))}n.eq(k).append(q)}}}}0==d&&c.remove()}return $("<section>").addClass("triggers").append($("<h3>").text("Triggers")).append($("<button>").text("Add a trigger").click(function(){UI.navto("Edit Trigger")})).append(e)},
pushes:function(a){var b=$("<div>").addClass("pushes");b.html("Loading..");mist.send(function(e){function c(b,c){function d(a,b,c){a=""+("$"+a+" ");switch(Number(b)){case 0:a+="is true";break;case 1:a+="is false";break;case 2:a+="== "+c;break;case 3:a+="!= "+c;break;case 10:a+="> (numerical) "+c;break;case 11:a+=">= (numerical) "+c;break;case 12:a+="< (numerical) "+c;break;case 13:a+="<= (numerical) "+c;break;case 20:a+="> (lexical) "+c;break;case 21:a+=">= (lexical) "+c;break;case 22:a+="< (lexical) "+
c;break;case 23:a+="<= (lexical) "+c;break;default:a+="comparison operator unknown"}return a}var e={Target:function(a){return"Automatic"==b?a[2]:4<=a.length&&a[2]!=a[3]?a[2]+$("<span>").html("&#187").addClass("unit").css("margin","0 0.5em").prop("outerHTML")+a[3]:a[2]},Conditions:!1,Statistics:!1,Actions:$("<div>").addClass("buttons")};"Automatic"==b?e.Conditions=function(a){var b=$("<div>");a[3]&&b.append($("<span>").text("schedule on "+(new Date(1E3*a[3])).toLocaleString()));5<=a.length&&a[4]&& c;break;case 23:a+="<= (lexical) "+c;break;default:a+="comparison operator unknown"}return a}var e={Target:function(a){return"Automatic"==b?a[2]:4<=a.length&&a[2]!=a[3]?a[2]+$("<span>").html("&#187").addClass("unit").css("margin","0 0.5em").prop("outerHTML")+a[3]:a[2]},Conditions:!1,Statistics:!1,Actions:$("<div>").addClass("buttons")};"Automatic"==b?e.Conditions=function(a){var b=$("<div>");a[3]&&b.append($("<span>").text("schedule on "+(new Date(1E3*a[3])).toLocaleString()));5<=a.length&&a[4]&&
b.append($("<span>").text("complete on "+(new Date(1E3*a[4])).toLocaleString()));8<=a.length&&a[5]&&b.append($("<span>").text("starts if "+d(a[5],a[6],a[7])));11<=a.length&&a[8]&&b.append($("<span>").text("stops if "+d(a[8],a[9],a[10])));return b.children().length?b.children():""}:e.Statistics={create:function(){return $("<div>").addClass("statistics")},add:{create:function(a){var b={active_seconds:"Active for: ",bytes:"Data transfered: ",mediatime:"Media time transfered: ",pkt_retrans_count:"Packets retransmitted: ", b.append($("<span>").text("complete on "+(new Date(1E3*a[4])).toLocaleString()));8<=a.length&&a[5]&&b.append($("<span>").text("starts if "+d(a[5],a[6],a[7])));11<=a.length&&a[8]&&b.append($("<span>").text("stops if "+d(a[8],a[9],a[10])));return b.children().length?b.children():""}:e.Statistics={create:function(){return $("<div>").addClass("statistics")},add:{create:function(a){var b={active_seconds:"Active for: ",bytes:"Data transfered: ",mediatime:"Media time transfered: ",pkt_retrans_count:"Packets retransmitted: ",
pkt_loss_count:"Packets lost: ",tracks:"Tracks: "};if(a in b)return $("<div>").attr("beforeifnotempty",b[a])},update:function(a,b){var c={active_seconds:UI.format.duration,bytes:UI.format.bytes,mediatime:function(a){return UI.format.duration(0.001*a)},tracks:function(a){return a.join(", ")},pkt_retrans_count:function(a){return UI.format.number(a||0)},pkt_loss_count:function(a){return UI.format.number(a||0)+" ("+UI.format.addUnit(UI.format.number(b.pkt_loss_perc||0),"%")+" over the last "+UI.format.addUnit(5, pkt_loss_count:"Packets lost: ",tracks:"Tracks: "};if(a in b)return $("<div>").attr("beforeifnotempty",b[a])},update:function(a,b){var c={active_seconds:UI.format.duration,bytes:UI.format.bytes,mediatime:function(a){return UI.format.duration(0.001*a)},tracks:function(a){return a.join(", ")},pkt_retrans_count:function(a){return UI.format.number(a||0)},pkt_loss_count:function(a){return UI.format.number(a||0)+" ("+UI.format.addUnit(UI.format.number(b.pkt_loss_perc||0),"%")+" over the last "+UI.format.addUnit(5,
"s")+")"}};this.id in c&&this.html(c[this.id](a))}}};e.Actions.append($("<button>").text("Automatic"==b?"Remove":"Stop").click(function(){var a=$(this).closest("table").data("values")[$(this).closest("td").attr("data-pushid")];if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+a[1]+" to "+a[2]))if($(this).html($("<span>").addClass("red").text("Automatic"==b?"Removing..":"Stopping..")),"Automatic"==b){var a=a.slice(1),c=this;mist.send(function(a){$(c).text("Done."); "s")+")"}};this._id in c&&this.html(c[this._id](a))}}};e.Actions.append($("<button>").text("Automatic"==b?"Remove":"Stop").click(function(){var a=$(this).closest("table").data("values")[$(this).closest("td").attr("data-pushid")];if(confirm("Are you sure you want to "+$(this).text().toLowerCase()+" this push?\n"+a[1]+" to "+a[2]))if($(this).html($("<span>").addClass("red").text("Automatic"==b?"Removing..":"Stopping..")),"Automatic"==b){var a=a.slice(1),c=this;mist.send(function(a){$(c).text("Done.");
j.update(a.push_auto_list)},{push_auto_remove:[a]})}else mist.send(function(){},{push_stop:[a[0]]})}));"Automatic"==b&&e.Actions.prepend($("<button>").text("Edit").click(function(){UI.navto("Start Push","auto_"+$(this).closest("td").attr("data-pushid"))}));var n=$("<div>").attr("onempty","None."),j;j="Automatic"==b?UI.dynamic({create:function(){var a=$("<table>"),b=$("<tr>");a.append($("<thead>").append(b));for(var c in e)if(e[c]){var d=$("<td>").addClass("header").text(c).attr("data-column",c);b.append(d)}return a}, k.update(a.push_auto_list)},{push_auto_remove:[a]})}else mist.send(function(){},{push_stop:[a[0]]})}));"Automatic"==b&&e.Actions.prepend($("<button>").text("Edit").click(function(){UI.navto("Start Push","auto_"+$(this).closest("td").attr("data-pushid"))}));var n=$("<div>").attr("onempty","None."),k;k="Automatic"==b?UI.dynamic({create:function(){var a=$("<table>"),b=$("<tr>");a.append($("<thead>").append(b));for(var c in e)if(e[c]){var d=$("<td>").addClass("header").text(c).attr("data-column",c);b.append(d)}return a},
add:{create:function(a){var b=$("<tr>");b._children={};for(var c in e)if(e[c]){var d=$("<td>").attr("data-pushid",a).attr("data-column",c);b._children[c]=d;b.append(d);e[c]instanceof jQuery?d.html(e[c].clone(!0)):"object"==typeof e[c]&&(d.dynamic=UI.dynamic(e[c]),d.html(d.dynamic))}return b},update:function(a){for(var b in e)if("function"==typeof e[b]){var c=e[b](a);c!=this._children[b].raw&&(this._children[b].html(c),this._children[b].raw=c)}}},update:function(a){this.data("values",a);if(Object.keys(a).length){this.parent().length|| add:{create:function(a){var b=$("<tr>");b._children={};for(var c in e)if(e[c]){var d=$("<td>").attr("data-pushid",a).attr("data-column",c);b._children[c]=d;b.append(d);e[c]instanceof jQuery?d.html(e[c].clone(!0)):"object"==typeof e[c]&&(d.dynamic=UI.dynamic(e[c]),d.html(d.dynamic))}return b},update:function(a){for(var b in e)if("function"==typeof e[b]){var c=e[b](a);c!=this._children[b].raw&&(this._children[b].html(c),this._children[b].raw=c)}}},update:function(a){this.data("values",a);if(Object.keys(a).length){this.parent().length||
n.append(this);var a=!1,b;for(b in this.children)if(""!=this.children[b]._children.Conditions.raw){a=!0;break}a?this.removeClass("hideConditioins"):this.addClass("hideConditions")}else this[0].parentNode&&this[0].parentNode.removeChild(this[0])},values:c,getEntries:function(b){var c={},d=!1;1==a.split("+").length&&(d=!0);for(var e in b){var f=b[e];f.unshift(Number(e));if(f[1]==a||!d&&f[1].split("+")[0]==a)c[f[0]]=f}return c}}):UI.dynamic({create:function(){var a=$("<table>");a.rows={};for(var b in e)if(e[b]){var c= n.append(this);var a=!1,b;for(b in this.children)if(""!=this.children[b]._children.Conditions.raw){a=!0;break}a?this.removeClass("hideConditioins"):this.addClass("hideConditions")}else this[0].parentNode&&this[0].parentNode.removeChild(this[0])},values:c,getEntries:function(b){var c={},d=!1;1==a.split("+").length&&(d=!0);for(var e in b){var f=b[e];f.unshift(Number(e));if(f[1]==a||!d&&f[1].split("+")[0]==a)c[f[0]]=f}return c}}):UI.dynamic({create:function(){var a=$("<table>");a.rows={};for(var b in e)if(e[b]){var c=
$("<tr>").addClass(b).append($("<th>").text(b+":"));a.append(c);a.rows[b]=c}a.rows.Target.addClass("header");return a},add:{create:function(a){var b=$("<tr>").text(a);b.children={};for(var c in e)if(e[c]){var d=$("<td>").attr("data-pushid",a);b.children[c]=d;b.append(d);e[c]instanceof jQuery?d.html(e[c].clone(!0)):"object"==typeof e[c]&&(d.dynamic=UI.dynamic(e[c]),d.html(d.dynamic))}var f=b.remove;b.remove=function(){for(var a in b.children)b.children[a].remove();return f.apply(this,arguments)};return b}, $("<tr>").addClass(b).append($("<th>").text(b+":"));a.append(c);a.rows[b]=c}a.rows.Target.addClass("header");return a},add:{create:function(a){var b=$("<tr>").text(a);b.children={};for(var c in e)if(e[c]){var d=$("<td>").attr("data-pushid",a);b.children[c]=d;b.append(d);e[c]instanceof jQuery?d.html(e[c].clone(!0)):"object"==typeof e[c]&&(d.dynamic=UI.dynamic(e[c]),d.html(d.dynamic))}var f=b.remove;b.remove=function(){for(var a in b.children)b.children[a].remove();return f.apply(this,arguments)};return b},
update:function(a){for(var b in e)if("function"==typeof e[b]){var c=e[b](a);c!=this.children[b].raw&&(this.children[b].html(c),this.children[b].raw=c)}else"Statistics"==b&&e[b]&&5<=a.length&&(c={},6<=a.length&&(c=a[5]),c.logs=a[4],this.children[b].dynamic.update(c))}},update:function(a){this.data("values",a);if(Object.keys(a).length){this.parent().length||n.append(this);for(var b in this.children)if(!this.children[b].moved){for(var c in this.children[b].children)this.rows[c].append(this.children[b].children[c]); update:function(a){for(var b in e)if("function"==typeof e[b]){var c=e[b](a);c!=this.children[b].raw&&(this.children[b].html(c),this.children[b].raw=c)}else"Statistics"==b&&e[b]&&5<=a.length&&(c={},6<=a.length&&(c=a[5]),c.logs=a[4],this.children[b].dynamic.update(c))}},update:function(a){this.data("values",a);if(Object.keys(a).length){this.parent().length||n.append(this);for(var b in this.children)if(!this.children[b].moved){for(var c in this.children[b].children)this.rows[c].append(this.children[b].children[c]);
this.children[b].moved=!0;this.children[b][0].parentNode.removeChild(this.children[b][0])}}else this[0].parentNode&&this[0].parentNode.removeChild(this[0])},values:c,getEntries:function(b){var c={},d=!1;1==a.split("+").length&&(d=!0);for(var e in b){var f=b[e];if(f[1]==a||!d&&f[1].split("+")[0]==a)c[f[0]]=f}return c}});n.update=function(){return j.update.apply(j,arguments)};return n}b.html("");b.append($("<h4>").text("Automatic pushes"));b.append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push", this.children[b].moved=!0;this.children[b][0].parentNode.removeChild(this.children[b][0])}}else this[0].parentNode&&this[0].parentNode.removeChild(this[0])},values:c,getEntries:function(b){var c={},d=!1;1==a.split("+").length&&(d=!0);for(var e in b){var f=b[e];if(f[1]==a||!d&&f[1].split("+")[0]==a)c[f[0]]=f}return c}});n.update=function(){return k.update.apply(k,arguments)};return n}b.html("");b.append($("<h4>").text("Automatic pushes"));b.append($("<button>").text("Add an automatic push").click(function(){UI.navto("Start Push",
"auto")}));b.append(c("Automatic",d.push_auto_list));b.append($("<h4>").text("Active pushes"));b.append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));var e=c("Manual",d.push_list);b.append(e);UI.sockets.http.api.subscribe(function(a){e.update(a.push_list)},{push_list:1})},{push_auto_list:1,push_list:1});return $("<section>").addClass("pushes").append($("<h3>").text("Pushes and recordings")).append(b)},logs:function(a){var b=$("<div>").attr("onempty","None.").addClass("logs"), "auto")}));b.append(c("Automatic",e.push_auto_list));b.append($("<h4>").text("Active pushes"));b.append($("<button>").text("Start a push").click(function(){UI.navto("Start Push")}));var d=c("Manual",e.push_list);b.append(d);UI.sockets.http.api.subscribe(function(a){d.update(a.push_list)},{push_list:1})},{push_auto_list:1,push_list:1});return $("<section>").addClass("pushes").append($("<h3>").text("Pushes and recordings")).append(b)},logs:function(a){var b=$("<div>").attr("onempty","None.").addClass("logs"),
d=!1;UI.sockets.ws.active_streams.subscribe(function(c,e){if("log"==c){var l=b[0].scrollTop>=b[0].scrollHeight-b[0].clientHeight;if(!(""!=e[3]&&e[3]!=a.split("+")[0])&&"ACCS"!=e[1]){var i=$("<div>").attr("data-debuglevel",e[1]).html($("<span>").addClass("description").text(UI.format.dateTime(e[0]))).append($("<span>").text(e[3])).append($("<span>").text(e[1]+":")).append($("<span>").text(e[2]));b.append(i);l&&(b[0].scrollTop=b[0].scrollHeight);if(d)try{l=d.document.scrollingElement.scrollTop>=d.document.scrollingElement.scrollHeight- e=!1;UI.sockets.ws.active_streams.subscribe(function(c,d){if("log"==c){var j=b[0].scrollTop>=b[0].scrollHeight-b[0].clientHeight;if(!(""!=d[3]&&d[3]!=a.split("+")[0])&&"ACCS"!=d[1]){var i=$("<div>").attr("data-debuglevel",d[1]).html($("<span>").addClass("description").text(UI.format.dateTime(d[0]))).append($("<span>").text(d[3])).append($("<span>").text(d[1]+":")).append($("<span>").text(d[2]));b.append(i);j&&(b[0].scrollTop=b[0].scrollHeight);if(e)try{j=e.document.scrollingElement.scrollTop>=e.document.scrollingElement.scrollHeight-
d.document.scrollingElement.clientHeight,d.document.write(i[0].outerHTML),l&&(d.document.scrollingElement.scrollTop=d.document.scrollingElement.scrollHeight)}catch(f){}}}});return $("<section>").addClass("logs").append($("<h3>").text("MistServer logs")).append($("<button>").text("Open raw").click(function(){d=window.open("","MistServer logs for "+a);d.document.write("<html><head><title>MistServer logs for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>body{padding-left:2em;text-indent:-2em;}body>*>*:not(:last-child):not(:empty){padding-right:.5em;}.description{font-size:.9em;color:#777}</style></head><body>'); e.document.scrollingElement.clientHeight,e.document.write(i[0].outerHTML),j&&(e.document.scrollingElement.scrollTop=e.document.scrollingElement.scrollHeight)}catch(f){}}}});return $("<section>").addClass("logs").append($("<h3>").text("MistServer logs")).append($("<button>").text("Open raw").click(function(){e=window.open("","MistServer logs for "+a);e.document.write("<html><head><title>MistServer logs for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>body{padding-left:2em;text-indent:-2em;}body>*>*:not(:last-child):not(:empty){padding-right:.5em;}.description{font-size:.9em;color:#777}</style></head><body>');
d.document.write(b[0].innerHTML);d.document.scrollingElement.scrollTop=d.document.scrollingElement.scrollHeight})).append(b)},accesslogs:function(a){var b=$("<div>").attr("onempty","None.").addClass("accesslogs"),d=!1;UI.sockets.ws.active_streams.subscribe(function(c,e){if("access"==c){var l=b[0].scrollTop>=b[0].scrollHeight-b[0].clientHeight;if(!(""!=e[2]&&e[2]!=a.split("+")[0])){var i=$("<div>").html($("<span>").addClass("description").text(UI.format.dateTime(e[0]))).append($("<span>").attr("beforeifnotempty", e.document.write(b[0].innerHTML);e.document.scrollingElement.scrollTop=e.document.scrollingElement.scrollHeight})).append(b)},accesslogs:function(a){var b=$("<div>").attr("onempty","None.").addClass("accesslogs"),e=!1;UI.sockets.ws.active_streams.subscribe(function(c,d){if("access"==c){var j=b[0].scrollTop>=b[0].scrollHeight-b[0].clientHeight;if(!(""!=d[2]&&d[2]!=a.split("+")[0])){var i=$("<div>").html($("<span>").addClass("description").text(UI.format.dateTime(d[0]))).append($("<span>").attr("beforeifnotempty",
"Token: ").attr("title",e[1]).css("max-width","10em").text(e[1])).append($("<span>").attr("beforeifnotempty","Connector: ").text(e[3])).append($("<span>").attr("beforeifnotempty","Hostname: ").text(e[4])).append($("<span>").attr("beforeifnotempty","Connected for: ").html(UI.format.duration(e[5]))).append($("<span>").html("\u2191"+UI.format.bytes(e[6]))).append($("<span>").html("\u2193"+UI.format.bytes(e[7]))).append($("<span>").attr("beforeifnotempty","Tags: ").text(e[8]));b.append(i);l&&(b[0].scrollTop= "Token: ").attr("title",d[1]).css("max-width","10em").text(d[1])).append($("<span>").attr("beforeifnotempty","Connector: ").text(d[3])).append($("<span>").attr("beforeifnotempty","Hostname: ").text(d[4])).append($("<span>").attr("beforeifnotempty","Connected for: ").html(UI.format.duration(d[5]))).append($("<span>").html("\u2191"+UI.format.bytes(d[6]))).append($("<span>").html("\u2193"+UI.format.bytes(d[7]))).append($("<span>").attr("beforeifnotempty","Tags: ").text(d[8]));b.append(i);j&&(b[0].scrollTop=
b[0].scrollHeight);if(d)try{l=d.document.scrollingElement.scrollTop>=d.document.scrollingElement.scrollHeight-d.document.scrollingElement.clientHeight,d.document.write(i[0].outerHTML),l&&(d.document.scrollingElement.scrollTop=d.document.scrollingElement.scrollHeight)}catch(f){}}}});return $("<section>").addClass("accesslogs").append($("<h3>").text("Access logs")).append($("<button>").text("Open raw").click(function(){d=window.open("","MistServer access logs for "+a);d.document.write("<html><head><title>MistServer access logs for '"+ b[0].scrollHeight);if(e)try{j=e.document.scrollingElement.scrollTop>=e.document.scrollingElement.scrollHeight-e.document.scrollingElement.clientHeight,e.document.write(i[0].outerHTML),j&&(e.document.scrollingElement.scrollTop=e.document.scrollingElement.scrollHeight)}catch(f){}}}});return $("<section>").addClass("accesslogs").append($("<h3>").text("Access logs")).append($("<button>").text("Open raw").click(function(){e=window.open("","MistServer access logs for "+a);e.document.write("<html><head><title>MistServer access logs for '"+
a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>body{padding-left:2em;text-indent:-2em;}body>*>*:not(:last-child):not(:empty){padding-right:.5em;}.description{font-size:.9em;color:#777}[beforeifnotempty]:not(:empty):before{content:attr(beforeifnotempty);color:#777}</style></head><body>');d.document.write(b[0].innerHTML);d.document.scrollingElement.scrollTop=d.document.scrollingElement.scrollHeight})).append(b)},preview:function(a,b){var d=$("<section>").addClass("preview"); a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>body{padding-left:2em;text-indent:-2em;}body>*>*:not(:last-child):not(:empty){padding-right:.5em;}.description{font-size:.9em;color:#777}[beforeifnotempty]:not(:empty):before{content:attr(beforeifnotempty);color:#777}</style></head><body>');e.document.write(b[0].innerHTML);e.document.scrollingElement.scrollTop=e.document.scrollingElement.scrollHeight})).append(b)},preview:function(a,b){var e=$("<section>").addClass("preview");
b||(window.mv={},b=mv);UI.sockets.http.player(function(){mistPlay(a,{target:d[0],host:UI.sockets.http_host,skin:"dev",loop:true,MistVideoObject:b})},function(a){$preciew_cont.html(a)});return d},playercontrols:function(a,b){function d(){function b(a){return d.UI.buildStructure.call(d.UI,a)}var d=a.reference,i=b({"if":function(){return this.playerName&&this.source},then:{type:"container",classes:["mistvideo-description"],style:{display:"block"},children:[{type:"playername",style:{display:"inline"}}, b||(window.mv={},b=mv);UI.sockets.http.player(function(){mistPlay(a,{target:e[0],host:UI.sockets.http_host,skin:{inherit:"dev",colors:{accent:"var(--accentColor)"}},loop:true,MistVideoObject:b})},function(a){$preciew_cont.html(a)});return e},playercontrols:function(a,b){function e(){function b(a){return e.UI.buildStructure.call(e.UI,a)}var e=a.reference,i=b({"if":function(){return this.playerName&&this.source},then:{type:"container",classes:["mistvideo-description"],style:{display:"block"},children:[{type:"playername",
{type:"text",text:"is playing",style:{margin:"0 0.2em"}},{type:"mimetype"}]}}),f=b({type:"container",classes:["mistvideo-column","mistvideo-devcontrols"],children:[{type:"text",text:"Player control"},{type:"container",classes:["mistvideo-devbuttons"],style:{"flex-wrap":"wrap"},children:[{"if":function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"Reload video",onclick:function(){this.player.api.load()}}},{type:"button",title:"Build MistVideo again", style:{display:"inline"}},{type:"text",text:"is playing",style:{margin:"0 0.2em"}},{type:"mimetype"}]}}),f=b({type:"container",classes:["mistvideo-column","mistvideo-devcontrols"],children:[{type:"text",text:"Player control"},{type:"container",classes:["mistvideo-devbuttons"],style:{"flex-wrap":"wrap"},children:[{"if":function(){return!(!this.player||!this.player.api)},then:{type:"button",title:"Reload the video source",label:"Reload video",onclick:function(){this.player.api.load()}}},{type:"button",
label:"Reload player",onclick:function(){this.reload()}},{type:"button",title:"Switch to the next available player and source combination",label:"Try next combination",onclick:function(){this.nextCombo()}}]},{type:"forcePlayer"},{type:"forceType"},{type:"forceSource"}]}),m=b({type:"decodingIssues",style:{"max-width":"30em","flex-flow":"column nowrap"}}),n=b({type:"log"}),j=$("<button>").text("Open raw").css({display:"block",marginTop:"0.333em"}).click(function(){var a=d.stream;tab=window.open("", title:"Build MistVideo again",label:"Reload player",onclick:function(){this.reload()}},{type:"button",title:"Switch to the next available player and source combination",label:"Try next combination",onclick:function(){this.nextCombo()}}]},{type:"forcePlayer"},{type:"forceType"},{type:"forceSource"}]}),m=b({type:"decodingIssues",style:{"max-width":"30em","flex-flow":"column nowrap"}}),n=b({type:"log"}),k=$("<button>").text("Open raw").css({display:"block",marginTop:"0.333em"}).click(function(){var a=
"Player logs for "+a);tab.document.write("<html><head><title>Player logs for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>.timestamp{color:#777;font-size:0.9em;}</style></head><body>');tab.document.write(n.lastChild.outerHTML);tab.document.scrollingElement.scrollTop=tab.document.scrollingElement.scrollHeight});n.insertBefore(j[0],n.children[0]);c.html($("<div>").append($("<div>").append($("<h3>").addClass("title").text("MistPlayer")).append(i)).append(f).append(m)).append(n)} e.stream;tab=window.open("","Player logs for "+a);tab.document.write("<html><head><title>Player logs for '"+a+'\'</title><meta http-equiv="content-type" content="application/json; charset=utf-8"><style>.timestamp{color:#777;font-size:0.9em;}</style></head><body>');tab.document.write(n.lastChild.outerHTML);tab.document.scrollingElement.scrollTop=tab.document.scrollingElement.scrollHeight});n.insertBefore(k[0],n.children[0]);c.html($("<div>").append($("<div>").append($("<h3>").addClass("title").text("MistPlayer")).append(i)).append(f).append(m)).append(n)}
var c=$("<section>").addClass("controls").addClass("mistvideo").html($("<h3>").text("MistPlayer")).append($("<p>").text("Waiting for player.."));b||(b=$(".dashboard"));$("link#devcss").length||document.head.appendChild($("<link>").attr("rel","stylesheet").attr("type","text/css").attr("href",UI.sockets.http_host+"skins/dev.css").attr("id","devcss")[0]);a&&(a.reference&&a.reference.skin)&&d();b[0].addEventListener("initialized",function(){d()});b[0].addEventListener("initializedFailed",function(){d()}); var c=$("<section>").addClass("controls").addClass("mistvideo").addClass("input_container").html($("<h3>").text("MistPlayer")).append($("<p>").text("Waiting for player.."));b||(b=$(".dashboard"));$("link#devcss").length||document.head.appendChild($("<link>").attr("rel","stylesheet").attr("type","text/css").attr("href",UI.sockets.http_host+"skins/dev.css").attr("id","devcss")[0]);a&&(a.reference&&a.reference.skin)&&e();b[0].addEventListener("initialized",function(){e()});b[0].addEventListener("initializedFailed",
return c},embedurls:function(a,b,d){function c(){function b(a){switch(typeof a){case "string":return $.isNumeric(a)?a:'"'+a+'"';case "object":return JSON.stringify(a);default:return a}}q&&UI.stored.saveOpt("embedoptions",h);for(var c=a+"_",e=12,f="";e--;){var i;i=Math.floor(62*Math.random());i=10>i?i:36>i?String.fromCharCode(i+55):String.fromCharCode(i+61);f+=i}var c=c+f,e=['target: document.getElementById("'+c+'")'],k;for(k in h)"prioritize_type"==k?h[k]&&""!=h[k]&&e.push("forcePriority: "+JSON.stringify({source:[["type", function(){e()});return c},embedurls:function(a,b,e){function c(){function b(a){switch(typeof a){case "string":return $.isNumeric(a)?a:'"'+a+'"';case "object":return JSON.stringify(a);default:return a}}q&&UI.stored.saveOpt("embedoptions",g);for(var c=a+"_",d=12,f="";d--;){var l;l=Math.floor(62*Math.random());l=10>l?l:36>l?String.fromCharCode(l+55):String.fromCharCode(l+61);f+=l}var c=c+f,d=['target: document.getElementById("'+c+'")'],i;for(i in g)"prioritize_type"==i?g[i]&&""!=g[i]&&d.push("forcePriority: "+
[h[k]]]]})):"monitor_action"==k?h[k]&&""!=h[k]&&"nextCombo"==h[k]&&e.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 }'):h[k]!=g[k]&&(null!=h[k]&&("object"!=typeof h[k]||JSON.stringify(h[k])!=JSON.stringify(g[k])))&&e.push(k+": "+b(h[k]));k=[];k.push('<div class="mistvideo" id="'+ JSON.stringify({source:[["type",[g[i]]]]})):"monitor_action"==i?g[i]&&""!=g[i]&&"nextCombo"==g[i]&&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 }'):g[i]!=h[i]&&(null!=g[i]&&("object"!=typeof g[i]||JSON.stringify(g[i])!=JSON.stringify(h[i])))&&d.push(i+": "+b(g[i]));i=[];i.push('<div class="mistvideo" id="'+
c+'">');k.push(" <noscript>");k.push(' <a href="'+n+j+'.html" target="_blank">');k.push(" Click here to play this video");k.push(" </a>");k.push(" </noscript>");k.push(" <script>");k.push(" var a = function(){");k.push(' mistPlay("'+a+'",{');k.push(" "+e.join(",\n "));k.push(" });");k.push(" };");k.push(" if (!window.mistplayers) {");k.push(' var p = document.createElement("script");');d.HTTPS.length?(k.push(' if (location.protocol == "https:") { p.src = "'+ c+'">');i.push(" <noscript>");i.push(' <a href="'+n+k+'.html" target="_blank">');i.push(" Click here to play this video");i.push(" </a>");i.push(" </noscript>");i.push(" <script>");i.push(" var a = function(){");i.push(' mistPlay("'+a+'",{');i.push(" "+d.join(",\n "));i.push(" });");i.push(" };");i.push(" if (!window.mistplayers) {");i.push(' var p = document.createElement("script");');e.HTTPS.length?(i.push(' if (location.protocol == "https:") { p.src = "'+
("https://"==parseURL(n).protocol?n:d.HTTPS[0])+'player.js" } '),k.push(' else { p.src = "'+("http://"==parseURL(n).protocol?n:d.HTTP[0])+'player.js" } ')):k.push(' p.src = "'+n+'player.js"');k.push(" document.head.appendChild(p);");k.push(" p.onload = a;");k.push(" }");k.push(" else { a(); }");k.push(" <\/script>");k.push("</div>");return k.join("\n")}function e(d){UI.sockets.ws.info_json.subscribe(function(a){if("error"==a.type)if(d==n)e(b);else throw a;else{if("source"in ("https://"==parseURL(n).protocol?n:e.HTTPS[0])+'player.js" } '),i.push(' else { p.src = "'+("http://"==parseURL(n).protocol?n:e.HTTP[0])+'player.js" } ')):i.push(' p.src = "'+n+'player.js"');i.push(" document.head.appendChild(p);");i.push(" p.onload = a;");i.push(" }");i.push(" else { a(); }");i.push(" <\/script>");i.push("</div>");return i.join("\n")}function d(e){UI.sockets.ws.info_json.subscribe(function(a){if("error"==a.type)if(e==n)d(b);else throw a;else{if("source"in
a&&(!q||a.source.length)){var g=d==n?!1:n,f=[],i=l.find(".field.forceType"),j=l.find(".field.prioritize_type");g&&(g=g.replace(parseURL(g).protocol,""),f.push($("<div>").addClass("orange").html('Warning: the provided base URL <a href="'+n+'">'+n+"</a> could not be reached. These links are my best guess but will probably not work properly.").css({margin:"0.5em 0",width:"45em","word-break":"normal"})));for(var m in a.source){var s=a.source[m],C=UI.humanMime(s.type),u=s.url;g&&(u=parseURL(s.url).protocol+ a&&(!q||a.source.length)){var f=e==n?!1:n,h=[],i=j.find(".field.forceType"),k=j.find(".field.prioritize_type");f&&(f=f.replace(parseURL(f).protocol,""),h.push($("<div>").addClass("orange").html('Warning: the provided base URL <a href="'+n+'">'+n+"</a> could not be reached. These links are my best guess but will probably not work properly.").css({margin:"0.5em 0",width:"45em","word-break":"normal"})));for(var m in a.source){var u=a.source[m],D=UI.humanMime(u.type),G=u.url;f&&(G=parseURL(u.url).protocol+
g+s.relurl);var D=u.match(/[\?\&]tkn=\d+\&?/);D&&(D=D[0],u=u.replace(D,"?"==D[0]&&"&"==D.slice(-1)?"?":"&"==D.slice(-1)?"&":""));f.push({label:C?C+" <span class=description>("+s.type+")</span>":UI.format.capital(s.type),type:"str",value:u,readonly:!0,qrcode:!0,clipboard:!0});C=UI.humanMime(s.type);0==i.children('option[value="'+s.type+'"]').length&&(i.append($("<option>").text(C?C+" ("+s.type+")":UI.format.capital(s.type)).val(s.type)),j.append($("<option>").text(C?C+" ("+s.type+")":UI.format.capital(s.type)).val(s.type)))}i.val(h.forceType); f+u.relurl);var v=G.match(/[\?\&]tkn=\d+\&?/);v&&(v=v[0],G=G.replace(v,"?"==v[0]&&"&"==v.slice(-1)?"?":"&"==v.slice(-1)?"&":""));h.push({label:D?D+" <span class=description>("+u.type+")</span>":UI.format.capital(u.type),type:"str",value:G,readonly:!0,qrcode:!0,clipboard:!0});D=UI.humanMime(u.type);0==i.children('option[value="'+u.type+'"]').length&&(i.append($("<option>").text(D?D+" ("+u.type+")":UI.format.capital(u.type)).val(u.type)),k.append($("<option>").text(D?D+" ("+u.type+")":UI.format.capital(u.type)).val(u.type)))}i.val(g.forceType);
j.val(h.prioritize_type);o.html(UI.buildUI(f));q=!0}if("meta"in a&&"tracks"in a.meta){var g={},v;for(v in a.meta.tracks)if(f=a.meta.tracks[v],"subtitle"==f.codec&&(f.type="subtitle"),!("audio"!=f.type&&"video"!=f.type&&"subtitle"!=f.type))f.type in g||(g[f.type]="subtitle"==f.type?[]:[["","Autoselect "+f.type]]),g[f.type].push([f.trackid,UI.format.capital(f.type)+" track "+(g[f.type].length+("subtitle"==f.type?1:0))]);k.html("");if(Object.keys(g).length){k.closest("label").show();var a=["audio","video", k.val(g.prioritize_type);o.html(UI.buildUI(h));q=!0}if("meta"in a&&"tracks"in a.meta){var f={},w;for(w in a.meta.tracks)if(h=a.meta.tracks[w],"subtitle"==h.codec&&(h.type="subtitle"),!("audio"!=h.type&&"video"!=h.type&&"subtitle"!=h.type))h.type in f||(f[h.type]="subtitle"==h.type?[]:[["","Autoselect "+h.type]]),f[h.type].push([h.trackid,UI.format.capital(h.type)+" track "+(f[h.type].length+("subtitle"==h.type?1:0))]);l.html("");if(Object.keys(f).length){l.closest("label").show();var a=["audio","video",
"subtitle"],A;for(A in a)if(v=a[A],g[v]&&g[v].length){f=$("<select>").attr("data-type",v).css("flex-grow","1").change(function(){""==$(this).val()?delete h.setTracks[$(this).attr("data-type")]:h.setTracks[$(this).attr("data-type")]=$(this).val();$(".embed_code").setval(c(h))});k.append(f);"subtitle"==v?g[v].unshift(["","No "+v]):g[v].push([-1,"No "+v]);for(var L in g[v])f.append($("<option>").val(g[v][L][0]).text(g[v][L][1]));v in h.setTracks&&(f.val(h.setTracks[v]),null==f.val()&&(f.val(""),delete h.setTracks[v], "subtitle"],P;for(P in a)if(w=a[P],f[w]&&f[w].length){h=$("<select>").attr("data-type",w).css("flex-grow","1").change(function(){""==$(this).val()?delete g.setTracks[$(this).attr("data-type")]:g.setTracks[$(this).attr("data-type")]=$(this).val();$(".embed_code").setval(c(g))});l.append(h);"subtitle"==w?f[w].unshift(["","No "+w]):f[w].push([-1,"No "+w]);for(var C in f[w])h.append($("<option>").val(f[w][C][0]).text(f[w][C][1]));w in g.setTracks&&(h.val(g.setTracks[w]),null==h.val()&&(h.val(""),delete g.setTracks[w],
$(".embed_code").setval(c(h))))}}else k.closest("label").hide()}}},a,d.replace(/^http/,"ws")+"json_"+encodeURIComponent(a)+".js",!1,"?inclzero=1")}var l=$("<section>").addClass("embedurls"),i=$("<datalist>").attr("id","urlhints"),f=d.HTTPS.concat(d.HTTP),m;for(m in f)i.append($("<option>").val(f[m]));var n=otherhost.host?otherhost.host:f.length?f[0]:b;l.append($("<span>").addClass("input_container").append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Use base URL:")).append($("<span>").addClass("field_container").append($("<input>").attr("type", $(".embed_code").setval(c(g))))}}else l.closest("label").hide()}}},a,e.replace(/^http/,"ws")+"json_"+encodeURIComponent(a)+".js",!1,"?inclzero=1")}var j=$("<section>").addClass("embedurls"),i=$("<datalist>").attr("id","urlhints"),f=e.HTTPS.concat(e.HTTP),m;for(m in f)i.append($("<option>").val(f[m]));var n=otherhost.host?otherhost.host:f.length?f[0]:b;j.append($("<span>").addClass("input_container").append($("<label>").addClass("UIelement").append($("<span>").addClass("label").text("Use base URL:")).append($("<span>").addClass("field_container").append($("<input>").attr("type",
"text").addClass("field").val(n).attr("list","urlhints")).append(i).append($("<span>").addClass("unit").append($("<button>").text("Apply").click(function(){otherhost.host=$(this).closest("label").find("input").val();"/"!=otherhost.host.slice(-1)&&(otherhost.host+="/");UI.navto("Embed",a)}))))));var j=encodeURIComponent(a),q=!1,g={forcePlayer:"",forceType:"",controls:!0,autoplay:!0,loop:!1,muted:!1,fillSpace:!1,poster:"",urlappend:"",setTracks:{}},h=$.extend({},g),i=UI.stored.getOpts();"embedoptions"in "text").addClass("field").val(n).attr("list","urlhints")).append(i).append($("<span>").addClass("unit").append($("<button>").text("Apply").click(function(){otherhost.host=$(this).closest("label").find("input").val();"/"!=otherhost.host.slice(-1)&&(otherhost.host+="/");UI.navto("Embed",a)}))))));var k=encodeURIComponent(a),q=!1,h={forcePlayer:"",forceType:"",controls:!0,autoplay:!0,loop:!1,muted:!1,fillSpace:!1,poster:"",urlappend:"",setTracks:{}},g=$.extend({},h),i=UI.stored.getOpts();"embedoptions"in
i&&(h=$.extend(h,i.embedoptions,!0),"object"!=typeof h.setTracks&&(h.setTracks={}));i={};switch(h.controls){case "stock":i.controls="stock";break;case !0:i.controls=1;break;case !1:i.controls=0}var f=c(h),k=$("<div>").text("Loading..").css("display","flex").css("flex-flow","column nowrap"),o=$("<span>").text("Loading..").css("word-break","break-all");if(mistplayers){var s=[["","Automatic"]];for(m in mistplayers)s.push([m,mistplayers[m].name])}l.append(UI.buildUI([$("<h3>").text("Urls"),{label:"Stream info json", i&&(g=$.extend(g,i.embedoptions,!0),"object"!=typeof g.setTracks&&(g.setTracks={}));i={};switch(g.controls){case "stock":i.controls="stock";break;case !0:i.controls=1;break;case !1:i.controls=0}var f=c(g),l=$("<div>").text("Loading..").css("display","flex").css("flex-flow","column nowrap"),o=$("<span>").text("Loading..").css("word-break","break-all");if(mistplayers){var u=[["","Automatic"]];for(m in mistplayers)u.push([m,mistplayers[m].name])}j.append(UI.buildUI([$("<h3>").text("Urls"),{label:"Stream info json",
type:"str",value:n+"json_"+j+".js",readonly:!0,clipboard:!0,help:"Information about this stream as a json page."},{label:"Stream info script",type:"str",value:n+"info_"+j+".js",readonly:!0,clipboard:!0,help:"This script loads information about this stream into a mistvideo javascript object."},{label:"HTML page",type:"str",value:n+j+".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:f, type:"str",value:n+"json_"+k+".js",readonly:!0,clipboard:!0,help:"Information about this stream as a json page."},{label:"Stream info script",type:"str",value:n+"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:n+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:f,
rows:f.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:h, rows:f.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:g,
index:"prioritize_type"},classes:["prioritize_type"],"function":function(){if(q){h.prioritize_type=$(this).getval();$(".embed_code").setval(c(h))}},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:h,index:"forceType"},classes:["forceType"],"function":function(){if(q){h.forceType=$(this).getval();$(".embed_code").setval(c(h))}},help:"Only use this particular source."},{label:"Force player", index:"prioritize_type"},classes:["prioritize_type"],"function":function(){if(q){g.prioritize_type=$(this).getval();$(".embed_code").setval(c(g))}},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:g,index:"forceType"},classes:["forceType"],"function":function(){if(q){g.forceType=$(this).getval();$(".embed_code").setval(c(g))}},help:"Only use this particular source."},{label:"Force player",
type:"select",select:s,pointer:{main:h,index:"forcePlayer"},classes:["forcePlayer"],"function":function(){if(q){h.forcePlayer=$(this).getval();$(".embed_code").setval(c(h))}},help:"Only use this particular player."},{label:"Controls",type:"select",select:[["1","MistServer Controls"],["stock","Player controls"],["0","None"]],pointer:{main:i,index:"controls"},"function":function(){h.controls=$(this).getval()==1;switch($(this).getval()){case 0:h.controls=false;break;case 1:h.controls=true;break;case "stock":h.controls= type:"select",select:u,pointer:{main:g,index:"forcePlayer"},classes:["forcePlayer"],"function":function(){if(q){g.forcePlayer=$(this).getval();$(".embed_code").setval(c(g))}},help:"Only use this particular player."},{label:"Controls",type:"select",select:[["1","MistServer Controls"],["stock","Player controls"],["0","None"]],pointer:{main:i,index:"controls"},"function":function(){g.controls=$(this).getval()==1;switch($(this).getval()){case 0:g.controls=false;break;case 1:g.controls=true;break;case "stock":g.controls=
"stock"}$(".embed_code").setval(c(h))},help:"The type of controls that should be shown."},{label:"Autoplay",type:"checkbox",pointer:{main:h,index:"autoplay"},"function":function(){h.autoplay=$(this).getval();$(".embed_code").setval(c(h))},help:"Whether or not the video should play as the page is loaded."},{label:"Loop",type:"checkbox",pointer:{main:h,index:"loop"},"function":function(){h.loop=$(this).getval();$(".embed_code").setval(c(h))},help:"If the video should restart when the end is reached."}, "stock"}$(".embed_code").setval(c(g))},help:"The type of controls that should be shown."},{label:"Autoplay",type:"checkbox",pointer:{main:g,index:"autoplay"},"function":function(){g.autoplay=$(this).getval();$(".embed_code").setval(c(g))},help:"Whether or not the video should play as the page is loaded."},{label:"Loop",type:"checkbox",pointer:{main:g,index:"loop"},"function":function(){g.loop=$(this).getval();$(".embed_code").setval(c(g))},help:"If the video should restart when the end is reached."},
{label:"Start muted",type:"checkbox",pointer:{main:h,index:"muted"},"function":function(){h.muted=$(this).getval();$(".embed_code").setval(c(h))},help:"If the video should restart when the end is reached."},{label:"Fill available space",type:"checkbox",pointer:{main:h,index:"fillSpace"},"function":function(){h.fillSpace=$(this).getval();$(".embed_code").setval(c(h))},help:"The video will fit the available space in its container, even if the video stream has a smaller resolution."},{label:"Poster", {label:"Start muted",type:"checkbox",pointer:{main:g,index:"muted"},"function":function(){g.muted=$(this).getval();$(".embed_code").setval(c(g))},help:"If the video should restart when the end is reached."},{label:"Fill available space",type:"checkbox",pointer:{main:g,index:"fillSpace"},"function":function(){g.fillSpace=$(this).getval();$(".embed_code").setval(c(g))},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:h,index:"poster"},"function":function(){h.poster=$(this).getval();$(".embed_code").setval(c(h))},help:"URL to an image that is displayed when the video is not playing."},{label:"Video URL addition",type:"str",pointer:{main:h,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(){h.urlappend=$(this).getval();$(".embed_code").setval(c(h))}},{label:"Preselect tracks", type:"str",pointer:{main:g,index:"poster"},"function":function(){g.poster=$(this).getval();$(".embed_code").setval(c(g))},help:"URL to an image that is displayed when the video is not playing."},{label:"Video URL addition",type:"str",pointer:{main:g,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(){g.urlappend=$(this).getval();$(".embed_code").setval(c(g))}},{label:"Preselect tracks",
type:"DOMfield",DOMfield:k,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:h,index:"monitor_action"},"function":function(){h.monitor_action=$(this).getval();$(".embed_code").setval(c(h))},help:"What the player should do when playback is poor."},$("<h3>").text("Protocol stream urls"),o]));e(n);return l}}},sockets:{http_host:null,http:{api:{command:{},listeners:[], type:"DOMfield",DOMfield:l,help:"Pre-select these tracks."},{label:"Monitoring action",type:"select",select:[["","Ask the viewer what to do"],["nextCombo","Try the next source / player combination"]],pointer:{main:g,index:"monitor_action"},"function":function(){g.monitor_action=$(this).getval();$(".embed_code").setval(c(g))},help:"What the player should do when playback is poor."},$("<h3>").text("Protocol stream urls"),o]));d(n);return j}}},sockets:{http_host:null,http:{api:{command:{},listeners:[],
interval:!1,get:function(){var a=this;mist.send(function(b){for(var d in a.listeners)a.listeners[d](b)},a.command)},init:function(){var a=this;a.get();a.interval=UI.interval.set(function(){a.get()},5E3)},subscribe:function(a,b){this.command=Object.assign(this.command,b);this.listeners.push(a);(!this.interval||!(this.interval in UI.interval.list))&&this.init()}},player:function(a,b){if(mistPlay)a();else{UI.sockets.http_host||b("Could not find player.js: MistServer host unknown");var d=UI.sockets.http_host+ interval:!1,get:function(){var a=this;mist.send(function(b){for(var e in a.listeners)a.listeners[e](b)},a.command)},init:function(){var a=this;a.get();a.interval=UI.interval.set(function(){a.get()},5E3)},subscribe:function(a,b){this.command=Object.assign(this.command,b);this.listeners.push(a);(!this.interval||!(this.interval in UI.interval.list))&&this.init()}},player:function(a,b){if(mistPlay)a();else{UI.sockets.http_host||b("Could not find player.js: MistServer host unknown");var e=UI.sockets.http_host+
"player.js";$.ajax({type:"GET",url:d,success:function(){a()},error:function(){b("Error while retrieving player.js from "+d)}})}}},ws:{info_json:{children:{},init:function(a){var b=UI.websockets.create(a);this.children[a]={ws:!1,listeners:[]};this.children[a].ws=b;var d=this;b.onmessage=function(b){b=JSON.parse(b.data);if(a in d.children)for(var c in d.children[a].listeners)d.children[a].listeners[c](b)};b.onerror=function(b){if(a in d.children)for(var c in d.children[a].listeners)d.children[a].listeners[c](b)}; "player.js";$.ajax({type:"GET",url:e,success:function(){a()},error:function(){b("Error while retrieving player.js from "+e)}})}}},ws:{info_json:{children:{},init:function(a){var b=UI.websockets.create(a);this.children[a]={ws:!1,messages:[],listeners:[]};this.children[a].ws=b;var e=this;b.onmessage=function(b){b=JSON.parse(b.data);if(a in e.children){e.children[a].messages.push(b);for(var c in e.children[a].listeners)e.children[a].listeners[c](b)}};b.onerror=function(b){if(a in e.children)for(var c in e.children[a].listeners)e.children[a].listeners[c](b)};
b.cleanup=function(){delete d.children[a];b.onclose=function(){};b.onmessage=function(){}};var c=b.close;b.close=function(){b.cleanup();return c.apply(this,arguments)};b.onclose=function(){b.cleanup()}},subscribe:function(a,b,d,c){if(!a)throw"Callback function not specified.";if(!b&&!d)throw"Stream name not specified.";c||(c="");d||(d=UI.sockets.http_host.replace(/^http/,"ws")+"json_"+encodeURIComponent(b)+".js"+c);(!(d in this.children)||1<this.children[d].ws.readyState)&&this.init(d);this.children[d].listeners.push(a)}}, b.cleanup=function(){delete e.children[a];b.onclose=function(){};b.onmessage=function(){}};var c=b.close;b.close=function(){b.cleanup();return c.apply(this,arguments)};b.onclose=function(){b.cleanup()}},subscribe:function(a,b,e,c){if(!a)throw"Callback function not specified.";if(!b&&!e)throw"Stream name not specified.";c||(c="");if(!e){if(!UI.sockets.http_host){var d=this,j=arguments;UI.modules.stream.findMist(function(){d.subscribe.apply(d,j)});return}e=UI.sockets.http_host.replace(/^http/,"ws")+
active_streams:{ws:!1,listeners:[],init:function(){var a=parseURL(mist.user.host),a=parseURL(mist.user.host,{pathname:a.pathname.replace(/\/api$/,"")+"/ws",search:"?logs=100&accs=100&streams=1"});this.ws=a=UI.websockets.create(a.full.replace(/^http/,"ws"));var b=this;a.authState=0;a.onmessage=function(a){var c=JSON.parse(a.data),a=c[0],c=c[1];if("auth"==a)!0===c?this.authState=2:!1===c?(this.send(JSON.stringify(["auth",{password:MD5(mist.user.password+mist.user.authstring),username:mist.user.name}])), "json_"+encodeURIComponent(b)+".js"+c}(!(e in this.children)||1<this.children[e].ws.readyState)&&this.init(e);for(var i in this.children[e].messages)a(this.children[e].messages[i]);this.children[e].listeners.push(a)}},active_streams:{ws:!1,listeners:[],messages:[],init:function(){var a=parseURL(mist.user.host),a=parseURL(mist.user.host,{pathname:a.pathname.replace(/\/api$/,"")+"/ws",search:"?logs=100&accs=100&streams=1"}),b=UI.websockets.create(a.full.replace(/^http/,"ws"));this.ws=b;var e=this;b.authState=
this.authState=1):"object"==typeof c&&("challenge"in c?(this.send(JSON.stringify(["auth",{password:MD5(mist.user.password+c.challenge),username:mist.user.name}])),this.authState=1):"status"in c&&"OK"==c.status&&(this.authState=2));else for(var e in b.listeners)b.listeners[e](a,c)};a.onclose=function(){b.listeners=[];b.ws=!1}},subscribe:function(a){(!this.ws||1<this.ws.readyState)&&this.init();this.listeners.push(a)}}}}};"origin"in location||(location.origin=location.protocol+"//");var host; 0;b.onmessage=function(a){var b=JSON.parse(a.data),a=b[0],b=b[1];if("auth"==a)!0===b?this.authState=2:!1===b?(this.send(JSON.stringify(["auth",{password:MD5(mist.user.password+mist.user.authstring),username:mist.user.name}])),this.authState=1):"object"==typeof b&&("challenge"in b?(this.send(JSON.stringify(["auth",{password:MD5(mist.user.password+b.challenge),username:mist.user.name}])),this.authState=1):"status"in b&&"OK"==b.status&&(this.authState=2));else{e.messages.push([a,b]);for(var j in e.listeners)e.listeners[j](a,
b)}};b.onclose=function(){e.listeners=[];e.messages=[];e.ws=!1};b.keepAlive=function(){setTimeout(function(){1==b.readyState&&(b.send(""),b.keepAlive())},200)};b.onopen=function(){b.keepAlive()}},subscribe:function(a){(!this.ws||1<this.ws.readyState)&&this.init();for(var b in this.messages)a(this.messages[b][0],this.messages[b][1]);this.listeners.push(a)}}}}};"origin"in location||(location.origin=location.protocol+"//");var host;
host="file://"==location.origin?"http://localhost:4242/api":location.origin+location.pathname.replace(/\/+$/,"")+"/api"; 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,d){var b=b||{},d=d||{},d=$.extend(true,{timeOut:3E4,sendData:b},d),c={authorize:{password:mist.user.authstring?MD5(mist.user.password+mist.user.authstring):"",username:mist.user.name}};$.extend(true,c,b);log("Send",$.extend(true,{},b));var e={url:mist.user.host,type:"POST",data:{command:JSON.stringify(c)},dataType:"jsonp",crossDomain:true,timeout:d.timeout*1E3,async:true,error:function(c,e,m){console.warn("connection failed :(", var mist={data:{},user:{name:"",password:"",host:host},send:function(a,b,e){var b=b||{},e=e||{},e=$.extend(true,{timeOut:3E4,sendData:b},e),c={authorize:{password:mist.user.authstring?MD5(mist.user.password+mist.user.authstring):"",username:mist.user.name}};$.extend(true,c,b);log("Send",$.extend(true,{},b));var d={url:mist.user.host,type:"POST",data:{command:JSON.stringify(c)},dataType:"jsonp",crossDomain:true,timeout:e.timeout*1E3,async:true,error:function(c,d,m){console.warn("connection failed :(",
m);delete mist.user.loggedin;if(!d.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,d)}))}UI.navto("Login")}, m);delete mist.user.loggedin;if(!e.hide){switch(d){case "timeout":d=$("<i>").text("The connection timed out. ");break;case "abort":d=$("<i>").text("The connection was aborted. ");break;default:d=$("<i>").text(d+". ").css("text-transform","capitalize")}$("#message").addClass("red").text("An error occurred while attempting to communicate with MistServer:").append($("<br>")).append($("<span>").text(d)).append($("<a>").text("Send server request again").click(function(){mist.send(a,b,e)}))}UI.navto("Login")},
success:function(e,f,m){log("Receive",$.extend(true,{},e),"as reply to",d.sendData);mist.lastrequest=m;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 f=$.extend({},e),m=["config","capabilities","ui_settings","LTS","active_streams","browse","log","totals","bandwidth","variable_list","external_writer_list"], success:function(d,f,m){log("Receive",$.extend(true,{},d),"as reply to",e.sendData);mist.lastrequest=m;delete mist.user.loggedin;switch(d.authorize.status){case "OK":if("streams"in d)if(d.streams)if("incomplete list"in d.streams){delete d.streams["incomplete list"];$.extend(mist.data.streams,d.streams)}else mist.data.streams=d.streams;else mist.data.streams={};var f=$.extend({},d),m=["config","capabilities","ui_settings","LTS","active_streams","browse","log","totals","bandwidth","variable_list","external_writer_list"],
l;for(l in f)m.indexOf(l)==-1&&delete f[l];if("bandwidth"in c&&!("bandwidth"in e))f.bandwidth=null;d.sendData.capabilities&&d.sendData.capabilities!==true&&delete f.capabilities;$.extend(mist.data,f);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()/ j;for(j in f)m.indexOf(j)==-1&&delete f[j];if("bandwidth"in c&&!("bandwidth"in d))f.bandwidth=null;e.sendData.capabilities&&e.sendData.capabilities!==true&&delete f.capabilities;$.extend(mist.data,f);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){f=e.log[e.log.length-1];UI.elements.connection.msg.append($("<br>")).append($("<span>").text("Last log entry: "+UI.format.time(f[0])+" ["+f[1]+"] "+f[2]))}if("totals"in e){f=function(a,b,c){var d;d=function(){for(var a in c.fields)e[c.fields[a]].push([l,0])};var e={},f;for(f in c.fields)e[c.fields[f]]=[];var i=0,l;if(c.data){if(c.start>mist.data.config.time-600){l=(mist.data.config.time-600)*1E3;d();l=c.start*1E3;d()}else l=c.start*1E3;for(f in c.data){if(f==0){l=c.start*1E3;var m= 1E3));if(d.log){f=d.log[d.log.length-1];UI.elements.connection.msg.append($("<br>")).append($("<span>").text("Last log entry: "+UI.format.time(f[0])+" ["+f[1]+"] "+f[2]))}if("totals"in d){f=function(a,b,c){var d;d=function(){for(var a in c.fields)e[c.fields[a]].push([j,0])};var e={},f;for(f in c.fields)e[c.fields[f]]=[];var i=0,j;if(c.data){if(c.start>mist.data.config.time-600){j=(mist.data.config.time-600)*1E3;d();j=c.start*1E3;d()}else j=c.start*1E3;for(f in c.data){if(f==0){j=c.start*1E3;var m=
0}else{l=l+c.interval[m][1]*1E3;c.interval[m][0]--;if(c.interval[m][0]<=0){m++;m<c.interval.length-1&&(i=i+2)}}if(i%2==1){d();i--}for(var n in c.data[f])e[c.fields[n]].push([l,c.data[f][n]]);if(i){d();i--}}if(mist.data.config.time-c.end>20){d();l=(mist.data.config.time-15)*1E3;d()}}else{l=(mist.data.config.time-600)*1E3;d();l=(mist.data.config.time-15)*1E3;d()}d=e;stream=a?a.join(" "):"all_streams";protocol=b?b.join("_"):"all_protocols";stream in mist.data.totals||(mist.data.totals[stream]={});protocol in 0}else{j=j+c.interval[m][1]*1E3;c.interval[m][0]--;if(c.interval[m][0]<=0){m++;m<c.interval.length-1&&(i=i+2)}}if(i%2==1){d();i--}for(var n in c.data[f])e[c.fields[n]].push([j,c.data[f][n]]);if(i){d();i--}}if(mist.data.config.time-c.end>20){d();j=(mist.data.config.time-15)*1E3;d()}}else{j=(mist.data.config.time-600)*1E3;d();j=(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)f(b.totals.streams,b.totals.protocols,e.totals);else for(l in e.totals)f(b.totals[l].streams,b.totals[l].protocols,e.totals[l])}a&&a(e,d);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== mist.data.totals[stream]||(mist.data.totals[stream][protocol]={});$.extend(mist.data.totals[stream][protocol],d)};mist.data.totals={};if("fields"in d.totals)f(b.totals.streams,b.totals.protocols,d.totals);else for(j in d.totals)f(b.totals[j].streams,b.totals[j].protocols,d.totals[j])}a&&a(d,e);break;case "CHALL":if(d.authorize.challenge==mist.user.authstring){mist.user.password!=""&&UI.elements.connection.msg.text("The credentials you provided are incorrect.").addClass("red");UI.navto("Login")}else if(mist.user.password==
"")UI.navto("Login");else{mist.user.authstring=e.authorize.challenge;mist.send(a,b,d);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,d);break;default:UI.navto("Login")}}};d.hide||UI.elements.connection.msg.removeClass("red").text("Data sent, waiting for a reply..").append($("<br>")).append($("<a>").text("Cancel request").click(function(){l.abort()})); "")UI.navto("Login");else{mist.user.authstring=d.authorize.challenge;mist.send(a,b,e);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,e);break;default:UI.navto("Login")}}};e.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 l=$.ajax(e)},inputMatch:function(a,b){if(typeof a=="undefined")return false;typeof a=="string"&&(a=[a]);for(var d in a){var c=a[d].replace(/[^\w\s]/g,"\\$&"),c=c.replace(/\\\*/g,".*");if(RegExp("^(?:[a-zA-Z]:)?"+c+"(?:\\?[^\\?]*)?$","i").test(b))return true}return false},convertBuildOptions:function(a,b){function d(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 var j=$.ajax(d)},inputMatch:function(a,b){if(typeof a=="undefined")return false;typeof a=="string"&&(a=[a]);for(var e in a){var c=a[e].replace(/[^\w\s]/g,"\\$&"),c=c.replace(/\\\*/g,".*");if(RegExp("^(?:[a-zA-Z]:)?"+c+"(?:\\?[^\\?]*)?$","i").test(b))return true}return false},convertBuildOptions:function(a,b){function e(a,c,e){var f={label:UI.format.capital(e.name?e.name:c),pointer:{main:b,index:c},validate:[]};d[a]=="required"&&(!("default"in e)||e["default"]=="")&&f.validate.push("required");if("default"in
d){f.placeholder=d["default"];if(d.type=="select")for(var i in d.select)if(d.select[i][0]==d["default"]){f.placeholder=d.select[i][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("datalist"in d)f.datalist=d.datalist;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= e){f.placeholder=e["default"];if(e.type=="select")for(var i in e.select)if(e.select[i][0]==e["default"]){f.placeholder=e.select[i][1];break}}if("help"in e)f.help=e.help;if("unit"in e)f.unit=e.unit;if("placeholder"in e)f.placeholder=e.placeholder;if("datalist"in e)f.datalist=e.datalist;if("type"in e)switch(e.type){case "int":f.type="int";if("max"in e)f.max=e.max;if("min"in e)f.min=e.min;break;case "uint":f.type="int";f.min=0;if("max"in e)f.max=e.max;if("min"in e)f.min=Math.max(f.min,e.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")>=0&&f.select.unshift(["","placeholder"in f?"Default ("+f.placeholder+")":""]);break;case "sublist":f.type="sublist";f.saveas={};f.itemLabel=d.itemLabel;f.sublist=mist.convertBuildOptions(d,f.saveas);break;case "group":a=mist.convertBuildOptions({optional:d.options},b);a=a.slice(1);"help"in d&&a.unshift($("<span>").addClass("description").text(d.help));"name"in d&& "radioselect";f.radioselect=e.radioselect;break;case "select":f.type="select";f.select=e.select.slice(0);f.validate.indexOf("required")>=0&&f.select.unshift(["","placeholder"in f?"Default ("+f.placeholder+")":""]);break;case "sublist":f.type="sublist";f.saveas={};f.itemLabel=e.itemLabel;f.sublist=mist.convertBuildOptions(e,f.saveas);break;case "group":a=mist.convertBuildOptions({optional:e.options},b);a=a.slice(1);"help"in e&&a.unshift($("<span>").addClass("description").text(e.help));"name"in e&&
a.unshift($("<b>").text(d.name));return $("<div>").addClass("itemsettings").append(UI.buildUI(a));case "bool":f.type="checkbox";break;case "unixtime":f.type="unix";break;case "json":case "debug":case "inputlist":f.type=d.type;break;default:f.type="str"}else f.type="checkbox";if("format"in d)switch(d.format){case "set_or_unset":f.postSave=function(){var a=$(this).data("pointer");a.main[a.index]||delete a.main[a.index]}}"influences"in d?f["function"]=function(){var a=$(this).closest(".UIelement"),b= a.unshift($("<b>").text(e.name));return $("<div>").addClass("itemsettings").append(UI.buildUI(a));case "bool":f.type="checkbox";break;case "unixtime":f.type="unix";break;case "json":case "debug":case "inputlist":f.type=e.type;break;default:f.type="str"}else f.type="checkbox";if("format"in e)switch(e.format){case "set_or_unset":f.postSave=function(){var a=$(this).data("pointer");a.main[a.index]||delete a.main[a.index]}}"influences"in e?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"]= 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 e&&(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>"; function(){for(var a=$(this).closest(".input_container"),b=$(this).getval(),c=0;c<e.disable.length;c++){var d=a.find('.field[name="'+e.disable[c]+'"]').closest(".UIelement");if(d.length)b==""?d[0].style.display="":d.hide()}});if("dependent"in e)f.dependent=e.dependent;if("value"in e)f.value=e.value;if("validate"in e){f.validate=f.validate.concat(e.validate);if(e.validate.indexOf("track_selector_parameter")>-1)f.help="<div>"+e.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} if(e.validate.indexOf("track_selector")>-1)f.help="<div>"+e.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 c=[],e=["required","optional"];"desc"in a&&c.push({type:"help",help:a.desc});for(var l in e)if(a[e[l]]){c.push($("<h4>").text(UI.format.capital(e[l])+" parameters"));var i=Object.keys(a[e[l]]);"sort"in a&&i.sort(function(b,c){return(""+a[e[l]][b][a.sort]).localeCompare(a[e[l]][c][a.sort])});for(var f in i){var m=i[f],n=a[e[l]][m];if(Array.isArray(n))for(var j in n)c.push(d(l,m,n[j]));else c.push(d(l,m,n))}}return c},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,b){var d= var c=[],d=["required","optional"];"desc"in a&&c.push({type:"help",help:a.desc});for(var j in d)if(a[d[j]]){c.push($("<h4>").text(UI.format.capital(d[j])+" parameters"));var i=Object.keys(a[d[j]]);"sort"in a&&i.sort(function(b,c){return(""+a[d[j]][b][a.sort]).localeCompare(a[d[j]][c][a.sort])});for(var f in i){var m=i[f],n=a[d[j]][m];if(Array.isArray(n))for(var k in n)c.push(e(j,m,n[k]));else c.push(e(j,m,n))}}return c},stored:{get:function(){return mist.data.ui_settings||{}},set:function(a,b){var e=
this.get();d[a]=b;mist.send(function(){},{ui_settings:d})},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){}} this.get();e[a]=b;mist.send(function(){},{ui_settings:e})},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= $.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"); [];$(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");
break;case "json":try{b=JSON.parse($(this).val())}catch(d){b=null}break;case "bitmask":b=0;$(this).find("input").each(function(){$(this).prop("checked")&&(b=b+Number($(this).val()))})}return b}; break;case "json":try{b=JSON.parse($(this).val())}catch(e){b=null}break;case "bitmask":b=0;$(this).find("input").each(function(){$(this).prop("checked")&&(b=b+Number($(this).val()))})}return b};
$.fn.setval=function(a){var b=$(this).data("opts");$(this).val(a);if(b&&"type"in b)switch(b.type){case "span":$(this).html(a);break;case "checkbox":$(this).prop("checked",a);break;case "geolimited":case "hostlimited":b=$(this).closest(".field_container").data("subUI");if(typeof a=="undefined"||a.length==0)a="-";b.blackwhite.val(a.charAt(0));var a=a.substr(1).split(" "),d;for(d in a)b.values.append(b.prototype.clone(true).val(a[d]));b.blackwhite.trigger("change");break;case "radioselect":if(typeof a== $.fn.setval=function(a){var b=$(this).data("opts");$(this).val(a);if(b&&"type"in b)switch(b.type){case "span":$(this).html(a).attr("title",a);break;case "checkbox":$(this).prop("checked",a);break;case "geolimited":case "hostlimited":b=$(this).closest(".field_container").data("subUI");if(typeof a=="undefined"||a.length==0)a="-";b.blackwhite.val(a.charAt(0));var a=a.substr(1).split(" "),e;for(e in a)b.values.append(b.prototype.clone(true).val(a[e]));b.blackwhite.trigger("change");break;case "radioselect":if(typeof a==
"undefined")return $(this);d=$(this).find('label > input[type=radio][value="'+a[0]+'"]').prop("checked",true).parent();a.length>1&&d.children("select").val(a[1]);break;case "checklist":b=$(this).find(".checklist input[type=checkbox]").prop("checked",false);for(d in a)b.filter('[name="'+a[d]+'"]').prop("checked",true);break;case "unix":if(typeof a!="undefined"&&a!=""&&a!==null){a=new Date(Math.round(a)*1E3);a.setMinutes(a.getMinutes()-a.getTimezoneOffset());a=a.toISOString();$(this).val(a.split("Z")[0])}break; "undefined")return $(this);e=$(this).find('label > input[type=radio][value="'+a[0]+'"]').prop("checked",true).parent();a.length>1&&e.children("select").val(a[1]);break;case "checklist":b=$(this).find(".checklist input[type=checkbox]").prop("checked",false);for(e in a)b.filter('[name="'+a[e]+'"]').prop("checked",true);break;case "unix":if(typeof a!="undefined"&&a!=""&&a!==null){a=new Date(Math.round(a)*1E3);a.setMinutes(a.getMinutes()-a.getTimezoneOffset());a=a.toISOString();$(this).val(a.split("Z")[0])}break;
case "selectinput":a===null&&(a="");var c=false;for(d in b.selectinput){var e;typeof b.selectinput[d]=="string"?e=b.selectinput[d]:typeof b.selectinput[d][0]=="string"&&(e=b.selectinput[d][0]);if(e==a){$(this).children("select").first().val(a);c=true;break}}if(!c){$(this).children("label").first().find(".field_container").children().first().setval(a);$(this).children("select").first().val("CUSTOM").trigger("change")}break;case "inputlist":typeof a=="string"&&(a=[a]);for(d in a){b=$(this).data("newitem")(); case "selectinput":a===null&&(a="");var c=false;for(e in b.selectinput){var d;typeof b.selectinput[e]=="string"?d=b.selectinput[e]:typeof b.selectinput[e][0]=="string"&&(d=b.selectinput[e][0]);if(d==a){$(this).children("select").first().val(a);c=true;break}}if(!c){$(this).children("label").first().find(".field_container").children().first().setval(a);$(this).children("select").first().val("CUSTOM").trigger("change")}break;case "inputlist":typeof a=="string"&&(a=[a]);for(e in a){b=$(this).data("newitem")();
b.find(".field").setval(a[d]);$(this).append(b)}$(this).append($(this).children().first());break;case "sublist":var l=$(this),b=$(this).children(".curvals");b.html("");if(a&&a.length)for(d in a){var c=$.extend(true,{},a[d]),i=function(a){for(var b in a)b.slice(0,6)=="x-LSP-"?delete a[b]:typeof a[b]=="object"&&i(a[b])};i(c);b.append($("<div>").addClass("subitem").append($("<span>").addClass("itemdetails").text(a[d]["x-LSP-name"]?a[d]["x-LSP-name"]:JSON.stringify(c)).attr("title",JSON.stringify(c,null, b.find(".field").setval(a[e]);$(this).append(b)}$(this).append($(this).children().first());break;case "sublist":var j=$(this),b=$(this).children(".curvals");b.html("");if(a&&a.length)for(e in a){var c=$.extend(true,{},a[e]),i=function(a){for(var b in a)b.slice(0,6)=="x-LSP-"?delete a[b]:typeof a[b]=="object"&&i(a[b])};i(c);b.append($("<div>").addClass("subitem").append($("<span>").addClass("itemdetails").text(a[e]["x-LSP-name"]?a[e]["x-LSP-name"]:JSON.stringify(c)).attr("title",JSON.stringify(c,null,
2))).append($("<button>").addClass("move").text("^").attr("title","Move item up").click(function(){var a=$(this).parent().index();if(a!=0){var b=l.getval();b.splice(a-1,0,b.splice(a,1)[0]);l.setval(b)}})).append($("<button>").text("Edit").click(function(){var a=$(this).parent().index(),b=$(this).closest(".field");b.data("build")(Object.assign({},b.getval()[a]),a)})).append($("<button>").text("x").attr("title","Remove item").click(function(a){var b=$(this).parent().index(),c=l.data("savelist");c.splice(b, 2))).append($("<button>").addClass("move").text("^").attr("title","Move item up").click(function(){var a=$(this).parent().index();if(a!=0){var b=j.getval();b.splice(a-1,0,b.splice(a,1)[0]);j.setval(b)}})).append($("<button>").text("Edit").click(function(){var a=$(this).parent().index(),b=$(this).closest(".field");b.data("build")(Object.assign({},b.getval()[a]),a)})).append($("<button>").text("x").attr("title","Remove item").click(function(a){var b=$(this).parent().index(),c=j.data("savelist");c.splice(b,
1);l.setval(c);a.preventDefault()})))}else b.append("None.");l.data("savelist",a);break;case "json":$(this).val(a===null?"":JSON.stringify(a,null,2));break;case "bitmask":c=$(this).data("opts").bitmask;b=$(this).find("input");for(d in c){$el=b.eq(d);(a&c[d][0])==c[d][0]?$el.attr("checked","checked"):$el.removeAttr("checked")}}$(this).trigger("change");return $(this)}; 1);j.setval(c);a.preventDefault()})))}else b.append("None.");j.data("savelist",a);break;case "json":$(this).val(a===null?"":JSON.stringify(a,null,2));break;case "bitmask":c=$(this).data("opts").bitmask;b=$(this).find("input");for(e in c){$el=b.eq(e);(a&c[e][0])==c[e][0]?$el.attr("checked","checked"):$el.removeAttr("checked")}}$(this).trigger("change");return $(this)};
function parseURL(a,b){var d;if("URL"in window&&typeof window.URL=="function")try{d=new URL(a)}catch(c){d=document.createElement("a");d.href=a}else{d=document.createElement("a");d.href=a}if(b)for(var e in b)d[e]=b[e];return{full:d.href,protocol:d.protocol+"//",host:d.hostname,port:d.port?":"+d.port:"",pathname:d.pathname?d.pathname:null,search:d.search?d.search.replace(/^\?/,""):null,searchParams:d.search?d.searchParams:null}} function parseURL(a,b){var e;if("URL"in window&&typeof window.URL=="function")try{e=new URL(a)}catch(c){e=document.createElement("a");e.href=a}else{e=document.createElement("a");e.href=a}if(b)for(var d in b)e[d]=b[d];return{full:e.href,protocol:e.protocol+"//",host:e.hostname,port:e.port?":"+e.port:"",pathname:e.pathname?e.pathname:null,search:e.search?e.search.replace(/^\?/,""):null,searchParams:e.search?e.searchParams:null}}
function triggerRewrite(a){return typeof a=="object"&&typeof a.length=="undefined"?a:obj={handler:a[0],sync:a[1],streams:a[2],"default":a[3]}}; function triggerRewrite(a){return typeof a=="object"&&typeof a.length=="undefined"?a:obj={handler:a[0],sync:a[1],streams:a[2],"default":a[3]}};

File diff suppressed because it is too large Load diff

View file

@ -16,12 +16,14 @@
</head> </head>
<body> <body>
<nav> <nav>
<div class="textures"></div>
<a href='#' class=logo>MistServer</a> <a href='#' class=logo>MistServer</a>
<div class=menu> <div class=menu>
</div> </div>
</nav> </nav>
<div class=filler> <div class=filler>
<header> <header>
<div class="textures"></div>
<h1>Management Interface</h1> <h1>Management Interface</h1>
<aside id=status> <aside id=status>
<span id='connection' class='red'>Disconnected</span> <span id='connection' class='red'>Disconnected</span>

View file

@ -100,6 +100,9 @@ message('Building release @0@ for version @1@ @ debug level @2@'.format(release,
mist_deps = [] mist_deps = []
ccpp = meson.get_compiler('cpp') ccpp = meson.get_compiler('cpp')
if ccpp.has_header_symbol('netinet/in.h', 'IPV6_RECVPKTINFO') and ccpp.has_header_symbol('netinet/in.h', 'IP_PKTINFO')
option_defines += '-DHASPKTINFO'
endif
if usessl if usessl
mbedtls = ccpp.find_library('mbedtls', required: false) mbedtls = ccpp.find_library('mbedtls', required: false)

View file

@ -350,6 +350,7 @@ void Controller::handleWebSocket(HTTP::Parser &H, Socket::Connection &C, bool au
lastStrmStat.erase(strm); lastStrmStat.erase(strm);
} }
} }
W.readFrame();
if (!sent){Util::sleep(500);} if (!sent){Util::sleep(500);}
} }
} }

View file

@ -174,14 +174,24 @@ void Controller::updateBandwidthConfig(){
/// This function is ran whenever a stream becomes active. /// This function is ran whenever a stream becomes active.
void Controller::streamStarted(std::string stream){ void Controller::streamStarted(std::string stream){
INFO_MSG("Stream %s became active", stream.c_str()); INFO_MSG("Stream %s became active", stream.c_str());
{
streamTotals & sT = streamStats[stream];
JSON::Value strCnf = Util::getStreamConfig(stream);
if (strCnf.isMember("tags")){
jsonForEachConst(strCnf["tags"], it){
sT.tags.insert(it->asString());
}
INFO_MSG("Applied %" PRIu32 " tags to stream %s from config",strCnf["tags"].size() , stream.c_str());
}
if (tagQueue.count(stream)){ if (tagQueue.count(stream)){
tagQueueItem & q = tagQueue[stream]; tagQueueItem & q = tagQueue[stream];
for (std::set<std::string>::iterator it = q.tags.begin(); it != q.tags.end(); ++it){ for (std::set<std::string>::iterator it = q.tags.begin(); it != q.tags.end(); ++it){
streamStats[stream].tags.insert(*it); sT.tags.insert(*it);
} }
INFO_MSG("Applied %zu tags to stream %s retroactively",q.tags.size() , stream.c_str()); INFO_MSG("Applied %zu tags to stream %s retroactively",q.tags.size() , stream.c_str());
tagQueue.erase(stream); tagQueue.erase(stream);
} }
}
Controller::doAutoPush(stream); Controller::doAutoPush(stream);
} }
@ -425,7 +435,7 @@ void Controller::SharedMemStats(void *config){
for (uint64_t cPos = startPos; cPos < endPos; ++cPos){ for (uint64_t cPos = startPos; cPos < endPos; ++cPos){
std::string strm = strmStats->getPointer("stream", cPos); std::string strm = strmStats->getPointer("stream", cPos);
std::string tags = strmStats->getPointer("tags", cPos); std::string tags = strmStats->getPointer("tags", cPos);
if (tags.size() && streamStats.count(strm)){ if (strm.size() && tags.size() && streamStats.count(strm)){
INFO_MSG("Restoring stream tags: %s -> %s", strm.c_str(), tags.c_str()); INFO_MSG("Restoring stream tags: %s -> %s", strm.c_str(), tags.c_str());
streamTotals & st = streamStats[strm]; streamTotals & st = streamStats[strm];
while (tags.size()){ while (tags.size()){
@ -468,7 +478,8 @@ void Controller::SharedMemStats(void *config){
cutOffPoint = 0; cutOffPoint = 0;
} }
for (std::map<std::string, statSession>::iterator it = sessions.begin(); it != sessions.end(); it++){ for (std::map<std::string, statSession>::iterator it = sessions.begin(); it != sessions.end(); it++){
streamStats[it->second.getStreamName()].currSessions++; std::string strm = it->second.getStreamName();
if (strm.size()){streamStats[strm].currSessions++;}
// This part handles ending sessions, keeping them in cache for now // This part handles ending sessions, keeping them in cache for now
if (it->second.getEnd() < cutOffPoint){ if (it->second.getEnd() < cutOffPoint){
viewSecondsTotal += it->second.getConnTime(); viewSecondsTotal += it->second.getConnTime();
@ -476,6 +487,7 @@ void Controller::SharedMemStats(void *config){
// Don't count this session as a viewer // Don't count this session as a viewer
continue; continue;
} }
if (strm.size()){
// Recount input, output and viewer type sessions // Recount input, output and viewer type sessions
switch (it->second.getSessType()){ switch (it->second.getSessType()){
case SESS_UNSET: break; case SESS_UNSET: break;
@ -502,6 +514,7 @@ void Controller::SharedMemStats(void *config){
break; break;
} }
} }
}
while (mustWipe.size()){ while (mustWipe.size()){
sessions.erase(mustWipe.front()); sessions.erase(mustWipe.front());
mustWipe.pop_front(); mustWipe.pop_front();
@ -753,14 +766,15 @@ void Controller::statSession::update(uint64_t index, Comms::Sessions &statComm){
} }
} }
// Only count connections that are countable // Only count connections that are countable
if (noBWCount != 2){ if (noBWCount != 2 && streamName.size()){
createEmptyStatsIfNeeded(streamName); createEmptyStatsIfNeeded(streamName);
streamStats[streamName].upBytes += currUp - prevUp; streamTotals & sT = streamStats[streamName];
streamStats[streamName].downBytes += currDown - prevDown; sT.upBytes += currUp - prevUp;
streamStats[streamName].packSent += currPktSent - prevPktSent; sT.downBytes += currDown - prevDown;
streamStats[streamName].packLoss += currPktLost - prevPktLost; sT.packSent += currPktSent - prevPktSent;
streamStats[streamName].packRetrans += currPktRetrans - prevPktRetrans; sT.packLoss += currPktLost - prevPktLost;
if (sessionType == SESS_VIEWER){streamStats[streamName].viewSeconds += secIncr;} sT.packRetrans += currPktRetrans - prevPktRetrans;
if (sessionType == SESS_VIEWER){sT.viewSeconds += secIncr;}
} }
} }

View file

@ -894,13 +894,6 @@ namespace Mist{
break; break;
} }
if (M.getLive() && !internalOnly){
uint64_t currLastUpdate = M.getLastUpdated();
if (currLastUpdate > activityCounter){activityCounter = currLastUpdate;}
}else{
if ((connectedUsers || isAlwaysOn()) && M.getValidTracks().size()){activityCounter = Util::bootSecs();}
}
inputServeStats(); inputServeStats();
// if not shutting down, wait 1 second before looping // if not shutting down, wait 1 second before looping
preMs = Util::bootMS() - preMs; preMs = Util::bootMS() - preMs;
@ -944,7 +937,14 @@ namespace Mist{
/// For live streams, this is twice the biggest fragment duration. /// For live streams, this is twice the biggest fragment duration.
/// For non-live streams this is INPUT_TIMEOUT seconds. /// For non-live streams this is INPUT_TIMEOUT seconds.
/// The default Pro implementation also allows cancelling the shutdown through the STREAM_UNLOAD trigger. /// The default Pro implementation also allows cancelling the shutdown through the STREAM_UNLOAD trigger.
bool Input::keepRunning(){ bool Input::keepRunning(bool updateActCtr){
// Default behaviour to stop an input when there's not activity after X seconds
// This is overriden by certain inputs (buffer, HLS, more) where there is different logic
// for updating 'activityCounter'
if (updateActCtr){
if ((connectedUsers || isAlwaysOn()) && M.getValidTracks().size()){activityCounter = Util::bootSecs();}
}
// We keep running in serve mode if the config is still active AND either // We keep running in serve mode if the config is still active AND either
// - INPUT_TIMEOUT seconds haven't passed yet, // - INPUT_TIMEOUT seconds haven't passed yet,
// - this is a live stream and at least two of the biggest fragment haven't passed yet, // - this is a live stream and at least two of the biggest fragment haven't passed yet,

View file

@ -74,7 +74,7 @@ namespace Mist{
virtual void getNext(size_t idx = INVALID_TRACK_ID){} virtual void getNext(size_t idx = INVALID_TRACK_ID){}
virtual void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID){} virtual void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID){}
virtual void finish(); virtual void finish();
virtual bool keepRunning(); virtual bool keepRunning(bool updateActCtr = true);
virtual bool openStreamSource(){return readHeader();} virtual bool openStreamSource(){return readHeader();}
virtual void closeStreamSource(){} virtual void closeStreamSource(){}
virtual void parseStreamHeader(){} virtual void parseStreamHeader(){}

View file

@ -111,7 +111,7 @@ namespace Mist{
// Overrides the default keepRunning function to shut down // Overrides the default keepRunning function to shut down
// if the file disappears or changes, by polling the file's mtime. // if the file disappears or changes, by polling the file's mtime.
// If neither applies, calls the original function. // If neither applies, calls the original function.
bool InputAAC::keepRunning(){ bool InputAAC::keepRunning(bool updateActCtr){
struct stat statData; struct stat statData;
if (stat(config->getString("input").c_str(), &statData) == -1){ if (stat(config->getString("input").c_str(), &statData) == -1){
INFO_MSG("Shutting down because input file disappeared"); INFO_MSG("Shutting down because input file disappeared");
@ -121,7 +121,7 @@ namespace Mist{
INFO_MSG("Shutting down because input file changed"); INFO_MSG("Shutting down because input file changed");
return false; return false;
} }
return Input::keepRunning(); return Input::keepRunning(updateActCtr);
} }

View file

@ -16,7 +16,7 @@ namespace Mist{
bool readHeader(); bool readHeader();
void seek(uint64_t seekTime, size_t idx); void seek(uint64_t seekTime, size_t idx);
void getNext(size_t idx = INVALID_TRACK_ID); void getNext(size_t idx = INVALID_TRACK_ID);
bool keepRunning(); bool keepRunning(bool updateActCtr = true);
uint64_t lastModTime; uint64_t lastModTime;
HTTP::URIReader inFile; HTTP::URIReader inFile;
size_t audioTrack; size_t audioTrack;

View file

@ -258,6 +258,14 @@ namespace Mist{
meta.setLive(true); meta.setLive(true);
} }
bool InputBuffer::keepRunning(bool updateActCtr){
if (M.getLive()){
uint64_t currLastUpdate = M.getLastUpdated();
if (currLastUpdate > activityCounter){activityCounter = currLastUpdate;}
}
return Input::keepRunning(false);
}
/// Checks if removing a key from this track is allowed/safe, and if so, removes it. /// Checks if removing a key from this track is allowed/safe, and if so, removes it.
/// Returns true if a key was actually removed, false otherwise /// Returns true if a key was actually removed, false otherwise
/// Aborts if any of the following conditions are true (while active): /// Aborts if any of the following conditions are true (while active):

View file

@ -34,6 +34,7 @@ namespace Mist{
bool needHeader(){return false;} bool needHeader(){return false;}
void getNext(size_t idx = INVALID_TRACK_ID){}; void getNext(size_t idx = INVALID_TRACK_ID){};
void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID){}; void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID){};
bool keepRunning(bool updateActCtr = true);
void removeTrack(size_t tid); void removeTrack(size_t tid);

View file

@ -67,7 +67,7 @@ namespace Mist{
/// Overrides the default keepRunning function to shut down /// Overrides the default keepRunning function to shut down
/// if the file disappears or changes, by polling the file's mtime. /// if the file disappears or changes, by polling the file's mtime.
/// If neither applies, calls the original function. /// If neither applies, calls the original function.
bool InputFLV::keepRunning(){ bool InputFLV::keepRunning(bool updateActCtr){
struct stat statData; struct stat statData;
if (stat(config->getString("input").c_str(), &statData) == -1){ if (stat(config->getString("input").c_str(), &statData) == -1){
INFO_MSG("Shutting down because input file disappeared"); INFO_MSG("Shutting down because input file disappeared");
@ -77,7 +77,7 @@ namespace Mist{
INFO_MSG("Shutting down because input file changed"); INFO_MSG("Shutting down because input file changed");
return false; return false;
} }
return Input::keepRunning(); return Input::keepRunning(updateActCtr);
} }
bool InputFLV::readHeader(){ bool InputFLV::readHeader(){

View file

@ -15,7 +15,7 @@ namespace Mist{
bool readHeader(); bool readHeader();
void getNext(size_t idx = INVALID_TRACK_ID); void getNext(size_t idx = INVALID_TRACK_ID);
void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID); void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID);
bool keepRunning(); bool keepRunning(bool updateActCtr = true);
FLV::Tag tmpTag; FLV::Tag tmpTag;
uint64_t lastModTime; uint64_t lastModTime;
FILE *inFile; FILE *inFile;

View file

@ -1169,6 +1169,16 @@ namespace Mist{
} }
} }
bool InputHLS::keepRunning(bool updateActCtr){
if (isAlwaysOn()){
uint64_t currLastUpdate = M.getLastUpdated();
if (currLastUpdate > activityCounter){activityCounter = currLastUpdate;}
return Input::keepRunning(false);
}else{
return Input::keepRunning(true);
}
}
/// \brief Applies any offset to the packets original timestamp /// \brief Applies any offset to the packets original timestamp
/// \param packetTime: the original timestamp of the packet /// \param packetTime: the original timestamp of the packet
/// \param tid: the trackid corresponding to this track and playlist /// \param tid: the trackid corresponding to this track and playlist

View file

@ -147,6 +147,7 @@ namespace Mist{
void postHeader(); void postHeader();
void getNext(size_t idx = INVALID_TRACK_ID); void getNext(size_t idx = INVALID_TRACK_ID);
void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID); void seek(uint64_t seekTime, size_t idx = INVALID_TRACK_ID);
bool keepRunning(bool updateActCtr = true);
bool readIndex(); bool readIndex();
bool initPlaylist(const std::string &uri, bool fullInit = true); bool initPlaylist(const std::string &uri, bool fullInit = true);

View file

@ -1,8 +1,10 @@
#include "input_tssrt.h" #include "input_tssrt.h"
#include <string>
#include <cerrno> #include <cerrno>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <sys/stat.h>
#include <mist/defines.h> #include <mist/defines.h>
#include <mist/downloader.h> #include <mist/downloader.h>
#include <mist/flv_tag.h> #include <mist/flv_tag.h>
@ -13,11 +15,9 @@
#include <mist/timing.h> #include <mist/timing.h>
#include <mist/ts_packet.h> #include <mist/ts_packet.h>
#include <mist/util.h> #include <mist/util.h>
#include <string> #include <mist/auth.h>
#include <mist/procs.h> #include <mist/procs.h>
#include <mist/tinythread.h> #include <mist/tinythread.h>
#include <sys/stat.h>
Util::Config *cfgPointer = NULL; Util::Config *cfgPointer = NULL;
std::string baseStreamName; std::string baseStreamName;
@ -33,7 +33,6 @@ void signal_handler(int signum, siginfo_t *sigInfo, void *ignore){
} }
} }
// We use threads here for multiple input pushes, because of the internals of the SRT Library // We use threads here for multiple input pushes, because of the internals of the SRT Library
static void callThreadCallbackSRT(void *socknum){ static void callThreadCallbackSRT(void *socknum){
// use the accepted socket as the second parameter // use the accepted socket as the second parameter
@ -47,6 +46,8 @@ namespace Mist{
/// \arg cfg Util::Config that contains all current configurations. /// \arg cfg Util::Config that contains all current configurations.
InputTSSRT::InputTSSRT(Util::Config *cfg, Socket::SRTConnection s) : Input(cfg){ InputTSSRT::InputTSSRT(Util::Config *cfg, Socket::SRTConnection s) : Input(cfg){
rawIdx = INVALID_TRACK_ID; rawIdx = INVALID_TRACK_ID;
udpInit = 0;
srtConn = 0;
lastRawPacket = 0; lastRawPacket = 0;
bootMSOffsetCalculated = false; bootMSOffsetCalculated = false;
assembler.setLive(); assembler.setLive();
@ -136,16 +137,17 @@ namespace Mist{
// Setup if we are called form with a thread for push-based input. // Setup if we are called form with a thread for push-based input.
if (s.connected()){ if (s.connected()){
srtConn = s; srtConn = new Socket::SRTConnection(s);
streamName = baseStreamName; streamName = baseStreamName;
std::string streamid = srtConn.getStreamName(); std::string streamid = srtConn->getStreamName();
int64_t acc = config->getInteger("acceptable"); int64_t acc = config->getInteger("acceptable");
if (acc == 0){ if (acc == 0){
if (streamid.size()){streamName += "+" + streamid;} if (streamid.size()){streamName += "+" + streamid;}
}else if(acc == 2){ }else if(acc == 2){
if (streamName != streamid){ if (streamName != streamid){
FAIL_MSG("Stream ID '%s' does not match stream name, push blocked", streamid.c_str()); FAIL_MSG("Stream ID '%s' does not match stream name, push blocked", streamid.c_str());
srtConn.close(); srtConn->close();
srtConn = 0;
} }
} }
Util::setStreamName(streamName); Util::setStreamName(streamName);
@ -169,7 +171,7 @@ namespace Mist{
Socket::SRT::libraryInit(); Socket::SRT::libraryInit();
rawMode = config->getBool("raw"); rawMode = config->getBool("raw");
if (rawMode){INFO_MSG("Entering raw mode");} if (rawMode){INFO_MSG("Entering raw mode");}
if (srtConn.getSocket() == -1){ if (srtConn && *srtConn){return true;}
std::string source = config->getString("input"); std::string source = config->getString("input");
standAlone = false; standAlone = false;
HTTP::URL u(source); HTTP::URL u(source);
@ -201,14 +203,17 @@ namespace Mist{
}else{ }else{
std::map<std::string, std::string> arguments; std::map<std::string, std::string> arguments;
HTTP::parseVars(u.args, arguments); HTTP::parseVars(u.args, arguments);
std::string addData;
if (arguments.count("streamid")){addData = arguments["streamid"];}
size_t connectCnt = 0; size_t connectCnt = 0;
do{ do{
srtConn.connect(u.host, u.getPort(), "input", arguments); if (!srtConn){srtConn = new Socket::SRTConnection();}
if (!srtConn){Util::sleep(1000);} srtConn->connect(u.host, u.getPort(), "input", arguments);
if (!*srtConn){Util::sleep(1000);}
++connectCnt; ++connectCnt;
}while (!srtConn && connectCnt < 10); }while (!*srtConn && connectCnt < 10);
if (!srtConn){WARN_MSG("Connecting to %s timed out", u.getUrl().c_str());} if (!*srtConn){WARN_MSG("Connecting to %s timed out", u.getUrl().c_str());}
}
} }
return true; return true;
} }
@ -217,13 +222,13 @@ namespace Mist{
void InputTSSRT::getNext(size_t idx){ void InputTSSRT::getNext(size_t idx){
thisPacket.null(); thisPacket.null();
bool hasPacket = tsStream.hasPacket(); bool hasPacket = tsStream.hasPacket();
while (!hasPacket && srtConn && config->is_active){ while (!hasPacket && srtConn && *srtConn && config->is_active){
size_t recvSize = srtConn.RecvNow(); size_t recvSize = srtConn->RecvNow();
if (recvSize){ if (recvSize){
if (rawMode){ if (rawMode){
keepAlive(); keepAlive();
rawBuffer.append(srtConn.recvbuf, recvSize); rawBuffer.append(srtConn->recvbuf, recvSize);
if (rawBuffer.size() >= 1316 && (lastRawPacket == 0 || lastRawPacket != Util::bootMS())){ if (rawBuffer.size() >= 1316 && (lastRawPacket == 0 || lastRawPacket != Util::bootMS())){
if (rawIdx == INVALID_TRACK_ID){ if (rawIdx == INVALID_TRACK_ID){
rawIdx = meta.addTrack(); rawIdx = meta.addTrack();
@ -240,8 +245,8 @@ namespace Mist{
} }
continue; continue;
} }
if (assembler.assemble(tsStream, srtConn.recvbuf, recvSize, true)){hasPacket = tsStream.hasPacket();} if (assembler.assemble(tsStream, srtConn->recvbuf, recvSize, true)){hasPacket = tsStream.hasPacket();}
}else if (srtConn){ }else if (srtConn && *srtConn){
// This should not happen as the SRT socket is read blocking and won't return until there is // This should not happen as the SRT socket is read blocking and won't return until there is
// data. But if it does, wait before retry // data. But if it does, wait before retry
Util::sleep(10); Util::sleep(10);
@ -250,7 +255,7 @@ namespace Mist{
if (hasPacket){tsStream.getEarliestPacket(thisPacket);} if (hasPacket){tsStream.getEarliestPacket(thisPacket);}
if (!thisPacket){ if (!thisPacket){
if (srtConn){ if (srtConn && *srtConn){
INFO_MSG("Could not getNext TS packet!"); INFO_MSG("Could not getNext TS packet!");
Util::logExitReason(ER_FORMAT_SPECIFIC, "internal TS parser error"); Util::logExitReason(ER_FORMAT_SPECIFIC, "internal TS parser error");
}else{ }else{
@ -286,7 +291,7 @@ namespace Mist{
void InputTSSRT::streamMainLoop(){ void InputTSSRT::streamMainLoop(){
// If we do not have a srtConn here, we are the main thread and should start accepting pushes. // If we do not have a srtConn here, we are the main thread and should start accepting pushes.
if (srtConn.getSocket() == -1){ if (!srtConn || !*srtConn){
cfgPointer = config; cfgPointer = config;
baseStreamName = streamName; baseStreamName = streamName;
while (config->is_active && sSock.connected()){ while (config->is_active && sSock.connected()){
@ -304,7 +309,7 @@ namespace Mist{
} }
// If we are here: we have a proper connection (either accepted or pull input) and should start parsing it as such // If we are here: we have a proper connection (either accepted or pull input) and should start parsing it as such
Input::streamMainLoop(); Input::streamMainLoop();
srtConn.close(); srtConn->close();
Socket::SRT::libraryCleanup(); Socket::SRT::libraryCleanup();
} }
@ -313,11 +318,11 @@ namespace Mist{
void InputTSSRT::setSingular(bool newSingular){singularFlag = newSingular;} void InputTSSRT::setSingular(bool newSingular){singularFlag = newSingular;}
void InputTSSRT::connStats(Comms::Connections &statComm){ void InputTSSRT::connStats(Comms::Connections &statComm){
statComm.setUp(srtConn.dataUp()); statComm.setUp(srtConn->dataUp());
statComm.setDown(srtConn.dataDown()); statComm.setDown(srtConn->dataDown());
statComm.setPacketCount(srtConn.packetCount()); statComm.setPacketCount(srtConn->packetCount());
statComm.setPacketLostCount(srtConn.packetLostCount()); statComm.setPacketLostCount(srtConn->packetLostCount());
statComm.setPacketRetransmitCount(srtConn.packetRetransmitCount()); statComm.setPacketRetransmitCount(srtConn->packetRetransmitCount());
} }
}// namespace Mist }// namespace Mist

View file

@ -4,7 +4,6 @@
#include <mist/socket_srt.h> #include <mist/socket_srt.h>
#include <mist/ts_packet.h> #include <mist/ts_packet.h>
#include <mist/ts_stream.h> #include <mist/ts_stream.h>
#include <set>
#include <string> #include <string>
namespace Mist{ namespace Mist{
@ -16,7 +15,7 @@ namespace Mist{
void setSingular(bool newSingular); void setSingular(bool newSingular);
virtual bool needsLock(); virtual bool needsLock();
virtual std::string getConnectedBinHost(){ virtual std::string getConnectedBinHost(){
if (srtConn){return srtConn.getBinHost();} if (srtConn && *srtConn){return srtConn->getBinHost();}
return Input::getConnectedBinHost(); return Input::getConnectedBinHost();
} }
@ -38,7 +37,8 @@ namespace Mist{
int64_t timeStampOffset; int64_t timeStampOffset;
uint64_t lastTimeStamp; uint64_t lastTimeStamp;
Socket::SRTConnection srtConn; Socket::SRTConnection * srtConn;
Socket::UDPConnection * udpInit;
bool singularFlag; bool singularFlag;
virtual void connStats(Comms::Connections &statComm); virtual void connStats(Comms::Connections &statComm);

View file

@ -37,7 +37,7 @@ if have_librist
endif endif
if have_srt if have_srt
outputs += {'name' : 'TSSRT', 'format' : 'tssrt', 'extra': ['ts', 'debased', 'with_srt']} outputs += {'name' : 'TSSRT', 'format' : 'tssrt', 'extra': ['ts', 'with_srt']}
endif endif
if get_option('WITH_SANITY') if get_option('WITH_SANITY')

View file

@ -93,6 +93,7 @@ namespace Mist{
Output::Output(Socket::Connection &conn) : myConn(conn){ Output::Output(Socket::Connection &conn) : myConn(conn){
dataWaitTimeout = 2500; dataWaitTimeout = 2500;
thisBootMs = Util::bootMS();
pushing = false; pushing = false;
recursingSync = false; recursingSync = false;
firstTime = Util::bootMS(); firstTime = Util::bootMS();

View file

@ -74,7 +74,7 @@ namespace Mist{
udpSize = 7; udpSize = 7;
if (targetParams.count("tracks")){tracks = targetParams["tracks"];} if (targetParams.count("tracks")){tracks = targetParams["tracks"];}
if (targetParams.count("pkts")){udpSize = atoi(targetParams["pkts"].c_str());} if (targetParams.count("pkts")){udpSize = atoi(targetParams["pkts"].c_str());}
packetBuffer.reserve(188 * udpSize); packetBuffer.allocate(188 * udpSize);
if (target.path.size()){ if (target.path.size()){
if (!pushSock.bind(0, target.path)){ if (!pushSock.bind(0, target.path)){
disconnect(); disconnect();
@ -230,7 +230,7 @@ namespace Mist{
if (wrapRTP){ if (wrapRTP){
// Send RTP packet itself // Send RTP packet itself
if (rand() % 100 >= dropPercentage){ if (rand() % 100 >= dropPercentage){
tsOut.sendTS(&pushSock, packetBuffer.c_str(), packetBuffer.size()); tsOut.sendTS(&pushSock, packetBuffer, packetBuffer.size());
myConn.addUp(tsOut.getHsize() + tsOut.getPayloadSize()); myConn.addUp(tsOut.getHsize() + tsOut.getPayloadSize());
} else { } else {
INFO_MSG("Dropping RTP packet in order to simulate packet loss"); INFO_MSG("Dropping RTP packet in order to simulate packet loss");
@ -239,15 +239,14 @@ namespace Mist{
if (sendFEC){ if (sendFEC){
// Send FEC packet if available // Send FEC packet if available
uint64_t bytesSent = 0; uint64_t bytesSent = 0;
tsOut.parseFEC(&fecColumnSock, &fecRowSock, bytesSent, packetBuffer.c_str(), packetBuffer.size()); tsOut.parseFEC(&fecColumnSock, &fecRowSock, bytesSent, packetBuffer, packetBuffer.size());
myConn.addUp(bytesSent); myConn.addUp(bytesSent);
} }
}else{ }else{
pushSock.SendNow(packetBuffer); pushSock.SendNow(packetBuffer, packetBuffer.size());
myConn.addUp(packetBuffer.size()); myConn.addUp(packetBuffer.size());
} }
packetBuffer.clear(); packetBuffer.truncate(0);
packetBuffer.reserve(udpSize * len);
curFilled = 0; curFilled = 0;
} }
packetBuffer.append(tsData, len); packetBuffer.append(tsData, len);

View file

@ -21,7 +21,7 @@ namespace Mist{
bool wrapRTP; bool wrapRTP;
bool sendFEC; bool sendFEC;
void onRTP(void *socket, const char *data, size_t nbytes); void onRTP(void *socket, const char *data, size_t nbytes);
std::string packetBuffer; Util::ResizeablePointer packetBuffer;
Socket::UDPConnection pushSock; Socket::UDPConnection pushSock;
Socket::UDPConnection fecColumnSock; Socket::UDPConnection fecColumnSock;
Socket::UDPConnection fecRowSock; Socket::UDPConnection fecRowSock;

View file

@ -8,6 +8,7 @@ namespace Mist{
setBlocking(true); setBlocking(true);
sendRepeatingHeaders = 0; sendRepeatingHeaders = 0;
lastHeaderTime = 0; lastHeaderTime = 0;
maxSkipAhead = 0;
} }
void TSOutput::fillPacket(char const *data, size_t dataLen, bool &firstPack, bool video, void TSOutput::fillPacket(char const *data, size_t dataLen, bool &firstPack, bool video,
@ -70,6 +71,8 @@ namespace Mist{
return; return;
} }
} }
if (liveSeek(true)){return;}
if (!M.trackLoaded(thisIdx)){return;}
// Get ready some data to speed up accesses // Get ready some data to speed up accesses
std::string type = M.getType(thisIdx); std::string type = M.getType(thisIdx);
std::string codec = M.getCodec(thisIdx); std::string codec = M.getCodec(thisIdx);

View file

@ -6,11 +6,13 @@
#include <mist/encode.h> #include <mist/encode.h>
#include <mist/stream.h> #include <mist/stream.h>
#include <mist/triggers.h> #include <mist/triggers.h>
#include <mist/auth.h>
bool allowStreamNameOverride = true; bool allowStreamNameOverride = true;
namespace Mist{ namespace Mist{
OutTSSRT::OutTSSRT(Socket::Connection &conn, Socket::SRTConnection & _srtSock) : TSOutput(conn), srtConn(_srtSock){ OutTSSRT::OutTSSRT(Socket::Connection &conn, Socket::SRTConnection * _srtSock) : TSOutput(conn){
srtConn = _srtSock;
// NOTE: conn is useless for SRT, as it uses a different socket type. // NOTE: conn is useless for SRT, as it uses a different socket type.
sendRepeatingHeaders = 500; // PAT/PMT every 500ms (DVB spec) sendRepeatingHeaders = 500; // PAT/PMT every 500ms (DVB spec)
streamName = config->getString("streamname"); streamName = config->getString("streamname");
@ -18,9 +20,14 @@ namespace Mist{
pushOut = false; pushOut = false;
bootMSOffsetCalculated = false; bootMSOffsetCalculated = false;
assembler.setLive(); assembler.setLive();
udpInit = 0;
// Push output configuration // Push output configuration
if (config->getString("target").size()){ if (config->getString("target").size()){
Socket::SRT::libraryInit();
target = HTTP::URL(config->getString("target")); target = HTTP::URL(config->getString("target"));
HTTP::parseVars(target.args, targetParams);
std::string addData;
if (targetParams.count("streamid")){addData = targetParams["streamid"];}
if (target.protocol != "srt"){ if (target.protocol != "srt"){
FAIL_MSG("Target %s must begin with srt://, aborting", target.getUrl().c_str()); FAIL_MSG("Target %s must begin with srt://, aborting", target.getUrl().c_str());
onFail("Invalid srt target: doesn't start with srt://", true); onFail("Invalid srt target: doesn't start with srt://", true);
@ -32,28 +39,27 @@ namespace Mist{
return; return;
} }
pushOut = true; pushOut = true;
HTTP::parseVars(target.args, targetParams);
size_t connectCnt = 0; size_t connectCnt = 0;
do{ do{
srtConn.connect(target.host, target.getPort(), "output", targetParams); if (!srtConn){srtConn = new Socket::SRTConnection();}
if (!srtConn){ if (srtConn){srtConn->connect(target.host, target.getPort(), "output", targetParams);}
if (!*srtConn){
Util::sleep(1000); Util::sleep(1000);
}else{ }else{
INFO_MSG("Connect success on attempt %zu", connectCnt+1); INFO_MSG("SRT socket %s on attempt %zu", srtConn->getStateStr(), connectCnt+1);
break; break;
} }
++connectCnt; ++connectCnt;
}while (!srtConn && connectCnt < 5); }while ((!srtConn || !*srtConn) && connectCnt < 5);
if (!srtConn){ if (!srtConn){
FAIL_MSG("Failed to connect to '%s'!", config->getString("target").c_str()); FAIL_MSG("Failed to connect to '%s'!", config->getString("target").c_str());
} }
wantRequest = false; wantRequest = false;
parseData = true; parseData = true;
initialize();
}else{ }else{
// Pull output configuration, In this case we have an srt connection in the second constructor parameter. // Pull output configuration, In this case we have an srt connection in the second constructor parameter.
// Handle override / append of streamname options // Handle override / append of streamname options
std::string sName = srtConn.getStreamName(); std::string sName = srtConn->getStreamName();
if (allowStreamNameOverride){ if (allowStreamNameOverride){
if (sName != ""){ if (sName != ""){
streamName = sName; streamName = sName;
@ -61,18 +67,19 @@ namespace Mist{
Util::setStreamName(streamName); Util::setStreamName(streamName);
} }
} }
myConn.setHost(srtConn->remotehost);
int64_t accTypes = config->getInteger("acceptable"); int64_t accTypes = config->getInteger("acceptable");
if (accTypes == 0){//Allow both directions if (accTypes == 0){//Allow both directions
srtConn.setBlocking(false); srtConn->setBlocking(false);
//Try to read the socket 10 times. If any reads succeed, assume they are pushing in //Try to read the socket 10 times. If any reads succeed, assume they are pushing in
size_t retries = 60; size_t retries = 60;
while (!accTypes && srtConn && retries){ while (!accTypes && *srtConn && retries){
size_t recvSize = srtConn.Recv(); size_t recvSize = srtConn->Recv();
if (recvSize){ if (recvSize){
accTypes = 2; accTypes = 2;
INFO_MSG("Connection put into ingest mode"); INFO_MSG("Connection put into ingest mode");
assembler.assemble(tsIn, srtConn.recvbuf, recvSize, true); assembler.assemble(tsIn, srtConn->recvbuf, recvSize, true);
}else{ }else{
Util::sleep(50); Util::sleep(50);
} }
@ -85,14 +92,14 @@ namespace Mist{
} }
} }
if (accTypes == 1){// Only allow outgoing if (accTypes == 1){// Only allow outgoing
srtConn.setBlocking(true); srtConn->setBlocking(true);
srtConn.direction = "output"; srtConn->direction = "output";
parseData = true; parseData = true;
wantRequest = false; wantRequest = false;
initialize(); initialize();
}else if (accTypes == 2){//Only allow incoming }else if (accTypes == 2){//Only allow incoming
srtConn.setBlocking(false); srtConn->setBlocking(false);
srtConn.direction = "input"; srtConn->direction = "input";
if (Triggers::shouldTrigger("PUSH_REWRITE")){ if (Triggers::shouldTrigger("PUSH_REWRITE")){
HTTP::URL reqUrl; HTTP::URL reqUrl;
reqUrl.protocol = "srt"; reqUrl.protocol = "srt";
@ -115,7 +122,11 @@ namespace Mist{
Util::sanitizeName(streamName); Util::sanitizeName(streamName);
} }
} }
myConn.setHost(srtConn.remotehost); if (!streamName.size()){
Util::logExitReason(ER_FORMAT_SPECIFIC, "Push from %s rejected - there is no stream name set", getConnectedHost().c_str());
onFinish();
return;
}
if (!allowPush("")){ if (!allowPush("")){
onFinish(); onFinish();
return; return;
@ -128,23 +139,57 @@ namespace Mist{
} }
} }
lastWorked = Util::bootSecs();
lastTimeStamp = 0; lastTimeStamp = 0;
timeStampOffset = 0; timeStampOffset = 0;
} }
bool OutTSSRT::onFinish(){ bool OutTSSRT::onFinish(){
myConn.close(); config->is_active = false;
srtConn.close();
return false; return false;
} }
OutTSSRT::~OutTSSRT(){} OutTSSRT::~OutTSSRT(){
if(srtConn){
srtConn->close();
delete srtConn;
srtConn = 0;
}
Socket::SRT::libraryCleanup();
}
static void addIntOpt(JSON::Value & pp, const std::string & param, const std::string & name, const std::string & help, size_t def = 0){ // Override initialSeek to go to last possible position for live streams
void OutTSSRT::initialSeek(bool dryRun){
if (!meta){return;}
meta.removeLimiter();
uint64_t seekPos = 0;
std::set<size_t> validTracks = M.getValidTracks();
if (M.getLive() && validTracks.size()){
if (userSelect.size()){
for (std::map<size_t, Comms::Users>::iterator it = userSelect.begin(); it != userSelect.end(); it++){
if (M.trackValid(it->first) && (M.getNowms(it->first) < seekPos || !seekPos)){
seekPos = meta.getNowms(it->first);
}
}
}else{
for (std::set<size_t>::iterator it = validTracks.begin(); it != validTracks.end(); it++){
if (meta.getNowms(*it) < seekPos || !seekPos){seekPos = meta.getNowms(*it);}
}
}
}
seek(seekPos);
}
static void addIntOpt(JSON::Value & pp, const std::string & param, const std::string & name, const std::string & help, size_t def = 0,const std::string unit = ""){
pp[param]["name"] = name; pp[param]["name"] = name;
pp[param]["help"] = help; pp[param]["help"] = help;
pp[param]["type"] = "int"; pp[param]["type"] = "int";
pp[param]["default"] = (uint64_t)def; pp[param]["default"] = (uint64_t)def;
if (unit != "") {
pp[param]["unit"] = unit;
}
} }
static void addStrOpt(JSON::Value & pp, const std::string & param, const std::string & name, const std::string & help, const std::string & def = ""){ static void addStrOpt(JSON::Value & pp, const std::string & param, const std::string & name, const std::string & help, const std::string & def = ""){
@ -158,16 +203,16 @@ namespace Mist{
pp[param]["name"] = name; pp[param]["name"] = name;
pp[param]["help"] = help; pp[param]["help"] = help;
pp[param]["type"] = "select"; pp[param]["type"] = "select";
pp[param]["select"][0u][0u] = 0; pp[param]["select"][0u][0u] = "";
pp[param]["select"][0u][1u] = "False"; pp[param]["select"][0u][1u] = def?"Default (true)":"Default (false)";
pp[param]["select"][1u][0u] = 1; pp[param]["select"][1u][0u] = 0;
pp[param]["select"][1u][1u] = "True"; pp[param]["select"][1u][1u] = "False";
pp[param]["select"][2u][0u] = 1;
pp[param]["select"][2u][1u] = "True";
pp[param]["type"] = "select"; pp[param]["type"] = "select";
pp[param]["default"] = def?1:0;
} }
void OutTSSRT::init(Util::Config *cfg){ void OutTSSRT::init(Util::Config *cfg){
Output::init(cfg); Output::init(cfg);
capa["name"] = "TSSRT"; capa["name"] = "TSSRT";
@ -190,14 +235,6 @@ namespace Mist{
capa["optional"]["streamname"]["short"] = "s"; capa["optional"]["streamname"]["short"] = "s";
capa["optional"]["streamname"]["default"] = ""; capa["optional"]["streamname"]["default"] = "";
capa["optional"]["filelimit"]["name"] = "Open file descriptor limit";
capa["optional"]["filelimit"]["help"] = "Increase open file descriptor to this value if current system value is lower. A higher value may be needed for handling many concurrent SRT connections.";
capa["optional"]["filelimit"]["type"] = "int";
capa["optional"]["filelimit"]["option"] = "--filelimit";
capa["optional"]["filelimit"]["short"] = "l";
capa["optional"]["filelimit"]["default"] = "1024";
capa["optional"]["acceptable"]["name"] = "Acceptable connection types"; capa["optional"]["acceptable"]["name"] = "Acceptable connection types";
capa["optional"]["acceptable"]["help"] = capa["optional"]["acceptable"]["help"] =
"Whether to allow only incoming pushes (2), only outgoing pulls (1), or both (0, default)"; "Whether to allow only incoming pushes (2), only outgoing pulls (1), or both (0, default)";
@ -232,61 +269,107 @@ namespace Mist{
config->addStandardPushCapabilities(capa); config->addStandardPushCapabilities(capa);
JSON::Value & pp = capa["push_parameters"]; JSON::Value & pp = capa["push_parameters"];
pp["mode"]["name"] = "Mode"; pp["srtopts_main"]["name"] = "Commonly used SRT options";
pp["mode"]["help"] = "The connection mode. Can be listener, caller, or rendezvous. By default is listener if the host is missing from the URL, and is caller otherwise."; pp["srtopts_main"]["help"] = "Control the SRT connection";
pp["mode"]["type"] = "select"; pp["srtopts_main"]["type"] = "group";
pp["mode"]["select"][0u][0u] = "default"; pp["srtopts_main"]["sort"] = "aaa";
pp["mode"]["select"][0u][1u] = "Default"; pp["srtopts_main"]["expand"] = true;
pp["mode"]["select"][1u][0u] = "listener";
pp["mode"]["select"][1u][1u] = "Listener"; addIntOpt(pp["srtopts_main"]["options"], "latency", "Latency", "Socket latency, in milliseconds.", 120,"ms");
pp["mode"]["select"][2u][0u] = "caller"; addStrOpt(pp["srtopts_main"]["options"], "streamid", "Stream ID", "Stream ID to transmit to the other side. MistServer uses this field for the stream name, but the field is entirely free-form and may contain anything.");
pp["mode"]["select"][2u][1u] = "Caller"; addStrOpt(pp["srtopts_main"]["options"], "passphrase", "Encryption passphrase", "Enables encryption with the given passphrase.");
pp["mode"]["select"][3u][0u] = "rendezvous";
pp["mode"]["select"][3u][1u] = "Rendezvous"; pp["srtopts_main"]["options"]["passphrase"]["minlength"] = 10;
pp["mode"]["type"] = "select"; pp["srtopts_main"]["options"]["passphrase"]["maxlength"] = 79;
pp["srtopts"]["name"] = "More SRT options";
pp["srtopts"]["help"] = "Control the SRT connection";
pp["srtopts"]["type"] = "group";
pp["srtopts"]["sort"] = "ab";
pp["srtopts"]["options"]["mode"]["name"] = "Mode";
pp["srtopts"]["options"]["mode"]["help"] = "The connection mode. Can be listener, caller, or rendezvous. By default is listener if the host is missing from the URL, and is caller otherwise.";
pp["srtopts"]["options"]["mode"]["type"] = "select";
pp["srtopts"]["options"]["mode"]["select"][0u][0u] = "";
pp["srtopts"]["options"]["mode"]["select"][0u][1u] = "Default (listener)";
pp["srtopts"]["options"]["mode"]["select"][1u][0u] = "listener";
pp["srtopts"]["options"]["mode"]["select"][1u][1u] = "Listener";
pp["srtopts"]["options"]["mode"]["select"][2u][0u] = "caller";
pp["srtopts"]["options"]["mode"]["select"][2u][1u] = "Caller";
pp["srtopts"]["options"]["mode"]["select"][3u][0u] = "rendezvous";
pp["srtopts"]["options"]["mode"]["select"][3u][1u] = "Rendezvous";
pp["srtopts"]["options"]["transtype"]["name"] = "Transmission type";
pp["srtopts"]["options"]["transtype"]["help"] = "This should be set to live (the default) unless you know what you're doing.";
pp["srtopts"]["options"]["transtype"]["select"][0u][0u] = "";
pp["srtopts"]["options"]["transtype"]["select"][0u][1u] = "Default (live)";
pp["srtopts"]["options"]["transtype"]["select"][1u][0u] = "live";
pp["srtopts"]["options"]["transtype"]["select"][1u][1u] = "Live";
pp["srtopts"]["options"]["transtype"]["select"][2u][0u] = "file";
pp["srtopts"]["options"]["transtype"]["select"][2u][1u] = "File";
pp["srtopts"]["options"]["transtype"]["type"] = "select";
pp["transtype"]["name"] = "Transmission type";
pp["transtype"]["help"] = "This should be set to live (the default) unless you know what you're doing.";
pp["transtype"]["type"] = "select";
pp["transtype"]["select"][0u][0u] = "";
pp["transtype"]["select"][0u][1u] = "Live";
pp["transtype"]["select"][1u][0u] = "file";
pp["transtype"]["select"][1u][1u] = "File";
pp["transtype"]["type"] = "select";
//addStrOpt(pp, "adapter", "", ""); //addStrOpt(pp, "adapter", "", "");
//addIntOpt(pp, "timeout", "", ""); //addIntOpt(pp, "timeout", "", "");
//addIntOpt(pp, "port", "", ""); //addIntOpt(pp, "port", "", "");
addBoolOpt(pp, "tsbpd", "Timestamp-based Packet Delivery mode", "In this mode the packet's time is assigned at the sending time (or allowed to be predefined), transmitted in the packet's header, and then restored on the receiver side so that the time intervals between consecutive packets are preserved when delivering to the application.", true);
addBoolOpt(pp, "linger", "Linger closed sockets", "Whether to keep closed sockets around for 180 seconds of linger time or not.", true); addBoolOpt(pp["srtopts"]["options"], "tsbpd", "Timestamp-based Packet Delivery mode", "In this mode the packet's time is assigned at the sending time (or allowed to be predefined), transmitted in the packet's header, and then restored on the receiver side so that the time intervals between consecutive packets are preserved when delivering to the application.", true);
addIntOpt(pp, "maxbw", "Maximum send bandwidth", "Maximum send bandwidth in bytes per second, -1 for infinite, 0 for relative to input bandwidth.", -1);
addIntOpt(pp, "pbkeylen", "Encryption key length", "May be 0 (auto), 16 (AES-128), 24 (AES-192) or 32 (AES-256).", 0); addBoolOpt(pp["srtopts"]["options"], "linger", "Linger closed sockets", "Whether to keep closed sockets around for 180 seconds of linger time or not.", true);
addStrOpt(pp, "passphrase", "Encryption passphrase", "Enables encryption with the given passphrase."); addIntOpt(pp["srtopts"]["options"], "maxbw", "Maximum send bandwidth", "Maximum send bandwidth in bytes per second, -1 for infinite, 0 for relative to input bandwidth.", -1,"bytes/s");
addIntOpt(pp, "mss", "Maximum Segment Size", "Maximum size for packets including all headers, in bytes. The default of 1500 is generally the maximum value you can use in most networks.", 1500);
addIntOpt(pp, "fc", "Flight Flag Size", "Maximum packets that may be 'in flight' without being acknowledged.", 25600);
addIntOpt(pp, "sndbuf", "Send Buffer Size", "Size of the send buffer, in bytes"); pp["srtopts"]["options"]["pbkeylen"]["name"] = "Encryption key length";
addIntOpt(pp, "rcvbuf", "Receive Buffer Size", "Size of the receive buffer, in bytes"); pp["srtopts"]["options"]["pbkeylen"]["help"] = "The encryption key length. Default: auto.";
addIntOpt(pp, "ipttl", "TTL", "Time To Live for IPv4 connections or unicast hops for IPv6 connections. Defaults to system default."); pp["srtopts"]["options"]["pbkeylen"]["select"][0u][0u] = "";
addIntOpt(pp, "iptos", "Type of Service", "TOS for IPv4 connections or Traffic Class for IPv6 connections. Defaults to system default."); pp["srtopts"]["options"]["pbkeylen"]["select"][0u][1u] = "Default (auto)";
addIntOpt(pp, "inputbw", "Input bandwidth", "Estimated bandwidth of data to be sent. Default of 0 means automatic."); pp["srtopts"]["options"]["pbkeylen"]["select"][1u][0u] = "0";
addIntOpt(pp, "oheadbw", "Recovery Bandwidth Overhead", "Percentage of bandwidth to use for recovery.", 25); pp["srtopts"]["options"]["pbkeylen"]["select"][1u][1u] = "Auto";
addIntOpt(pp, "latency", "Latency", "Socket latency, in milliseconds.", 120); pp["srtopts"]["options"]["pbkeylen"]["select"][2u][0u] = "16";
pp["srtopts"]["options"]["pbkeylen"]["select"][2u][1u] = "AES-128";
pp["srtopts"]["options"]["pbkeylen"]["select"][3u][0u] = "24";
pp["srtopts"]["options"]["pbkeylen"]["select"][3u][1u] = "AES-192";
pp["srtopts"]["options"]["pbkeylen"]["select"][4u][0u] = "32";
pp["srtopts"]["options"]["pbkeylen"]["select"][4u][1u] = "AES-256";
pp["srtopts"]["options"]["pbkeylen"]["default"] = "0";
pp["srtopts"]["options"]["pbkeylen"]["type"] = "select";
addIntOpt(pp["srtopts"]["options"], "mss", "Maximum Segment Size", "Maximum size for packets including all headers, in bytes. The default of 1500 is generally the maximum value you can use in most networks.", 1500,"bytes");
addIntOpt(pp["srtopts"]["options"], "fc", "Flight Flag Size", "Maximum packets that may be 'in flight' without being acknowledged.", 25600,"packets");
addIntOpt(pp["srtopts"]["options"], "sndbuf", "Send Buffer Size", "Size of the send buffer, in bytes",0,"bytes");
addIntOpt(pp["srtopts"]["options"], "rcvbuf", "Receive Buffer Size", "Size of the receive buffer, in bytes",0,"bytes");
addIntOpt(pp["srtopts"]["options"], "ipttl", "TTL", "Time To Live for IPv4 connections or unicast hops for IPv6 connections. Defaults to system default.",0,"hops");
addIntOpt(pp["srtopts"]["options"], "iptos", "Type of Service", "TOS for IPv4 connections or Traffic Class for IPv6 connections. Defaults to system default.");
addIntOpt(pp["srtopts"]["options"], "inputbw", "Input bandwidth", "Estimated bandwidth of data to be sent. Default of 0 means automatic.",0,"bytes/s");
addIntOpt(pp["srtopts"]["options"], "oheadbw", "Recovery Bandwidth Overhead", "Percentage of bandwidth to use for recovery.",25,"%");
//addIntOpt(pp, "rcvlatency", "Receive Latency", "Latency in receive mode, in milliseconds", 120); //addIntOpt(pp, "rcvlatency", "Receive Latency", "Latency in receive mode, in milliseconds", 120);
//addIntOpt(pp, "peerlatency", "", ""); //addIntOpt(pp, "peerlatency", "", "");
addBoolOpt(pp, "tlpktdrop", "Too-late Packet Drop", "Skips packets that cannot (sending) or have not (receiving) been delivered in time", true); addBoolOpt(pp["srtopts"]["options"], "tlpktdrop", "Too-late Packet Drop", "Skips packets that cannot (sending) or have not (receiving) been delivered in time", true);
addIntOpt(pp, "snddropdelay", "Send Drop Delay", "Extra delay before Too-late packet drop on sender side is triggered, in milliseconds."); addIntOpt(pp["srtopts"]["options"], "snddropdelay", "Send Drop Delay", "Extra delay before Too-late packet drop on sender side is triggered, in milliseconds.",0,"ms");
addBoolOpt(pp, "nakreport", "Repeat loss reports", "When enabled, repeats loss reports every time the retransmission timeout has expired.", true); addBoolOpt(pp["srtopts"]["options"], "nakreport", "Repeat loss reports", "When enabled, repeats loss reports every time the retransmission timeout has expired.", true);
addIntOpt(pp, "conntimeo", "Connect timeout", "Milliseconds to wait before timing out a connection attempt for caller and rendezvous modes.", 3000); addIntOpt(pp["srtopts"]["options"], "conntimeo", "Connect timeout", "Milliseconds to wait before timing out a connection attempt for caller and rendezvous modes.", 3000,"ms");
addIntOpt(pp, "lossmaxttl", "Reorder Tolerance", "Maximum amount of packets that may be out of order, or 0 to disable this mechanism."); addIntOpt(pp["srtopts"]["options"], "lossmaxttl", "Reorder Tolerance", "Maximum amount of packets that may be out of order, or 0 to disable this mechanism.",0,"packets");
addIntOpt(pp, "minversion", "Minimum SRT version", "Minimum SRT version to require the other side of the connection to support."); addIntOpt(pp["srtopts"]["options"], "minversion", "Minimum SRT version", "Minimum SRT version to require the other side of the connection to support.");
addStrOpt(pp, "streamid", "Stream ID", "Stream ID to transmit to the other side. MistServer uses this field for the stream name, but the field is entirely free-form and may contain anything.");
addStrOpt(pp, "congestion", "Congestion controller", "May be set to 'live' or 'file'", "live"); addStrOpt(pp["srtopts"]["options"], "congestion", "Congestion controller", "May be set to 'live' or 'file'", "live");
addBoolOpt(pp, "messageapi", "Message API", "When true, uses the default Message API. When false, uses the Stream API", true); pp["srtopts"]["options"]["congestion"]["select"][0u][0u] = "";
pp["srtopts"]["options"]["congestion"]["select"][0u][1u] = "Default (live)";
pp["srtopts"]["options"]["congestion"]["select"][1u][0u] = "live";
pp["srtopts"]["options"]["congestion"]["select"][1u][1u] = "Live";
pp["srtopts"]["options"]["congestion"]["select"][2u][0u] = "file";
pp["srtopts"]["options"]["congestion"]["select"][2u][1u] = "File";
pp["srtopts"]["options"]["congestion"]["type"] = "select";
addBoolOpt(pp["srtopts"]["options"], "messageapi", "Message API", "When true, uses the default Message API. When false, uses the Stream API", true);
//addIntOpt(pp, "kmrefreshrate", "", ""); //addIntOpt(pp, "kmrefreshrate", "", "");
//addIntOpt(pp, "kmreannounce", "", ""); //addIntOpt(pp, "kmreannounce", "", "");
addBoolOpt(pp, "enforcedencryption", "Enforced Encryption", "If enabled, enforces that both sides either set no passphrase, or set the same passphrase. When disabled, falls back to no passphrase if the passphrases do not match.", true); addBoolOpt(pp["srtopts"]["options"], "enforcedencryption", "Enforced Encryption", "If enabled, enforces that both sides either set no passphrase, or set the same passphrase. When disabled, falls back to no passphrase if the passphrases do not match.", true);
addIntOpt(pp, "peeridletimeo", "Peer Idle Timeout", "Time to wait, in milliseconds, before the connection is considered broken if the peer does not respond.", 5000); addIntOpt(pp["srtopts"]["options"], "peeridletimeo", "Peer Idle Timeout", "Time to wait, in milliseconds, before the connection is considered broken if the peer does not respond.", 5000,"ms");
addStrOpt(pp, "packetfilter", "Packet Filter", "Sets the SRT packet filter string, see SRT library documentation for details."); addStrOpt(pp["srtopts"]["options"], "packetfilter", "Packet Filter", "Sets the SRT packet filter string, see SRT library documentation for details.");
JSON::Value opt; JSON::Value opt;
opt["arg"] = "string"; opt["arg"] = "string";
@ -313,32 +396,83 @@ namespace Mist{
opt["default"] = ""; opt["default"] = "";
opt["help"] = "Which parser to use for data tracks"; opt["help"] = "Which parser to use for data tracks";
config->addOption("datatrack", opt); config->addOption("datatrack", opt);
capa["optional"]["passphrase"]["name"] = "Passphrase";
capa["optional"]["passphrase"]["help"] = "If set, requires a SRT passphrase to connect";
capa["optional"]["passphrase"]["type"] = "string";
capa["optional"]["passphrase"]["option"] = "--passphrase";
capa["optional"]["passphrase"]["short"] = "P";
capa["optional"]["passphrase"]["default"] = "";
capa["optional"]["passphrase"]["minlength"] = 10;
capa["optional"]["passphrase"]["maxlength"] = 79;
opt.null();
opt["long"] = "passphrase";
opt["short"] = "P";
opt["arg"] = "string";
opt["default"] = "";
opt["help"] = "If set, requires a SRT passphrase to connect";
config->addOption("passphrase", opt);
capa["optional"]["sockopts"]["name"] = "SRT socket options";
capa["optional"]["sockopts"]["help"] = "Any additional SRT socket options to apply";
capa["optional"]["sockopts"]["type"] = "string";
capa["optional"]["sockopts"]["option"] = "--sockopts";
capa["optional"]["sockopts"]["short"] = "O";
capa["optional"]["sockopts"]["default"] = "";
opt.null();
opt["long"] = "sockopts";
opt["short"] = "O";
opt["arg"] = "string";
opt["default"] = "";
opt["help"] = "Any additional SRT socket options to apply";
config->addOption("sockopts", opt);
} }
// Buffers TS packets and sends after 7 are buffered. // Buffers TS packets and sends after 7 are buffered.
void OutTSSRT::sendTS(const char *tsData, size_t len){ void OutTSSRT::sendTS(const char *tsData, size_t len){
packetBuffer.append(tsData, len); packetBuffer.append(tsData, len);
if (packetBuffer.size() >= 1316){//7 whole TS packets if (packetBuffer.size() >= 1316){//7 whole TS packets
if (!srtConn){ if (!*srtConn){
if (config->getString("target").size()){ if (config->getString("target").size()){
if (lastWorked + 5 < Util::bootSecs()){
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed, no reconnect success after 5s");
config->is_active = false;
parseData = false;
return;
}
INFO_MSG("Reconnecting..."); INFO_MSG("Reconnecting...");
srtConn.connect(target.host, target.getPort(), "output", targetParams); if (srtConn){
if (!srtConn){Util::sleep(500);} srtConn->close();
delete srtConn;
}
if (udpInit){
srtConn = new Socket::SRTConnection(*udpInit, "rendezvous", targetParams);
}else{ }else{
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed"); srtConn = new Socket::SRTConnection();
myConn.close(); }
srtConn->connect(target.host, target.getPort(), "output", targetParams);
if (!*srtConn){Util::sleep(500);}
}else{
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed (mid-send)");
config->is_active = false;
parseData = false; parseData = false;
return; return;
} }
} }
if (srtConn){ if (*srtConn){
srtConn.SendNow(packetBuffer, packetBuffer.size()); srtConn->SendNow(packetBuffer, packetBuffer.size());
if (!srtConn){ if (!*srtConn){
if (!config->getString("target").size()){ if (!config->getString("target").size()){
Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed"); Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection closed (post-send)");
myConn.close(); config->is_active = false;
parseData = false; parseData = false;
} }
}else{
lastWorked = Util::bootSecs();
} }
} }
packetBuffer.assign(0,0); packetBuffer.assign(0,0);
@ -346,11 +480,12 @@ namespace Mist{
} }
void OutTSSRT::requestHandler(){ void OutTSSRT::requestHandler(){
size_t recvSize = srtConn.Recv(); size_t recvSize = srtConn->Recv();
if (!recvSize){ if (!recvSize){
if (!srtConn){ if (!*srtConn){
myConn.close(); Util::logExitReason(ER_CLEAN_REMOTE_CLOSE, "SRT connection %s (in request handler)", srtConn->getStateStr());
srtConn.close(); config->is_active = false;
srtConn->close();
wantRequest = false; wantRequest = false;
}else{ }else{
Util::sleep(50); Util::sleep(50);
@ -358,13 +493,13 @@ namespace Mist{
return; return;
} }
lastRecv = Util::bootSecs(); lastRecv = Util::bootSecs();
if (!assembler.assemble(tsIn, srtConn.recvbuf, recvSize, true)){return;} if (!assembler.assemble(tsIn, srtConn->recvbuf, recvSize, true)){return;}
while (tsIn.hasPacket()){ while (tsIn.hasPacket()){
tsIn.getEarliestPacket(thisPacket); tsIn.getEarliestPacket(thisPacket);
if (!thisPacket){ if (!thisPacket){
INFO_MSG("Could not get TS packet"); Util::logExitReason(ER_FORMAT_SPECIFIC, "Could not get TS packet");
myConn.close(); config->is_active = false;
srtConn.close(); srtConn->close();
wantRequest = false; wantRequest = false;
return; return;
} }
@ -380,7 +515,7 @@ namespace Mist{
size_t thisIdx = M.trackIDToIndex(thisPacket.getTrackId(), getpid()); size_t thisIdx = M.trackIDToIndex(thisPacket.getTrackId(), getpid());
if (thisIdx == INVALID_TRACK_ID){return;} if (thisIdx == INVALID_TRACK_ID){return;}
if (!userSelect.count(thisIdx)){ if (!userSelect.count(thisIdx)){
userSelect[thisIdx].reload(streamName, thisIdx, COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK); userSelect[thisIdx].reload(streamName, thisIdx, COMM_STATUS_ACTIVE | COMM_STATUS_SOURCE | COMM_STATUS_DONOTTRACK);
} }
uint64_t pktTimeWithOffset = thisPacket.getTime() + timeStampOffset; uint64_t pktTimeWithOffset = thisPacket.getTime() + timeStampOffset;
@ -406,164 +541,126 @@ namespace Mist{
bool OutTSSRT::dropPushTrack(uint32_t trackId, const std::string & dropReason){ bool OutTSSRT::dropPushTrack(uint32_t trackId, const std::string & dropReason){
Util::logExitReason(ER_SHM_LOST, "track dropped by buffer"); Util::logExitReason(ER_SHM_LOST, "track dropped by buffer");
myConn.close(); config->is_active = false;
srtConn.close(); if (srtConn){srtConn->close();}
return Output::dropPushTrack(trackId, dropReason); return Output::dropPushTrack(trackId, dropReason);
} }
void OutTSSRT::connStats(uint64_t now, Comms::Connections &statComm){ void OutTSSRT::connStats(uint64_t now, Comms::Connections &statComm){
if (!srtConn){return;} if (!srtConn || !*srtConn){return;}
statComm.setUp(srtConn.dataUp()); statComm.setUp(srtConn->dataUp());
statComm.setDown(srtConn.dataDown()); statComm.setDown(srtConn->dataDown());
statComm.setTime(now - srtConn.connTime()); statComm.setTime(now - srtConn->connTime());
statComm.setPacketCount(srtConn.packetCount()); statComm.setPacketCount(srtConn->packetCount());
statComm.setPacketLostCount(srtConn.packetLostCount()); statComm.setPacketLostCount(srtConn->packetLostCount());
statComm.setPacketRetransmitCount(srtConn.packetRetransmitCount()); statComm.setPacketRetransmitCount(srtConn->packetRetransmitCount());
} }
}// namespace Mist
bool OutTSSRT::listenMode(){
std::string tgt = config->getString("target");
Socket::SRTServer server_socket; return (!tgt.size() || (tgt.size() >= 6 && tgt.substr(0, 6) == "srt://" && Socket::interpretSRTMode(HTTP::URL(tgt)) == "listener"));
static uint64_t sockCount = 0;
void (*oldSignal)(int, siginfo_t *,void *) = 0;
void signal_handler(int signum, siginfo_t *sigInfo, void *ignore){
server_socket.close();
if (oldSignal){
oldSignal(signum, sigInfo, ignore);
} }
}
void handleUSR1(int signum, siginfo_t *sigInfo, void *ignore){ void initSRTConnection(Socket::UDPConnection & s, std::map<std::string, std::string> & arguments, bool listener = true){
if (!sockCount){
INFO_MSG("USR1 received - triggering rolling restart (no connections active)");
Util::Config::is_restarting = true;
Util::logExitReason(ER_CLEAN_SIGNAL, "signal USR1, no connections");
server_socket.close();
Util::Config::is_active = false;
}else{
INFO_MSG("USR1 received - triggering rolling restart when connection count reaches zero");
Util::Config::is_restarting = true;
Util::logExitReason(ER_CLEAN_SIGNAL, "signal USR1, after disconnect wait");
}
}
// Callback for SRT-serving threads
static void callThreadCallbackSRT(void *srtPtr){
sockCount++;
Socket::SRTConnection & srtSock = *(Socket::SRTConnection*)srtPtr;
int fds[2];
pipe(fds);
Socket::Connection Sconn(fds[0], fds[1]);
HIGH_MSG("Started thread for socket %i", srtSock.getSocket());
mistOut tmp(Sconn,srtSock);
tmp.run();
HIGH_MSG("Closing thread for socket %i", srtSock.getSocket());
Sconn.close();
srtSock.close();
delete &srtSock;
sockCount--;
if (!sockCount && Util::Config::is_restarting){
server_socket.close();
Util::Config::is_active = false;
INFO_MSG("Last active connection closed; triggering rolling restart now!");
}
}
int main(int argc, char *argv[]){
Socket::SRT::libraryInit(); Socket::SRT::libraryInit();
DTSC::trackValidMask = TRACK_VALID_EXT_HUMAN; Socket::SRTConnection * tmpSock = new Socket::SRTConnection(s, listener?"output":"rendezvous", arguments);
Util::redirectLogsIfNeeded(); if (!*tmpSock){
Util::Config conf(argv[0]); delete tmpSock;
Util::Config::binaryType = Util::OUTPUT; return;
mistOut::init(&conf);
if (conf.parseArgs(argc, argv)){
if (conf.getBool("json")){
mistOut::capa["version"] = PACKAGE_VERSION;
std::cout << mistOut::capa.toString() << std::endl;
return -1;
} }
conf.activate(); if (!listener){
std::string host;
int filelimit = conf.getInteger("filelimit"); uint32_t port;
Util::sysSetNrOpenFiles(filelimit); s.GetDestination(host, port);
tmpSock->connect(host, port, "output", arguments);
std::string target = conf.getString("target"); INFO_MSG("UDP to SRT socket conversion: %s", tmpSock->getStateStr());
if (!mistOut::listenMode() && (!target.size() || Socket::interpretSRTMode(HTTP::URL(target)) != "listener")){ }
Socket::Connection S(fileno(stdout), fileno(stdin)); Socket::Connection S(1, 0);
Socket::SRTConnection tmpSock;
mistOut tmp(S, tmpSock); mistOut tmp(S, tmpSock);
return tmp.run(); tmp.run();
}
{
struct sigaction new_action;
new_action.sa_sigaction = handleUSR1;
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = 0;
sigaction(SIGUSR1, &new_action, NULL);
} }
void OutTSSRT::listener(Util::Config &conf, int (*callback)(Socket::Connection &S)){
// Check SRT options/arguments first
std::string target = conf.getString("target");
std::map<std::string, std::string> arguments;
if (target.size()){ if (target.size()){
//Force acceptable option to 1 (outgoing only), since this is a push output and we can't accept incoming connections //Force acceptable option to 1 (outgoing only), since this is a push output and we can't accept incoming connections
conf.getOption("acceptable", true).append((uint64_t)1); conf.getOption("acceptable", true).append((uint64_t)1);
//Disable overriding streamname with streamid parameter on other side //Disable overriding streamname with streamid parameter on other side
allowStreamNameOverride = false; allowStreamNameOverride = false;
HTTP::URL tgt(target); HTTP::URL tgt(target);
std::map<std::string, std::string> arguments;
HTTP::parseVars(tgt.args, arguments); HTTP::parseVars(tgt.args, arguments);
server_socket = Socket::SRTServer(tgt.getPort(), tgt.host, arguments, false, "output"); conf.getOption("interface", true).append(tgt.host);
conf.getOption("port", true).append((uint64_t)tgt.getPort());
conf.getOption("target", true).append(""); conf.getOption("target", true).append("");
}else{ }else{
std::map<std::string, std::string> arguments; HTTP::parseVars(conf.getString("sockopts"), arguments);
server_socket = Socket::SRTServer(conf.getInteger("port"), conf.getString("interface"), arguments, false, "output"); std::string opt = conf.getString("passphrase");
if (opt.size()){arguments["passphrase"] = opt;}
} }
if (!server_socket.connected()){
DEVEL_MSG("Failure to open socket"); uint16_t localPort;
return 1; // Either re-use socket 0 or bind a new socket
} Socket::UDPConnection udpSrv;
struct sigaction new_action; if (Socket::checkTrueSocket(0)){
struct sigaction cur_action; udpSrv.assimilate(0);
new_action.sa_sigaction = signal_handler; localPort = udpSrv.getBoundPort();
sigemptyset(&new_action.sa_mask);
new_action.sa_flags = SA_SIGINFO;
sigaction(SIGINT, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
sigaction(SIGHUP, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
sigaction(SIGTERM, &new_action, &cur_action);
if (cur_action.sa_sigaction && cur_action.sa_sigaction != oldSignal){
if (oldSignal){WARN_MSG("Multiple signal handlers! I can't deal with this.");}
oldSignal = cur_action.sa_sigaction;
}
Comms::defaultCommFlags = COMM_STATUS_NOKILL;
Util::Procs::socketList.insert(server_socket.getSocket());
while (conf.is_active && server_socket.connected()){
Socket::SRTConnection S = server_socket.accept(false, "output");
if (S.connected()){// check if the new connection is valid
// spawn a new thread for this connection
tthread::thread T(callThreadCallbackSRT, (void *)new Socket::SRTConnection(S));
// detach it, no need to keep track of it anymore
T.detach();
}else{ }else{
Util::sleep(10); // sleep 10ms localPort = udpSrv.bind(conf.getInteger("port"), conf.getString("interface"));
}
// Ensure socket zero is now us
if (udpSrv.getSock()){
int oldSock = udpSrv.getSock();
if (!dup2(oldSock, 0)){
udpSrv.assimilate(0);
} }
} }
Util::Procs::socketList.erase(server_socket.getSocket()); if (!udpSrv){
server_socket.close(); Util::logExitReason(ER_READ_START_FAILURE, "Failure to open listening socket");
if (conf.is_restarting){ conf.is_active = false;
INFO_MSG("Reloading input..."); return;
execvp(argv[0], argv); }
FAIL_MSG("Error reloading: %s", strerror(errno)); Util::Config::setServerFD(0);
udpSrv.allocateDestination();
Util::Procs::socketList.insert(udpSrv.getSock());
int maxFD = udpSrv.getSock();
while (conf.is_active && udpSrv){
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(maxFD, &rfds);
struct timeval T;
T.tv_sec = 2;
T.tv_usec = 0;
int r = select(maxFD + 1, &rfds, NULL, NULL, &T);
if (r){
while(udpSrv.Receive()){
// Ignore if it's not an SRT handshake packet
if (udpSrv.data.size() >= 4 && udpSrv.data[0] == 0x80 && !udpSrv.data[1] && !udpSrv.data[2] && !udpSrv.data[3]){
bool rendezvous = false;
if (udpSrv.data.size() >= 40){
rendezvous = (!udpSrv.data[36] && !udpSrv.data[37] && !udpSrv.data[38] && !udpSrv.data[39]);
}
std::string remoteIP, localIP;
uint32_t remotePort, localPort;
udpSrv.GetDestination(remoteIP, remotePort);
udpSrv.GetLocalDestination(localIP, localPort);
INFO_MSG("SRT handshake from %s:%" PRIu32 "! Spawning child process to handle it...", remoteIP.c_str(), remotePort);
if (!fork()){
Socket::UDPConnection s(udpSrv);
udpSrv.close();
if (!s.connect()){return;}
return initSRTConnection(s, arguments, !rendezvous);
} }
} }
INFO_MSG("Exit reason: %s", Util::exitReason); }
Socket::SRT::libraryCleanup(); }
return 0; }
} }
}// namespace Mist

View file

@ -5,25 +5,29 @@
namespace Mist{ namespace Mist{
class OutTSSRT : public TSOutput{ class OutTSSRT : public TSOutput{
public: public:
OutTSSRT(Socket::Connection &conn, Socket::SRTConnection & _srtSock); OutTSSRT(Socket::Connection &conn, Socket::SRTConnection * _srtSock = 0);
~OutTSSRT(); ~OutTSSRT();
static bool listenMode(){return !(config->getString("target").size());} static bool listenMode();
static void listener(Util::Config &conf, int (*callback)(Socket::Connection &S));
static void init(Util::Config *cfg); static void init(Util::Config *cfg);
void sendTS(const char *tsData, size_t len = 188); void sendTS(const char *tsData, size_t len = 188);
bool isReadyForPlay(){return true;} bool isReadyForPlay(){return true;}
virtual void requestHandler(); virtual void requestHandler();
virtual bool onFinish(); virtual bool onFinish();
virtual void initialSeek(bool dryRun = false);
inline virtual bool keepGoing(){return config->is_active;}
protected: protected:
virtual void connStats(uint64_t now, Comms::Connections &statComm); virtual void connStats(uint64_t now, Comms::Connections &statComm);
virtual std::string getConnectedHost(){return srtConn.remotehost;} virtual std::string getConnectedHost(){return srtConn?srtConn->remotehost:"";}
virtual std::string getConnectedBinHost(){return srtConn.getBinHost();} virtual std::string getConnectedBinHost(){return srtConn?srtConn->getBinHost():"";}
virtual bool dropPushTrack(uint32_t trackId, const std::string & dropReason); virtual bool dropPushTrack(uint32_t trackId, const std::string & dropReason);
private: private:
HTTP::URL target; HTTP::URL target;
int64_t timeStampOffset; int64_t timeStampOffset;
uint64_t lastTimeStamp; uint64_t lastTimeStamp;
uint64_t lastWorked;
bool pushOut; bool pushOut;
Util::ResizeablePointer packetBuffer; Util::ResizeablePointer packetBuffer;
Socket::UDPConnection pushSock; Socket::UDPConnection pushSock;
@ -31,7 +35,8 @@ namespace Mist{
TS::Assembler assembler; TS::Assembler assembler;
bool bootMSOffsetCalculated; bool bootMSOffsetCalculated;
Socket::SRTConnection & srtConn; Socket::SRTConnection * srtConn;
Socket::UDPConnection * udpInit;
}; };
}// namespace Mist }// namespace Mist

View file

@ -1,7 +1,7 @@
[wrap-git] [wrap-git]
directory = srt directory = srt
url = https://github.com/Haivision/srt.git url = https://github.com/Haivision/srt.git
revision = v1.5.1 revision = v1.5.3
patch_directory = libsrt patch_directory = libsrt
[provide] [provide]

View file

@ -1,9 +1,9 @@
project('SRT', 'cpp', 'c', version: '1.5.1') project('SRT', 'cpp', 'c', version: '1.5.3')
if host_machine.system() == 'cygwin' if host_machine.system() == 'cygwin'
add_project_arguments(['-DENABLE_LOGGING=1', '-O3', '-DNDEBUG', '-DENABLE_MONOTONIC_CLOCK=1', '-DENABLE_NEW_RCVBUFFER=1', '-DENABLE_SOCK_CLOEXEC=1', '-DHAI_ENABLE_SRT=1', '-DHAI_PATCH=1', '-DHAVE_INET_PTON=1', '-DHAVE_PTHREAD_GETNAME_NP=1', '-DHAVE_PTHREAD_SETNAME_NP=1', '-DCYGWIN=1', '-DCYGWIN_USE_POSIX', '-DNDEBUG', '-DSRT_DYNAMIC', '-DSRT_ENABLE_APP_READER', '-DSRT_ENABLE_CLOSE_SYNCH', '-DSRT_ENABLE_ENCRYPTION', '-DSRT_EXPORTS', '-DSRT_VERSION="1.5.1"', '-DUSE_MBEDTLS=1', '-D_GNU_SOURCE'], language: ['cpp','c']) add_project_arguments(['-DENABLE_LOGGING=1', '-O3', '-DNDEBUG', '-DENABLE_MONOTONIC_CLOCK=1', '-DENABLE_NEW_RCVBUFFER=1', '-DENABLE_SOCK_CLOEXEC=1', '-DHAI_ENABLE_SRT=1', '-DHAI_PATCH=1', '-DHAVE_INET_PTON=1', '-DHAVE_PTHREAD_GETNAME_NP=1', '-DHAVE_PTHREAD_SETNAME_NP=1', '-DCYGWIN=1', '-DCYGWIN_USE_POSIX', '-DNDEBUG', '-DSRT_DYNAMIC', '-DSRT_ENABLE_APP_READER', '-DSRT_ENABLE_CLOSE_SYNCH', '-DSRT_ENABLE_ENCRYPTION', '-DSRT_EXPORTS', '-DSRT_VERSION="1.5.3"', '-DUSE_MBEDTLS=1', '-D_GNU_SOURCE'], language: ['cpp','c'])
else else
add_project_arguments(['-DENABLE_LOGGING=1', '-O3', '-DNDEBUG', '-DENABLE_MONOTONIC_CLOCK=1', '-DENABLE_NEW_RCVBUFFER=1', '-DENABLE_SOCK_CLOEXEC=1', '-DHAI_ENABLE_SRT=1', '-DHAI_PATCH=1', '-DHAVE_INET_PTON=1', '-DHAVE_PTHREAD_GETNAME_NP=1', '-DHAVE_PTHREAD_SETNAME_NP=1', '-DLINUX=1', '-DNDEBUG', '-DSRT_DYNAMIC', '-DSRT_ENABLE_APP_READER', '-DSRT_ENABLE_BINDTODEVICE', '-DSRT_ENABLE_CLOSE_SYNCH', '-DSRT_ENABLE_ENCRYPTION', '-DSRT_EXPORTS', '-DSRT_VERSION="1.5.1"', '-DUSE_MBEDTLS=1', '-D_GNU_SOURCE'], language: ['cpp','c']) add_project_arguments(['-DENABLE_LOGGING=1', '-O3', '-DNDEBUG', '-DENABLE_MONOTONIC_CLOCK=1', '-DENABLE_NEW_RCVBUFFER=1', '-DENABLE_SOCK_CLOEXEC=1', '-DHAI_ENABLE_SRT=1', '-DHAI_PATCH=1', '-DHAVE_INET_PTON=1', '-DHAVE_PTHREAD_GETNAME_NP=1', '-DHAVE_PTHREAD_SETNAME_NP=1', '-DLINUX=1', '-DNDEBUG', '-DSRT_DYNAMIC', '-DSRT_ENABLE_APP_READER', '-DSRT_ENABLE_BINDTODEVICE', '-DSRT_ENABLE_CLOSE_SYNCH', '-DSRT_ENABLE_ENCRYPTION', '-DSRT_EXPORTS', '-DSRT_VERSION="1.5.3"', '-DUSE_MBEDTLS=1', '-D_GNU_SOURCE'], language: ['cpp','c'])
endif endif
@ -24,7 +24,8 @@ subdir('srt')
srt_src = files( srt_src = files(
'srtcore/api.cpp', 'srtcore/api.cpp',
'srtcore/buffer.cpp', 'srtcore/buffer_snd.cpp',
'srtcore/buffer_tools.cpp',
'srtcore/buffer_rcv.cpp', 'srtcore/buffer_rcv.cpp',
'srtcore/cache.cpp', 'srtcore/cache.cpp',
'srtcore/channel.cpp', 'srtcore/channel.cpp',
@ -71,7 +72,8 @@ libsrt = library(
'srt', 'srt',
sources: [srt_src, versionfile], sources: [srt_src, versionfile],
dependencies: [mbedtls_lib, mbedx509_lib, mbedcrypto_lib, thread_dep], dependencies: [mbedtls_lib, mbedx509_lib, mbedcrypto_lib, thread_dep],
include_directories: ['srt', 'haicrypt', 'srtcore'] include_directories: ['srt', 'haicrypt', 'srtcore'],
install: true
) )
srt_dep = declare_dependency( srt_dep = declare_dependency(
@ -81,3 +83,11 @@ srt_dep = declare_dependency(
include_directories: include_directories('.'), include_directories: include_directories('.'),
) )
pkg = import('pkgconfig')
pkg.generate(libraries : libsrt,
subdirs : ['.', 'srt'],
version : '1.5.3',
name : 'srt',
filebase : 'srt',
description : 'Haivision SRT library')

View file

@ -1,15 +1,14 @@
versionfile = configure_file(format: 'cmake@', output: 'version.h', input: files('../srtcore/version.h.in'), configuration: { versionfile = configure_file(format: 'cmake@', output: 'version.h', input: files('../srtcore/version.h.in'), configuration: {
'SRT_VERSION_MAJOR': 1, 'SRT_VERSION_MAJOR': 1,
'SRT_VERSION_MINOR' : 5, 'SRT_VERSION_MINOR' : 5,
'SRT_VERSION_PATCH': 1, 'SRT_VERSION_PATCH': 3,
'CI_BUILD_NUMBER_STRING': '"1.5.1"', 'CI_BUILD_NUMBER_STRING': '"1.5.3"',
'SRT_VERSION': '1.5.1', 'SRT_VERSION': '1.5.3',
}) }, install_dir: 'include/srt')
header_tgts += configure_file(copy:true, input: files('../srtcore/srt.h'), output: 'srt.h') header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/srt.h'), output: 'srt.h')
header_tgts += configure_file(copy:true, input: files('../srtcore/logging_api.h'), output: 'logging_api.h') header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/logging_api.h'), output: 'logging_api.h')
header_tgts += configure_file(copy:true, input: files('../srtcore/access_control.h'), output: 'access_control.h') header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/access_control.h'), output: 'access_control.h')
header_tgts += configure_file(copy:true, input: files('../srtcore/platform_sys.h'), output: 'platform_sys.h') header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/platform_sys.h'), output: 'platform_sys.h')
header_tgts += configure_file(copy:true, input: files('../srtcore/udt.h'), output: 'udt.h') header_tgts += configure_file(copy:true, install_dir: 'include/srt', input: files('../srtcore/udt.h'), output: 'udt.h')