| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <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 autoplay></video>
- <div class="click-box" @dblclick="goFullScreen(`video${index}`)"></div>
- </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, cameraAddr } 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'].includes('0.0.0.0') ? item['addr'].replace('0.0.0.0', window.location.hostname) :item['addr'] , name: item['name'] }))
- const cameraList = <{ name: string, addr: string }[]>[]
- result.records.forEach(async item => {
- if (item['devicekind'] == 'toHKRtsp') {
- // 从海康平台接口获取视频流
- const data = await cameraAddr({ cameraCode: item['addr'] });
- if (data && data['url']) {
- cameraList.push({ name: item['name'], addr: data['url'] });
- }
- } else {
- cameraList.push({ name: item['name'], addr: item['addr'] });
- }
- });
- addrList.value = cameraList
- }
- }
- function getVideo() {
- const ip = VUE_APP_URL.webRtcUrl;
- for(let i =0; i < addrList.value.length; i++){
- const item = addrList.value[i]
- if(item.addr.startsWith('rtsp://')){
- const dom = document.getElementById('video' + i) as HTMLVideoElement
- dom.muted = true;
- dom.volume = 0
- const webRtcServer = new window['WebRtcStreamer'](dom, location.protocol + ip)
- webRtcServerList.push(webRtcServer)
- webRtcServer.connect(item.addr)
- }
- }
- }
- function goFullScreen(domId) {
- const videoDom = document.getElementById(domId) as HTMLVideoElement
- if(videoDom.requestFullscreen){
- videoDom.requestFullscreen()
- videoDom.play()
- } else if(videoDom.mozRequestFullscreen){
- videoDom.mozRequestFullscreen()
- videoDom.play()
- } else if (videoDom.webkitRequestFullscreen) {
- videoDom.webkitRequestFullscreen()
- videoDom.play()
- } else if (videoDom.msRequestFullscreen) {
- videoDom.msRequestFullscreen()
- videoDom.play()
- }
- }
- 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;
- }
- .click-box{
- position: absolute;
- width: 100%;
- height: 100%;
- top: 0;
- left: 0;
- }
- }
- }
- // :deep(video){
- // width: 100% !important;
- // height: 100% !important;
- // object-fit: cover !important;
- // }
- </style>
|