ventutil.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { render, h, nextTick } from 'vue';
  2. import LivePlayer from '@liveqing/liveplayer-v3';
  3. import { play } from '../views/vent/monitorManager/balancePressMonitor/balancePress.threejs';
  4. export function toEchartsData(list, option) {
  5. option.legend['data'] = [];
  6. option.yAxis.length = list.length;
  7. option.yAxis.series = list.length;
  8. list.forEach((item: any, index) => {
  9. option.legend['data'].push(`${item['legend']}(${item['unit']})`);
  10. const yAxiObj = {
  11. type: 'value',
  12. position: item['yaxispos'],
  13. axisLabel: { formatter: `{value} ${item['unit']}` },
  14. };
  15. const serieObj = {
  16. name: `${item['legend']}(${item['unit']})`,
  17. type: item['linetype'],
  18. yAxisIndex: item['sort'],
  19. };
  20. if (!option.yAxis[index]) {
  21. option.yAxis[index] = yAxiObj;
  22. } else {
  23. Object.assign(option.yAxis[index], yAxiObj);
  24. }
  25. if (!option.series[index]) {
  26. option.series[index] = serieObj;
  27. } else {
  28. Object.assign(option.series[index], serieObj);
  29. }
  30. });
  31. return option;
  32. }
  33. export function formatNum(data) {
  34. return new Intl.NumberFormat('ja-JP', {
  35. minimumFractionDigits: 2,
  36. maximumFractionDigits: 2,
  37. }).format(data);
  38. }
  39. export function cameraInit(dom, rtspUrl) {
  40. let webRtcServer = undefined;
  41. const ip = VUE_APP_URL.webRtcUrl;
  42. // const ip = '//192.168.183.216:8000';
  43. webRtcServer = new window['WebRtcStreamer'](dom, location.protocol + ip);
  44. if (webRtcServer) webRtcServer.connect(rtspUrl);
  45. return { webRtcServer };
  46. }
  47. export function deviceCameraInit(cameraAddrs, player: HTMLElement, webRtcServerList: any[] = []) {
  48. const webRtcServerLen = webRtcServerList.length;
  49. const playerDoms: HTMLElement[] = [];
  50. const cameraUrls: string[] = [];
  51. const webRtcServer: any[] = [];
  52. let livePlayerDiv: HTMLElement | null = document.getElementById('LivePlayerBox');
  53. if (livePlayerDiv) livePlayerDiv.remove();
  54. if (!livePlayerDiv) {
  55. const dom = document.createElement('div');
  56. dom.setAttribute('id', 'LivePlayerBox');
  57. livePlayerDiv = dom;
  58. player.appendChild(livePlayerDiv);
  59. }
  60. return new Promise((resolve) => {
  61. const playCamrea = () => {
  62. cameraAddrs.forEach((cameraUrl: string, index) => {
  63. if (cameraUrl.startsWith('rtsp://')) {
  64. const server = webRtcServerList.shift();
  65. if (server) {
  66. server.connect(cameraUrls[index]);
  67. webRtcServer.push(server);
  68. } else {
  69. const videoDom = document.createElement('video');
  70. videoDom.setAttribute('class', 'rtspVideo');
  71. videoDom.autoplay = true;
  72. player.appendChild(videoDom);
  73. playerDoms.push(videoDom);
  74. const server = new window['WebRtcStreamer'](videoDom, location.protocol + VUE_APP_URL.webRtcUrl);
  75. webRtcServer.push(server);
  76. if (server) server.connect(cameraUrl);
  77. }
  78. } else {
  79. render(h(LivePlayer, { class: 'player', muted: true, autoplay: true, live: true, videoUrl: cameraUrl }), livePlayerDiv);
  80. }
  81. });
  82. resolve(null);
  83. };
  84. playCamrea();
  85. }).then(() => {
  86. const players = livePlayerDiv?.getElementsByClassName('player');
  87. if (players && players.length) {
  88. for (let i = 0; i < players.length; i++) {
  89. debugger;
  90. const dom = players[i].getElementsByTagName('video')[0];
  91. if (dom) playerDoms.push(dom);
  92. }
  93. }
  94. debugger
  95. if (webRtcServerList.length > 0) {
  96. const rtspVideoList = player.getElementsByClassName('rtspVideo');
  97. for (let i = 0; i < webRtcServerList.length; i++) {
  98. webRtcServerList[i].disconnect();
  99. rtspVideoList[webRtcServerLen - webRtcServerList.length + i].remove()
  100. }
  101. }
  102. return { webRtcServer, playerDoms };
  103. });
  104. }