♻️ cam: extract another function from template
Also fetch video elements only once on startup.
This commit is contained in:
1 parent
8d0d3187de
commit
9eb92cfba1
2 files changed
+20
-7
No files matched your search
@@ -45,6 +45,8 @@ $(function () {
|
||||
self.webcamError = ko.observable(false);
|
||||
self.webcamMuted = ko.observable(true);
|
||||
self.webRTCPeerConnection = null;
|
||||
self.webcamElementHls = null;
|
||||
self.webcamElementWebrtc = null;
|
||||
|
||||
self.keycontrolActive = ko.observable(false);
|
||||
self.keycontrolHelpActive = ko.observable(false);
|
||||
@@ -330,9 +332,9 @@ $(function () {
|
||||
|
||||
self._getActiveWebcamVideoElement = function () {
|
||||
if (self.webcamWebRTCEnabled()) {
|
||||
return document.getElementById("webcam_webrtc");
|
||||
return self.webcamElementWebrtc;
|
||||
} else {
|
||||
return document.getElementById("webcam_hls");
|
||||
return self.webcamElementHls;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -344,6 +346,12 @@ $(function () {
|
||||
self._getActiveWebcamVideoElement().requestFullscreen();
|
||||
};
|
||||
|
||||
self.toggleWebcamMute = function () {
|
||||
self.webcamMuted(!self.webcamMuted());
|
||||
self.webcamElementWebrtc.muted = self.webcamMuted();
|
||||
self.webcamElementHls.muted = self.webcamMuted();
|
||||
};
|
||||
|
||||
self.sendJogCommand = function (axis, multiplier, distance) {
|
||||
if (typeof distance === "undefined") distance = self.distance();
|
||||
if (
|
||||
@@ -603,6 +611,11 @@ $(function () {
|
||||
self.extrusionAmount(self.settings.printer_defaultExtrusionLength());
|
||||
};
|
||||
|
||||
self.onStartup = function () {
|
||||
self.webcamElementHls = document.getElementById("webcam_hls");
|
||||
self.webcamElementWebrtc = document.getElementById("webcam_webrtc");
|
||||
};
|
||||
|
||||
self.onFocus = function (data, event) {
|
||||
if (!self.settings.feature_keyboardControl()) return;
|
||||
self.keycontrolActive(true);
|
||||
@@ -743,7 +756,7 @@ $(function () {
|
||||
};
|
||||
|
||||
self._switchToHlsWebcam = function () {
|
||||
var video = document.getElementById("webcam_hls");
|
||||
var video = self.webcamElementHls;
|
||||
video.onresize = self._updateVideoTagWebcamLayout;
|
||||
|
||||
// Ensure WebRTC is unloaded
|
||||
@@ -774,12 +787,12 @@ $(function () {
|
||||
if (!isWebRTCAvailable()) {
|
||||
return;
|
||||
}
|
||||
var video = document.getElementById("webcam_webrtc");
|
||||
var video = self.webcamElementWebrtc;
|
||||
video.onresize = self._updateVideoTagWebcamLayout;
|
||||
|
||||
// Ensure HLS is unloaded
|
||||
if (self.hls != null) {
|
||||
document.getElementById("webcam_hls").src = null;
|
||||
self.webcamElementHls.src = null;
|
||||
self.hls.destroy();
|
||||
self.hls = null;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<!-- ko if: loginState.hasPermissionKo(access.permissions.WEBCAM) -->
|
||||
<div id="webcam_video_container" tabindex="0" data-bind="visible: webcamWebRTCEnabled() || webcamHlsEnabled(), css: { webcam_rotated: settings.webcam_rotate90(), webcam_unrotated: !settings.webcam_rotate90() }">
|
||||
<div class="video-controls btn-group action-buttons">
|
||||
<div class="btn btn-mini" data-bind="click: function(data, event) { $root.launchWebcamFullscreen() }"><i class="fas fa-expand"></i></div>
|
||||
<div class="btn btn-mini" data-bind="click: function(data, event) { $root.launchWebcamFullscreen() }"><i class="fas fa-expand"></i></div>
|
||||
<div class="btn btn-mini" data-bind="visible: document.pictureInPictureEnabled, click: function(data, event) { $root.launchWebcamPictureInPicture() }"><i class="fas fa-images"></i></div>
|
||||
<div class="btn btn-mini" data-bind="click: function(data, event) { webcamMuted(!webcamMuted()); document.getElementById('webcam_webrtc').muted = webcamMuted(); document.getElementById('webcam_hls').muted = webcamMuted() }">
|
||||
<div class="btn btn-mini" data-bind="click: function(data, event) { $root.toggleWebcamMute() }">
|
||||
<!-- ko if: webcamMuted() -->
|
||||
<i class="fas fa-volume-mute"></i>
|
||||
<!-- /ko -->
|
||||
|
||||
Reference in new issue
Block a user