From ec01d4fa74aac62d00b6ca7b4ca5d545dc7c203a Mon Sep 17 00:00:00 2001 From: rudolfkoenig Date: Wed, 31 Jan 2018 09:27:17 +0000 Subject: [PATCH] FHEMWEB.pm: set default to websocket for Chrome (Forum #83349) git-svn-id: https://svn.fhem.de/fhem/trunk@16053 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/01_FHEMWEB.pm | 51 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/fhem/FHEM/01_FHEMWEB.pm b/fhem/FHEM/01_FHEMWEB.pm index 38a3a297e..f417ad745 100644 --- a/fhem/FHEM/01_FHEMWEB.pm +++ b/fhem/FHEM/01_FHEMWEB.pm @@ -226,6 +226,14 @@ FHEMWEB_Initialize($) FW_readIcons($pe); } } + + eval { require Digest::SHA; }; + if($@) { + Log 4, $@; + Log 3, "FHEMWEB: Can't load Digest::SHA, ". + "longpoll via websocket is not available"; + } + $FW_use_sha = 1; } ##################################### @@ -340,7 +348,7 @@ FW_Read($$) } } - if($hash->{websocket}) { # Work in Progress (Forum #59713) + if($hash->{websocket}) { # 59713 my $fin = (ord(substr($hash->{BUF},0,1)) & 0x80)?1:0; my $op = (ord(substr($hash->{BUF},0,1)) & 0x0F); my $mask = (ord(substr($hash->{BUF},1,1)) & 0x80)?1:0; @@ -461,6 +469,8 @@ FW_Read($$) $hash->{LASTACCESS} = $now; $FW_userAgent = $FW_httpheader{"User-Agent"}; + $FW_userAgent = "" if(!defined($FW_userAgent)); + $FW_ME = "/" . AttrVal($FW_wname, "webname", "fhem"); $FW_CSRF = (defined($defs{$FW_wname}{CSRFTOKEN}) ? "&fwcsrf=".$defs{$FW_wname}{CSRFTOKEN} : ""); @@ -682,7 +692,7 @@ FW_closeConn($) my ($hash) = @_; if(!$hash->{inform} && !$hash->{BUF}) { # Forum #41125 my $cc = AttrVal($hash->{SNAME}, "closeConn", - $FW_userAgent && $FW_userAgent=~m/(iPhone|iPad|iPod)/); + $FW_userAgent =~ m/(iPhone|iPad|iPod)/); if(!$FW_httpheader{Connection} || $cc) { TcpServer_Close($hash, 1); } @@ -989,7 +999,8 @@ FW_answerCall($) my $csrf= ($FW_CSRF ? "fwcsrf='$defs{$FW_wname}{CSRFTOKEN}'" : ""); my $gen = 'generated="'.(time()-1).'"'; - my $lp = 'longpoll="'.AttrVal($FW_wname,"longpoll",1).'"'; + my $lp = 'longpoll="'.AttrVal($FW_wname,"longpoll", + $FW_use_sha && $FW_userAgent=~m/Chrome/ ? "websocket": 1).'"'; $FW_id = $FW_chash->{NR} if( !$FW_id ); my $dataAttr = FW_dataAttr(); @@ -2566,13 +2577,8 @@ FW_Attr(@) } if($attrName eq "longpoll" && $type eq "set" && $param[0] eq "websocket") { - eval { require Digest::SHA; }; - if($@) { - Log3 $FW_wname, 1, $@; - return "$devName: Can't load Digest::SHA, no websocket"; - return -1; - } - $FW_use_sha = 1; + return "$devName: Could not load Digest::SHA on startup, no websocket" + if(!$FW_use_sha); } return $retMsg; @@ -3614,12 +3620,12 @@ FW_widgetOverride($$)
-
  • longpoll
    - Affects devices states in the room overview only.
    - In this mode status update is refreshed more or less instantaneously, - and state change (on/off only) is done without requesting a complete - refresh from the server. - Default is on. +
  • longpoll [0|1|websocket]
    + If activated, the browser is notifed when device states, readings or + attributes are changed, a reload of the page is not necessary. + Default is 1 (on), use 0 to deactivate it.
    + If websocket is specified, then this API is used to notify the browser, + else HTTP longpoll. Note: some older browser do not implement websocket.

  • @@ -4311,11 +4317,14 @@ FW_widgetOverride($$)
    -
  • longpoll
    - Dies betrifft die Aktualisierung der Gerätestati in der - Weboberfläche. Ist longpoll aktiviert, werden - Statusänderungen sofort im Browser dargestellt. ohne die Seite - manuell neu laden zu müssen. Standard ist aktiviert. +
  • longpoll [0|1|websocket]
    + Falls gesetzt, FHEMWEB benachrichtigt den Browser, wenn + Gerätestatuus, Readings or Attribute sich ändern, ein + Neuladen der Seite ist nicht notwendig. Zum deaktivieren 0 verwenden. +
    + Falls websocket spezifiziert ist, läuft die Benachrichtigung des + Browsers über dieses Verfahren sonst über HTTP longpoll. + Achtung: ältere Browser haben keine websocket Implementierung.