| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <template>
- <div class="vent-flex-row-wrap camera-box">
- <div v-for="(item, index) in addrList" :key="index" class="player-box">
- <div class="player-name">{{ item.name }}</div>
- <div>
- <template v-if="item.addr.startsWith('rtsp://')">
- <video :id="`video${index}`" muted="true" autoplay></video>
- </template>
- <template v-else>
- <LivePlayer :videoUrl="item.addr" muted live loading/>
- </template>
- </div>
- </div>
- </div>
-
- </template>
- <script lang="ts" setup>
- import {onMounted, onUnmounted, ref } from 'vue';
- import { list } from './camera.api'
- import LivePlayer from '@liveqing/liveplayer-v3';
- const webRtcServerList = <any[]>[]
- let addrList = ref<{ name: string, addr: string }[]>([])
- async function getVideoAddrs(){
- const result = await list({ pageSize: 10000 })
- if(result && result.records && result.records.length > 0){
- addrList.value = result.records.map(item => ({ addr: item['addr'], name: item['name'] }))
- }
- }
- function getVideo() {
- const ip = VUE_APP_URL.webRtcUrl;
- for(let i =1; i<= addrList.value.length; i++){
- const item = addrList.value[i]
- if(item.addr.startsWith('rtsp://')){
- const webRtcServer = new window['WebRtcStreamer']('video' + i, location.protocol + ip)
- webRtcServerList.push(webRtcServer)
- // webRtcServer.connect('rtsp://admin:admin12345@192.168.183.64:554/Streaming/Channels/1')
- webRtcServer.connect(item.addr)
- }
- }
- }
- onMounted(async() => {
- await getVideoAddrs()
- getVideo()
- })
- onUnmounted(() => {
- const num = webRtcServerList.length
- for (let i = 0; i < num; i++) {
- webRtcServerList[i].disconnect()
- webRtcServerList[i] = null
- }
- })
- </script>
- <style lang="less">
- .camera-box{
- overflow-y: auto;
- .player-box{
- width: 314px;
- height: 208px;
- padding: 10px;
- background: url('/@/assets/images/vent/camera_bg.png');
- background-size: cover;
- position: relative;
- margin: 10px;
- .player-name{
- font-size: 14px;
- position: absolute;
- top: 15px;
- right: 15px;
- color: #fff;
- background-color: hsla(0, 0%, 50%, .5);
- border-radius: 2px;
- padding: 1px 5px;
- max-width: 120px;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- z-index: 999;
- }
- }
- }
-
- </style>
|