49_SSCamSTRM.pm 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. ########################################################################################################################
  2. # $Id: 49_SSCamSTRM.pm 17654 2018-10-31 22:44:31Z DS_Starter $
  3. #########################################################################################################################
  4. # 49_SSCamSTRM.pm
  5. #
  6. # (c) 2018 by Heiko Maaz
  7. # forked from 98_weblink.pm by Rudolf König
  8. # e-mail: Heiko dot Maaz at t-online dot de
  9. #
  10. # This Module is used by module 49_SSCam to create Streaming devices.
  11. # It can't be used without any SSCam-Device.
  12. #
  13. # This script is part of fhem.
  14. #
  15. # Fhem is free software: you can redistribute it and/or modify
  16. # it under the terms of the GNU General Public License as published by
  17. # the Free Software Foundation, either version 2 of the License, or
  18. # (at your option) any later version.
  19. #
  20. # Fhem is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
  27. #
  28. #########################################################################################################################
  29. package main;
  30. use strict;
  31. use warnings;
  32. # Versions History intern
  33. our %SSCamSTRM_vNotesIntern = (
  34. "1.4.1" => "31.10.2018 attribute \"autoLoop\" changed to \"autoRefresh\", new attribute \"autoRefreshFW\" ",
  35. "1.4.0" => "29.10.2018 readingFnAttributes added ",
  36. "1.3.0" => "28.10.2018 direct help for attributes, new attribute \"autoLoop\" ",
  37. "1.2.4" => "27.10.2018 fix undefined subroutine &main::SSCam_ptzpanel (https://forum.fhem.de/index.php/topic,45671.msg850505.html#msg850505) ",
  38. "1.2.3" => "03.07.2018 behavior changed if device is disabled ",
  39. "1.2.2" => "26.06.2018 make changes for generic stream dev ",
  40. "1.2.1" => "23.06.2018 no name add-on if MODEL is snapgallery ",
  41. "1.2.0" => "20.06.2018 running stream as human readable entry for SSCamSTRM-Device ",
  42. "1.1.0" => "16.06.2018 attr hideDisplayName regarding to Forum #88667 ",
  43. "1.0.1" => "14.06.2018 commandref revised ",
  44. "1.0.0" => "14.06.2018 switch to longpoll refresh ",
  45. "0.4.0" => "13.06.2018 new attribute \"noDetaillink\" (deleted in V1.0.0) ",
  46. "0.3.0" => "12.06.2018 new attribute \"forcePageRefresh\" ",
  47. "0.2.0" => "11.06.2018 check in with SSCam 5.0.0 ",
  48. "0.1.0" => "10.06.2018 initial Version "
  49. );
  50. # Standardvariablen und Forward-Declaration
  51. sub SSCam_ptzpanel($;$$);
  52. sub SSCam_StreamDev($$$);
  53. ################################################################
  54. sub SSCamSTRM_Initialize($) {
  55. my ($hash) = @_;
  56. my $fwd = join(",",devspec2array("TYPE=FHEMWEB:FILTER=STATE=Initialized"));
  57. $hash->{DefFn} = "SSCamSTRM_Define";
  58. $hash->{AttrList} = "autoRefresh:selectnumbers,120,0.2,1800,0,log10 ".
  59. "autoRefreshFW:$fwd ".
  60. "disable:1,0 ".
  61. "forcePageRefresh:1,0 ".
  62. "htmlattr ".
  63. "hideDisplayName:1,0 ".
  64. $readingFnAttributes;
  65. $hash->{FW_summaryFn} = "SSCamSTRM_FwFn";
  66. $hash->{FW_detailFn} = "SSCamSTRM_FwFn";
  67. $hash->{AttrFn} = "SSCamSTRM_Attr";
  68. $hash->{FW_hideDisplayName} = 1; # Forum 88667
  69. # $hash->{FW_addDetailToSummary} = 1;
  70. # $hash->{FW_atPageEnd} = 1; # wenn 1 -> kein Longpoll ohne informid in HTML-Tag
  71. }
  72. ################################################################
  73. sub SSCamSTRM_Define($$) {
  74. my ($hash, $def) = @_;
  75. my ($name, $type, $link) = split("[ \t]+", $def, 3);
  76. if(!$link) {
  77. return "Usage: define <name> SSCamSTRM <arg>";
  78. }
  79. my $arg = (split("[()]",$link))[1];
  80. $arg =~ s/'//g;
  81. ($hash->{PARENT},$hash->{MODEL}) = ((split(",",$arg))[0],(split(",",$arg))[2]);
  82. $hash->{VERSION} = $hash->{VERSION} = (reverse sort(keys %SSCamSTRM_vNotesIntern))[0];
  83. $hash->{LINK} = $link;
  84. readingsSingleUpdate($hash,"state", "initialized", 1); # Init für "state"
  85. return undef;
  86. }
  87. ################################################################
  88. sub SSCamSTRM_Attr($$$$) {
  89. my ($cmd,$name,$aName,$aVal) = @_;
  90. my $hash = $defs{$name};
  91. my ($do,$val);
  92. # $cmd can be "del" or "set"
  93. # $name is device name
  94. # aName and aVal are Attribute name and value
  95. if ($aName eq "disable") {
  96. if($cmd eq "set") {
  97. $do = ($aVal) ? 1 : 0;
  98. }
  99. $do = 0 if($cmd eq "del");
  100. $val = ($do == 1 ? "disabled" : "initialized");
  101. readingsSingleUpdate($hash, "state", $val, 1);
  102. }
  103. return undef;
  104. }
  105. ################################################################
  106. sub SSCamSTRM_FwFn($;$$$) {
  107. my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
  108. my $hash = $defs{$d};
  109. my $link = $hash->{LINK};
  110. RemoveInternalTimer($hash);
  111. $hash->{HELPER}{FW} = $FW_wname;
  112. $link = AnalyzePerlCommand(undef, $link) if($link =~ m/^{(.*)}$/s);
  113. my $show = $defs{$hash->{PARENT}}->{HELPER}{ACTSTRM} if($hash->{MODEL} =~ /switched/);
  114. $show = $show?"($show)":"";
  115. my $alias = AttrVal($d, "alias", $d); # Linktext als Aliasname oder Devicename setzen
  116. my $dlink = "<a href=\"/fhem?detail=$d\">$alias</a>";
  117. my $ret = "";
  118. $ret .= "<span>$dlink $show</span><br>" if(!AttrVal($d,"hideDisplayName",0));
  119. if(IsDisabled($d)) {
  120. if(AttrVal($d,"hideDisplayName",0)) {
  121. $ret .= "Stream-device <a href=\"/fhem?detail=$d\">$d</a> is disabled";
  122. } else {
  123. $ret .= "<html>Stream-device is disabled</html>";
  124. }
  125. } else {
  126. $ret .= $link;
  127. }
  128. # Autorefresh nur des aufrufenden FHEMWEB-Devices
  129. my $al = AttrVal($d, "autoRefresh", 0);
  130. if($al) {
  131. InternalTimer(gettimeofday()+$al, "SSCamSTRM_refresh", $hash, 0);
  132. Log3($d, 5, "$d - next start of autoRefresh: ".FmtDateTime(gettimeofday()+$al));
  133. }
  134. return $ret;
  135. }
  136. ################################################################
  137. sub SSCamSTRM_refresh($) {
  138. my ($hash) = @_;
  139. my $d = $hash->{NAME};
  140. # Seitenrefresh festgelegt durch SSCamSTRM-Attribut "autoRefresh" und "autoRefreshFW"
  141. my $rd = AttrVal($d, "autoRefreshFW", $hash->{HELPER}{FW});
  142. { map { FW_directNotify("#FHEMWEB:$_", "location.reload('true')", "") } $rd }
  143. my $al = AttrVal($d, "autoRefresh", 0);
  144. if($al) {
  145. InternalTimer(gettimeofday()+$al, "SSCamSTRM_refresh", $hash, 0);
  146. Log3($d, 5, "$d - next start of autoRefresh: ".FmtDateTime(gettimeofday()+$al));
  147. } else {
  148. RemoveInternalTimer($hash);
  149. }
  150. return;
  151. }
  152. 1;
  153. =pod
  154. =item summary define a Streaming device by SSCam module
  155. =item summary_DE Erstellung eines Streaming-Device durch das SSCam-Modul
  156. =begin html
  157. <a name="SSCamSTRM"></a>
  158. <h3>SSCamSTRM</h3>
  159. <br>
  160. The module SSCamSTRM is a special device module synchronized to the SSCam module. It is used for definition of
  161. Streaming-Devices. <br>
  162. Dependend of the Streaming-Device state, different buttons are provided to start actions:
  163. <ul>
  164. <table>
  165. <colgroup> <col width=25%> <col width=75%> </colgroup>
  166. <tr><td> Switch off </td><td>- stops a running playback </td></tr>
  167. <tr><td> Refresh </td><td>- refresh a view (no page reload) </td></tr>
  168. <tr><td> Restart </td><td>- restart a running content (e.g. a HLS-Stream) </td></tr>
  169. <tr><td> MJPEG </td><td>- starts a MJPEG Livestream </td></tr>
  170. <tr><td> HLS </td><td>- starts HLS (HTTP Live Stream) </td></tr>
  171. <tr><td> Last Record </td><td>- playback the last recording as iFrame </td></tr>
  172. <tr><td> Last Rec H.264 </td><td>- playback the last recording if available as H.264 </td></tr>
  173. <tr><td> Last Rec MJPEG </td><td>- playback the last recording if available as MJPEG </td></tr>
  174. <tr><td> Last SNAP </td><td>- show the last snapshot </td></tr>
  175. <tr><td> Start Recording </td><td>- starts an endless recording </td></tr>
  176. <tr><td> Stop Recording </td><td>- stopps the recording </td></tr>
  177. <tr><td> Take Snapshot </td><td>- take a snapshot </td></tr>
  178. </table>
  179. </ul>
  180. <br>
  181. <ul>
  182. <a name="SSCamSTRMdefine"></a>
  183. <b>Define</b>
  184. <ul>
  185. A SSCam Streaming-device is defined by the SSCam "set &lt;name&gt; createStreamDev" command.
  186. Please refer to SSCam <a href="#SSCamcreateStreamDev">"createStreamDev"</a> command.
  187. <br><br>
  188. </ul>
  189. <a name="SSCamSTRMset"></a>
  190. <b>Set</b> <ul>N/A</ul><br>
  191. <a name="SSCamSTRMget"></a>
  192. <b>Get</b> <ul>N/A</ul><br>
  193. <a name="SSCamSTRMattr"></a>
  194. <b>Attributes</b>
  195. <br><br>
  196. <ul>
  197. <ul>
  198. <a name="autoRefresh"></a>
  199. <li><b>autoRefresh</b><br>
  200. If set, active browser pages of the FHEMWEB-Device which has called the SSCamSTRM-Device, are new reloaded after
  201. the specified time (seconds). Browser pages of a particular FHEMWEB-Device to be refreshed can be specified by
  202. attribute "autoRefreshFW" instead.
  203. This may stabilize the video playback in some cases.
  204. </li>
  205. <br>
  206. <a name="autoRefreshFW"></a>
  207. <li><b>autoRefreshFW</b><br>
  208. If "autoRefresh" is activated, you can specify a particular FHEMWEB-Device whose active browser pages are refreshed
  209. periodically.
  210. </li>
  211. <br>
  212. <a name="disable"></a>
  213. <li><b>disable</b><br>
  214. Deactivates the device.
  215. </li>
  216. <br>
  217. <a name="forcePageRefresh"></a>
  218. <li><b>forcePageRefresh</b><br>
  219. The attribute is evaluated by SSCam. <br>
  220. If set, a reload of all browser pages with active FHEMWEB connections will be enforced when particular camera operations
  221. were finished.
  222. This may stabilize the video playback in some cases.
  223. </li>
  224. <br>
  225. <a name="hideDisplayName"></a>
  226. <li><b>hideDisplayName</b><br>
  227. Hide the device/alias name (link to detail view).
  228. </li>
  229. <br>
  230. <a name="htmlattr"></a>
  231. <li><b>htmlattr</b><br>
  232. Additional HTML tags to manipulate the streaming device. <br>
  233. <ul>
  234. <ul>
  235. <b>Example: </b><br>
  236. attr &lt;name&gt; htmlattr width="480" height="560" <br>
  237. </ul>
  238. </ul>
  239. </li>
  240. </ul>
  241. </ul>
  242. </ul>
  243. =end html
  244. =begin html_DE
  245. <a name="SSCamSTRM"></a>
  246. <h3>SSCamSTRM</h3>
  247. <br>
  248. Das Modul SSCamSTRM ist ein mit SSCam abgestimmtes Gerätemodul zur Definition von Streaming-Devices. <br>
  249. Abhängig vom Zustand des Streaming-Devices werden zum Start von Aktionen unterschiedliche Drucktasten angeboten:
  250. <ul>
  251. <table>
  252. <colgroup> <col width=25%> <col width=75%> </colgroup>
  253. <tr><td> Switch off </td><td>- stoppt eine laufende Wiedergabe </td></tr>
  254. <tr><td> Refresh </td><td>- auffrischen einer Ansicht (kein Browser Seiten-Reload) </td></tr>
  255. <tr><td> Restart </td><td>- neu starten eines laufenden Contents (z.B. eines HLS-Streams) </td></tr>
  256. <tr><td> MJPEG </td><td>- Startet MJPEG Livestream </td></tr>
  257. <tr><td> HLS </td><td>- Startet HLS (HTTP Live Stream) </td></tr>
  258. <tr><td> Last Record </td><td>- spielt die letzte Aufnahme als iFrame </td></tr>
  259. <tr><td> Last Rec H.264 </td><td>- spielt die letzte Aufnahme wenn als H.264 vorliegend </td></tr>
  260. <tr><td> Last Rec MJPEG </td><td>- spielt die letzte Aufnahme wenn als MJPEG vorliegend </td></tr>
  261. <tr><td> Last SNAP </td><td>- zeigt den letzten Snapshot </td></tr>
  262. <tr><td> Start Recording </td><td>- startet eine Endlosaufnahme </td></tr>
  263. <tr><td> Stop Recording </td><td>- stoppt eine Aufnahme </td></tr>
  264. <tr><td> Take Snapshot </td><td>- löst einen Schnappschuß aus </td></tr>
  265. </table>
  266. </ul>
  267. <br>
  268. <ul>
  269. <a name="SSCamSTRMdefine"></a>
  270. <b>Define</b>
  271. <ul>
  272. Ein SSCam Streaming-Device wird durch den SSCam Befehl "set &lt;name&gt; createStreamDev" erstellt.
  273. Siehe auch die Beschreibung zum SSCam <a href="#SSCamcreateStreamDev">"createStreamDev"</a> Befehl.
  274. <br><br>
  275. </ul>
  276. <a name="SSCamSTRMset"></a>
  277. <b>Set</b> <ul>N/A</ul><br>
  278. <a name="SSCamSTRMget"></a>
  279. <b>Get</b> <ul>N/A</ul><br>
  280. <a name="SSCamSTRMattr"></a>
  281. <b>Attributes</b>
  282. <br><br>
  283. <ul>
  284. <ul>
  285. <a name="autoRefresh"></a>
  286. <li><b>autoRefresh</b><br>
  287. Wenn gesetzt, werden aktive Browserseiten des FHEMWEB-Devices welches das SSCamSTRM-Device aufgerufen hat, nach der
  288. eingestellten Zeit (Sekunden) neu geladen. Sollen statt dessen Broserseiten eines bestimmten FHEMWEB-Devices neu
  289. geladen werden, kann dieses Device mit dem Attribut "autoRefreshFW" festgelegt werden.
  290. Dies kann in manchen Fällen die Wiedergabe innerhalb einer Anwendung stabilisieren.
  291. </li>
  292. <br>
  293. <a name="autoRefreshFW"></a>
  294. <li><b>autoRefreshFW</b><br>
  295. Ist "autoRefresh" aktiviert, kann mit diesem Attribut das FHEMWEB-Device bestimmt werden dessen aktive Browserseiten
  296. regelmäßig neu geladen werden sollen.
  297. </li>
  298. <br>
  299. <a name="disable"></a>
  300. <li><b>disable</b><br>
  301. Aktiviert/deaktiviert das Device.
  302. </li>
  303. <br>
  304. <a name="forcePageRefresh"></a>
  305. <li><b>forcePageRefresh</b><br>
  306. Das Attribut wird durch SSCam ausgewertet. <br>
  307. Wenn gesetzt, wird ein Reload aller Browserseiten mit aktiven FHEMWEB-Verbindungen nach dem Abschluß bestimmter
  308. SSCam-Befehle erzwungen.
  309. Dies kann in manchen Fällen die Wiedergabe innerhalb einer Anwendung stabilisieren.
  310. </li>
  311. <br>
  312. <a name="hideDisplayName"></a>
  313. <li><b>hideDisplayName</b><br>
  314. Verbirgt den Device/Alias-Namen (Link zur Detailansicht).
  315. </li>
  316. <br>
  317. <a name="htmlattr"></a>
  318. <li><b>htmlattr</b><br>
  319. Zusätzliche HTML Tags zur Darstellungsänderung im Streaming Device. <br>
  320. <ul>
  321. <b>Beispiel: </b><br>
  322. attr &lt;name&gt; htmlattr width="480" height="560" <br>
  323. </ul>
  324. </li>
  325. </ul>
  326. </ul>
  327. </ul>
  328. =end html_DE
  329. =cut