@@ -6137,6 +6137,7 @@ var UI = {
61376137 } ) ;
61386138 $dashboard . append ( $findMist ) ;
61396139 $dashboard . append ( UI . modules . stream . actions ( "Status" , other ) ) ; //the actions can be used even if the http host is unknown
6140+ $dashboard . append ( UI . modules . stream . clients ( other ) ) ;
61406141
61416142 break ;
61426143 }
@@ -10332,6 +10333,118 @@ var UI = {
1033210333 return out ;
1033310334 }
1033410335 } ) ;
10336+ } ,
10337+ clients : function ( streamname ) {
10338+ var layout = {
10339+ Host : function ( d ) {
10340+ return d . host ;
10341+ } ,
10342+ Protocol : function ( d ) {
10343+ return d . protocol . replace ( "INPUT:" , "" ) ;
10344+ } ,
10345+ Connected : function ( d ) {
10346+ return UI . format . duration ( d . conntime ) ;
10347+ } ,
10348+ "Data downloaded" : function ( d ) {
10349+ return UI . format . bytes ( d . down ) ;
10350+ } ,
10351+ "Current bitrate" : function ( d ) {
10352+ return UI . format . bits ( d . downbps * 8 , true ) ;
10353+ } ,
10354+ "Media time" : function ( d ) {
10355+ return d . position ? UI . format . duration ( d . position ) : "" ;
10356+ } ,
10357+ "Packets received" : function ( d ) {
10358+ return d . pktcount ? UI . format . number ( d . pktcount , { round :false } ) : ""
10359+ } ,
10360+ "Packets lost" : function ( d ) {
10361+ return d . pktcount ? UI . format . number ( d . pktlost , { round :false } ) : ""
10362+ } ,
10363+ "Packets retransmitted" : function ( d ) {
10364+ return d . pktcount ? UI . format . number ( d . pktretransmit , { round :false } ) : ""
10365+ }
10366+
10367+ } ;
10368+ var $inputs = UI . dynamic ( {
10369+ create : function ( ) {
10370+ var $thead = $ ( "<thead>" ) ;
10371+ var $tbody = $ ( "<tbody>" ) ;
10372+ var $table = $ ( "<table>" ) . append ( $thead ) . append ( $tbody ) ;
10373+ $table . _rows = { } ;
10374+ for ( var i in layout ) {
10375+ var row = $ ( "<tr>" ) ;
10376+
10377+ var cell = $ ( "<td>" ) . text ( i + ":" ) ;
10378+ row . append ( cell ) ;
10379+
10380+ $table . _rows [ i ] = row ;
10381+ $tbody . append ( row ) ;
10382+ }
10383+ $thead . append ( $tbody . children ( ) . first ( ) ) ;
10384+ return $table ;
10385+ } ,
10386+ add : {
10387+ create : function ( ) {
10388+ var out = {
10389+ cells : { } ,
10390+ customAdd : function ( table ) {
10391+ for ( var i in this . cells ) {
10392+ table . _rows [ i ] . append ( this . cells [ i ] ) ;
10393+ }
10394+ } ,
10395+ remove : function ( table ) {
10396+ for ( var i in this . cells ) {
10397+ this . cells [ i ] . remove ( ) ;
10398+ delete this . cells [ i ] ;
10399+ }
10400+ }
10401+ } ;
10402+ for ( var i in layout ) {
10403+ out . cells [ i ] = $ ( "<td>" ) ;
10404+ }
10405+ return out ;
10406+ } ,
10407+ update : function ( d ) {
10408+ for ( var i in this . cells ) {
10409+ var value = layout [ i ] . call ( null , d ) ;
10410+ if ( this . cells [ i ] . raw != value ) {
10411+ this . cells [ i ] . html ( value ) ;
10412+ this . cells [ i ] . raw = value ;
10413+ }
10414+ }
10415+ }
10416+ } ,
10417+ update : function ( values ) {
10418+ if ( values . length ) {
10419+ if ( ! $inputs . parent ( ) . length ) {
10420+ $inputs . _parent . append ( $inputs ) ;
10421+ }
10422+ }
10423+ else if ( $inputs . parent ( ) ) {
10424+ $inputs . _parent = $inputs . parent ( ) ;
10425+ $inputs . remove ( ) ;
10426+ }
10427+ }
10428+ } ) ;
10429+
10430+ UI . sockets . http . clients . subscribe ( function ( d ) {
10431+ for ( var i = d . data . length - 1 ; i >= 0 ; i -- ) {
10432+ if ( d . data [ i ] . stream != streamname ) {
10433+ d . data . splice ( i , 1 ) ;
10434+ }
10435+ }
10436+ $inputs . update ( d . data ) ;
10437+ //console.warn(d);
10438+ } , { streams :[ streamname ] , protocols :[ "INPUT" ] } ) ;
10439+
10440+
10441+ return $ ( "<section>" ) . addClass ( "clients" ) . append (
10442+ $ ( "<div>" ) . addClass ( "inputs" ) . append (
10443+ $ ( "<h3>" ) . text ( "Current input" )
10444+ ) . append (
10445+ $inputs
10446+ )
10447+ )
1033510448 }
1033610449 } ,
1033710450 pushes : function ( options ) {
@@ -11316,7 +11429,51 @@ var UI = {
1131611429 }
1131711430 else {
1131811431 this . listeners . push ( callback ) ;
11432+ this . get ( ) ;
11433+ }
11434+ }
11435+ } ,
11436+ clients : {
11437+ requests : [ ] ,
11438+ listeners : [ ] ,
11439+ interval : false ,
11440+ subscribe : function ( callback , request ) {
11441+ if ( ! this . interval || ! ( this . interval in UI . interval . list ) ) {
11442+ this . listeners = [ ] ;
11443+ this . requests = [ ] ;
11444+ }
11445+
11446+ if ( ! ( "time" in request ) ) { request . time = - 3 ; }
11447+ this . requests . push ( request ) ;
11448+ this . listeners . push ( callback ) ;
11449+ var me = this ;
11450+
11451+ if ( this . listeners . length == 1 ) {
11452+ //we only have to do this once because {clients: this.requests} is a pointer and the callback loops over this.listeners
11453+ UI . sockets . http . api . subscribe ( function ( d ) {
11454+ for ( var i in d . clients ) {
11455+ var res = d . clients [ i ] ;
11456+ //make it prettier
11457+ var out = { data : [ ] , time : res . time } ;
11458+ for ( var j in res . data ) {
11459+ var entry = { } ;
11460+ for ( var k in res . fields ) {
11461+ var key = res . fields [ k ] ;
11462+ entry [ key ] = res . data [ j ] [ k ] ;
11463+ }
11464+ out . data . push ( entry ) ;
11465+ }
11466+
11467+ me . listeners [ i ] . call ( null , out ) ;
11468+ }
11469+ } , { clients :this . requests } ) ;
11470+ this . interval = UI . sockets . http . api . interval ;
11471+ }
11472+ else {
11473+ //execute the api call right now
11474+ UI . sockets . http . api . get ( ) ;
1131911475 }
11476+ //TODO reset on tab refresh
1132011477 }
1132111478 } ,
1132211479 player : function ( callback , errorCallback ) {
0 commit comments