1
0

index.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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="true" autoplay></video>
  8. </template>
  9. <template v-else>
  10. <LivePlayer :videoUrl="item.addr" muted live loading/>
  11. </template>
  12. </div>
  13. </div>
  14. </div>
  15. </template>
  16. <script lang="ts" setup>
  17. import {onMounted, onUnmounted, ref } from 'vue';
  18. import { list } from './camera.api'
  19. import LivePlayer from '@liveqing/liveplayer-v3';
  20. const webRtcServerList = <any[]>[]
  21. let addrList = ref<{ name: string, addr: string }[]>([])
  22. async function getVideoAddrs(){
  23. const result = await list({ pageSize: 10000 })
  24. if(result && result.records && result.records.length > 0){
  25. addrList.value = result.records.map(item => ({ addr: item['addr'], name: item['name'] }))
  26. }
  27. }
  28. function getVideo() {
  29. const ip = VUE_APP_URL.webRtcUrl;
  30. for(let i =1; i<= addrList.value.length; i++){
  31. const item = addrList.value[i]
  32. if(item.addr.startsWith('rtsp://')){
  33. const webRtcServer = new window['WebRtcStreamer']('video' + i, location.protocol + ip)
  34. webRtcServerList.push(webRtcServer)
  35. // webRtcServer.connect('rtsp://admin:admin12345@192.168.183.64:554/Streaming/Channels/1')
  36. webRtcServer.connect(item.addr)
  37. }
  38. }
  39. }
  40. onMounted(async() => {
  41. await getVideoAddrs()
  42. getVideo()
  43. })
  44. onUnmounted(() => {
  45. const num = webRtcServerList.length
  46. for (let i = 0; i < num; i++) {
  47. webRtcServerList[i].disconnect()
  48. webRtcServerList[i] = null
  49. }
  50. })
  51. </script>
  52. <style lang="less">
  53. .camera-box{
  54. overflow-y: auto;
  55. .player-box{
  56. width: 314px;
  57. height: 208px;
  58. padding: 10px;
  59. background: url('/@/assets/images/vent/camera_bg.png');
  60. background-size: cover;
  61. position: relative;
  62. margin: 10px;
  63. .player-name{
  64. font-size: 14px;
  65. position: absolute;
  66. top: 15px;
  67. right: 15px;
  68. color: #fff;
  69. background-color: hsla(0, 0%, 50%, .5);
  70. border-radius: 2px;
  71. padding: 1px 5px;
  72. max-width: 120px;
  73. overflow: hidden;
  74. white-space: nowrap;
  75. text-overflow: ellipsis;
  76. z-index: 999;
  77. }
  78. }
  79. }
  80. </style>