2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

fhemweb.js: ping the ws connection every 30s (Forum #85080)

git-svn-id: https://svn.fhem.de/fhem/trunk@16311 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2018-03-02 10:58:36 +00:00
parent e1fe302c6b
commit 87477e33cb
3 changed files with 16 additions and 4 deletions

View File

@ -817,7 +817,7 @@ FW_answerCall($)
$FW_plotsize = AttrVal($FW_wname, "plotsize", $FW_ss ? "480,160" :
$FW_tp ? "640,160" : "800,160");
my ($cmd, $cmddev) = FW_digestCgi($arg);
if($cmd && $FW_CSRF && $cmd !~ m/style (list|select)/) {
if($cmd && $FW_CSRF && $cmd !~ m/style (list|select|eventMonitor)/) {
my $supplied = defined($FW_webArgs{fwcsrf}) ? $FW_webArgs{fwcsrf} : "";
my $want = $defs{$FW_wname}{CSRFTOKEN};
if($supplied ne $want) {
@ -2394,7 +2394,8 @@ FW_pH(@)
my ($link, $txt, $td, $class, $doRet,$nonl) = @_;
my $ret;
$link .= $FW_CSRF if($link =~ m/cmd/ && $link !~m/cmd=style%20(list|select)/);
$link .= $FW_CSRF if($link =~ m/cmd/ &&
$link !~m/cmd=style%20(list|select|eventMonitor)/);
$link = ($link =~ m,^/,) ? $link : "$FW_ME$FW_subdir?$link";
# Using onclick, as href starts safari in a webapp.

View File

@ -84,14 +84,14 @@ consFill()
var loc = (""+location).replace(/\?.*/,"");
if($("body").attr("longpoll") == "websocket") {
if(consConn) {
if(consConn)
consConn.close();
}
consConn = new WebSocket(loc.replace(/[&?].*/,'')
.replace(/^http/i, "ws")+query);
consConn.onclose =
consConn.onerror =
consConn.onmessage = consUpdate;
setTimeout(function(){FW_wsPing(consConn);}, 30000);
} else {
if(consConn) {

View File

@ -1108,6 +1108,7 @@ FW_longpoll()
FW_pollConn.onclose =
FW_pollConn.onerror =
FW_pollConn.onmessage = FW_doUpdate;
setTimeout(function(){FW_wsPing(FW_pollConn);}, 30000);
} else {
FW_pollConn = new XMLHttpRequest();
@ -1123,6 +1124,16 @@ FW_longpoll()
") with filter "+filter);
}
function
FW_wsPing(conn) // idle websockets are closed by the browser after 55sec
{
if(!conn || conn.readyState != conn.OPEN)
return;
conn.send("\n");
setTimeout(function(){FW_wsPing(conn);}, 30000);
}
/*************** LONGPOLL END **************/