ucservice 1.8.1 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3695 +0,0 @@
1
- /**
2
- * video工具类
3
- * @author xbb
4
- * @version r1.4.4.15
5
- * @update 20210518
6
- */
7
- (function (root, factory) {
8
- if (typeof define === 'function' && define.amd) {
9
- // AMD
10
- define(['jquery'], factory);
11
- } else if (typeof exports === 'object') {
12
- // Node, CommonJS之类的
13
- module.exports = factory(require('jquery'));
14
- } else {
15
- // 浏览器全局变量(root 即 window)
16
- root.scooper = root.scooper || {};
17
-
18
- root.scooper.video = factory(root.jQuery);
19
- }
20
- }(window, function ($) {
21
- "use strict";
22
-
23
- window.console = window.console || (function(){
24
- var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
25
- = c.clear = c.exception = c.trace = c.assert = function(){};
26
- return c;
27
- })();
28
-
29
- /**
30
- * 立即执行函数形式
31
- * 兼容IE8 indexOf
32
- */
33
- (function () {
34
- if(Array.prototype.indexOf) {
35
- return;
36
- }
37
- Array.prototype.indexOf = function(item) {
38
- var len = this.length >>> 0; //保证结构为非负数
39
-
40
- for(var i = 0; i<len ; i++) {
41
- if(i in this && this[i] === item) {
42
- return i;
43
- }
44
- }
45
- return -1;
46
- }
47
- })();
48
-
49
- /**
50
- * 闭包
51
- * 为事件添加唯一标识字符串
52
- */
53
- var guid = (function() {
54
- var id = 1;
55
- return function() {
56
- return 'SCVIDEO_ID_'+ (++id).toString();
57
- }
58
- })();
59
-
60
- /**
61
- * 公共方法
62
- * 判断是否为IE
63
- */
64
- function isIE() {
65
- return !!window.ActiveXObject || "ActiveXObject" in window;
66
- }
67
-
68
- /**
69
- * 公共方法
70
- * 克隆对象
71
- * 让新出来的对象是独立的
72
- */
73
- function cloneObj(obj) {
74
- var str, newObj = $.isArray(obj)?[]:{};
75
- if ( typeof obj != 'object' ) {
76
- return;
77
- }
78
-
79
- if (window.JSON) {
80
- str = JSON.stringify(obj);
81
- newObj = JSON.parse(str);
82
- } else {
83
- $.each(obj,function(key,val) {
84
- newObj[key] = typeof val == 'object' ? cloneObj(val) : val;
85
- });
86
- }
87
- return newObj;
88
- }
89
-
90
- /**
91
- * 公共方法
92
- * 提示
93
- */
94
- var showPrompt = true;
95
- function promptSuccess(msg, type) {
96
- console.log(msg);
97
- //panduanpromptView弹层对象是否引入
98
- 'undefined' != typeof(promptView) && showPrompt && promptView.showSuccess(msg);
99
- }
100
- function promptFailed(msg, type) {
101
- console.error(msg);
102
- 'undefined' != typeof(promptView) && showPrompt && promptView.showFailed(msg);
103
- }
104
- function promptAlarm(msg, type) {
105
- console.info(msg);
106
- 'undefined' != typeof(promptView) && showPrompt && promptView.showAlarm(msg);
107
- }
108
-
109
- /**
110
- * 公共方法
111
- * 判断能否获取本地声卡设备
112
- */
113
- function checkUserMediaAvailable() {
114
- return Janus.isGetUserMediaAvailable() && !checkIsHttp() && window.hasAudioInputDevices;
115
- }
116
-
117
- /**
118
- * 公共方法
119
- * 是否有声卡设备
120
- * 异步方法 结果保存在window.hasAudioInputDevices中 true or false
121
- */
122
- function hasMediaDevices() {
123
- if (window.checkAudioDevicesStatus != undefined && window.hasAudioInputDevices != undefined) {
124
- //已检测
125
- return;
126
- }
127
- //参数初始化,防止为空报错
128
- window.checkAudioDevicesStatus = false;
129
- window.hasAudioInputDevices = false;
130
- if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
131
- console.log("Not support enumerateDevices() .");
132
- return;
133
- }
134
- var startTime = new Date().getTime();
135
- // 列出相机和麦克风.
136
- navigator.mediaDevices.enumerateDevices()
137
- .then(function(devices) {
138
- devices.forEach(function(device) {
139
- if (device.kind == "audioinput") {
140
- //判断到1个就返回true
141
- window.hasAudioInputDevices = true;
142
- }
143
- });
144
- window.checkAudioDevicesStatus = true;
145
- console.log("检查音频输入设备总计耗时: " + (new Date().getTime() - startTime) + "ms");
146
- })
147
- .catch(function(err) {
148
- console.log(err.name + ": " + err.message);
149
- });
150
- }
151
-
152
- /**
153
- * 公共方法
154
- * 判断是否是http 或者 https
155
- */
156
- function checkIsHttp() {
157
- var protocolStr = document.location.protocol;
158
- if(protocolStr == "http:" || window.location.hostname == "localhost" ) return true;
159
- return false;
160
- }
161
-
162
- /**
163
- * 公共方法
164
- * 判断是否是https 和检测http分开的目的是还有本地打开的情况(前缀为file:)
165
- * webrtc规定打开摄像头、麦克风需要加密传输 所以需要再https环境下, 本地打开不需要加密 可以正常获取
166
- * 这也是分开的另一个目的
167
- */
168
- function checkIsHttps() {
169
- var protocolStr = document.location.protocol;
170
- if(protocolStr == "https:") return true;
171
- return false;
172
- }
173
-
174
- /**
175
- * 事件对象包装类,通过事件type,加载必要的属性
176
- * @class
177
- */
178
- function VideoEvent(type,target) {
179
- this.type = type;
180
- this.returnValue = true;
181
- this.target = target || null;
182
- this.currentTarget = null;
183
- }
184
-
185
- /**
186
- * 轮巡工具类
187
- */
188
- var PollTimer = /** @class */ (function () {
189
- function PollTimer(cb, time) {
190
- cb(true); // 首次执行
191
- this.timerId = setInterval(cb, time * 1000);
192
- }
193
- PollTimer.prototype.stop = function () {
194
- if (!this.timerId)
195
- return;
196
- clearInterval(this.timerId);
197
- this.timerId = 0;
198
-
199
- if (waitTimerId) {
200
- clearTimeout(waitTimerId);
201
- waitTimerId = null;
202
- }
203
- };
204
- return PollTimer;
205
- }());
206
-
207
-
208
- var waitTimerId = 0;
209
- function wait(time) {
210
- return new Promise(function(resolve, reject) {
211
- if (waitTimerId) {
212
- clearTimeout(waitTimerId);
213
- waitTimerId = null;
214
- }
215
- waitTimerId = setTimeout(resolve, time);
216
- });
217
- }
218
-
219
- /**
220
- * 事件
221
- */
222
- function Listener() {
223
- // 在构造函数中进行初始化
224
- this._listeners = {};
225
- }
226
-
227
- Listener.prototype = {
228
-
229
- constructor: Listener,
230
- /**
231
- * 添加事件
232
- */
233
- addListener: function(type, handler, key){
234
- if (typeof handler != 'function') {
235
- return;
236
- }
237
- var t = this._listeners,id;
238
- if (typeof key == "string" && key) {
239
- if (/[^\w\-]/.test(key)) {
240
- throw("nonstandard key:" + key);
241
- } else {
242
- handler.hashCode = key;
243
- id = key;
244
- }
245
- }
246
- type.indexOf("on") != 0 && (type = "on" + type);
247
- typeof t[type] != "object" && (t[type] = {});
248
- id = id || guid();
249
- handler.hashCode = id;
250
- t[type][id] = handler;
251
- },
252
-
253
- /**
254
- * 删除事件
255
- */
256
- removeListener: function(type, handler){
257
- type.indexOf("on") != 0 && (type = "on" + type);
258
- var t = this._listeners;
259
- if (!t[type]) {
260
- return;
261
- }
262
- if (handler) {
263
- if (typeof handler == 'function') {
264
- handler = handler.hashCode;
265
- }else if (typeof key != "string"){
266
- return;
267
- }
268
- t[type][handler] && delete t[type][handler];
269
- }else{
270
- t[type] = {};
271
- }
272
- },
273
-
274
- /**
275
- * 派发事件
276
- */
277
- dispatch: function(e, options){
278
- if (typeof e == 'string') {
279
- e = new VideoEvent(e);
280
- }
281
- options = options || {};
282
- for (var i in options) {
283
- e[i] = options[i];
284
- }
285
- var i, t = this._listeners, p = e.type;
286
- e.target || (e.target = this);
287
- e.currentTarget = this;
288
- p.indexOf("on") != 0 && (p = "on" + p);
289
- typeof this[p] == 'function' && this[p].apply(this, arguments);
290
- if (typeof t[p] == "object") {
291
- for (i in t[p]) {
292
- t[p][i].call(this, e);
293
- }
294
- }
295
- return e.returnValue;
296
- },
297
-
298
- /**
299
- * 清空事件
300
- */
301
- removeAllListeners: function () {
302
- this._listeners = {};
303
- }
304
- }
305
-
306
- /**
307
- * 使用ocx方式的video工具类
308
- * @author savage
309
- * @version 1.0.0
310
- */
311
- function VideoOcx($dom, opts){
312
- this.videoListener = new Listener();
313
- if (!isIE()) {
314
- console.log('视频控件不支持非IE浏览器');
315
- return this._getTipObj();
316
- }
317
- if (!opts) {
318
- console.error('VideoOcx的参数opts不能为空');
319
- return;
320
- }
321
- this._init($dom,opts);
322
- }
323
-
324
- /**
325
- * 使用ocx方式的视频播放的方法
326
- */
327
- VideoOcx.prototype = {
328
-
329
- constructor: VideoOcx,
330
- /**
331
- * 播放视频
332
- * 参数:index(视频窗口编号,从0开始) video(视频设备id,即devId) id(标识,空的话使用设备id) opts(其他参数)
333
- * 返回true/false
334
- */
335
- play: function(index, video, id, opts){
336
- /*if (!$.isNumeric(video*1)) {
337
- throw new Error('video is not number,id = '+id);
338
- }*/
339
- console.log("play >>> " + "video=" + video + "; id=" + id + "; index=" + index);
340
- this.dispatch('beforeplay',{index:index, video:video, id:id});
341
-
342
- this._obj.SCWebSetCurrentWindow(index);
343
- var playId = this._obj.SCWebRealPlay(video, this._opts.streamType);
344
- console.log("play = " + playId);
345
-
346
- opts = opts || {};
347
- playId > 0 && (this.videoStatus[index] = {
348
- video: video,
349
- id: id,
350
- playId: playId,
351
- opts:opts
352
- },this.dispatch('playsuccess', this.videoStatus[index]));
353
-
354
- if (playId < 0) {
355
- var name = opts.name || '视频';
356
- promptFailed(name + '播放失败!');
357
- }
358
-
359
- return playId > 0;
360
- },
361
-
362
- /**
363
- * 在序号最小的空闲窗口播放视频
364
- * 参数:index(视频窗口编号,从0开始) video(视频设备id,即devId) opts(其他参数)
365
- * 返回true/false
366
- */
367
- playByOrder: function(video, id, opts){
368
- var freeWindow = this._getMinIndexFreeWindow(0);
369
-
370
- if(freeWindow == -1 &&
371
- (this._getChoiceWindow() != -1 && !this.getInChoiceVideo())){
372
- return this.playInChoice(video,id,opts);
373
- }
374
- return this.play(freeWindow,video,id,opts);
375
- },
376
-
377
- /**
378
- * 扩展视频窗口数的播放方式
379
- */
380
- playByOrderExpandWindow: function(video,id,opts){
381
-
382
- var freeWindow = this._getMinIndexFreeWindow(0);
383
-
384
- var maxWindows = this._opts.windowsNum || 16;
385
-
386
- while (this._opts.windows < maxWindows && freeWindow == -1) {
387
- var zoom = Math.sqrt(this._opts.windows*1)+1;
388
-
389
- if (this._opts.windows == 6) {
390
- this.setWindowsNum(9);
391
- } else {
392
- this.setWindowsNum(Math.pow(zoom,2));
393
- }
394
-
395
- freeWindow = this._getMinIndexFreeWindow(zoom-1);
396
- }
397
-
398
- if(freeWindow == -1 ||
399
- (this._getChoiceWindow() != -1 && !this.getInChoiceVideo())){
400
- return this.playInChoice(video,id,opts);
401
- }
402
- return this.play(freeWindow,video,id,opts);
403
- },
404
-
405
- /**
406
- * 播放所有视频
407
- */
408
- playAll: function(array){
409
- if (array.length > this._opts.windows) {
410
- throw new Error('windows is not enough');
411
- }
412
- var me = this;
413
- me.closeAll();
414
- $.each(array,function(i,obj){
415
- me.play(i,obj.video,obj.id,obj.opts);
416
- });
417
- },
418
- /**
419
- * 在鼠标选中的窗口中播放视频
420
- */
421
- playInChoice: function(video,id,opts){
422
- var index = this._obj.SCWebGetCurrentWindowIndex();
423
- this.videoStatus[index] && this.close(index);
424
- return this.play(index,video,id,opts);
425
- },
426
- /**
427
- * 如果被指定的窗口有视频id,则播放
428
- */
429
- playMulWindows: function(indexs) {
430
- var me = this;
431
- $.each(indexs,function(i,index){
432
- me.videoStatus[index] && me.play(index,me.videoStatus[index].video,me.videoStatus[index].id);
433
- });
434
- },
435
- /**
436
- * 检索当前点的视频是否被播放,被播放则返回播放的视频窗口
437
- */
438
- isPlaying: function(id){
439
- var index = -1;
440
- $.each(this.videoStatus,function(key,val){
441
- if (id == val.id) {
442
- index = key;
443
- return false;
444
- }
445
- });
446
- return index;
447
- },
448
-
449
- /**
450
- * 判断指定窗口是否正在播放视频
451
- */
452
- isPlayingByIndex: function(index){
453
- return this.videoStatus[index] && true;
454
- },
455
-
456
- /**
457
- * 获取视频数据
458
- */
459
- getVideoData: function(){
460
- return this.videoStatus;
461
- },
462
-
463
- /**
464
- * 关闭语音
465
- * @param index
466
- */
467
- closeVoice: function(index) {
468
- this._obj.SCWebVoiceComControl(this.videoStatus[index].video, this.videoStatus[index].playId, 0);
469
- },
470
-
471
- /**
472
- * 根据playId获取窗口
473
- * @param playId
474
- * IE下才有该方法
475
- */
476
- getWindowByPlayId: function(playId) {
477
- var index = -1;
478
- $.each(this.videoStatus,function(key,val){
479
- if (playId == val.playId) {
480
- index = key;
481
- return false;
482
- }
483
- });
484
- return index;
485
- },
486
-
487
- /**
488
- * 根据窗口获取playId
489
- * @param index
490
- * IE下才有该方法
491
- */
492
- getPlayIdBywindow : function(index) {
493
- return this.videoStatus[index].playId;
494
- },
495
-
496
- /**
497
- * 关闭指定窗口的视频
498
- */
499
- close: function(index, isSave){
500
-
501
- if (!this.videoStatus[index] || index >= this._opts.windows || this._disableClosed.indexOf(index*1) > -1 ) {
502
- return;
503
- }
504
- this._obj.SCWebSetCurrentWindow(index);
505
- var close = this._obj.SCWebStopRealPlay(this.videoStatus[index].playId);
506
- console.log("close = "+close);
507
-
508
- if (!isSave) {
509
- this.videoStatus[index].closeType = 'close';
510
- this.dispatch('afterclose',this.videoStatus[index]);
511
- delete this.videoStatus[index];
512
- }
513
-
514
- },
515
-
516
- /**
517
- * 关闭指定视频编号正在播放的视频
518
- */
519
- closeByVideo: function(video, isSave){
520
- var me = this;
521
-
522
- if (video == undefined) {
523
- console.info('video参数错误');
524
- return;
525
- }
526
-
527
- var videoData = me.videoStatus;
528
- if (!videoData || videoData.length == 0) {
529
- return;
530
- }
531
-
532
- for (var i in videoData) {
533
- if (video == videoData[i].video) {
534
- me.close(videoData[i].index);
535
- }
536
- }
537
- },
538
-
539
- /**
540
- *
541
- */
542
- closeHistory: function(playId) {
543
- var close = this._obj.SCWebStopRealPlay(playId);
544
- console.log("close = "+close);
545
- var index = this._getChoiceWindow();
546
- delete this.videoStatus[index];
547
- },
548
-
549
- /**
550
- * 关闭所有视频
551
- * TODO 不可关闭
552
- */
553
- closeAll: function(isSave){
554
- var me = this;
555
- isSave || (this._disableClosed = []);
556
- var windows = me._obj.SCWebGetRealPlayWindows();
557
- console.log('要关闭的视频窗:' + windows);
558
- if (windows) {
559
- $.each(windows.split(','),function(i,index){
560
- me.close(index,isSave);
561
- console.log('窗口:' + i);
562
- });
563
- }
564
- },
565
-
566
- /**
567
- * 获取视频窗口
568
- * @returns
569
- */
570
- getWindowsPlay : function() {
571
- var me = this;
572
- var windows = me._obj.SCWebGetRealPlayWindows();
573
- return windows;
574
- },
575
-
576
- /**
577
- * 设置鼠标选中窗口
578
- */
579
- setChoiceWindow: function(index) {
580
- this._obj.SCWebSetCurrentWindow(index);
581
- },
582
- /**
583
- * 获取视频窗口数
584
- */
585
- getWindowsNum: function() {
586
- return this._opts.windows;
587
- },
588
-
589
- /**
590
- * 是否还有空闲窗口
591
- */
592
- hasFreeWindow: function() {
593
- return this._obj.SCWebGetFreeWindows() != '';
594
- },
595
-
596
- /**
597
- * 设置视频窗口数
598
- */
599
- setWindowsNum: function(num,extra) {
600
- var me = this;
601
- num = num*1;
602
- var result;
603
- if (extra) {
604
- result = me._obj.SCWebDecoderSetExtraScreenMode(num);
605
- } else {
606
- result = me._obj.SCWebDecoderSetScreenMode(num);
607
- }
608
- console.log("setWindowsNum >>> " + "result=" + result);
609
- /*extra
610
- ? me._obj.SCWebDecoderSetExtraScreenMode(num)
611
- : me._obj.SCWebDecoderSetScreenMode(num);*/
612
- num = num == 66 ? 6 : num;
613
- me._changeWindowsAction(num);
614
- me.dispatch('screenchange',{windowNums: num});
615
- me._opts.windows = num;
616
- me._opts.extra = extra;
617
-
618
- },
619
-
620
- /**
621
- * 询问是否无可用窗口
622
- */
623
- isUnavailable: function() {
624
- return this._opts.windows == 16 && !this.hasFreeWindow();
625
- },
626
-
627
- disableClosed: function(num){
628
- $.isNumeric(num) ? this._disableClosed.push(num) :
629
- $.isArray(num) && (this._disableClosed = this._disableClosed.concat(num));
630
-
631
- },
632
-
633
- enableClosed: function(){
634
- this._disableClosed = [];
635
- },
636
-
637
- //轮巡就是建立一个轮巡数组,然后根据最大屏幕数去遍历数组,记录当前轮巡下标,并标记该视频已被打开,如果视频关闭后 将视频标记为未关闭,建立一个定时器反复去执行这些动作。
638
- //如果要执行之前视频的记录保存,那么关闭轮巡的关闭方法就需要重新写,或者关闭的时候加一个参数去判断。
639
-
640
- //云台就是调用 dataHolder方法
641
- /**
642
- * 执行轮巡
643
- */
644
- startPoll: function(array,time) {
645
- if (!array || array.length == 0) {
646
- promptAlarm('请选择视频设备!');
647
- return false;
648
- }
649
-
650
- time = $.isNumeric(time) ? time : this._opts.pollInterval;
651
- this._pollArray = array;
652
- var me = this,
653
- windowNum = me._opts.windows,
654
- maxNum = array.length,
655
- nowNum = 0 ;
656
- me.saveList();
657
-
658
- //延迟
659
- me.delayTimeId = 0;
660
-
661
- me._polltimer = new PollTimer(function(firstRun){
662
- me.closeAll();
663
-
664
- if (me.delayTimeId) {
665
- clearTimeout(me.delayTimeId);
666
- }
667
-
668
- me.delayTimeId = setTimeout(function() {
669
- for(var i = 0; i < windowNum; i++) {
670
- if(nowNum == maxNum){
671
- nowNum = 0;
672
- if(maxNum < windowNum) {
673
- break;
674
- }
675
- }
676
-
677
- me.playByOrder(array[nowNum].video, array[nowNum].id, array[nowNum].opts);
678
- nowNum++;
679
- }
680
- if (firstRun) {
681
- me.dispatch('startpoll', array);
682
- }
683
- }, 1000)
684
- }, time);
685
- },
686
-
687
- /**
688
- * 结束轮巡
689
- */
690
- stopPoll: function() {
691
- if(!this._polltimer){
692
- return;
693
- }
694
- this._polltimer.stop();
695
- this._polltimer = undefined;
696
- console.log('------> 轮巡结束 <-------');
697
- this.dispatch('stoppoll', {});
698
- //恢复之前打开的视频
699
- this.playSaveList();
700
- },
701
-
702
- /**
703
- * 获取是否在轮巡
704
- */
705
- isPolling: function() {
706
- return !!this._polltimer;
707
- },
708
-
709
- /**
710
- * 云台控制
711
- * up 上
712
- * down 下
713
- * left 左
714
- * right 右
715
- * upleft 上左
716
- * upright 上右
717
- * downleft 下左
718
- * downright 下右
719
- * zoomin 倍率变大
720
- * zoomout 倍率变下
721
- * focusnear 焦点+
722
- * focusfar 焦点-
723
- * irisopen 光圈+
724
- * irisclose 光圈-
725
- * pointset 设置预置点
726
- * pointdel 删除预置点
727
- * pointgoto 到预置点
728
- * scansetleft 自动扫描左边界
729
- * scansetright 自动扫描又边界
730
- * scansetspeed 设置扫描速度
731
- * scanrun 自动扫描运行
732
- * cruiseadd 添加巡航点
733
- * cruisedel 删除巡航点
734
- * cruisespeed 设置巡航点速度
735
- * cruisepausetime 设置巡航滞留时间
736
- * cruiserun 启动巡航
737
- */
738
- holder: function(type, opts, isStop) {
739
- var index = this._getChoiceWindow();
740
- if( !this.videoStatus[index] ){
741
- promptAlarm('未选中播放的视频!');
742
- return;
743
- }
744
-
745
- var holdType = 'up down left right upleft upright downleft downright zoomin zoomout focusnear focusfar irisopen irisclose pointset pointdel pointgoto '+
746
- 'scansetleft scansetright scansetspeed scanrun cruiseadd cruisedel cruisespeed cruisepausetime cruiserun';
747
-
748
- var typeVal = (Number(holdType.split(' ').indexOf(type))+Number(1));
749
- console.log("holdType:" + typeVal + " type:" + type + (isStop ? ' 停止' : ''));
750
-
751
- if (!typeVal || typeVal <= 0) {
752
- console.error('异常PTZ指令:' + typeVal);
753
- }
754
-
755
- var video = this.videoStatus[index].video;
756
-
757
- if(isStop) {
758
- //var playerId = this._obj.SCWebGetCurrentPlayID();
759
- var result = this._obj.SCWebPTZControl(video,1,typeVal,0,0,0,0);
760
- //var result = this._obj.SCWebPTZControlEx(playerId, 4, 1, 1);
761
- console.log(">>>>yuntai control,stop, video=" + video + ", result=" + result);
762
- return;
763
- }
764
- var _opts = {
765
- speed: 200,
766
- group: 0,
767
- present: 0,
768
- time:0
769
- }
770
- $.extend(_opts,opts);
771
- this._obj.SCWebPTZControl(video, 0,
772
- typeVal, _opts.speed, _opts.group, 1, _opts.time);
773
- console.log('设备号:'+ video +', 云台移动-->'+ type);
774
- },
775
-
776
- /**
777
- * 视频回放
778
- * @param startTime [YYYY-MM-DDTHH:mm:ss]
779
- * @param endTime
780
- * @return playId
781
- */
782
- playHistory: function(video,startTime,endTime,opts) {
783
- var me = this;
784
- var playId = me._obj.SCWebHistoryPlay(video, startTime, endTime);
785
- console.log("play = " + playId);
786
-
787
- if (playId < 0) {
788
- var name = opts.name || '视频';
789
- promptFailed(name + '播放失败!');
790
- return playId;
791
- }
792
-
793
- var index = me._getChoiceWindow();
794
-
795
- opts = opts || {};
796
- playId > 0 && (me.videoStatus[index] = {
797
- video: video,
798
- id: video,
799
- playId: playId,
800
- opts: opts,
801
- isPlayBack: true
802
- }, me.dispatch('playsuccess', me.videoStatus[index]));
803
-
804
- return playId;
805
- },
806
-
807
- /**
808
- * 历史流控制
809
- * @param {number} playId
810
- * @param {string} playType 播放类型(play && pause)
811
- * @param {numner} playSpeed 播放速率
812
- * @param {string} startTime 回放时间(暂时无用)
813
- */
814
- historyControl: function(playId, playType, playSpeed, startTime) {
815
- var contorlType = {
816
- play: 1,
817
- pause: 2
818
- };
819
-
820
- var playCommand = contorlType[playType];
821
- if (!playCommand) {
822
- console.error('unsupported type: ', playType);
823
- return;
824
- }
825
-
826
- this._obj.SCWebHistoryControl(playId, playCommand, playSpeed, startTime);
827
- },
828
-
829
- /**
830
- * 历史流控制(原)
831
- */
832
- _historyControl: function(playId,type,speed,startTime) {
833
- var contorlType = {
834
- normal: 1,
835
- pause: 2,
836
- 'continue': 3
837
- };
838
- var commad = 1;
839
-
840
- type == 'speed' ? speed && speed < 1 ? (commad = 7 , speed = 1/speed) : commad = 6
841
- : commad = contorlType[type];
842
-
843
- this._obj.SCWebHistoryControl(playId,commad,speed);
844
-
845
- },
846
-
847
- /**
848
- * 跳转历史流
849
- */
850
- skipHistory: function(playId,time) {
851
- this._obj.SCWebHistorySeekPlay(playId,time);
852
- },
853
-
854
- /**
855
- * 抓图
856
- * @return 0:失败|1:成功
857
- */
858
- capturePicture: function(playId) {
859
- var videoCapImagePath = this._opts.videoCapImagePath ? this._opts.videoCapImagePath : '';
860
- return this._obj.SCWebCapturePicture(playId, videoCapImagePath, '');
861
- },
862
-
863
-
864
- saveList: function() {
865
- this._saveList = cloneObj(this.videoStatus);
866
- },
867
-
868
- playSaveList: function() {
869
- if (!this._saveList) {
870
- return;
871
- }
872
- this.closeAll();
873
- var me = this;
874
- $.each(this._saveList,function(index,obj){
875
- me.play(index, obj.video, obj.id, obj.opts);
876
- });
877
- },
878
-
879
- /**
880
- * 获取当前选择窗口的视频video
881
- */
882
- getInChoiceVideo: function() {
883
- return this.videoStatus[this._obj.SCWebGetCurrentWindowIndex()];
884
- },
885
-
886
- /**
887
- * 获取当前选择的窗口的playId
888
- */
889
- getInChoicePlayId: function() {
890
- return this._obj.SCWebGetCurrentPlayID();
891
- },
892
-
893
- /**
894
- * 设置全屏
895
- */
896
- setFullScreen: function() {
897
- this._obj.ScWebFullScreen(1);
898
- },
899
-
900
- /**
901
- * 获取当前视频控件的配置项
902
- */
903
- getVideoControllerOpts: function() {
904
- return this._opts;
905
- },
906
-
907
- /**
908
- * 获取截屏数据
909
- */
910
- getScreenCaptureData: function(index, callback) {
911
- var msg = 'IE下暂不支持获取截屏数据!';
912
- console.log(msg);
913
- throw Error(msg);
914
- },
915
-
916
- /**
917
- * 添加事件
918
- */
919
- addListener: function(type,handler,key){
920
- this.videoListener.addListener(type,handler,key);
921
- },
922
-
923
- /**
924
- * 删除事件
925
- */
926
- removeListener: function(type,handler){
927
- this.videoListener.removeListener(type,handler);
928
- },
929
- /**
930
- * 派发事件
931
- */
932
- dispatch: function(e,options){
933
- this.videoListener.dispatch(e,options);
934
- },
935
-
936
- /**
937
- * 获取ocx的版本信息
938
- */
939
- getOcxVersion: function() {
940
- return this._obj.SCWebDecoderGetVersion();
941
- },
942
-
943
- /*
944
- * 总的初始化
945
- * 参数示例:
946
- * var opts = {
947
- windows: 4, //初始化的窗口数
948
- conf: { //配置参数
949
- user: conf['video.username'], //用户名
950
- passwd: conf['video.password'], //密码
951
- ip: conf['video.ip'], //videoServer ip
952
- port: conf['video.port'], //videoServer port
953
- token : token //通讯录令牌,若token非空,则用户名和密码可不传
954
- },
955
- extra: false,
956
- streamType: 0, //码流类型 默认0
957
- openChangeWindowStrategy: true, //打开策略,切屏:属性为true,则当从大分屏切换到小分屏的时候会保留被关闭的视频,如果未设置 则不保留
958
- capImage: true, //是否截屏:属性为true的时候,视频上会浮现控制条,进行截图、云台控制操作
959
- videoCapImagePath: conf['video.cap.image.path'] //截屏默认保存的地址
960
- pollInterval: 30 //轮巡时间,单位秒
961
- };
962
- */
963
- _init: function($dom,opts){
964
- var me = this;
965
- //配置项
966
- me._opts = {
967
- windows: 4,
968
- conf: {},
969
- extra: false,
970
- ocxName: '__videoDiv',
971
- streamType: 0,
972
- openChangeWindowStrategy: false,
973
- capImage: false,
974
- videoCapImagePath: '',
975
- pollInterval: 10
976
- };
977
-
978
- $.extend(me._opts,opts);
979
- var windowsArr = me._opts.windowsArr;
980
- if (!windowsArr || windowsArr.length == 0) {
981
- me._windowList = {1:{}, 4:{}, 6:{}, 9:{}, 16:{}};
982
- me._windowsArr = [1, 4, 6, 9, 16];
983
- } else {
984
- me._windowList = {};
985
- for (var index in windowsArr){
986
- var item = windowsArr[index];
987
- me._windowList[item] = {};
988
- }
989
- me._windowsArr = windowsArr;
990
- }
991
-
992
- //me._windowList = {1:{},2:{},3:{},4:{}}
993
-
994
- if (!$.isNumeric(me._opts.pollInterval)) {
995
- console.error('pollInterval should be number');
996
- return;
997
- }
998
-
999
- //是否提示
1000
- me._opts.showPrompt === false && (showPrompt = false);
1001
- //事件注册区域
1002
- me._addStopHandler();
1003
- me._addClickHandler();
1004
- me._addHisHandler();
1005
- me._addCapPicHandler();
1006
- me._addHistoryPlayHandler();
1007
-
1008
- //浏览器刷新/关闭前执行
1009
- me._beforeUnload();
1010
-
1011
- //当前视频窗口的值
1012
- me.videoStatus = {};
1013
- //不可关闭的窗口
1014
- me._disableClosed = new Array();
1015
- //动态生成monitor对象
1016
- me._obj = $('<OBJECT>').attr({
1017
- id: me._opts.ocxName,
1018
- name: me._opts.ocxName,
1019
- classid: 'clsid:5D62BFBF-7B2D-4E9E-A359-5228400C77BC',
1020
- width: '100%',
1021
- height: '100%'
1022
- });
1023
- $dom.append(me._obj);
1024
-
1025
- me._obj = me._obj[0];
1026
-
1027
-
1028
- var conf = me._opts.conf;
1029
- //初始化和登录
1030
- var init = me._obj.ScWebDecoderInit(0);
1031
- console.log('init:' + init);
1032
- //是否开启抓图
1033
-
1034
- conf.ip == '127.0.0.1' && (conf.ip = location.hostname);
1035
-
1036
- var login;
1037
- if(conf.token && conf.token.length > 0 && me._obj.SCWebDecoderLoginInVS_Token) {
1038
- login = me._obj.SCWebDecoderLoginInVS_Token(conf.token, conf.ip, conf.port);
1039
- } else {
1040
- login = me._obj.SCWebDecoderLoginInVs(conf.user, conf.passwd, conf.ip, conf.port);
1041
- }
1042
- console.log('login:' + login);
1043
-
1044
- //调整分屏模式
1045
- setTimeout(function(){
1046
- //设置云台抓图控制按钮
1047
- me._opts.capImage && me._obj.SCWebSetPtzButtonLayout('');
1048
-
1049
- me._opts.extra
1050
- ? me._obj.SCWebDecoderSetExtraScreenMode(me._opts.windows)
1051
- : me._obj.SCWebDecoderSetScreenMode(me._opts.windows);
1052
- }, 100);
1053
-
1054
- },
1055
-
1056
- /**
1057
- * TODO 添加注释
1058
- */
1059
- _getTipObj: function() {
1060
- var obj = {};
1061
- var fncName = 'play playByOrder playAll playInChoice playMulWindows click getWindowsNum setWindowsNum',
1062
- fncName2 = 'isPlaying setChoiceWindow close closeAll enableClosede disableClosed addListener removeListener dispatch';
1063
- $.each(fncName.split(' '),function(i,name) {
1064
- obj[name] = function() {
1065
- alert('不支持非IE环境');
1066
- }
1067
- });
1068
- $.each(fncName2.split(' '),function(i,name) {
1069
- obj[name] = function() {
1070
- console.log('不支持非IE环境');
1071
- }
1072
- });
1073
- obj.type = 'disable';
1074
- return obj;
1075
- },
1076
-
1077
- /**
1078
- * 获取编号最小的空闲窗口的编号
1079
- */
1080
- _getMinIndexFreeWindow: function(searchedZoom) {
1081
- searchedZoom = searchedZoom || 0;
1082
- var index = Math.ceil(Math.pow(searchedZoom,2));
1083
- for (; index < this._opts.windows ; index++) {
1084
- if (!this.videoStatus[index]) {
1085
- return index;
1086
- }
1087
- }
1088
- return -1;
1089
- },
1090
-
1091
- /**
1092
- * 获取选择的窗口的编号
1093
- */
1094
- _getChoiceWindow: function(){
1095
- // var playId = this._obj.SCWebGetCurrentPlayID();
1096
- // var index;
1097
- // if (playId > 0) {
1098
- // index = this._obj.SCWebGetRealPlayWindows().split(',')[0];
1099
- // this.setChoiceWindow(index ? index : 0);
1100
- // }
1101
- // return index;
1102
- return this._obj.SCWebGetCurrentWindowIndex();
1103
- },
1104
-
1105
- /**
1106
- * 切换分屏
1107
- */
1108
- /* _changeWindowsAction: function(num) {
1109
- var me = this,
1110
- old = me._opts.windows,
1111
- now = num,
1112
- oldZoom = Math.sqrt(old),
1113
- nowZoom = Math.sqrt(now);
1114
- if (old == now) {
1115
- return;
1116
- }
1117
- if (me._opts.openChangeWindowStrategy) {
1118
- if (old > now) {
1119
- for (; now < old ; now++) {
1120
- var tempZoom = Math.ceil(Math.sqrt(now+1));
1121
-
1122
- me.videoStatus[now] && (me._windowList[tempZoom][now] = {
1123
- video: me.videoStatus[now].video,
1124
- id: me.videoStatus[now].id,
1125
- opts: me.videoStatus[now].opts,
1126
- },
1127
- me.close(now));
1128
- }
1129
-
1130
- } else {
1131
- while (oldZoom < nowZoom) {
1132
- oldZoom = oldZoom+1;
1133
- me._windowList[oldZoom] && $.each(me._windowList[oldZoom],function(index,obj) {
1134
- me.play(index, obj.video, obj.id, obj.opts);
1135
- });
1136
- me._windowList[oldZoom] = {};
1137
- }
1138
- }
1139
- } else {
1140
- if (old > now) {
1141
- for (; now < old ; now++) {
1142
- me.videoStatus[now] && me.close(now);
1143
- }
1144
- }
1145
- }
1146
- },*/
1147
-
1148
- /**
1149
- * 切换分屏
1150
- */
1151
- _changeWindowsAction: function(num) {
1152
- var me = this,
1153
- old = me._opts.windows,
1154
- now = num;
1155
- // oldZoom = Math.sqrt(old),
1156
- // nowZoom = Math.sqrt(now);
1157
- if (old == now) {
1158
- return;
1159
- }
1160
- if (me._opts.openChangeWindowStrategy) {
1161
- if (old > now) {
1162
- for (; now < old ; now++) {
1163
- //var tempZoom = Math.ceil(Math.sqrt(now+1));
1164
- var tempZoom = me._getWindowsNum(now + 1);
1165
-
1166
- me.videoStatus[now] && (me._windowList[tempZoom][now] = {
1167
- video: me.videoStatus[now].video,
1168
- id: me.videoStatus[now].id,
1169
- opts: me.videoStatus[now].opts
1170
- },
1171
- me.close(now));
1172
- }
1173
-
1174
- } else {
1175
- while (old < now) {
1176
- old = me._getNextWindowsNum(old);
1177
- me._windowList[old] && $.each(me._windowList[old],function(index,obj) {
1178
- me.play(index, obj.video, obj.id, obj.opts);
1179
- });
1180
- me._windowList[old] = {};
1181
- }
1182
- }
1183
- } else {
1184
- if (old > now) {
1185
- for (; now < old ; now++) {
1186
- me.videoStatus[now] && me.close(now);
1187
- }
1188
- }
1189
- }
1190
- },
1191
-
1192
- /**
1193
- * 获取当前的分屏数
1194
- * now为当前窗口的编号
1195
- */
1196
- _getWindowsNum: function(now) {
1197
- var me = this;
1198
- var windowsArr = me._windowsArr;
1199
- for (var index in windowsArr){
1200
- if (now <= windowsArr[index]) {
1201
- return windowsArr[index];
1202
- }
1203
- }
1204
- },
1205
-
1206
- /**
1207
- * 获取下一窗口
1208
- */
1209
- _getNextWindowsNum: function(old) {
1210
- var me = this;
1211
- var windowsArr = me._windowsArr;
1212
- for (var index in windowsArr){
1213
- if (index == windowsArr.length - 1) {
1214
- return windowsArr[index];
1215
- }
1216
- if (old == windowsArr[index]) {
1217
- return windowsArr[Number(index) + Number(1)];
1218
- }
1219
- }
1220
- },
1221
-
1222
- _addStopHandler: function() {
1223
- var me = this;
1224
- window.stopVideo = function(playId,videoId) {
1225
- if (me.getWindowByPlayId(playId) != -1 &&
1226
- me.videoStatus[me.getWindowByPlayId(playId)].isPlayBack) {
1227
- me.closeHistory(playId);
1228
- } else {
1229
- me.close(me.getWindowByPlayId(playId));
1230
- }
1231
-
1232
- me.dispatch('streamoff', {playId:playId,videoId:videoId});
1233
- };
1234
- me._regEvent('SCWebStopVideoEvent(playId,videoId)', 'stopVideo(playId,videoId);');
1235
-
1236
- },
1237
-
1238
- _addClickHandler: function() {
1239
- var me = this;
1240
- window.clickVideo = function(playId) {
1241
- me.dispatch('click',me.videoStatus[me.getWindowByPlayId(playId)]);
1242
- };
1243
- me._regEvent('SCWebDecoderClick(playId,type)', 'clickVideo(playId);');
1244
- },
1245
-
1246
- _addHisHandler: function() {
1247
- var me = this;
1248
- window.playbackVideo = function(playId,videoId,historytime) {
1249
- me.dispatch('playback',{playId:playId,videoId:videoId,historyTime:historytime});
1250
- };
1251
- me._regEvent('SCWebHistoryPlayTime(playId,videoId,historytime)', 'playbackVideo(playId,videoId,historytime);');
1252
- },
1253
-
1254
- //监听截图事件
1255
- _addCapPicHandler: function() {
1256
- var me = this;
1257
- window.getCapPicPath = function(playId, capPicPath, capPicName) {
1258
- me.dispatch('getCapPicPath', {playId:playId, capPicPath:capPicPath, capPicName: capPicName});
1259
- };
1260
- me._regEvent('SCWebGetCapPicPathName(playId, capPicPath, capPicName)', 'getCapPicPath(playId, capPicPath, capPicName);');
1261
- },
1262
-
1263
- //监听点击视频框的历史回放
1264
- _addHistoryPlayHandler: function() {
1265
- var me = this;
1266
- window.historyPlay = function(playId, videoId) {
1267
- me.dispatch('historyPlay', {playId:playId, videoId:videoId});
1268
- };
1269
- me._regEvent('SCWebHistoryPlayEvent(playId, videoId)', 'historyPlay(playId, videoId);');
1270
- },
1271
-
1272
- _regEvent: function(eventName,handlerName) {
1273
- window._addScriptFlag = true;
1274
- var script;
1275
- try {
1276
- script = $('<script>').attr({
1277
- 'for': this._opts.ocxName,
1278
- 'event': eventName
1279
- }).text('if (!_addScriptFlag) {'
1280
- +handlerName
1281
- +'}'
1282
- +'_addScriptFlag = false;');
1283
-
1284
- } catch (e) {
1285
- script = '<script for="'+this._opts.ocxName+'" event = "'+eventName+'" >'
1286
- +'if (!_addScriptFlag) {'
1287
- +handlerName
1288
- +'}'
1289
- +'_addScriptFlag = false;'
1290
- +'</script>';
1291
- }
1292
- $('body').append(script);
1293
- },
1294
-
1295
- _beforeUnload: function() {
1296
- var me = this;
1297
- window.onbeforeunload = function (e) {
1298
- me.closeAll();
1299
- me._obj.SCWebDecoderDestroy();
1300
- };
1301
- }
1302
-
1303
- }
1304
-
1305
- /**
1306
- * 使用webRtc方式的video工具类
1307
- */
1308
- function VideoWebRtc($dom,opts) {
1309
- var _self = this;
1310
- _self.videoListener = new Listener();
1311
- if (!opts) {
1312
- console.error('VideoWebRtc的参数opts不能为空');
1313
- return;
1314
- }
1315
- _self.configOpt = (opts && opts.configOpt) || 3;
1316
- hasMediaDevices();
1317
-
1318
- //检测声卡设备为异步方法,耗时在几十毫秒左右,因此需要做延迟
1319
- //默认检查次数为40 间隔为20ms
1320
- var count = 0;
1321
- var index = setInterval(function () {
1322
- if (count == 40) {
1323
- clearInterval(index);
1324
- _self._init($dom,opts);
1325
- } else {
1326
- if (window.checkAudioDevicesStatus) {
1327
- clearInterval(index);
1328
- _self._init($dom,opts);
1329
- }
1330
- }
1331
- count++;
1332
- }, 20);
1333
- }
1334
-
1335
- /**
1336
- * 使用WEB-RTC方式的视频播放的方法
1337
- */
1338
- VideoWebRtc.prototype = {
1339
- constructor: VideoWebRtc,
1340
- /**
1341
- * 播放视频
1342
- * 参数:index(视频窗口编号,从0开始) video(视频设备id,即devId) id(标识,空的话使用设备id) opts(其他参数)
1343
- * opts.businessType 0:调度业务 1:勤指
1344
- * 返回true/false
1345
- */
1346
- play: function(index, video, id, opts){
1347
- var me = this;
1348
- // if (me.isPlaying(id) != -1) {
1349
- // console.info('该视频正在播放');
1350
- // return false;
1351
- // }
1352
- // 启用播放队列时,当前位置正在关闭上一个视频,则加入播放队列
1353
- if (me.waitPlayQueueSwitch && me.VIDEO_DATA[index].isClosing) {
1354
- me._addWaitingVideo(index, video, id, opts);
1355
- return ;
1356
- }
1357
- console.log("play >>> " + "video=" + video + "; id=" + id + "; index=" + index);
1358
- me.dispatch('beforeplay',{index:index, video:video, id:id});
1359
-
1360
- if (index < 0) {
1361
- console.error('index参数错误');
1362
- return false;
1363
- }
1364
- me.VIDEO_DATA[index].play(video);
1365
-
1366
- opts = opts || {};
1367
-
1368
- if (me.VIDEO_DATA[index].playing) {
1369
- me.VIDEO_DATA[index].opts = opts;
1370
- me.VIDEO_DATA[index].id = id;
1371
- me.dispatch('playsuccess', me.VIDEO_DATA[index]);
1372
- return true;
1373
- }
1374
- return false;
1375
- },
1376
-
1377
- /**
1378
- * 在序号最小的空闲窗口播放视频
1379
- * 参数:index(视频窗口编号,从0开始) video(视频设备id,即devId) opts(其他参数)
1380
- * 返回true/false
1381
- */
1382
- playByOrder: function(video, id, opts){
1383
- var freeWindow = this._getMinIndexFreeWindow();
1384
-
1385
- if(freeWindow == -1 &&
1386
- (this._getChoiceWindow() != -1 && !this.getInChoiceVideo() && this._opts.windowsNum > 1)){
1387
- return this.playInChoice(video,id,opts);
1388
- }
1389
-
1390
- return this.play(freeWindow, video, id, opts);
1391
- },
1392
-
1393
- /**
1394
- * 扩展视频窗口数的播放方式
1395
- */
1396
- playByOrderExpandWindow: function(video, id, opts){
1397
- var me = this;
1398
-
1399
- var freeWindow = this._getMinIndexFreeWindow();
1400
-
1401
- // while (this._opts.windows < 16 && freeWindow == -1) {
1402
- // me.setWindowsNum(me._getNextWindowsNum(parseInt(me._opts.windows)));
1403
- // freeWindow = this._getMinIndexFreeWindow(0);
1404
- // }
1405
-
1406
- var maxWindows = this._opts.windowsNum || 16;
1407
-
1408
- while (me._opts.windows < maxWindows && freeWindow == -1) {
1409
- var zoom = Math.sqrt(this._opts.windows*1)+1;
1410
-
1411
- if (this._opts.windows == 6) {
1412
- this.setWindowsNum(9);
1413
- } else {
1414
- this.setWindowsNum(Math.pow(zoom,2));
1415
- }
1416
-
1417
- freeWindow = this._getMinIndexFreeWindow(zoom-1);
1418
- }
1419
-
1420
- if (this._getChoiceWindow() == -1 && this._getMinIndexFreeWindow() != -1) {
1421
- this.setChoiceWindow(this._getMinIndexFreeWindow());
1422
- }
1423
-
1424
- if(freeWindow == -1 ||
1425
- (this._getChoiceWindow() != -1 && !this.getInChoiceVideo() && this._opts.windowsNum > 1)){
1426
- return this.playInChoice(video,id,opts);
1427
- }
1428
-
1429
- return this.play(freeWindow, video, id, opts);
1430
- },
1431
-
1432
- /**
1433
- * 播放所有视频
1434
- */
1435
- playAll: function(array){
1436
- if (array.length > this._opts.windows) {
1437
- throw new Error('windows is not enough');
1438
- }
1439
- var me = this;
1440
- me.closeAll();
1441
- $.each(array,function(i,obj){
1442
- me.play(i, obj.video, obj.id, obj.opts);
1443
- });
1444
- },
1445
-
1446
- /**
1447
- * 在鼠标选中的窗口中播放视频
1448
- */
1449
- playInChoice: function(video, id, opts){
1450
- var me = this;
1451
- var selView = $(me.selector + ' li.sel');
1452
- if(selView.length){
1453
- var index = selView.attr("index");
1454
- if (me.VIDEO_DATA[index].playing) {
1455
- me.close(index);
1456
- //延时打开 禁止同时一关一开
1457
- setTimeout(function(){
1458
- me.play(index, video, id, opts);
1459
- }, 1000);
1460
- } else {
1461
- me.play(index, video, id, opts);
1462
- }
1463
- }
1464
- },
1465
-
1466
- /**
1467
- * 检索当前点的视频是否被播放,被播放则返回播放的视频窗口
1468
- */
1469
- isPlaying: function(id){
1470
- var me = this;
1471
- var index = -1;
1472
- $.each(me.VIDEO_DATA,function(key,val){
1473
- if (id == val.id && me.VIDEO_DATA[key].playing) {
1474
- index = key;
1475
- }
1476
- });
1477
- return index;
1478
- },
1479
-
1480
- /**
1481
- * 判断指定窗口是否正在播放视频
1482
- */
1483
- isPlayingByIndex: function(index){
1484
- var me = this;
1485
- if (index > me.VIDEO_DATA.length - 1 || index < 0) return false;
1486
-
1487
- return me.VIDEO_DATA[index].playing;
1488
- },
1489
-
1490
- /**
1491
- * 获取视频数据
1492
- */
1493
- getVideoData: function(){
1494
- return this.VIDEO_DATA;
1495
- },
1496
-
1497
- /**
1498
- * 关闭指定窗口的视频
1499
- */
1500
- close: function(index, isSave){
1501
- if (index < 0) {
1502
- console.info('index参数错误');
1503
- return;
1504
- }
1505
-
1506
- this.VIDEO_DATA[index].close();
1507
-
1508
- if (!isSave) {
1509
- this.VIDEO_DATA[index].closeType = 'close';
1510
- this.dispatch('afterclose', this.VIDEO_DATA[index]);
1511
- }
1512
- // todo 优化点
1513
- /**if (this.videoInfoTimer) {
1514
- clearInterval(this.videoInfoTimer);
1515
- this.videoInfoTimer = null;
1516
- }**/
1517
-
1518
- },
1519
-
1520
- /**
1521
- * 关闭指定视频编号正在播放的视频
1522
- */
1523
- closeByVideo: function(video, isSave){
1524
- var me = this;
1525
-
1526
- if (video == undefined) {
1527
- console.info('video参数错误');
1528
- return;
1529
- }
1530
-
1531
- var videoData = me.VIDEO_DATA;
1532
- if (!videoData || videoData.length == 0) {
1533
- return;
1534
- }
1535
-
1536
- for (var i in videoData) {
1537
- if (video == videoData[i].video) {
1538
- me.close(videoData[i].index);
1539
-
1540
- if (!isSave) {
1541
- videoData[i].closeType = 'close';
1542
- me.dispatch('afterclose', videoData[i]);
1543
- }
1544
- }
1545
- }
1546
- },
1547
-
1548
- /**
1549
- * 关闭所有视频
1550
- */
1551
- closeAll: function(isSave){
1552
- var me = this;
1553
- // 清除所有等待播放队列
1554
- me._removeAllWaitingVideo();
1555
- var openVideos = [];
1556
- for(var i = me._opts.windowsBeginIndex; i < me._opts.windowsBeginIndex + me._opts.windowsNum; i++){
1557
- /*if(me.VIDEO_DATA[i].playing){
1558
- me.close(i, isSave)
1559
- }*/
1560
- me.close(i, isSave);
1561
- }
1562
- // todo 优化点
1563
- //已存在则清除
1564
- //if (me.videoInfoTimer) {
1565
- // clearInterval(me.videoInfoTimer);
1566
- // me.videoInfoTimer = null;
1567
- // }
1568
-
1569
- // if(!openVideos.length) return;
1570
- //
1571
- // //适当延时进行关闭
1572
- // var count = 0;
1573
- // var interval = setInterval(function(){
1574
- // if(count == openVideos.length){
1575
- // clearInterval(interval);
1576
- // }else{
1577
- // me.close(openVideos[count], isSave)
1578
- // count++;
1579
- // }
1580
- // }, 50);
1581
- },
1582
-
1583
- /**
1584
- * 设置鼠标选中窗口
1585
- */
1586
- setChoiceWindow: function(index) {
1587
- $('.screen-' + (index + 1)).click();
1588
- },
1589
-
1590
- /**
1591
- * 获取视频窗口数
1592
- */
1593
- getWindowsNum: function() {
1594
- return this._opts.windows;
1595
- },
1596
-
1597
- /**
1598
- * 分屏切换,传入的参数为新的屏数
1599
- */
1600
- setWindowsNum: function(num) {
1601
- var me = this;
1602
-
1603
- //切换屏幕后 选中空闲最小的窗口
1604
- if (me._opts.windows != num && me._getMinIndexFreeWindow() != -1) {
1605
- me.setChoiceWindow(me._getMinIndexFreeWindow());
1606
- }
1607
-
1608
- $(me.selector + ' .video-main').removeClass("mode-" + me._opts.windows).addClass("mode-" + num);
1609
- var _li = $(me.selector + ' li.screen').hide();
1610
- me._opts.windows = num;
1611
- for(var i = 0; i < num; i++){
1612
- _li.eq(i).show();
1613
- }
1614
- //分屏切换事件
1615
- this.dispatch('screenchange', {windowNums:num, flag:me._opts.flag});
1616
- },
1617
-
1618
- /**
1619
- * 询问是否无可用窗口
1620
- */
1621
- isUnavailable: function() {
1622
- return this._opts.windows == 16 && this._getMinIndexFreeWindow() == -1;
1623
- },
1624
-
1625
- /**
1626
- * 执行轮巡
1627
- */
1628
- startPoll: function(array,time) {
1629
- if (!array || array.length == 0) {
1630
- promptAlarm('请选择视频设备!');
1631
- return false;
1632
- }
1633
-
1634
- time = $.isNumeric(time) ? time : this._opts.pollInterval;
1635
- this._pollArray = array;
1636
- var me = this,
1637
- windowNum = me._opts.windows,
1638
- maxNum = array.length,
1639
- nowNum = 0 ;
1640
- me.saveList();
1641
-
1642
- this._polltimer = new PollTimer(function(firstRun){
1643
- me.closeAll();
1644
-
1645
- if (firstRun) {
1646
- for(var i = 0; i < windowNum; i++) {
1647
- if(nowNum == maxNum){
1648
- nowNum = 0;
1649
- if(maxNum < windowNum) {
1650
- break;
1651
- }
1652
- }
1653
-
1654
- me.playByOrder(array[nowNum].video, array[nowNum].id, array[nowNum].opts);
1655
- nowNum++;
1656
- }
1657
- me.dispatch('startpoll', array);
1658
- } else {
1659
- wait(1500).then(function(){
1660
- for(var i = 0; i < windowNum; i++) {
1661
- if(nowNum == maxNum){
1662
- nowNum = 0;
1663
- if(maxNum < windowNum) {
1664
- break;
1665
- }
1666
- }
1667
- me.playByOrder(array[nowNum].video, array[nowNum].id, array[nowNum].opts);
1668
- nowNum++;
1669
- }
1670
- })
1671
- }
1672
- }, time);
1673
- },
1674
-
1675
- /**
1676
- * 结束轮巡
1677
- */
1678
- stopPoll: function() {
1679
- if(!this._polltimer){
1680
- return;
1681
- }
1682
-
1683
- this._polltimer.stop();
1684
- this._polltimer = undefined;
1685
-
1686
- console.log('------> 轮巡结束 <-------');
1687
- this.dispatch('stoppoll', {});
1688
-
1689
- this._pollArray = null;
1690
- this.closeAll();
1691
- //恢复之前打开的视频
1692
- //this.playSaveList();
1693
- },
1694
-
1695
- /**
1696
- * 获取是否在轮巡
1697
- */
1698
- isPolling: function() {
1699
- return !!this._polltimer;
1700
- },
1701
-
1702
- holder: function(type, opts, isStop) {
1703
- var index = this._getChoiceWindow();
1704
- if (index < 0) {
1705
- promptFailed('请先选中视频');
1706
- return false;
1707
- }
1708
- return this.VIDEO_DATA[index].holder(type, opts, isStop);
1709
- },
1710
-
1711
- /**
1712
- * 视频回放
1713
- * @param startTime [YYYY-MM-DDTHH:mm:ss]
1714
- * @param endTime
1715
- * @return playId
1716
- */
1717
- playHistory: function(video, startTime, endTime, opts) {
1718
- var me = this;
1719
-
1720
- var index;
1721
- //回放是一分屏的默认使用一个窗口
1722
- if (me._opts.windowsNum == 1) {
1723
- index = me._opts.windowsBeginIndex;
1724
- } else {
1725
- index = me._getMinIndexFreeWindow();
1726
- }
1727
-
1728
- if (index < 0) {
1729
- console.error('窗口编号获取失败!');
1730
- }
1731
-
1732
- me.setChoiceWindow(index);
1733
- me.VIDEO_DATA[index].opts = opts;
1734
- return me.VIDEO_DATA[index].playback(video,startTime,endTime);
1735
- },
1736
-
1737
- /**
1738
- * 关闭历史流
1739
- */
1740
- closeHistory: function(video, index) {
1741
- if (!video) return;
1742
-
1743
- var me = this;
1744
-
1745
- if (!index) {
1746
- var index;
1747
- if (me._opts.windowsNum == 1) {
1748
- index = me._opts.windowsBeginIndex;
1749
- }
1750
- }
1751
-
1752
- return me.VIDEO_DATA[index].playbackControl(video, "stop", 0);
1753
- },
1754
-
1755
- /**
1756
- * 历史流控制
1757
- * @param {number} video
1758
- * @param {string} playType 播放类型(play && pause & stop)
1759
- * @param {numner} playSpeed 播放速率
1760
- * @param {string} startTime 回放时间(暂时无用)
1761
- */
1762
- historyControl: function(video, playType, playSpeed, startTime) {
1763
- var me = this;
1764
- var index;
1765
- if (me._opts.windowsNum == 1) {
1766
- index = me._opts.windowsBeginIndex;
1767
- } else {
1768
- index = me._getChoiceWindow();
1769
- }
1770
- return me.VIDEO_DATA[index].playbackControl(video, playType, playSpeed, startTime);
1771
- },
1772
-
1773
- saveList: function() {
1774
- this._saveList = cloneObj(this.VIDEO_DATA);
1775
- },
1776
-
1777
-
1778
- playSaveList: function() {
1779
- if (!this._saveList) {
1780
- return;
1781
- }
1782
- this.closeAll();
1783
- var me = this;
1784
- $.each(this._saveList, function(index, obj){
1785
- if (obj.video) {
1786
- me.play(obj.index, obj.video, obj.id, obj.opts);
1787
- }
1788
- });
1789
- },
1790
-
1791
- /**
1792
- * 获取当前选择窗口的视频video
1793
- */
1794
- getInChoiceVideo: function() {
1795
- var me = this;
1796
- var selView = $(me.selector + ' li.sel');
1797
- if(selView.length && me.VIDEO_DATA[selView.attr("index")].video){
1798
- return me.VIDEO_DATA[selView.attr("index")];
1799
- }
1800
- return undefined;
1801
- },
1802
-
1803
- /**
1804
- * 设置全屏
1805
- */
1806
- setFullScreen: function() {
1807
- this._fullScreenEvent(document.getElementById("video-main-web-rtc"));
1808
- },
1809
-
1810
- /**
1811
- * 获取当前视频控件的配置项
1812
- */
1813
- getVideoControllerOpts: function() {
1814
- return this._opts;
1815
- },
1816
-
1817
- /**
1818
- * 获取截屏数据
1819
- * @param callback 回调函数
1820
- */
1821
- getScreenCaptureData: function(index, callback) {
1822
- var me = this;
1823
-
1824
- //如果index为空则使用选中窗口的index
1825
- var dataObj = me.VIDEO_DATA[index != undefined ? index : me._getChoiceWindow()];
1826
-
1827
- if (!dataObj.playing) {
1828
- promptAlarm('请选择播放的视频源!');
1829
- return;
1830
- }
1831
-
1832
- var canvasObj = document.getElementById('myCanvas');
1833
- var videoObj = dataObj.tagBox.get(0);
1834
-
1835
- if (videoObj == undefined) {
1836
- return;
1837
- }
1838
- // 取流中 取视频框尺寸
1839
- // 播放中 取视频画面尺寸
1840
- if (dataObj.tagBox.parent().find(".stream-loading").length != 0) {
1841
- canvasObj.width = dataObj.tagBox.width();
1842
- canvasObj.height = dataObj.tagBox.height();
1843
- } else {
1844
- canvasObj.width = videoObj.videoWidth;
1845
- canvasObj.height = videoObj.videoHeight;
1846
- }
1847
-
1848
- var ctx = canvasObj.getContext("2d");
1849
- ctx.drawImage(videoObj, 0, 0, videoObj.videoWidth, videoObj.videoHeight);
1850
-
1851
- var dataUrl = canvasObj.toDataURL('image/jpeg');
1852
- callback ? callback(dataUrl) : null;
1853
- },
1854
-
1855
- /**
1856
- * 开始录像
1857
- */
1858
- startAvRecord: function(index) {
1859
- var me = this;
1860
- return me.VIDEO_DATA[index].recordAv("start_av_record", recordAvBusinessId);
1861
- },
1862
-
1863
- /**
1864
- * 结束录像
1865
- */
1866
- stopAvRecord: function(index) {
1867
- var me = this;
1868
- return me.VIDEO_DATA[index].recordAv("stop_av_record", recordAvBusinessId);
1869
- },
1870
-
1871
- /**
1872
- * 改变分辨率
1873
- * @param resolution 新分辨率
1874
- */
1875
- changeResolution: function(index, resolution) {
1876
- var me = this;
1877
- return me.VIDEO_DATA[index].changeResolution("change_resolution", resolution);
1878
- },
1879
-
1880
- /**
1881
- * 开启对讲预呼叫
1882
- * @param pocNo 对讲号码
1883
- * @param centerTel 调度中心号
1884
- */
1885
- openPocCall: function(pocNo, centerTel) {
1886
- var me = this;
1887
-
1888
- var index;
1889
- //对讲预呼叫默认使用一个窗口
1890
- if (me._opts.windowsNum == 1) {
1891
- index = me._opts.windowsBeginIndex;
1892
- } else {
1893
- index = me._getMinIndexFreeWindow();
1894
- }
1895
-
1896
- if (index < 0) {
1897
- console.error('窗口编号获取失败!')
1898
- }
1899
-
1900
- //保存对讲号码
1901
- window.pocNo = pocNo;
1902
- return me.VIDEO_DATA[index].pocCall("open_poccall", pocNo, centerTel);
1903
- },
1904
-
1905
- /**
1906
- * 关闭对讲预呼叫
1907
- * @param pocNo 对讲号码
1908
- * @param centerTel 调度中心号
1909
- */
1910
- closePocCall: function(pocNo, centerTel) {
1911
- var me = this;
1912
-
1913
- var index;
1914
- //对讲预呼叫默认使用一个窗口
1915
- if (me._opts.windowsNum == 1) {
1916
- index = me._opts.windowsBeginIndex;
1917
- } else {
1918
- index = me._getMinIndexFreeWindow();
1919
- }
1920
-
1921
- if (index < 0) {
1922
- console.error('窗口编号获取失败!')
1923
- }
1924
-
1925
- me.VIDEO_DATA[index].stream = null;
1926
- window.pocNo = null;
1927
- return me.VIDEO_DATA[index].pocCall("close_poccall", pocNo, centerTel);
1928
- },
1929
-
1930
- /**
1931
- * 设置录像的businessId
1932
- * @param businessId 业务ID
1933
- */
1934
- setRecordAvBusinessId: function(businessId) {
1935
- //var me = this;
1936
- recordAvBusinessId = businessId;
1937
- },
1938
-
1939
- /**
1940
- * 开启音频
1941
- */
1942
- sendAudio: function(index) {
1943
- var me = this;
1944
- var index = (index != undefined ? index : me._opts.windowsBeginIndex);
1945
- me.VIDEO_DATA[index].stream.getAudioTracks()[0].enabled = true;
1946
- },
1947
-
1948
- /**
1949
- * 关闭音频
1950
- */
1951
- unSendAudio: function(index) {
1952
- var me = this;
1953
- var index = (index != undefined ? index : me._opts.windowsBeginIndex);
1954
- me.VIDEO_DATA[index].stream.getAudioTracks()[0].enabled = false;
1955
- },
1956
-
1957
- /**
1958
- * 添加事件
1959
- */
1960
- addListener: function(type, handler, key){
1961
- this.videoListener.addListener(type, handler, key);
1962
- },
1963
-
1964
- /**
1965
- * 删除事件
1966
- */
1967
- removeListener: function(type, handler){
1968
- this.videoListener.removeListener(type, handler);
1969
- },
1970
- /**
1971
- * 派发事件
1972
- */
1973
- dispatch: function(e, options){
1974
- this.videoListener.dispatch(e, options);
1975
- },
1976
-
1977
- /**
1978
- * 清空事件
1979
- */
1980
- removeAllListeners: function() {
1981
- this.videoListener.removeAllListeners();
1982
- },
1983
-
1984
- /**
1985
- * 获取编号最小的空闲窗口的编号, 正在播放或有视频在等待播放标识不是空闲窗口
1986
- */
1987
- _getMinIndexFreeWindow: function(index) {
1988
- var me = this;
1989
- index = index || me._opts.windowsBeginIndex;
1990
- for (; index < me._opts.windowsBeginIndex + me._opts.windows ; index++) {
1991
- if (!me.VIDEO_DATA[index].playing && !me.VIDEO_DATA[index].isWaiting) {
1992
- return index;
1993
- }
1994
- }
1995
- return -1;
1996
- },
1997
-
1998
- /**
1999
- * 获取选中的窗口的index
2000
- */
2001
- _getChoiceWindow: function() {
2002
- var me = this;
2003
- var selView = $(me.selector + ' li.sel');
2004
- if (selView.length) {
2005
- return selView.attr("index");
2006
- }
2007
- return -1;
2008
- },
2009
-
2010
- /**
2011
- * 获取下一窗口
2012
- */
2013
- _getNextWindowsNum: function(old) {
2014
- var me = this;
2015
- var windowsArr = me._windowsArr;
2016
- for (var index in windowsArr){
2017
- if (index == windowsArr.length - 1) {
2018
- return windowsArr[index]
2019
- }
2020
- if (old == windowsArr[index]) {
2021
- return windowsArr[Number(index) + Number(1)];
2022
- }
2023
- }
2024
- },
2025
-
2026
- /**
2027
- * 设置鼠标选中窗口
2028
- */
2029
- _initWindowEvent: function() {
2030
- var me = this;
2031
- //视频窗口选中
2032
- $(me.selector + ' li').click(function(){
2033
- $(me.selector + ' li').removeClass("sel");
2034
- $(this).addClass("sel");
2035
-
2036
- //如果视频正在播放则分发点击消息
2037
- if (me.getInChoiceVideo()) {
2038
- me.dispatch('click', me.getInChoiceVideo());
2039
- }
2040
- });
2041
-
2042
- // 设置视频窗可拖拽
2043
- var src = null;
2044
- $(me.selector + ' li').bind("dragstart", function (ev) {
2045
- src = $(this);
2046
- })
2047
-
2048
- $(me.selector + ' li').bind("dragover", function (ev) {
2049
- ev.preventDefault();
2050
- })
2051
-
2052
- $(me.selector + ' li').bind("drop", function (ev) {
2053
- ev.preventDefault();
2054
- if(src.prop("outerHTML") === $(this).prop("outerHTML")){
2055
- return;
2056
- }
2057
- var target = $(this);
2058
- var srcIndex = src.index();
2059
- var targetIndex = target.index();
2060
-
2061
- if (srcIndex > targetIndex) {
2062
- src.insertBefore(target);
2063
- target.insertAfter($(me.selector +' .video-main li.screen').eq(srcIndex));
2064
- } else {
2065
- src.insertAfter(target);
2066
- target.insertBefore($(me.selector +' .video-main li.screen').eq(srcIndex));
2067
- }
2068
- })
2069
- },
2070
-
2071
- /*
2072
- * 总的初始化
2073
- * 参数示例:
2074
- * var opts = {
2075
- windows: 4, //初始化的窗口数
2076
- conf: { //配置参数
2077
- user: 'admin', //用户名
2078
- passwd: '6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b', //密码
2079
- janusUrl: 'wss: //192.168.103.226:8989', //janusServer服务地址
2080
- },
2081
- pollInterval: 30 //轮巡时间,单位秒
2082
- };
2083
- */
2084
- _init: function($dom,opts){
2085
- var me = this;
2086
- //保存dom元素的selector用作后续所有子集对象的定位(在多组件对讲模式下有用)
2087
- if($dom.length == 0 || !me.getDomSelector($dom)) {
2088
- console.error("父doom元素为空,无法进行视频初始化", $dom);
2089
- return ;
2090
- }
2091
-
2092
- //保存视频窗口列表对象
2093
- me.VIDEO_DATA = [];
2094
- //配置项
2095
- me._opts = {
2096
- windows: 4,
2097
- conf: {},
2098
- pollInterval: 10,
2099
- windowsNum: 16,
2100
- isVideoTag: true, //true生成video标签 false生产audio标签 默认true
2101
- showVideoInfo: 1, //显示分辨率、码率等信息,1-显示左下角 2-显示左上角,为0时控制_showVideoInfo函数处理,默认1
2102
- waitPlayQueueSwitch: false, //播放队列开关,默认false
2103
- defaultBusinessType: 0, // 配置的默认业务类型 0:调度主线 1:勤指
2104
- videoTipTimeOut: 5, // 超时无首屏检测时间
2105
- };
2106
-
2107
- $.extend(me._opts,opts);
2108
-
2109
- var windowsArr = me._opts.windowsArr;
2110
- if (!windowsArr || windowsArr.length == 0) {
2111
- me._windowList = {1:{}, 4:{}, 6:{}, 9:{}, 16:{}}
2112
- me._windowsArr = [1, 4, 6, 9, 16];
2113
- } else {
2114
- me._windowList = {};
2115
- for (var index in windowsArr){
2116
- var item = windowsArr[index];
2117
- me._windowList[item] = {};
2118
- }
2119
- me._windowsArr = windowsArr;
2120
- }
2121
-
2122
- //获取起始的窗口位置
2123
- me._opts.windowsBeginIndex = 0;
2124
- // 对讲号码初始化
2125
- window.pocNo = 0;
2126
- // 播放队列开关 默认打开
2127
- me.waitPlayQueueSwitch = opts.waitPlayQueueSwitch == undefined ? false : opts.waitPlayQueueSwitch;
2128
-
2129
- //是否提示
2130
- me._opts.showPrompt === false && (showPrompt = false);
2131
- // 勤指业务下 设备检测
2132
- me._opts.defaultBusinessType == 1 && me._checkDevices();
2133
- //初始化界面
2134
- me._opts.isVideoTag ? me._initVideoView($dom, me._opts.showVideoInfo) : me._initAudioView($dom);
2135
- //初始化Janus
2136
- me._initJanus();
2137
- //初始化按钮点击事件
2138
- me._initBtnEvent();
2139
- // 初始化事件监听
2140
- me._initEventListen();
2141
- //设置鼠标点击选中窗口
2142
- me._initWindowEvent();
2143
- if (me._opts.showVideoInfo != 0) {
2144
- //显示视频信息:名称、分辨率、码率、丢包率
2145
- me._showVideoInfo();
2146
- }
2147
- //双击某个视频全屏
2148
- me._dbClickFullScreen();
2149
- },
2150
-
2151
- /**
2152
- * 获取父窗口传入dom的唯一selector(针对jquery高版本dom对象没有selector属性的问题)
2153
- * @param $dom
2154
- * @return {boolean}
2155
- */
2156
- getDomSelector: function($dom) {
2157
- var me = this;
2158
- if($dom.selector) {
2159
- me.selector = $dom.selector;
2160
- }
2161
- else {
2162
- if($dom.attr("id")) {
2163
- me.selector = "#" + $dom.attr("id");
2164
- }
2165
- else {
2166
- if(!$dom.attr("class")) return false;
2167
- var classNames = $dom.attr("class").split(/\s+/);
2168
- $.each(classNames, function (i, className) {
2169
- if ($("." + className).length == 1) {
2170
- me.selector = "." + className;
2171
- return true;
2172
- }
2173
- });
2174
- }
2175
- }
2176
- if(!me.selector) return false;
2177
- else return true;
2178
- },
2179
-
2180
- /**
2181
- * 初始化按钮点击事件
2182
- */
2183
- _initBtnEvent: function() {
2184
- var me = this;
2185
- var videoFlagObj = $(me.selector + ' .video-main');
2186
-
2187
- //锁定视频事件
2188
- videoFlagObj.find("button[name='lockVideo']").click(function(e){
2189
- var index = Number($(this).parent().parent().attr("index"));
2190
-
2191
- if (!me.VIDEO_DATA[index].playing) {
2192
- promptAlarm('请选择播放的视频源!');
2193
- return;
2194
- }
2195
-
2196
- if ($(this).attr('class') == 'lock-video-btn') {
2197
- me.VIDEO_DATA[index].isLockVideo = false;
2198
- $(this).attr('class', 'unlock-video-btn');
2199
- } else {
2200
- me.VIDEO_DATA[index].isLockVideo = true;
2201
- $(this).attr('class', 'lock-video-btn');
2202
- }
2203
- //jquery方式阻止默认事件 & 冒泡事件
2204
- return false;
2205
- });
2206
-
2207
- //接收音频事件
2208
- videoFlagObj.find("button[name='recvAudio']").click(function(e){
2209
- var _self = this;
2210
- var index = Number($(this).parent().parent().attr("index"));
2211
- // 优先当前窗口参数设置的业务类型 其次配置的默认业务类型
2212
- var businessType = me.VIDEO_DATA[index].opts.businessType == undefined ? me._opts.defaultBusinessType : me.VIDEO_DATA[index].opts.businessType;
2213
-
2214
- if (!me.VIDEO_DATA[index].playing) {
2215
- promptAlarm('请选择播放的视频源!');
2216
- return;
2217
- }
2218
-
2219
- if ($(this).attr('class') == 'recv-audio-btn') {
2220
- //发送停止播放音频的请求
2221
- me.VIDEO_DATA[index].operateAudio("stop_audio")
2222
- $(this).attr('class', 'unrecv-audio-btn');
2223
- me.VIDEO_DATA[index].tagBox.prop("muted", true);
2224
- } else {
2225
- if (businessType == 0) {
2226
- //发送前先关闭其它音频通道(包括接收和发送音频)
2227
- var lis = $($(_self).parent().parent().parent()).children();
2228
- for (var i = 0; i < lis.length; i++) {
2229
- var btnIndex = Number($(lis[i]).attr("index"));
2230
- if (index == btnIndex) {
2231
- continue;
2232
- }
2233
- var recvBtn = $($(lis[i]).find("button[name='recvAudio']")[0]);
2234
- var sendBtn = $($(lis[i]).find("button[name='sendAudio']")[0]);
2235
-
2236
- if (recvBtn.attr("class") == 'recv-audio-btn') {
2237
- if (me.VIDEO_DATA[btnIndex].playing) {
2238
- recvBtn.click();
2239
- }
2240
- }
2241
- if (sendBtn.attr("class") == 'send-audio-btn') {
2242
- if (me.VIDEO_DATA[btnIndex].playing) {
2243
- sendBtn.click();
2244
- }
2245
- }
2246
- }
2247
- //发送播放音频的请求
2248
- $(_self).attr('class', 'recv-audio-btn');
2249
- setTimeout(function () {
2250
- if(!me.VIDEO_DATA[index].isClosing){
2251
- me.VIDEO_DATA[index].operateAudio("recv_audio");
2252
- me.VIDEO_DATA[index].tagBox.prop("muted", false);
2253
- }
2254
- }, 1000);
2255
- } else if (businessType == 1) {
2256
- // poc新模式支持回传多个音频,因此不关闭
2257
- //发送播放音频的请求
2258
- $(_self).attr('class', 'recv-audio-btn');
2259
- me.VIDEO_DATA[index].operateAudio("recv_audio");
2260
- me.VIDEO_DATA[index].tagBox.prop("muted", false)
2261
- }
2262
- }
2263
- //jquery方式阻止默认事件 & 冒泡事件
2264
- return false;
2265
- });
2266
-
2267
- //发送音频事件
2268
- videoFlagObj.find("button[name='sendAudio']").click(function(e){
2269
- var index = Number($(this).parent().parent().attr("index"));
2270
- // 优先当前窗口参数设置的业务类型 其次配置的默认业务类型 最后默认调度业务
2271
- var businessType = me.VIDEO_DATA[index].opts.businessType == undefined ? me._opts.defaultBusinessType : me.VIDEO_DATA[index].opts.businessType;
2272
-
2273
- if (!me.VIDEO_DATA[index].playing) {
2274
- promptAlarm('请选择播放的视频源!');
2275
- return;
2276
- }
2277
-
2278
- if (businessType == 0) {
2279
- // 主线业务
2280
- if ($(this).attr('class') == 'send-audio-btn') {
2281
- me.VIDEO_DATA[index].operateAudio("unsend_audio")
2282
- $(this).attr('class', 'unsend-audio-btn');
2283
- me.VIDEO_DATA[index].stream.getAudioTracks()[0].enabled = false;
2284
- } else {
2285
- me.VIDEO_DATA[index].operateAudio("send_audio");
2286
- $(this).attr('class', 'send-audio-btn');
2287
- // $(this).parent().find("button[name='recvAudio']").attr('class', 'recv-audio-btn')
2288
- me.VIDEO_DATA[index].stream.getAudioTracks()[0].enabled = true;
2289
- }
2290
- } else if (businessType == 1) {
2291
- // 勤指业务
2292
- if ($(this).attr('class') == 'send-audio-btn') {
2293
- $(this).attr('class', 'unsend-audio-btn');
2294
- //关闭点对点对讲
2295
- me.VIDEO_DATA[index].ptopPoc("close_ptop_poc", window.pocNo);
2296
- } else {
2297
- $(this).attr('class', 'send-audio-btn');
2298
- //发起点对点对讲
2299
- me.VIDEO_DATA[index].ptopPoc("open_ptop_poc", window.pocNo);
2300
- }
2301
- }
2302
- //jquery方式阻止默认事件 & 冒泡事件
2303
- return false;
2304
- });
2305
-
2306
- //关闭视频事件
2307
- videoFlagObj.find("button[name='closeVideo']").click(function(e){
2308
- var index = Number($(this).parent().parent().attr("index"));
2309
- me.close(index);
2310
- //jquery方式阻止默认事件 & 冒泡事件
2311
- return false;
2312
- });
2313
- },
2314
-
2315
- /**
2316
- * 初始化事件监听
2317
- */
2318
- _initEventListen: function () {
2319
- var _self = this;
2320
- // 打开视频 {index, video, id, opts} index(视频窗口编号,从0开始) video(视频设备id,即devId) id(标识,空的话使用设备id) opts(其他参数)
2321
- _self.addListener('openVideo', function (e) {
2322
- _self.play(e.index, e.video, e.id, e.opts);
2323
- })
2324
-
2325
- // janus通知后台已关闭视频
2326
- _self.addListener('notifyCloseVideo', function (e) {
2327
- _self._notifyWaitingVideo(e.index);
2328
- });
2329
- },
2330
-
2331
- /**
2332
- * 双击某个视频全屏
2333
- */
2334
- _dbClickFullScreen: function() {
2335
- var me = this;
2336
- $(me.selector + ' .video-main').find('.video-box').on("dblclick",function(){
2337
- me._fullScreenEvent(this);
2338
- });
2339
- },
2340
-
2341
- /**
2342
- * 全屏事件
2343
- */
2344
- _fullScreenEvent: function(el) {
2345
- var isFullscreen = el.fullScreen || el.mozFullScreen || el.webkitIsFullScreen;
2346
- if(!isFullscreen){//进入全屏,多重短路表达式
2347
- (el.requestFullscreen && el.requestFullscreen()) ||
2348
- (el.mozRequestFullScreen && el.mozRequestFullScreen()) ||
2349
- (el.webkitRequestFullscreen && el.webkitRequestFullscreen()) || (el.msRequestFullscreen && el.msRequestFullscreen());
2350
- }
2351
-
2352
- //关闭全屏
2353
- // colseFullscreen();
2354
- // function colseFullscreen() {
2355
- // el.onmouseup = function(e){ //在body里点击触发事件
2356
- // if(e.button === 0){
2357
- // document.exitFullscreen?document.exitFullscreen():
2358
- // document.mozCancelFullScreen?document.mozCancelFullScreen():
2359
- // document.webkitExitFullscreen?document.webkitExitFullscreen():'';
2360
- // }
2361
- // }
2362
- // }
2363
- },
2364
-
2365
- /**
2366
- * 在视频界面上显示视频的信息 码率、分辨率、丢包率
2367
- */
2368
- _showVideoInfo: function() {
2369
- var me = this;
2370
- function clock(){
2371
- if(!me.VIDEO_DATA || !me.VIDEO_DATA.length) return;
2372
- for (var i = 0; i < me.VIDEO_DATA.length; i++) {
2373
- if (me.VIDEO_DATA[i].playing) {
2374
- var number = Number(i) + Number(1);
2375
- //获取视频video标签
2376
- var $videoList = $(me.selector + " .video-main #video-" + number);
2377
- if(!$videoList.length) {
2378
- console.error("can not find dom by id [video-" + number + "]");
2379
- continue ;
2380
- }
2381
- var videoObj = $videoList[0];
2382
-
2383
- if (!videoObj) continue;
2384
-
2385
- var width = videoObj.videoWidth;
2386
- var height = videoObj.videoHeight;
2387
-
2388
- //码率
2389
- var bitrate = me.VIDEO_DATA[i].sipcall.getBitrate();
2390
- if (!width || !height || !bitrate || bitrate.indexOf("kbits") == -1 || bitrate.indexOf("NaN") != -1) {
2391
- continue;
2392
- }
2393
-
2394
- var config = me.VIDEO_DATA[i].sipcall.webrtcStuff;
2395
- me._setPacketsLostRate(i, config, me);
2396
- me._setFrameDecoded(i, config, me);
2397
- var resolution = width + "×" + height;
2398
- switch(height + '') {
2399
- case '1080':
2400
- resolution = "1080P";
2401
- break;
2402
- case '720':
2403
- resolution = "720P";
2404
- break;
2405
- case '480':
2406
- resolution = "480P";
2407
- break;
2408
- case '288':
2409
- resolution = "CIF";
2410
- break;
2411
- default:
2412
- break;
2413
- }
2414
-
2415
- //获取文案显示dom元素
2416
- var $videoInfoList = $(me.selector + " .video-main #info-" + number);
2417
- if(!$videoInfoList.length) {
2418
- console.error("can not find dom by id [info-" + number + "]");
2419
- continue ;
2420
- }
2421
- var videoInfoObj = $videoInfoList[0];
2422
- //拼接文案显示内容
2423
- var videoName = me.VIDEO_DATA[i].opts && me.VIDEO_DATA[i].opts.name ?
2424
- me.VIDEO_DATA[i].opts.name : me.VIDEO_DATA[i].video;
2425
- videoInfoObj.innerHTML = videoName + '&nbsp;&nbsp;' + resolution +
2426
- '<br>丢包率:' + me.VIDEO_DATA[i].packetsLostRate + '&nbsp;&nbsp;' + bitrate.replace("kbits/sec", "kbps");
2427
- //根据视频框大小自动计算 显示文案的文字大小
2428
- var fontHeightSize = $(me.selector + " .video-main #video-" + number).height() / 15;
2429
- var fontWidthSize = $(me.selector + " .video-main #video-" + number).width() / 18;
2430
- //长和宽 除以 15, 取小的值做文字大小样式
2431
- var fontSize = fontHeightSize < fontWidthSize? fontHeightSize:fontWidthSize;
2432
- fontSize = (!fontSize || fontSize > 20)? 20 : fontSize;
2433
- $("#info-" + number).css("font-size", fontSize+"px");
2434
- }
2435
- }
2436
- }
2437
-
2438
- //已存在则清除
2439
- if (me.videoInfoTimer) {
2440
- clearInterval(me.videoInfoTimer);
2441
- me.videoInfoTimer = null;
2442
- }
2443
-
2444
- me.videoInfoTimer = setInterval(clock, 1000);
2445
- },
2446
- /**
2447
- * 获取设置丢包率
2448
- */
2449
- _setPacketsLostRate: function (index, config, me) {
2450
- if (config.pc !== null && typeof config.pc !== 'undefined' && config.pc.getStats) {
2451
- config.pc.getStats().then(function (stats) {
2452
- stats.forEach(function (res) {
2453
- if (!res) {
2454
- return;
2455
- }
2456
- var inStats = false;
2457
- // Check if these are statistics on incoming media
2458
- if ((res.mediaType === 'video' || res.id.toLowerCase().indexOf('video') > -1) &&
2459
- res.type === 'inbound-rtp' && res.id.indexOf('rtcp') < 0) {
2460
- // New stats
2461
- inStats = true;
2462
- } else if (res.type === 'ssrc' && res.bytesReceived &&
2463
- (res.googCodecName === 'VP8' || res.googCodecName === '')) {
2464
- // Older Chromer versions
2465
- inStats = true;
2466
- }
2467
- // Parse stats now
2468
- if (inStats) {
2469
- if (res.hasOwnProperty('packetsLost')) {
2470
- //console.info('丢包率:' + res.packetsLost);
2471
- if (!res.packetsLost || isNaN(res.packetsLost) || Number(res.packetsLost) == '0' || res.packetsLost == 'NaN') {
2472
- me.VIDEO_DATA[index].packetsLostRate = '0.00%';
2473
- } else {
2474
- var packetsLost = Number(res.packetsLost) - Number(me.VIDEO_DATA[index].packetsLostSum);
2475
- var packetsReceived = Number(res.packetsReceived) - Number(me.VIDEO_DATA[index].packetsReceivedSum);
2476
-
2477
- var packetsLostRate = 0;
2478
- //防止分母是0
2479
- if (packetsLost > 0) {
2480
- var packetsLostRate = (Number(packetsLost) / (Number(packetsLost) + Number(packetsReceived))) * 100;
2481
- }
2482
- me.VIDEO_DATA[index].packetsLostRate = packetsLostRate.toFixed(2) + '%';
2483
- }
2484
- //window.VIDEO_DATA[index].packetsLostRate = (Number(res.packetsLost) / (Number(res.packetsLost) + Number(res.packetsReceived))) * 100;
2485
- /* videoInfoObj.innerHTML = videoName + '&nbsp;&nbsp;' + width + "×" + height +
2486
- '<br>' + bitrate + '&nbsp;&nbsp;Lost:' + res.packetsLost;*/
2487
- }
2488
- }
2489
- });
2490
- });
2491
- }
2492
- },
2493
-
2494
- /**
2495
- * 设置当前网络信号提示
2496
- * @param index 当前打开视频的索引
2497
- * @param config
2498
- * @param me
2499
- * @private
2500
- */
2501
- _setFrameDecoded: function(index, config, me) {
2502
- if (config.pc !== null && typeof config.pc !== 'undefined' && config.pc.getStats) {
2503
- config.pc.getStats().then(function (stats) {
2504
- stats.forEach(function (res) {
2505
- if (res) {
2506
- var inStats = false;
2507
- // Check if these are statistics on incoming media
2508
- if ((res.mediaType === 'video' || res.id.toLowerCase().indexOf('video') > -1) &&
2509
- res.type === 'inbound-rtp' && res.id.indexOf('rtcp') < 0) {
2510
- // New stats
2511
- inStats = true;
2512
- } else if (res.type === 'ssrc' && res.bytesReceived &&
2513
- (res.googCodecName === 'VP8' || res.googCodecName === '')) {
2514
- // Older Chromer versions
2515
- inStats = true;
2516
- }
2517
- // Parse stats now
2518
- if (inStats) {
2519
- if (res.hasOwnProperty('framesDecoded')) {
2520
- if (res.framesDecoded <= 1) return;
2521
- if (typeof me.VIDEO_DATA[index].framesDecodedCount === 'undefined') {
2522
- me.VIDEO_DATA[index].framesDecodedCount = 0;
2523
- }
2524
- if (typeof me.VIDEO_DATA[index].framesDecodedLast === 'undefined') {
2525
- me.VIDEO_DATA[index].framesDecodedLast = res.framesDecoded;
2526
- }
2527
- if (res.framesDecoded > me.VIDEO_DATA[index].framesDecodedLast) {
2528
- if (typeof me.VIDEO_DATA[index].tipDom !== 'undefined' && me.VIDEO_DATA[index].tipDom.style.display === 'block') {
2529
- me.VIDEO_DATA[index].tipDom.style.display = 'none';
2530
- }
2531
- }
2532
- me.VIDEO_DATA[index].framesDecodedCount++;
2533
- // 定时检测
2534
- if (me.VIDEO_DATA[index].framesDecodedCount === me.configOpt) {
2535
- if (res.framesDecoded - me.VIDEO_DATA[index].framesDecodedLast === 0) { // 卡顿
2536
- if (typeof me.VIDEO_DATA[index].tipDom === 'undefined') {
2537
- var numIndex = index + 1;
2538
- me.VIDEO_DATA[index].tipDom = document.getElementById('frame-decoded-' + numIndex);
2539
- }
2540
- me.VIDEO_DATA[index].tipDom.style.display = 'block';
2541
- }
2542
- me.VIDEO_DATA[index].framesDecodedCount = 0;
2543
- me.VIDEO_DATA[index].framesDecodedLast = res.framesDecoded;
2544
- } else {
2545
- me.VIDEO_DATA[index].framesDecodedLast = res.framesDecoded;
2546
- }
2547
- }
2548
- }
2549
- }
2550
- });
2551
- });
2552
- }
2553
- },
2554
-
2555
- /**
2556
- * 设备可用性检查(扬声器、麦克风、分辨率、浏览器类型)
2557
- * 1. 未检测(status == undefined)询问进入检测界面
2558
- * 2. 检测完成按相应结果给予相应提示
2559
- * 3. 拒绝检测按所有检测通过处理
2560
- * 4. 程序自行检测,并将是否加载声卡结果放入window对象
2561
- * @private
2562
- */
2563
- _checkDevices: function() {
2564
- var me = this;
2565
- var tipCountKey = "DEVICES_CHECK_TIP_COUNT";
2566
- var statusKey = "DEVICES_CHECK_STATUS";
2567
- var checkCompleted = "completed";
2568
- var checkRejected = "rejected";
2569
- var microResultKey = "MICRO_RESULT";
2570
- var speakerResultKey = "SPEAKER_RESULT";
2571
- var screenResultKey = "SCREEN_RESULT";
2572
- var resultPass = "pass";
2573
- var resultNotPass = "not pass";
2574
-
2575
- var tipCount = sessionStorage.getItem(tipCountKey);
2576
- var status = localStorage.getItem(statusKey);
2577
- if ((tipCount == undefined || tipCount == "0") && status == undefined) {
2578
- sessionStorage.setItem(tipCountKey, "1");
2579
- //弹窗讯问是否进入检测界面
2580
- if (confirm("您还没有检测硬件设备,是否先进行检测?")) {
2581
- window.open("/scooper-video/new/checkDevices");
2582
- } else {
2583
- localStorage.setItem(statusKey, checkRejected);
2584
- }
2585
- return;
2586
- }
2587
-
2588
- if (status == checkCompleted) {
2589
- var microResult = (localStorage.getItem(microResultKey) == undefined) ? resultPass : localStorage.getItem(microResultKey);
2590
- var speakerResult = (localStorage.getItem(speakerResultKey) == undefined) ? resultPass : localStorage.getItem(speakerResultKey);
2591
- var screenResult = (localStorage.getItem(screenResultKey) == undefined) ? resultPass : localStorage.getItem(screenResultKey);
2592
-
2593
- var msg = "";
2594
- if(speakerResult == resultNotPass){
2595
- msg += "检测到扬声器异常,可能影响系统某些功能的使用!";
2596
- console.error(msg);
2597
- }
2598
- if (microResult == resultNotPass) {
2599
- msg += "检测到麦克风异常,可能影响系统某些功能的使用!";
2600
- console.error(msg);
2601
- }
2602
- if (screenResult === resultNotPass) {
2603
- msg += "您的屏幕分辨率过低,可能导致页面布局混乱!";
2604
- //提示消息
2605
- promptAlarm(msg);
2606
- }
2607
- var userAgent = navigator.userAgent;
2608
- if (userAgent.toLowerCase().indexOf("chrome") < 0 && userAgent.toLowerCase().indexOf("firefox") < 0 && userAgent.toLowerCase().indexOf("edge") < 0) {
2609
- msg += "当前浏览器下部分功能可能存在兼容问题,建议使用谷歌浏览器!";
2610
- promptAlarm(msg);
2611
- }
2612
-
2613
- if (msg != "") {
2614
- //提示并派发消息
2615
- // promptAlarm(msg);
2616
- //防止外部未监听消息就派发事件
2617
- setTimeout(function () {
2618
- me.videoListener.dispatch('msginfo', {'msg' : msg});
2619
- }, 3000);
2620
- }
2621
- }
2622
-
2623
- },
2624
-
2625
- /**
2626
- * 视频界面的初始化,在传过来的dom中创建界面
2627
- * @param infoPosition 视频码率等信息显示位置,1-显示左下角 2-显示左上角,为0时控制_showVideoInfo函数处理,默认左下角
2628
- */
2629
- _initVideoView: function($dom, infoPosition) {
2630
- var me = this;
2631
- var position;
2632
- switch (infoPosition) {
2633
- case 1: position = "info-bottom"; break;
2634
- case 2: position = "info-top"; break;
2635
- default : position = "info-bottom";
2636
- }
2637
- var objClass = (me._opts.windowsNum == 1 ? 'video-main video-main-full mode-' : 'video-main mode-') + me._opts.windows;
2638
- var videoHtml = '<ul class="' + objClass +'" id="video-main-web-rtc">';
2639
- var index = me._opts.windowsBeginIndex + 1;
2640
- for (var i = index; i < index + me._opts.windowsNum; i++) {
2641
- videoHtml += '<li class="screen screen-' + i +'" index="' + (i - 1) +'" draggable="true"><video muted class="video-box" id="video-' + i +'" autoplay ></video>' +
2642
- '<div class="hide info ' + position + '" id="info-' + i +'"></div>' +
2643
- '<div class="hide frame-decoded" id="frame-decoded-' + i + '"style="position:absolute;float:left;color:#fff;width:67%;z-index:1;top:135px;left:180px">网络信号不佳</div>' +
2644
- '<div class="operate-btn">';
2645
- videoHtml +='<button type="button" class="unlock-video-btn hide" name="lockVideo"></button>';
2646
- checkUserMediaAvailable() && (videoHtml += '<button type="button" class="unsend-audio-btn hide" name="sendAudio"></button>');
2647
- videoHtml += '<button type="button" class="unrecv-audio-btn hide" name="recvAudio"></button>' +
2648
- '<button type="button" class="close-btn hide" name="closeVideo"></button>' +
2649
- '</div>' +
2650
- '</li>';
2651
- }
2652
- videoHtml += '</ul> <div class="canvasBox hide"><canvas id="myCanvas" ></canvas></div>';
2653
- $dom.append(videoHtml);
2654
-
2655
- me.setWindowsNum(me._opts.windows);
2656
- },
2657
-
2658
- /**
2659
- * 音频界面的初始化,在传过来的dom中创建界面
2660
- */
2661
- _initAudioView: function($dom) {
2662
- var me = this;
2663
- var objClass = (me._opts.windowsNum == 1 ? 'video-main video-main-full mode-' : 'video-main mode-') + me._opts.windows;
2664
- var videoHtml = '<ul class="' + objClass +'" id="video-main-web-rtc">';
2665
- var index = me._opts.windowsBeginIndex + 1;
2666
- for (var i = index; i < index + me._opts.windowsNum; i++) {
2667
- videoHtml += '<audio id="audio-' + i +'" autoplay ></audio>';
2668
- }
2669
- $dom.append(videoHtml);
2670
- },
2671
-
2672
- /**
2673
- * Janus的初始化
2674
- */
2675
- _initJanus: function(){
2676
- var me = this;
2677
-
2678
- // if (window.parent && window.parent.janus) {
2679
- // me._initSVideo(window.parent.janus);
2680
- // return;
2681
- // }
2682
-
2683
- Janus.init({debug:"error", callback: function(){
2684
- if(!Janus.isWebrtcSupported()) {
2685
- alert("不支持WEB-RTC");
2686
- return;
2687
- }
2688
-
2689
- var janusUrl = me._opts.conf.janusUrl;
2690
- checkIsHttps() && (janusUrl = janusUrl.replace('ws:','wss:'));
2691
- janusUrl.indexOf("127.0.0.1") > 0 && (janusUrl = janusUrl.replace('127.0.0.1', location.hostname));
2692
- me._opts.janus = new Janus({
2693
- //如果是https 则用页面的url头(已保证用nginx代理为前提) 否则用后台配置的
2694
- server: location.protocol == "https:" ? janusUrl.split("//")[0] + "//" + (location.host) + "/janus/" : janusUrl,
2695
- success: function(){
2696
- console.log("Janus服务连接成功!");
2697
- me._initSVideo(me._opts.janus);
2698
- },
2699
- error: function(error) {
2700
- //只提示一次,防止Janus挂了一直重连
2701
- !me._opts.isNotFistTip && promptFailed('Janus服务连接失败!');
2702
- me._opts.isNotFistTip = true;
2703
-
2704
- console.error('Janus服务连接失败:'+ error)
2705
- me.closeAll();
2706
- me._removeAllWaitingVideo();
2707
- me._initJanus();
2708
- },
2709
- destroyed: function() {
2710
- me._opts.isNotFistTip = true;
2711
- }
2712
- });
2713
-
2714
- }});
2715
- },
2716
-
2717
- /**
2718
- * 销毁所有
2719
- */
2720
- destory: function() {
2721
- var me = this;
2722
- me.destoryJanus();
2723
- $(me.selector).empty();
2724
- me.videoListener = null;
2725
- me.VIDEO_DATA = null;
2726
- me.selector = null;
2727
- //destoryJanus会触发回调,需要使用到opts
2728
- // me._opts = null;
2729
- },
2730
-
2731
- /**
2732
- * 销毁:Janus销毁、资源释放
2733
- */
2734
- destoryJanus: function() {
2735
- var me = this;
2736
- me._opts.janus.destroy({
2737
- success: function() {
2738
- registered = false;
2739
- },
2740
- asyncRequest: true,
2741
- notifyDestroyed: true,
2742
-
2743
- });
2744
- me.removeAllListeners();
2745
- },
2746
-
2747
- reLoginJanusItvIndex : -1,
2748
- /**
2749
- * 初始化插件、登陆,初始化窗口
2750
- */
2751
- _initSVideo: function(janus){
2752
- var me = this;
2753
-
2754
- //初始化一个插件,用来登陆,不能用此插件播放视频。
2755
- var _loginSipCall = null;
2756
- janus.attach({
2757
- plugin: me._opts.conf.janusPlugin ? me._opts.conf.janusPlugin : "janus.plugin.videoserver",
2758
- opaqueId: "siptest-" + Janus.randomString(12),
2759
- success: function(pluginHandle) {
2760
- console.log("Janus登陆插件初始化成功!");
2761
- _loginSipCall = pluginHandle;
2762
- var register = {
2763
- "request" : "register",
2764
- "username" : me._opts.conf.user,
2765
- "secret": me._opts.conf.passwd,
2766
- };
2767
- _loginSipCall.send({"message": register});
2768
- },
2769
- error: function(error) {
2770
- promptFailed('Janus登陆插件初始化失败!');
2771
- console.error("Janus登陆插件初始化失败:" + error);
2772
- },
2773
- onmessage: function(msg, jsep) {
2774
- if (msg.error_code) {
2775
- console.error(msg.error)
2776
- promptFailed(CONST_CODE.FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code);
2777
- return false;
2778
- }
2779
-
2780
- var result = msg["result"];
2781
- var event = result["event"];
2782
-
2783
- if (result.error_code && result.error_code != 0) {
2784
- promptFailed(CONST_CODE.FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
2785
- }
2786
-
2787
- if(result !== null && result !== undefined && result["event"] !== undefined && result["event"] !== null) {
2788
- console.log("result event:" + event);
2789
- if(event === 'registration_failed') {
2790
- promptFailed("janus登陆失败: " + result["code"] + " " + result["reason"]);
2791
- if(me.reLoginJanusItvIndex == -1) {
2792
- me.reLoginJanusItvIndex = setInterval(function () {
2793
- console.log("尝试重新登陆janus!");
2794
- me._initJanus(janus);
2795
- }, 5000);
2796
- }
2797
- return;
2798
- }
2799
- if (event === 'video_server_closed') {
2800
- if(me.reLoginJanusItvIndex == -1) {
2801
- me.reLoginJanusItvIndex = setInterval(function () {
2802
- console.log("尝试重新登陆janus!");
2803
- me._initJanus(janus);
2804
- }, 5000);
2805
- }
2806
- return;
2807
- }
2808
- if(event === 'registered') {
2809
- var userToken = result["userToken"];
2810
- console.log('janus登陆成功')
2811
- registered = true;
2812
- if (me.reLoginJanusItvIndex != -1) {
2813
- clearInterval(me.reLoginJanusItvIndex);
2814
- me.reLoginJanusItvIndex = -1;
2815
- }
2816
-
2817
- //生成主界面
2818
- //相对序号,用于标识当前janus连接初始化的序号窗口
2819
- var relativeIndex = 0;
2820
- for(var i = me._opts.windowsBeginIndex; i < me._opts.windowsBeginIndex + me._opts.windowsNum; i++){
2821
- me.VIDEO_DATA[i] = new SVideo({
2822
- index: i,
2823
- userToken: userToken,
2824
- janus: janus,
2825
- windowsNum: me._opts.windowsNum,
2826
- relativeIndex: relativeIndex++,
2827
- flag: me._opts.flag,
2828
- isVideoTag: me._opts.isVideoTag,
2829
- janusPlugin: me._opts.conf.janusPlugin,
2830
- videoTipTimeOut: me._opts.videoTipTimeOut,
2831
- parentSelector: me.selector
2832
- }, me.videoListener);
2833
- }
2834
- }
2835
- }
2836
- }
2837
- });
2838
- },
2839
-
2840
- /* ----------------------------- 播放队列 --------------------------- */
2841
-
2842
- // 记录等待中的视频
2843
- WAITING_DATA: [],
2844
-
2845
- // 播放队列开关 默认关闭
2846
- waitPlayQueueSwitch: false,
2847
-
2848
- /**
2849
- * 添加等待视频数据
2850
- * 同一位置再次打开,则覆盖上一次的
2851
- * 参数:index(视频窗口编号,从0开始) video(视频设备id,即devId) id(标识,空的话使用设备id) opts(其他参数)
2852
- */
2853
- _addWaitingVideo: function (index, video, id, opts) {
2854
- var _self = this;
2855
- var isOverride = false;
2856
- $.each(_self.WAITING_DATA, function (i, obj) {
2857
- if (obj.index == index) {
2858
- console.log("播放队列中 index = " + index + ", video = " + obj.video + " 替换为 video = " + video);
2859
- _self.WAITING_DATA[i] = {
2860
- index: index,
2861
- video: video,
2862
- id: id,
2863
- opts: opts
2864
- }
2865
- isOverride = true;
2866
- return false;
2867
- }
2868
- });
2869
- if (!isOverride) {
2870
- _self.WAITING_DATA.push({
2871
- index: index,
2872
- video: video,
2873
- id: id,
2874
- opts: opts
2875
- });
2876
- console.log("index = " + index + ", video = " + video + " 加入播放队列");
2877
- }
2878
- _self.VIDEO_DATA[index].isWaiting = true;
2879
- },
2880
-
2881
- /**
2882
- * 删除等待视频数据
2883
- */
2884
- _removeWaitingVideo: function (index, video) {
2885
- var _self = this;
2886
- $.each(_self.WAITING_DATA, function (i, obj) {
2887
- if (obj.index == index && obj.video == video) {
2888
- _self.WAITING_DATA.splice(i, 1);
2889
- _self.VIDEO_DATA[index].isWaiting = false;
2890
- console.log("index = " + index + ", video = " + video + " 从播放队列移除");
2891
- return false;
2892
- }
2893
- });
2894
- },
2895
-
2896
- /**
2897
- * 删除所有等待播放视频的数据
2898
- */
2899
- _removeAllWaitingVideo: function () {
2900
- var _self = this;
2901
- _self.WAITING_DATA = [];
2902
- var index = _self._opts.windowsBeginIndex;
2903
- for (; index < _self._opts.windowsBeginIndex + _self._opts.windows ; index++) {
2904
- _self.VIDEO_DATA[index].isWaiting = false;
2905
- }
2906
- },
2907
-
2908
- /**
2909
- * 上一个视频关闭后,如果该位置由等待视频,通知打开新视频
2910
- * @param index
2911
- */
2912
- _notifyWaitingVideo: function (index) {
2913
- var _self = this;
2914
- $.each(_self.WAITING_DATA, function (i, obj) {
2915
- if (obj.index == index) {
2916
- _self.play(obj.index, obj.video, obj.id, obj.opts);
2917
- _self._removeWaitingVideo(obj.index, obj.video);
2918
- return false;
2919
- }
2920
- });
2921
- }
2922
-
2923
- }
2924
-
2925
- var CONST_CODE = {
2926
- //打开失败错误码,面板显示,不做浮窗提示框显示
2927
- VIDEO_CODE: {
2928
- 2002 : "打开失败,未找到该ID的视频源",
2929
- 2003 : "打开失败,请确认视频服务版本",
2930
- 3001 : "打开失败,未接收到引流包,请检查端口映射",
2931
- 3002 : "",
2932
- 3003 : "打开失败,对方拒绝视频请求",
2933
- 4001 : "打开失败,视频流中断",
2934
- 4002 : "打开失败,终端挂机或超时未接听",
2935
- 7000 : "打开失败,无法连接视频设备",
2936
- 7001 : "打开失败,无法连接视频设备",
2937
- 7002 : "打开失败,无法连接视频设备"
2938
- },
2939
-
2940
- OTHER_CODE: {
2941
- 453 : "videoServer连接失败,错误码453",
2942
- 454 : "视频窗口已被占用,请选择其它窗口打开或停止播放",
2943
- 455 : "操作失败,该段时间无视频录像",
2944
- 499 : "操作异常,错误码499",
2945
- 440 : "操作异常,错误码440",
2946
- 441 : "操作异常,错误码441",
2947
- 442 : "操作异常,错误码442",
2948
- 443 : "操作异常,错误码443",
2949
- 444 : "操作异常,错误码444",
2950
- 445 : "操作异常,错误码445",
2951
- 446 : "操作异常,错误码446",
2952
- 447 : "操作异常,错误码447",
2953
- 448 : "操作异常,错误码448",
2954
- 449 : "操作异常,错误码449",
2955
- 450 : "操作异常,错误码450",
2956
- 451 : "操作异常,错误码451",
2957
- 452 : "操作异常,错误码452",
2958
- 456 : "设备已处于对讲状态或不支持对讲",
2959
- 6001 : "录像失败"
2960
- },
2961
- //操作异常错误码,做浮窗提示显示
2962
- FAILED_CODE: {
2963
- 1001 : "账号或密码错误",
2964
- 1002 : "该帐号已连接",
2965
- 1004 : "没有鉴权",
2966
- 2001 : "未携带token或token错误",
2967
- 2002 : "视频源id不存在",
2968
- 2003 : "操作指令非法(该账号不允许执行这个指令,或者不支持该指令)",
2969
- 3001 : "nat通道未建立",
2970
- 3002 : "该视频流已在传输",
2971
- 3003 : "无法获取远端视频流",
2972
- 4001 : "视频流异常断开连接",
2973
- 4002 : "获取视频失败",
2974
- 5000 : "内部错误",
2975
- 8001 : "该设备不支持云台操作",
2976
- 453 : "videoServer连接失败",
2977
- 454 : "录像回放窗口已占用,请先停止播放",
2978
- 455 : "无视频录像,操作失败",
2979
- 5001 : "呼叫异常断开",
2980
- 5002 : "禁止修改分辨率",
2981
- 401 : "禁止修改分辨率",
2982
- 4003 : "音频重置",
2983
- 4004 : "音频被占用",
2984
- 4005 : "客户端已打开对讲",
2985
- 4006 : "终端离开云眼音频",
2986
- 4008 : "终端拒绝打开视频",
2987
- 6001 : "录像失败",
2988
- 499 : "内部创建失败",
2989
- 440 : "请求消息内容为空",
2990
- 441 : "json格式错误",
2991
- 442 : "无效的请求",
2992
- 443 : "消息内容缺失",
2993
- 444 : "消息缺少参数",
2994
- 445 : "账户已登陆",
2995
- 446 : "收到的videoserver消息有误",
2996
- 447 : "消息参数错误",
2997
- 448 : "SDP创建失败",
2998
- 449 : "未使用",
2999
- 450 : "创建端口失败",
3000
- 451 : "SDP创建失败",
3001
- 452 : "未使用加密的RTP",
3002
- 456 : "对讲未打开",
3003
- 7000 : "URL账号密码错误(RTSP)",
3004
- 7001 : "URL地址不通(RTSP)",
3005
- 7002 : "URL格式错误(RTSP)"
3006
- },
3007
-
3008
- /**
3009
- * 以下的错误状态不会关闭视频
3010
- */
3011
- STATUS_CODE_ARR: ['5002', '401', '4003', '4004', '4005', '4006', '8001', '6001']
3012
- }
3013
-
3014
- /**
3015
- * 显示播放错误内容, 4002特殊处理
3016
- * @param videoObj 视频对象
3017
- * @param code 状态码(包含错误码)
3018
- * @param isShowReplayBtn 是否显示重新播放按钮
3019
- * @param video 打开错误的视频Id
3020
- */
3021
- function showResult(videoObj, code, isShowReplayBtn, video) {
3022
- var videoDom = videoObj.tagBox.parent();
3023
-
3024
- videoDom.addClass("result");
3025
- videoDom.find('.operate-btn .close-btn').show();
3026
-
3027
- if (CONST_CODE.FAILED_CODE[code] && code != "4002") {
3028
- var resultHtml = "<div class='real-result'>错误码" + code + ": " + CONST_CODE.FAILED_CODE[code] + "</div>"
3029
- videoDom.append(resultHtml);
3030
- }
3031
-
3032
- var resultHtml = "<div class='result'><div class='result-tip'>" + CONST_CODE.VIDEO_CODE[code] + "</div>";
3033
- if(isShowReplayBtn && code != "4002") {
3034
- resultHtml += "<div class='result-replay'><span id='replay-" + videoObj.index + "' class='replay'>点击重试</span></div>"
3035
- }
3036
- resultHtml += "</div>";
3037
- videoDom.append(resultHtml);
3038
- if(isShowReplayBtn && code != "4002") {
3039
- $("#replay-" + videoObj.index).unbind("click").click(function () {
3040
- videoObj.videoListener.dispatch("openVideo", {index: videoObj.index, video: video, id: videoObj.id, opts: videoObj.opts});
3041
- });
3042
- }
3043
- if (code == "4002") {
3044
- setTimeout(function () {
3045
- clearResult(videoDom);
3046
- }, 5000);
3047
- }
3048
- }
3049
-
3050
- /**
3051
- * 清除显示内容 videoDom: 视频Dom对象
3052
- */
3053
- function clearResult(videoDom, videoObj) {
3054
- videoDom.removeClass("result");
3055
- videoDom.find(".real-result").remove();
3056
- videoDom.find(".result").remove();
3057
- if (!videoObj || !videoObj.playing) {
3058
- // bug id 18654: 增加是否正在播放判断
3059
- videoDom.find('.operate-btn .close-btn').hide();
3060
- }
3061
- }
3062
-
3063
- var registered = false;
3064
- var recordAvBusinessId = null;
3065
-
3066
- function SVideo (opts, videoListener) {
3067
- this.janus = opts.janus;
3068
- this.userToken = opts.userToken;
3069
- this.sipcall = null;
3070
- this.index = opts.index;
3071
- this.relativeIndex = opts.relativeIndex;
3072
- this.tagBox = opts.isVideoTag ? $(opts.parentSelector + ' #video-' + (this.index + 1)) : $('#audio-' + (this.index + 1));
3073
- this.windowsNum = opts.windowsNum;
3074
- this.flag = opts.flag;
3075
- this.isVideoTag = opts.isVideoTag;
3076
- this.janusPlugin = opts.janusPlugin;
3077
- this.isClosing = false; // 当前分屏是否正在关闭视频
3078
- this.isWaiting = false; // 当前分屏是否有视频在等待播放
3079
- this.playSucTimeOutIndex = -1; // 超时提示定时器index
3080
- this.videoTipTimeOut = opts.videoTipTimeOut; // 超时无首屏时间
3081
- this.videoListener = videoListener;
3082
- this.init();
3083
- }
3084
-
3085
- /**
3086
- * 使用web-rtc方式的视频播放
3087
- */
3088
- SVideo.prototype = {
3089
-
3090
- /**
3091
- * 初始化
3092
- */
3093
- init:function(){
3094
- var self = this;
3095
-
3096
- self.janus.attach({
3097
- plugin: self.janusPlugin ? self.janusPlugin : "janus.plugin.videoserver",
3098
- opaqueId:"siptest-" + Janus.randomString(12),
3099
-
3100
- success: function(pluginHandle) {
3101
- console.log("视频插件初始化成功:" + self.index);
3102
- self.sipcall = pluginHandle;
3103
-
3104
- if (self.relativeIndex + 1 >= self.windowsNum) {
3105
- self.videoListener.dispatch('initsucc', self);
3106
- }
3107
- },
3108
-
3109
- error: function(error) {
3110
- console.error("插件初始化失败");
3111
- },
3112
-
3113
- consentDialog: function(on) {
3114
- console.log("Consent dialog should be " + (on ? "on" : "off") + " now");
3115
- },
3116
-
3117
- onmessage: function(msg, jsep) {
3118
- if(!registered) {
3119
- promptFailed("请先登陆");
3120
- }
3121
-
3122
- var video = self.video;
3123
- if (msg.error_code) {
3124
- console.error("错误码:" + msg.error_code + " " + CONST_CODE.FAILED_CODE[msg.error_code]);
3125
- if (CONST_CODE.VIDEO_CODE[msg.error_code]) {
3126
- showResult(self, msg.error_code, true, video);
3127
- } else {
3128
- promptFailed(CONST_CODE.OTHER_CODE[msg.error_code] || CONST_CODE.FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code);
3129
- }
3130
- self.videoListener.dispatch('msginfo', {'code': msg.error_code, 'msg' : CONST_CODE.OTHER_CODE[msg.error_code] || CONST_CODE.FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code});
3131
- return false;
3132
- }
3133
-
3134
- var result = msg["result"];
3135
- if (!result) return;
3136
- if (result.error_code && result.error_code != 0) {
3137
- console.error("错误码:" + result.error_code + " " + CONST_CODE.FAILED_CODE[result.error_code]);
3138
- if (!CONST_CODE.STATUS_CODE_ARR.includes(result.error_code + '')) {
3139
- //播放失败 关闭视频
3140
- self.close('err');
3141
- if (self.isLockVideo) {
3142
- setTimeout(function () {
3143
- self.play(video);
3144
- }, 1500);
3145
- } else {
3146
- self.closeType = 'error';
3147
- self.videoListener.dispatch('afterclose', self);
3148
- }
3149
- }
3150
-
3151
- self.videoListener.dispatch('msginfo', {'code': result.error_code, 'msg' : CONST_CODE.OTHER_CODE[result.error_code] || CONST_CODE.FAILED_CODE[result.error_code] || '错误码:' + result.error_code});
3152
- if (CONST_CODE.VIDEO_CODE[result.error_code]) {
3153
- showResult(self, result.error_code, true, video);
3154
- } else {
3155
- promptFailed(CONST_CODE.OTHER_CODE[result.error_code] || CONST_CODE.FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
3156
- }
3157
- self.tagBox.parent().find('.recv-audio-btn').attr("class", "unrecv-audio-btn");
3158
- self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
3159
- }
3160
-
3161
- //事件响应
3162
- var event = result["event"];
3163
- if (!event) return;
3164
- switch(event) {
3165
- //即将播放视频
3166
- case 'incomingcall':
3167
- self.sipcall.createAnswer({
3168
- jsep: jsep,
3169
- media: { audioSend: checkUserMediaAvailable(), videoSend:false, audioRecv: true, videoRecv: true},
3170
- success: function(jsep) {
3171
- var body = {
3172
- request:"accept",
3173
- videoidentify: result["videoidentify"],
3174
- playseq: parseInt(result["playseq"]),
3175
- userToken: self.userToken,
3176
- };
3177
- self.sipcall.send({"message": body, "jsep": jsep});
3178
- },
3179
- error: function(error) {
3180
- console.error(error);
3181
- }
3182
- });
3183
- break;
3184
- case 'accepted' :
3185
- self.playSucTimeOutIndex = setTimeout(function () {
3186
- var _li = self.tagBox.parent();
3187
- _li.append('<div class="video-tip">网络环境较差,可能无法正常加载视频</div>');
3188
- }, self.videoTipTimeOut * 1000);
3189
- break;
3190
- //呼叫失败
3191
- case 'callfaild':
3192
- //promptFailed(FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
3193
- break;
3194
- //云台
3195
- case 'ptz':
3196
- break;
3197
- //历史流控制
3198
- case 'av_control':
3199
- break;
3200
- //录像通知
3201
- case 'start_av_record':
3202
- if (result && result.filename) {
3203
- self.videoFileName = result.filename;
3204
- self.videoListener.dispatch('startRecordVideo', self);
3205
- console.log('录像地址:' + result.filename);
3206
- }
3207
- break;
3208
- case 'stop_av_record':
3209
- if (result && result.filename) {
3210
- self.videoFileName = result.filename;
3211
- self.videoListener.dispatch('stopRecordVideo', self);
3212
- console.log('录像地址:' + result.filename);
3213
- }
3214
- break;
3215
- //修改分辨率
3216
- case 'ser_notify_resolution':
3217
- if (result && result.resolution) {
3218
- self.resolution = result.resolution;
3219
- self.videoListener.dispatch('notifyresolution', self);
3220
- console.log('接收notifyresolution:' + result.resolution);
3221
- //promptAlarm('当前分辨率:' + result.resolution);
3222
- }
3223
- break;
3224
- case 'change_resolution':
3225
- if(result) {
3226
- self.videoListener.dispatch('notifyResolutionChange', self);
3227
- }
3228
- break;
3229
- //建立预呼叫响应
3230
- case 'open_poccall':
3231
- console.log('建立预呼叫');
3232
- self.sipcall.createAnswer({
3233
- jsep: jsep,
3234
- media: {audioSend: checkUserMediaAvailable(), videoSend:false, audioRecv: true , videoRecv: false},
3235
- success: function(jsep) {
3236
- var body = {
3237
- request:"accept",
3238
- userToken: self.userToken,
3239
- };
3240
- self.sipcall.send({"message": body, "jsep": jsep});
3241
- },
3242
- error: function(error) {
3243
- console.error(error);
3244
- promptFailed("发生未知错误,请重试或联系管理员!");
3245
- self.videoListener.dispatch('msginfo', {'msg' : "发生未知错误,请重试或联系管理员!"});
3246
- }
3247
- });
3248
- break
3249
- //预呼叫异常断开
3250
- case 'ser_close_poccall':
3251
- console.log('预呼叫异常断开');
3252
- break;
3253
- case 'ser_stop_audio':
3254
- self.tagBox.parent().find('.recv-audio-btn').attr("class", "unrecv-audio-btn");
3255
- console.log('音频异常关闭!');
3256
- break;
3257
- case 'close_down_audio':
3258
- self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
3259
- promptSuccess("通话时间到");
3260
- console.log('通话时间到!');
3261
- break;
3262
- case 'ser_notify_dispatch_close_ptop_poc':
3263
- self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
3264
- console.log('调度通知点对点对讲关闭!');
3265
- break;
3266
- case 'ser_close_ptop_poc':
3267
- self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
3268
- console.log('点对点对讲关闭!');
3269
- break;
3270
- case 'ser_open_ptop_poc':
3271
- self.tagBox.parent().find('.unsend-audio-btn').attr("class", "send-audio-btn");
3272
- console.log('点对点对讲打开!');
3273
- break;
3274
- // 视频关闭通知
3275
- case 'ser_close_video':
3276
- console.log('视频框 ' + self.index + ' 视频已关闭');
3277
- self.isClosing = false;
3278
- self.videoListener.dispatch('notifyCloseVideo', self);
3279
- break;
3280
- default:
3281
- console.log('event:' + event);
3282
- break;
3283
- }
3284
- },
3285
-
3286
- //处理远程流
3287
- onremotestream: function(stream) {
3288
- console.log('onremotestream:分屏=' + (self.index + 1) + ', video=' + self.video);
3289
- Janus.attachMediaStream(self.tagBox.get(0), stream);
3290
- },
3291
-
3292
- //处理本地流
3293
- onlocalstream: function(stream) {
3294
- stream.getAudioTracks()[0].enabled = false;
3295
- self.stream = stream;
3296
- },
3297
-
3298
- //清理
3299
-
3300
- oncleanup: function() {
3301
- console.log('oncleanup:分屏=' + (self.index + 1));
3302
- }
3303
- });
3304
-
3305
- //<video>注册playing/canplay事件,用于判断视频播放成功
3306
- self.tagBox.bind("canplay play playing", function () {
3307
- if(self.video){
3308
- if (self.tagBox.is(':visible')) return;
3309
-
3310
- // 清除播放监测定时任务,清除内容
3311
- self.playSucTimeOutIndex > 0 && clearTimeout(self.playSucTimeOutIndex);
3312
- self.tagBox.parent().find(".video-tip").remove();
3313
-
3314
- console.log('分屏=' + (self.index + 1) + ', ' + self.video + ' 播放成功');
3315
- promptSuccess('分屏' + (self.index + 1) + ' 播放成功');
3316
- self.tagBox.show();
3317
- //self.tagBox.parent().removeClass("loading").find(".stream-loading").remove();
3318
- self.tagBox.parent().find(".stream-loading").remove();
3319
-
3320
- //显示视频信息
3321
- self.tagBox.parent().find('.info').show();
3322
-
3323
- //显示音频按钮
3324
- self.tagBox.parent().find('.operate-btn button').show();
3325
- if (self.isPlayBack) {
3326
- self.tagBox.parent().find('.unrecv-audio-btn').hide();
3327
- }
3328
- self.tagBox.parent().find('.recv-audio-btn').attr("class", "unrecv-audio-btn");
3329
- self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
3330
-
3331
- var width = this.videoWidth;
3332
- var height = this.videoHeight;
3333
- //保持长宽比例填充video视频框
3334
- if (width <= height && width != '0') {
3335
- self.tagBox.css('object-fit', 'contain');
3336
- }
3337
- }
3338
- });
3339
- },
3340
-
3341
- /**
3342
- * 播放视频
3343
- * video:视频编号(ID)
3344
- */
3345
- play:function(video){
3346
- if(!video){
3347
- //alert("请输入视频ID");
3348
- promptAlarm('视频ID不能为空');
3349
- return;
3350
- }
3351
- var body = {
3352
- request: "call",
3353
- videoidentify: video,
3354
- playseq: this.index,
3355
- userToken: this.userToken,
3356
- autoack: true
3357
- };
3358
- this.sipcall.send({"message": body });
3359
- this.video = video;
3360
- this.isClosing = false;
3361
- this.playing = true;
3362
- this.packetsLostRate = '0.00%';
3363
- this.packetsLostSum = 0;
3364
- this.packetsReceivedSum = 0;
3365
- var numIndex = this.index + 1;
3366
- var framesDecodedDom = document.getElementById("frame-decoded-" + numIndex);
3367
- framesDecodedDom.style.display = 'none';
3368
- this.framesDecodedLast = undefined;
3369
- this.framesDecodedCount = 0;
3370
-
3371
- //loading
3372
- var _li = this.tagBox.parent();
3373
- clearResult(_li, this);
3374
- if(!_li.hasClass("loading")){
3375
- _li.addClass("loading").append('<div class="stream-loading">等待数据流传送...</div>');
3376
- }
3377
- _li.find('.operate-btn .close-btn').show();
3378
- console.log("视频播放:分屏=" + (this.index + 1) + ",设备ID=" + video);
3379
- },
3380
-
3381
- close:function(type){
3382
- if (!type) {
3383
- this.isLockVideo = false;
3384
- this.tagBox.parent().find('.lock-video-btn').attr("class", "unlock-video-btn");
3385
- }
3386
- //清除结果提示内容
3387
- clearResult(this.tagBox.parent(), this);
3388
-
3389
- //var reqType = type ? type : "hangup";
3390
- if(!this.playing) return;
3391
- var _hangup = {
3392
- request: "hangup",
3393
- videoidentify: this.video,
3394
- playseq: this.index,
3395
- userToken: this.userToken
3396
- };
3397
- this.sipcall.send({"message": _hangup});
3398
- this.sipcall.hangup();
3399
- this.tagBox.hide();
3400
- this.isClosing = true;
3401
- this.playing = false;
3402
- this.video = null;
3403
- this.packetsLostRate = '0.00%';
3404
- this.packetsLostSum = 0;
3405
- this.packetsReceivedSum = 0;
3406
- //清除显示的视频信息
3407
- document.getElementById('info-' + (Number(this.index) + Number(1))).innerHTML = '';
3408
- //隐藏视频信息
3409
- this.tagBox.parent().find('.info').hide();
3410
- //隐藏音频喇叭
3411
- this.tagBox.parent().find('.operate-btn button').hide();
3412
- //避免没收到成功时就点击关闭,清除loading框
3413
- this.tagBox.parent().removeClass("loading").find(".stream-loading").remove();
3414
- //清除object-fit
3415
- this.tagBox.css('object-fit', '');
3416
- // 清除内容提示
3417
- this.playSucTimeOutIndex > 0 && clearTimeout(this.playSucTimeOutIndex);
3418
- this.tagBox.parent().find(".video-tip").remove();
3419
- var numIndex = Number(this.index) + 1;
3420
- var framesDecodedDom = document.getElementById("frame-decoded-" + numIndex);
3421
- framesDecodedDom.style.display = 'none';
3422
- this.framesDecodedLast = undefined;
3423
- this.framesDecodedCount = 0;
3424
- },
3425
-
3426
- /**
3427
- * 云台控制
3428
- * up 上
3429
- * down 下
3430
- * left 左
3431
- * right 右
3432
- * upleft 上左
3433
- * upright 上右
3434
- * downleft 下左
3435
- * downright 下右
3436
- * zoomin 倍率变大
3437
- * zoomout 倍率变下
3438
- * focusnear 焦点+
3439
- * focusfar 焦点-
3440
- * irisopen 光圈+
3441
- * irisclose 光圈-
3442
- * pointset 设置预置点
3443
- * pointdel 删除预置点
3444
- * pointgoto 到预置点
3445
- * scansetleft 自动扫描左边界
3446
- * scansetright 自动扫描又边界
3447
- * scansetspeed 设置扫描速度
3448
- * scanrun 自动扫描运行
3449
- * cruiseadd 添加巡航点
3450
- * cruisedel 删除巡航点
3451
- * cruisespeed 设置巡航点速度
3452
- * cruisepausetime 设置巡航滞留时间
3453
- * cruiserun 启动巡航
3454
- */
3455
- holder: function(type, opts, isStop) {
3456
- if(!this.video || !this.playing){
3457
- promptAlarm('未选中播放的视频!');
3458
- return;
3459
- }
3460
-
3461
- var holdType = 'up down left right upleft upright downleft downright zoomin zoomout focusnear focusfar irisopen irisclose pointset pointdel pointgoto '+
3462
- 'scansetleft scansetright scansetspeed scanrun cruiseadd cruisedel cruisespeed cruisepausetime cruiserun';
3463
- var typeVal = (Number(holdType.split(' ').indexOf(type))+Number(1));
3464
-
3465
- console.log("holdType:" + typeVal + " type:" + type + (isStop ? ' 停止' : ''));
3466
-
3467
- if (!typeVal || typeVal <= 0) {
3468
- console.error('异常PTZ指令:' + typeVal);
3469
- return false;
3470
- }
3471
-
3472
- var body = {
3473
- request: "ptz",
3474
- videoidentify: this.video,
3475
- playseq: this.index,
3476
- userToken: this.userToken,
3477
- };
3478
-
3479
- body.cmd = {
3480
- speed: opts.speed ? opts.speed : 200,
3481
- group: 0,
3482
- present: opts.present ? opts.present : 0,
3483
- time: 0,
3484
- type: typeVal
3485
- }
3486
-
3487
- if(isStop) {
3488
- console.log(">>>>yuntai control,stop, video=" + this.video);
3489
- body.cmd.action = 1;
3490
- } else {
3491
- body.cmd.action = 0;
3492
- console.log('设备号:'+this.video+', 云台移动-->'+ type);
3493
- }
3494
-
3495
- this.sipcall.send({"message": body });
3496
- },
3497
-
3498
- /**
3499
- * 历史回放
3500
- * video设备ID startTime录像开始 stopTime录像结束 例:2015-07-22T12:00:00,注意T隔开
3501
- */
3502
- playback: function(video, startTime, stopTime) {
3503
- if(!video){
3504
- promptAlarm('视频ID不能为空');
3505
- return;
3506
- }
3507
-
3508
- var body = {
3509
- request: "av_playback",
3510
- videoidentify: video,
3511
- playseq: this.index,
3512
- userToken: this.userToken,
3513
- start_time: startTime,
3514
- stop_time: stopTime
3515
- };
3516
-
3517
- console.log(">>>>playback video=" + video +" startTime=" + startTime + " stopTime=" + stopTime);
3518
- this.sipcall.send({"message": body });
3519
- this.video = video;
3520
- this.playing = true;
3521
- this.packetsLostRate = '0.00%';
3522
- this.packetsLostSum = 0;
3523
- this.packetsReceivedSum = 0;
3524
- this.isPlayBack = true;
3525
-
3526
- //loading
3527
- var _li = this.tagBox.parent();
3528
- clearResult(_li, this);
3529
- if(!_li.hasClass("loading")){
3530
- _li.addClass("loading").append('<div class="stream-loading">等待数据流传送...</div>');
3531
- }
3532
- _li.find('.operate-btn .close-btn').show();
3533
- console.log("历史回放:分屏=" + (this.index + 1) + ",视频ID=" + video);
3534
- },
3535
-
3536
- /**
3537
- * 历史回放控制
3538
- * video设备ID playType类型 playSpeed速率 startTime开始时间
3539
- */
3540
- playbackControl: function(video, playType, playSpeed, startTime) {
3541
- var self = this;
3542
-
3543
- var body = {
3544
- request: "av_control",
3545
- videoidentify: video,
3546
- playseq: self.index,
3547
- userToken: self.userToken,
3548
- start_time: startTime,
3549
- rate: String(playSpeed),
3550
- cmd: playType
3551
- };
3552
-
3553
- console.log(">>>>playbackControl video=" + video + " playType=" + playType + " playSpeed=" + playSpeed);
3554
-
3555
- //setTimeout(function (){
3556
- self.sipcall.send({"message": body });
3557
- //}, 1000);
3558
-
3559
- if (playType == 'stop') {
3560
- self.close();
3561
-
3562
- self.tagBox.hide();
3563
- self.playing = false;
3564
- self.video = null;
3565
- self.packetsLostRate = '0.00%';
3566
- self.packetsLostSum = 0;
3567
- self.packetsReceivedSum = 0;
3568
- self.isPlayBack = false;
3569
- //清除显示的视频信息
3570
- document.getElementById('info-' + (Number(self.index) + Number(1))).innerHTML = '';
3571
-
3572
- //隐藏音频喇叭
3573
- this.tagBox.parent().find('.operate-btn button').hide();
3574
- //避免没收到成功时就点击关闭,清除loading框
3575
- self.tagBox.parent().removeClass("loading").find(".stream-loading").remove();
3576
- //清除object-fit
3577
- self.tagBox.css('object-fit', '');
3578
- }
3579
- },
3580
-
3581
- /**
3582
- * 音频流操作
3583
- * requstType: recv_audio、stop_audio、send_audio、unsend_audio
3584
- */
3585
- operateAudio: function(requestType) {
3586
- var self = this;
3587
-
3588
- if(!self.video){
3589
- promptAlarm('视频ID不能为空');
3590
- return;
3591
- }
3592
- var body = {
3593
- request: requestType,
3594
- videoidentify: self.video,
3595
- playseq: self.index,
3596
- userToken: self.userToken,
3597
- };
3598
-
3599
- self.sipcall.send({"message": body });
3600
- console.log("音频操作="+ requestType +", 分屏=" + (self.index + 1) + ",设备ID=" + self.video);
3601
- },
3602
-
3603
- /**
3604
- * 录像操作
3605
- * requstType: start_av_record(开启录像)、stop_av_record(停止录像)
3606
- */
3607
- recordAv: function(requestType, businessId) {
3608
- var self = this;
3609
-
3610
- if(!self.video){
3611
- promptAlarm('视频ID不能为空');
3612
- return;
3613
- }
3614
- var body = {
3615
- request: requestType,
3616
- videoidentify: self.video,
3617
- playseq: self.index,
3618
- userToken: self.userToken,
3619
- businessid: businessId || null
3620
- };
3621
-
3622
- self.sipcall.send({"message": body });
3623
- console.log("录像操作="+ requestType +", 分屏=" + (self.index + 1) + ",设备ID=" + self.video + ",业务ID=" + (businessId || null));
3624
- },
3625
-
3626
- /**
3627
- * 修改分辨率
3628
- * requstType: change_resolution
3629
- * CIF 480P 720P 1080P
3630
- */
3631
- changeResolution: function(requestType, resolution) {
3632
- var self = this;
3633
-
3634
- if(!self.video){
3635
- promptAlarm('视频ID不能为空');
3636
- return;
3637
- }
3638
-
3639
- var body = {
3640
- request: requestType,
3641
- videoidentify: self.video,
3642
- playseq: self.index,
3643
- resolution: resolution,
3644
- userToken: self.userToken,
3645
- };
3646
-
3647
- self.sipcall.send({"message": body });
3648
- console.log("修改分辨率操作="+ resolution +", 分屏=" + (self.index + 1) + ",设备ID=" + self.video);
3649
- },
3650
-
3651
- /**
3652
- * 对象预呼叫
3653
- * requstType: open_poccall(开启) close_poccall(关闭)
3654
- * pocno
3655
- * centerTel
3656
- */
3657
- pocCall: function(requestType, pocNo, centerTel) {
3658
- var self = this;
3659
-
3660
- var body = {
3661
- request: requestType,
3662
- pocno: pocNo,
3663
- playseq: self.index,
3664
- center_tel: centerTel,
3665
- userToken: self.userToken,
3666
- };
3667
-
3668
- self.sipcall.send({"message": body });
3669
- console.log("预呼叫操作="+ requestType +", 对讲号码=" + pocNo + ",调度中心号码=" + centerTel);
3670
- },
3671
-
3672
- /**
3673
- * 点对点对讲
3674
- * requstType: open_ptop_poc(开启) close_poc_poc(关闭)
3675
- * pocno
3676
- */
3677
- ptopPoc: function(requestType, pocNo) {
3678
- var self = this;
3679
-
3680
- var body = {
3681
- request: requestType,
3682
- pocno: pocNo,
3683
- playseq: self.index,
3684
- pocmember: self.video,
3685
- userToken: self.userToken,
3686
- };
3687
-
3688
- self.sipcall.send({"message": body });
3689
- console.log("点对点对讲操作="+ requestType +", 主叫号码=" + pocNo + ",被叫号码=" + self.video);
3690
- }
3691
- }
3692
-
3693
- return isIE() ? VideoOcx : VideoWebRtc;
3694
- }));
3695
-