4.17websocket调试成功

main
coco1986509808 2023-04-17 20:32:10 +08:00
parent 8c6d65631a
commit fc0a1cf860
3 changed files with 97 additions and 3 deletions

View File

@ -387,10 +387,7 @@
*/
getWarningPicture(warningData) {
// warningDataws
console.log("this warningDAta")
console.log(warningData)
this.warningList = warningData
//this.warningList.unshift(warningData)
console.log("this warningList")
console.log(this.warningList)

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

View File

@ -0,0 +1,97 @@
<template>
<video style="width: 100%;height: 100%" ref="video"></video>
</template>
<script>
import qs from "qs";
export default {
props: ['msg'],
data() {
return {
rtspUrl:this.msg,
}
},
created() {
console.log(this.rtspUrl)
this.startVideo();
},
methods: {
startVideo() {
this.status = false;
this.pc = new RTCPeerConnection();
this.pc.ontrack = (e) => {
let el = this.$refs.video;
if(el){
el.srcObject = event.streams[0];
el.muted = true;
el.autoplay = true;
el.controls = true;
// el.width = 600;
}
};
this.pc.oniceconnectionstatechange = (e) => {
console.log(
new Date() + " ConnectionState:" + this.pc.iceConnectionState
);
};
this.pc.onnegotiationneeded = this.handleNegotiationNeededEvent;
this.pc.addTransceiver("video", {
direction: "sendrecv",
});
//
let sendChannel = this.pc.createDataChannel("KeepAlive");
sendChannel.onclose = () => console.log("sendChannel has closed");
sendChannel.onopen = () => {
console.log("sendChannel has opened");
sendChannel.send("ping");
this.timer = setInterval(() => {
sendChannel.send("ping");
}, 1000);
};
},
async handleNegotiationNeededEvent() {
let offer = await this.pc.createOffer();
await this.pc.setLocalDescription(offer);
let params = qs.stringify({
url: this.rtspUrl,
data: btoa(this.pc.localDescription.sdp),
});
this.$http
.post(window.GLOBAL_CONFIG['rtspApi_URL']+"/api/v1/play", params, {emulateJSON: true})
.then(({ data: res }) => {
console.log(`msg: ${res.msg}; data:${res.data}`);
this.pc.setRemoteDescription(
new RTCSessionDescription({
type: "answer",
sdp: atob(res.data),
})
);
})
.catch((e) => {
console.warn(e);
});
},
stopVideo() {
this.status = true;
if (this.timer != null) {
clearInterval(this.timer);
}
if (this.pc != null) {
this.pc.close();
}
try {
let arr=this.$map.getBuilding(this.mapData.mapName).getFloor(this.mapData.floorName).getLayer('videoFence');
if(arr&&arr.children){
arr.children.forEach(item=>{
item.stopFlash();
})
}
}catch(err){
}
},
}
}
</script>