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.

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