videoCam.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /**
  2. *
  3. */
  4. var baseUrl;
  5. var baseIp;
  6. var videoStore;
  7. var company_code;
  8. var theme;
  9. var maxHeight = 10000;
  10. var maxWidth = 10000;
  11. var close_dev = function(id){
  12. var query = {
  13. CMD:3,
  14. BODY:{
  15. DEVICE:id,
  16. ACTION:0
  17. }
  18. }
  19. $.ajax({
  20. type:'POST',
  21. url:baseUrl+'cgi-bin/demo.cgi',
  22. data:'queryJson:'+JSON.stringify(query),
  23. success:function(result){
  24. }
  25. });
  26. }
  27. var open_dev = function(id){
  28. var query = {
  29. CMD:3,
  30. BODY:{
  31. DEVICE:id,
  32. ACTION:1
  33. }
  34. }
  35. $.ajax({
  36. type:'POST',
  37. url:baseUrl+'cgi-bin/demo.cgi',
  38. data:'queryJson:'+JSON.stringify(query),
  39. success:function(result){
  40. }
  41. });
  42. }
  43. var chk_cideo = function(){
  44. var query = {
  45. CMD:1
  46. }
  47. $.ajax({
  48. type:'POST',
  49. url:baseUrl+'cgi-bin/demo.cgi',
  50. data:'queryJson:'+JSON.stringify(query),
  51. success:function(result){
  52. var json = eval('(' + result + ')');
  53. if(json.RESULT.LIST!=undefined){
  54. if(json.RESULT.LIST.length>0){
  55. for(var i=0;i<json.RESULT.LIST.length;i++){
  56. var close_btn = document.getElementById('close_'+json.RESULT.LIST[i].DEVICE);
  57. var open_btn = document.getElementById('open_'+json.RESULT.LIST[i].DEVICE);
  58. if(json.RESULT.LIST[i].LIVEONLINE==true){
  59. document.getElementById('close_'+json.RESULT.LIST[i].DEVICE).innerHTML = '视频重载';
  60. document.getElementById('open_'+json.RESULT.LIST[i].DEVICE).disabled = true;
  61. }else{
  62. document.getElementById('close_'+json.RESULT.LIST[i].DEVICE).innerHTML = '关闭视频';
  63. document.getElementById('open_'+json.RESULT.LIST[i].DEVICE).disabled = false;
  64. }
  65. }
  66. }
  67. }
  68. }
  69. });
  70. setTimeout(chk_cideo,5000);
  71. }
  72. var getVideoList = function() {
  73. var query = {
  74. company_code:company_code
  75. }
  76. $.ajax({
  77. type:'POST',
  78. url: baseUrl+"iot/alarm/view/getVideoList",
  79. data: {
  80. queryJson : Ext.JSON.encode(query)
  81. },
  82. success: function(result){
  83. var json = eval('(' + result + ')');
  84. if(json.action=='getVideoList'){
  85. videoStore = json.RESULT;
  86. if(json.company.length>0)
  87. $("#videoCamPanel_title_string").innerHTML=json.company+".视频监控";
  88. else
  89. $("#videoCamPanel_title_string").innerHTML="视频监控";
  90. var videoCams = document.getElementById('Video_Cams');
  91. var table = document.createElement('table');
  92. table.border="0";
  93. table.style="border:0px solid #000; width:1260px; margin:10px auto 5px auto;";
  94. videoCams.appendChild(table);
  95. var tr1,tr2,tr3;
  96. for(var i=0;i<videoStore.length;i++){
  97. if((i%3)==0){
  98. tr1 = document.createElement('tr');
  99. table.appendChild(tr1);
  100. tr2 = document.createElement('tr');
  101. table.appendChild(tr2);
  102. tr3 = document.createElement('tr');
  103. table.appendChild(tr3);
  104. }
  105. var td = document.createElement('td');
  106. td.style='border:0px solid #000; width:420px; height:50px; text-align:center;';
  107. tr1.appendChild(td);
  108. var cam_title = document.createElement('div');
  109. cam_title.id = 'title_'+videoStore[i].device_code;
  110. cam_title.style = 'width:400px; heigh:30px;text-align:center;font-size:24px;font-weight:bold;margin:5px 10px;';
  111. cam_title.innerHTML=videoStore[i].dev_name;
  112. td.appendChild(cam_title);
  113. // var cam_video = document.createElement('div');
  114. // cam_video.style='width:320px; height:240px; background-color:#000;margin-left:40px;';
  115. // cam_video.id='video_'+videoStore[i].device_code;
  116. // td.appendChild(cam_video);
  117. // if(videoStore[i].comm_type==1)
  118. // {
  119. // var video = document.createElement('object');
  120. // video.id = 'my2_'+videoStore[i].device_code;
  121. // video.setAttribute('type','application/x-vlc-plugin');
  122. // video.width='320';
  123. // video.height='240';
  124. // video.setAttribute('pluginspage','http://www.videolan.org');
  125. // video.setAttribute('codebase','http://download.videolan.org/pub/videolan/vlc/last/win32/axvlc.cab');
  126. // cam_video.appendChild(video);
  127. // var param1 = document.createElement('param');
  128. // param1.setAttribute('name','controls');
  129. // param1.setAttribute('value','false');
  130. // video.appendChild(param1);
  131. // var param2 = document.createElement('param');
  132. // param2.setAttribute('name','text');
  133. // param2.setAttribute('value','正在加载视频中...');
  134. // video.appendChild(param2);
  135. // var param3 = document.createElement('param');
  136. // param3.setAttribute('name','branding');
  137. // param3.setAttribute('value','false');
  138. // video.appendChild(param3);
  139. // var embed = document.createElement('embed');
  140. // embed.setAttribute('type','application/x-google-vlc-plugin');
  141. // embed.setAttribute('width','320');
  142. // embed.setAttribute('height','240');
  143. // video.appendChild(embed);
  144. // }else
  145. {
  146. var td_v = document.createElement('td');
  147. td_v.style='border:0px solid #000; width:400px; height:240px; text-align:center;';
  148. tr2.appendChild(td_v);
  149. var video = document.createElement('video');
  150. video.id = 'my-'+videoStore[i].device_code;
  151. video.setAttribute('style','margin:0px 10px;')
  152. video.setAttribute('class','video-js');
  153. video.setAttribute('preload','auto');
  154. video.autoplay='autoplay';
  155. video.controls='controls';
  156. video.onclick=function(){
  157. alert('hello');
  158. }
  159. // video.playsInline='';
  160. // video.webkitPlaysinline='';
  161. video.width='400';
  162. video.height='300';
  163. video.setAttribute('data-setup','{}');
  164. td_v.appendChild(video);
  165. var source = document.createElement('source');
  166. source.setAttribute('src','rtmp://47.103.74.123:1935/live/'+videoStore[i].device_code);
  167. source.setAttribute('type','rtmp/flv');
  168. video.appendChild(source);
  169. var embed = document.createElement('embed');
  170. embed.id = 'openflash_'+videoStore[i].device_code;
  171. embed.width='300';
  172. embed.height='70';
  173. embed.setAttribute('class','openFlash');
  174. embed.style='position:absolute;top:130px;left:225px;z-Index:9999;dispaly:none;';
  175. embed.type='application/x-shockwave-flash';
  176. td_v.appendChild(embed);
  177. }
  178. var td_b = document.createElement('td');
  179. td_b.style='border:0px solid #000; width:400px; height:50px; text-align:center;';
  180. tr3.appendChild(td_b);
  181. var subTable = document.createElement('table');
  182. subTable.style="border:0px solid #000;width:320;height:30px;";
  183. subTable.width='100%';
  184. td_b.appendChild(subTable);
  185. var subTr = document.createElement('tr');
  186. subTable.appendChild(subTr);
  187. var subTd = document.createElement('td');
  188. subTd.style='border:0px solid #000;height:50px; text-align:center;padding-top:10px;';
  189. subTd.width='50%';
  190. subTr.appendChild(subTd);
  191. var close_button = document.createElement('button');
  192. close_button.id='close_'+videoStore[i].device_code;
  193. close_button.setAttribute('onclick', 'close_dev("'+videoStore[i].device_code+'");');
  194. close_button.innerHTML='关闭视频';
  195. subTd.appendChild(close_button);
  196. subTd = document.createElement('td');
  197. subTd.style='border:0px solid #000;height:50px; text-align:center;padding-top:10px;';
  198. subTd.width='50%';
  199. subTr.appendChild(subTd);
  200. var open_button = document.createElement('button');
  201. open_button.id='open_'+videoStore[i].device_code;
  202. open_button.setAttribute('onclick','open_dev("'+videoStore[i].device_code+'");');
  203. open_button.innerHTML='打开视频';
  204. subTd.appendChild(open_button);
  205. }
  206. var hasFlash = 0; //是否安装了flash
  207. var flashVersion = 0; //flash版本
  208. var isIE = /*@cc_on!@*/0; //是否IE浏览器
  209. if (isIE) {
  210. var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
  211. if (swf) {
  212. hasFlash = 1;
  213. VSwf = swf.GetVariable("$version");
  214. flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
  215. }
  216. } else {
  217. if (navigator.plugins && navigator.plugins.length > 0) {
  218. var swf = navigator.plugins["Shockwave Flash"];
  219. if (swf) {
  220. hasFlash = 1;
  221. var words = swf.description.split(" ");
  222. for (var i = 0; i < words.length; ++i) {
  223. if (isNaN(parseInt(words[i]))) continue;
  224. flashVersion = parseInt(words[i]);
  225. }
  226. }
  227. }
  228. }
  229. for(var i=0;i<videoStore.length;i++){
  230. if((document.getElementById('openflash_'+videoStore[i].device_code)!=undefined)
  231. &&(document.getElementById('my-'+videoStore[i].device_code)!=undefined)){
  232. if(hasFlash){
  233. document.getElementById('openflash_'+videoStore[i].device_code).style.display='none';
  234. videojs('my-'+videoStore[i].device_code).play();
  235. }
  236. }
  237. else if(document.getElementById('my2_'+videoStore[i].device_code)!=undefined){
  238. var vlc = document.getElementById('my2_'+videoStore[i].device_code);
  239. var options = new Array(":network-caching=300");
  240. var id = vlc.playlist.add(videoStore[i].rtsp_path,"vedio",options);
  241. vlc.playlist.playItem(id);
  242. }
  243. }
  244. $(".openFlashTips").css('display','none');
  245. }
  246. chk_cideo();
  247. }
  248. });
  249. }
  250. var body_resize = function(){
  251. maxHeight = document.documentElement.clientHeight;
  252. maxWidth = document.documentElement.clientWidth;
  253. Ext.getCmp('videoCamPanel').setHeight(maxHeight);
  254. Ext.getCmp('videoCamPanel').setWidth(maxWidth);
  255. }
  256. Ext.onReady(function(){
  257. baseIp = document.getElementById('baseIp').value;
  258. baseUrl = document.getElementById('basePath').value;
  259. theme = document.getElementById('theme').value;
  260. company_code = document.getElementById('company_code').value;
  261. new Ext.create('Ext.panel.Panel',{
  262. width:'100%',
  263. height:maxHeight,
  264. id: 'videoCamPanel',
  265. tbar:new Ext.create('Ext.toolbar.Toolbar',{
  266. items:[{
  267. html:'<span id="videoCamPanel_title_string" style="color:#ffffff;background-color:rgba(0,0,0,0)">视频监控</span>'
  268. },'->',{
  269. xtype: 'button',
  270. iconCls:'back_btn',
  271. text: '<span style="color:#ffffff;background-color:rgba(0,0,0,0)">返回</span>',
  272. listeners: {
  273. click: function(){
  274. location.href=baseUrl+'view/frontpage/map.jsp?&theme='+theme+'&company_code='+company_code;
  275. }
  276. }
  277. },'-']
  278. }),
  279. html:'<div id="Video_Cams" style="text-align:center;"></div>',
  280. renderTo: Ext.getBody()
  281. });
  282. getVideoList();
  283. $(window).resize(function(){
  284. body_resize();
  285. });
  286. body_resize();
  287. });