ucservice 1.5.0 → 1.5.3

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.
@@ -298,7 +298,14 @@
298
298
  }
299
299
  }
300
300
  return e.returnValue;
301
- }
301
+ },
302
+
303
+ /**
304
+ * 清空事件
305
+ */
306
+ removeAllListeners: function () {
307
+ this._listeners = {};
308
+ }
302
309
  }
303
310
 
304
311
  let videoListener = new Listener();
@@ -916,20 +923,20 @@
916
923
  * 添加事件
917
924
  */
918
925
  addListener: function(type,handler,key){
919
- videoListener.addListener(type,handler,key);
926
+ this.videoListener.addListener(type,handler,key);
920
927
  },
921
928
 
922
929
  /**
923
930
  * 删除事件
924
931
  */
925
932
  removeListener: function(type,handler){
926
- videoListener.removeListener(type,handler);
933
+ this.videoListener.removeListener(type,handler);
927
934
  },
928
935
  /**
929
936
  * 派发事件
930
937
  */
931
938
  dispatch: function(e,options){
932
- videoListener.dispatch(e,options);
939
+ this.videoListener.dispatch(e,options);
933
940
  },
934
941
 
935
942
  /**
@@ -1306,10 +1313,12 @@
1306
1313
  */
1307
1314
  function VideoWebRtc($dom,opts){
1308
1315
  let _self = this;
1316
+ _self.videoListener = new Listener();
1309
1317
  if (!opts) {
1310
1318
  console.error('VideoWebRtc的参数opts不能为空');
1311
1319
  return;
1312
1320
  }
1321
+ _self.configOpt = (opts && opts.configOpt) || 3;
1313
1322
  hasMediaDevices();
1314
1323
  //检测声卡设备为异步方法,耗时在几十毫秒左右,因此需要做延迟
1315
1324
  //默认检查次数为40 间隔为20ms
@@ -1318,10 +1327,52 @@
1318
1327
  if (count == 40) {
1319
1328
  clearInterval(index);
1320
1329
  _self._init($dom,opts);
1330
+ let resizeObserver = new ResizeObserver(function( entries ) {
1331
+ // console.log(entries)
1332
+ entries.forEach((item, index) =>{
1333
+ let target = item.target
1334
+ let videoLi = document.getElementById(me.selector).querySelectorAll('li')
1335
+ _self.VIDEO_DATA.forEach((item, index) => {
1336
+ let tel = item.video
1337
+ if (!tel&&item.id) {
1338
+ videoLi[index].querySelector('video').style = ''
1339
+ videoLi[index].querySelector('.rotate-btn').setAttribute('rotate-index', 0)
1340
+ }else{
1341
+ let rotateIndex = $(videoLi[index]).find('button[name=rotateVideo]').attr('rotate-index')
1342
+ setTimeout(() => {
1343
+ _self.videoRotateSize(videoLi[index], rotateIndex);
1344
+ }, 200);
1345
+ }
1346
+ })
1347
+ })
1348
+ })
1349
+ // 监听dom
1350
+ resizeObserver.observe(document.querySelector(_self.selector))
1321
1351
  } else {
1322
1352
  if (window.checkAudioDevicesStatus) {
1323
1353
  clearInterval(index);
1324
1354
  _self._init($dom,opts);
1355
+ let resizeObserver = new ResizeObserver(function( entries ) {
1356
+ // console.log(entries)
1357
+ entries.forEach((item, index) =>{
1358
+ let target = item.target
1359
+ let videoLi = document.getElementById(me.selector).querySelectorAll('li')
1360
+ _self.VIDEO_DATA.forEach((item, index) => {
1361
+ let tel = item.video
1362
+ if (!tel&&item.id) {
1363
+ videoLi[index].querySelector('video').style = ''
1364
+ videoLi[index].querySelector('.rotate-btn').setAttribute('rotate-index', 0)
1365
+ }else{
1366
+ let rotateIndex = $(videoLi[index]).find('button[name=rotateVideo]').attr('rotate-index')
1367
+ setTimeout(() => {
1368
+ _self.videoRotateSize(videoLi[index], rotateIndex);
1369
+ }, 200);
1370
+ }
1371
+ })
1372
+ })
1373
+ })
1374
+ // 监听dom
1375
+ resizeObserver.observe(document.querySelector(_self.selector))
1325
1376
  }
1326
1377
  }
1327
1378
  count++;
@@ -1347,6 +1398,11 @@
1347
1398
  // console.info('该视频正在播放');
1348
1399
  // return false;
1349
1400
  // }
1401
+ // 启用播放队列时,当前位置正在关闭上一个视频,则加入播放队列
1402
+ if (me.waitPlayQueueSwitch && me.VIDEO_DATA[index].isClosing) {
1403
+ me._addWaitingVideo(index, video, id, opts);
1404
+ return ;
1405
+ }
1350
1406
  console.log("play >>> " + "video=" + video + "; id=" + id + "; index=" + index);
1351
1407
  me.dispatch('beforeplay',{index:index, video:video, id:id});
1352
1408
 
@@ -1441,7 +1497,7 @@
1441
1497
  */
1442
1498
  playInChoice: function(video, id, opts){
1443
1499
  let me = this;
1444
- let selView = $('[video-flag="'+me._opts.windowsBeginIndex+'"]>li.sel');
1500
+ let selView = $(me.selector + ' li.sel');
1445
1501
  if(selView.length){
1446
1502
  if (me.VIDEO_DATA[selView.index()].playing) {
1447
1503
  me.close(selView.index());
@@ -1498,6 +1554,7 @@
1498
1554
  this.VIDEO_DATA[index].close();
1499
1555
 
1500
1556
  if (!isSave) {
1557
+ this.VIDEO_DATA[index].closeType = 'close';
1501
1558
  this.dispatch('afterclose', this.VIDEO_DATA[index]);
1502
1559
  }
1503
1560
 
@@ -1524,6 +1581,7 @@
1524
1581
  me.close(videoData[i].index);
1525
1582
 
1526
1583
  if (!isSave) {
1584
+ videoData[i].closeType = 'close';
1527
1585
  me.dispatch('afterclose', videoData[i]);
1528
1586
  }
1529
1587
  }
@@ -1535,12 +1593,14 @@
1535
1593
  */
1536
1594
  closeAll: function(isSave){
1537
1595
  let me = this;
1538
-
1596
+ // 清除所有等待播放队列
1597
+ me._removeAllWaitingVideo();
1539
1598
  let openVideos = [];
1540
1599
  for(let i = me._opts.windowsBeginIndex; i < me._opts.windowsBeginIndex + me._opts.windowsNum; i++){
1541
- if(me.VIDEO_DATA[i].playing){
1542
- me.close(i, isSave)
1543
- }
1600
+ // if(me.VIDEO_DATA[i].playing){
1601
+ // me.close(i, isSave)
1602
+ // }
1603
+ me.close(i, isSave);
1544
1604
  }
1545
1605
 
1546
1606
  // if(!openVideos.length) return;
@@ -1582,8 +1642,8 @@
1582
1642
  me.setChoiceWindow(me._getMinIndexFreeWindow());
1583
1643
  }
1584
1644
 
1585
- $('[video-flag="'+me._opts.windowsBeginIndex+'"]').removeClass("mode-" + me._opts.windows).addClass("mode-" + num);
1586
- let _li = $('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').hide();
1645
+ $(me.selector + ' .video-main').removeClass("mode-" + me._opts.windows).addClass("mode-" + num);
1646
+ let _li = $(me.selector + ' li').hide();
1587
1647
  me._opts.windows = num;
1588
1648
  for(let i = 0; i < num; i++){
1589
1649
  _li.eq(i).show();
@@ -1592,7 +1652,7 @@
1592
1652
  this.dispatch('screenchange', {windowNums:num, flag:me._opts.flag});
1593
1653
 
1594
1654
  //设置旋转了的视频样式
1595
- let videoLi = document.getElementById('videoRef').querySelectorAll('li')
1655
+ let videoLi = document.getElementById(me.selector).querySelectorAll('li')
1596
1656
  me.VIDEO_DATA.forEach((item, index) => {
1597
1657
  let tel = item.video
1598
1658
  if (!tel&&item.id) {
@@ -1603,11 +1663,11 @@
1603
1663
  //设置旋转视频的样式
1604
1664
  for(let k = 0; k < _li.length; k++){
1605
1665
  let rotateIndex = _li.eq(k).find('button[name=rotateVideo]').attr('rotate-index');
1606
- if(rotateIndex != 0 && rotateIndex != 2){
1666
+ // if(rotateIndex != 0 && rotateIndex != 2){
1607
1667
  setTimeout(() => {
1608
1668
  me.videoRotateSize(_li.eq(k)[0], rotateIndex);
1609
1669
  }, 200);
1610
- }
1670
+ // }
1611
1671
  }
1612
1672
 
1613
1673
  },
@@ -1639,23 +1699,34 @@
1639
1699
  this._polltimer = new PollTimer(function(firstRun){
1640
1700
  me.closeAll();
1641
1701
 
1642
- wait(500).then(function(){
1643
- for(let i = 0; i < windowNum; i++) {
1702
+ if (firstRun) {
1703
+ for(let i = 0; i < windowNum; i++) {
1644
1704
  if(nowNum == maxNum){
1645
- nowNum = 0;
1646
- if(maxNum < windowNum) {
1647
- break;
1648
- }
1705
+ nowNum = 0;
1706
+ if(maxNum < windowNum) {
1707
+ break;
1708
+ }
1649
1709
  }
1650
-
1710
+
1651
1711
  me.playByOrder(array[nowNum].video, array[nowNum].id, array[nowNum].opts);
1652
1712
  nowNum++;
1653
- }
1654
- if (firstRun) {
1713
+ }
1655
1714
  me.dispatch('startpoll', array);
1656
- }
1657
- })
1658
-
1715
+ }else {
1716
+ wait(1500).then(function(){
1717
+ for(let i = 0; i < windowNum; i++) {
1718
+ if(nowNum == maxNum){
1719
+ nowNum = 0;
1720
+ if(maxNum < windowNum) {
1721
+ break;
1722
+ }
1723
+ }
1724
+
1725
+ me.playByOrder(array[nowNum].video, array[nowNum].id, array[nowNum].opts);
1726
+ nowNum++;
1727
+ }
1728
+ })
1729
+ }
1659
1730
  }, time);
1660
1731
  },
1661
1732
 
@@ -1780,9 +1851,9 @@
1780
1851
  */
1781
1852
  getInChoiceVideo: function() {
1782
1853
  let me = this;
1783
- let selView = $('[video-flag="'+me._opts.windowsBeginIndex+'"]>li.sel');
1784
- if(selView.length && me.VIDEO_DATA[selView.index()].video){
1785
- return me.VIDEO_DATA[selView.index()];
1854
+ let selView = $(me.selector + ' li.sel');
1855
+ if(selView.length && me.VIDEO_DATA[selView.attr("index")].video){
1856
+ return me.VIDEO_DATA[selView.attr("index")];
1786
1857
  }
1787
1858
  return undefined;
1788
1859
  },
@@ -1818,13 +1889,21 @@
1818
1889
 
1819
1890
  let canvasObj = document.getElementById('myCanvas');
1820
1891
  let videoObj = dataObj.tagBox.get(0);
1821
-
1822
- canvasObj.width = dataObj.tagBox.parent().width();
1823
- canvasObj.height = dataObj.tagBox.parent().height();
1892
+ if (videoObj == undefined) {
1893
+ return;
1894
+ }
1895
+ // 取流中 取视频框尺寸
1896
+ // 播放中 取视频画面尺寸
1897
+ if (dataObj.tagBox.parent().find(".stream-loading").length != 0) {
1898
+ canvasObj.width = dataObj.tagBox.width();
1899
+ canvasObj.height = dataObj.tagBox.height();
1900
+ } else {
1901
+ canvasObj.width = videoObj.videoWidth;
1902
+ canvasObj.height = videoObj.videoHeight;
1903
+ }
1824
1904
 
1825
1905
  let ctx = canvasObj.getContext("2d");
1826
- ctx.drawImage(videoObj, 0, 0, dataObj.tagBox.parent().width(),
1827
- dataObj.tagBox.parent().height());
1906
+ ctx.drawImage(videoObj, 0, 0, videoObj.videoWidth, videoObj.videoHeight);
1828
1907
 
1829
1908
  let dataUrl = canvasObj.toDataURL('image/jpeg');
1830
1909
  callback ? callback(dataUrl) : null;
@@ -1874,7 +1953,8 @@
1874
1953
  if (index < 0) {
1875
1954
  console.error('窗口编号获取失败!')
1876
1955
  }
1877
-
1956
+ //保存对讲号码
1957
+ window.pocNo = pocNo;
1878
1958
  return me.VIDEO_DATA[index].pocCall("open_poccall", pocNo, centerTel);
1879
1959
  },
1880
1960
 
@@ -1899,6 +1979,7 @@
1899
1979
  }
1900
1980
 
1901
1981
  me.VIDEO_DATA[index].stream = null;
1982
+ window.pocNo = null;
1902
1983
  return me.VIDEO_DATA[index].pocCall("close_poccall", pocNo, centerTel);
1903
1984
  },
1904
1985
 
@@ -1933,22 +2014,28 @@
1933
2014
  * 添加事件
1934
2015
  */
1935
2016
  addListener: function(type, handler, key){
1936
- videoListener.addListener(type, handler, key);
2017
+ this.videoListener.addListener(type, handler, key);
1937
2018
  },
1938
2019
 
1939
2020
  /**
1940
2021
  * 删除事件
1941
2022
  */
1942
2023
  removeListener: function(type, handler){
1943
- videoListener.removeListener(type, handler);
2024
+ this.videoListener.removeListener(type, handler);
1944
2025
  },
1945
2026
  /**
1946
2027
  * 派发事件
1947
2028
  */
1948
2029
  dispatch: function(e, options){
1949
- videoListener.dispatch(e, options);
2030
+ this.videoListener.dispatch(e, options);
1950
2031
  },
1951
2032
 
2033
+ /**
2034
+ * 清空事件
2035
+ */
2036
+ removeAllListeners: function() {
2037
+ this.videoListener.removeAllListeners();
2038
+ },
1952
2039
  /**
1953
2040
  * 获取编号最小的空闲窗口的编号
1954
2041
  */
@@ -1956,7 +2043,7 @@
1956
2043
  let me = this;
1957
2044
  index = index || me._opts.windowsBeginIndex;
1958
2045
  for (; index < me._opts.windowsBeginIndex + me._opts.windows ; index++) {
1959
- if (!me.VIDEO_DATA[index].playing) {
2046
+ if (!me.VIDEO_DATA[index].playing && !me.VIDEO_DATA[index].isWaiting) {
1960
2047
  return index;
1961
2048
  }
1962
2049
  }
@@ -1968,7 +2055,7 @@
1968
2055
  */
1969
2056
  _getChoiceWindow: function() {
1970
2057
  let me = this;
1971
- let selView = $('[video-flag="' + me._opts.windowsBeginIndex+'"]>li.sel');
2058
+ let selView = $(me.selector + ' li.sel');
1972
2059
  if (selView.length) {
1973
2060
  return selView.index();
1974
2061
  }
@@ -1997,8 +2084,8 @@
1997
2084
  _clickWindow: function() {
1998
2085
  let me = this;
1999
2086
  //视频窗口选中
2000
- $('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').click(function(){
2001
- $('[video-flag="'+me._opts.windowsBeginIndex+'"]>li').removeClass("sel");
2087
+ $(me.selector + ' li').click(function(){
2088
+ $(me.selector + ' li').removeClass("sel");
2002
2089
  $(this).addClass("sel");
2003
2090
 
2004
2091
  //如果视频正在播放则分发点击消息
@@ -2006,6 +2093,33 @@
2006
2093
  me.dispatch('click', me.getInChoiceVideo());
2007
2094
  }
2008
2095
  });
2096
+ // 设置视频窗可拖拽
2097
+ let src = null;
2098
+ $(me.selector + ' li').bind("dragstart", function (ev) {
2099
+ src = $(this);
2100
+ })
2101
+
2102
+ $(me.selector + ' li').bind("dragover", function (ev) {
2103
+ ev.preventDefault();
2104
+ })
2105
+
2106
+ $(me.selector + ' li').bind("drop", function (ev) {
2107
+ ev.preventDefault();
2108
+ if(src.prop("outerHTML") === $(this).prop("outerHTML")){
2109
+ return;
2110
+ }
2111
+ let target = $(this);
2112
+ let srcIndex = src.index();
2113
+ let targetIndex = target.index();
2114
+
2115
+ if (srcIndex > targetIndex) {
2116
+ src.insertBefore(target);
2117
+ target.insertAfter($(me.selector +' .video-main li.screen').eq(srcIndex));
2118
+ } else {
2119
+ src.insertAfter(target);
2120
+ target.insertBefore($(me.selector +' .video-main li.screen').eq(srcIndex));
2121
+ }
2122
+ })
2009
2123
  },
2010
2124
 
2011
2125
  /*
@@ -2034,7 +2148,11 @@
2034
2148
  conf: {},
2035
2149
  pollInterval: 10,
2036
2150
  windowsNum: 16,
2037
- isVideoTag: true //true生成video标签 false生产audio标签 默认true
2151
+ isVideoTag: true, //true生成video标签 false生产audio标签 默认true
2152
+ showVideoInfo: 1, //显示分辨率、码率等信息,1-显示左下角 2-显示左上角,为0时控制_showVideoInfo函数处理,默认1
2153
+ waitPlayQueueSwitch: false, //播放队列开关,默认false
2154
+ defaultBusinessType: 0, // 配置的默认业务类型 0:调度主线 1:勤指
2155
+ videoTipTimeOut: 5, // 超时无首屏检测时间
2038
2156
  };
2039
2157
 
2040
2158
  $.extend(me._opts,opts);
@@ -2053,23 +2171,32 @@
2053
2171
  }
2054
2172
 
2055
2173
  //获取起始的窗口位置
2056
- me._opts.windowsBeginIndex = windowsSum;
2057
- //窗口总数
2058
- windowsSum += me._opts.windowsNum;
2174
+ me._opts.windowsBeginIndex = 0;
2175
+ // 对讲号码初始化
2176
+ window.pocNo = 0;
2177
+ // 播放队列开关 默认打开
2178
+ me.waitPlayQueueSwitch = opts.waitPlayQueueSwitch == undefined ? false : opts.waitPlayQueueSwitch;
2059
2179
 
2060
2180
  //是否提示
2061
2181
  me._opts.showPrompt === false && (showPrompt = false);
2062
- //初始化界面
2063
- me._opts.isVideoTag ? me._initVideoView($dom) : me._initAudioView($dom);
2182
+ // 勤指业务下 设备检测
2183
+ me._opts.defaultBusinessType == 1 && me._checkDevices();
2184
+ //初始化界面
2185
+ me._opts.isVideoTag ? me._initVideoView($dom, me._opts.showVideoInfo) : me._initAudioView($dom);
2186
+
2064
2187
  //初始化Janus
2065
2188
  me._initJanus();
2066
2189
  //初始化按钮点击事件
2067
2190
  me._initBtnEvent();
2191
+ // 初始化事件监听
2192
+ me._initEventListen();
2068
2193
 
2069
2194
  //设置鼠标点击选中窗口
2070
2195
  me._clickWindow();
2071
- //显示视频信息:名称、分辨率、码率、丢包率
2072
- me._showVideoInfo();
2196
+ if (me._opts.showVideoInfo != 0) {
2197
+ //显示视频信息:名称、分辨率、码率、丢包率
2198
+ me._showVideoInfo();
2199
+ }
2073
2200
  //双击某个视频全屏
2074
2201
  me._dbClickFullScreen();
2075
2202
  },
@@ -2172,36 +2299,7 @@
2172
2299
  */
2173
2300
  _initBtnEvent: function() {
2174
2301
  let me = this;
2175
-
2176
- // 设置视频窗可拖拽
2177
- var src = null;
2178
- $(me.selector + ' li').bind("dragstart", function (ev) {
2179
- src = $(this);
2180
- })
2181
-
2182
- $(me.selector + ' li').bind("dragover", function (ev) {
2183
- ev.preventDefault();
2184
- })
2185
-
2186
- $(me.selector + ' li').bind("drop", function (ev) {
2187
- ev.preventDefault();
2188
- if(src.prop("outerHTML") === $(this).prop("outerHTML")){
2189
- return;
2190
- }
2191
- var target = $(this);
2192
- var srcIndex = src.index();
2193
- var targetIndex = target.index();
2194
-
2195
- if (srcIndex > targetIndex) {
2196
- src.insertBefore(target);
2197
- target.insertAfter($(me.selector +' .video-main li.screen').eq(srcIndex));
2198
- } else {
2199
- src.insertAfter(target);
2200
- target.insertBefore($(me.selector +' .video-main li.screen').eq(srcIndex));
2201
- }
2202
- })
2203
-
2204
- let videoFlagObj = $('[video-flag="'+me._opts.windowsBeginIndex+'"]');
2302
+ let videoFlagObj = $(me.selector + ' .video-main');
2205
2303
 
2206
2304
  //锁定视频事件
2207
2305
  videoFlagObj.find("button[name='lockVideo']").click(function(){
@@ -2219,6 +2317,8 @@
2219
2317
  me.VIDEO_DATA[index].isLockVideo = true;
2220
2318
  $(this).attr('class', 'lock-video-btn');
2221
2319
  }
2320
+ //jquery方式阻止默认事件 & 冒泡事件
2321
+ return false;
2222
2322
  });
2223
2323
  videoFlagObj.find('button[name=rotateVideo]').click(function(){
2224
2324
  let rotateIndex = Number($(this).attr("rotate-index"));
@@ -2227,12 +2327,16 @@
2227
2327
  $(this).attr("rotate-index", rotateIndex);
2228
2328
  let li = $(this).parent().parent()[0];
2229
2329
  me.videoRotateSize(li, rotateIndex)
2330
+ //jquery方式阻止默认事件 & 冒泡事件
2331
+ return false;
2230
2332
  })
2231
2333
 
2232
2334
  //接收音频事件
2233
2335
  videoFlagObj.find("button[name='recvAudio']").click(function(){
2234
2336
  let _self = this;
2235
2337
  let index = Number($(this).parent().parent().attr("index"));
2338
+ // 优先当前窗口参数设置的业务类型 其次配置的默认业务类型
2339
+ let businessType = me.VIDEO_DATA[index].opts.businessType == undefined ? me._opts.defaultBusinessType : me.VIDEO_DATA[index].opts.businessType;
2236
2340
 
2237
2341
  if (!me.VIDEO_DATA[index].playing) {
2238
2342
  promptAlarm('请选择播放的视频源!');
@@ -2243,8 +2347,9 @@
2243
2347
  //发送停止播放音频的请求
2244
2348
  me.VIDEO_DATA[index].operateAudio("stop_audio")
2245
2349
  $(this).attr('class', 'unrecv-audio-btn');
2246
- me.VIDEO_DATA[index].tagBox.muted = false;
2350
+ me.VIDEO_DATA[index].tagBox.prop("muted", true);
2247
2351
  } else {
2352
+ if (businessType == 0) {
2248
2353
  //发送前先关闭其它音频通道(包括接收和发送音频)
2249
2354
  let lis = $($(_self).parent().parent().parent()).children();
2250
2355
  for (let i = 0; i < lis.length; i++) {
@@ -2269,21 +2374,33 @@
2269
2374
  //发送播放音频的请求
2270
2375
  $(_self).attr('class', 'recv-audio-btn');
2271
2376
  setTimeout(function () {
2272
- me.VIDEO_DATA[index].operateAudio("recv_audio");
2273
- me.VIDEO_DATA[index].tagBox.muted = true;
2377
+ if(!me.VIDEO_DATA[index].isClosing){
2378
+ me.VIDEO_DATA[index].operateAudio("recv_audio");
2379
+ me.VIDEO_DATA[index].tagBox.prop("muted", false);
2380
+ }
2274
2381
  }, 1000);
2382
+ } else if (businessType == 1) {
2383
+ // poc新模式支持回传多个音频,因此不关闭
2384
+ //发送播放音频的请求
2385
+ $(_self).attr('class', 'recv-audio-btn');
2386
+ me.VIDEO_DATA[index].operateAudio("recv_audio");
2387
+ me.VIDEO_DATA[index].tagBox.prop("muted", false)
2388
+ }
2275
2389
  }
2276
2390
  });
2277
2391
 
2278
2392
  //发送音频事件
2279
2393
  videoFlagObj.find("button[name='sendAudio']").click(function(){
2280
2394
  let index = Number($(this).parent().parent().attr("index"));
2395
+ // 优先当前窗口参数设置的业务类型 其次配置的默认业务类型 最后默认调度业务
2396
+ let businessType = me.VIDEO_DATA[index].opts.businessType == undefined ? me._opts.defaultBusinessType : me.VIDEO_DATA[index].opts.businessType;
2281
2397
 
2282
2398
  if (!me.VIDEO_DATA[index].playing) {
2283
2399
  promptAlarm('请选择播放的视频源!');
2284
2400
  return;
2285
2401
  }
2286
-
2402
+ if (businessType == 0) {
2403
+ // 主线业务
2287
2404
  if ($(this).attr('class') == 'send-audio-btn') {
2288
2405
  me.VIDEO_DATA[index].operateAudio("unsend_audio")
2289
2406
  $(this).attr('class', 'unsend-audio-btn');
@@ -2293,23 +2410,53 @@
2293
2410
  $(this).attr('class', 'send-audio-btn');
2294
2411
  me.VIDEO_DATA[index].stream.getAudioTracks()[0].enabled = true;
2295
2412
  }
2413
+ } else if (businessType == 1) {
2414
+ // 勤指业务
2415
+ if ($(this).attr('class') == 'send-audio-btn') {
2416
+ $(this).attr('class', 'unsend-audio-btn');
2417
+ //关闭点对点对讲
2418
+ me.VIDEO_DATA[index].ptopPoc("close_ptop_poc", window.pocNo);
2419
+ } else {
2420
+ $(this).attr('class', 'send-audio-btn');
2421
+ //发起点对点对讲
2422
+ me.VIDEO_DATA[index].ptopPoc("open_ptop_poc", window.pocNo);
2423
+ }
2424
+ }
2425
+ //jquery方式阻止默认事件 & 冒泡事件
2426
+ return false;
2296
2427
  });
2297
2428
 
2298
2429
  //关闭视频事件
2299
2430
  videoFlagObj.find("button[name='closeVideo']").click(function(){
2300
2431
  let index = Number($(this).parent().parent().attr("index"));
2301
2432
  me.close(index);
2433
+ // //jquery方式阻止默认事件 & 冒泡事件
2434
+ // return false;
2435
+ });
2436
+ },
2437
+ /**
2438
+ * 初始化事件监听
2439
+ */
2440
+ _initEventListen: function () {
2441
+ let _self = this;
2442
+ // 打开视频 {index, video, id, opts} index(视频窗口编号,从0开始) video(视频设备id,即devId) id(标识,空的话使用设备id) opts(其他参数)
2443
+ _self.addListener('openVideo', function (e) {
2444
+ _self.play(e.index, e.video, e.id, e.opts);
2445
+ })
2446
+
2447
+ // janus通知后台已关闭视频
2448
+ _self.addListener('notifyCloseVideo', function (e) {
2449
+ _self._notifyWaitingVideo(e.index);
2302
2450
  });
2303
2451
  },
2304
-
2305
2452
  /**
2306
2453
  * 双击某个视频全屏
2307
2454
  */
2308
2455
  _dbClickFullScreen: function() {
2309
2456
  let me = this;
2310
- $('[video-flag="'+me._opts.windowsBeginIndex+'"]').find('.video-box').on("dblclick",function(){
2311
- me._fullScreenEvent(this);
2312
- });
2457
+ $(me.selector + ' .video-main').find('.video-box').on("dblclick",function(){
2458
+ me._fullScreenEvent(this);
2459
+ });
2313
2460
  },
2314
2461
 
2315
2462
  /**
@@ -2342,10 +2489,17 @@
2342
2489
  _showVideoInfo: function() {
2343
2490
  let me = this;
2344
2491
  function clock(){
2492
+ if(!me.VIDEO_DATA || !me.VIDEO_DATA.length) return;
2345
2493
  for (let i = 0; i < me.VIDEO_DATA.length; i++) {
2346
2494
  if (me.VIDEO_DATA[i].playing) {
2347
2495
  let number = Number(i) + Number(1);
2348
- let videoObj = document.getElementById('video-' + number);
2496
+ //获取视频video标签
2497
+ let $videoList = $(me.selector + " .video-main #video-" + number);
2498
+ if(!$videoList.length) {
2499
+ console.error("can not find dom by id [video-" + number + "]");
2500
+ continue ;
2501
+ }
2502
+ let videoObj = $videoList[0];
2349
2503
 
2350
2504
  if (!videoObj) continue;
2351
2505
 
@@ -2360,6 +2514,7 @@
2360
2514
 
2361
2515
  let config = me.VIDEO_DATA[i].sipcall.webrtcStuff;
2362
2516
  me._setPacketsLostRate(i, config, me);
2517
+ me._setFrameDecoded(i, config, me);
2363
2518
  let resolution = width + "×" + height;
2364
2519
  switch(height + '') {
2365
2520
  case '1080':
@@ -2378,11 +2533,24 @@
2378
2533
  break;
2379
2534
  }
2380
2535
 
2381
- let videoInfoObj = document.getElementById('info-' + number);
2536
+ //获取文案显示dom元素
2537
+ let $videoInfoList = $(me.selector + " .video-main #info-" + number);
2538
+ if(!$videoInfoList.length) {
2539
+ console.error("can not find dom by id [info-" + number + "]");
2540
+ continue ;
2541
+ }
2542
+ let videoInfoObj = $videoInfoList[0];
2382
2543
  let videoName = me.VIDEO_DATA[i].opts && me.VIDEO_DATA[i].opts.name ?
2383
2544
  me.VIDEO_DATA[i].opts.name : me.VIDEO_DATA[i].video;
2384
2545
  videoInfoObj.innerHTML = videoName + '&nbsp;&nbsp;' + resolution +
2385
2546
  '<br>丢包率:' + me.VIDEO_DATA[i].packetsLostRate + '&nbsp;&nbsp;' + bitrate.replace("kbits/sec", "kbps");
2547
+ //根据视频框大小自动计算 显示文案的文字大小
2548
+ let fontHeightSize = $(me.selector + " .video-main #video-" + number).height() / 15;
2549
+ let fontWidthSize = $(me.selector + " .video-main #video-" + number).width() / 18;
2550
+ //长和宽 除以 15, 取小的值做文字大小样式
2551
+ let fontSize = fontHeightSize < fontWidthSize? fontHeightSize:fontWidthSize;
2552
+ fontSize = (!fontSize || fontSize > 20)? 20 : fontSize;
2553
+ $("#info-" + number).css("font-size", fontSize+"px");
2386
2554
  }
2387
2555
  }
2388
2556
  }
@@ -2438,23 +2606,163 @@
2438
2606
  '<br>' + bitrate + '&nbsp;&nbsp;Lost:' + res.packetsLost;*/
2439
2607
  }
2440
2608
  }
2441
-
2442
2609
  });
2443
- });
2444
- }
2445
- },
2610
+ });
2611
+ }
2612
+ },
2613
+
2614
+ /**
2615
+ * 设置当前网络信号提示
2616
+ * @param index 当前打开视频的索引
2617
+ * @param config
2618
+ * @param me
2619
+ * @private
2620
+ */
2621
+ _setFrameDecoded: function(index, config, me) {
2622
+ if (config.pc !== null && typeof config.pc !== 'undefined' && config.pc.getStats) {
2623
+ config.pc.getStats().then(function (stats) {
2624
+ stats.forEach(function (res) {
2625
+ if (res) {
2626
+ let inStats = false;
2627
+ // Check if these are statistics on incoming media
2628
+ if ((res.mediaType === 'video' || res.id.toLowerCase().indexOf('video') > -1) &&
2629
+ res.type === 'inbound-rtp' && res.id.indexOf('rtcp') < 0) {
2630
+ // New stats
2631
+ inStats = true;
2632
+ } else if (res.type === 'ssrc' && res.bytesReceived &&
2633
+ (res.googCodecName === 'VP8' || res.googCodecName === '')) {
2634
+ // Older Chromer versions
2635
+ inStats = true;
2636
+ }
2637
+ // Parse stats now
2638
+ if (inStats) {
2639
+ if (res.hasOwnProperty('framesDecoded')) {
2640
+ if (res.framesDecoded <= 1) return;
2641
+ if (typeof me.VIDEO_DATA[index].framesDecodedCount === 'undefined') {
2642
+ me.VIDEO_DATA[index].framesDecodedCount = 0;
2643
+ }
2644
+ if (typeof me.VIDEO_DATA[index].framesDecodedLast === 'undefined') {
2645
+ me.VIDEO_DATA[index].framesDecodedLast = res.framesDecoded;
2646
+ }
2647
+ if (res.framesDecoded > me.VIDEO_DATA[index].framesDecodedLast) {
2648
+ if (typeof me.VIDEO_DATA[index].tipDom !== 'undefined' && me.VIDEO_DATA[index].tipDom.style.display === 'block') {
2649
+ me.VIDEO_DATA[index].tipDom.style.display = 'none';
2650
+ }
2651
+ }
2652
+ me.VIDEO_DATA[index].framesDecodedCount++;
2653
+ // 定时检测
2654
+ if (me.VIDEO_DATA[index].framesDecodedCount === me.configOpt) {
2655
+ if (res.framesDecoded - me.VIDEO_DATA[index].framesDecodedLast === 0) { // 卡顿
2656
+ if (typeof me.VIDEO_DATA[index].tipDom === 'undefined') {
2657
+ var numIndex = index + 1;
2658
+ me.VIDEO_DATA[index].tipDom = document.getElementById('frame-decoded-' + numIndex);
2659
+ }
2660
+ me.VIDEO_DATA[index].tipDom.style.display = 'block';
2661
+ }
2662
+ me.VIDEO_DATA[index].framesDecodedCount = 0;
2663
+ me.VIDEO_DATA[index].framesDecodedLast = res.framesDecoded;
2664
+ } else {
2665
+ me.VIDEO_DATA[index].framesDecodedLast = res.framesDecoded;
2666
+ }
2667
+ }
2668
+ }
2669
+ }
2670
+
2671
+ });
2672
+ });
2673
+ }
2674
+ },
2675
+
2676
+
2677
+ /**
2678
+ * 设备可用性检查(扬声器、麦克风、分辨率、浏览器类型)
2679
+ * 1. 未检测(status == undefined)询问进入检测界面
2680
+ * 2. 检测完成按相应结果给予相应提示
2681
+ * 3. 拒绝检测按所有检测通过处理
2682
+ * 4. 程序自行检测,并将是否加载声卡结果放入window对象
2683
+ * @private
2684
+ */
2685
+ _checkDevices: function() {
2686
+ let me = this;
2687
+ let tipCountKey = "DEVICES_CHECK_TIP_COUNT";
2688
+ let statusKey = "DEVICES_CHECK_STATUS";
2689
+ let checkCompleted = "completed";
2690
+ let checkRejected = "rejected";
2691
+ let microResultKey = "MICRO_RESULT";
2692
+ let speakerResultKey = "SPEAKER_RESULT";
2693
+ let screenResultKey = "SCREEN_RESULT";
2694
+ let resultPass = "pass";
2695
+ let resultNotPass = "not pass";
2696
+
2697
+ let tipCount = sessionStorage.getItem(tipCountKey);
2698
+ let status = localStorage.getItem(statusKey);
2699
+ if ((tipCount == undefined || tipCount == "0") && status == undefined) {
2700
+ sessionStorage.setItem(tipCountKey, "1");
2701
+ //弹窗讯问是否进入检测界面
2702
+ if (confirm("您还没有检测硬件设备,是否先进行检测?")) {
2703
+ window.open("/scooper-video/new/checkDevices");
2704
+ } else {
2705
+ localStorage.setItem(statusKey, checkRejected);
2706
+ }
2707
+ return;
2708
+ }
2709
+
2710
+ if (status == checkCompleted) {
2711
+ let microResult = (localStorage.getItem(microResultKey) == undefined) ? resultPass : localStorage.getItem(microResultKey);
2712
+ let speakerResult = (localStorage.getItem(speakerResultKey) == undefined) ? resultPass : localStorage.getItem(speakerResultKey);
2713
+ let screenResult = (localStorage.getItem(screenResultKey) == undefined) ? resultPass : localStorage.getItem(screenResultKey);
2714
+
2715
+ let msg = "";
2716
+ if(speakerResult == resultNotPass){
2717
+ msg += "检测到扬声器异常,可能影响系统某些功能的使用!";
2718
+ console.error(msg);
2719
+ }
2720
+ if (microResult == resultNotPass) {
2721
+ msg += "检测到麦克风异常,可能影响系统某些功能的使用!";
2722
+ console.error(msg);
2723
+ }
2724
+ if (screenResult === resultNotPass) {
2725
+ msg += "您的屏幕分辨率过低,可能导致页面布局混乱!";
2726
+ //提示消息
2727
+ promptAlarm(msg);
2728
+ }
2729
+ let userAgent = navigator.userAgent;
2730
+ if (userAgent.toLowerCase().indexOf("chrome") < 0 && userAgent.toLowerCase().indexOf("firefox") < 0 && userAgent.toLowerCase().indexOf("edge") < 0) {
2731
+ msg += "当前浏览器下部分功能可能存在兼容问题,建议使用谷歌浏览器!";
2732
+ promptAlarm(msg);
2733
+ }
2734
+
2735
+ if (msg != "") {
2736
+ //提示并派发消息
2737
+ // promptAlarm(msg);
2738
+ //防止外部未监听消息就派发事件
2739
+ setTimeout(function () {
2740
+ me.videoListener.dispatch('msginfo', {'msg' : msg});
2741
+ }, 3000);
2742
+ }
2743
+ }
2744
+
2745
+ },
2746
+
2446
2747
 
2447
2748
  /**
2448
2749
  * 视频界面的初始化,在传过来的dom中创建界面
2449
2750
  */
2450
- _initVideoView: function($dom) {
2751
+ _initVideoView: function($dom, infoPosition) {
2451
2752
  let me = this;
2452
- let objClass = (me._opts.windowsNum == 1 ? 'video-main-full mode-' : 'video-main mode-') + me._opts.windows;
2753
+ let position;
2754
+ switch (infoPosition) {
2755
+ case 1: position = "info-bottom"; break;
2756
+ case 2: position = "info-top"; break;
2757
+ default : position = "info-bottom";
2758
+ }
2759
+ let objClass = (me._opts.windowsNum == 1 ? 'video-main video-main-full mode-' : 'video-main mode-') + me._opts.windows;
2453
2760
  let videoHtml = '<ul class="' + objClass +'" id="video-main-web-rtc" video-flag="'+me._opts.windowsBeginIndex+'">';
2454
2761
  let index = me._opts.windowsBeginIndex + 1;
2455
2762
  for (let i = index; i < index + me._opts.windowsNum; i++) {
2456
- videoHtml += '<li class="screen-' + i +'" index="' + (i - 1) +'" draggable="true"><video class="video-box" id="video-' + i +'" autoplay ></video>' +
2457
- '<div class="info hide" id="info-' + i +'"></div>' +
2763
+ videoHtml += '<li class="screen screen-' + i +'" index="' + (i - 1) +'" draggable="true"><video muted class="video-box" id="video-' + i +'" autoplay ></video>' +
2764
+ '<div class="hide info ' + position + '" id="info-' + i +'"></div>' +
2765
+ '<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>' +
2458
2766
  '<div class="operate-btn">';
2459
2767
  //videoHtml +='<button type="button" class="unlock-video-btn hide" name="lockVideo"></button>';
2460
2768
  checkUserMediaAvailable() && (videoHtml += '<button type="button" class="rotate-btn hide" name="rotateVideo" rotate-index="0" title="视频旋转"></button><button type="button" class="unsend-audio-btn hide" name="sendAudio"></button>');
@@ -2474,7 +2782,7 @@
2474
2782
  */
2475
2783
  _initAudioView: function($dom) {
2476
2784
  let me = this;
2477
- let objClass = (me._opts.windowsNum == 1 ? 'video-main-full mode-' : 'video-main mode-') + me._opts.windows;
2785
+ let objClass = (me._opts.windowsNum == 1 ? 'video-main video-main-full mode-' : 'video-main mode-') + me._opts.windows;
2478
2786
  let videoHtml = '<ul class="' + objClass +'" id="video-main-web-rtc" video-flag="'+me._opts.windowsBeginIndex+'">';
2479
2787
  let index = me._opts.windowsBeginIndex + 1;
2480
2788
  for (let i = index; i < index + me._opts.windowsNum; i++) {
@@ -2523,6 +2831,7 @@
2523
2831
 
2524
2832
  console.error('Janus服务连接失败:'+ error)
2525
2833
  me.closeAll();
2834
+ me._removeAllWaitingVideo();
2526
2835
  me._initJanus();
2527
2836
  },
2528
2837
  destroyed: function() {
@@ -2533,6 +2842,19 @@
2533
2842
  }
2534
2843
  });
2535
2844
  },
2845
+ /**
2846
+ * 销毁所有
2847
+ */
2848
+ destory: function() {
2849
+ var me = this;
2850
+ me.destoryJanus();
2851
+ $(me.selector).empty();
2852
+ me.videoListener = null;
2853
+ me.VIDEO_DATA = null;
2854
+ me.selector = null;
2855
+ //destoryJanus会触发回调,需要使用到opts
2856
+ // me._opts = null;
2857
+ },
2536
2858
 
2537
2859
  /**
2538
2860
  * 销毁:Janus销毁、资源释放
@@ -2541,7 +2863,7 @@
2541
2863
  let me = this;
2542
2864
  me._opts.janus.destroy({
2543
2865
  success: function() {
2544
- window.windowsSum = 0;
2866
+ // window.windowsSum = 0;
2545
2867
  //userToken = null;
2546
2868
  registered = false;
2547
2869
  },
@@ -2549,7 +2871,10 @@
2549
2871
  notifyDestroyed: true,
2550
2872
 
2551
2873
  });
2874
+ me.removeAllListeners();
2552
2875
  },
2876
+
2877
+ reLoginJanusItvIndex : -1,
2553
2878
 
2554
2879
  /**
2555
2880
  * 初始化插件、登陆,初始化窗口
@@ -2607,59 +2932,271 @@
2607
2932
  console.log("result event:" + event);
2608
2933
  if(event === 'registration_failed') {
2609
2934
  promptFailed("janus登陆失败: " + result["code"] + " " + result["reason"]);
2935
+ if(me.reLoginJanusItvIndex == -1) {
2936
+ me.reLoginJanusItvIndex = setInterval(function () {
2937
+ console.log("尝试重新登陆janus!");
2938
+ me._initJanus(janus);
2939
+ }, 5000);
2940
+ }
2941
+ return;
2942
+ }
2943
+ if (event === 'video_server_closed') {
2944
+ if(me.reLoginJanusItvIndex == -1) {
2945
+ me.reLoginJanusItvIndex = setInterval(function () {
2946
+ console.log("尝试重新登陆janus!");
2947
+ me._initJanus(janus);
2948
+ }, 5000);
2949
+ }
2610
2950
  return;
2611
2951
  }
2612
2952
  if(event === 'registered') {
2613
2953
  let userToken = result["userToken"];
2614
2954
  console.log('janus登陆成功')
2615
2955
  registered = true;
2956
+ if (me.reLoginJanusItvIndex != -1) {
2957
+ clearInterval(me.reLoginJanusItvIndex);
2958
+ me.reLoginJanusItvIndex = -1;
2959
+ }
2616
2960
 
2617
2961
  //生成主界面
2962
+ //相对序号,用于标识当前janus连接初始化的序号窗口
2963
+ let relativeIndex = 0;
2618
2964
  for(let i = me._opts.windowsBeginIndex; i < me._opts.windowsBeginIndex + me._opts.windowsNum; i++){
2619
2965
  me.VIDEO_DATA[i] = new SVideo({
2620
2966
  index: i,
2621
2967
  janus: janus,
2622
2968
  userToken: userToken,
2623
2969
  windowsNum: me._opts.windowsNum,
2970
+ relativeIndex: relativeIndex++,
2624
2971
  flag: me._opts.flag,
2625
2972
  isVideoTag: me._opts.isVideoTag,
2626
- janusPlugin: me._opts.conf.janusPlugin
2627
- });
2973
+ janusPlugin: me._opts.conf.janusPlugin,
2974
+ videoTipTimeOut: me._opts.videoTipTimeOut,
2975
+ parentSelector: me.selector
2976
+ }, me.videoListener);
2628
2977
  }
2629
2978
  }
2630
2979
  }
2631
2980
  }
2632
2981
  });
2633
2982
  },
2983
+ /* ----------------------------- 播放队列 --------------------------- */
2984
+
2985
+ // 记录等待中的视频
2986
+ WAITING_DATA: [],
2987
+
2988
+ // 播放队列开关 默认关闭
2989
+ waitPlayQueueSwitch: false,
2990
+
2991
+ /**
2992
+ * 添加等待视频数据
2993
+ * 同一位置再次打开,则覆盖上一次的
2994
+ * 参数:index(视频窗口编号,从0开始) video(视频设备id,即devId) id(标识,空的话使用设备id) opts(其他参数)
2995
+ */
2996
+ _addWaitingVideo: function (index, video, id, opts) {
2997
+ let _self = this;
2998
+ let isOverride = false;
2999
+ $.each(_self.WAITING_DATA, function (i, obj) {
3000
+ if (obj.index == index) {
3001
+ console.log("播放队列中 index = " + index + ", video = " + obj.video + " 替换为 video = " + video);
3002
+ _self.WAITING_DATA[i] = {
3003
+ index: index,
3004
+ video: video,
3005
+ id: id,
3006
+ opts: opts
3007
+ }
3008
+ isOverride = true;
3009
+ return false;
3010
+ }
3011
+ });
3012
+ if (!isOverride) {
3013
+ _self.WAITING_DATA.push({
3014
+ index: index,
3015
+ video: video,
3016
+ id: id,
3017
+ opts: opts
3018
+ });
3019
+ console.log("index = " + index + ", video = " + video + " 加入播放队列");
3020
+ }
3021
+ _self.VIDEO_DATA[index].isWaiting = true;
3022
+ },
3023
+
3024
+ /**
3025
+ * 删除等待视频数据
3026
+ */
3027
+ _removeWaitingVideo: function (index, video) {
3028
+ let _self = this;
3029
+ $.each(_self.WAITING_DATA, function (i, obj) {
3030
+ if (obj.index == index && obj.video == video) {
3031
+ _self.WAITING_DATA.splice(i, 1);
3032
+ _self.VIDEO_DATA[index].isWaiting = false;
3033
+ console.log("index = " + index + ", video = " + video + " 从播放队列移除");
3034
+ return false;
3035
+ }
3036
+ });
3037
+ },
3038
+
3039
+ /**
3040
+ * 删除所有等待播放视频的数据
3041
+ */
3042
+ _removeAllWaitingVideo: function () {
3043
+ let _self = this;
3044
+ _self.WAITING_DATA = [];
3045
+ let index = _self._opts.windowsBeginIndex;
3046
+ for (; index < _self._opts.windowsBeginIndex + _self._opts.windows ; index++) {
3047
+ _self.VIDEO_DATA[index].isWaiting = false;
3048
+ }
3049
+ },
3050
+
3051
+ /**
3052
+ * 上一个视频关闭后,如果该位置由等待视频,通知打开新视频
3053
+ * @param index
3054
+ */
3055
+ _notifyWaitingVideo: function (index) {
3056
+ let _self = this;
3057
+ $.each(_self.WAITING_DATA, function (i, obj) {
3058
+ if (obj.index == index) {
3059
+ _self.play(obj.index, obj.video, obj.id, obj.opts);
3060
+ _self._removeWaitingVideo(obj.index, obj.video);
3061
+ return false;
3062
+ }
3063
+ });
3064
+ }
2634
3065
 
2635
3066
  }
2636
3067
 
2637
- let FAILED_CODE = {
2638
- 1001 : "账号或密码错误",
2639
- 1002 : "该帐号已连接",
2640
- 1004 : "没有鉴权",
2641
- 2001 : "未携带token或token错误",
2642
- 2002 : "视频源id不存在",
2643
- 2003 : "操作指令非法(该账号不允许执行这个指令,或者不支持该指令)",
2644
- 3001 : "nat通道未建立",
2645
- 3002 : "该视频流已在传输",
2646
- 3003 : "无法获取远端视频流",
2647
- 4001 : "视频流断开连接",
2648
- 4002 : "获取视频失败",
2649
- 5000 : "内部错误",
2650
- 8001 : "设备不支持该指令",
2651
- 453 : "videoServer连接失败",
2652
- 454 : "录像回放窗口已占用,请先停止播放",
2653
- 455 : "无视频录像,操作失败",
2654
- 5001 : "呼叫异常断开",
2655
- 5002 : "禁止修改分辨率",
2656
- 4003 : "音频被占用",
2657
- 4004 : "音频被占用",
2658
- 4005 : "客户端已打开对讲",
2659
- 4006 : "终端离开云眼音频"
2660
- }
3068
+ let CONST_CODE = {
3069
+ //打开失败错误码,面板显示,不做浮窗提示框显示
3070
+ VIDEO_CODE: {
3071
+ 2002 : "打开失败,未找到该ID的视频源",
3072
+ 2003 : "打开失败,请确认视频服务版本",
3073
+ 3001 : "打开失败,未接收到引流包,请检查端口映射",
3074
+ 3002 : "",
3075
+ 3003 : "打开失败,对方拒绝视频请求",
3076
+ 4001 : "打开失败,视频流中断",
3077
+ 4002 : "打开失败,终端挂机或超时未接听",
3078
+ 7000 : "打开失败,无法连接视频设备",
3079
+ 7001 : "打开失败,无法连接视频设备",
3080
+ 7002 : "打开失败,无法连接视频设备"
3081
+ },
3082
+
3083
+ OTHER_CODE: {
3084
+ 453 : "videoServer连接失败,错误码453",
3085
+ 454 : "视频窗口已被占用,请选择其它窗口打开或停止播放",
3086
+ 455 : "操作失败,该段时间无视频录像",
3087
+ 499 : "操作异常,错误码499",
3088
+ 440 : "操作异常,错误码440",
3089
+ 441 : "操作异常,错误码441",
3090
+ 442 : "操作异常,错误码442",
3091
+ 443 : "操作异常,错误码443",
3092
+ 444 : "操作异常,错误码444",
3093
+ 445 : "操作异常,错误码445",
3094
+ 446 : "操作异常,错误码446",
3095
+ 447 : "操作异常,错误码447",
3096
+ 448 : "操作异常,错误码448",
3097
+ 449 : "操作异常,错误码449",
3098
+ 450 : "操作异常,错误码450",
3099
+ 451 : "操作异常,错误码451",
3100
+ 452 : "操作异常,错误码452",
3101
+ 456 : "设备已处于对讲状态或不支持对讲",
3102
+ 6001 : "录像失败"
3103
+ },
3104
+ FAILED_CODE: {
3105
+ 1001 : "账号或密码错误",
3106
+ 1002 : "该帐号已连接",
3107
+ 1004 : "没有鉴权",
3108
+ 2001 : "未携带token或token错误",
3109
+ 2002 : "视频源id不存在",
3110
+ 2003 : "操作指令非法(该账号不允许执行这个指令,或者不支持该指令)",
3111
+ 3001 : "nat通道未建立",
3112
+ 3002 : "该视频流已在传输",
3113
+ 3003 : "无法获取远端视频流",
3114
+ 4001 : "视频流异常断开连接",
3115
+ 4002 : "获取视频失败",
3116
+ 5000 : "内部错误",
3117
+ 8001 : "该设备不支持云台操作",
3118
+ 453 : "videoServer连接失败",
3119
+ 454 : "录像回放窗口已占用,请先停止播放",
3120
+ 455 : "无视频录像,操作失败",
3121
+ 5001 : "呼叫异常断开",
3122
+ 5002 : "禁止修改分辨率",
3123
+ 401 : "禁止修改分辨率",
3124
+ 4003 : "音频重置",
3125
+ 4004 : "音频被占用",
3126
+ 4005 : "客户端已打开对讲",
3127
+ 4006 : "终端离开云眼音频",
3128
+ 4008 : "终端拒绝打开视频",
3129
+ 6001 : "录像失败",
3130
+ 499 : "内部创建失败",
3131
+ 440 : "请求消息内容为空",
3132
+ 441 : "json格式错误",
3133
+ 442 : "无效的请求",
3134
+ 443 : "消息内容缺失",
3135
+ 444 : "消息缺少参数",
3136
+ 445 : "账户已登陆",
3137
+ 446 : "收到的videoserver消息有误",
3138
+ 447 : "消息参数错误",
3139
+ 448 : "SDP创建失败",
3140
+ 449 : "未使用",
3141
+ 450 : "创建端口失败",
3142
+ 451 : "SDP创建失败",
3143
+ 452 : "未使用加密的RTP",
3144
+ 456 : "对讲未打开",
3145
+ 7000 : "URL账号密码错误(RTSP)",
3146
+ 7001 : "URL地址不通(RTSP)",
3147
+ 7002 : "URL格式错误(RTSP)"
3148
+ },
2661
3149
 
2662
- let STATUS_CODE_ARR = ['5002', '4003', '4004', '4005', '4006'];
3150
+ STATUS_CODE_ARR: ['5002', '4003', '4004', '4005', '4006']
3151
+ }
3152
+ /**
3153
+ * 显示播放错误内容, 4002特殊处理
3154
+ * @param videoObj 视频对象
3155
+ * @param code 状态码(包含错误码)
3156
+ * @param isShowReplayBtn 是否显示重新播放按钮
3157
+ * @param video 打开错误的视频Id
3158
+ */
3159
+ function showResult(videoObj, code, isShowReplayBtn, video) {
3160
+ let videoDom = videoObj.tagBox.parent();
3161
+
3162
+ videoDom.addClass("result");
3163
+ videoDom.find('.operate-btn .close-btn').show();
3164
+
3165
+ if (CONST_CODE.FAILED_CODE[code] && code != "4002") {
3166
+ let resultHtml = "<div class='real-result'>错误码" + code + ": " + CONST_CODE.FAILED_CODE[code] + "</div>"
3167
+ videoDom.append(resultHtml);
3168
+ }
3169
+
3170
+ let resultHtml = "<div class='result'><div class='result-tip'>" + CONST_CODE.VIDEO_CODE[code] + "</div>";
3171
+ if(isShowReplayBtn && code != "4002") {
3172
+ resultHtml += "<div class='result-replay'><span id='replay-" + videoObj.index + "' class='replay'>点击重试</span></div>"
3173
+ }
3174
+ resultHtml += "</div>";
3175
+ videoDom.append(resultHtml);
3176
+ if(isShowReplayBtn && code != "4002") {
3177
+ $("#replay-" + videoObj.index).unbind("click").click(function () {
3178
+ videoObj.videoListener.dispatch("openVideo", {index: videoObj.index, video: video, id: videoObj.id, opts: videoObj.opts});
3179
+ });
3180
+ }
3181
+ if (code == "4002") {
3182
+ setTimeout(function () {
3183
+ clearResult(videoDom);
3184
+ }, 5000);
3185
+ }
3186
+ }
3187
+
3188
+ /**
3189
+ * 清除显示内容 videoDom: 视频Dom对象
3190
+ */
3191
+ function clearResult(videoDom, videoObj) {
3192
+ videoDom.removeClass("result");
3193
+ videoDom.find(".real-result").remove();
3194
+ videoDom.find(".result").remove();
3195
+ if (!videoObj || !videoObj.playing) {
3196
+ // bug id 18654: 增加是否正在播放判断
3197
+ videoDom.find('.operate-btn .close-btn').hide();
3198
+ }
3199
+ }
2663
3200
 
2664
3201
  //window.VIDEO_DATA = [];//记录视频各分屏的状态
2665
3202
  window.windowsSum = 0; //当前页面的视频总数,可能有多个VideoWebRtc对象
@@ -2667,16 +3204,23 @@
2667
3204
  let registered = false;
2668
3205
  let recordAvBusinessId = null;
2669
3206
 
2670
- function SVideo (opts) {
3207
+ function SVideo (opts, videoListener) {
2671
3208
  this.janus = opts.janus;
2672
3209
  this.userToken = opts.userToken;
2673
3210
  this.sipcall = null;
2674
3211
  this.index = opts.index;
2675
- this.tagBox = opts.isVideoTag ? $('#video-' + (this.index + 1)) : $('#audio-' + (this.index + 1));
3212
+ this.relativeIndex = opts.relativeIndex;
3213
+ // this.tagBox = opts.isVideoTag ? $('#video-' + (this.index + 1)) : $('#audio-' + (this.index + 1));
3214
+ this.tagBox = opts.isVideoTag ? $(opts.parentSelector + ' #video-' + (this.index + 1)) : $('#audio-' + (this.index + 1));
2676
3215
  this.windowsNum = opts.windowsNum;
2677
3216
  this.flag = opts.flag;
2678
3217
  this.isVideoTag = opts.isVideoTag;
2679
3218
  this.janusPlugin = opts.janusPlugin;
3219
+ this.isClosing = false; // 当前分屏是否正在关闭视频
3220
+ this.isWaiting = false; // 当前分屏是否有视频在等待播放
3221
+ this.playSucTimeOutIndex = -1; // 超时提示定时器index
3222
+ this.videoTipTimeOut = opts.videoTipTimeOut; // 超时无首屏时间
3223
+ this.videoListener = videoListener;
2680
3224
  this.init();
2681
3225
  }
2682
3226
 
@@ -2699,8 +3243,8 @@
2699
3243
  console.log("视频插件初始化成功:" + self.index);
2700
3244
  self.sipcall = pluginHandle;
2701
3245
 
2702
- if (self.index + 1 >= self.windowsNum) {
2703
- videoListener.dispatch('initsucc', self);
3246
+ if (self.relativeIndex + 1 >= self.windowsNum) {
3247
+ self.videoListener.dispatch('initsucc', self);
2704
3248
  }
2705
3249
  },
2706
3250
 
@@ -2717,10 +3261,15 @@
2717
3261
  promptFailed("请先登陆");
2718
3262
  }
2719
3263
 
2720
- if (msg.error_code) {
2721
- console.error(msg.error_code + ' ' + msg.error);
2722
- promptFailed(FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code);
2723
- videoListener.dispatch('msginfo', {'msg' : FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code});
3264
+ let video = self.video;
3265
+ if (msg.error_code) {
3266
+ console.error("错误码:" + msg.error_code + " " + CONST_CODE.FAILED_CODE[msg.error_code]);
3267
+ if (CONST_CODE.VIDEO_CODE[msg.error_code]) {
3268
+ showResult(self, msg.error_code, true, video);
3269
+ } else {
3270
+ promptFailed(CONST_CODE.OTHER_CODE[msg.error_code] || CONST_CODE.FAILED_CODE[msg.error_code] || '错误码:' + msg.error_code);
3271
+ }
3272
+ 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});
2724
3273
  return false;
2725
3274
  }
2726
3275
 
@@ -2729,21 +3278,28 @@
2729
3278
  if (result.error_code && result.error_code != 0) {
2730
3279
  //videoListener.dispatch('afterclose', self);
2731
3280
 
2732
- if (!STATUS_CODE_ARR.includes(result.error_code + '')) {
3281
+ if (!CONST_CODE.STATUS_CODE_ARR.includes(result.error_code + '')) {
2733
3282
  //videoListener.dispatch('afterclose', self);
2734
3283
  //播放失败 关闭视频
2735
- let video = self.video;
3284
+
2736
3285
  self.close('err');
2737
3286
 
2738
3287
  if (self.isLockVideo) {
2739
- self.play(video);
3288
+ setTimeout(function () {
3289
+ self.play(video);
3290
+ }, 1500);
2740
3291
  } else {
2741
- videoListener.dispatch('afterclose', self);
3292
+ self.closeType = 'error';
3293
+ self.videoListener.dispatch('afterclose', self);
2742
3294
  }
2743
3295
  }
2744
3296
 
2745
- videoListener.dispatch('msginfo', {'msg' : FAILED_CODE[result.error_code] || '错误码:' + result.error_code});
2746
- promptFailed(FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
3297
+ 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});
3298
+ if (CONST_CODE.VIDEO_CODE[result.error_code]) {
3299
+ showResult(self, result.error_code, true, video);
3300
+ } else {
3301
+ promptFailed(CONST_CODE.OTHER_CODE[result.error_code] || CONST_CODE.FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
3302
+ }
2747
3303
 
2748
3304
  self.tagBox.parent().find('.recv-audio-btn').attr("class", "unrecv-audio-btn");
2749
3305
  self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
@@ -2769,11 +3325,17 @@
2769
3325
  },
2770
3326
  error: function(error) {
2771
3327
  console.error(error);
2772
- let body = { "request": "decline", "code": 480 };
2773
- self.sipcall.send({"message": body});
3328
+ // let body = { "request": "decline", "code": 480 };
3329
+ // self.sipcall.send({"message": body});
2774
3330
  }
2775
3331
  });
2776
3332
  break;
3333
+ case 'accepted' :
3334
+ self.playSucTimeOutIndex = setTimeout(function () {
3335
+ let _li = self.tagBox.parent();
3336
+ _li.append('<div class="video-tip">网络环境较差,可能无法正常加载视频</div>');
3337
+ }, self.videoTipTimeOut * 1000);
3338
+ break;
2777
3339
  //呼叫失败
2778
3340
  case 'callfaild':
2779
3341
  //promptFailed(FAILED_CODE[result.error_code] || '错误码:' + result.error_code);
@@ -2788,19 +3350,31 @@
2788
3350
  case 'start_av_record':
2789
3351
  if (result && result.filename) {
2790
3352
  self.videoFileName = result.filename;
2791
- videoListener.dispatch('recordvideo', self);
3353
+ self.videoListener.dispatch('startRecordVideo', self);
2792
3354
  console.log('录像地址:' + result.filename);
2793
3355
  }
2794
3356
  break;
3357
+ case 'stop_av_record':
3358
+ if (result && result.filename) {
3359
+ self.videoFileName = result.filename;
3360
+ self.videoListener.dispatch('stopRecordVideo', self);
3361
+ console.log('录像地址:' + result.filename);
3362
+ }
3363
+ break;
2795
3364
  //修改分辨率
2796
3365
  case 'ser_notify_resolution':
2797
3366
  if (result && result.resolution) {
2798
3367
  self.resolution = result.resolution;
2799
- videoListener.dispatch('notifyresolution', self);
3368
+ self.videoListener.dispatch('notifyresolution', self);
2800
3369
  console.log('接收notifyresolution:' + result.resolution);
2801
3370
  //promptAlarm('当前分辨率:' + result.resolution);
2802
3371
  }
2803
3372
  break;
3373
+ case 'change_resolution':
3374
+ if(result) {
3375
+ self.videoListener.dispatch('notifyResolutionChange', self);
3376
+ }
3377
+ break;
2804
3378
  //建立预呼叫响应
2805
3379
  case 'open_poccall':
2806
3380
  console.log('建立预呼叫');
@@ -2826,8 +3400,32 @@
2826
3400
  console.log('预呼叫异常断开');
2827
3401
  break;
2828
3402
  case 'ser_stop_audio':
3403
+ self.tagBox.parent().find('.recv-audio-btn').attr("class", "unrecv-audio-btn");
2829
3404
  console.log('音频异常关闭!');
2830
3405
  break;
3406
+ case 'close_down_audio':
3407
+ self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
3408
+ promptSuccess("通话时间到");
3409
+ console.log('通话时间到!');
3410
+ break;
3411
+ case 'ser_notify_dispatch_close_ptop_poc':
3412
+ self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
3413
+ console.log('调度通知点对点对讲关闭!');
3414
+ break;
3415
+ case 'ser_close_ptop_poc':
3416
+ self.tagBox.parent().find('.send-audio-btn').attr("class", "unsend-audio-btn");
3417
+ console.log('点对点对讲关闭!');
3418
+ break;
3419
+ case 'ser_open_ptop_poc':
3420
+ self.tagBox.parent().find('.unsend-audio-btn').attr("class", "send-audio-btn");
3421
+ console.log('点对点对讲打开!');
3422
+ break;
3423
+ // 视频关闭通知
3424
+ case 'ser_close_video':
3425
+ console.log('视频框 ' + self.index + ' 视频已关闭');
3426
+ self.isClosing = false;
3427
+ self.videoListener.dispatch('notifyCloseVideo', self);
3428
+ break;
2831
3429
  default:
2832
3430
  console.log('event:' + event);
2833
3431
  break;
@@ -2883,7 +3481,9 @@
2883
3481
  self.tagBox.bind("canplay play playing", function () {
2884
3482
  if(self.video){
2885
3483
  if (self.tagBox.is(':visible')) return;
2886
-
3484
+ // 清除播放监测定时任务,清除内容
3485
+ self.playSucTimeOutIndex > 0 && clearTimeout(self.playSucTimeOutIndex);
3486
+ self.tagBox.parent().find(".video-tip").remove();
2887
3487
  console.log('分屏=' + (self.index + 1) + ', ' + self.video + ' 播放成功');
2888
3488
  promptSuccess('分屏' + (self.index + 1) + ' 播放成功');
2889
3489
  self.tagBox.show();
@@ -2930,13 +3530,20 @@
2930
3530
  };
2931
3531
  this.sipcall.send({"message": body });
2932
3532
  this.video = video;
3533
+ this.isClosing = false;
2933
3534
  this.playing = true;
2934
3535
  this.packetsLostRate = '0.00%';
2935
3536
  this.packetsLostSum = 0;
2936
3537
  this.packetsReceivedSum = 0;
3538
+ let numIndex = this.index + 1;
3539
+ let framesDecodedDom = document.getElementById("frame-decoded-" + numIndex);
3540
+ framesDecodedDom.style.display = 'none';
3541
+ this.framesDecodedLast = undefined;
3542
+ this.framesDecodedCount = 0;
2937
3543
 
2938
3544
  //loading
2939
3545
  let _li = this.tagBox.parent();
3546
+ clearResult(_li, this);
2940
3547
  if(!_li.hasClass("loading")){
2941
3548
  _li.addClass("loading").append('<div class="stream-loading">等待数据流传送...</div>');
2942
3549
  }
@@ -2950,6 +3557,8 @@
2950
3557
  this.tagBox.parent().find('.lock-video-btn').attr("class", "unlock-video-btn");
2951
3558
 
2952
3559
  }
3560
+ //清除结果提示内容
3561
+ clearResult(this.tagBox.parent(), this);
2953
3562
 
2954
3563
  //let reqType = type ? type : "hangup";
2955
3564
  if(!this.playing) return;
@@ -2962,6 +3571,7 @@
2962
3571
  this.sipcall.send({"message": _hangup});
2963
3572
  this.sipcall.hangup();
2964
3573
  this.tagBox.hide();
3574
+ this.isClosing = true;
2965
3575
  this.playing = false;
2966
3576
  this.video = null;
2967
3577
  this.packetsLostRate = '0.00%';
@@ -2977,6 +3587,15 @@
2977
3587
  this.tagBox.parent().removeClass("loading").find(".stream-loading").remove();
2978
3588
  //清除object-fit
2979
3589
  this.tagBox.css('object-fit', '');
3590
+
3591
+ // 清除内容提示
3592
+ this.playSucTimeOutIndex > 0 && clearTimeout(this.playSucTimeOutIndex);
3593
+ this.tagBox.parent().find(".video-tip").remove();
3594
+ var numIndex = Number(this.index) + 1;
3595
+ var framesDecodedDom = document.getElementById("frame-decoded-" + numIndex);
3596
+ framesDecodedDom.style.display = 'none';
3597
+ this.framesDecodedLast = undefined;
3598
+ this.framesDecodedCount = 0;
2980
3599
  },
2981
3600
 
2982
3601
  /**
@@ -3081,6 +3700,7 @@
3081
3700
 
3082
3701
  //loading
3083
3702
  let _li = this.tagBox.parent();
3703
+ clearResult(_li, this);
3084
3704
  if(!_li.hasClass("loading")){
3085
3705
  _li.addClass("loading").append('<div class="stream-loading">等待数据流传送...</div>');
3086
3706
  }
@@ -3222,26 +3842,28 @@
3222
3842
 
3223
3843
  self.sipcall.send({"message": body });
3224
3844
  console.log("预呼叫操作="+ requestType +", 对讲号码=" + pocNo + ",调度中心号码=" + centerTel);
3845
+ },
3846
+
3847
+ /**
3848
+ * 点对点对讲
3849
+ * requstType: open_ptop_poc(开启) close_poc_poc(关闭)
3850
+ * pocno
3851
+ */
3852
+ ptopPoc: function(requestType, pocNo) {
3853
+ let self = this;
3854
+
3855
+ let body = {
3856
+ request: requestType,
3857
+ pocno: pocNo,
3858
+ playseq: self.index,
3859
+ pocmember: self.video,
3860
+ userToken: self.userToken,
3861
+ };
3862
+
3863
+ self.sipcall.send({"message": body });
3864
+ console.log("点对点对讲操作="+ requestType +", 主叫号码=" + pocNo + ",被叫号码=" + self.video);
3225
3865
  }
3226
3866
  }
3227
3867
 
3228
3868
  return isIE() ? VideoOcx : VideoWebRtc;
3229
- }));
3230
-
3231
-
3232
-
3233
-
3234
-
3235
-
3236
-
3237
-
3238
-
3239
-
3240
-
3241
-
3242
-
3243
-
3244
-
3245
-
3246
-
3247
-
3869
+ }));