index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div class="vent-flex-row-wrap camera-box">
  3. <div v-for="(item, index) in addrList" :key="index" class="player-box">
  4. <div class="player-name">{{ item.name }}</div>
  5. <div>
  6. <template v-if="item.addr.startsWith('rtsp://')">
  7. <video :id="`video${index}`" muted autoplay></video>
  8. <div class="click-box" @dblclick="goFullScreen(`video${index}`)"></div>
  9. </template>
  10. <template v-else>
  11. <LivePlayer :videoUrl="item.addr" muted live loading/>
  12. </template>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script lang="ts" setup>
  18. import {onMounted, onUnmounted, ref } from 'vue';
  19. import { list } from './camera.api'
  20. import LivePlayer from '@liveqing/liveplayer-v3';
  21. import { Icon } from '/@/components/Icon';
  22. const webRtcServerList = <any[]>[]
  23. let addrList = ref<{ name: string, addr: string }[]>([])
  24. async function getVideoAddrs(){
  25. const result = await list({ pageSize: 10000 })
  26. if(result && result.records && result.records.length > 0){
  27. addrList.value = result.records.map(item => ({ addr: item['addr'], name: item['name'] }))
  28. }
  29. }
  30. function getVideo() {
  31. const ip = VUE_APP_URL.webRtcUrl;
  32. for(let i =0; i < addrList.value.length; i++){
  33. const item = addrList.value[i]
  34. if(item.addr.startsWith('rtsp://')){
  35. const dom = document.getElementById('video' + i) as HTMLVideoElement
  36. dom.muted = true;
  37. dom.volume = 0
  38. const webRtcServer = new window['WebRtcStreamer'](dom, location.protocol + ip)
  39. webRtcServerList.push(webRtcServer)
  40. webRtcServer.connect(item.addr)
  41. }
  42. }
  43. }
  44. function goFullScreen(domId) {
  45. const videoDom = document.getElementById(domId) as HTMLVideoElement
  46. if(videoDom.requestFullscreen){
  47. videoDom.requestFullscreen()
  48. videoDom.play()
  49. } else if(videoDom.mozRequestFullscreen){
  50. videoDom.mozRequestFullscreen()
  51. videoDom.play()
  52. } else if (videoDom.webkitRequestFullscreen) {
  53. videoDom.webkitRequestFullscreen()
  54. videoDom.play()
  55. } else if (videoDom.msRequestFullscreen) {
  56. videoDom.msRequestFullscreen()
  57. videoDom.play()
  58. }
  59. }
  60. onMounted(async() => {
  61. await getVideoAddrs()
  62. getVideo()
  63. })
  64. onUnmounted(() => {
  65. const num = webRtcServerList.length
  66. for (let i = 0; i < num; i++) {
  67. webRtcServerList[i].disconnect()
  68. webRtcServerList[i] = null
  69. }
  70. })
  71. </script>
  72. <style lang="less">
  73. .camera-box{
  74. overflow-y: auto;
  75. .player-box{
  76. width: 314px;
  77. height: 208px;
  78. padding: 10px;
  79. background: url('/@/assets/images/vent/camera_bg.png');
  80. background-size: cover;
  81. position: relative;
  82. margin: 10px;
  83. .player-name{
  84. font-size: 14px;
  85. position: absolute;
  86. top: 15px;
  87. right: 15px;
  88. color: #fff;
  89. background-color: hsla(0, 0%, 50%, .5);
  90. border-radius: 2px;
  91. padding: 1px 5px;
  92. max-width: 120px;
  93. overflow: hidden;
  94. white-space: nowrap;
  95. text-overflow: ellipsis;
  96. z-index: 999;
  97. }
  98. .click-box{
  99. position: absolute;
  100. width: 100%;
  101. height: 100%;
  102. top: 0;
  103. left: 0;
  104. }
  105. }
  106. }
  107. // :deep(video){
  108. // width: 100% !important;
  109. // height: 100% !important;
  110. // object-fit: cover !important;
  111. // }
  112. </style>