1
0

index.vue 3.3 KB

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