You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1309 lines
41 KiB

​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
12 months ago
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
12 months ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. //<?php require_once('../../js_asm.php'); ?>
  2. var monitoringViewLevel = 0;
  3. var monitoringActiveSession = false;
  4. var mon_selectedEventId = 0;
  5. var mon_selectedPlatform = 0;
  6. var mon_selectedStation = 0;
  7. var mon_selectedTrack = 0;
  8. var mon_selectedModule = 0;
  9. var autoRiseEvent = true;
  10. var activeEvents = [];
  11. var expiredEvents = [];
  12. function imgLoadEvent(){
  13. alert('l c');
  14. };
  15. function createEventTagContent( a ){
  16. var gif='green_2.gif';
  17. var add=','+a.status;
  18. if( a.status == 0 ){
  19. gif='red_2.gif';
  20. };
  21. if( mon_selectedEventId == a.id ){
  22. return '<div id="event_tag_'+a.id+'"class="evt_side_tag_selected" onclick="selectEvent('+a.id+add+');"><table width="100%" border=0><tr><td colspan=2><div class="evt_side_stname">'+a.station_name+'</div></td><td width="18px"><img src="/style/assets/'+gif+'"></td></tr><tr><td><div class="evt_side_plname">'+a.platform_name+'</div></td><td colspan=2><div class="level_label_title">'+a.track_tag+'</div></td></tr></div>';
  23. };
  24. return '<div id="event_tag_'+a.id+'"class="evt_side_tag" onclick="selectEvent('+a.id+add+');"><table width="100%" border=0><tr><td colspan=2><div class="evt_side_stname">'+a.station_name+'</div></td><td width="18px"><img src="/style/assets/'+gif+'"></td></tr><tr><td><div class="evt_side_plname">'+a.platform_name+'</div></td><td colspan=2><div class="level_label_title">'+a.track_tag+'</div></td></tr></div>';
  25. };
  26. var GREEN_Icon = L.icon({
  27. iconUrl: '/style/assets/igr.png',
  28. iconSize: [44, 44],
  29. iconAnchor: [22, 22],
  30. popupAnchor: [0, -22]
  31. //shadowUrl: 'leaf-shadow.png',
  32. //shadowSize: [50, 64], // size of the shadow
  33. //shadowAnchor: [4, 62], // the same for the shadow
  34. });
  35. var BLUE_Icon = L.icon({
  36. iconUrl: '/style/assets/irs.png',
  37. iconSize: [44, 44],
  38. iconAnchor: [22, 22],
  39. popupAnchor: [0, -22]
  40. //shadowUrl: 'leaf-shadow.png',
  41. //shadowSize: [50, 64], // size of the shadow
  42. //shadowAnchor: [4, 62], // the same for the shadow
  43. });
  44. var RED_Icon = L.icon({
  45. iconUrl: '/style/assets/ira.png',
  46. iconSize: [44, 44],
  47. iconAnchor: [22, 22],
  48. popupAnchor: [0, -22]
  49. });
  50. var REDB_Icon = L.icon({
  51. iconUrl: '/style/assets/irabl.gif',
  52. iconSize: [44, 44],
  53. iconAnchor: [22, 22],
  54. popupAnchor: [0, -22]
  55. });
  56. var GREY_Icon = L.icon({
  57. iconUrl: '/style/assets/ign.png',
  58. iconSize: [44, 44],
  59. iconAnchor: [22, 22],
  60. popupAnchor: [0, -22]
  61. });
  62. var GREYN_Icon = L.icon({
  63. iconUrl: '/style/assets/ign.png',
  64. iconSize: [44, 44],
  65. iconAnchor: [22, 22],
  66. popupAnchor: [0, -22]
  67. });
  68. function makePtzMove( me ){
  69. var name = me.target.id;
  70. const myArray = name.split("_");
  71. Ext.Ajax.request({
  72. url: '/lib/controller/doModuleOperations.php',
  73. params: {
  74. UID: <?=$UserID;?>,
  75. SID: '<?=$Session;?>',
  76. OPID: 8,
  77. MID: myArray[3],
  78. MOV: myArray[2]
  79. },
  80. failure: failureAJAXFunction
  81. });
  82. };
  83. function makePtzStop( me ){
  84. var name = me.target.id;
  85. const myArray = name.split("_");
  86. Ext.Ajax.request({
  87. url: '/lib/controller/doModuleOperations.php',
  88. params: {
  89. SITE: <?=$SiteID;?>,
  90. UID: <?=$UserID;?>,
  91. SID: '<?=$Session;?>',
  92. OPID: 8,
  93. MID: myArray[3],
  94. MOV: 0
  95. },
  96. failure: failureAJAXFunction
  97. });
  98. };
  99. function makePtzHome( me ){
  100. var name = me.target.id;
  101. const myArray = name.split("_");
  102. Ext.Ajax.request({
  103. url: '/lib/controller/doModuleOperation.php',
  104. params: {
  105. SITE: <?=$SiteID;?>,
  106. UID: <?=$UserID;?>,
  107. SID: '<?=$Session;?>',
  108. OPID: 9,
  109. MID: myArray[3],
  110. MOV: 0
  111. },
  112. failure: failureAJAXFunction
  113. });
  114. };
  115. var fsDrawID = 0;
  116. function exitFullScreen( evt ){
  117. if( document.fullscreenElement ){
  118. } else {
  119. if( fsDrawID ){
  120. console.log("Leaving fullscreen mode.");
  121. };
  122. };
  123. };
  124. function fullScreen( id = '' ){
  125. if(
  126. id == '' ||
  127. document.fullscreenElement ||
  128. document.webkitFullscreenElement ||
  129. document.mozFullScreenElement ||
  130. document.msFullscreenElement
  131. ){
  132. if( document.exitFullscreen ){
  133. document.exitFullscreen();
  134. }else if( document.mozCancelFullScreen ){
  135. document.mozCancelFullScreen();
  136. }else if( document.webkitExitFullscreen ){
  137. document.webkitExitFullscreen();
  138. }else if( document.msExitFullscreen ){
  139. document.msExitFullscreen();
  140. };
  141. if( fsDrawID ){
  142. console.log('resized');
  143. };
  144. }else{
  145. var element = document.getElementById( id );
  146. if( element.requestFullscreen ){
  147. element.requestFullscreen();
  148. }else if( element.mozRequestFullScreen ){
  149. element.mozRequestFullScreen();
  150. }else if( element.webkitRequestFullscreen ){
  151. element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
  152. }else if( element.msRequestFullscreen ){
  153. element.msRequestFullscreen();
  154. };
  155. };
  156. };
  157. function loadStationViewEvt( e ){
  158. loadStationView( e.target.options.mycustomid );
  159. };
  160. function loadStationView( STT, buba ){
  161. if( buba == undefined ){
  162. autoRiseEvent = false;
  163. } else {
  164. autoRiseEvent = buba;
  165. };
  166. if( mon_selectedEventId ) unselectEvent();
  167. mon_selectedStation = STT;
  168. changeContent( 1, 1, mon_selectedStation );
  169. updateUserContent();
  170. Ext.Ajax.request({
  171. url: '/lib/controller/getMonitoringStationView.php',
  172. params: {
  173. STT: mon_selectedStation,
  174. UID: <?=$UserID;?>,
  175. SID: '<?=$Session;?>'
  176. },
  177. success: function( response, opts ){
  178. var data = Ext.decode(response.responseText);
  179. if( data.status == 'ok' ){
  180. monitoringViewLevel = 1;
  181. Ext.getCmp('main_content').removeAll(true);
  182. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  183. Ext.getCmp('main_content').doLayout();
  184. if( data.pids != undefined ){
  185. if( data.pids.length > 0 ){
  186. //for( i=0; i<data.pids.length; i++ )correctPlatformView( data.pids[i] );
  187. };
  188. };
  189. fetchStatus();
  190. } else {
  191. if( data.status == 'steight' ){
  192. loadPlatformView( data.next_id );
  193. };
  194. };
  195. },
  196. failure: failureAJAXFunction
  197. });
  198. return;
  199. };
  200. function correctPlatformView( id ){
  201. var pp = Ext.getCmp('plat_panel_'+id);
  202. var pawi = pp.getWidth() / 70;
  203. var tt = document.getElementById('plat_table_'+id );
  204. if( tt != null ){
  205. tt.width = 36.5 * pawi +'px';
  206. };
  207. tt = Ext.getCmp('plat_schematics_'+id );
  208. if( tt != null ){
  209. tt.setHeight( 18 * pawi + 2 * 56 );
  210. };
  211. tt = document.getElementById('plat_video_'+id+'_'+pp.getComponent(0).custom);
  212. if( tt != null ){
  213. tt.style.width = 16 * pawi +'px';
  214. tt.style.height = 9 * pawi +'px';
  215. };
  216. tt = document.getElementById('plat_video_'+id+'_'+pp.getComponent(2).custom);
  217. if( tt != null ){
  218. tt.style.width = 16 * pawi +'px';
  219. tt.style.height = 9 * pawi +'px';
  220. };
  221. tt = document.getElementById('plat_video_'+id+'_'+pp.getComponent(3).custom);
  222. if( tt != null ){
  223. tt.style.width = 16 * pawi +'px';
  224. tt.style.height = 9 * pawi +'px';
  225. };
  226. tt = document.getElementById('plat_video_'+id+'_'+pp.getComponent(4).custom);
  227. if( tt != null ){
  228. tt.style.width = 16 * pawi +'px';
  229. tt.style.height = 9 * pawi +'px';
  230. };
  231. };
  232. function correctModuleView( id ){
  233. var juja = Ext.getCmp('module_panel_'+id );
  234. var pawi = juja.getWidth() / 70;
  235. var tt = Ext.getCmp('module_schematics_'+id);
  236. tt.setWidth( 20+35 * pawi );
  237. tt.setHeight( 38+19 * pawi );
  238. tt = document.getElementById('plat_video_div_'+id );
  239. tt.style.width = 32 * pawi +'px';
  240. tt.style.height = 18 * pawi +'px';
  241. pawi = Ext.getCmp('plat_video_panel_'+id);
  242. pawi.setWidth( 32+32 * pawi);
  243. pawi.setHeight( 32+ 18 * pawi);
  244. };
  245. function addSetSessionUI( session_id ){
  246. Ext.Ajax.request({
  247. url: '/lib/controller/doSessionOperations.php',
  248. params: {
  249. SESSION: session_id,
  250. OPID: 2,
  251. OPAR: 0,
  252. UID: <?=$UserID;?>,
  253. SID: '<?=$Session;?>'
  254. },
  255. success: function( response, opts ){
  256. var data = Ext.decode(response.responseText);
  257. if( data.status == 'ok' ){
  258. var tv = Ext.getCmp('trx_view');
  259. if( tv != undefined ){
  260. var tt = Ext.getCmp('sets_ui');
  261. if( tt != undefined ){
  262. tv.remove( tt );
  263. };
  264. tv.add( Ext.decode( data.content ) );
  265. tv.doLayout();
  266. };
  267. };
  268. }//,
  269. //failure: failureAJAXFunction
  270. });
  271. };
  272. function doSessionOperation( session_id, op, param, reload ){
  273. Ext.Ajax.request({
  274. url: '/lib/controller/doSessionOperations.php',
  275. params: {
  276. SESSION: session_id,
  277. OPID: op,
  278. OPAR: param,
  279. UID: <?=$UserID;?>,
  280. SID: '<?=$Session;?>'
  281. },
  282. success: function( response, opts ){
  283. var data = Ext.decode(response.responseText);
  284. if( data.status == 'ok' ){
  285. if( reload ){
  286. };
  287. };
  288. },
  289. failure: failureAJAXFunction
  290. });
  291. };
  292. function loadPlatformView( pid, buba ){
  293. if( buba == undefined ){
  294. autoRiseEvent = false;
  295. } else {
  296. autoRiseEvent = buba;
  297. };
  298. if( mon_selectedEventId ) unselectEvent( mon_selectedEventId );
  299. mon_selectedPlatform = pid;
  300. changeContent( 1, 2, pid );
  301. updateUserContent();
  302. Ext.Ajax.request({
  303. url: '/lib/controller/getMonitoringPlatformView.php',
  304. params: {
  305. PID: mon_selectedPlatform,
  306. UID: <?=$UserID;?>,
  307. SID: '<?=$Session;?>'
  308. },
  309. success: function( response, opts ){
  310. var data = Ext.decode(response.responseText);
  311. if( data.status == 'ok' ){
  312. monitoringViewLevel = 2;
  313. Ext.getCmp('main_content').removeAll(true);
  314. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  315. Ext.getCmp('main_content').doLayout();
  316. correctPlatformView( data.pid );
  317. fetchStatus();
  318. };
  319. },
  320. failure: failureAJAXFunction
  321. });
  322. return;
  323. };
  324. function loadTrackViewBySession( session_id ){
  325. autoRiseEvent = false;
  326. mSvgElements = [];
  327. Ext.Ajax.request({
  328. url: '/lib/controller/getMonitoringTrackView.php',
  329. params: {
  330. SESSION: session_id,
  331. UID: <?=$UserID;?>,
  332. SID: '<?=$Session;?>'
  333. },
  334. success: function( response, opts ){
  335. var data = Ext.decode(response.responseText);
  336. if( data.status == 'ok' ){
  337. monitoringViewLevel = 3;
  338. mon_selectedTrack = data.track_id;
  339. changeContent( 1, 3, mon_selectedTrack );
  340. updateUserContent();
  341. Ext.getCmp('main_content').removeAll(true);
  342. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  343. Ext.getCmp('main_content').doLayout();
  344. tt=document.getElementById('trx_status_txt');
  345. tt.classList.remove('static_status_text');
  346. tt.classList.add('blinking_status_text');
  347. tt.innerText = 'ACTIVE';
  348. tt=document.getElementById('trx_status_cell');
  349. tt.classList.remove('top_status_hidden');
  350. tt.classList.add('top_status_red_lbl');
  351. monitoringActiveSession = true;
  352. fetchStatus();
  353. };
  354. },
  355. failure: failureAJAXFunction
  356. });
  357. return;
  358. };
  359. function loadTrackView( tid ){
  360. autoRiseEvent = false;
  361. mon_selectedTrack = tid;
  362. changeContent( 1, 3, mon_selectedTrack );
  363. updateUserContent();
  364. mSvgElements = [];
  365. Ext.Ajax.request({
  366. url: '/lib/controller/getMonitoringTrackView.php',
  367. params: {
  368. TID: mon_selectedTrack,
  369. UID: <?=$UserID;?>,
  370. SID: '<?=$Session;?>'
  371. },
  372. success: function( response, opts ){
  373. var data = Ext.decode(response.responseText);
  374. if( data.status == 'ok' ){
  375. monitoringViewLevel = 3;
  376. mon_selectedPlatform = data.platform_id;
  377. mon_selectedStation = data.station_id;
  378. Ext.getCmp('main_content').removeAll(true);
  379. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  380. Ext.getCmp('main_content').doLayout();
  381. tt=document.getElementById('trx_status_txt');
  382. tt.innerText = 'LIVE VIEW';
  383. monitoringActiveSession = false;
  384. tt=document.getElementById('trx_status_cell');
  385. tt.classList.remove('top_status_hidden');
  386. tt.classList.add('top_status_green_lbl');
  387. fetchStatus();
  388. };
  389. },
  390. failure: failureAJAXFunction
  391. });
  392. return;
  393. };
  394. function loadModuleView( pid, mid ){
  395. autoRiseEvent = false;
  396. if( mon_selectedEventId ) unselectEvent( mon_selectedEventId );
  397. changeContent( 1, 4, pid+'-'+mid );
  398. updateUserContent();
  399. Ext.Ajax.request({
  400. url: '/lib/controller/getMonitoringModuleView.php',
  401. params: {
  402. PID: pid,
  403. MID: mid,
  404. UID: <?=$UserID;?>,
  405. SID: '<?=$Session;?>'
  406. },
  407. success: function( response, opts ){
  408. var data = Ext.decode(response.responseText);
  409. if( data.status == 'ok' ){
  410. monitoringViewLevel = 4;
  411. Ext.getCmp('main_content').removeAll(true);
  412. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  413. Ext.getCmp('main_content').doLayout();
  414. correctModuleView( mid );
  415. fetchStatus();
  416. };
  417. },
  418. failure: failureAJAXFunction
  419. });
  420. return;
  421. };
  422. function loadMapView(){
  423. autoRiseEvent = false;
  424. if( mon_selectedEventId ) unselectEvent( mon_selectedEventId );
  425. Ext.Ajax.request({
  426. url: '/lib/controller/getMonitoringMapView.php',
  427. params: {
  428. UID: <?=$UserID;?>,
  429. SID: '<?=$Session;?>'
  430. },
  431. success: function( response, opts ){
  432. var data = Ext.decode(response.responseText);
  433. if( data.status == 'ok' ){
  434. monitoringViewLevel = 0;
  435. Ext.getCmp('main_content').removeAll(true);
  436. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  437. Ext.getCmp('main_content').doLayout();
  438. };
  439. },
  440. failure: failureAJAXFunction
  441. });
  442. return;
  443. };
  444. var monitoring_map = null;
  445. var c_icon = null;
  446. var stationMarkers = [];
  447. function initMonitoringMap( map_id, x, y ){
  448. var mapLayers = [];
  449. if( monitoring_map != null ){
  450. monitoring_map.off();
  451. monitoring_map.remove();
  452. monitoring_map = null;
  453. };
  454. monitoring_map = L.map( map_id,{
  455. crs: L.CRS.Simple,
  456. attributionControl: false,
  457. preferCanvas: true,
  458. zoomControl: true,
  459. center: [x,y],
  460. zoom: 0,
  461. minZoom: -3,
  462. maxZoom: 0,
  463. keyboard: false
  464. });
  465. var bounds = [[SCHEMATIC_SET.bounds_lx,SCHEMATIC_SET.bounds_ly], [SCHEMATIC_SET.bounds_rx,SCHEMATIC_SET.bounds_ry]];
  466. var image = L.imageOverlay( SCHEMATIC_SET.layer_url, bounds ).addTo( monitoring_map );
  467. Ext.Ajax.request({
  468. url: '/lib/controller/listStations.php',
  469. params: {
  470. UID: <?=$UserID;?>,
  471. SID: '<?=$Session;?>'
  472. },
  473. success: function( response, opts ){
  474. var data = Ext.decode(response.responseText);
  475. if( data.status == 'ok' ){
  476. for( i=0; i < data.stations.length; i++ ){
  477. stationMarkers[ data.stations[i].id ] = L.marker([data.stations[i].y, data.stations[i].x], { draggable: false, icon: GREY_Icon, zIndexOffset: 1000, mycustomid: data.stations[i].id } ).addTo( monitoring_map ).on('click', loadStationViewEvt );;
  478. };
  479. };
  480. // Ready -> Start Getting data
  481. fetchStatus();
  482. },
  483. failure: failureAJAXFunction
  484. });
  485. };
  486. function getBackToMap(){
  487. autoRiseEvent = true;
  488. changeContent( 1, 0 );
  489. updateUserContent();
  490. loadMapView();
  491. };
  492. function initMonitoring( x, y ){
  493. if( tlInterval!= null ){
  494. window.clearInterval( tlInterval );
  495. tlInterval = null;
  496. timelineObj = null;
  497. };
  498. var tP = Ext.getCmp('left_side_menu');
  499. tP.removeAll( true );
  500. tP.add({
  501. layout:'vbox',
  502. frame: false,
  503. border: false,
  504. items:[{
  505. width: "100%",
  506. height: 42,
  507. html: '<div id="a_title" class="mon_side_tag">Active Alerts</div>'
  508. },{
  509. id: 'sme_inner',
  510. //layout:'vbox',
  511. width: "100%",
  512. height: PanelH/2-24,
  513. frame: false,
  514. border: false,
  515. autoScroll: true,
  516. cls: 'thin-scrollbar',//'hide-scrollbar', // Apply the CSS class
  517. items:[],
  518. listeners: {
  519. render: function(p) {
  520. p.body.on('scroll', function(e, t) {
  521. if (t.scrollTop + t.clientHeight >= t.scrollHeight) {
  522. console.log('A Scrolled to end!');
  523. // Handle reaching the bottom here
  524. };
  525. });
  526. }
  527. }
  528. },{
  529. width: "100%",
  530. height: 42,
  531. html: '<div id="e_title" class="mon_side_tag">Expired Alerts</div>'
  532. },{
  533. id: 'sme_outer',
  534. //layout:'vbox',
  535. width: "100%",
  536. height: PanelH/2-24,
  537. frame: false,
  538. border: true,
  539. autoScroll: true,
  540. cls: 'thin-scrollbar',//'hide-scrollbar', // Apply the CSS class
  541. items:[],
  542. listeners: {
  543. render: function(p) {
  544. p.body.on('scroll', function(e, t) {
  545. if (t.scrollTop + t.clientHeight >= t.scrollHeight) {
  546. console.log('E Scrolled to end!');
  547. // Handle reaching the bottom here
  548. };
  549. });
  550. }
  551. }
  552. }]
  553. });
  554. tP.doLayout();
  555. monitoringViewLevel = contentView.l[1].v;
  556. switch( monitoringViewLevel ){
  557. case 0:{
  558. loadMapView();
  559. break;
  560. };
  561. case 1:{
  562. loadStationView( parseInt( contentView.l[1].p ), autoRiseEvent );
  563. break;
  564. };
  565. case 2:{
  566. loadPlatformView( parseInt( contentView.l[1].p ), autoRiseEvent );
  567. break;
  568. };
  569. case 3:{
  570. loadTrackView( parseInt( contentView.l[1].p ), autoRiseEvent );
  571. break;
  572. };
  573. case 4:{
  574. var tA = contentView.l[1].p.split('-');
  575. a = parseInt( tA[0] );
  576. b = parseInt( tA[1] );
  577. loadModuleView( a, b );
  578. break;
  579. };
  580. case 5:{
  581. selectEvent( parseInt( contentView.l[1].p ), true );
  582. break;
  583. };
  584. };
  585. Ext.getCmp('main_content').doLayout();
  586. };
  587. var statusLTS = 0;
  588. var statusLID = 0;
  589. function manageSideTags( tag_area, buba ){
  590. var tP = Ext.getCmp( tag_area );
  591. if( tP != undefined ){
  592. if( buba != undefined ){
  593. if( buba.length ){
  594. var idx_a = 0;
  595. //alert( tag_area + ' has '+tP.items.getCount() );
  596. while( a = tP.getComponent( idx_a ) ){
  597. var f=false;
  598. for( var zz=0; zz < buba.length; zz++ ){
  599. if( a.getId() == 'tag_panel_'+buba[zz].id ){
  600. f = true;
  601. break;
  602. };
  603. };
  604. if( !f ) {
  605. tt--;
  606. tP.remove( a, true );
  607. } else idx_a++;
  608. };
  609. tP.doLayout();
  610. var aa = tP.items.getRange();
  611. var tt = aa.length;
  612. for( var zz=0; zz < buba.length; zz++ ){
  613. var f=false;
  614. for( var i=0; i < aa.length; i++ ){
  615. if( aa[i].getId() == 'tag_panel_'+buba[zz].id ){
  616. f = true;
  617. break;
  618. };
  619. };
  620. if( !f ){
  621. tP.insert( 0,{
  622. id: 'tag_panel_'+buba[zz].id,
  623. width: "100%",
  624. html: createEventTagContent( buba[zz] )
  625. });
  626. tt++;
  627. };
  628. if( tt > 32 ){
  629. tP.remove( aa[31], true );
  630. tt--;
  631. };
  632. };
  633. if( tag_area == 'sme_inner' ){
  634. // Active
  635. activeEvents = [];
  636. for( var zz=0; zz < buba.length; zz++ ) activeEvents[zz]={id: buba[zz].id};
  637. } else {
  638. // Expired
  639. expiredEvents = [];
  640. for( var zz=0; zz < buba.length; zz++ ) expiredEvents[zz]={id: buba[zz].id};
  641. };
  642. } else {
  643. tP.removeAll( true );
  644. if( tag_area == 'sme_inner' ){
  645. // Active
  646. activeEvents = [];
  647. } else {
  648. // Expired
  649. expiredEvents = [];
  650. };
  651. };
  652. } else {
  653. tP.removeAll( true );
  654. if( tag_area == 'sme_inner' ){
  655. // Active
  656. activeEvents = [];
  657. } else {
  658. // Expired
  659. expiredEvents = [];
  660. };
  661. };
  662. tP.doLayout();
  663. };
  664. };
  665. var mSvgElements = [];
  666. function fetchStatus(){
  667. if( tlInterval!= null ){
  668. window.clearTimeout( tlInterval );
  669. tlInterval = null;
  670. };
  671. switch(monitoringViewLevel){
  672. case 0:{
  673. var ll = monitoring_map.getCenter();
  674. CX = ll.lat;
  675. CY = ll.lng;
  676. ajax_params = {
  677. VLVL: monitoringViewLevel,
  678. UID: <?=$UserID;?>,
  679. SID: '<?=$Session;?>',
  680. LTS: statusLTS,
  681. LID: statusLID,
  682. MX: CX,
  683. MY: CY
  684. };
  685. break;
  686. };
  687. case 1:{
  688. ajax_params = {
  689. VLVL: monitoringViewLevel,
  690. UID: <?=$UserID;?>,
  691. SID: '<?=$Session;?>',
  692. LTS: statusLTS,
  693. LID: statusLID,
  694. SSID: mon_selectedStation
  695. };
  696. break;
  697. };
  698. case 2:{
  699. ajax_params = {
  700. VLVL: monitoringViewLevel,
  701. UID: <?=$UserID;?>,
  702. SID: '<?=$Session;?>',
  703. PID: mon_selectedPlatform,
  704. LTS: statusLTS,
  705. LID: statusLID
  706. };
  707. break;
  708. };
  709. case 3:{
  710. ajax_params = {
  711. VLVL: monitoringViewLevel,
  712. UID: <?=$UserID;?>,
  713. SID: '<?=$Session;?>',
  714. TID: mon_selectedTrack,
  715. LTS: statusLTS,
  716. LID: statusLID
  717. };
  718. break;
  719. };
  720. case 4:{
  721. ajax_params = {
  722. VLVL: monitoringViewLevel,
  723. UID: <?=$UserID;?>,
  724. SID: '<?=$Session;?>',
  725. MID: mon_selectedModule,
  726. LTS: statusLTS,
  727. LID: statusLID
  728. };
  729. break;
  730. };
  731. case 5:{
  732. ajax_params = {
  733. VLVL: monitoringViewLevel,
  734. UID: <?=$UserID;?>,
  735. SID: '<?=$Session;?>',
  736. SESSION: mon_selectedEventId,
  737. LTS: statusLTS,
  738. LID: statusLID
  739. };
  740. break;
  741. };
  742. };
  743. Ext.Ajax.request({
  744. url: '/lib/controller/getStatus.php',
  745. params: ajax_params,
  746. success: function( response, opts ){
  747. var data = Ext.decode(response.responseText);
  748. if( data.status == 'ok' ){
  749. if( monitoringViewLevel == data.VLVL ){
  750. statusLTS = data.LTS;
  751. if( autoRiseEvent ){
  752. if( data.active_session_id != undefined ){
  753. if( data.active_session_id > 0 ){
  754. if( ssIsActive ) ssHideSS();
  755. if( data.active_session_id != mon_selectedEventId ){
  756. playSound( 1 );
  757. selectEvent( data.active_session_id, false );
  758. return;
  759. };
  760. };
  761. };
  762. };
  763. //debugger;
  764. switch( monitoringViewLevel ){
  765. case 0:{ //Map
  766. for( i=0; i < data.station_ids.length; i++ ){
  767. switch( data.station_status[i] ){
  768. case 0: {
  769. if( stationMarkers[data.station_ids[i]].options.icon != GREY_Icon ) stationMarkers[data.station_ids[i]].setIcon( GREY_Icon );
  770. break;
  771. };
  772. case 1: {
  773. if( stationMarkers[data.station_ids[i]].options.icon != BLUE_Icon ) stationMarkers[data.station_ids[i]].setIcon( BLUE_Icon );
  774. break;
  775. };
  776. case 2: {
  777. if( stationMarkers[data.station_ids[i]].options.icon != GREEN_Icon ) stationMarkers[data.station_ids[i]].setIcon( GREEN_Icon );
  778. break;
  779. };
  780. case 3: {
  781. if( ( Math.floor(Date.now() / 1000) % 2 ) == 0 ) {
  782. if( stationMarkers[data.station_ids[i]].options.icon != GREEN_Icon ) stationMarkers[data.station_ids[i]].setIcon( GREEN_Icon );
  783. } else {
  784. if( stationMarkers[data.station_ids[i]].options.icon != RED_Icon ) stationMarkers[data.station_ids[i]].setIcon( RED_Icon );
  785. };
  786. break;
  787. };
  788. case 4: {
  789. if( stationMarkers[data.station_ids[i]].options.icon != REDB_Icon ) stationMarkers[data.station_ids[i]].setIcon( REDB_Icon );
  790. break;
  791. };
  792. };
  793. };
  794. break;
  795. };
  796. case 1:{ //Platforms
  797. if( data.platforms != undefined ){
  798. for( i=0; i< data.platforms.length; i++ ){
  799. var tt = document.getElementById( 'plat_table_'+data.platforms[i].id );
  800. if( data.platforms[i].status == 1 ){
  801. if( tt.classList.contains('active_green') ){
  802. tt.classList.remove('active_green');
  803. tt.classList.add('active_red');
  804. };
  805. } else {
  806. if( tt.classList.contains('active_red') ){
  807. tt.classList.remove('active_red');
  808. tt.classList.add('active_green');
  809. };
  810. };
  811. if( data.platforms[i].modules != undefined ){
  812. for( j=0; j<data.platforms[i].modules.length; j++ ){
  813. if( data.platforms[i].modules[j].status ){
  814. var zz = document.getElementById('mod_vp_'+data.platforms[i].modules[j].id );
  815. if( zz.style.backgroundImage != 'url("'+data.platforms[i].modules[j].img+'")' ){
  816. zz.style.backgroundImage = 'url("'+data.platforms[i].modules[j].img+'")';
  817. };
  818. };
  819. };
  820. };
  821. };
  822. };
  823. break;
  824. };
  825. case 2:{ // Platform
  826. if( data.modules != undefined ){
  827. for( var i=0; i< data.modules.length; i++){
  828. if( data.modules[i].status > 0 ){
  829. var tt = document.getElementById('plat_video_'+mon_selectedPlatform+'_'+data.modules[i].id );
  830. if( tt != undefined ){
  831. //if( tt.src != data.modules[i].img ) tt.src = data.modules[i].img;
  832. };
  833. tt = document.getElementById('plat_status_'+mon_selectedPlatform+'_'+data.modules[i].id );
  834. if( tt != undefined ){
  835. switch( data.modules[i].status ){
  836. case 1: tt.innerHTML='<img src="/style/assets/bul_gray.png">'; break;
  837. case 2: tt.innerHTML='<img src="/style/assets/bul_green.png">'; break;
  838. case 3: tt.innerHTML='<img src="/style/assets/bul_green_rst.png">'; break;
  839. };
  840. };
  841. };
  842. };
  843. };
  844. if( data.scada != undefined ){
  845. var tt = document.getElementById('scada_status');
  846. switch( data.scada.status ){
  847. case 0:{
  848. tt.innerHTML='<?=$Labels->GetLabel('_NOT_ASSIGNED_');?>';
  849. tt.setAttribute('class', 'mon_scada_status_tag_na');
  850. tt = document.getElementById('scada_a');
  851. tt.setAttribute('class', 'mon_scada_head');
  852. tt = document.getElementById('scada_b');
  853. tt.setAttribute('class', 'mon_scada_head');
  854. tt = document.getElementById('scada_c');
  855. tt.setAttribute('class', 'mon_scada_head');
  856. tt = document.getElementById('scada_d');
  857. tt.setAttribute('class', 'mon_scada_head');
  858. break;
  859. };
  860. case 1:{
  861. tt.innerHTML='<?=$Labels->GetLabel('__DISABLED__');?>';
  862. tt.setAttribute('class', 'mon_scada_status_tag_na');
  863. tt = document.getElementById('scada_a');
  864. tt.setAttribute('class', 'mon_scada_head');
  865. tt = document.getElementById('scada_b');
  866. tt.setAttribute('class', 'mon_scada_head');
  867. tt = document.getElementById('scada_c');
  868. tt.setAttribute('class', 'mon_scada_head');
  869. tt = document.getElementById('scada_d');
  870. tt.setAttribute('class', 'mon_scada_head');
  871. break;
  872. };
  873. case 2:{//offline
  874. tt.innerHTML='<?=$Labels->GetLabel('__OFFLINE__');?>';
  875. tt.setAttribute('class', 'mon_scada_status_tag_na');
  876. tt = document.getElementById('scada_a');
  877. tt.setAttribute('class', 'mon_scada_head');
  878. tt = document.getElementById('scada_b');
  879. tt.setAttribute('class', 'mon_scada_head');
  880. tt = document.getElementById('scada_c');
  881. tt.setAttribute('class', 'mon_scada_head');
  882. tt = document.getElementById('scada_d');
  883. tt.setAttribute('class', 'mon_scada_head');
  884. break;
  885. };
  886. case 3:{//online
  887. tt.innerHTML='<?=$Labels->GetLabel('__ONLINE__');?>';
  888. tt.setAttribute('class', 'mon_scada_status_tag_ok');
  889. tt = document.getElementById('scada_a');
  890. if( data.scada.A ){
  891. tt.setAttribute('class', 'mon_scada_head_active');
  892. } else {
  893. tt.setAttribute('class', 'mon_scada_head_ok');
  894. };
  895. tt = document.getElementById('scada_b');
  896. if( data.scada.B ){
  897. tt.setAttribute('class', 'mon_scada_head_active');
  898. } else {
  899. tt.setAttribute('class', 'mon_scada_head_ok');
  900. };
  901. tt = document.getElementById('scada_c');
  902. if( data.scada.C ){
  903. tt.setAttribute('class', 'mon_scada_head_active');
  904. } else {
  905. tt.setAttribute('class', 'mon_scada_head_ok');
  906. };
  907. tt = document.getElementById('scada_d');
  908. if( data.scada.D ){
  909. tt.setAttribute('class', 'mon_scada_head_active');
  910. } else {
  911. tt.setAttribute('class', 'mon_scada_head_ok');
  912. };
  913. break;
  914. };
  915. };
  916. };
  917. if( data.events != undefined ){
  918. var sid = data.events.length - 1;
  919. if( sid > -1 ){
  920. for( var i=0; i< max_grad_levels; i++ ){
  921. var cid = sid-i;
  922. var csize = getSize( i );
  923. //debugger;
  924. if( typeof mSvgElements[i] === 'undefined') {
  925. if( cid > -1 ){
  926. var svgns = "http://www.w3.org/2000/svg";
  927. mSvgElements[i] = document.createElementNS(svgns, 'rect');
  928. mSvgElements[i].setAttribute('x', data.events[cid].x+'%');
  929. mSvgElements[i].setAttribute('y', ''+(50+(100-csize)/2) );
  930. mSvgElements[i].setAttribute('height', ''+csize);
  931. mSvgElements[i].setAttribute('width', ''+csize);
  932. mSvgElements[i].setAttribute('fill', '#FF0000'+getTransperecy(i));
  933. var tt = document.getElementById('svgTrackMap');
  934. var zz = document.getElementById('scheme_anch');
  935. tt.insertBefore( mSvgElements[i], zz );
  936. //document.getElementById('svgTrackMap').appendChild(this.mSvgElements[i]);
  937. };
  938. } else {
  939. if( cid > -1 ){
  940. mSvgElements[i].setAttribute('x', data.events[cid].x+'%');
  941. mSvgElements[i].setAttribute('y', ''+(50+(100-csize)/2) );
  942. mSvgElements[i].setAttribute('height', ''+csize);
  943. mSvgElements[i].setAttribute('width', ''+csize);
  944. mSvgElements[i].setAttribute('fill', '#FF0000'+getTransperecy(i) );
  945. } else {
  946. mSvgElements[i].setAttribute('fill', '#FF000000');
  947. };
  948. };
  949. };
  950. } else
  951. for( var i=0; i< max_grad_levels; i++ )
  952. if( typeof mSvgElements[i] !== 'undefined') mSvgElements[i].setAttribute('fill', '#FF000000');
  953. };
  954. if( data.scada != undefined ){
  955. };
  956. break;
  957. };
  958. case 3:{ // Track
  959. if( data.active_session_id != undefined ){
  960. if( data.active_session_id > 0 ){
  961. if( mon_selectedEventId != data.active_session_id ){
  962. mon_selectedEventId = data.active_session_id;
  963. monitoringActiveSession = true;
  964. for( var zz=0; zz< activeEvents.length; zz++ ){
  965. var tP = document.getElementById('event_tag_'+activeEvents[zz].id );
  966. if( tP != undefined ){
  967. tP.className ='';
  968. if( activeEvents[zz].id == mon_selectedEventId ){
  969. tP.classList.add("evt_side_tag_selected");
  970. } else {
  971. tP.classList.add("evt_side_tag");
  972. };
  973. };
  974. };
  975. addSetSessionUI( mon_selectedEventId );
  976. tt=document.getElementById('trx_status_txt');
  977. tt.classList.remove('static_status_text');
  978. tt.classList.add('blinking_status_text');
  979. tt.innerText = 'ACTIVE';
  980. tt=document.getElementById('trx_status_cell');
  981. tt.classList.remove('top_status_hidden');
  982. tt.classList.remove('top_status_green_lbl');
  983. tt.classList.add('top_status_red_lbl');
  984. };
  985. } else {
  986. if( mon_selectedEventId ){
  987. mon_selectedEventId = 0;
  988. monitoringActiveSession = false;
  989. tt=document.getElementById('trx_status_txt');
  990. tt.classList.remove('blinking_status_text');
  991. tt.classList.add('static_status_text');
  992. tt.innerText = 'LIVE VEW';
  993. tt=document.getElementById('trx_status_cell');
  994. tt.classList.remove('top_status_hidden');
  995. tt.classList.remove('top_status_red_lbl');
  996. tt.classList.add('top_status_green_lbl');
  997. };
  998. };
  999. };
  1000. if( data.modules != undefined ){
  1001. for( var i=0; i< data.modules.length; i++){
  1002. if( data.modules[i].status > 0 ){
  1003. var tt = document.getElementById('plat_video_img_'+data.modules[i].id );
  1004. if( tt != undefined ){
  1005. if( tt.src != data.modules[i].img ) tt.src = data.modules[i].img;
  1006. };
  1007. //tt = document.getElementById('plat_status_'+mon_selectedPlatform+'_'+data.modules[i].id );
  1008. tt = document.getElementById('cam_ctrl_'+data.modules[i].id );
  1009. if( tt != undefined ){
  1010. if( data.modules[i].status > 1 ) {
  1011. if( tt.style.display != 'block' )tt.style.display = 'block';
  1012. } else {
  1013. if( tt.style.display != 'none' )tt.style.display = 'none';
  1014. };
  1015. };
  1016. };
  1017. };
  1018. };
  1019. if( data.events != undefined ){
  1020. var sid = data.events.length - 1;
  1021. if( sid > -1 ){
  1022. for( var i=0; i< max_grad_levels; i++ ){
  1023. var cid = sid-i;
  1024. var csize = getSize( i );
  1025. //debugger;
  1026. if( typeof mSvgElements[i] === 'undefined') {
  1027. if( cid > -1 ){
  1028. var svgns = "http://www.w3.org/2000/svg";
  1029. mSvgElements[i] = document.createElementNS(svgns, 'rect');
  1030. mSvgElements[i].setAttribute('x', data.events[cid].x+'%');
  1031. mSvgElements[i].setAttribute('y', ''+(50+(100-csize)/2) );
  1032. mSvgElements[i].setAttribute('height', ''+csize);
  1033. mSvgElements[i].setAttribute('width', ''+csize);
  1034. mSvgElements[i].setAttribute('fill', '#FF0000'+getTransperecy(i));
  1035. var tt = document.getElementById('svgTrackMap');
  1036. var zz = document.getElementById('scheme_anch');
  1037. tt.insertBefore( mSvgElements[i], zz );
  1038. //document.getElementById('svgTrackMap').appendChild(this.mSvgElements[i]);
  1039. };
  1040. } else {
  1041. if( cid > -1 ){
  1042. mSvgElements[i].setAttribute('x', data.events[cid].x+'%');
  1043. mSvgElements[i].setAttribute('y', ''+(50+(100-csize)/2) );
  1044. mSvgElements[i].setAttribute('height', ''+csize);
  1045. mSvgElements[i].setAttribute('width', ''+csize);
  1046. mSvgElements[i].setAttribute('fill', '#FF0000'+getTransperecy(i) );
  1047. } else {
  1048. mSvgElements[i].setAttribute('fill', '#FF000000');
  1049. };
  1050. };
  1051. };
  1052. } else
  1053. for( var i=0; i< max_grad_levels; i++ )
  1054. if( typeof mSvgElements[i] !== 'undefined') mSvgElements[i].setAttribute('fill', '#FF000000');
  1055. };
  1056. if( data.scada != undefined ){
  1057. };
  1058. break;
  1059. };
  1060. };
  1061. var tt = document.getElementById('a_title');
  1062. if( tt != null ){
  1063. if( data.actual_count > 0 ){
  1064. tt.innerHTML = 'Active Alerts<br/>['+data.actual_count+']';
  1065. } else {
  1066. tt.innerHTML = 'Active Alerts';
  1067. };
  1068. manageSideTags('sme_inner', data.actual );
  1069. };
  1070. if( tt != null ){
  1071. tt = document.getElementById('e_title');
  1072. if( data.expired_count > 0 ){
  1073. tt.innerHTML = 'Expired Alerts<br/>['+data.expired_count+']';
  1074. } else {
  1075. tt.innerHTML = 'Expired Alerts';
  1076. };
  1077. manageSideTags('sme_outer', data.expired );
  1078. };
  1079. };
  1080. };
  1081. if( contentView.l[0].v == 0 ){
  1082. tlInterval = window.setTimeout( fetchStatus, 333, selectedSite );
  1083. };
  1084. },
  1085. failure: failureAJAXFunction
  1086. });
  1087. };
  1088. function selectEvent( ii, bb ){
  1089. mon_selectedEventId = ii;
  1090. if( tlInterval!= null ){
  1091. window.clearTimeout( tlInterval );
  1092. tlInterval = null;
  1093. };
  1094. for( var zz=0; zz< expiredEvents.length; zz++ ){
  1095. var tP = document.getElementById('event_tag_'+expiredEvents[zz].id );
  1096. if( tP != undefined ){
  1097. tP.className ='';
  1098. if( expiredEvents[zz].id == mon_selectedEventId ){
  1099. monitoringActiveSession = false;
  1100. tP.classList.add("evt_side_tag_selected");
  1101. } else {
  1102. tP.classList.add("evt_side_tag");
  1103. };
  1104. };
  1105. };
  1106. for( var zz=0; zz< activeEvents.length; zz++ ){
  1107. var tP = document.getElementById('event_tag_'+activeEvents[zz].id );
  1108. if( tP != undefined ){
  1109. tP.className ='';
  1110. if( activeEvents[zz].id == mon_selectedEventId ){
  1111. monitoringActiveSession = true;
  1112. tP.classList.add("evt_side_tag_selected");
  1113. } else {
  1114. tP.classList.add("evt_side_tag");
  1115. };
  1116. };
  1117. };
  1118. if( bb ){
  1119. loadMonitoringSessionView( ii );
  1120. } else {
  1121. loadTrackViewBySession( ii );
  1122. };
  1123. };
  1124. function setSessionStatus( a , b, autoremove ){
  1125. if( autoremove ) alert( 'Autoremove' );
  1126. Ext.Ajax.request({
  1127. url: '/lib/controller/doSessionOperations.php',
  1128. params: {
  1129. SESSION: a,
  1130. OPID: 2,
  1131. OPAR: b,
  1132. UID: <?=$UserID;?>,
  1133. SID: '<?=$Session;?>'
  1134. },
  1135. success: function( response, opts ){
  1136. var data = Ext.decode(response.responseText);
  1137. if( data.status == 'ok' ){
  1138. var tv = Ext.getCmp('trx_view');
  1139. if( tv != undefined ){
  1140. var tt = Ext.getCmp('sets_ui');
  1141. if( tt != undefined ){
  1142. tv.remove( tt );
  1143. };
  1144. tv.add( Ext.decode( data.content ) );
  1145. tv.doLayout();
  1146. };
  1147. };
  1148. },
  1149. failure: failureAJAXFunction
  1150. });
  1151. };
  1152. function unselectEvent( ii ){
  1153. mon_selectedEventId = 0;
  1154. for( var zz=0; zz< activeEvents.length; zz++ ){
  1155. var tP = document.getElementById('event_tag_'+activeEvents[zz].id );
  1156. if( tP != undefined ){
  1157. tP.className ='';
  1158. tP.classList.add("evt_side_tag");
  1159. };
  1160. };
  1161. for( var zz=0; zz< expiredEvents.length; zz++ ){
  1162. var tP = document.getElementById('event_tag_'+expiredEvents[zz].id );
  1163. if( tP != undefined ){
  1164. tP.className ='';
  1165. tP.classList.add("evt_side_tag");
  1166. };
  1167. };
  1168. };
  1169. function loadMonitoringSessionView( session_id ){
  1170. autoRiseEvent = false;
  1171. mon_selectedEventId = session_id;
  1172. changeContent( 1, 5, mon_selectedEventId );
  1173. updateUserContent();
  1174. Ext.Ajax.request({
  1175. url: '/lib/controller/getMonitoringSessionView.php',
  1176. params: {
  1177. SESSION: mon_selectedEventId,
  1178. UID: <?=$UserID;?>,
  1179. SID: '<?=$Session;?>'
  1180. },
  1181. success: function( response, opts ){
  1182. var data = Ext.decode(response.responseText);
  1183. if( data.status == 'ok' ){
  1184. monitoringViewLevel = 5;
  1185. if( mSesPlay!= null ) {
  1186. mSesPlay.dispose();
  1187. mSesPlay = null;
  1188. };
  1189. Ext.getCmp('main_content').removeAll(true);
  1190. Ext.getCmp('main_content').add( Ext.decode( data.content ) );
  1191. Ext.getCmp('main_content').doLayout();
  1192. tt=document.getElementById('trx_status_txt');
  1193. //tt.classList.remove('static_status_text');
  1194. //tt.classList.add('blinking_status_text');
  1195. tt.innerText = 'EXPIRED';
  1196. tt=document.getElementById('trx_status_cell');
  1197. tt.classList.remove('top_status_hidden');
  1198. tt.classList.remove('top_status_red_lbl');
  1199. tt.classList.remove('top_status_green_lbl');
  1200. tt.classList.add('top_status_orange_lbl');
  1201. mSesPlay = new argusSessionPlayer( mon_selectedEventId, true );
  1202. //mSesPlay.triggerPlay();
  1203. fetchStatus();
  1204. };
  1205. },
  1206. failure: failureAJAXFunction
  1207. });
  1208. };
  1209. var peerConnections = [];
  1210. async function startWhepClient( video_id, ip_address, stream_id ){
  1211. const STREAM_PATH = stream_id; // 'stream_3'; // Replace with your stream name
  1212. const MEDIAMTX_URL = 'http://'+ip_address+':8889/'+STREAM_PATH+'/whep';
  1213. // 1. Initialize the RTCPeerConnection
  1214. //if( peerConnection == null ){
  1215. const peerConnection = new RTCPeerConnection({
  1216. iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] // Standard STUN for local/NAT routing
  1217. });
  1218. peerConnections[video_id] = peerConnection;
  1219. //};
  1220. // 2. Set up media placeholders (MediaMTX requires transceivers before the offer)
  1221. peerConnection.addTransceiver('video', { direction: 'recvonly' });
  1222. //peerConnection.addTransceiver('audio', { direction: 'recvonly' });
  1223. // 3. Handle incoming stream track
  1224. peerConnection.ontrack = (event) => {
  1225. var videoElement = document.getElementById( video_id );
  1226. if (videoElement && event.streams[0]) {
  1227. videoElement.srcObject = event.streams[0];
  1228. }
  1229. };
  1230. // 4. Create and set Local Description (Offer)
  1231. const offer = await peerConnection.createOffer();
  1232. await peerConnection.setLocalDescription(offer);
  1233. // 5. Send Offer to MediaMTX via HTTP POST
  1234. const response = await fetch(MEDIAMTX_URL, {
  1235. method: 'POST',
  1236. headers: { 'Content-Type': 'application/sdp' },
  1237. body: peerConnection.localDescription.sdp
  1238. });
  1239. if (!response.ok) {
  1240. throw new Error(`MediaMTX WHEP signaling failed: ${response.statusText}`);
  1241. }
  1242. // 6. Set Remote Description (Answer) received from MediaMTX
  1243. const answerSdp = await response.text();
  1244. await peerConnection.setRemoteDescription(new RTCSessionDescription({
  1245. type: 'answer',
  1246. sdp: answerSdp
  1247. }));
  1248. };
  1249. function stopWhepClient( video_id, stream_id ){
  1250. if( peerConnections[video_id] != undefined ){
  1251. peerConnections[video_id].getReceivers().forEach( receiver => {
  1252. if( receiver.track ){
  1253. receiver.track.stop();
  1254. }
  1255. });
  1256. peerConnections[video_id].close();
  1257. delete( peerConnections[video_id] );
  1258. var videoElement = document.getElementById( video_id );
  1259. videoElement.srcObject = null;
  1260. videoElement.load();
  1261. };
  1262. }