mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-24 01:31:44 +00:00
* Reverted to front end using MJPEG streams. Added FPS limiting to the stream. * formatting * fixup - got handlers getting called on error to reload * revised architecture to let a click open a new tab Co-authored-by: Matt <matthew.morley.ca@gmail.com>
111 lines
3.7 KiB
Vue
111 lines
3.7 KiB
Vue
<template>
|
|
<img
|
|
:id="id"
|
|
crossOrigin="anonymous"
|
|
:style="styleObject"
|
|
:src="src"
|
|
alt=""
|
|
@click="clickHandler"
|
|
@error="loadErrHandler"
|
|
/>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: "CvImage",
|
|
// eslint-disable-next-line vue/require-prop-types
|
|
props: ['address', 'scale', 'maxHeight', 'maxHeightMd', 'maxHeightLg', 'maxHeightXl', 'colorPicking', 'id', 'disconnected'],
|
|
data() {
|
|
return {
|
|
seed: 1.0,
|
|
}
|
|
},
|
|
computed: {
|
|
styleObject: {
|
|
get() {
|
|
let ret = {
|
|
"border-radius": "3px",
|
|
"display": "block",
|
|
"object-fit": "contain",
|
|
"background-size:": "contain",
|
|
"object-position": "50% 50%",
|
|
"max-width": "100%",
|
|
"margin-left": "auto",
|
|
"margin-right": "auto",
|
|
"max-height": this.maxHeight,
|
|
height: `${this.scale}%`,
|
|
cursor: (this.colorPicking ? `url(${require("../../assets/eyedropper.svg")}),` : "pointer") + "default",
|
|
};
|
|
|
|
if (this.$vuetify.breakpoint.xl) {
|
|
ret["max-height"] = this.maxHeightXl;
|
|
} else if (this.$vuetify.breakpoint.lg) {
|
|
ret["max-height"] = this.maxHeightLg;
|
|
} else if (this.$vuetify.breakpoint.md) {
|
|
ret["max-height"] = this.maxHeightMd;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
},
|
|
src: {
|
|
get() {
|
|
var port = this.getCurPort();
|
|
if(port <= 0){
|
|
//Invalid port, keep it spinny
|
|
return require("../../assets/loading.gif");
|
|
} else {
|
|
//Valid port, connect
|
|
return this.getSrcURLFromPort(port);
|
|
}
|
|
},
|
|
},
|
|
},
|
|
mounted() {
|
|
this.reload(); // Force reload image on creation
|
|
},
|
|
methods: {
|
|
getCurPort(){
|
|
var port = -1;
|
|
if(this.disconnected){
|
|
//Disconnected, port is unknown.
|
|
port = -1;
|
|
} else {
|
|
//Connected - get the port
|
|
if(this.id == 'raw-stream'){
|
|
port = this.$store.state.cameraSettings[this.$store.state.currentCameraIndex].inputStreamPort
|
|
} else {
|
|
port = this.$store.state.cameraSettings[this.$store.state.currentCameraIndex].outputStreamPort
|
|
}
|
|
}
|
|
return port;
|
|
},
|
|
getSrcURLFromPort(port){
|
|
return "http://" + location.hostname + ":" + port + "/stream.mjpg" + "?" + this.seed;
|
|
},
|
|
loadErrHandler(event) {
|
|
console.log(event);
|
|
console.log("Error loading image, attempting to do it again...");
|
|
this.reload();
|
|
},
|
|
clickHandler(event) {
|
|
if(this.colorPicking){
|
|
this.$emit('click', event);
|
|
} else {
|
|
var port = this.getCurPort();
|
|
if(port <= 0){
|
|
console.log("No valid port, ignoring click.");
|
|
} else {
|
|
//Valid port, connect
|
|
window.open(this.getSrcURLFromPort(port), '_blank');
|
|
}
|
|
}
|
|
|
|
},
|
|
reload() {
|
|
this.seed = new Date().getTime();
|
|
}
|
|
},
|
|
}
|
|
</script>
|