demo_window_integration.html
44.6 KB
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
<!doctype html>
<html>
<head>
<title>开放平台视频web插件Demo</title>
<!--显示字符集设定:文本网页使用的字符集为utf-8-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--清除缓存,再访问本网站需要重新下载-->
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
<meta http-equiv="Expires" content="0" />
</head>
<style>
html, body {
padding: 0;
margin: 0;
}
.playWnd {
margin: 30px 0 0 400px;
width: 800px;
height: 400px;
border: 1px solid red;
}
.cbInfoDiv {
float: left;
width: 360px;
margin-left: 16px;
border:1px solid #7F9DB9;
}
.cbInfo {
height: 200px;
padding: 5px;
border: 1px solid #7F9DB9;
overflow: auto;
word-break: break-all;
}
.operate {
margin-top: 24px;
}
.operate::after {
content: '';
display: block;
clear: both;
}
.operate .btns {
height: 32px;
}
.module {
float: left;
width: 340px;
min-height: 320px;
margin-left: 16px;
padding: 16px 8px;
box-sizing: border-box;
border: 1px solid #e5e5e5;
}
.module .item {
margin-bottom: 4px;
}
.module .label {
width: 150px;
display: inline-block;
vertical-align: middle;
margin-right: 8px;
text-align: right;
}
.module input[type="text"],
.module select {
box-sizing: border-box;
display: inline-block;
vertical-align: middle;
margin-left: 0;
width: 150px;
min-height: 20px;
}
.module .btn {
min-width: 80px;
min-height: 24px;
margin-top: 16px;
margin-left: 158px;
}
<!--弹框风格
.white_content {
display: none;
position: absolute;
top: 25%;
left: 25%;
width: 30%;
height: 30%;
padding: 20px;
border: 3px solid orange;
background-color: white;
z-index:1002;
overflow: auto;
}
-->
.white_content {
display: none;
position: absolute;
top: 80px;
left: 450px;
width: 600px;
height: 300px;
border: 3px solid orange;
background-color: white;
z-index:1002;
}
</style>
<body>
<div id="playWnd" class="playWnd" style="left: 109px; top: 133px;"></div>
<div id="operate" class="operate">
<!--初始化、反初始化、设置认证信息接口调用入口。
1.插件所有接口都需要在调用初始化并返回成功后才能调用
2.设置认证信息仅适用于多平台接入时的情况,具体参照开发指南
3.反初始化后,插件资源销毁-->
<div class="module" style="height:50;width:330px;padding:10;margin:10;">
<div class="item">
<label >初始化相关参数:</label>
<textarea id="initParam" type="text" style="width:310px;height:350px;">
{
"argument": {
"appkey": "29492226",
"ip": "139.9.65.252",
"port": 1443,
"secret": "82TBBS3plLUTx1XftSh2",
"enableHTTPS": 1,
"language": "zh_CN",
"layout": "1x1",
"playMode": 0,
"reconnectDuration": 5,
"reconnectTimes": 5,
"showSmart": 0,
"showToolbar": 1,
"toolBarButtonIDs": "2048,2049,2050,2304,2306,2305,2307,2308,2309,4096,4608,4097,4099,4098,4609,4100",
"snapDir": "D:/snap",
"videoDir": "D:/video"
},
"funcName": "init"
}
</textarea>
</div>
<div class="item">
<select id="initFuncType" onchange="UpdateInitParamValue()" value="0">
<option value="0" selected>初始化</option>
<option value="1">反初始化</option>
<option value="2">设置认证信息</option>
</select>
<button style="width:10px;padding:0;margin:0;" id="initBtn" class="btn" title="初始化、反初始化、设置认证信息功能入口">执行</button>
</div>
</div>
<!--单个点位播放、批量点位播放、批量停止播放、全部停止播放接口调用入口。
1.authUuid为多平台接入时必须的播放字段,单平台接入时,可不指定-->
<div class="module" style="height:50;width:330px;padding:10;margin:10;">
<div class="item">
<label >播放相关参数:</label>
<textarea id="playParam" type="text" style="width:310px;height:350px;">
{
"argument": {
"authUuid": "",
"cameraIndexCode": "212125350cb942818b8aebcb1ac07bcc",
"ezvizDirect": 0,
"gpuMode": 0,
"streamMode": 2,
"transMode": 0,
"wndId": -1,
"cascade": 1
},
"funcName": "startPreview"
}
</textarea>
</div>
<div class="item">
<select id="playFuncType" onchange="UpdatePlayParamValue()" value="0">
<option value="0" selected>指定监控点编号播放</option>
<option value="1">指定监控点编号批量播放</option>
<option value="2">指定窗口Id集停止播放</option>
<option value="3">停止全部播放</option>
</select>
<button style="width:10px;padding:0;margin:0;" id="playBtn" class="btn" title="指定监控点编号播放 、指定监控点编号批量播放、指定窗口Id集停止播放、停止全部播放功能入口">执行</button>
</div>
</div>
<!-- 轮巡测试模块,仅支持单平台对接时的测试效果,多个监控点编号以英文逗号分隔开-->
<div class="module" id = "TourPreview" style="display: ;" style="height:50;width:330px;padding:10;margin:10;">
<div class="item" >
<label >10s轮巡预览(仅支持测试单平台轮巡)</label>
<div class="item">
<label >监控点编号集(多个监控点以','分隔):</label>
<textarea id="TourPreviewCamIdx" type="text" style="width:310px;height:325px;" placeholder="多个监控点以','分隔" ></textarea>
</div>
<!--<div class="item"><label >监控点编号集:</label>
<input id="TourPreviewCamIdx" type="text" placeholder="多个监控点以','分隔" value="4c47d87440304304ad948883a76350a0,5540a1c645314e43b31a53bf2799d2a4,6bb1345ba3fe428f80631f8a38c3386d"></div>-->
<div class="item">
<select id="tourPreviewType" style="width:130px;" value="0" >
<option value="0" selected>单路播放接口轮巡</option>
<option value="1">批量播放接口轮巡</option>
</select>
<button style="width:;padding:0;margin:0;" id="startTourPreviewBtn" class="btn" title="1.支持单路预览接口轮巡和批量播放接口轮巡,可通过下拉框配置; 2.仅支持单平台对接预览时测试轮巡功能; 3.轮巡时间默认10s,不可配置,但可修改html文件中的内容修改轮巡时间;">开始轮巡预览</button>
<button style="width:;padding:0;margin:0;" id="stopTourPreviewBtn" class="btn" title="1.需要配合开始轮巡预览使用,每次开始后都需要停止">停止轮巡预览</button>
</div>
</div>
</div>
<!--设置布局、获取布局、画面字符叠加接口调用入口-->
<div class="module" style="height:50;width:330px;padding:10;margin:10;">
<!--设置布局、获取布局接口调用入口
1.支持初始化时指定默认布局
2.支持手动点击插件界面上的切换布局或调用切换布局接口后,抛出切换布局消息,信息包含切换后的布局类型、窗口个数-->
<div class="item">
<label >设置布局相关参数:</label>
<textarea id="layoutParam" type="text" style="width:310px;height:75px;">
{
"funcName": "getLayout"
}
</textarea>
</div>
<div class="item">
<select id="layoutFuncType" onchange="UpdateLayoutParamValue()" value="0">
<option value="0" selected>获取布局</option>
<option value="1">设置布局</option>
</select>
<button style="width:10px;padding:0;margin:0;" id="layoutBtn" class="btn" title="1.获取布局、设置布局功能入口 2.双击窗口放大后,切换为1窗口视图,但还是原有布局类型,仅视图切换为1窗口">执行</button>
</div>
<!--画面字符叠加接口调用入口
1.支持调整字体颜色、字体大小、是否加粗、x轴位置、y轴位置、字符所占区域的居中类型(各字段具体取值范围详见对应开发指南)
2.alignType居中类型字段、仅支持对字符所占矩形区域的内容进行居中调整,而不是整个画面的矩形区域居中调整(位置信息主要根据x、y轴字段内容)
3.字体大小设置后,插件放大或窗口放大,字体大小不会发生改变-->
<div class="item">
<label >画面字符叠加相关参数:</label>
<textarea id="drawOSDParam" type="text" style="width:310px;height:175px;">
{
"argument": {
"alignType": 1,
"bold": 0,
"color": 255,
"fontSize": 12,
"text": "测试监控点",
"wndId": 0,
"x": 0,
"y": 0
},
"funcName": "drawOSD"
}
</textarea>
</div>
<div class="item">
<button style="width:100px;padding:0;margin:0;" id="drawOSDBtn" class="btn" title="1.对齐方式仅支持控制字符所占矩形区域内的对齐方式 2.字体大小设置后,效果固定,无法随着画面变大变小一起变大变小 3.去除字符叠加内容只需要将叠加字符串字段传入空字符即可">画面字符叠加</button>
</div>
<div class="item">
<button style="width:100px;padding:0;margin:0;" id="enterFullScreen" class="btn">进入全屏</button>
<button style="width:100px;padding:0;margin:0;" id="exitFullScreen" class="btn">退出全屏</button>
</div>
</div>
<!--抓图接口调用入口、接口调用返回信息显示、插件事件信息显示-->
<div class="module" style="height:50;width:350px;padding:10;margin:10;">
<!--抓图接口调用入口
1.抓图仅支持jpg和bmp后缀的图片文件名,其他后缀则报错
2.抓图后,插件会抛出抓图结果事件。若成功,则包含图片存储路径;当且仅当抓图后缀为jpg时,支持返回图片base64位编码字符串字段-->
<div class="item">
<label >抓图相关参数:</label>
<textarea id="snapParam" type="text" style="width:310px;height:100px;">
{
"argument": {
"name": "D:/snap/测试抓图.jpg",
"wndId": 1
},
"funcName": "snapShot"
}
</textarea>
</div>
<div class="item">
<button style="width:100px;padding:0;margin:0;" id="snapBtn" class="btn" title="1.仅支持jpg和bmp两种图片格式 2.bmp抓图后,由于图片过大,抓图事件中无图片base64位编码信息 3.支持设置路径+名称、仅设置路径,若路径错误,使用默认路径及图片命名规则">抓图</button>
</div>
<legend>返回值信息</legend>
<div id="cbInfo" class="cbInfo"></div>
<button id="clear">清空</button>
<button id="getVerSion" title="插件V1.5.0以下版本不支持此功能(V1.5.0版本支持)">获取版本号</button>
<button id="instructions" title="1.插件demo使用前先安装对应版本的插件到本地机器; 2.所有操作都需要先初始化。若反初始化后,需要再次操作,请重新初始化; 3.初始化指定ip、port、appkey、secret时,仅支持单平台接入,此时播放参数中authUuid字段非必填(参照开发安指南文档); 4.初始化不指定ip、port、appkey、secret时,支持多平台接入,需要通过设置认证信息传入各平台的合作方信息,此时播放参数中authUuid字段必填; 5.demo中轮巡模块只有在单平台接入预览时,才显示;多平台接入或回放时,默认隐藏">使用说明(弹框示例)</button>
</div>
</div>
<div id="light" class="white_content">
<!--iframe标签,为解决ie10上OCX控件遮挡div问题。chrome或ie11使用websocket方式,无需使用iframe-->
<iframe src='about:blank' frameBorder='0' marginHeight='0' marginWidth='0' style='position: absolute; visibility: inherit; top: 0px; left: 0px; width: 100%; height: 100%; z-index: -1; filter: alpha(opacity = 0);'></iframe>
这是一个弹窗示例<a href = "javascript:void(0)" onclick=CloseInstructionsDiv()>点这里关闭本窗口
</a>
<div>【使用说明】 </div>
<div>1.插件demo使用前先安装对应版本的插件到本地机器; </div>
<div>2.所有操作都需要先初始化。若反初始化后,需要再次操作,请重新初始化;</div>
<div>3.初始化指定ip、port、appkey、secret时,仅支持单平台接入,此时播放参数中authUuid字段非必填(参照开发安指南文档); </div>
<div>4.初始化不指定ip、port、appkey、secret时,支持多平台接入,需要通过设置认证信息传入各平台的合作方信息,此时播放参数中authUuid字段必填;</div>
<div>5.demo中轮巡模块只有在单平台接入预览时,才显示;多平台接入或回放时,默认隐藏</div>
</div>
</body>
<script src="jquery-1.12.4.min.js"></script>
<script src="jsencrypt.min.js"></script>
<script src="jsWebControl-1.0.0.min.js"></script>
<script type="text/javascript">
// 插件对象实例,初始化为null,需要创建多个插件窗口时,需要定义多个插件对象实例变量,各个变量唯一标志对应的插件实例
var oWebControl = null;
var bIE = (!!window.ActiveXObject || 'ActiveXObject' in window);// 是否为IE浏览器
var pubKey = ''; // demo中未使用加密,可根据需求参照开发指南自行使用加密功能
var initCount = 0;
var playMode = 0; // 播放类型,0-预览,1-回放
var showDivInstruction = false; // 标志是否显示使用说明弹框
var endTime = Math.floor(new Date(dateFormat(new Date(), "yyyy-MM-dd 23:59:59").replace('-', '/').replace('-', '/')).getTime() / 1000).toString();
var startTime = Math.floor(new Date(dateFormat(new Date(), "yyyy-MM-dd 00:00:00").replace('-', '/').replace('-', '/')).getTime() / 1000).toString();
var playTime = Math.floor(new Date(dateFormat(new Date(), "yyyy-MM-dd 00:00:00").replace('-', '/').replace('-', '/')).getTime() / 1000).toString();
function UpdateInitParamValue(){
var sel = document.getElementById("initFuncType");
var selectedId = sel.selectedIndex;
var v = sel.options[selectedId].value;
var param;
if (0 == v){ //更新为初始化请求的参数
var result = JSON.stringify({
"argument": {
"appkey": "",
"ip": "",
"port": 443,
"secret": "",
"enableHTTPS": 1,
"language": "zh_CN",
"layout": "2x2",
"playMode": 0,
"reconnectDuration": 5,
"reconnectTimes": 5,
"showSmart": 0,
"showToolbar": 1,
"toolBarButtonIDs": "2048,2049,2050,2304,2306,2305,2307,2308,2309,4096,4608,4097,4099,4098,4609,4100",
"snapDir": "D:/snap",
"videoDir": "D:/video"
},
"funcName": "init"
}, null, 2);//将json对象转换成字符串
//document.getElementById('initParam').innerText= result ;
$("#initParam").val(result);
}
else if (1 == v) //更新为反初始化请求的参数
{
var result = JSON.stringify({
"funcName": "uninit"
}, null, 2);//将json对象转换成字符串
//document.getElementById('initParam').innerText= result ;
$("#initParam").val(result);
}
else //更新为设置认证信息请求的参数
{
var result = JSON.stringify({
"argument": {
"list": [
{
"appkey": "",
"authUuid": "111",
"ip": "",
"port": 443,
"secret": ""
},
{
"appkey": "",
"authUuid": "222",
"ip": "",
"port": 443,
"secret": ""
}
]
},
"funcName": "setAuthInfo"
}, null, 2);//将json对象转换成字符串
//document.getElementById('initParam').innerText= result;
$("#initParam").val(result);
}
}
function UpdatePlayParamValue(){
var sel = document.getElementById("playFuncType");
var selectedId = sel.selectedIndex;
var v = sel.options[selectedId].value;
var param;
if (0 == v){ //更新为单个播放请求的参数,根据初始化时的playmode字段,设置为预览或回放
var result = 0 == playMode ? JSON.stringify({
"argument": {
"authUuid": "",
"cameraIndexCode": "212125350cb942818b8aebcb1ac07bcc",
"ezvizDirect": 0,
"gpuMode": 0,
"streamMode": 0,
"transMode": 1,
"wndId": -1,
"cascade": 1
},
"funcName": "startPreview"
}, null, 2) : JSON.stringify({
"argument": {
"authUuid": "",
"cameraIndexCode": "212125350cb942818b8aebcb1ac07bcc",
"endTimeStamp": endTime,
"ezvizDirect": 0,
"gpuMode": 0,
"playTimeStamp": startTime,
"recordLocation": 0,
"startTimeStamp": startTime,
"transMode": 1,
"wndId": 0,
"cascade": 1
},
"funcName": "startPlayback"
}, null, 2);//将json对象转换成字符串
//document.getElementById('playParam').innerText= result;
$("#playParam").val(result);
}
else if (1 == v) //更新为批量播放请求的参数,根据初始化时的playmode字段,设置为预览或回放
{
var result = 0 == playMode ? JSON.stringify({
"argument": {
"list": [
{
"authUuid": "",
"cameraIndexCode": "",
"ezvizDirect": 0,
"gpuMode": 0,
"streamMode": 0,
"transMode": 1,
"wndId": 1
},
{
"authUuid": "",
"cameraIndexCode": "",
"ezvizDirect": 0,
"gpuMode": 0,
"streamMode": 0,
"transMode": 1,
"wndId": 2
}
]
},
"funcName": "startMultiPreviewByCameraIndexCode"
}, null, 2) : JSON.stringify({
"argument": {
"list": [
{
"authUuid": "",
"cameraIndexCode": "",
"endTimeStamp": endTime,
"ezvizDirect": 0,
"gpuMode": 0,
"playTimeStamp": startTime,
"recordLocation": 0,
"startTimeStamp": startTime,
"transMode": 1,
"wndId": 1
},
{
"authUuid": "",
"cameraIndexCode": "",
"endTimeStamp": endTime,
"ezvizDirect": 0,
"gpuMode": 0,
"playTimeStamp": startTime,
"recordLocation": 0,
"startTimeStamp": startTime,
"transMode": 1,
"wndId": 2
}
]
},
"funcName": "startMultiPlaybackByCameraIndexCode"
}, null, 2);//将json对象转换成字符串
//document.getElementById('playParam').innerText= result;
$("#playParam").val(result);
}
else if (2 == v) //更新为批量停止播放请求的参数
{
var result = JSON.stringify({
"argument": {
"list": [
{
"wndId": 1
},
{
"wndId": 2
}
]
},
"funcName": "stopMultiPlay"
}, null, 2);//将json对象转换成字符串
//document.getElementById('playParam').innerText= result;
$("#playParam").val(result);
}
else //更新为停止所有播放请求的参数,根据初始化时的playmode字段,设置为预览或回放
{
var result = 0 == playMode ? JSON.stringify({
"funcName": "stopAllPreview"
}, null, 2) : JSON.stringify({
"funcName": "stopAllPlayback"
}, null, 2);//将json对象转换成字符串
//document.getElementById('playParam').innerText= result;
$("#playParam").val(result);
}
}
function UpdateLayoutParamValue(){
var sel = document.getElementById("layoutFuncType");
var selectedId = sel.selectedIndex;
var v = sel.options[selectedId].value;
var param;
if (0 == v){ //更新为获取布局请求的参数
var result = JSON.stringify({
"funcName": "getLayout"
}, null, 2);//将json对象转换成字符串
//document.getElementById('layoutParam').innerText= result;
$("#layoutParam").val(result);
}
else //更新为设置布局请求的参数
{
var result = JSON.stringify({
"argument": {
"layout": "2x2"
},
"funcName": "setLayout"
}, null, 2);//将json对象转换成字符串
//document.getElementById('layoutParam').innerText= result;
$("#layoutParam").val(result);
}
}
// 标签关闭
$(window).unload(function () {
if (oWebControl != null){
oWebControl.JS_HideWnd(); // 先让窗口隐藏,规避可能的插件窗口滞后于浏览器消失问题
oWebControl.JS_Disconnect().then(function(){}, function() {});
}
});
// 窗口resize
$(window).resize(function () {
if (oWebControl != null) {
oWebControl.JS_Resize(800, 400);
setWndCover();
}
});
// 滚动条scroll
$(window).scroll(function () {
if (oWebControl != null) {
oWebControl.JS_Resize(800, 400);
setWndCover();
}
});
// 设置窗口裁剪,当因滚动条滚动导致窗口需要被遮住的情况下需要JS_CuttingPartWindow部分窗口
function setWndCover() {
//获取web页面的尺寸
var iWidth = $(window).width();
var iHeight = $(window).height();
//获取播放窗口div元素的左边界、右边界距离web页面左边界的长度、上边界、下边界距离web页面上边界的长度
var oDivRect = $("#playWnd").get(0).getBoundingClientRect();
//Math.round 为四舍五入 Math.abs 为取绝对值
var iCoverLeft = (oDivRect.left < 0) ? Math.abs(oDivRect.left): 0;
var iCoverTop = (oDivRect.top < 0) ? Math.abs(oDivRect.top): 0;
var iCoverRight = (oDivRect.right - iWidth > 0) ? Math.round(oDivRect.right - iWidth) : 0;
var iCoverBottom = (oDivRect.bottom - iHeight > 0) ? Math.round(oDivRect.bottom - iHeight) : 0;
iCoverLeft = (iCoverLeft > 800) ? 800 : iCoverLeft;
iCoverTop = (iCoverTop > 400) ? 400 : iCoverTop;
iCoverRight = (iCoverRight > 800) ? 800 : iCoverRight;
iCoverBottom = (iCoverBottom > 400) ? 400 : iCoverBottom;
oWebControl.JS_RepairPartWindow(0, 0, 801, 400); // 多1个像素点防止还原后边界缺失一个像素条
//抠除左边界
if (iCoverLeft != 0) {
oWebControl.JS_CuttingPartWindow(0, 0, iCoverLeft, 401);
}
//抠除上边界
if (iCoverTop != 0) {
oWebControl.JS_CuttingPartWindow(0, 0, 801, iCoverTop); // 多剪掉一个像素条,防止出现剪掉一部分窗口后出现一个像素条
}
//抠除右边界
if (iCoverRight != 0) {
oWebControl.JS_CuttingPartWindow(801 - iCoverRight, 0, iCoverRight, 401);
}
//抠除下边界
if (iCoverBottom != 0) {
oWebControl.JS_CuttingPartWindow(0, 401 - iCoverBottom, 801, iCoverBottom);
}
//弹框示例位置扣除
if (showDivInstruction)
{
// 获取弹框的位置、尺寸信息
var oDivLightRect = document.getElementById('light').getBoundingClientRect();
iCoverLeft = (oDivLightRect.left - oDivRect.left < 0) ? 0 : oDivLightRect.left - oDivRect.left;
iCoverTop = (oDivLightRect.top - oDivRect.top < 0) ? 0 : oDivLightRect.top - oDivRect.top;
iCoverRight = (oDivLightRect.right - oDivRect.left < 0) ? 0 : oDivLightRect.right - oDivRect.left;
iCoverBottom = (oDivLightRect.bottom - oDivRect.top < 0) ? 0 : oDivLightRect.bottom - oDivRect.top;
iCoverLeft = (iCoverLeft > 800) ? 800 : Math.round(iCoverLeft);
iCoverTop = (iCoverTop > 400) ? 400 : Math.round(iCoverTop);
iCoverRight = (iCoverRight > 800) ? 800 : Math.round(iCoverRight);
iCoverBottom = (iCoverBottom > 400) ? 400 : Math.round(iCoverBottom);
//JS_CuttingPartWindow接口参照开发指南,参数为:抠图左上角点在插件窗口上的left长度、top长度、所扣除矩形区域的宽度、所扣除矩形区域的长度
oWebControl.JS_CuttingPartWindow(iCoverLeft - 1, iCoverTop - 1, iCoverRight - iCoverLeft + 2, iCoverBottom - iCoverTop + 2);
}
}
// 创建插件实例,并启动本地服务建立websocket连接,创建插件窗口
function initPlugin () {
oWebControl = new WebControl({
szPluginContainer: "playWnd",
iServicePortStart: 15900,
iServicePortEnd: 15909,
szClassId:"23BF3B0A-2C56-4D97-9C03-0CB103AA8F11", // 用于IE10使用ActiveX的clsid
cbConnectSuccess: function () {
initCount = 0;
setCallbacks();
oWebControl.JS_StartService("window", {
dllPath: "./VideoPluginConnect.dll"
}).then(function () {
oWebControl.JS_CreateWnd("playWnd", 800, 400).then(function () {
console.log("JS_CreateWnd success");
oWebControl.JS_RequestInterface({
funcName: "getRSAPubKey",
argument: JSON.stringify({
keyLength: 1024
})
}).then(function (oData) {
console.log(oData)
if (oData.responseMsg.data) {
pubKey = oData.responseMsg.data
}
});
});
}, function () {
});
},
cbConnectError: function () {
console.log("cbConnectError");
oWebControl = null;
$("#playWnd").html("插件未启动,正在尝试启动,请稍候...");
WebControl.JS_WakeUp("VideoWebPlugin://");
initCount ++;
if (initCount < 3) {
setTimeout(function () {
initPlugin();
}, 3000)
} else {
$("#playWnd").html("插件启动失败,请检查插件是否安装!");
}
},
cbConnectClose: function (bNormalClose) {
// 异常断开:bNormalClose = false
// JS_Disconnect正常断开:bNormalClose = true
console.log("cbConnectClose");
oWebControl = null;
}
});
}
initPlugin();
// 获取公钥
function getPubKey (callback) {
oWebControl.JS_RequestInterface({
funcName: "getRSAPubKey",
argument: JSON.stringify({
keyLength: 1024
})
}).then(function (oData) {
console.log(oData)
if (oData.responseMsg.data) {
pubKey = oData.responseMsg.data
callback()
}
})
}
// 设置窗口控制回调
function setCallbacks() {
oWebControl.JS_SetWindowControlCallback({
cbIntegrationCallBack: cbIntegrationCallBack
});
}
// 推送消息
function cbIntegrationCallBack(oData) {
showCBInfo(JSON.stringify(oData.responseMsg));
}
// RSA加密
function setEncrypt (value) {
var encrypt = new JSEncrypt();
encrypt.setPublicKey(pubKey);
return encrypt.encrypt(value);
}
// value为字符串,JS_RequestInterface仅接收json格式的变量,且需要先解析出argument,并且将argument字段的内容转为字符串
function requestInterface(value)
{
isJSON(value);
var JsonParam = JSON.parse(value);
var JsonArgument = JsonParam.argument;
JsonParam.argument = JSON.stringify(JsonArgument);
oWebControl.JS_RequestInterface(JsonParam).then(function (oData) {
console.log(oData)
showCBInfo(JSON.stringify(oData ? oData.responseMsg : ''));
});
}
// 显示接口返回的消息及插件回调信息
function showCBInfo(szInfo, type) {
if (type === 'error') {
szInfo = "<div style='color: red;'>" + dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss") + " " + szInfo + "</div>";
} else {
szInfo = "<div>" + dateFormat(new Date(), "yyyy-MM-dd hh:mm:ss") + " " + szInfo + "</div>";
}
$("#cbInfo").html(szInfo + $("#cbInfo").html());
}
$("#initBtn").click(function() {
var param = $("#initParam").val();
//删除字符串中的回车换行和空格
//param = param.replace(/(\s*)/g, "");
//解析初始化时的playMode字段
var initFuncType = $("#initFuncType").val();
if (0 == initFuncType)
{
isJSON(param);
var JsonParam = JSON.parse(param);
if (!JsonParam.hasOwnProperty("argument"))
{
showCBInfo("init failed, param miss argument field");
}
else
{
if (JsonParam.argument.hasOwnProperty("playMode"))
{
playMode = JsonParam.argument.playMode;
}
//隐藏/显示轮巡功能模块
document.getElementById("TourPreview").style.display= (0 == playMode && JsonParam.argument.hasOwnProperty("appkey")) ? "" : "none";
//如果包含加密处理,处理加密字段
if(JsonParam.argument.hasOwnProperty("encryptedFields"))
{
var enFields = JsonParam.argument.encryptedFields;
var strArray = new Array();
strArray = enFields.split(",");
for(var i = 0, len = strArray.length; i< len; i++)
{
if("appkey" == strArray[i])
{
if (JsonParam.argument.hasOwnProperty("appkey"))
{
var appkey = JsonParam.argument.appkey;
appkey = setEncrypt(appkey);
JsonParam.argument.appkey = appkey;
}
}
if("secret" == strArray[i])
{
if (JsonParam.argument.hasOwnProperty("secret"))
{
var secret = JsonParam.argument.secret;
secret = setEncrypt(secret);
JsonParam.argument.secret = secret;
}
}
if("ip" == strArray[i])
{
if (JsonParam.argument.hasOwnProperty("ip"))
{
var ip = JsonParam.argument.ip;
ip = setEncrypt(ip);
JsonParam.argument.ip = ip;
}
}
if("snapDir" == strArray[i])
{
if (JsonParam.argument.hasOwnProperty("snapDir"))
{
var snapDir = JsonParam.argument.snapDir;
snapDir = setEncrypt(snapDir);
JsonParam.argument.snapDir = snapDir;
}
}
if("layout" == strArray[i])
{
if (JsonParam.argument.hasOwnProperty("layout"))
{
var layout = JsonParam.argument.layout;
layout = setEncrypt(layout);
JsonParam.argument.layout = layout;
}
}
if("videoDir" == strArray[i])
{
if (JsonParam.argument.hasOwnProperty("videoDir"))
{
var videoDir = JsonParam.argument.videoDir;
videoDir = setEncrypt(videoDir);
JsonParam.argument.videoDir = videoDir;
}
}
}
}
//1.4.1及以上版本支持argument字段为json,以下版本argument必须为string
var JsonArgument = JsonParam.argument;
JsonParam.argument = JSON.stringify(JsonArgument);
}
//param = {
// "argument": '{"appkey": "21216099","ip": "172.7.13.242","port": 443,"secret": "dX5Gt0C0hmKbQ9ucHnWY","enableHTTPS": 1,"language": "zh_CN","layout": "2x2","playMode": 0,"reconnectDuration": 5,"reconnectTimes": 5,"showSmart": 0,"showToolbar": 1,"snapDir": "D:/snap","videoDir": "D:/video"}',
// "funcName": "init"
//}
oWebControl.JS_RequestInterface(JsonParam).then(function (oData) {
console.log(oData)
showCBInfo(JSON.stringify(oData ? oData.responseMsg : ''));
UpdatePlayParamValue();
oWebControl.JS_Resize(800, 400); //
});
}
else{
requestInterface(param);
}
})
$("#playBtn").click(function() {
var param = $("#playParam").val();
//删除字符串中的回车换行
//param = param.replace(/(\s*)/g, "");
requestInterface(param);
})
// 设置布局/获取布局
$("#layoutBtn").click(function() {
var param = $("#layoutParam").val();
//删除字符串中的回车换行
//param = param.replace(/(\s*)/g, "");
requestInterface(param);
})
//画面字符叠加
$("#drawOSDBtn").click(function (){
var param = $("#drawOSDParam").val();
//删除字符串中的回车换行
//param = param.replace(/(\s*)/g, "");
requestInterface(param);
})
// 进入全屏
$("#enterFullScreen").click(function (){
oWebControl.JS_RequestInterface({
funcName: "setFullScreen"
}).then(function (oData) {
console.log(oData)
showCBInfo(JSON.stringify(oData ? oData.responseMsg : ''));
});
})
// 退出全屏
$("#exitFullScreen").click(function (){
oWebControl.JS_RequestInterface({
funcName: "exitFullScreen"
}).then(function (oData) {
console.log(oData)
showCBInfo(JSON.stringify(oData ? oData.responseMsg : ''));
});
})
//抓图
$("#snapBtn").click(function (){
var param = $("#snapParam").val();
//删除字符串中的回车换行
//param = param.replace(/(\s*)/g, "");
requestInterface(param);
})
var timeStart = false;
var timer;
//轮巡,每隔10s执行一次
$("#startTourPreviewBtn").click(function (){
if (!timeStart)
{
timeStart = true;
var sel = document.getElementById("tourPreviewType");
var selectedId = sel.selectedIndex;
var v = sel.options[selectedId].value;
if (0 == v) // 单路播放轮巡
{
SingleTourPreview();
timer = window.setInterval(SingleTourPreview, 1000*10);
}
else{ // 批量播放轮巡
MultiTourPreview();
timer = window.setInterval(MultiTourPreview, 1000*10);
}
}
else{
showCBInfo('start tour preview failed, please stop tour preview first');
}
})
$("#stopTourPreviewBtn").click(function(){
window.clearInterval(timer);
timeStart = false;
})
// 单路播放轮巡函数
function SingleTourPreview() {
// 解析轮巡的监控点编号
var param = $("#TourPreviewCamIdx").val();
//param = param.replace(/(\s*)/g, "");
var cameraIndexArray = new Array();
cameraIndexArray = param.split(",");
var arraySize = cameraIndexArray.length;
// 获取当前窗口个数
var WndNum = 1;
oWebControl.JS_RequestInterface({
funcName: "getLayout"
}).then(function (oData) {
//分析窗口数
var Data = JSON.stringify(oData.responseMsg.data);
Data = Data.replace(/\\n/g, "");
Data = Data.replace(/\\/g, "");
Data = Data.replace(/\"{/g, "{");
Data = Data.replace(/}\"/g, "}");
WndNum = JSON.parse(Data).wndNum;
for (i = 0; i < WndNum; i++)
{
var cameraIdx = cameraIndexArray[i % arraySize];
var previewParam = JSON.stringify({
"argument": {
"authUuid": "",
"cameraIndexCode": cameraIdx,
"ezvizDirect": 0,
"gpuMode": 0,
"streamMode": 0,
"transMode": 1,
"wndId": i+1,
"cascade": 1
},
"funcName": "startPreview"
});
requestInterface(previewParam);
}
});
}
// 批量播放轮巡函数
function MultiTourPreview() {
// 解析轮巡的监控点编号
var param = $("#TourPreviewCamIdx").val();
//param = param.replace(/(\s*)/g, "");
var cameraIndexArray = new Array();
cameraIndexArray = param.split(",");
var arraySize = cameraIndexArray.length;
// 获取当前窗口个数
var WndNum = 1;
oWebControl.JS_RequestInterface({
funcName: "getLayout"
}).then(function (oData) {
//分析窗口数
var Data = JSON.stringify(oData.responseMsg.data);
Data = Data.replace(/\\n/g, "");
Data = Data.replace(/\\/g, "");
Data = Data.replace(/\"{/g, "{");
Data = Data.replace(/}\"/g, "}");
WndNum = JSON.parse(Data).wndNum;
var multiPlayParam = {
"argument": {
"list": []
},
"funcName": "startMultiPreviewByCameraIndexCode"
}
for (i = 0; i < WndNum; i++)
{
var PlayParam = {
"authUuid": "",
"cameraIndexCode": cameraIndexArray[i % arraySize],
"ezvizDirect": 0,
"gpuMode": 0,
"streamMode": 0,
"transMode": 1,
"wndId": i+1
}
multiPlayParam.argument.list.push(PlayParam);
}
var previewParam = JSON.stringify(multiPlayParam);
requestInterface(previewParam);
});
}
// 清空
$("#clear").click(function() {
$("#cbInfo").html('');
})
// 获取版本
$("#getVerSion").click(function() {
oWebControl.JS_RequestInterface({
funcName: "getVersion"
}).then(function (oData) {
console.log(oData)
showCBInfo(JSON.stringify(oData ? oData.responseMsg : ''));
});
})
// 使用说明
$("#instructions").click(function() {
//var instructionInfo = "1.插件demo使用前先安装对应版本的插件到本地机器; \n2.所有操作都需要先初始化,反初始化后,再次操作需要重新初始化; \n3.初始化指定ip、port、appkey、secret时,仅支持单平台接入,此时播放参数中authUuid字段非必填; \n4.初始化不指定ip、port、appkey、secret时,支持多平台接入,需要通过设置认证信息传入各平台的合作方信息,此时播放参数中authUuid字段必填;\n5.demo中轮巡模块只有在单平台接入预览时,才显示;多平台接入或回放时,默认隐藏";
//$("#cbInfo").html(instructionInfo + $("#cbInfo").html());
document.getElementById('light').style.display='block';
showDivInstruction = true;
setWndCover();
})
// 关闭隐藏弹框
function CloseInstructionsDiv()
{
document.getElementById('light').style.display='none';
showDivInstruction = false;
setWndCover();
}
// 判断字符串是否为json
function isJSON(str) {
if (typeof str == 'string') {
try {
var obj=JSON.parse(str);
if(typeof obj == 'object' && obj ){
return true;
}else{
showCBInfo("param is not the correct JSON message");
return false;
}
} catch(e) {
showCBInfo("param is not the correct JSON message");
return false;
}
}
console.log('It is not a string!')
}
// 格式化时间
function dateFormat(oDate, fmt) {
var o = {
"M+": oDate.getMonth() + 1, //月份
"d+": oDate.getDate(), //日
"h+": oDate.getHours(), //小时
"m+": oDate.getMinutes(), //分
"s+": oDate.getSeconds(), //秒
"q+": Math.floor((oDate.getMonth() + 3) / 3), //季度
"S": oDate.getMilliseconds()//毫秒
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (oDate.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}
function textbox(obj, min, max){
obj.value=obj.value.replace(/[^\d]/g,'');
if(parseInt(obj.value)==obj.value && parseInt(obj.value)>=min && parseInt(obj.value)<=max)
{}
else
{
if(parseInt(obj.value) < min)
{
obj.value = min;
}
if(parseInt(obj.value) > max)
{
obj.value = max;
}
}
}
</script>
</html>