guide.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. var CONST = {
  2. DeployStep_Begin : 0,
  3. DeployStep_GetTerminalInfo : 1,
  4. DeployStep_FetchCenterSettings : 2,
  5. DeployStep_AccessAuthorize : 3,
  6. DeployStep_MediaConfig : 4,
  7. DeployStep_Finished : 5
  8. };
  9. var MEDIA_TYPE = {
  10. CAMERA : 1,
  11. MICROPHONE : 2,
  12. LOUNDSPEAKER:4
  13. }
  14. var MEDIA_DETAIL_TYPE = {
  15. MediaDev_OutSpeaker:1,
  16. MediaDev_InSpeaker:2,
  17. MediaDev_OutMicrophone:3,
  18. MediaDev_InMicrophone:4
  19. }
  20. var VENDOR = {
  21. KEBA : 'KEBA',
  22. CW : 'CW',
  23. GRG : 'GRG',
  24. NANTIAN : 'NANTIAN',
  25. GWI : 'GWI'
  26. };
  27. $(function () {
  28. RVC.GuideController = RVC.Object.extend({
  29. hideAllPage: function () {
  30. $('#guide_start_page').hide();
  31. $('#guide_initparam_page').hide();
  32. $('#guide_sync_centersetting_page').hide();
  33. $('#guide_access_authorize_page').hide();
  34. $('#guide_media_config_page').hide();
  35. $('#guide_finish_page').hide();
  36. },
  37. resizeWindow: function () {
  38. var winHei = $(window).height();
  39. var popHeight = 480;
  40. var adjustHeight = 0;
  41. var blueBackgroundHeight = 0;
  42. if (winHei < 860) {
  43. winHei = 860;
  44. }
  45. blueBackgroundHeight = winHei - $('.headcontainer').height() - $('#page_footer').height();
  46. $('#guide_height').height(blueBackgroundHeight);
  47. adjustHeight = (blueBackgroundHeight - popHeight) * 0.5;
  48. $('#guide_start_page').css('padding-top', (adjustHeight + 100) + 'px');
  49. var domWidth = $('body').width();
  50. var winWidth = $('window').width();
  51. if (domWidth > winWidth) {
  52. setTimeout(function () {
  53. $('body').scrollTop($('.headcontainer').height() + adjustHeight);
  54. $('body').scrollLeft(($('body').width() - $(window).width()) / 2);
  55. }, 1000)
  56. }
  57. $('#guide_initparam_page').css('padding-top', adjustHeight + 'px');
  58. },
  59. beginInstall: function() {
  60. this.gotoPage(CONST.DeployStep_GetTerminalInfo);
  61. },
  62. gotoPage: function(nextStep) {
  63. var select_page = '';
  64. switch(nextStep) {
  65. case CONST.DeployStep_Begin:
  66. select_page = 'guide_start_page';
  67. break;
  68. case CONST.DeployStep_GetTerminalInfo :
  69. select_page = 'guide_initparam_page';
  70. break;
  71. case CONST.DeployStep_FetchCenterSettings:
  72. select_page = 'guide_sync_centersetting_page';
  73. break;
  74. case CONST.DeployStep_AccessAuthorize :
  75. select_page = 'guide_access_authorize_page';
  76. break;
  77. case CONST.DeployStep_MediaConfig :
  78. select_page = 'guide_media_config_page';
  79. break;
  80. case CONST.DeployStep_Finished :
  81. select_page = 'guide_finish_page';
  82. break;
  83. default:
  84. break;
  85. }
  86. if(select_page !== '') {
  87. this.hideAllPage();
  88. $('#' + select_page).show();
  89. } else {
  90. utilShowToast('无法识别步骤标识:' + nextStep, 3000);
  91. }
  92. },
  93. sectOverPass: function() {
  94. },
  95. sectNext: function() {
  96. }
  97. });
  98. RVC.CameraConfigEntity = RVC.EntityController.extend({
  99. entityName: 'CameraConfigManage',
  100. className: 'CameraConfigManageService',
  101. methodID: {
  102. GetMediaAvailableList: 9,
  103. SetMediaDevice: 10,
  104. TestAvailableMedieDev: 11
  105. },
  106. methodSignature: {
  107. GetMediaAvailableList: -1547834445,
  108. SetMediaDevice: -865058557,
  109. TestAvailableMedieDev: -2126935432
  110. },
  111. GetMediaAvailableList: function(req, callback) {
  112. this.webSocketInvokeEx(req,
  113. ({id:this.methodID.GetMediaAvailableList, sig:this.methodSignature.GetMediaAvailableList}),
  114. callback);
  115. },
  116. SetMediaDevice: function(req, callback) {
  117. this.webSocketInvokeEx(req,
  118. ({id:this.methodID.SetMediaDevice, sig:this.methodSignature.SetMediaDevice}),
  119. callback);
  120. },
  121. TestAvailableMedieDev: function(req, callback) {
  122. this.webSocketInvokeEx(req,
  123. ({id:this.methodID.TestAvailableMedieDev, sig:this.methodSignature.TestAvailableMedieDev}),
  124. callback);
  125. }
  126. });
  127. function IPConnectableTest(ip)
  128. {
  129. let req = new Request();
  130. req.protocol = 1; //Ping
  131. req.ip = ip;
  132. req.port = 0;
  133. req.reserved1 = 0;
  134. req.reserved2 = '';
  135. function showErrTips(val) {
  136. setTimeout(function () {
  137. $('#text_guide_initparam_ip_tips').addClass('hide');
  138. }, 3000);
  139. $('#text_guide_initparam_ip_tips').removeClass('hide')
  140. .removeClass('guide_input_descript').addClass('guide_error').html(val);
  141. }
  142. function showSuccTips(val) {
  143. setTimeout(function () {
  144. $('#text_guide_initparam_ip_tips').addClass('hide');
  145. }, 3000);
  146. $('#text_guide_initparam_ip_tips').removeClass('hide')
  147. .removeClass('guide_error').addClass('guide_input_descript').html(val);
  148. }
  149. if(!isValidIpAddress(ip)) {
  150. showErrTips('无效IP格式');
  151. return;
  152. }
  153. RVC.DeviceControlEntityCtrl.TestConnectivity(req, function(ret) {
  154. if(ret.errorCode === 0) {
  155. console.log('Ping 返回成功');
  156. let result = JSON.parse(ret[RVC.EntityController.sigResponseUUID])
  157. if(result.result == 0) {
  158. console.log(ip + ' 可正常连通');
  159. showSuccTips('可正常连通');
  160. } else {
  161. console.log(result.additionalMsg);
  162. showErrTips(result.additionalMsg);
  163. }
  164. } else {
  165. let tips = ip + ' 测试连接失败:' + ErrorCodeStringfy(ret.errorCode);
  166. console.error(tips);
  167. showErrTips(tips);
  168. }
  169. });
  170. }
  171. function DeployTerminalWithIPAndPort(server_ip, port, access_flag)
  172. {
  173. let req = new Request();
  174. if(!access_flag) {//下载集中配置
  175. req.currStep = CONST.DeployStep_FetchCenterSettings;
  176. req.preStep = CONST.DeployStep_GetTerminalInfo;
  177. //test
  178. req.nextStep = CONST.DeployStep_MediaConfig; //CONST.DeployStep_AccessAuthorize;
  179. } else {
  180. req.currStep = CONST.DeployStep_AccessAuthorize;
  181. req.preStep = CONST.DeployStep_FetchCenterSettings;
  182. req.nextStep = CONST.DeployStep_MediaConfig;
  183. }
  184. req.param1 = parseInt(port, 10);
  185. req.param2 = 0;
  186. req.param3 = server_ip;
  187. req.param4 = '';
  188. req.param5 = '';
  189. req.array1 = [0];
  190. req.array2 = [''];
  191. utilStartSubmitDialog();
  192. RVC.HealthmanagerEntityCtrl.DeployTerminal(req, function(ret) {
  193. utilStopSubmitDialog();
  194. if(ret.errorCode === 0) {
  195. let result = JSON.parse(ret[RVC.EntityController.sigResponseUUID])
  196. if(result.result == 0) {
  197. utilStartAlertDialog("操作成功", function() {
  198. RVC.GuideController.gotoPage(result.nextStep);
  199. });
  200. } else {
  201. utilStartAlertDialog("操作失败:[" + result.result + "] " + result.additionalMsg);
  202. }
  203. } else {
  204. RVC.HealthmanagerEntityCtrl.commErrorCallback(ret);
  205. }
  206. });
  207. }
  208. function InitTemrinalAbout(server_ip, new_terminalno, vendorName)
  209. {
  210. let req = new Request();
  211. req.currStep = CONST.DeployStep_GetTerminalInfo;
  212. req.preStep = CONST.DeployStep_Begin;
  213. req.nextStep = CONST.DeployStep_FetchCenterSettings;
  214. req.param1 = 0;
  215. req.param2 = 0;
  216. req.param3 = server_ip;
  217. req.param4 = new_terminalno + '|' + vendorName;
  218. req.param5 = '';
  219. req.array1 = [0];
  220. req.array2 = [''];
  221. utilStartSubmitDialog();
  222. RVC.HealthmanagerEntityCtrl.DeployTerminal(req, function(ret) {
  223. utilStopSubmitDialog();
  224. if(ret.errorCode === 0) {
  225. let result = JSON.parse(ret[RVC.EntityController.sigResponseUUID])
  226. if(result.result == 0) {
  227. utilStartAlertDialog("操作成功", function() {
  228. RVC.GuideController.gotoPage(result.nextStep);
  229. });
  230. } else {
  231. utilStartAlertDialog("操作失败:[" + result.result + "] " + result.additionalMsg);
  232. }
  233. } else {
  234. RVC.HealthmanagerEntityCtrl.commErrorCallback(ret);
  235. }
  236. });
  237. }
  238. function PreDeployTerminalWithIPAndPort(server_ip, port, access_flag)
  239. {
  240. if(!isValidIpAddress(server_ip)) {
  241. utilStartAlertDialog("无效IP格式");
  242. return;
  243. }
  244. if(!check_port(port)) {
  245. utilStartAlertDialog("无效端口号");
  246. return;
  247. }
  248. DeployTerminalWithIPAndPort(server_ip, port, access_flag);
  249. }
  250. function DownloadCenterSetting(ip, port)
  251. {
  252. PreDeployTerminalWithIPAndPort(ip, port, false);
  253. }
  254. function AuthorizeTerminal(ip, port)
  255. {
  256. PreDeployTerminalWithIPAndPort(ip, port, true);
  257. }
  258. function generateDeviceSelect(devices, select_id) {
  259. var deviceLength = 0;
  260. if ((devices) instanceof Array) {
  261. deviceLength = devices.length;
  262. } else {
  263. deviceLength = 1
  264. }
  265. var devicesHtml = '';
  266. var selectid = select_id;
  267. $('#' + selectid).empty();
  268. for (var loop = 0; loop < deviceLength; loop++) {
  269. var cur = devices[loop];
  270. var deviceTemplateData = {
  271. loop: loop,
  272. deviceName : cur,
  273. type: selectid
  274. };
  275. var pushHtml = '';
  276. pushHtml = '<div id="{{type}}_item_{{loop}}" option="{{deviceName}}" class="select_medium hide_with_ellipsis">'
  277. pushHtml += '{{deviceName}}</div>'
  278. $('#' + selectid).secureAppend(pushHtml, deviceTemplateData);
  279. }
  280. }
  281. function FulfillMediaDeviceList(flag)
  282. {
  283. let req = new Request();
  284. req.type = 6; //不需要摄像头配置
  285. req.interest = 0;
  286. req.reserverd1 = 0;
  287. req.reserverd2 = '';
  288. req.reserverd2 = '';
  289. RVC.CameraConfigEntity.GetMediaAvailableList(req, function(ret) {
  290. if(ret.errorCode === 0) {
  291. let result = JSON.parse(ret[RVC.EntityController.sigResponseUUID])
  292. console.log('device count: ' + result.result);
  293. var microphones = [];
  294. var loundspeakers = [];
  295. var cameras = [];
  296. for (var n = 0; n < result.AvailableList.length; n++) {
  297. console.log(result.AvailableList[n] + ' ' + result.ListItemType[n] + ' ' + result.ListItemStatus[n]);
  298. if(result.ListItemType[n] == MEDIA_TYPE.MICROPHONE) {
  299. microphones.push(result.AvailableList[n]);
  300. } else if(result.ListItemType[n] == MEDIA_TYPE.LOUNDSPEAKER) {
  301. loundspeakers.push(result.AvailableList[n]);
  302. } else if(result.ListItemType[n] == MEDIA_TYPE.CAMERA) {
  303. cameras.push(result.AvailableList[n]);
  304. }
  305. }
  306. generateDeviceSelect(loundspeakers, 'gui_media_config_audio_output_outfree_list');
  307. generateDeviceSelect(loundspeakers, 'gui_media_config_audio_output_infree_list');
  308. generateDeviceSelect(microphones, 'gui_media_config_audio_input_outfree_list');
  309. generateDeviceSelect(microphones, 'gui_media_config_audio_input_infree_list');
  310. if(typeof flag !== 'undefined') {
  311. $('#gui_media_config_audio_input_infree').empty();
  312. $('#gui_media_config_audio_input_infree').attr('value', '');
  313. $('#gui_media_config_audio_input_outfree').empty();
  314. $('#gui_media_config_audio_input_outfree').attr('value', '');
  315. $('#gui_media_config_audio_output_infree').empty();
  316. $('#gui_media_config_audio_output_infree').attr('value', '');
  317. $('#gui_media_config_audio_output_outfree').empty();
  318. $('#gui_media_config_audio_output_outfree').attr('value', '');
  319. utilShowToast("已刷新");
  320. }
  321. } else if(typeof flag !== 'undefined'){
  322. RVC.CameraConfigEntity.commErrorCallback(ret);
  323. }
  324. });
  325. }
  326. function SaveMediaDeviceConfig()
  327. {
  328. //话筒扬声器
  329. var output_infree = $('#gui_media_config_audio_output_infree').attr('value');
  330. //外部扬声器
  331. var output_outfree = $('#gui_media_config_audio_output_outfree').attr('value');
  332. //话筒麦克风
  333. var input_infree = $('#gui_media_config_audio_input_infree').attr('value');
  334. //外部麦克风
  335. var input_outfree = $('#gui_media_config_audio_input_outfree').attr('value');
  336. if(output_outfree === '') {
  337. utilStartAlertDialog('请选择外部扬声器');
  338. return;
  339. }
  340. if(output_infree === '') {
  341. utilStartAlertDialog('请选择话筒扬声器');
  342. return;
  343. }
  344. if(input_outfree === '') {
  345. utilStartAlertDialog('请选择外部麦克风');
  346. return;
  347. }
  348. if(input_infree === '') {
  349. utilStartAlertDialog('请选择话筒麦克风');
  350. return;
  351. }
  352. // if(output_infree == output_outfree) {
  353. // utilStartAlertDialog('扬声器选取冲突,请重新选择');
  354. // return;
  355. // }
  356. // if(input_infree == input_outfree) {
  357. // utilStartAlertDialog('麦克风选取冲突,请重新选择');
  358. // return;
  359. // }
  360. let req = new Request();
  361. req.currStep = CONST.DeployStep_MediaConfig;
  362. req.preStep = CONST.DeployStep_AccessAuthorize;
  363. req.nextStep = CONST.DeployStep_Finished;
  364. req.param1 = 0;
  365. req.param2 = 0;
  366. req.param3 = '';
  367. req.param4 = '';
  368. req.param5 = '';
  369. req.array1 = [MEDIA_DETAIL_TYPE.MediaDev_OutSpeaker, MEDIA_DETAIL_TYPE.MediaDev_InSpeaker, MEDIA_DETAIL_TYPE.MediaDev_OutMicrophone, MEDIA_DETAIL_TYPE.MediaDev_InMicrophone];
  370. req.array2 = [output_outfree, output_infree, input_outfree, input_infree];
  371. utilStartSubmitDialog();
  372. RVC.HealthmanagerEntityCtrl.DeployTerminal(req, function(ret) {
  373. utilStopSubmitDialog();
  374. if(ret.errorCode === 0) {
  375. let result = JSON.parse(ret[RVC.EntityController.sigResponseUUID])
  376. if(result.result == 0) {
  377. utilStartAlertDialog("操作成功", function() {
  378. RVC.GuideController.gotoPage(result.nextStep);
  379. });
  380. } else {
  381. utilStartAlertDialog("操作失败:[" + result.result + "] " + result.additionalMsg);
  382. }
  383. } else {
  384. RVC.HealthmanagerEntityCtrl.commErrorCallback(ret);
  385. }
  386. });
  387. }
  388. $(document).on('click', '#guide_initparam_ip_check #ip_connect_check', function(){
  389. var ip = $('#guide_server_ip').val();
  390. console.log('ip: ' + ip);
  391. IPConnectableTest(ip);
  392. });
  393. $(document).on('click', '#guide_initparam_next', function() {
  394. const ip = $('#guide_server_ip').val();
  395. const terminalno = $('#guide_initparam_terminalno').val();
  396. if(!isValidIpAddress(ip)) {
  397. utilStartAlertDialog("无效IP格式");
  398. return;
  399. }
  400. if(!IsDigital(terminalno)) {
  401. utilStartAlertDialog("无效终端号格式");
  402. return;
  403. }
  404. var vendorType = $('#gui_initparam_vendor').attr('value');
  405. if(vendorType === '' || vendorType === 'None') {
  406. utilStartAlertDialog("请选择设备厂商");
  407. return;
  408. }
  409. InitTemrinalAbout(ip, terminalno, vendorType);
  410. });
  411. $(document).on('click', '#guide_sync_centersetting_next', function() {
  412. const ip = $('#guide_sync_centersetting_server_ip_content').val();
  413. var port = $('#guide_sync_centersetting_port_content').val();
  414. DownloadCenterSetting(ip, port);
  415. });
  416. $(document).on('click', '#guide_access_authorize_next', function() {
  417. const ip = $('#guide_access_authorize_server_ip_content').val();
  418. var port = $('#guide_access_authorize_port_content').val();
  419. AuthorizeTerminal(ip, port);
  420. });
  421. $(document).on('click', '#guide_media_config_refresh', function() {
  422. FulfillMediaDeviceList(true);
  423. });
  424. $(document).on('click', '#guide_media_config_next', function() {
  425. SaveMediaDeviceConfig();
  426. });
  427. if (window.location.href.indexOf('guide.html') !== -1) {
  428. RVC.GuideController.resizeWindow();
  429. RVC.Scroll.initScroll('#initparam_content');
  430. }
  431. if (window.addEventListener) {
  432. window.addEventListener('resize', RVC.GuideController.resizeWindow, false);
  433. } else {
  434. window.attachEvent('resize', RVC.GuideController.resizeWindow);
  435. }
  436. setTimeout(RVC.GuideController.resizeWindow, 200);
  437. RVC.CameraConfigEntity.init();
  438. FulfillMediaDeviceList();
  439. RVC.GuideController.hideAllPage();
  440. $('#guide_start_page').show();
  441. });