<template>
|
<div class="video-player">
|
<video ref="videoPlayer" :poster="poster" preload="auto" muted></video>
|
<div class="controls">
|
<!-- 全屏 -->
|
<i class="el-icon-full-screen" @click="fullScreen"></i>
|
</div>
|
</div>
|
</template>
|
<script>
|
import Wfs from "./wfs";
|
|
export default {
|
name: "CameraPlayer",
|
props: {
|
wsAddr: {
|
type: String,
|
// default: "ws://192.168.1.182:10101/ws"
|
default: `${location.protocol === "https" ? "wss" : "ws"}://${location.host}/ws`
|
},
|
cameraName: {
|
type: String,
|
default: ""
|
},
|
cameraID: {
|
type: String,
|
default: "C4668FD0-3CAE-C31F-C21E-28B7001243C4"
|
},
|
rtspUrl: {
|
type: String,
|
default: "rtsp://admin:a1234567@192.168.1.201:554/h264/ch1/main/av_stream"
|
},
|
isRunning: {
|
type: Boolean,
|
default: false
|
},
|
isGb: {
|
type: Boolean,
|
default: false
|
}
|
},
|
computed: {
|
poster() {
|
return "/images/player/player_poster.gif?t=" + Math.random()
|
}
|
},
|
data() {
|
return {
|
wfs: {},
|
wfsId: 0
|
};
|
},
|
watch: {
|
rtspUrl: function (newVal, oldVal) {
|
if (newVal !== oldVal) {
|
if (this.wfs.config) {
|
this.wfs.destroy();
|
}
|
this.$nextTick(() => {
|
this.clickStart();
|
});
|
}
|
}
|
},
|
methods: {
|
checkConnect(id) {
|
// console.log(this.wfs)
|
if (id !== this.wfsId) {
|
return
|
}
|
|
if (this.wfs.websocketLoader && this.wfs.websocketLoader.client) {
|
if (this.wfs.websocketLoader.client.disconnected) {
|
this.clickStart();
|
console.log("实时视频已断开,正在重连")
|
return
|
}
|
}
|
|
let _this = this;
|
setTimeout(() => {
|
_this.checkConnect(id)
|
}, 10000)
|
},
|
clickStart() {
|
if (this.rtspUrl == "") {
|
return;
|
}
|
|
let cameraId = this.cameraID;
|
if (cameraId == "") {
|
cameraId = this.getUuid();
|
}
|
|
if (Wfs.isSupported()) {
|
let wsAddr = this.wsAddr;
|
let cameraInfo = {
|
cameraID: cameraId,
|
rtspUrl: this.rtspUrl,
|
isRunning: this.isRunning,
|
isGb28181: this.isGb
|
};
|
|
// let camera = document.getElementById(this.cameraID);
|
let camera = this.$refs.videoPlayer;
|
this.wfs = new Wfs();
|
let randomId = this.getUuid();
|
this.wfsId = randomId;
|
this.wfs.attachMedia(camera, "chX", "H264Raw", wsAddr, cameraInfo);
|
|
this.checkConnect(randomId)
|
}
|
},
|
getUuid() {
|
var s = [];
|
var hexDigits = "0123456789abcdefghijkopqrst";
|
for (var i = 0; i < 36; i++) {
|
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
}
|
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
|
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
|
s[8] = s[13] = s[18] = s[23] = "-";
|
var uuid = s.join("");
|
return uuid;
|
},
|
fullScreen() {
|
this.$refs.videoPlayer.webkitRequestFullScreen();
|
}
|
},
|
mounted() {
|
this.clickStart();
|
},
|
beforeDestroy() {
|
this.wfs.destroy();
|
this.wfsId = "";
|
}
|
};
|
</script>
|
|
<style lang="scss">
|
video {
|
object-fit: fill;
|
width: 100%;
|
height: 100%;
|
}
|
.video-player {
|
position: relative;
|
width: 100%;
|
height: 100%;
|
.controls {
|
display: none;
|
position: absolute;
|
bottom: 0%;
|
color: #fff;
|
width: 100%;
|
height: 10%;
|
background: -webkit-linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.9));
|
|
i {
|
float: right;
|
font-size: 15px;
|
margin-right: 7%;
|
cursor: pointer;
|
}
|
i:hover {
|
color: rgb(236, 235, 235);
|
-moz-box-shadow: 2px 2px 7px #000;
|
-webkit-box-shadow: 2px 2px 7px #000;
|
box-shadow: 2px 2px 7px #000;
|
}
|
}
|
}
|
|
.video-player:hover {
|
.controls {
|
display: block;
|
}
|
}
|
</style>
|