demo-gateway.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Demo</title>
  6. <style>
  7. * {
  8. padding: 0;
  9. margin: 0;
  10. font-size: 12px;
  11. }
  12. #playWind {
  13. float: left;
  14. display: inline-block;
  15. }
  16. body {
  17. margin: 10px;
  18. }
  19. button {
  20. margin: 10px 10px;
  21. padding:2px 5px;
  22. }
  23. .button_box {
  24. float: left;
  25. }
  26. .button_box div {
  27. margin: 10px 10px;
  28. }
  29. #volume {
  30. position: relative;
  31. top: 5px;
  32. }
  33. .items {
  34. border: 1px solid #444444;
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. <div id="playWind" style="width: 600px; height: 400px;"></div>
  40. <div class="button_box">
  41. <div class="items">
  42. <div>Gateway</div>
  43. &nbsp;&nbsp;Access URL: <input type="text" id="ipPort" value="10.19.166.137:81" />
  44. &nbsp;&nbsp;User Name: <input type="text" id="username" value="admin" />
  45. &nbsp;&nbsp;Password: <input type="text" id="password" value="hik12345" />
  46. &nbsp;&nbsp;<button type="button" onClick="login()">Login</button>
  47. <div class="items">
  48. <div>Live View</div>
  49. &nbsp;&nbsp;Live View URL: <input style="width:600px; height=20px;" type="text" id="previewUrl" value="rtsp://10.19.166.137:554/dac/realplay/8E93887C-0916-40CD-A0B6-FF0057FAE2D21/MAIN/TCP?streamform=rtp" />
  50. <br />
  51. <button type="button" onClick="realplay()">Start Live View</button>
  52. <button type="button" onClick="stopPlay()">Stop Live View</button>
  53. <button type="button" onClick="stopPlayAll()">Stop All</button>
  54. <button type="button" onclick="record()">Start Recording</button>
  55. <button type="button" onclick="stopRecord()">Stop Recording</button>
  56. <button type="button" onClick="capturePicture()">Capture</button>
  57. </div>
  58. <div class="items">
  59. <div>Playback</div>
  60. &nbsp;&nbsp;Playback URL: <input style="width:800px; height=20px;" type="text" id="playbackUrl" value="rtsp://172.7.203.17:554/dac/playback/camera/1F16052F-FD9D-4E63-9164-104D4D6109B01/SUB/TCP?starttime=20210413T191007Z&endtime=20210414T121007Z&streamform=rtp" />
  61. <br />
  62. <button type="button" onClick="playback()">Start Playback</button>
  63. <button type="button" onClick="stopPlay()">Stop Playback</button>
  64. <button type="button" onClick="fast()">Fast Forward</button>
  65. <button type="button" onClick="slow()">Slow Forward</button>
  66. <button type="button" onclick="record()">Start Recording</button>
  67. <button type="button" onclick="stopRecord()">Stop Recording</button><br />
  68. </div>
  69. <div class="items">
  70. <div>Voicetalk</div>
  71. <div>&nbsp;&nbsp;Device Index: <input style="width:400px; height=20px;" type="text" id="devIndex" value="8E93887C-0916-40CD-A0B6-FF0057FAE2D2" />
  72. </div>
  73. <div>&nbsp;&nbsp;Two-Way Audio Channel: <select style="width:80px; height=20px;" id="voicetalkChannel"></select></div>
  74. <!-- &nbsp;&nbsp;Get a Two-Way Audio Channel URL: <input style="width:800px; height=20px;" type="text" id="voicetalkChannelUrl" value="http://10.19.166.137:81/ISAPI/System/TwoWayAudio/channels?devIndex=8E93887C-0916-40CD-A0B6-FF0057FAE2D2" /> -->
  75. <!-- &nbsp;&nbsp;Get a Two-Way Audio Params URL: <input style="width:800px; height=20px;" type="text" id="voicetalkUrl" value="http://10.19.166.137:81/ISAPI/System/TwoWayAudio/channels/1?format=json&devIndex=8E93887C-0916-40CD-A0B6-FF0057FAE2D2" /> -->
  76. <!-- <div>&nbsp;&nbsp;Start Two-Way Audio URL: <input style="width:800px; height=20px;" type="text" id="voicetalkUrl" value="rtsp://10.19.166.137:554/dac/talk/8E93887C-0916-40CD-A0B6-FF0057FAE2D21/TCP" /> -->
  77. <!-- </div> -->
  78. <br />
  79. <button type="button" onClick="getVoiceChannel()">Get Two-Way Audio Channel</button>
  80. <button type="button" onClick="voicetalk()">Start Voicetalk</button>
  81. <button type="button" onClick="stopvoicetalk()">Stop Voicetalk</button>
  82. <br />
  83. </div>
  84. <div class="items">
  85. <div>Audio</div>
  86. <button type="button" onClick="openSound()">Turn on Audio</button>
  87. <button type="button" onClick="closeSound()">Turn off Audio</button>
  88. </div>
  89. <div class="items">
  90. <div>Plugin</div>
  91. <button type="button" onClick="arrangeWindow(1)">1x1</button>
  92. <button type="button" onClick="arrangeWindow(2)">2x2</button>
  93. <button type="button" onClick="fullSreen()">Full Screen (All Windows)</button>
  94. <button type="button" onClick="checkUpdate()">Check Plugin Update</button>
  95. <table cellpadding="0" cellspacing="3" border="0">
  96. <tr>
  97. <td class="tt">Snapshot format</td>
  98. <td>
  99. <select id="captureFileFormat" name="captureFileFormat" class="sel">
  100. <option value="0">JPEG</option>
  101. <option value="1">BMP</option>
  102. </select>
  103. </td>
  104. </tr>
  105. <tr>
  106. <td class="tt">Save record files to</td>
  107. <td colspan="3"><input id="recordPath" type="text" style="width:400px; height=20px;" />&nbsp;<button type="button" onclick="clickOpenFileDlg('recordPath');">Browse</button></td>
  108. </tr>
  109. <tr>
  110. <td class="tt">Save snapshots in live view to</td>
  111. <td colspan="3"><input id="previewPicPath" type="text" style="width:400px; height=20px;" />&nbsp;<button type="button" onclick="clickOpenFileDlg('previewPicPath');">Browse</button></td>
  112. </tr>
  113. <tr>
  114. <td class="tt">Save snapshots when playback to</td>
  115. <td colspan="3"><input id="playbackPicPath" type="text" style="width:400px; height=20px;" />&nbsp;<button type="button" onclick="clickOpenFileDlg('playbackPicPath');">Browse</button></td>
  116. </tr>
  117. <tr>
  118. <td class="tt">Save clips to</td>
  119. <td colspan="3"><input id="playbackFilePath" type="text" style="width:400px; height=20px;" />&nbsp;<button type="button" onclick="clickOpenFileDlg('playbackFilePath');">Browse</button></td>
  120. </tr>
  121. <tr>
  122. <td colspan="4"><button type="button" onclick="clickGetLocalCfg();">Get</button>&nbsp;<button type="button" onclick="clickSetLocalCfg();">Set</button>&nbsp;&nbsp;After modifying parameters, you need to refresh the interface to take effect.</td>
  123. </tr>
  124. </table>
  125. </div>
  126. <div class="items">
  127. <div>Prompt</div>
  128. <div id="prompt" style="color:red"></div>
  129. </div>
  130. </div>
  131. <script src="../jquery-1.7.1.min.js"></script>
  132. <script id="videonode" src="../codebase/webVideoCtrl.js"></script>
  133. <script>
  134. var iWind = 0; //the selected window
  135. function msgLog(szMsg) {
  136. $("#prompt").html("<div>" + szMsg + "</div>");
  137. }
  138. function initPlugin() {
  139. WebVideoCtrl.I_InitPlugin({
  140. bWndFull: true,
  141. iWndowType: 1,
  142. cbSelWnd: function (xmlDoc) {
  143. iWind = parseInt($(xmlDoc).find("SelectWnd").eq(0).text(), 10);
  144. msgLog("the window is selected: " + iWind);
  145. },
  146. cbEvent: function (iEventType, iParam1, iParam2) {
  147. msgLog(iEventType, iParam1, iParam2);
  148. },
  149. cbInitPluginComplete: function () {
  150. WebVideoCtrl.I_InsertOBJECTPlugin("playWind").then(() => {
  151. WebVideoCtrl.I_CheckPluginVersion().then((bFlag) => {
  152. if (bFlag) {
  153. alert("Please update the HCWebSDKPlugin to the latest version.");
  154. }
  155. });
  156. }, () => {
  157. alert("HCWebSDKPlugin initialization failed.");
  158. });
  159. }
  160. });
  161. }
  162. initPlugin();
  163. function login () {
  164. var szIPPort = $("#ipPort").val(),
  165. szIP = "",
  166. szPort = "",
  167. szUsername = $("#username").val(),
  168. szPassword = $("#password").val();
  169. if ("" == szIPPort || "" == szUsername || "" == szPassword) {
  170. return;
  171. }
  172. szIP = szIPPort.split(":")[0];
  173. szPort = szIPPort.split(":")[1];
  174. WebVideoCtrl.I_Login(szIP, 1, szPort, szUsername, szPassword, {
  175. timeout: 3000
  176. }).then(() => {
  177. msgLog("login success");
  178. }, (oError) => {
  179. msgLog("login failed");
  180. });
  181. }
  182. function realplay () {
  183. var szDeviceIdentify = $("#ipPort").val().split(":")[0];
  184. WebVideoCtrl.I_StartPlay(szDeviceIdentify, {
  185. szUrl: $("#previewUrl").val()
  186. }).then(() => {
  187. msgLog("realplay success");
  188. }, (oError) => {
  189. msgLog("realplay failed: " + oError.errorCode + ":" + oError.errorMsg);
  190. });
  191. }
  192. function playback () {
  193. var szDeviceIdentify = $("#ipPort").val().split(":")[0];
  194. var szUrl = $("#playbackUrl").val();
  195. var szStartTime = szUrl.substring(szUrl.indexOf("starttime=") + 10, szUrl.indexOf("starttime=") + 26);
  196. var szEndTime = szUrl.substring(szUrl.indexOf("endtime=") + 8, szUrl.indexOf("endtime=") + 24);
  197. WebVideoCtrl.I_StartPlay(szDeviceIdentify, {
  198. szUrl: szUrl,
  199. startTime: szStartTime,
  200. endTime: szEndTime
  201. }).then(() => {
  202. msgLog("playback success");
  203. }, (oError) => {
  204. msgLog("playback failed");
  205. });
  206. }
  207. var aVoiceChannelInfo = [];
  208. function getVoiceChannel () {
  209. var szDeviceIdentify = $("#ipPort").val().split(":")[0];
  210. var szUrl = "ISAPI/System/TwoWayAudio/channels?devIndex=" + $("#devIndex").val();
  211. WebVideoCtrl.I_SendHTTPRequest(szDeviceIdentify, szUrl, {
  212. type: "GET"
  213. }).then((oData) => {
  214. aVoiceChannelInfo.length = 0;
  215. var szOptions = "";
  216. var szID = "";
  217. var szAudioCompressionType = "";
  218. $(oData).find("TwoWayAudioChannel").each((i, val) => {
  219. szID = $(val).find("id").eq(0).text();
  220. szAudioCompressionType = $(val).find("audioCompressionType").eq(0).text();
  221. aVoiceChannelInfo.push({
  222. id: szID,
  223. audioCompressionType: szAudioCompressionType
  224. });
  225. szOptions += "<option value='" + szID + "'>" + szID + "</option>"
  226. });
  227. if (szOptions) {
  228. $("#voicetalkChannel").html(szOptions);
  229. $("#voicetalkChannel").val(aVoiceChannelInfo[0].id);
  230. }
  231. }, (oError) => {
  232. msgLog("get Two-Way audio channel failed");
  233. });
  234. }
  235. function voicetalk () {
  236. var szDeviceIdentify = $("#ipPort").val().split(":")[0];
  237. var szUrl = "ISAPI/System/streamMedia?format=json&devIndex=" + $("#devIndex").val();
  238. var szData = '{"StreamInfo": {"id": "' + $("#voicetalkChannel").val() + '","method": "twoWayAudio"}}';
  239. var szSelectAuidoChannelID = $("#voicetalkChannel").val();
  240. var iAudioType = 1;
  241. var szAudioCompressionType = "";
  242. aVoiceChannelInfo.forEach((val) => {
  243. if (szSelectAuidoChannelID === val.id) {
  244. szAudioCompressionType = val.audioCompressionType;
  245. }
  246. });
  247. if ("G.711alaw" == szAudioCompressionType) {
  248. iAudioType = 1;
  249. } else if ("G.711ulaw" == szAudioCompressionType) {
  250. iAudioType = 2;
  251. } else if ("G.722.1" == szAudioCompressionType) {
  252. iAudioType = 3;
  253. }
  254. WebVideoCtrl.I_SendHTTPRequest(szDeviceIdentify, szUrl, {
  255. type: "POST",
  256. data: szData,
  257. }).then((oData) => {
  258. var szVoiceUrl = oData.MediaAccessInfo.URL;
  259. WebVideoCtrl.I_StartAudioPlay(szDeviceIdentify, {
  260. szUrl: szVoiceUrl,
  261. iAudioType: iAudioType
  262. }).then(() => {
  263. msgLog("voicetalk success");
  264. }, (oError) => {
  265. msgLog("voicetalk failed.");
  266. });
  267. }, (oError) => {
  268. msgLog("get Two-Way audio url failed.");
  269. });
  270. }
  271. function stopvoicetalk () {
  272. WebVideoCtrl.I_StopAudioPlay().then(() => {
  273. msgLog("stop voicetalk success");
  274. }, () => {
  275. msgLog("stop voicetalk failed.");
  276. });
  277. }
  278. function stopPlay () {
  279. WebVideoCtrl.I_Stop(iWind).then(() => {
  280. msgLog("stop success");
  281. }, (oError) => {
  282. msgLog("stop failed: " + iWind);
  283. });
  284. }
  285. function arrangeWindow (iWinType) {
  286. WebVideoCtrl.I_ChangeWndNum(iWinType).then(() => {
  287. msgLog("arrange window success");
  288. }, (oError) => {
  289. msgLog("arrange window failed");
  290. });
  291. }
  292. function slow () {
  293. WebVideoCtrl.I_PlaySlow(iWind).then(() => {
  294. msgLog("slow success");
  295. }, (oError) => {
  296. msgLog("slow failed: " + iWind);
  297. });
  298. }
  299. function fast () {
  300. WebVideoCtrl.I_PlayFast(iWind).then(() => {
  301. msgLog("fast success");
  302. }, (oError) => {
  303. msgLog("fast failed: " + iWind);
  304. });
  305. }
  306. function openSound () {
  307. WebVideoCtrl.I_OpenSound(iWind).then(() => {
  308. msgLog("turn on audio success");
  309. }, (oError) => {
  310. msgLog("turn on audio failed: " + iWind);
  311. });
  312. }
  313. function closeSound () {
  314. WebVideoCtrl.I_CloseSound(iWind).then(() => {
  315. msgLog("turn off audio success");
  316. }, (oError) => {
  317. msgLog("turn off audio failed: " + iWind);
  318. });
  319. }
  320. async function capturePicture() {
  321. var szFileName = "img" + "_" + new Date().getTime();
  322. var oLocalConfig = await WebVideoCtrl.I_GetLocalCfg();
  323. var szCaptureFileFormat = "0";
  324. if (oLocalConfig) {
  325. szCaptureFileFormat = oLocalConfig.captureFileFormat;
  326. }
  327. szFileName += ("0" === szCaptureFileFormat) ? ".jpg": ".bmp";
  328. WebVideoCtrl.I_CapturePic(szFileName, iWind).then(() => {
  329. msgLog("capturePicture success");
  330. }, (oError) => {
  331. msgLog("capturePicture failed: " + iWind);
  332. });
  333. }
  334. function stopPlayAll () {
  335. WebVideoCtrl.I_StopAllPlay().then(() => {
  336. msgLog("stop all play success");
  337. }, (oError) => {
  338. msgLog("stop all play failed");
  339. });
  340. }
  341. function dateFormat(oDate, fmt) {
  342. var o = {
  343. "M+": oDate.getMonth() + 1,
  344. "d+": oDate.getDate(),
  345. "h+": oDate.getHours(),
  346. "m+": oDate.getMinutes(),
  347. "s+": oDate.getSeconds(),
  348. "q+": Math.floor((oDate.getMonth() + 3) / 3),
  349. "S": oDate.getMilliseconds()
  350. };
  351. if (/(y+)/.test(fmt)) {
  352. fmt = fmt.replace(RegExp.$1, (oDate.getFullYear() + "").substr(4 - RegExp.$1.length));
  353. }
  354. for (var k in o) {
  355. if (new RegExp("(" + k + ")").test(fmt)) {
  356. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  357. }
  358. }
  359. return fmt;
  360. }
  361. function record() {
  362. var szTime = dateFormat(new Date(), "yyyyMMddhhmmssS");
  363. var szFileName = "10.17.137.229_01_" + szTime;
  364. WebVideoCtrl.I_StartRecord(szFileName, iWind).then(() => {
  365. msgLog("record success");
  366. }, (oError) => {
  367. msgLog("record failed");
  368. });
  369. }
  370. function stopRecord() {
  371. WebVideoCtrl.I_StopRecord(iWind).then(() => {
  372. msgLog("stop record success");
  373. }, (oError) => {
  374. msgLog("stop record failed");
  375. });
  376. }
  377. function fullSreen() {
  378. WebVideoCtrl.I_FullScreen(true).then(() => {
  379. msgLog("fullscreen success");
  380. }, (oError) => {
  381. msgLog("fullscreen failed");
  382. });
  383. }
  384. function checkUpdate () {
  385. WebVideoCtrl.I_CheckPluginVersion().then((bFlag) => {
  386. if (bFlag) {
  387. msgLog("HCWebSDKPlugin has detected a new version.");
  388. } else {
  389. msgLog("HCWebSDKPlugin is currently the latest version.");
  390. }
  391. });
  392. }
  393. function clickOpenFileDlg(szElemID) {
  394. WebVideoCtrl.I_OpenFileDlg(0).then((szDirPath) => {
  395. if (szDirPath != -1 && szDirPath != "" && szDirPath != null) {
  396. $("#" + szElemID).val(szDirPath);
  397. }
  398. }, (oError) => {
  399. msgLog("Failed to open folder.");
  400. });
  401. }
  402. var g_oLocalConfig = null;
  403. function clickGetLocalCfg() {
  404. WebVideoCtrl.I_GetLocalCfg().then((oLocalConfig) => {
  405. g_oLocalConfig = oLocalConfig;
  406. $("#recordPath").val(oLocalConfig.recordPath);
  407. $("#previewPicPath").val(oLocalConfig.capturePath);
  408. $("#playbackPicPath").val(oLocalConfig.playbackPicPath);
  409. $("#playbackFilePath").val(oLocalConfig.playbackFilePath);
  410. $("#captureFileFormat").val(oLocalConfig.captureFileFormat);
  411. msgLog("get plugin configuration success.");
  412. }, (oError) => {
  413. msgLog("get plugin configuration failed.");
  414. });
  415. }
  416. function clickSetLocalCfg() {
  417. g_oLocalConfig.recordPath = $("#recordPath").val();
  418. g_oLocalConfig.capturePath = $("#previewPicPath").val();
  419. g_oLocalConfig.playbackPicPath = $("#playbackPicPath").val();
  420. g_oLocalConfig.playbackFilePath = $("#playbackFilePath").val();
  421. g_oLocalConfig.captureFileFormat = $("#captureFileFormat").val();
  422. WebVideoCtrl.I_SetLocalCfg(g_oLocalConfig).then(() => {
  423. msgLog("set plugin configuration success.");
  424. }, (oError) => {
  425. msgLog("set plugin configuration failed.");
  426. });
  427. }
  428. window.onresize = function () {
  429. WebVideoCtrl.I_Resize(600, 400);
  430. };
  431. </script>
  432. </body>
  433. </html>