From 2b4056398ea584273258ddd39110fb30f2aa284f Mon Sep 17 00:00:00 2001 From: nasseeder1 <> Date: Sun, 28 Feb 2016 19:14:13 +0000 Subject: [PATCH] 49_SSCAM: enhanced command runView by option "link_open" to open a streamlink immediately git-svn-id: https://svn.fhem.de/fhem/trunk@10959 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 2 + fhem/FHEM/49_SSCam.pm | 90 ++++++++++++++++++++++++++++++------------- 2 files changed, 65 insertions(+), 27 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 70f60d484..bfad6cee1 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature 49_SSCAM: enhanced command runView by option "link_open" to + open a streamlink immediately - feature: new module LGTV_IP12 for controlling LG SmartTV's manufactured between 2012-2014 via network connection - feature: 30_MilightBridge: Support tcp bridge. diff --git a/fhem/FHEM/49_SSCam.pm b/fhem/FHEM/49_SSCam.pm index e6a12f68e..7cddd9054 100644 --- a/fhem/FHEM/49_SSCam.pm +++ b/fhem/FHEM/49_SSCam.pm @@ -27,6 +27,8 @@ ########################################################################################################## # Versions History: # +# 1.19.1 28.02.2016 enhanced command runView by option "link_open" to +# open a streamlink immediately # 1.19 25.02.2016 functions for cam-livestream added # 1.18.1 21.02.2016 fixed a problem that the state is "disable" instead of # "disabled" if a camera is disabled and FHEM will be restarted @@ -262,7 +264,7 @@ sub SSCam_Set { "snap ". "enable ". "disable ". - "runView:image,link ". + "runView:image,link,link_open ". "stopView:noArg ". ((ReadingsVal("$name", "DeviceType", "Camera") eq "PTZ") ? "runPatrol:".ReadingsVal("$name", "Patrols", "")." " : ""). ((ReadingsVal("$name", "DeviceType", "Camera") eq "PTZ") ? "goPreset:".ReadingsVal("$name", "Presets", "")." " : ""). @@ -396,6 +398,15 @@ sub SSCam_Set { elsif ($opt eq "runView") { if (!$hash->{CREDENTIALS}) {return "Credentials of $name are not set - make sure you've set it with \"set $name credentials username password\"";} + + if ($prop eq "link_open") { + $prop = "link"; + if ($prop1) {$hash->{HELPER}{VIEWOPENROOM} = $prop1;} else {delete $hash->{HELPER}{VIEWOPENROOM};} + $hash->{HELPER}{OPENWINDOW} = 1; + } else { + $hash->{HELPER}{OPENWINDOW} = 0; + } + $hash->{HELPER}{WLTYPE} = $prop; runliveview($hash); } @@ -2180,6 +2191,7 @@ sub camop_nonbl ($) { my $apivideostmmaxver = $hash->{HELPER}{APIVIDEOSTMMAXVER}; my $sid = $hash->{HELPER}{SID}; my $OpMode = $hash->{OPMODE}; + my ($livestream,$winname,$attr,$room); my $url; my $camid; my $snapid; @@ -2423,7 +2435,7 @@ sub camop_nonbl ($) { # SID nach SID_STRM sichern und nutzen (für stopLiveview-Routine) $hash->{HELPER}{SID_STRM} = $sid; # externe URL - my $livestream = !AttrVal($name, "livestreamprefix", undef) ? "http://$serveraddr:$serverport" : AttrVal($name, "livestreamprefix", undef); + $livestream = !AttrVal($name, "livestreamprefix", undef) ? "http://$serveraddr:$serverport" : AttrVal($name, "livestreamprefix", undef); $livestream .= "/webapi/$apivideostmpath?api=$apivideostm&version=$apivideostmmaxver&method=Stream&cameraId=$camid&format=mjpeg&_sid=\"$sid\""; # interne URL $url = "http://$serveraddr:$serverport/webapi/$apivideostmpath?api=$apivideostm&version=$apivideostmmaxver&method=Stream&cameraId=$camid&format=mjpeg&_sid=\"$sid\""; @@ -2434,6 +2446,20 @@ sub camop_nonbl ($) { $logstr = "Set Livestream-URL: $url"; &printlog($hash,$logstr,"4"); + + # livestream sofort in neuem Browsertab öffnen + if ($hash->{HELPER}{OPENWINDOW}) { + $winname = $name."_view"; + $attr = AttrVal($name, "htmlattr", ""); + # öffnen streamwindow für die Instanz die "VIEWOPENROOM" oder Attr "room" aktuell geöffnet hat + + if ($hash->{HELPER}{VIEWOPENROOM}) { + $room = $hash->{HELPER}{VIEWOPENROOM}; + map {FW_directNotify("FILTER=room=$room", "#FHEMWEB:$_", "window.open ('$url','$winname','$attr')", "")} devspec2array("WEB.*"); + } else { + map {FW_directNotify("#FHEMWEB:$_", "window.open ('$url','$winname','$attr')", "")} devspec2array("WEB.*"); + } + } $logstr = "--- End Function cam: $OpMode nonblocking ---"; &printlog($hash,$logstr,"4"); @@ -2445,7 +2471,7 @@ sub camop_nonbl ($) { { readingsSingleUpdate($hash,"state", "off", 1); } - + $hash->{HELPER}{ACTIVE} = "off"; return; } @@ -3728,7 +3754,7 @@ return; "runPatrol <Patrolname>": starts a predefinied patrol (PTZ-cameras) "goAbsPTZ [ X Y | up | down | left | right ]": moves a PTZ-camera to a absolute X/Y-coordinate or to direction up/down/left/right "move [ up | down | left | right | dir_X ]": starts a continuous move of PTZ-camera to direction up/down/left/right or dir_X - "runView [image | link]": starts a livestream as embedded image or link + "runView [image | link | link_open <room> ]": starts a livestream as embedded image or link "stopView": stops a camera livestream

@@ -3922,18 +3948,23 @@ return;
- set <name> runView [ image | link ]

+ set <name> runView [ image | link | link_open <room> ]

- A livestream of a camera will be started, either as embedded image or as a generated link. + A livestream (mjpeg-stream) of a camera will be started, either as embedded image or as a generated link. The behavior of livestream in FHEMWEB can be affected by statements in attribute "htmlattr".

- Example:
+ Examples:
     attr <name> htmlattr target=_blank width="500" height="375"
+    attr <name> htmlattr target=_blank width=500,height=375
+    attr <name> htmlattr width=700,height=525,top=200,left=300
   
- With these attribute values a streaming link will be opened in a new browser tab. If the stream will be started as an image, the size changes appropriately the - values of width and hight.
+ With these attribute values a streaming link will be opened (by click on) in a new browser tab or windows. If the stream will be started as an image, the size changes appropriately the + values of width and hight.
+ The command "set <name> runView link_open" starts the stream immediately in a new browser window (longpoll=1 must be set for WEB). + A browser window will be initiated to open for every FHEM session which is active. If you want to change this, + you can use command "set <name> runView link_open <room>" what initiates to open a browser window in that FHEM session that has just opend the room <room>. The settings of attribute "livestreamprefix" overwrite the data for protocol, servername and port in reading "LiveStreamUrl". With it the LivestreamURL can be modified and used for distribution and external access to SVS livestream.

@@ -4290,21 +4321,21 @@ return; - - - - - - - - - - - - - - - + + + + + + + + + + + + + + +
"on [rectime]": startet eine Aufnahme. Die Aufnahme wird automatisch nach Ablauf der Zeit [rectime] gestoppt.
Mit rectime = 0 wird eine Daueraufnahme gestartet die durch "set <name> off" wieder gestoppt werden muß.
"off" : stoppt eine laufende Aufnahme manuell oder durch die Nutzung anderer Events (z.B. über at, notify)
"snap": löst einen Schnappschuß der entsprechenden Kamera aus und speichert ihn in der Synology Surveillance Station
"disable": deaktiviert eine Kamera in der Synology Surveillance Station
"enable": aktiviert eine Kamera in der Synology Surveillance Station
"credentials <username> <password>": speichert die Zugangsinformationen
"expmode [ day | night | auto ]": aktiviert den Belichtungsmodus Tag, Nacht oder Automatisch
"motdetsc [ camera | SVS | disable ]": schaltet die Bewegungserkennung in den gewünschten Modus (durch Kamera, SVS, oder deaktiviert)
"goPreset <Presetname>": bewegt eine PTZ-Kamera zu einer vordefinierten Preset-Position
"runPatrol <Patrolname>": startet eine vordefinierte Überwachungstour einer PTZ-Kamera
"goAbsPTZ [ X Y | up | down | left | right ]": positioniert eine PTZ-camera zu einer absoluten X/Y-Koordinate oder maximalen up/down/left/right-position
"move [ up | down | left | right | dir_X ]": startet kontinuerliche Bewegung einer PTZ-Kamera in Richtung up/down/left/right bzw. dir_X
"runView [image | link]": startet einen Livestream als eingbettetes Image oder als Link
"stopView": stoppt einen Kamera-Livestream
"on [rectime]": startet eine Aufnahme. Die Aufnahme wird automatisch nach Ablauf der Zeit [rectime] gestoppt.
Mit rectime = 0 wird eine Daueraufnahme gestartet die durch "set <name> off" wieder gestoppt werden muß.
"off" : stoppt eine laufende Aufnahme manuell oder durch die Nutzung anderer Events (z.B. über at, notify)
"snap": löst einen Schnappschuß der entsprechenden Kamera aus und speichert ihn in der Synology Surveillance Station
"disable": deaktiviert eine Kamera in der Synology Surveillance Station
"enable": aktiviert eine Kamera in der Synology Surveillance Station
"credentials <username> <password>": speichert die Zugangsinformationen
"expmode [ day | night | auto ]": aktiviert den Belichtungsmodus Tag, Nacht oder Automatisch
"motdetsc [ camera | SVS | disable ]": schaltet die Bewegungserkennung in den gewünschten Modus (durch Kamera, SVS, oder deaktiviert)
"goPreset <Presetname>": bewegt eine PTZ-Kamera zu einer vordefinierten Preset-Position
"runPatrol <Patrolname>": startet eine vordefinierte Überwachungstour einer PTZ-Kamera
"goAbsPTZ [ X Y | up | down | left | right ]": positioniert eine PTZ-camera zu einer absoluten X/Y-Koordinate oder maximalen up/down/left/right-position
"move [ up | down | left | right | dir_X ]": startet kontinuerliche Bewegung einer PTZ-Kamera in Richtung up/down/left/right bzw. dir_X
"runView [image | link | link_open <room> ]": startet einen Livestream als eingbettetes Image oder als Link
"stopView": stoppt einen Kamera-Livestream


@@ -4494,18 +4525,23 @@ return;
- set <name> runView [ image | link ]

+ set <name> runView [ image | link | link_open <room> ]

- Es wird ein Livestream der Kamera, entweder als eingebettetes Image oder als generierter Link, gestartet. + Es wird ein Livestream (mjpeg-Stream) der Kamera, entweder als eingebettetes Image oder als generierter Link, gestartet. Das Verhalten des Livestreams im FHEMWEB kann durch Angaben im Attribut "htmlattr" beeinflusst werden.

Beispiel:
     attr <name> htmlattr target=_blank width="500" height="375"
+    attr <name> htmlattr target=_blank width=500,height=375
+    attr <name> htmlattr width=700,height=525,top=200,left=300
   
- Mit diesen Attributwerten öffnet der Link als weiteres Fenster/Browsertab. Wird der Stream als Image gestartet, ändert sich die Größe entsprechend der + Mit diesen Attributwerten öffnet der Link (mit Klick) als weiteres Fenster/Browsertab. Wird der Stream als Image gestartet, ändert sich die Größe entsprechend der Angaben von Width und Hight.
+ Das Kommando "set <name> runView link_open" startet den Livestreamlink sofort in einem neuen Browserfenster (longpoll=1 muß für WEB gesetzt sein). + Dabei wird für jede aktive FHEM-Session eine Fensteröffnung initiiert. Soll dieses Verhalten geändert werden, kann "set <name> runView link_open <room>" + verwendet werden um das Öffnen des Browserwindows in einem beliebigen in einer FHEM-Session angezeigten Raum <room> zu initiieren.
Das gesetzte Attribut "livestreamprefix" überschreibt im Reading "LiveStreamUrl" die Angaben für Protokoll, Servername und Port. Damit kann z.B. die LiveStreamUrl für den Versand und externen Zugriff auf die SVS modifiziert werden.