【调度系统】广东民航医疗快线调度系统源代码
hzj
6 小时以前 1503b9d7ed1d71b98bd5715c23d236ef3c019ead
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
    <title>省平台视频接口</title>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script> 
    <link rel="stylesheet" href="videojs/video-js.min.css">
    <script src="videojs/video.js"></script>
    <script src="videojs/videojs-contrib-hls.js"></script>
    <script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/jquery.query-2.1.7.js"></script>
    <script type="text/javascript" src="CryptoJS/components/core.js"></script>
    <script type="text/javascript" src="CryptoJS/components/cipher-core.js"></script>
    <script type="text/javascript" src="CryptoJS/components/tripledes.js"></script>
    <script type="text/javascript" src="CryptoJS/components/mode-ecb.js"></script>
    <script type="text/javascript" src="../js/encrypt.js"></script>
    <style type="text/css">
    @media (min-width:1340px) {
            .container{
            display: flex;
            flex-flow:column nowrap;
            width: 1340px;/*任意改变长宽*/
            height: 700px;
            background:#ccc;
            }
        }
    
    @media (min-width:1820px) {
           .container{
            display: flex;
            flex-flow:column nowrap;
            width: 1850px;/*任意改变长宽*/
            height: 890px;
            background:#ccc;
            }
        }
        
        .parent{
            display: flex;
             flex-flow:row nowrap;
            flex:1 1 0;/*元素弹性*/
            text-align: center;
        }
        .container .parent:first-child{margin-bottom: 5px;}
        .item{
            flex:1 1 0;/*元素弹性*/
            background: black;
        }
        .parent .item:first-child{margin-right: 5px;}
    </style>
    <script type="text/javascript">
        var isInitFinished = false;
        var jsession = "";
        var vehiIdno = "";
        var devIdno = "";
        var name = "";
        var channel = 0;
        var chnCount = 1;
        var closeSecond = 0;
        var lang = new langZhCn();
        var myPlayer = null;
        var isVideoBreak = null;        //判断视频是否卡住,卡主后重载加载视频
        var lastTime = -1;
        var tryTimes = 0;
        // 车载视频接入省平台接口参数
        // 接口请求格式 : http://地址:端口/路径?Key=密钥&VehPlateNum=车牌号&VehPlateColorCode=2&Channel=1,2,3,4
        var isSptReq = false;
        var sptInfRequestObj = {
                key :null, // 双向加密
                channelList : [], // 通道号
                chnCount: 0, // 总通道数
                plateColor : 0, // 车牌颜色 1蓝色 2黄色
                vehiIdNo: "", //车牌号                
                jsession: null, // 本次请求会话
                devIdno : null // 设备号
        }
        
        //获取URL参数信息
        function getUrlParameter(name){
            if(location.search==''){
                return '';
            }
            var o={};
            var search=location.search.replace(/\?/,'');//只替换第一个问号,如果参数中带有问号,当作普通文本
            var s=search.split('&');
            for(var i=0;i<s.length;i++){
                o[s[i].split('=')[0]]=s[i].split('=')[1];
            }
            return o[name]==undefined?'':o[name];
        }
        
        
        
        function langZhCn() {
            this.loginError = "登陆失败";
            this.jsessionError = "会话号不存在";
            this.deviceNoExist = "找不到车辆信息";
            this.errorVideoDevice = "这个设备不是视频设备";
            this.vehicleNotOperate = "没有车辆或者设备操作权限";
            this.closeTip = "秒后关闭视频";
        }
        
        function langEn() {
            this.loginError = "Login failed";
            this.jsessionError = "Jsession error";
            this.deviceNoExist = "Can't not find vehicles";
            this.vehicleNotOperate = "No vehicle or device operating authority";
            this.errorVideoDevice = "This device is not video device";
            this.closeTip = " seconds later close video"
        }
    
        //  http://地址:端口/路径?Key=密钥&VehPlateNum=车牌号&VehPlateColorCode=2&Channel=1,2,3,4
        function initSptInfRequestObj() {
            var Key = getUrlParameter("Key");
            if(Key == null || typeof Key == 'undefined' || Key == '') {
                console.log("并非调用省平台车载视频接入接口。");
                isSptReq = false;
                return;
            } else {
                isSptReq = true;
            }
            var Channel = getUrlParameter("Channel");
            var VehPlateNum = getUrlParameter("VehPlateNum");
            var VehPlateColorCode = getUrlParameter("VehPlateColorCode");
            sptInfRequestObj.channelList = Channel.split(',');
            sptInfRequestObj.key = Key;
            sptInfRequestObj.plateColor = VehPlateColorCode;
            sptInfRequestObj.vehiIdNo = VehPlateNum;
        }
        
        $(document).ready(function(){
            // 初始化省平台接口参数
            initSptInfRequestObj();
            if(isNaN(Number(sptInfRequestObj.plateColor))) {
                alert("车牌类型输入有误,请输入数字。");
                return;
            }
            /* if(Number(sptInfRequestObj.plateColor) > 2) {
                alert("车牌类型输入有误,目前仅支持黄牌跟蓝牌。");
                return;
            } */
            $("#closeTip").hide();
            var chn = getUrlParameter("channel");
            if (chn) {
                channel = parseInt(chn, 10);
            }
            var temp = getUrlParameter("close");
            if (temp) {
                closeSecond = parseInt(temp, 10);
            }
            if (getUrlParameter("lang") == "en") {
                lang = new langEn();
            }
            //设备号
            devIdno = getUrlParameter("devIdno");
            //车牌号
            vehiIdno = decodeURIComponent(getUrlParameter("vehiIdno"));
            if((!devIdno && !vehiIdno) && !isSptReq) {//都为空 而且不是省平台视频接口
                alert(lang.deviceNoExist);
            }else {
                if(devIdno) {
                       name = devIdno;
                   }else {
                       name = vehiIdno;
                   }
                document.title = name;
                //会话号
                jsession = getUrlParameter("jsession");
                //如果jsession为空,则登陆获取会话号
                if(!jsession) {
                    login();
                }else {
                    //加载设备信息
                    loadDeviceInfo();
                }
            }
        });
 
        //如果传入了用户名和密码,则登陆获取会话号
        function login() {
            var account = "";
            var password = "";
            if(isSptReq) {
                // 解密key 格式 account|password
                var decryptKey = decryptByDESModeEBC(sptInfRequestObj.key);
                var userInfo = decryptKey.split("|");
                account = userInfo[0];
                password = userInfo[1];
            } else {
                account = getUrlParameter("account");
                password = getUrlParameter("password");
            }
            var param = [];
            param.push({name: 'account', value: account});
            param.push({name: 'password', value: password});
            this.doAjaxSubmit('StandardApiAction_loginEx.action', param, function(json, action, success) {
                if(success) {
                    jsession = json.jsession;
                    if(isSptReq) {
                        sptInfRequestObj.jsession = json.jsession;
                    }
                    //获取到会话号,则加载设备信息
                    loadDeviceInfo();
                }else {
                    if(isSptReq) {
                        alert("Key值错误,请确认输入正确的Key值。");
                    }
                    alert(lang.loginError);
                }
            });
        }
 
        //如果传入设备号,则直接判断设备号;
        //如果没传入设备号,则判断传入的车牌号
        //根据设备号或者车牌号获取设备信息,并判断是否有效和是否视频设备
        //获取设备通道
        function loadDeviceInfo() {
            var param = [];
            var ajaxUrl = "StandardApiAction_getVideoDevice.action";
               param.push({name: 'jsession', value: jsession});
               if(isSptReq) {
                   // 省平台接口不存在设备参数
                   param.push({name: 'devIdno', value: null});
                param.push({name: 'vehiIdno', value: sptInfRequestObj.vehiIdNo});
                param.push({name: 'plateType', value: sptInfRequestObj.plateColor});
            }else {
                param.push({name: 'devIdno', value: devIdno});
                   param.push({name: 'vehiIdno', value: vehiIdno});
            }
            
               this.doAjaxSubmit(ajaxUrl, param, function(json, action, success) {
                if(success) {
                    //不是视频设备
                    if(!json.isVideoDevice) {
                        alert(lang.errorVideoDevice);
                    }else {
                        devIdno = json.devIdno;
                        chnCount = json.chnCount;
                        if(isSptReq) {
                            if(json.plateTypeErr == 1) {
                                alert("该汽车没有对应的车牌颜色,请核对车牌颜色输入是否有误。");
                                return;
                            }
                            sptInfRequestObj.devIdno = json.devIdno;
                            sptInfRequestObj.chnCount = json.chnCount;
                            //sptInfRequestObj.chnCount = 9;
                        }
                        //加载完成再加载其他信息
                        if(isSptReq) {
                            previewMutiChVideo();
                        }else{
                            previewVideo();
                        }
                    }
                }else {
                    //没有操作权限
                    if(json) {
                        if(json.result == 5) {
                            alert(lang.jsessionError);
                        }else if(json.result == 8) {
                            alert(lang.vehicleNotOperate);
                        }else {
                            alert(lang.deviceNoExist);
                        }
                    }else {
                        alert(lang.deviceNoExist);
                    }
                }
            });
        }
        
        //提交ajax
        function doAjaxSubmit(action, params, callback) {
            $.ajax({
                type: 'POST',
                url: action,
                data: params,
                cache:false,/*禁用浏览器缓存*/
                dataType: 'json',
                success: function (json) {
                    if(json.result == 0){
                        callback.call(this, json, action, true);
                    } else {
                        callback.call(this, json, action, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    try {
                        if (p.onError) p.onError(XMLHttpRequest, textStatus, errorThrown);
                    } catch (e) {}
                    callback.call(this, null, action, false);
                }
            });
        }
        
        //开始预览视频
        function previewVideo() {
            var host = window.location.host;
            var ip = host.split(":")[0];
            if(!ip || ip == 'localhost') {
                ip = '127.0.0.1';
            }
            //ip = "192.168.1.230";
            
            var m3u8Url = "http://" + ip + ":6604/hls/1_" + devIdno + "_" +channel + "_1.m3u8?JSESSIONID=" + jsession;
            var divVideo = "<video id=\"hls_example_video\" class=\"video-js vjs-default-skin\" controls preload=\"none\" width=\"352\" height=\"288\" data-setup=\"{}\">"
                + "<source src=\"" + m3u8Url + "\" type=\"application/x-mpegURL\">"              
                  + "</video>";
              $("#hls_video").empty();
              $("#hls_video").append(divVideo);
              videojs("hls_example_video").ready(function(){
                    myPlayer = this;
                    myPlayer.width(document.documentElement.clientWidth - 20);
                    var height = document.documentElement.clientWidth;
                    if (document.documentElement.clientWidth > document.documentElement.clientHeight) {
                        var height = document.documentElement.clientHeight;
                    }
                    myPlayer.height(height - 20);
                    myPlayer.on("pause", onPause);
                    myPlayer.on("play", onPlay);
                    myPlayer.play();
                });
        }
        
        //预览一个设备的多个通道视频
        function previewMutiChVideo(requsetObj) {
            var host = window.location.host;
            var ip = host.split(":")[0];
            if(!ip || ip == 'localhost') {
                ip = '127.0.0.1';
            }
            //ip = "192.168.1.230";
            
            var divVideo = "";
            var chn = 0;
            var m3u8Url = "";
            var renderVideoForDivObj = {isRenderVideo : false,m3u8Url : "",chn:null}
            var pageChNum = 4;
            var divWidth = "45%";
            var divHeight = "45%";
            var videoWidth = "590";
            var videoHeight = "420";
            var adjustMargin = "40px";
            if(screen.width < 1441 || document.documentElement.clientWidth < 1441) {
                videoWidth = "440";
                videoHeight = "325";
            }
            
            
            if(sptInfRequestObj.chnCount > 4){
                pageChNum = 9;
                divWidth = document.documentElement.clientWidth * 0.3;
                divWidth += "px";
                divHeight = document.documentElement.clientHeight * 0.3;
                divHeight += "px";
                videoWidth = "400";
                videoHeight = "290"; 
                adjustMargin = "20px";
            }
            
            var getIsRenderVideoObj = function (divId) {
                if($.inArray((divId + 1).toString(),sptInfRequestObj.channelList) != -1) {
                    renderVideoForDivObj.isRenderVideo = true;
                    renderVideoForDivObj.chn = divId;
                    renderVideoForDivObj.m3u8Url = m3u8Url = "http://" + ip + ":6604/hls/1_" + sptInfRequestObj.devIdno + "_" +renderVideoForDivObj.chn + "_1.m3u8?JSESSIONID=" + sptInfRequestObj.jsession;
                } else { // 重置
                    renderVideoForDivObj = {isRenderVideo : false,m3u8Url : "",chn:divId}
                }
                return renderVideoForDivObj;
            }
            
            for(var i=0;i<pageChNum;i++) {
                // 决定对每个i 容器是否渲染视频,如果渲染视频,则要给url,通道号,是否渲染提示
                renderVideoForDivObj = getIsRenderVideoObj(i);
                /* if (renderVideoForDivObj.isRenderVideo) {
                    divVideo += "<div style=\"width:"+ divWidth +";height:"+ divHeight +";float:left;margin:10px;margin-left:"+ adjustMargin +";padding:10px;\"><video id=\"hls_example_video"+ i +"\" class=\"video-js vjs-default-skin\" style=\"margin-left:5px\" controls preload=\"none\" width=\"352\" height=\"288\" data-setup=\"{}\">"
                    + "<source src=\"" + renderVideoForDivObj.m3u8Url + "\" type=\"application/x-mpegURL\">"              
                      + "</video></div>";
                } else {
                    divVideo += "<div style=\"width:"+ divWidth +";height:"+ divHeight +";float:left;margin:10px;margin-left:"+ adjustMargin +";padding:10px;\"><video id=\"hls_example_video"+ i +"\" class=\"video-js vjs-default-skin\" style=\"margin-left:5px\" controls preload=\"none\" width=\""+ videoWidth +"\" height=\""+videoHeight+"\" data-setup=\"{}\">"
                    + "<source src=\"\" type=\"application/x-mpegURL\">"              
                      + "</video></div>";
                } */
                if (i%2 == 0) { // 偶数
                    // 偶数为行第一个
                    divVideo += "<div class=\"parent\">";
                    //divVideo += "<div class=\"item\"></div>";
                    if (renderVideoForDivObj.isRenderVideo) {
                        divVideo += "<div class=\"item\" align=\"center\">"
                        + "<div style=\"color:red\">车牌号:"+ decodeURI(sptInfRequestObj.vehiIdNo) +"&nbsp;&nbsp;&nbsp;通道号:" + (renderVideoForDivObj.chn + 1) + "</div>"
                        + "<video id=\"hls_example_video"+ i +"\" class=\"video-js vjs-default-skin\" controls preload=\"none\" width=\""+ videoWidth +"\" height=\""+ videoHeight +"\" data-setup=\"{}\">"
                        + "<source src=\"" + renderVideoForDivObj.m3u8Url + "\" type=\"application/x-mpegURL\">"              
                          + "</video></div>";
                    } else {
                        divVideo += "<div class=\"item\" align=\"center\"></div>";
                        /* + "<div style=\"color:red\">车牌号:"+ decodeURI(sptInfRequestObj.vehiIdNo) +"&nbsp;&nbsp;&nbsp;通道号:" + renderVideoForDivObj.chn + "</div>"
                        + "<video id=\"hls_example_video"+ i +"\" class=\"video-js vjs-default-skin\" controls preload=\"none\" width=\""+ videoWidth +"\" height=\""+ videoHeight +"\" data-setup=\"{}\">"
                        + "<source src=\"\" type=\"application/x-mpegURL\">"              
                          + "</video></div>"; */
                    }
                } else { // 奇数
                    //divVideo += "<div class=\"item\"></div>";
                    if (renderVideoForDivObj.isRenderVideo) {
                        divVideo += "<div class=\"item\" align=\"center\">"
                        + "<div style=\"color:red\">车牌号:"+ decodeURI(sptInfRequestObj.vehiIdNo) +"&nbsp;&nbsp;&nbsp;通道号:" + (renderVideoForDivObj.chn + 1) + "</div>"
                        + "<video id=\"hls_example_video"+ i +"\" class=\"video-js vjs-default-skin\" controls preload=\"none\" width=\""+ videoWidth +"\" height=\""+ videoHeight +"\" data-setup=\"{}\">"
                        + "<source src=\"" + renderVideoForDivObj.m3u8Url + "\" type=\"application/x-mpegURL\">"              
                          + "</video></div>";
                    } else {
                        divVideo += "<div class=\"item\" align=\"center\"></div>";
                        /* + "<div style=\"color:red\">车牌号:"+ decodeURI(sptInfRequestObj.vehiIdNo) +"&nbsp;&nbsp;&nbsp;通道号:" + renderVideoForDivObj.chn + "</div>"
                        + "<video id=\"hls_example_video"+ i +"\" class=\"video-js vjs-default-skin\" controls preload=\"none\" width=\""+ videoWidth +"\" height=\""+ videoHeight +"\" data-setup=\"{}\">"
                        + "<source src=\"\" type=\"application/x-mpegURL\">"              
                          + "</video></div>"; */
                    }
                    divVideo += "</div>";
                }
            }
              $("#hls_video").empty();
              $("#hls_video").append(divVideo);
              for(var j=0;j<pageChNum;j++) {
                  chn = sptInfRequestObj.channelList[j];
                // 输入通道不能大于已有通道数        
                // v1.0.1 经省平台指出,不显示提示
                  /* if(chn > sptInfRequestObj.chnCount) {
                         alert("通道参数不能大于已有通道数,请输入正确的通道参数。");
                        break;
                  } */
                  var obj = "hls_example_video" + j;
                  if(!document.getElementById( obj)) {
                      continue;
                  }
                  videojs(obj).ready(function(){
                        myPlayer = this;
                        myPlayer.width(videoWidth);
                        myPlayer.height(videoHeight);
                        myPlayer.on("pause", onPause);
                        myPlayer.on("play", onPlay);
                        myPlayer.play();
                    });
              }
            //url示例
            //http://192.168.1.230:6604/hls/1_10000_0_1.m3u8?JSESSIONID=123456789
            //http://流媒体服务器IP:流媒体服务器客户服务端口(默认为6604)/hls/请求类型(1表示实时视频)_设备编号_通道号_码流类型(0主码流1子码流).m3u8?JSESSION=会话号
            //暂时只考虑单个流媒体服务器,如果为多个流媒体服务器,则为先请求流媒体服务器的地址
            
            /*myPlayer.src({src:m3u8Url,type:"application/x-mpegURL"});
            alert(myPlayer.cache_.source.src);
            alert(myPlayer.cache_.source.type);
            alert(myPlayer.cache_.src);
            myPlayer.cache_.src = m3u8Url;
            myPlayer.play();
            checkVideo();
            if (closeSecond != 0) {
                $("#closeTip").show();        
                setTimeout(closeVideo, 1000);
            }*/
        }
        
        function checkVideo() {
            if (isVideoBreak != null) {
                clearInterval(isVideoBreak);    
                isVideoBreak = null;
            }
            isVideoBreak = setInterval(function(){
                var currentTime = myPlayer.currentTime();
                //currentTime为0表示还未加载
                if (currentTime != 0) {
                    if(currentTime == lastTime){
                        if(++tryTimes > 2){
                             //设置当前播放时间为超时时间,此时videojs会在play()后把currentTime设置为0
                            myPlayer.currentTime(currentTime+10000);
                            myPlayer.play();
                            tryTimes = 0;
                        }
                    }else{
                        lastTime = currentTime;
                        tryTimes = 0;
                    }
                }
            },3000)
        }
        
        function onPlay() {
            checkVideo();
        }
        
        function onPause() {
            if (isVideoBreak != null) {
                clearInterval(isVideoBreak);    
                isVideoBreak = null;
            }
        }
 
        function closeVideo() {
//            for (var i = 0; i < 4; ++ i) {
//                swfobject.getObjectById('cmsv6flash').stopVideo(i);
//            }
            if (closeSecond > 0) {
                closeSecond -- ;
                $("#spanCloseSecond").text(closeSecond + lang.closeTip);
                setTimeout(closeVideo, 1000);
            } else {
                 if (isVideoBreak != null) {
                    clearInterval(isVideoBreak);    
                    isVideoBreak = null;
                }
                $("#closeTip").hide();
                myPlayer.pause();
            }
        }
    </script>
</head>
<body>
    <div id="closeTip">
        <p><span id="spanCloseSecond"></span></p>
    </div>
    <div id="hls_video" class="container">
      </div>
</body>
</html>