Huge restructuring of frontend code. 1.2.0 prerelease

This commit is contained in:
2020-10-24 00:32:14 +02:00
parent b645a1ff94
commit 91a4cea453
12 changed files with 506 additions and 413 deletions

46
js/camera.js Normal file
View File

@@ -0,0 +1,46 @@
export const BrowserModCameraMixin = (C) => class extends C {
setup_camera() {
console.log("Starting camera")
if(this._video) return;
this._video = document.createElement("video");
this._video.autoplay = true;
this._video.playsInline = true;
this._video.style.display = "none";
this._canvas = document.createElement("canvas");
this._canvas.style.display = "none";
document.body.appendChild(this._video);
document.body.appendChild(this._canvas);
if(!navigator.mediaDevices) return;
console.log("Starting devices")
navigator.mediaDevices.getUserMedia({video: true, audio: false}).then((stream) => {
this._video.srcObject = stream;
this._video.play();
this.update_camera();
})
this._camera_framerate = 2;
window.addEventListener("click", () => this._video.play(), {once: true});
}
update_camera() {
this._canvas.width = this._video.videoWidth;
this._canvas.height = this._video.videoHeight;
const context = this._canvas.getContext('2d');
context.drawImage(this._video, 0, 0, this._video.videoWidth, this._video.videoHeight);
this.sendUpdate({
camera: this._canvas.toDataURL('image/jpeg'),
});
setTimeout(() => this.update_camera(), Math.round(1000 / this._camera_framerate));
}
}