demo.js 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130
  1. // Init plugin
  2. // overall save the current selected window
  3. var g_iWndIndex = 0; //don't have to set the variable; default to use the current selected window without transmiting value when the interface has window parameters
  4. $(function () {
  5. // check the installation status of plugin
  6. var iRet = WebVideoCtrl.I_CheckPluginInstall();
  7. if (-1 == iRet) {
  8. alert("If the plugin is uninstalled, please install the WebComponentsKit.exe!");
  9. return;
  10. }
  11. // Init plugin parameters and insert the plugin
  12. WebVideoCtrl.I_InitPlugin(500, 300, {
  13. bWndFull: true, //Wether support doule clicking to switch the full-screen mode: it's supported by default; true:support, false:not support
  14. iPackageType: 2, //2:PS 11:MP4
  15. iWndowType: 1,
  16. bNoPlugin: true,
  17. cbSelWnd: function (xmlDoc) {
  18. g_iWndIndex = parseInt($(xmlDoc).find("SelectWnd").eq(0).text(), 10);
  19. var szInfo = "selected window number: " + g_iWndIndex;
  20. showCBInfo(szInfo);
  21. },
  22. cbDoubleClickWnd: function (iWndIndex, bFullScreen) {
  23. var szInfo = "present window number to zoom: " + iWndIndex;
  24. if (!bFullScreen) {
  25. szInfo = "present window number to restore: " + iWndIndex;
  26. }
  27. showCBInfo(szInfo);
  28. // you can handle the single window bit stream switching here
  29. /*if (bFullScreen) {
  30. clickStartRealPlay(1);
  31. } else {
  32. clickStartRealPlay(2);
  33. }*/
  34. },
  35. cbEvent: function (iEventType, iParam1, iParam2) {
  36. if (2 == iEventType) {// playback finished normally
  37. showCBInfo("window " + iParam1 + " playback finished!");
  38. } else if (-1 == iEventType) {
  39. showCBInfo("device " + iParam1 + " network error!");
  40. } else if (3001 == iEventType) {
  41. clickStopRecord(g_szRecordType, iParam1);
  42. }
  43. },
  44. cbRemoteConfig: function () {
  45. showCBInfo("closed remote config!");
  46. },
  47. cbInitPluginComplete: function () {
  48. WebVideoCtrl.I_InsertOBJECTPlugin("divPlugin");
  49. // check plugin to see whether it is the latest
  50. if (-1 == WebVideoCtrl.I_CheckPluginVersion()) {
  51. alert("Detect the latest version, please double click WebComponentsKit.exe to update!");
  52. return;
  53. }
  54. }
  55. });
  56. // window event binding
  57. $(window).bind({
  58. resize: function () {
  59. var $Restart = $("#restartDiv");
  60. if ($Restart.length > 0) {
  61. var oSize = getWindowSize();
  62. $Restart.css({
  63. width: oSize.width + "px",
  64. height: oSize.height + "px"
  65. });
  66. }
  67. }
  68. });
  69. //init date
  70. var szCurTime = dateFormat(new Date(), "yyyy-MM-dd");
  71. $("#starttime").val(szCurTime + " 00:00:00");
  72. $("#endtime").val(szCurTime + " 23:59:59");
  73. $("#downloadstarttime").val(szCurTime + " 00:00:00");
  74. $("#downloadendtime").val(szCurTime + " 23:59:59");
  75. if(WebVideoCtrl.I_SupportNoPlugin()){
  76. $(".localconfig").hide();
  77. $(".ipparse").hide();
  78. $("#checkVersion").hide();
  79. $("#remoteconfig").hide();
  80. $("#btnReverse").hide();
  81. }
  82. });
  83. // display operation info
  84. function showOPInfo(szInfo, status, xmlDoc) {
  85. var szTip = "<div>" + dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss") + " " + szInfo;
  86. if (typeof status != "undefined" && status != 200) {
  87. var szStatusString = $(xmlDoc).find("statusString").eq(0).text();
  88. var szSubStatusCode = $(xmlDoc).find("subStatusCode").eq(0).text();
  89. if ("" === szSubStatusCode) {
  90. if("" === szSubStatusCode && "" === szStatusString){
  91. szTip += "(" + status + ")";
  92. }
  93. else{
  94. szTip += "(" + status + ", " + szStatusString + ")";
  95. }
  96. } else {
  97. szTip += "(" + status + ", " + szSubStatusCode + ")";
  98. }
  99. }
  100. szTip += "</div>";
  101. $("#opinfo").html(szTip + $("#opinfo").html());
  102. }
  103. // display callback info
  104. function showCBInfo(szInfo) {
  105. szInfo = "<div>" + dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss") + " " + szInfo + "</div>";
  106. $("#cbinfo").html(szInfo + $("#cbinfo").html());
  107. }
  108. // time format
  109. function dateFormat(oDate, fmt) {
  110. var o = {
  111. "M+": oDate.getMonth() + 1, //month
  112. "d+": oDate.getDate(), //day
  113. "h+": oDate.getHours(), //hour
  114. "m+": oDate.getMinutes(), //minute
  115. "s+": oDate.getSeconds(), //second
  116. "q+": Math.floor((oDate.getMonth() + 3) / 3), //quarter
  117. "S": oDate.getMilliseconds()//millisecond
  118. };
  119. if (/(y+)/.test(fmt)) {
  120. fmt = fmt.replace(RegExp.$1, (oDate.getFullYear() + "").substr(4 - RegExp.$1.length));
  121. }
  122. for (var k in o) {
  123. if (new RegExp("(" + k + ")").test(fmt)) {
  124. fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  125. }
  126. }
  127. return fmt;
  128. }
  129. // get window size
  130. function getWindowSize() {
  131. var nWidth = $(this).width() + $(this).scrollLeft(),
  132. nHeight = $(this).height() + $(this).scrollTop();
  133. return {width: nWidth, height: nHeight};
  134. }
  135. // open option dialog 0: folder, 1: file
  136. function clickOpenFileDlg(id, iType) {
  137. WebVideoCtrl.I2_OpenFileDlg(iType).then(function(szDirPath){
  138. if (szDirPath != -1 && szDirPath != "" && szDirPath != null) {
  139. $("#" + id).val(szDirPath);
  140. }
  141. });
  142. // var szDirPath = WebVideoCtrl.I_OpenFileDlg(iType);
  143. // if (szDirPath != -1 && szDirPath != "" && szDirPath != null) {
  144. // $("#" + id).val(szDirPath);
  145. // }
  146. }
  147. // get local parameters
  148. function clickGetLocalCfg() {
  149. var xmlDoc = WebVideoCtrl.I_GetLocalCfg();
  150. if (xmlDoc != null) {
  151. $("#netsPreach").val($(xmlDoc).find("BuffNumberType").eq(0).text());
  152. $("#wndSize").val($(xmlDoc).find("PlayWndType").eq(0).text());
  153. $("#rulesInfo").val($(xmlDoc).find("IVSMode").eq(0).text());
  154. $("#captureFileFormat").val($(xmlDoc).find("CaptureFileFormat").eq(0).text());
  155. $("#packSize").val($(xmlDoc).find("PackgeSize").eq(0).text());
  156. $("#recordPath").val($(xmlDoc).find("RecordPath").eq(0).text());
  157. $("#downloadPath").val($(xmlDoc).find("DownloadPath").eq(0).text());
  158. $("#previewPicPath").val($(xmlDoc).find("CapturePath").eq(0).text());
  159. $("#playbackPicPath").val($(xmlDoc).find("PlaybackPicPath").eq(0).text());
  160. $("#devicePicPath").val($(xmlDoc).find("DeviceCapturePath").eq(0).text());
  161. $("#playbackFilePath").val($(xmlDoc).find("PlaybackFilePath").eq(0).text());
  162. $("#protocolType").val($(xmlDoc).find("ProtocolType").eq(0).text());
  163. showOPInfo("local configuration success!");
  164. } else {
  165. showOPInfo("local configuration failed!");
  166. }
  167. }
  168. // set local parameters
  169. function clickSetLocalCfg() {
  170. var arrXml = [],
  171. szInfo = "";
  172. arrXml.push("<LocalConfigInfo>");
  173. arrXml.push("<PackgeSize>" + $("#packSize").val() + "</PackgeSize>");
  174. arrXml.push("<PlayWndType>" + $("#wndSize").val() + "</PlayWndType>");
  175. arrXml.push("<BuffNumberType>" + $("#netsPreach").val() + "</BuffNumberType>");
  176. arrXml.push("<RecordPath>" + $("#recordPath").val() + "</RecordPath>");
  177. arrXml.push("<CapturePath>" + $("#previewPicPath").val() + "</CapturePath>");
  178. arrXml.push("<PlaybackFilePath>" + $("#playbackFilePath").val() + "</PlaybackFilePath>");
  179. arrXml.push("<PlaybackPicPath>" + $("#playbackPicPath").val() + "</PlaybackPicPath>");
  180. arrXml.push("<DeviceCapturePath>" + $("#devicePicPath").val() + "</DeviceCapturePath>");
  181. arrXml.push("<DownloadPath>" + $("#downloadPath").val() + "</DownloadPath>");
  182. arrXml.push("<IVSMode>" + $("#rulesInfo").val() + "</IVSMode>");
  183. arrXml.push("<CaptureFileFormat>" + $("#captureFileFormat").val() + "</CaptureFileFormat>");
  184. arrXml.push("<ProtocolType>" + $("#protocolType").val() + "</ProtocolType>");
  185. arrXml.push("</LocalConfigInfo>");
  186. var iRet = WebVideoCtrl.I_SetLocalCfg(arrXml.join(""));
  187. if (0 == iRet) {
  188. szInfo = "local configuration success!";
  189. } else {
  190. szInfo = "local configuration failed!";
  191. }
  192. showOPInfo(szInfo);
  193. }
  194. // windows number
  195. function changeWndNum(iType) {
  196. iType = parseInt(iType, 10);
  197. WebVideoCtrl.I_ChangeWndNum(iType);
  198. }
  199. // login
  200. function clickLogin() {
  201. var szIP = $("#loginip").val(),
  202. szPort = $("#port").val(),
  203. szUsername = $("#username").val(),
  204. szPassword = $("#password").val();
  205. if ("" == szIP || "" == szPort) {
  206. return;
  207. }
  208. var szDeviceIdentify = szIP + "_" + szPort;
  209. var iRet = WebVideoCtrl.I_Login(szIP, 1, szPort, szUsername, szPassword, {
  210. success: function (xmlDoc) {
  211. showOPInfo(szDeviceIdentify + " login success!");
  212. $("#ip").prepend("<option value='" + szDeviceIdentify + "'>" + szDeviceIdentify + "</option>");
  213. //var i =1;
  214. setTimeout(function () {
  215. $("#ip").val(szDeviceIdentify);
  216. getChannelInfo();
  217. getDevicePort();
  218. }, 10);
  219. // var a= setInterval(function(){
  220. // i++;
  221. // if(i>100){
  222. // clearInterval(a);
  223. // alert("done");
  224. // }
  225. // clickStartRealPlay();
  226. // setTimeout(function () {
  227. // clickStopRealPlay();
  228. // }, 900);
  229. // },1000);
  230. },
  231. error: function (status, xmlDoc) {
  232. showOPInfo(szDeviceIdentify + " login failed!", status, xmlDoc);
  233. }
  234. });
  235. if (-1 == iRet) {
  236. showOPInfo(szDeviceIdentify + " login already !");
  237. }
  238. }
  239. // exit
  240. function clickLogout() {
  241. var szDeviceIdentify = $("#ip").val(),
  242. szInfo = "";
  243. if (null == szDeviceIdentify) {
  244. return;
  245. }
  246. var iRet = WebVideoCtrl.I_Logout(szDeviceIdentify);
  247. if (0 == iRet) {
  248. szInfo = "exit success!";
  249. $("#ip option[value='" + szDeviceIdentify + "']").remove();
  250. getChannelInfo();
  251. getDevicePort();
  252. } else {
  253. szInfo = "exit failed!";
  254. }
  255. showOPInfo(szDeviceIdentify + " " + szInfo);
  256. }
  257. // get deivce info
  258. function clickGetDeviceInfo() {
  259. var szDeviceIdentify = $("#ip").val();
  260. if (null == szDeviceIdentify) {
  261. return;
  262. }
  263. WebVideoCtrl.I_GetDeviceInfo(szDeviceIdentify, {
  264. success: function (xmlDoc) {
  265. var arrStr = [];
  266. arrStr.push("device name:" + $(xmlDoc).find("deviceName").eq(0).text() + "\r\n");
  267. arrStr.push("device ID:" + $(xmlDoc).find("deviceID").eq(0).text() + "\r\n");
  268. arrStr.push("model:" + $(xmlDoc).find("model").eq(0).text() + "\r\n");
  269. arrStr.push("serial number:" + $(xmlDoc).find("serialNumber").eq(0).text() + "\r\n");
  270. arrStr.push("MAC address:" + $(xmlDoc).find("macAddress").eq(0).text() + "\r\n");
  271. arrStr.push("firmware version:" + $(xmlDoc).find("firmwareVersion").eq(0).text() + " " + $(xmlDoc).find("firmwareReleasedDate").eq(0).text() + "\r\n");
  272. arrStr.push("encoder version:" + $(xmlDoc).find("encoderVersion").eq(0).text() + " " + $(xmlDoc).find("encoderReleasedDate").eq(0).text() + "\r\n");
  273. showOPInfo(szDeviceIdentify + " get deivce info success!");
  274. alert(arrStr.join(""));
  275. },
  276. error: function (status, xmlDoc) {
  277. showOPInfo(szDeviceIdentify + " get device info failed!", status, xmlDoc);
  278. }
  279. });
  280. }
  281. // get channel info
  282. function getChannelInfo() {
  283. var szDeviceIdentify = $("#ip").val(),
  284. oSel = $("#channels").empty();
  285. if (null == szDeviceIdentify) {
  286. return;
  287. }
  288. // analog channel
  289. WebVideoCtrl.I_GetAnalogChannelInfo(szDeviceIdentify, {
  290. async: false,
  291. success: function (xmlDoc) {
  292. var oChannels = $(xmlDoc).find("VideoInputChannel");
  293. $.each(oChannels, function (i) {
  294. var id = $(this).find("id").eq(0).text(),
  295. name = $(this).find("name").eq(0).text();
  296. if ("" == name) {
  297. name = "Camera " + (i < 9 ? "0" + (i + 1) : (i + 1));
  298. }
  299. oSel.append("<option value='" + id + "' bZero='false'>" + name + "</option>");
  300. });
  301. showOPInfo(szDeviceIdentify + " get analog channel success!");
  302. },
  303. error: function (status, xmlDoc) {
  304. showOPInfo(szDeviceIdentify + " get analog channel failed!", status, xmlDoc);
  305. }
  306. });
  307. // IP channel
  308. WebVideoCtrl.I_GetDigitalChannelInfo(szDeviceIdentify, {
  309. async: false,
  310. success: function (xmlDoc) {
  311. var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
  312. $.each(oChannels, function (i) {
  313. var id = $(this).find("id").eq(0).text(),
  314. name = $(this).find("name").eq(0).text(),
  315. online = $(this).find("online").eq(0).text();
  316. if ("false" == online) {// filter the forbidden IP channel
  317. return true;
  318. }
  319. if ("" == name) {
  320. name = "IPCamera " + (i < 9 ? "0" + (i + 1) : (i + 1));
  321. }
  322. oSel.append("<option value='" + id + "' bZero='false'>" + name + "</option>");
  323. });
  324. showOPInfo(szDeviceIdentify + " get IP channel success!");
  325. },
  326. error: function (status, xmlDoc) {
  327. showOPInfo(szDeviceIdentify + " get IP channel failed!", status, xmlDoc);
  328. }
  329. });
  330. // zero-channel info
  331. WebVideoCtrl.I_GetZeroChannelInfo(szDeviceIdentify, {
  332. async: false,
  333. success: function (xmlDoc) {
  334. var oChannels = $(xmlDoc).find("ZeroVideoChannel");
  335. $.each(oChannels, function (i) {
  336. var id = $(this).find("id").eq(0).text(),
  337. name = $(this).find("name").eq(0).text();
  338. if ("" == name) {
  339. name = "Zero Channel " + (i < 9 ? "0" + (i + 1) : (i + 1));
  340. }
  341. if ("true" == $(this).find("enabled").eq(0).text()) {// filter the forbidden zero-channel
  342. oSel.append("<option value='" + id + "' bZero='true'>" + name + "</option>");
  343. }
  344. });
  345. showOPInfo(szDeviceIdentify + " get zero-channel success!");
  346. },
  347. error: function (status, xmlDoc) {
  348. showOPInfo(szDeviceIdentify + " get zero-channel failed!", status, xmlDoc);
  349. }
  350. });
  351. }
  352. // get port
  353. function getDevicePort() {
  354. var szDeviceIdentify = $("#ip").val();
  355. if (null == szDeviceIdentify) {
  356. return;
  357. }
  358. var oPort = WebVideoCtrl.I_GetDevicePort(szDeviceIdentify);
  359. if (oPort != null) {
  360. $("#deviceport").val(oPort.iDevicePort);
  361. $("#rtspport").val(oPort.iRtspPort);
  362. showOPInfo(szDeviceIdentify + " get port success!");
  363. } else {
  364. showOPInfo(szDeviceIdentify + " get port failed!");
  365. }
  366. }
  367. // get IP channel
  368. function clickGetDigitalChannelInfo() {
  369. var szDeviceIdentify = $("#ip").val(),
  370. iAnalogChannelNum = 0;
  371. $("#digitalchannellist").empty();
  372. if (null == szDeviceIdentify) {
  373. return;
  374. }
  375. // analog channel
  376. WebVideoCtrl.I_GetAnalogChannelInfo(szDeviceIdentify, {
  377. async: false,
  378. success: function (xmlDoc) {
  379. iAnalogChannelNum = $(xmlDoc).find("VideoInputChannel").length;
  380. },
  381. error: function () {
  382. }
  383. });
  384. // IP channel
  385. WebVideoCtrl.I_GetDigitalChannelInfo(szDeviceIdentify, {
  386. async: false,
  387. success: function (xmlDoc) {
  388. var oChannels = $(xmlDoc).find("InputProxyChannelStatus");
  389. $.each(oChannels, function () {
  390. var id = parseInt($(this).find("id").eq(0).text(), 10),
  391. ipAddress = $(this).find("ipAddress").eq(0).text(),
  392. srcInputPort = $(this).find("srcInputPort").eq(0).text(),
  393. managePortNo = $(this).find("managePortNo").eq(0).text(),
  394. online = $(this).find("online").eq(0).text(),
  395. proxyProtocol = $(this).find("proxyProtocol").eq(0).text();
  396. var objTr = $("#digitalchannellist").get(0).insertRow(-1);
  397. var objTd = objTr.insertCell(0);
  398. objTd.innerHTML = (id - iAnalogChannelNum) < 10 ? "D0" + (id - iAnalogChannelNum) : "D" + (id - iAnalogChannelNum);
  399. objTd = objTr.insertCell(1);
  400. objTd.width = "25%";
  401. objTd.innerHTML = ipAddress;
  402. objTd = objTr.insertCell(2);
  403. objTd.width = "15%";
  404. objTd.innerHTML = srcInputPort;
  405. objTd = objTr.insertCell(3);
  406. objTd.width = "20%";
  407. objTd.innerHTML = managePortNo;
  408. objTd = objTr.insertCell(4);
  409. objTd.width = "15%";
  410. objTd.innerHTML = "true" == online ? "online" : "offline";
  411. objTd = objTr.insertCell(5);
  412. objTd.width = "25%";
  413. objTd.innerHTML = proxyProtocol;
  414. });
  415. showOPInfo(szDeviceIdentify + " get IP channel success!");
  416. },
  417. error: function (status, xmlDoc) {
  418. showOPInfo(szDeviceIdentify + " no IP channel!", status, xmlDoc);
  419. }
  420. });
  421. }
  422. // strat real play
  423. function clickStartRealPlay(iStreamType) {
  424. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  425. szDeviceIdentify = $("#ip").val(),
  426. iRtspPort = parseInt($("#rtspport").val(), 10),
  427. iChannelID = parseInt($("#channels").val(), 10),
  428. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  429. szInfo = "";
  430. if ("undefined" === typeof iStreamType) {
  431. iStreamType = parseInt($("#streamtype").val(), 10);
  432. }
  433. if (null == szDeviceIdentify) {
  434. return;
  435. }
  436. var startRealPlay = function () {
  437. WebVideoCtrl.I_StartRealPlay(szDeviceIdentify, {
  438. iRtspPort: iRtspPort,
  439. iStreamType: iStreamType,
  440. iChannelID: iChannelID,
  441. bZeroChannel: bZeroChannel,
  442. success: function () {
  443. szInfo = "start real play success!";
  444. showOPInfo(szDeviceIdentify + " " + szInfo);
  445. },
  446. error: function (status, xmlDoc) {
  447. if (403 === status) {
  448. szInfo = "Device do not support Websocket extracting the flow!";
  449. } else {
  450. szInfo = "start real play failed!";
  451. }
  452. showOPInfo(szDeviceIdentify + " " + szInfo);
  453. }
  454. });
  455. };
  456. if (oWndInfo != null) {// stop play first
  457. WebVideoCtrl.I_Stop({
  458. success: function () {
  459. startRealPlay();
  460. }
  461. });
  462. } else {
  463. startRealPlay();
  464. }
  465. }
  466. function setTextOverlay() {
  467. var szDeviceIdentify = $("#ip").val();
  468. var szInfo = "";
  469. var that = this;
  470. var szUrl = "ISAPI/System/Video/inputs/channels/1/overlays";
  471. WebVideoCtrl.I_GetTextOverlay(szUrl,szDeviceIdentify,{
  472. success:function(data){
  473. $(data).find("TextOverlay").eq(0).find("displayText").eq(0).text("eee6444是66ee&lt;");
  474. $(data).find("TextOverlay").eq(0).find("positionX").eq(0).text("208");
  475. $(data).find("TextOverlay").eq(0).find("positionY").eq(0).text("304");
  476. var xmldoc = toXMLStr(data);
  477. var newOptions = {
  478. async:true,
  479. type: "PUT",
  480. data:xmldoc,
  481. success:function(){
  482. szInfo = "draw osd succ";
  483. showOPInfo(szDeviceIdentify + " " + szInfo);
  484. },
  485. error:function(){
  486. szInfo = "draw osd fail";
  487. showOPInfo(szDeviceIdentify + " " + szInfo);
  488. }
  489. };
  490. WebVideoCtrl.I_SendHTTPRequest(szDeviceIdentify,szUrl,newOptions);
  491. },
  492. error:function(){
  493. szInfo = "get osd fail";
  494. showOPInfo(szDeviceIdentify + " " + szInfo);
  495. }
  496. });
  497. }
  498. // stop real play
  499. function clickStopRealPlay() {
  500. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  501. szInfo = "";
  502. if (oWndInfo != null) {
  503. WebVideoCtrl.I_Stop({
  504. success: function () {
  505. szInfo = "stop real play success!";
  506. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  507. },
  508. error: function () {
  509. szInfo = "stop real play failed!";
  510. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  511. }
  512. });
  513. }
  514. }
  515. // open sound
  516. function clickOpenSound() {
  517. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  518. szInfo = "";
  519. if (oWndInfo != null) {
  520. var allWndInfo = WebVideoCtrl.I_GetWindowStatus();
  521. // close the sound by iterating over all the window
  522. for (var i = 0, iLen = allWndInfo.length; i < iLen; i++) {
  523. oWndInfo = allWndInfo[i];
  524. if (oWndInfo.bSound) {
  525. WebVideoCtrl.I_CloseSound(oWndInfo.iIndex);
  526. break;
  527. }
  528. }
  529. var iRet = WebVideoCtrl.I_OpenSound();
  530. if (0 == iRet) {
  531. szInfo = "open sound success!";
  532. } else {
  533. szInfo = "open sound failed!";
  534. }
  535. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  536. }
  537. }
  538. // close sound
  539. function clickCloseSound() {
  540. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  541. szInfo = "";
  542. if (oWndInfo != null) {
  543. var iRet = WebVideoCtrl.I_CloseSound();
  544. if (0 == iRet) {
  545. szInfo = "close sound success!";
  546. } else {
  547. szInfo = "close sound failed!";
  548. }
  549. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  550. }
  551. }
  552. // set volume
  553. function clickSetVolume() {
  554. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  555. iVolume = parseInt($("#volume").val(), 10),
  556. szInfo = "";
  557. if (oWndInfo != null) {
  558. var iRet = WebVideoCtrl.I_SetVolume(iVolume);
  559. if (0 == iRet) {
  560. szInfo = "set volume success!";
  561. } else {
  562. szInfo = "set volume failed!";
  563. }
  564. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  565. }
  566. }
  567. // capture
  568. function clickCapturePic() {
  569. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  570. szInfo = "";
  571. if (oWndInfo != null) {
  572. var xmlDoc = WebVideoCtrl.I_GetLocalCfg();
  573. var szCaptureFileFormat = "0";
  574. if (xmlDoc != null) {
  575. szCaptureFileFormat = $(xmlDoc).find("CaptureFileFormat").eq(0).text();
  576. }
  577. var szChannelID = $("#channels").val();
  578. var szPicName = oWndInfo.szDeviceIdentify + "_" + szChannelID + "_" + new Date().getTime();
  579. szPicName += ("0" === szCaptureFileFormat) ? ".jpg": ".bmp";
  580. var iRet = WebVideoCtrl.I_CapturePic(szPicName, {
  581. bDateDir: true //generate the date file or not
  582. });
  583. if (0 == iRet) {
  584. szInfo = "capture success!";
  585. } else {
  586. szInfo = "capture failed!";
  587. }
  588. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  589. }
  590. }
  591. // capture onload
  592. function clickCapturePicData() {
  593. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  594. szInfo = "";
  595. if (oWndInfo != null) {
  596. WebVideoCtrl.I2_CapturePicData().then(function(data){
  597. szInfo = "capture onload success!";
  598. console.log(data);
  599. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  600. },function(){
  601. szInfo = "capture onload failed!";
  602. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  603. });
  604. }
  605. }
  606. // start record
  607. var g_szRecordType = "";
  608. function clickStartRecord(szType) {
  609. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  610. szInfo = "";
  611. g_szRecordType = szType;
  612. if (oWndInfo != null) {
  613. var szChannelID = $("#channels").val(),
  614. szFileName = oWndInfo.szDeviceIdentify + "_" + szChannelID + "_" + new Date().getTime();
  615. WebVideoCtrl.I_StartRecord(szFileName, {
  616. bDateDir: true, //generate the date file or not
  617. success: function () {
  618. if ('realplay' === szType) {
  619. szInfo = "start recording success!";
  620. } else if ('playback' === szType) {
  621. szInfo = "start clip success!";
  622. }
  623. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  624. },
  625. error: function () {
  626. if ('realplay' === szType) {
  627. szInfo = "start recording failed!";
  628. } else if ('playback' === szType) {
  629. szInfo = "start clip failed!";
  630. }
  631. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  632. }
  633. });
  634. }
  635. }
  636. // stop record
  637. function clickStopRecord(szType, iWndIndex) {
  638. if ("undefined" === typeof iWndIndex) {
  639. iWndIndex = g_iWndIndex;
  640. }
  641. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(iWndIndex),
  642. szInfo = "";
  643. if (oWndInfo != null) {
  644. WebVideoCtrl.I_StopRecord({
  645. success: function () {
  646. if ('realplay' === szType) {
  647. szInfo = "stop recording success!";
  648. } else if ('playback' === szType) {
  649. szInfo = "stop clip success!";
  650. }
  651. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  652. },
  653. error: function () {
  654. if ('realplay' === szType) {
  655. szInfo = "stop recording failed!";
  656. } else if ('playback' === szType) {
  657. szInfo = "stop clip failed!";
  658. }
  659. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  660. }
  661. });
  662. }
  663. }
  664. // get audio channel
  665. function clickGetAudioInfo() {
  666. var szDeviceIdentify = $("#ip").val();
  667. if (null == szDeviceIdentify) {
  668. return;
  669. }
  670. WebVideoCtrl.I_GetAudioInfo(szDeviceIdentify, {
  671. success: function (xmlDoc) {
  672. var oAudioChannels = $(xmlDoc).find("TwoWayAudioChannel"),
  673. oSel = $("#audiochannels").empty();
  674. $.each(oAudioChannels, function () {
  675. var id = $(this).find("id").eq(0).text();
  676. oSel.append("<option value='" + id + "'>" + id + "</option>");
  677. });
  678. showOPInfo(szDeviceIdentify + " get audio channel success!");
  679. },
  680. error: function (status, xmlDoc) {
  681. showOPInfo(szDeviceIdentify + " get audio channel failed!", status, xmlDoc);
  682. }
  683. });
  684. }
  685. // start voice talk
  686. function clickStartVoiceTalk() {
  687. var szDeviceIdentify = $("#ip").val(),
  688. iAudioChannel = parseInt($("#audiochannels").val(), 10),
  689. szInfo = "";
  690. if (null == szDeviceIdentify) {
  691. return;
  692. }
  693. if (isNaN(iAudioChannel)) {
  694. alert("please select channel first!");
  695. return;
  696. }
  697. var iRet = WebVideoCtrl.I_StartVoiceTalk(szDeviceIdentify, iAudioChannel);
  698. if (0 == iRet) {
  699. szInfo = "start voice talk success!";
  700. } else {
  701. szInfo = "start voice talk failed!";
  702. }
  703. showOPInfo(szDeviceIdentify + " " + szInfo);
  704. }
  705. // stop voice talk
  706. function clickStopVoiceTalk() {
  707. var szDeviceIdentify = $("#ip").val(),
  708. iRet = WebVideoCtrl.I_StopVoiceTalk(),
  709. szInfo = "";
  710. if (null == szDeviceIdentify) {
  711. return;
  712. }
  713. if (0 == iRet) {
  714. szInfo = "stop voice talk success!";
  715. } else {
  716. szInfo = "stop voice talk failed!";
  717. }
  718. showOPInfo(szDeviceIdentify + " " + szInfo);
  719. }
  720. // enable E-zoom
  721. function clickEnableEZoom() {
  722. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  723. szInfo = "";
  724. if (oWndInfo != null) {
  725. var iRet = WebVideoCtrl.I_EnableEZoom();
  726. if (0 == iRet) {
  727. szInfo = "enable E-zoom success!";
  728. } else {
  729. szInfo = "enable E-zoom failed!";
  730. }
  731. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  732. }
  733. }
  734. // disable E-zoom
  735. function clickDisableEZoom() {
  736. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  737. szInfo = "";
  738. if (oWndInfo != null) {
  739. var iRet = WebVideoCtrl.I_DisableEZoom();
  740. if (0 == iRet) {
  741. szInfo = "disable E-zoom success!";
  742. } else {
  743. szInfo = "disable E-zoom failed!";
  744. }
  745. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  746. }
  747. }
  748. // enable 3D zoom
  749. function clickEnable3DZoom() {
  750. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  751. szInfo = "";
  752. if (oWndInfo != null) {
  753. var iRet = WebVideoCtrl.I_Enable3DZoom();
  754. if (0 == iRet) {
  755. szInfo = "enable 3D zoom success!";
  756. } else {
  757. szInfo = "enable 3D zoom failed!";
  758. }
  759. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  760. }
  761. }
  762. // diasble 3D zoom
  763. function clickDisable3DZoom() {
  764. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  765. szInfo = "";
  766. if (oWndInfo != null) {
  767. var iRet = WebVideoCtrl.I_Disable3DZoom();
  768. if (0 == iRet) {
  769. szInfo = "diasble 3D zoom success!";
  770. } else {
  771. szInfo = "diasble 3D zoom failed!";
  772. }
  773. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  774. }
  775. }
  776. // full screen
  777. function clickFullScreen() {
  778. WebVideoCtrl.I_FullScreen(true);
  779. }
  780. // PTZ control, 9- auto; 1,2,3,4,5,6,7,8 - PTZ direction control by mouse
  781. var g_bPTZAuto = false;
  782. function mouseDownPTZControl(iPTZIndex) {
  783. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  784. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  785. iPTZSpeed = $("#ptzspeed").val();
  786. if (bZeroChannel) {// zero-channel does not support PTZ
  787. return;
  788. }
  789. if (oWndInfo != null) {
  790. if (9 == iPTZIndex && g_bPTZAuto) {
  791. iPTZSpeed = 0;// you can close auto mode by setting speed to 0 when auto is start already
  792. } else {
  793. g_bPTZAuto = false;// auto mode will be close when you clik other direction
  794. }
  795. WebVideoCtrl.I_PTZControl(iPTZIndex, false, {
  796. iPTZSpeed: iPTZSpeed,
  797. success: function (xmlDoc) {
  798. if (9 == iPTZIndex && g_bPTZAuto) {
  799. showOPInfo(oWndInfo.szDeviceIdentify + " stop PTZ success!");
  800. } else {
  801. showOPInfo(oWndInfo.szDeviceIdentify + " start PTZ success!");
  802. }
  803. if (9 == iPTZIndex) {
  804. g_bPTZAuto = !g_bPTZAuto;
  805. }
  806. },
  807. error: function (status, xmlDoc) {
  808. showOPInfo(oWndInfo.szDeviceIdentify + " start PTZ failed!", status, xmlDoc);
  809. }
  810. });
  811. }
  812. }
  813. // stop PTZ direction
  814. function mouseUpPTZControl() {
  815. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  816. if (oWndInfo != null) {
  817. WebVideoCtrl.I_PTZControl(1, true, {
  818. success: function (xmlDoc) {
  819. showOPInfo(oWndInfo.szDeviceIdentify + " stop PTZ success!");
  820. },
  821. error: function (status, xmlDoc) {
  822. showOPInfo(oWndInfo.szDeviceIdentify + " stop PTZ failed!", status, xmlDoc);
  823. }
  824. });
  825. }
  826. }
  827. // set preset
  828. function clickSetPreset() {
  829. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  830. iPresetID = parseInt($("#preset").val(), 10);
  831. if (oWndInfo != null) {
  832. WebVideoCtrl.I_SetPreset(iPresetID, {
  833. success: function (xmlDoc) {
  834. showOPInfo(oWndInfo.szDeviceIdentify + " set preset success!");
  835. },
  836. error: function (status, xmlDoc) {
  837. showOPInfo(oWndInfo.szDeviceIdentify + " set preset failed!", status, xmlDoc);
  838. }
  839. });
  840. }
  841. }
  842. // call preset
  843. function clickGoPreset() {
  844. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  845. iPresetID = parseInt($("#preset").val(), 10);
  846. if (oWndInfo != null) {
  847. WebVideoCtrl.I_GoPreset(iPresetID, {
  848. success: function (xmlDoc) {
  849. showOPInfo(oWndInfo.szDeviceIdentify + " call preset success!");
  850. },
  851. error: function (status, xmlDoc) {
  852. showOPInfo(oWndInfo.szDeviceIdentify + " call preset failed!", status, xmlDoc);
  853. }
  854. });
  855. }
  856. }
  857. // record searching
  858. var g_iSearchTimes = 0;
  859. function clickRecordSearch(iType) {
  860. var szDeviceIdentify = $("#ip").val(),
  861. iChannelID = parseInt($("#channels").val(), 10),
  862. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  863. iStreamType = parseInt($("#record_streamtype").val(), 10),
  864. szStartTime = $("#starttime").val(),
  865. szEndTime = $("#endtime").val();
  866. if (Date.parse(szEndTime.replace(/-/g, "/")) - Date.parse(szStartTime.replace(/-/g, "/")) < 0) {
  867. alert("starttime must earlier than endtime");
  868. return;
  869. }
  870. if (null == szDeviceIdentify) {
  871. return;
  872. }
  873. if (bZeroChannel) {// zero-channel does not support record searching
  874. return;
  875. }
  876. if (0 == iType) {// search for the first time
  877. $("#searchlist").empty();
  878. iSearchTimes = 0;
  879. }
  880. WebVideoCtrl.I_RecordSearch(szDeviceIdentify, iChannelID, szStartTime, szEndTime, {
  881. iStreamType: iStreamType,
  882. iSearchPos: g_iSearchTimes * 40,
  883. success: function (xmlDoc) {
  884. if("MORE" === $(xmlDoc).find("responseStatusStrg").eq(0).text()) {
  885. for(var i = 0, nLen = $(xmlDoc).find("searchMatchItem").length; i < nLen; i++) {
  886. var szPlaybackURI = $(xmlDoc).find("playbackURI").eq(i).text();
  887. if(szPlaybackURI.indexOf("name=") < 0) {
  888. break;
  889. }
  890. var szStartTime = $(xmlDoc).find("startTime").eq(i).text();
  891. var szEndTime = $(xmlDoc).find("endTime").eq(i).text();
  892. var szFileName = szPlaybackURI.substring(szPlaybackURI.indexOf("name=") + 5, szPlaybackURI.indexOf("&size="));
  893. var objTr = $("#searchlist").get(0).insertRow(-1);
  894. var objTd = objTr.insertCell(0);
  895. objTd.id = "downloadTd" + i;
  896. objTd.innerHTML = g_iSearchTimes * 40 + (i + 1);
  897. objTd = objTr.insertCell(1);
  898. objTd.width = "30%";
  899. objTd.innerHTML = szFileName;
  900. objTd = objTr.insertCell(2);
  901. objTd.width = "30%";
  902. objTd.innerHTML = (szStartTime.replace("T", " ")).replace("Z", "");
  903. objTd = objTr.insertCell(3);
  904. objTd.width = "30%";
  905. objTd.innerHTML = (szEndTime.replace("T", " ")).replace("Z", "");
  906. objTd = objTr.insertCell(4);
  907. objTd.width = "10%";
  908. objTd.innerHTML = "<a href='javascript:;' onclick='clickStartDownloadRecord(" + (i + g_iSearchTimes * 40) + ");'>download</a>";
  909. $("#downloadTd" + (i + g_iSearchTimes * 40)).data("fileName", szFileName);
  910. $("#downloadTd" + (i + g_iSearchTimes * 40)).data("playbackURI", szPlaybackURI);
  911. }
  912. g_iSearchTimes++;
  913. clickRecordSearch(1);// contine to search
  914. } else if ("OK" === $(xmlDoc).find("responseStatusStrg").eq(0).text()) {
  915. var iLength = $(xmlDoc).find("searchMatchItem").length;
  916. for(var i = 0; i < iLength; i++) {
  917. var szPlaybackURI = $(xmlDoc).find("playbackURI").eq(i).text();
  918. if(szPlaybackURI.indexOf("name=") < 0) {
  919. break;
  920. }
  921. var szStartTime = $(xmlDoc).find("startTime").eq(i).text();
  922. var szEndTime = $(xmlDoc).find("endTime").eq(i).text();
  923. var szFileName = szPlaybackURI.substring(szPlaybackURI.indexOf("name=") + 5, szPlaybackURI.indexOf("&size="));
  924. var objTr = $("#searchlist").get(0).insertRow(-1);
  925. var objTd = objTr.insertCell(0);
  926. objTd.id = "downloadTd" + i;
  927. objTd.innerHTML = g_iSearchTimes * 40 + (i + 1);
  928. objTd = objTr.insertCell(1);
  929. objTd.width = "30%";
  930. objTd.innerHTML = szFileName;
  931. objTd = objTr.insertCell(2);
  932. objTd.width = "30%";
  933. objTd.innerHTML = (szStartTime.replace("T", " ")).replace("Z", "");
  934. objTd = objTr.insertCell(3);
  935. objTd.width = "30%";
  936. objTd.innerHTML = (szEndTime.replace("T", " ")).replace("Z", "");
  937. objTd = objTr.insertCell(4);
  938. objTd.width = "10%";
  939. objTd.innerHTML = "<a href='javascript:;' onclick='clickStartDownloadRecord(" + (i + g_iSearchTimes * 40) + ");'>download</a>";
  940. $("#downloadTd" + (i + g_iSearchTimes * 40)).data("fileName", szFileName);
  941. $("#downloadTd" + (i + g_iSearchTimes * 40)).data("playbackURI", szPlaybackURI);
  942. }
  943. showOPInfo(szDeviceIdentify + " search video file success!");
  944. } else if("NO MATCHES" === $(xmlDoc).find("responseStatusStrg").eq(0).text()) {
  945. setTimeout(function() {
  946. showOPInfo(szDeviceIdentify + " no record file!");
  947. }, 50);
  948. }
  949. },
  950. error: function (status, xmlDoc) {
  951. showOPInfo(szDeviceIdentify + " search record file failed!", status, xmlDoc);
  952. }
  953. });
  954. }
  955. // start play back
  956. function clickStartPlayback() {
  957. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  958. szDeviceIdentify = $("#ip").val(),
  959. iRtspPort = parseInt($("#rtspport").val(), 10),
  960. iStreamType = parseInt($("#record_streamtype").val(), 10),
  961. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  962. iChannelID = parseInt($("#channels").val(), 10),
  963. szStartTime = $("#starttime").val(),
  964. szEndTime = $("#endtime").val(),
  965. szInfo = "",
  966. bChecked = $("#transstream").prop("checked"),
  967. iRet = -1;
  968. if (null == szDeviceIdentify) {
  969. return;
  970. }
  971. if (bZeroChannel) {// zero-channel does not support play back
  972. return;
  973. }
  974. var startPlayback = function () {
  975. if (bChecked) {// enable transcode playback
  976. var oTransCodeParam = {
  977. TransFrameRate: "16",// 0:full,5:1,6:2,7:4,8:6,9:8,10:10,11:12,12:16,14:15,15:18,13:20,16:22
  978. TransResolution: "2",// 255:Auto,3:4CIF,2:QCIF,1:CIF
  979. TransBitrate: "23"// 2:32K,3:48K,4:64K,5:80K,6:96K,7:128K,8:160K,9:192K,10:224K,11:256K,12:320K,13:384K,14:448K,15:512K,16:640K,17:768K,18:896K,19:1024K,20:1280K,21:1536K,22:1792K,23:2048K,24:3072K,25:4096K,26:8192K
  980. };
  981. WebVideoCtrl.I_StartPlayback(szDeviceIdentify, {
  982. iRtspPort: iRtspPort,
  983. iStreamType: iStreamType,
  984. iChannelID: iChannelID,
  985. szStartTime: szStartTime,
  986. szEndTime: szEndTime,
  987. oTransCodeParam: oTransCodeParam,
  988. success: function () {
  989. szInfo = "start play back success!";
  990. showOPInfo(szDeviceIdentify + " " + szInfo);
  991. },
  992. error: function (status, xmlDoc) {
  993. if (403 === status) {
  994. szInfo = "Device do not support Websocket extracting the flow!";
  995. } else {
  996. szInfo = "start play back failed!";
  997. }
  998. showOPInfo(szDeviceIdentify + " " + szInfo);
  999. }
  1000. });
  1001. } else {
  1002. WebVideoCtrl.I_StartPlayback(szDeviceIdentify, {
  1003. iRtspPort: iRtspPort,
  1004. iStreamType: iStreamType,
  1005. iChannelID: iChannelID,
  1006. szStartTime: szStartTime,
  1007. szEndTime: szEndTime,
  1008. success: function () {
  1009. szInfo = "start play back success!";
  1010. showOPInfo(szDeviceIdentify + " " + szInfo);
  1011. },
  1012. error: function (status, xmlDoc) {
  1013. if (403 === status) {
  1014. szInfo = "Device do not support Websocket extracting the flow!";
  1015. } else {
  1016. szInfo = "start play back failed!";
  1017. }
  1018. showOPInfo(szDeviceIdentify + " " + szInfo);
  1019. }
  1020. });
  1021. }
  1022. };
  1023. if (oWndInfo != null) {// stop play first
  1024. WebVideoCtrl.I_Stop({
  1025. success: function () {
  1026. startPlayback();
  1027. }
  1028. });
  1029. } else {
  1030. startPlayback();
  1031. }
  1032. }
  1033. // stop play back
  1034. function clickStopPlayback() {
  1035. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1036. szInfo = "";
  1037. if (oWndInfo != null) {
  1038. WebVideoCtrl.I_Stop({
  1039. success: function () {
  1040. szInfo = "stop play back success!";
  1041. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1042. },
  1043. error: function () {
  1044. szInfo = "stop play back failed!";
  1045. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1046. }
  1047. });
  1048. }
  1049. }
  1050. // start reverse play
  1051. function clickReversePlayback() {
  1052. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1053. szDeviceIdentify = $("#ip").val(),
  1054. iRtspPort = parseInt($("#rtspport").val(), 10),
  1055. iStreamType = parseInt($("#record_streamtype").val(), 10),
  1056. bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false,
  1057. iChannelID = parseInt($("#channels").val(), 10),
  1058. szStartTime = $("#starttime").val(),
  1059. szEndTime = $("#endtime").val(),
  1060. szInfo = "";
  1061. if (null == szDeviceIdentify) {
  1062. return;
  1063. }
  1064. if (bZeroChannel) {// zero-channel does not support reverse play
  1065. return;
  1066. }
  1067. var reversePlayback = function () {
  1068. var iRet = WebVideoCtrl.I_ReversePlayback(szDeviceIdentify, {
  1069. iRtspPort: iRtspPort,
  1070. iStreamType: iStreamType,
  1071. iChannelID: iChannelID,
  1072. szStartTime: szStartTime,
  1073. szEndTime: szEndTime
  1074. });
  1075. if (0 == iRet) {
  1076. szInfo = "start reverse play success!";
  1077. } else {
  1078. szInfo = "start reverse play failed!";
  1079. }
  1080. showOPInfo(szDeviceIdentify + " " + szInfo);
  1081. };
  1082. if (oWndInfo != null) {// stop play first
  1083. WebVideoCtrl.I_Stop({
  1084. success: function () {
  1085. reversePlayback();
  1086. }
  1087. });
  1088. } else {
  1089. reversePlayback();
  1090. }
  1091. }
  1092. // single frame
  1093. function clickFrame() {
  1094. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1095. szInfo = "";
  1096. if (oWndInfo != null) {
  1097. WebVideoCtrl.I_Frame({
  1098. success: function () {
  1099. szInfo = "single frame play success!";
  1100. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1101. },
  1102. error: function () {
  1103. szInfo = "single frame play failed!";
  1104. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1105. }
  1106. });
  1107. }
  1108. }
  1109. // pause
  1110. function clickPause() {
  1111. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1112. szInfo = "";
  1113. if (oWndInfo != null) {
  1114. WebVideoCtrl.I_Pause({
  1115. success: function () {
  1116. szInfo = "pause success!";
  1117. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1118. },
  1119. error: function () {
  1120. szInfo = "pause failed!";
  1121. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1122. }
  1123. });
  1124. }
  1125. }
  1126. // resume
  1127. function clickResume() {
  1128. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1129. szInfo = "";
  1130. if (oWndInfo != null) {
  1131. WebVideoCtrl.I_Resume({
  1132. success: function () {
  1133. szInfo = "resume success!";
  1134. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1135. },
  1136. error: function () {
  1137. szInfo = "resume failed!";
  1138. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1139. }
  1140. });
  1141. }
  1142. }
  1143. // slow play
  1144. function clickPlaySlow() {
  1145. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1146. szInfo = "";
  1147. if (oWndInfo != null) {
  1148. WebVideoCtrl.I_PlaySlow({
  1149. success: function () {
  1150. szInfo = "slow play success!";
  1151. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1152. },
  1153. error: function () {
  1154. szInfo = "slow play failed!";
  1155. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1156. }
  1157. });
  1158. }
  1159. }
  1160. // fast play
  1161. function clickPlayFast() {
  1162. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex),
  1163. szInfo = "";
  1164. if (oWndInfo != null) {
  1165. WebVideoCtrl.I_PlayFast({
  1166. success: function () {
  1167. szInfo = "fast play success!";
  1168. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1169. },
  1170. error: function () {
  1171. szInfo = "fast play failed!";
  1172. showOPInfo(oWndInfo.szDeviceIdentify + " " + szInfo);
  1173. }
  1174. });
  1175. }
  1176. }
  1177. // OSD time
  1178. function clickGetOSDTime() {
  1179. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1180. if (oWndInfo != null) {
  1181. var szTime = WebVideoCtrl.I_GetOSDTime({
  1182. success: function (szOSDTime) {
  1183. $("#osdtime").val(szOSDTime);
  1184. showOPInfo(oWndInfo.szDeviceIdentify + " get OSD time success!");
  1185. },
  1186. error: function () {
  1187. showOPInfo(oWndInfo.szDeviceIdentify + " get OSD time failed!");
  1188. }
  1189. });
  1190. }
  1191. }
  1192. // download video
  1193. var g_iDownloadID = -1;
  1194. var g_tDownloadProcess = 0;
  1195. function clickStartDownloadRecord(i) {
  1196. var szDeviceIdentify = $("#ip").val(),
  1197. szChannelID = $("#channels").val(),
  1198. szFileName = $("#downloadTd" + i).data("fileName"),
  1199. szPlaybackURI = $("#downloadTd" + i).data("playbackURI");
  1200. if (null == szDeviceIdentify) {
  1201. return;
  1202. }
  1203. g_iDownloadID = WebVideoCtrl.I_StartDownloadRecord(szDeviceIdentify, szPlaybackURI, szFileName, {
  1204. bDateDir: true //generate the date file or not
  1205. });
  1206. if (g_iDownloadID < 0) {
  1207. var iErrorValue = WebVideoCtrl.I_GetLastError();
  1208. if (34 == iErrorValue) {
  1209. showOPInfo(szDeviceIdentify + " download already!");
  1210. } else if (33 == iErrorValue) {
  1211. showOPInfo(szDeviceIdentify + " lack of space!");
  1212. } else {
  1213. showOPInfo(szDeviceIdentify + " download failed!");
  1214. }
  1215. } else {
  1216. $("<div id='downProcess' class='freeze'></div>").appendTo("body");
  1217. g_tDownloadProcess = setInterval("downProcess(" + i + ")", 1000);
  1218. }
  1219. }
  1220. function clickStartDownloadRecordByTime() {
  1221. var szDeviceIdentify = $("#ip").val(),
  1222. szChannelID = $("#channels").val(),
  1223. szFileName = $("#downloadTd0").data("fileName"),
  1224. szPlaybackURI = $("#downloadTd0").data("playbackURI"),
  1225. szStartTime = $("#downloadstarttime").val(),
  1226. szEndTime = $("#downloadendtime").val();
  1227. if (null == szDeviceIdentify) {
  1228. return;
  1229. }
  1230. if (Date.parse(szEndTime.replace(/-/g, "/")) - Date.parse(szStartTime.replace(/-/g, "/")) < 0) {
  1231. alert("starttime must earlier than endtime");
  1232. return;
  1233. }
  1234. g_iDownloadID = WebVideoCtrl.I_StartDownloadRecordByTime(szDeviceIdentify, szPlaybackURI, szFileName, szStartTime,szEndTime,{
  1235. bDateDir: true //是否生成日期文件
  1236. });
  1237. if (g_iDownloadID < 0) {
  1238. var iErrorValue = WebVideoCtrl.I_GetLastError();
  1239. if (34 == iErrorValue) {
  1240. showOPInfo(szDeviceIdentify + " Downloaded");
  1241. } else if (33 == iErrorValue) {
  1242. showOPInfo(szDeviceIdentify + " No enough space");
  1243. } else {
  1244. showOPInfo(szDeviceIdentify + " Download Failed!");
  1245. }
  1246. } else {
  1247. $("<div id='downProcess' class='freeze'></div>").appendTo("body");
  1248. g_tDownloadProcess = setInterval("downProcess(" + 0 + ")", 1000);
  1249. }
  1250. }
  1251. // download process
  1252. function downProcess() {
  1253. var iStatus = WebVideoCtrl.I_GetDownloadStatus(g_iDownloadID);
  1254. if (0 == iStatus) {
  1255. $("#downProcess").css({
  1256. width: $("#searchlist").width() + "px",
  1257. height: "100px",
  1258. lineHeight: "100px",
  1259. left: $("#searchdiv").offset().left + "px",
  1260. top: $("#searchdiv").offset().top + "px"
  1261. });
  1262. var iProcess = WebVideoCtrl.I_GetDownloadProgress(g_iDownloadID);
  1263. if (iProcess < 0) {
  1264. clearInterval(g_tDownloadProcess);
  1265. g_tDownloadProcess = 0;
  1266. g_iDownloadID = -1;
  1267. } else if (iProcess < 100) {
  1268. $("#downProcess").text(iProcess + "%");
  1269. } else {
  1270. $("#downProcess").text("100%");
  1271. setTimeout(function () {
  1272. $("#downProcess").remove();
  1273. }, 1000);
  1274. WebVideoCtrl.I_StopDownloadRecord(g_iDownloadID);
  1275. showOPInfo("video dowload finish");
  1276. clearInterval(g_tDownloadProcess);
  1277. g_tDownloadProcess = 0;
  1278. g_iDownloadID = -1;
  1279. }
  1280. } else {
  1281. WebVideoCtrl.I_StopDownloadRecord(g_iDownloadID);
  1282. clearInterval(g_tDownloadProcess);
  1283. g_tDownloadProcess = 0;
  1284. g_iDownloadID = -1;
  1285. }
  1286. }
  1287. // export configuration file
  1288. function clickExportDeviceConfig() {
  1289. var szDeviceIdentify = $("#ip").val(),
  1290. szInfo = "";
  1291. if (null == szDeviceIdentify) {
  1292. return;
  1293. }
  1294. var szDevicePassWord = $("#edfpassword").val();
  1295. var iRet = WebVideoCtrl.I_ExportDeviceConfig(szDeviceIdentify,szDevicePassWord);
  1296. if (0 == iRet) {
  1297. szInfo = " export configuration file success!";
  1298. } else {
  1299. szInfo = " export configuration file failed!";
  1300. }
  1301. showOPInfo(szDeviceIdentify + " " + szInfo);
  1302. }
  1303. // import configuration file
  1304. function clickImportDeviceConfig() {
  1305. var szDeviceIdentify = $("#ip").val(),
  1306. szFileName = $("#configFile").val();
  1307. var szDevicePassWord= $("#edfpassword").val();
  1308. if (null == szDeviceIdentify) {
  1309. return;
  1310. }
  1311. if ("" == szFileName) {
  1312. alert("please select configuration file!");
  1313. return;
  1314. }
  1315. var iRet = WebVideoCtrl.I_ImportDeviceConfig(szDeviceIdentify, szFileName,szDevicePassWord);
  1316. if (0 == iRet) {
  1317. WebVideoCtrl.I_Restart(szDeviceIdentify, {
  1318. success: function (xmlDoc) {
  1319. $("<div id='restartDiv' class='freeze'>reboot...</div>").appendTo("body");
  1320. var oSize = getWindowSize();
  1321. $("#restartDiv").css({
  1322. width: oSize.width + "px",
  1323. height: oSize.height + "px",
  1324. lineHeight: oSize.height + "px",
  1325. left: 0,
  1326. top: 0
  1327. });
  1328. setTimeout("reconnect('" + szDeviceIdentify + "')", 20000);
  1329. },
  1330. error: function (status, xmlDoc) {
  1331. showOPInfo(szDeviceIdentify + " reboot failed!", status, xmlDoc);
  1332. }
  1333. });
  1334. } else {
  1335. showOPInfo(szDeviceIdentify + " export failed!");
  1336. }
  1337. }
  1338. // reconnection
  1339. function reconnect(szDeviceIdentify) {
  1340. WebVideoCtrl.I_Reconnect(szDeviceIdentify, {
  1341. success: function (xmlDoc) {
  1342. $("#restartDiv").remove();
  1343. },
  1344. error: function (status, xmlDoc) {
  1345. if (401 == status) {// no plug-in scheme,session invalid after restart,program log out,delete from the device which has logged in
  1346. $("#restartDiv").remove();
  1347. clickLogout();
  1348. } else {
  1349. setTimeout(function () {reconnect(szDeviceIdentify);}, 5000);
  1350. }
  1351. }
  1352. });
  1353. }
  1354. // start upgrade
  1355. var g_tUpgrade = 0;
  1356. function clickStartUpgrade(szDeviceIdentify) {
  1357. var szDeviceIdentify = $("#ip").val(),
  1358. szFileName = $("#upgradeFile").val();
  1359. if (null == szDeviceIdentify) {
  1360. return;
  1361. }
  1362. if ("" == szFileName) {
  1363. alert("please select upgrade file!");
  1364. return;
  1365. }
  1366. WebVideoCtrl.I2_StartUpgrade(szDeviceIdentify, szFileName).then(function(){
  1367. g_tUpgrade = setInterval("getUpgradeStatus('" + szDeviceIdentify + "')", 1000);
  1368. },function(){
  1369. showOPInfo(szDeviceIdentify + " upgrade failed!");
  1370. });
  1371. }
  1372. // get upgrade status
  1373. function getUpgradeStatus(szDeviceIdentify) {
  1374. var iStatus = WebVideoCtrl.I_UpgradeStatus();
  1375. if (iStatus == 0) {
  1376. var iProcess = WebVideoCtrl.I_UpgradeProgress();
  1377. if (iProcess < 0) {
  1378. clearInterval(g_tUpgrade);
  1379. g_tUpgrade = 0;
  1380. showOPInfo(szDeviceIdentify + " get process failed!");
  1381. return;
  1382. } else if (iProcess < 100) {
  1383. if (0 == $("#restartDiv").length) {
  1384. $("<div id='restartDiv' class='freeze'></div>").appendTo("body");
  1385. var oSize = getWindowSize();
  1386. $("#restartDiv").css({
  1387. width: oSize.width + "px",
  1388. height: oSize.height + "px",
  1389. lineHeight: oSize.height + "px",
  1390. left: 0,
  1391. top: 0
  1392. });
  1393. }
  1394. $("#restartDiv").text(iProcess + "%");
  1395. } else {
  1396. WebVideoCtrl.I_StopUpgrade();
  1397. clearInterval(g_tUpgrade);
  1398. g_tUpgrade = 0;
  1399. $("#restartDiv").remove();
  1400. WebVideoCtrl.I_Restart(szDeviceIdentify, {
  1401. success: function (xmlDoc) {
  1402. $("<div id='restartDiv' class='freeze'>reboot...</div>").appendTo("body");
  1403. var oSize = getWindowSize();
  1404. $("#restartDiv").css({
  1405. width: oSize.width + "px",
  1406. height: oSize.height + "px",
  1407. lineHeight: oSize.height + "px",
  1408. left: 0,
  1409. top: 0
  1410. });
  1411. setTimeout("reconnect('" + szDeviceIdentify + "')", 20000);
  1412. },
  1413. error: function (status, xmlDoc) {
  1414. showOPInfo(szDeviceIdentify + " reboot failed!", status, xmlDoc);
  1415. }
  1416. });
  1417. }
  1418. } else if (iStatus == 1) {
  1419. WebVideoCtrl.I_StopUpgrade();
  1420. showOPInfo(szDeviceIdentify + " upgrade failed!");
  1421. clearInterval(g_tUpgrade);
  1422. g_tUpgrade = 0;
  1423. } else if (iStatus == 2) {
  1424. WebVideoCtrl.I_StopUpgrade();
  1425. showOPInfo(szDeviceIdentify + " language does not match!");
  1426. clearInterval(g_tUpgrade);
  1427. g_tUpgrade = 0;
  1428. } else {
  1429. WebVideoCtrl.I_StopUpgrade();
  1430. showOPInfo(szDeviceIdentify + " get status failed!");
  1431. clearInterval(g_tUpgrade);
  1432. g_tUpgrade = 0;
  1433. }
  1434. }
  1435. // check plugin version
  1436. function clickCheckPluginVersion() {
  1437. var iRet = WebVideoCtrl.I_CheckPluginVersion();
  1438. if (0 == iRet) {
  1439. alert("your plugin version is the latest!");
  1440. } else {
  1441. alert("detect the latest plugin version!");
  1442. }
  1443. }
  1444. // remote configuration library
  1445. function clickRemoteConfig() {
  1446. var szDeviceIdentify = $("#ip").val(),
  1447. iDevicePort = parseInt($("#deviceport").val(), 10) || "",
  1448. szInfo = "";
  1449. if (null == szDeviceIdentify) {
  1450. return;
  1451. }
  1452. var iRet = WebVideoCtrl.I_RemoteConfig(szDeviceIdentify, {
  1453. iDevicePort: iDevicePort,
  1454. iLan: 0
  1455. });
  1456. if (-1 == iRet) {
  1457. szInfo = "call remote configuration library failed!";
  1458. } else {
  1459. szInfo = "call remote configuration library success!";
  1460. }
  1461. showOPInfo(szDeviceIdentify + " " + szInfo);
  1462. }
  1463. function clickRestoreDefault() {
  1464. var szDeviceIdentify = $("#ip").val(),
  1465. szMode = "basic";
  1466. WebVideoCtrl.I_RestoreDefault(szDeviceIdentify, szMode, {
  1467. timeout: 30000,
  1468. success: function (xmlDoc) {
  1469. $("#restartDiv").remove();
  1470. showOPInfo(szDeviceIdentify + " restore default success!");
  1471. //reboot after restore
  1472. WebVideoCtrl.I_Restart(szDeviceIdentify, {
  1473. success: function (xmlDoc) {
  1474. $("<div id='restartDiv' class='freeze'>reboot...</div>").appendTo("body");
  1475. var oSize = getWindowSize();
  1476. $("#restartDiv").css({
  1477. width: oSize.width + "px",
  1478. height: oSize.height + "px",
  1479. lineHeight: oSize.height + "px",
  1480. left: 0,
  1481. top: 0
  1482. });
  1483. setTimeout("reconnect('" + szDeviceIdentify + "')", 20000);
  1484. },
  1485. error: function (status, xmlDoc) {
  1486. showOPInfo(szDeviceIdentify + " reboot failed!", status, xmlDoc);
  1487. }
  1488. });
  1489. },
  1490. error: function (status, xmlDoc) {
  1491. showOPInfo(szDeviceIdentify + " restore default failed!", status, xmlDoc);
  1492. }
  1493. });
  1494. }
  1495. function PTZZoomIn() {
  1496. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1497. if (oWndInfo != null) {
  1498. WebVideoCtrl.I_PTZControl(10, false, {
  1499. iWndIndex: g_iWndIndex,
  1500. success: function (xmlDoc) {
  1501. showOPInfo(oWndInfo.szDeviceIdentify + " Zoom+success!");
  1502. },
  1503. error: function (status, xmlDoc) {
  1504. showOPInfo(oWndInfo.szDeviceIdentify + " Zoom+failed!", status, xmlDoc);
  1505. }
  1506. });
  1507. }
  1508. }
  1509. function PTZZoomout() {
  1510. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1511. if (oWndInfo != null) {
  1512. WebVideoCtrl.I_PTZControl(11, false, {
  1513. iWndIndex: g_iWndIndex,
  1514. success: function (xmlDoc) {
  1515. showOPInfo(oWndInfo.szDeviceIdentify + " Zoom-success!");
  1516. },
  1517. error: function (status, xmlDoc) {
  1518. showOPInfo(oWndInfo.szDeviceIdentify + " Zoom-failed!", status, xmlDoc);
  1519. }
  1520. });
  1521. }
  1522. }
  1523. function PTZZoomStop() {
  1524. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1525. if (oWndInfo != null) {
  1526. WebVideoCtrl.I_PTZControl(11, true, {
  1527. iWndIndex: g_iWndIndex,
  1528. success: function (xmlDoc) {
  1529. showOPInfo(oWndInfo.szDeviceIdentify + " stop zoom success!");
  1530. },
  1531. error: function (status, xmlDoc) {
  1532. showOPInfo(oWndInfo.szDeviceIdentify + " stop zoom failed!", status, xmlDoc);
  1533. }
  1534. });
  1535. }
  1536. }
  1537. function PTZFocusIn() {
  1538. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1539. if (oWndInfo != null) {
  1540. WebVideoCtrl.I_PTZControl(12, false, {
  1541. iWndIndex: g_iWndIndex,
  1542. success: function (xmlDoc) {
  1543. showOPInfo(oWndInfo.szDeviceIdentify + " focus+success!");
  1544. },
  1545. error: function (status, xmlDoc) {
  1546. showOPInfo(oWndInfo.szDeviceIdentify + " focus+failed!", status, xmlDoc);
  1547. }
  1548. });
  1549. }
  1550. }
  1551. function PTZFoucusOut() {
  1552. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1553. if (oWndInfo != null) {
  1554. WebVideoCtrl.I_PTZControl(13, false, {
  1555. iWndIndex: g_iWndIndex,
  1556. success: function (xmlDoc) {
  1557. showOPInfo(oWndInfo.szDeviceIdentify + " focus-success!");
  1558. },
  1559. error: function (status, xmlDoc) {
  1560. showOPInfo(oWndInfo.szDeviceIdentify + " focus-failed!", status, xmlDoc);
  1561. }
  1562. });
  1563. }
  1564. }
  1565. function PTZFoucusStop() {
  1566. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1567. if (oWndInfo != null) {
  1568. WebVideoCtrl.I_PTZControl(12, true, {
  1569. iWndIndex: g_iWndIndex,
  1570. success: function (xmlDoc) {
  1571. showOPInfo(oWndInfo.szDeviceIdentify + " stop focus success!");
  1572. },
  1573. error: function (status, xmlDoc) {
  1574. showOPInfo(oWndInfo.szDeviceIdentify + " stop focus failed!", status, xmlDoc);
  1575. }
  1576. });
  1577. }
  1578. }
  1579. function PTZIrisIn() {
  1580. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1581. if (oWndInfo != null) {
  1582. WebVideoCtrl.I_PTZControl(14, false, {
  1583. iWndIndex: g_iWndIndex,
  1584. success: function (xmlDoc) {
  1585. showOPInfo(oWndInfo.szDeviceIdentify + " Iris+success!");
  1586. },
  1587. error: function (status, xmlDoc) {
  1588. showOPInfo(oWndInfo.szDeviceIdentify + " Iris+failed!", status, xmlDoc);
  1589. }
  1590. });
  1591. }
  1592. }
  1593. function PTZIrisOut() {
  1594. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1595. if (oWndInfo != null) {
  1596. WebVideoCtrl.I_PTZControl(15, false, {
  1597. iWndIndex: g_iWndIndex,
  1598. success: function (xmlDoc) {
  1599. showOPInfo(oWndInfo.szDeviceIdentify + " Iris-success!");
  1600. },
  1601. error: function (status, xmlDoc) {
  1602. showOPInfo(oWndInfo.szDeviceIdentify + " Iris-failed!", status, xmlDoc);
  1603. }
  1604. });
  1605. }
  1606. }
  1607. function PTZIrisStop() {
  1608. var oWndInfo = WebVideoCtrl.I_GetWindowStatus(g_iWndIndex);
  1609. if (oWndInfo != null) {
  1610. WebVideoCtrl.I_PTZControl(14, true, {
  1611. iWndIndex: g_iWndIndex,
  1612. success: function (xmlDoc) {
  1613. showOPInfo(oWndInfo.szDeviceIdentify + " stop Iris success!");
  1614. },
  1615. error: function (status, xmlDoc) {
  1616. showOPInfo(oWndInfo.szDeviceIdentify + " stop Iris failed!", status, xmlDoc);
  1617. }
  1618. });
  1619. }
  1620. }
  1621. // change mode
  1622. function changeIPMode(iType) {
  1623. var arrPort = [0, 7071, 80];
  1624. $("#serverport").val(arrPort[iType]);
  1625. }
  1626. // get device ip
  1627. function clickGetDeviceIP() {
  1628. var iDeviceMode = parseInt($("#devicemode").val(), 10),
  1629. szAddress = $("#serveraddress").val(),
  1630. iPort = parseInt($("#serverport").val(), 10) || 0,
  1631. szDeviceID = $("#deviceid").val(),
  1632. szDeviceInfo = "";
  1633. szDeviceInfo = WebVideoCtrl.I_GetIPInfoByMode(iDeviceMode, szAddress, iPort, szDeviceID);
  1634. if ("" == szDeviceInfo) {
  1635. showOPInfo("get device ip failed!");
  1636. } else {
  1637. showOPInfo("get device ip success!");
  1638. var arrTemp = szDeviceInfo.split("-");
  1639. $("#loginip").val(arrTemp[0]);
  1640. $("#deviceport").val(arrTemp[1]);
  1641. }
  1642. }
  1643. // polygon drawing enabled
  1644. var g_bEnableDraw = false;
  1645. function clickEnableDraw() {
  1646. var iRet = WebVideoCtrl.I_SetPlayModeType(6);// polygon pattern
  1647. if (0 === iRet) {
  1648. g_bEnableDraw = true;
  1649. showOPInfo("drawing enabled succeed!");
  1650. } else {
  1651. showOPInfo("drawing enabled failed!");
  1652. }
  1653. }
  1654. // polygon drawing disabled
  1655. function clickDisableDraw() {
  1656. var iRet = WebVideoCtrl.I_SetPlayModeType(0);// preview pattern
  1657. if (0 === iRet) {
  1658. g_bEnableDraw = false;
  1659. showOPInfo("drawing disabled success!");
  1660. } else {
  1661. showOPInfo("drawing disabled failed!");
  1662. }
  1663. }
  1664. // add the graph
  1665. function clickAddSnapPolygon() {
  1666. if (!g_bEnableDraw) {
  1667. return;
  1668. }
  1669. var szId = $("#snapId").val();
  1670. var szName = encodeString($("#snapName").val());
  1671. var szInfo = "<?xml version='1.0' encoding='utf-8'?>";
  1672. szInfo += "<SnapPolygonList>";
  1673. szInfo += "<SnapPolygon>";
  1674. szInfo += "<id>" + szId + "</id>"; // [1, 32]
  1675. szInfo += "<polygonType>1</polygonType>";
  1676. szInfo += "<PointNumMax>17</PointNumMax>"; // [MinClosed, 17]
  1677. szInfo += "<MinClosed>4</MinClosed>"; // [4, 17]
  1678. szInfo += "<tips>#" + szId + "#" + szName + "</tips>";
  1679. szInfo += "<isClosed>false</isClosed>";
  1680. szInfo += "<color><r>0</r><g>255</g><b>0</b></color>";
  1681. szInfo += "<pointList/>";
  1682. szInfo += "</SnapPolygon>";
  1683. szInfo += "</SnapPolygonList>";
  1684. var iRet = WebVideoCtrl.I_SetSnapPolygonInfo(g_iWndIndex, szInfo);
  1685. if (0 === iRet) {
  1686. showOPInfo("window " + g_iWndIndex + " add graph succeed!");
  1687. } else if (-1 === iRet) {
  1688. showOPInfo("window " + g_iWndIndex + " add graph failed!");
  1689. } else if (-2 === iRet) {
  1690. alert("Parameter error!");
  1691. } else if (-3 === iRet) {
  1692. alert("The number of grapg reaches the ceiling!");
  1693. } else if (-4 === iRet) {
  1694. alert("Graph ID has existed!");
  1695. }
  1696. WebVideoCtrl.I_SetSnapDrawMode(g_iWndIndex, 2);
  1697. }
  1698. // delete the graph
  1699. function clickDelSnapPolygon() {
  1700. if (!g_bEnableDraw) {
  1701. return;
  1702. }
  1703. var szId = $("#snapId").val();
  1704. var iIndex = getSnapPolygon(szId);
  1705. if (iIndex != -1) {
  1706. var oXML = getSnapPolygon();
  1707. $(oXML).find("SnapPolygon").eq(iIndex).remove();
  1708. var szInfo = toXMLStr(oXML);
  1709. WebVideoCtrl.I_ClearSnapInfo(g_iWndIndex);
  1710. WebVideoCtrl.I2_SetSnapPolygonInfo(g_iWndIndex, szInfo);
  1711. WebVideoCtrl.I_SetSnapDrawMode(g_iWndIndex, 3);
  1712. } else {
  1713. alert("Graph ID do not exist!");
  1714. }
  1715. }
  1716. // edit the graph
  1717. function clickEditSnapPolygon() {
  1718. if (!g_bEnableDraw) {
  1719. return;
  1720. }
  1721. var iRet = WebVideoCtrl.I_SetSnapDrawMode(g_iWndIndex, 3);
  1722. if (0 === iRet) {
  1723. showOPInfo("window " + g_iWndIndex + " edit graph succeed!");
  1724. } else {
  1725. showOPInfo("window " + g_iWndIndex + " edit graph failed!");
  1726. }
  1727. }
  1728. // stop editing
  1729. function clickStopSnapPolygon() {
  1730. if (!g_bEnableDraw) {
  1731. return;
  1732. }
  1733. var iRet = WebVideoCtrl.I_SetSnapDrawMode(g_iWndIndex, -1);
  1734. if (0 === iRet) {
  1735. showOPInfo("window " + g_iWndIndex + " stop editing succeed!");
  1736. } else {
  1737. showOPInfo("window " + g_iWndIndex + " stop editing failed!");
  1738. }
  1739. }
  1740. function getSnapPolygon(szId) {
  1741. var szInfo = WebVideoCtrl.I_GetSnapPolygonInfo(g_iWndIndex);
  1742. var oXML = loadXML(szInfo);
  1743. if (typeof szId === "undefined") {
  1744. return oXML;
  1745. } else {
  1746. var iIndex = -1;
  1747. var aNodeList = $(oXML).find("SnapPolygon");
  1748. if (aNodeList.length > 0) {
  1749. $.each(aNodeList, function (i) {
  1750. if ($(this).find("id").text() === szId) {
  1751. iIndex = i;
  1752. return false;
  1753. }
  1754. });
  1755. }
  1756. return iIndex;
  1757. }
  1758. }
  1759. // gain the graph,save to own database
  1760. function clickGetSnapPolygon() {
  1761. if (!g_bEnableDraw) {
  1762. return;
  1763. }
  1764. var szInfo = WebVideoCtrl.I_GetSnapPolygonInfo(g_iWndIndex);
  1765. alert(szInfo);
  1766. }
  1767. // set the graph,you can set the graph which has been set before when opening the page
  1768. function clickSetSnapPolygon() {
  1769. if (!g_bEnableDraw) {
  1770. return;
  1771. }
  1772. WebVideoCtrl.I_ClearSnapInfo(g_iWndIndex);
  1773. var szInfo = "<?xml version='1.0' encoding='utf-8'?>";
  1774. szInfo += "<SnapPolygonList>";
  1775. szInfo += "<SnapPolygon>";
  1776. szInfo += "<id>1</id>";
  1777. szInfo += "<polygonType>1</polygonType>";
  1778. szInfo += "<tips>#1#Set1</tips>";
  1779. szInfo += "<isClosed>true</isClosed>";
  1780. szInfo += "<color><r>0</r><g>255</g><b>0</b></color>";
  1781. szInfo += "<pointList>";
  1782. szInfo += "<point><x>0.737903</x><y>0.229730</y></point>";
  1783. szInfo += "<point><x>0.947581</x><y>0.804054</y></point>";
  1784. szInfo += "<point><x>0.362903</x><y>0.777027</y></point>";
  1785. szInfo += "</pointList>";
  1786. szInfo += "</SnapPolygon>";
  1787. szInfo += "<SnapPolygon>";
  1788. szInfo += "<id>2</id>";
  1789. szInfo += "<polygonType>1</polygonType>";
  1790. szInfo += "<tips>#2#Set2</tips>";
  1791. szInfo += "<isClosed>true</isClosed>";
  1792. szInfo += "<color><r>0</r><g>255</g><b>0</b></color>";
  1793. szInfo += "<pointList>";
  1794. szInfo += "<point><x>0.451613</x><y>0.216216</y></point>";
  1795. szInfo += "<point><x>0.447581</x><y>0.729730</y></point>";
  1796. szInfo += "<point><x>0.116935</x><y>0.554054</y></point>";
  1797. szInfo += "</pointList>";
  1798. szInfo += "</SnapPolygon>";
  1799. szInfo += "</SnapPolygonList>";
  1800. var iRet = WebVideoCtrl.I2_SetSnapPolygonInfo(g_iWndIndex, szInfo);
  1801. if (0 === iRet) {
  1802. showOPInfo("window " + g_iWndIndex + " set the graph succeed!");
  1803. } else if (-1 === iRet) {
  1804. showOPInfo("window " + g_iWndIndex + " set the graph failed!");
  1805. } else if (-2 === iRet) {
  1806. alert("Parameter error!");
  1807. } else if (-3 === iRet) {
  1808. alert("The number of grapg reaches the ceiling!");
  1809. } else if (-4 === iRet) {
  1810. alert("Graph ID has existed!");
  1811. }
  1812. }
  1813. // clear the graph
  1814. function clickDelAllSnapPolygon() {
  1815. if (!g_bEnableDraw) {
  1816. return;
  1817. }
  1818. var iRet = WebVideoCtrl.I_ClearSnapInfo(g_iWndIndex);
  1819. if (0 === iRet) {
  1820. showOPInfo("window " + g_iWndIndex + " empty the graph succeed!");
  1821. } else {
  1822. showOPInfo("window " + g_iWndIndex + " empty the graph failed!");
  1823. }
  1824. }
  1825. // device capturing
  1826. function clickDeviceCapturePic() {
  1827. var szInfo = "";
  1828. var szDeviceIdentify = $("#ip").val();
  1829. var bZeroChannel = $("#channels option").eq($("#channels").get(0).selectedIndex).attr("bZero") == "true" ? true : false;
  1830. var iChannelID = parseInt($("#channels").val(), 10);
  1831. var iResolutionWidth = parseInt($("#resolutionWidth").val(), 10);
  1832. var iResolutionHeight = parseInt($("#resolutionHeight").val(), 10);
  1833. if (null == szDeviceIdentify) {
  1834. return;
  1835. }
  1836. if (bZeroChannel) {// zero channel do not support device capturing
  1837. return;
  1838. }
  1839. var szPicName = szDeviceIdentify + "_" + iChannelID + "_" + new Date().getTime();
  1840. var iRet = WebVideoCtrl.I_DeviceCapturePic(szDeviceIdentify, iChannelID, szPicName, {
  1841. bDateDir: true, //generate the date file or not
  1842. iResolutionWidth: iResolutionWidth,
  1843. iResolutionHeight: iResolutionHeight
  1844. });
  1845. if (0 == iRet) {
  1846. szInfo = "device capturing succeed!";
  1847. } else {
  1848. szInfo = "device capturing failed!";
  1849. }
  1850. showOPInfo(szDeviceIdentify + " " + szInfo);
  1851. }
  1852. function loadXML(szXml) {
  1853. if(null == szXml || "" == szXml) {
  1854. return null;
  1855. }
  1856. var oXmlDoc = null;
  1857. if (window.DOMParser) {
  1858. var oParser = new DOMParser();
  1859. oXmlDoc = oParser.parseFromString(szXml, "text/xml");
  1860. } else {
  1861. oXmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  1862. oXmlDoc.async = false;
  1863. oXmlDoc.loadXML(szXml);
  1864. }
  1865. return oXmlDoc;
  1866. }
  1867. function toXMLStr(oXmlDoc) {
  1868. var szXmlDoc = "";
  1869. try {
  1870. var oSerializer = new XMLSerializer();
  1871. szXmlDoc = oSerializer.serializeToString(oXmlDoc);
  1872. } catch (e) {
  1873. try {
  1874. szXmlDoc = oXmlDoc.xml;
  1875. } catch (e) {
  1876. return "";
  1877. }
  1878. }
  1879. if (szXmlDoc.indexOf("<?xml") == -1) {
  1880. szXmlDoc = "<?xml version='1.0' encoding='utf-8'?>" + szXmlDoc;
  1881. }
  1882. return szXmlDoc;
  1883. }
  1884. function encodeString(str) {
  1885. if (str) {
  1886. return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1887. } else {
  1888. return "";
  1889. }
  1890. }