mirror of
https://github.com/unraid/webgui.git
synced 2026-05-04 00:39:32 -05:00
Feat support string or array passed as a message
This commit is contained in:
@@ -87,7 +87,6 @@ while (true) {
|
||||
}
|
||||
if ($running < 1) $echo = "<tr><td colspan='7' style='text-align:center;padding-top:12px'>"._('No VMs running')."</td></tr>";
|
||||
|
||||
$echo = json_encode($echo);
|
||||
publish_md5('vm_usage',$echo,true);
|
||||
|
||||
sleep($timer);
|
||||
|
||||
@@ -25,6 +25,7 @@ function curl_socket($socket, $url, $message='') {
|
||||
return $reply;
|
||||
}
|
||||
|
||||
// $message: if an array, it will be converted to a JSON string
|
||||
// $abort: if true, the script will exit if the endpoint is without subscribers on the next publish attempt after $abortTime seconds
|
||||
// If a script publishes to multiple endpoints, timing out on one endpoint will terminate the entire script even if other enpoints succeed.
|
||||
// If this is a problem, don't use $abort and instead handle this in the script or utilize a single sript per endpoint.
|
||||
@@ -38,6 +39,10 @@ function publish($endpoint, $message, $opt1=1, $opt2=false, $opt3=120) {
|
||||
if ( is_file("/tmp/publishPaused") )
|
||||
return false;
|
||||
|
||||
if ( is_array($message) ) {
|
||||
$message = json_encode($message,true);
|
||||
}
|
||||
|
||||
// handle the $opt1/$opt2/$opt3 parameters while remaining backwards compatible
|
||||
if ( is_numeric($opt1) ) {
|
||||
$len = $opt1;
|
||||
@@ -120,6 +125,10 @@ function publish_md5($endpoint, $message, $opt1=1, $opt2=false, $opt3=120) {
|
||||
$timeout = $opt2 ?: $opt3;
|
||||
}
|
||||
|
||||
if ( is_array($message) ) {
|
||||
$message = json_encode($message,true);
|
||||
}
|
||||
|
||||
// if abort is set, republish the message even if it hasn't changed after $timeout seconds to check for subscribers and exit accordingly
|
||||
if ( $abort ) {
|
||||
if ( (time() - ($md5_time[$endpoint]??0)) > $timeout ) {
|
||||
|
||||
@@ -122,7 +122,7 @@ while (true) {
|
||||
$share = array_keys($shares);
|
||||
$count = array_count_values($lsof ?? array());
|
||||
foreach ($share as $name) $echo['stream'][] = $count[$name]??0;
|
||||
$echo = json_encode($echo);
|
||||
|
||||
publish_md5('update1',$echo,true);
|
||||
|
||||
sleep(5);
|
||||
|
||||
@@ -499,7 +499,6 @@ while (true) {
|
||||
$echo[$a] = [implode($echo[$a]), $extra];
|
||||
}
|
||||
|
||||
$echo = json_encode($echo);
|
||||
publish_md5('update2',$echo,true);
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
@@ -159,7 +159,6 @@ while (true) {
|
||||
$date = my_date($xdate ? 'D j M Y, T' : $display['date'].', T',$now);
|
||||
$echo['time'] = [$clock,_($date,0)];
|
||||
|
||||
$echo = json_encode($echo);
|
||||
publish_md5('update3',$echo,true);
|
||||
|
||||
sleep(1);
|
||||
|
||||
@@ -131,7 +131,6 @@ while (true) {
|
||||
elseif (isset($load)) $echo[5] = ($load<90 ? "<span>" : "<span $red>").$echo[5]."</span>";
|
||||
$echo[6] = isset($output) ? ((empty($volt) || ($minv<$output && $output<$maxv) ? "<span $green>" : "<span $red>").$echo[6].(isset($freq) ? " ~ $freq Hz" : "")."</span>") : $echo[6];
|
||||
}
|
||||
$echo = json_encode($echo);
|
||||
|
||||
publish_md5('apcups',$echo,true);
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@ while (true) {
|
||||
$row = preg_split('/\s+/',$row);
|
||||
if (count($row)>5) $echo[] = [$row[0], $row[5]?$now-$row[5]:0, my_scale($row[6],$unit)." $unit", my_scale($row[7],$unit)." $unit"];
|
||||
}
|
||||
$echo = json_encode($echo);
|
||||
publish_md5('wireguard',$echo,true);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ while (true) {
|
||||
}
|
||||
}
|
||||
// Short of closing all web pages, the timeout should only happen if wifi is enabled and then disabled
|
||||
publish_md5('wlan0',json_encode($echo),true);
|
||||
publish_md5('wlan0',$echo,true);
|
||||
sleep(3);
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user