49_SSCamSTRM.pm 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. ########################################################################################################################
  2. # $Id: 49_SSCamSTRM.pm 16938 2018-07-03 17:31:13Z 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. # Versions History:
  30. #
  31. # 1.2.3 03.07.2018 behavior changed if device is disabled
  32. # 1.2.2 26.06.2018 make changes for generic stream dev
  33. # 1.2.1 23.06.2018 no name add-on if MODEL is snapgallery
  34. # 1.2.0 20.06.2018 running stream as human readable entry for SSCamSTRM-Device
  35. # 1.1.0 16.06.2018 attr hideDisplayName regarding to Forum #88667
  36. # 1.0.1 14.06.2018 commandref revised
  37. # 1.0.0 14.06.2018 switch to longpoll refresh
  38. # 0.4 13.06.2018 new attribute "noDetaillink" (deleted in V1.0.0)
  39. # 0.3 12.06.2018 new attribute "forcePageRefresh"
  40. # 0.2 11.06.2018 check in with SSCam 5.0.0
  41. # 0.1 10.06.2018 initial Version
  42. package main;
  43. use strict;
  44. use warnings;
  45. my $SSCamSTRMVersion = "1.2.3";
  46. ################################################################
  47. sub SSCamSTRM_Initialize($) {
  48. my ($hash) = @_;
  49. $hash->{DefFn} = "SSCamSTRM_Define";
  50. $hash->{AttrList} = "disable:1,0 forcePageRefresh:1,0 htmlattr hideDisplayName:1,0 ";
  51. $hash->{FW_summaryFn} = "SSCamSTRM_FwFn";
  52. $hash->{FW_detailFn} = "SSCamSTRM_FwFn";
  53. $hash->{AttrFn} = "SSCamSTRM_Attr";
  54. $hash->{FW_hideDisplayName} = 1; # Forum 88667
  55. # $hash->{FW_addDetailToSummary} = 1;
  56. # $hash->{FW_atPageEnd} = 1; # wenn 1 -> kein Longpoll ohne informid in HTML-Tag
  57. }
  58. ################################################################
  59. sub SSCamSTRM_Define($$) {
  60. my ($hash, $def) = @_;
  61. my ($name, $type, $link) = split("[ \t]+", $def, 3);
  62. if(!$link) {
  63. return "Usage: define <name> SSCamSTRM <arg>";
  64. }
  65. my $arg = (split("[()]",$link))[1];
  66. $arg =~ s/'//g;
  67. ($hash->{PARENT},$hash->{MODEL}) = ((split(",",$arg))[0],(split(",",$arg))[2]);
  68. $hash->{VERSION} = $SSCamSTRMVersion;
  69. $hash->{LINK} = $link;
  70. readingsSingleUpdate($hash,"state", "initialized", 1); # Init für "state"
  71. return undef;
  72. }
  73. ################################################################
  74. sub SSCamSTRM_Attr($$$$) {
  75. my ($cmd,$name,$aName,$aVal) = @_;
  76. my $hash = $defs{$name};
  77. my ($do,$val);
  78. # $cmd can be "del" or "set"
  79. # $name is device name
  80. # aName and aVal are Attribute name and value
  81. if ($aName eq "disable") {
  82. if($cmd eq "set") {
  83. $do = ($aVal) ? 1 : 0;
  84. }
  85. $do = 0 if($cmd eq "del");
  86. $val = ($do == 1 ? "disabled" : "initialized");
  87. readingsSingleUpdate($hash, "state", $val, 1);
  88. }
  89. return undef;
  90. }
  91. ################################################################
  92. sub SSCamSTRM_FwFn($$$$) {
  93. my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
  94. my $hash = $defs{$d};
  95. my $link = $hash->{LINK};
  96. # return undef if(IsDisabled($d));
  97. $link = AnalyzePerlCommand(undef, $link) if($link =~ m/^{(.*)}$/s);
  98. my $show = $defs{$hash->{PARENT}}->{HELPER}{ACTSTRM} if($hash->{MODEL} =~ /switched/);
  99. $show = $show?"($show)":"";
  100. my $alias = AttrVal($d, "alias", $d); # Linktext als Aliasname oder Devicename setzen
  101. my $dlink = "<a href=\"/fhem?detail=$d\">$alias</a>";
  102. my $ret = "";
  103. $ret .= "<span>$dlink $show</span><br>" if(!AttrVal($d,"hideDisplayName",0));
  104. if(IsDisabled($d)) {
  105. if(AttrVal($d,"hideDisplayName",0)) {
  106. $ret .= "Stream-device <a href=\"/fhem?detail=$d\">$d</a> is disabled";
  107. } else {
  108. $ret .= "<html>Stream-device is disabled</html>";
  109. }
  110. } else {
  111. $ret .= $link;
  112. }
  113. return $ret;
  114. }
  115. 1;
  116. =pod
  117. =item summary define a Streaming device by SSCam module
  118. =item summary_DE Erstellung eines Streaming-Device durch das SSCam-Modul
  119. =begin html
  120. <a name="SSCamSTRM"></a>
  121. <h3>SSCamSTRM</h3>
  122. <br>
  123. The module SSCamSTRM is a special device module synchronized to the SSCam module. It is used for definition of
  124. Streaming-Devices. <br>
  125. Dependend of the Streaming-Device state, different buttons are provided to start actions:
  126. <ul>
  127. <table>
  128. <colgroup> <col width=25%> <col width=75%> </colgroup>
  129. <tr><td> Switch off </td><td>- stops a running playback </td></tr>
  130. <tr><td> Refresh </td><td>- refresh a view (no page reload) </td></tr>
  131. <tr><td> Restart </td><td>- restart a running content (e.g. a HLS-Stream) </td></tr>
  132. <tr><td> MJPEG </td><td>- starts a MJPEG Livestream </td></tr>
  133. <tr><td> HLS </td><td>- starts HLS (HTTP Live Stream) </td></tr>
  134. <tr><td> Last Record </td><td>- playback the last recording as iFrame </td></tr>
  135. <tr><td> Last Rec H.264 </td><td>- playback the last recording if available as H.264 </td></tr>
  136. <tr><td> Last Rec MJPEG </td><td>- playback the last recording if available as MJPEG </td></tr>
  137. <tr><td> Last SNAP </td><td>- show the last snapshot </td></tr>
  138. <tr><td> Start Recording </td><td>- starts an endless recording </td></tr>
  139. <tr><td> Stop Recording </td><td>- stopps the recording </td></tr>
  140. <tr><td> Take Snapshot </td><td>- take a snapshot </td></tr>
  141. </table>
  142. </ul>
  143. <br>
  144. <ul>
  145. <a name="SSCamSTRMdefine"></a>
  146. <b>Define</b>
  147. <ul>
  148. A SSCam Streaming-device is defined by the SSCam "set &lt;name&gt; createStreamDev" command.
  149. Please refer to SSCam <a href="#SSCamcreateStreamDev">"createStreamDev"</a> command.
  150. <br><br>
  151. </ul>
  152. <a name="SSCamSTRMset"></a>
  153. <b>Set</b> <ul>N/A</ul><br>
  154. <a name="SSCamSTRMget"></a>
  155. <b>Get</b> <ul>N/A</ul><br>
  156. <a name="SSCamSTRMattr"></a>
  157. <b>Attributes</b>
  158. <br><br>
  159. <ul>
  160. <ul>
  161. <li><b>disable</b><br>
  162. deactivates the device definition
  163. </li>
  164. <br>
  165. <li><b>forcePageRefresh</b><br>
  166. The attribute is evaluated by SSCam. <br>
  167. If set, a reload of all browser pages with active FHEMWEB-connections will be enforced.
  168. This may be helpful if problems with longpoll are appear.
  169. </li>
  170. <br>
  171. <li><b>hideDisplayName</b><br>
  172. hide the device/alias name (link to detail view)
  173. </li>
  174. <br>
  175. <a name="htmlattr"></a>
  176. <li><b>htmlattr</b><br>
  177. HTML attributes to be used for Streaming device e.g.: <br><br>
  178. <ul>
  179. <code>
  180. attr &lt;name&gt; htmlattr width="480" height="560" <br>
  181. </code>
  182. </ul>
  183. </li>
  184. </ul>
  185. </ul>
  186. </ul>
  187. =end html
  188. =begin html_DE
  189. <a name="SSCamSTRM"></a>
  190. <h3>SSCamSTRM</h3>
  191. <br>
  192. Das Modul SSCamSTRM ist ein mit SSCam abgestimmtes Gerätemodul zur Definition von Streaming-Devices. <br>
  193. Abhängig vom Zustand des Streaming-Devices werden zum Start von Aktionen unterschiedliche Drucktasten angeboten:
  194. <ul>
  195. <table>
  196. <colgroup> <col width=25%> <col width=75%> </colgroup>
  197. <tr><td> Switch off </td><td>- stoppt eine laufende Wiedergabe </td></tr>
  198. <tr><td> Refresh </td><td>- auffrischen einer Ansicht (kein Browser Seiten-Reload) </td></tr>
  199. <tr><td> Restart </td><td>- neu starten eines laufenden Contents (z.B. eines HLS-Streams) </td></tr>
  200. <tr><td> MJPEG </td><td>- Startet MJPEG Livestream </td></tr>
  201. <tr><td> HLS </td><td>- Startet HLS (HTTP Live Stream) </td></tr>
  202. <tr><td> Last Record </td><td>- spielt die letzte Aufnahme als iFrame </td></tr>
  203. <tr><td> Last Rec H.264 </td><td>- spielt die letzte Aufnahme wenn als H.264 vorliegend </td></tr>
  204. <tr><td> Last Rec MJPEG </td><td>- spielt die letzte Aufnahme wenn als MJPEG vorliegend </td></tr>
  205. <tr><td> Last SNAP </td><td>- zeigt den letzten Snapshot </td></tr>
  206. <tr><td> Start Recording </td><td>- startet eine Endlosaufnahme </td></tr>
  207. <tr><td> Stop Recording </td><td>- stoppt eine Aufnahme </td></tr>
  208. <tr><td> Take Snapshot </td><td>- löst einen Schnappschuß aus </td></tr>
  209. </table>
  210. </ul>
  211. <br>
  212. <ul>
  213. <a name="SSCamSTRMdefine"></a>
  214. <b>Define</b>
  215. <ul>
  216. Ein SSCam Streaming-Device wird durch den SSCam Befehl "set &lt;name&gt; createStreamDev" erstellt.
  217. Siehe auch die Beschreibung zum SSCam <a href="#SSCamcreateStreamDev">"createStreamDev"</a> Befehl.
  218. <br><br>
  219. </ul>
  220. <a name="SSCamSTRMset"></a>
  221. <b>Set</b> <ul>N/A</ul><br>
  222. <a name="SSCamSTRMget"></a>
  223. <b>Get</b> <ul>N/A</ul><br>
  224. <a name="SSCamSTRMattr"></a>
  225. <b>Attributes</b>
  226. <br><br>
  227. <ul>
  228. <ul>
  229. <li><b>disable</b><br>
  230. aktiviert/deaktiviert das Device
  231. </li>
  232. <br>
  233. <li><b>forcePageRefresh</b><br>
  234. Das Attribut wird durch SSCam ausgewertet. <br>
  235. Wenn gesetzt, wird ein Reload aller Browserseiten mit aktiven FHEMWEB-Verbindungen bei bestimmten Aktionen erzwungen.
  236. Das kann hilfreich sein, falls es mit Longpoll Probleme geben sollte.
  237. eingefügt ist.
  238. </li>
  239. <br>
  240. <li><b>hideDisplayName</b><br>
  241. verbirgt den Device/Alias-Namen (Link zur Detailansicht)
  242. </li>
  243. <br>
  244. <a name="htmlattr"></a>
  245. <li><b>htmlattr</b><br>
  246. HTML-Attribute zur Darstellungsänderung des SSCam Streaming Device z.B.: <br><br>
  247. <ul>
  248. <code>
  249. attr &lt;name&gt; htmlattr width="480" height="560" <br>
  250. </code>
  251. </ul>
  252. </li>
  253. </ul>
  254. </ul>
  255. </ul>
  256. =end html_DE
  257. =cut