|
@@ -1,32 +1,42 @@
|
|
|
/*
|
|
|
viewport.js
|
|
|
*/
|
|
|
+let massStorageSwitchURL = "/api/v1/mass_storage/switch"; //side accept kvm or remote
|
|
|
|
|
|
-function cjax(object){
|
|
|
- let csrf_token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
|
|
- $.ajax({
|
|
|
- url: object.url,
|
|
|
- type: object.type || 'POST',
|
|
|
- data: object.data || {},
|
|
|
- headers: {
|
|
|
- 'X-CSRF-Token': csrf_token
|
|
|
- },
|
|
|
- success: object.success,
|
|
|
- error: object.error
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-// Add cjax as a jQuery method
|
|
|
-$.cjax = cjax;
|
|
|
+// CSRF-protected AJAX function
|
|
|
+$.cjax = function(payload){
|
|
|
+ let requireTokenMethod = ["POST", "PUT", "DELETE"];
|
|
|
+ if (requireTokenMethod.includes(payload.method) || requireTokenMethod.includes(payload.type)){
|
|
|
+ //csrf token is required
|
|
|
+ let csrfToken = document.getElementsByTagName("meta")["dezukvm.csrf.token"].getAttribute("content");
|
|
|
+ payload.headers = {
|
|
|
+ "dezukvm_csrf_token": csrfToken,
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ $.ajax(payload);
|
|
|
+}
|
|
|
|
|
|
+$(document).ready(function() {
|
|
|
+ // Check if the user has opted out of seeing the audio tips
|
|
|
+ if (localStorage.getItem('dontShowAudioTipsAgain') === 'true') {
|
|
|
+ $('#audioTips').remove();
|
|
|
+ }
|
|
|
+});
|
|
|
|
|
|
+/* Mass Storage Switch */
|
|
|
function switchMassStorageToRemote(){
|
|
|
$.cjax({
|
|
|
- url: '/aux/switchusbremote',
|
|
|
- type: 'GET',
|
|
|
+ url: massStorageSwitchURL,
|
|
|
+ type: 'POST',
|
|
|
+ data: {
|
|
|
+ side: 'remote',
|
|
|
+ uuid: kvmDeviceUUID
|
|
|
+ },
|
|
|
success: function(response) {
|
|
|
- //alert('Mass Storage switched to Remote successfully.');
|
|
|
+ if (response.error) {
|
|
|
+ alert('Error switching Mass Storage to Remote: ' + response.error);
|
|
|
+ }
|
|
|
},
|
|
|
error: function(xhr, status, error) {
|
|
|
alert('Error switching Mass Storage to Remote: ' + error);
|
|
@@ -36,10 +46,16 @@ function switchMassStorageToRemote(){
|
|
|
|
|
|
function switchMassStorageToKvm(){
|
|
|
$.cjax({
|
|
|
- url: '/aux/switchusbkvm',
|
|
|
- type: 'GET',
|
|
|
+ url: massStorageSwitchURL,
|
|
|
+ type: 'POST',
|
|
|
+ data: {
|
|
|
+ side: 'kvm',
|
|
|
+ uuid: kvmDeviceUUID
|
|
|
+ },
|
|
|
success: function(response) {
|
|
|
- //alert('Mass Storage switched to KVM successfully.');
|
|
|
+ if (response.error) {
|
|
|
+ alert('Error switching Mass Storage to KVM: ' + response.error);
|
|
|
+ }
|
|
|
},
|
|
|
error: function(xhr, status, error) {
|
|
|
alert('Error switching Mass Storage to KVM: ' + error);
|
|
@@ -47,6 +63,16 @@ function switchMassStorageToKvm(){
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+/*
|
|
|
+ UI elements and events
|
|
|
+*/
|
|
|
+
|
|
|
+function handleDontShowAudioTipsAgain(){
|
|
|
+ localStorage.setItem('dontShowAudioTipsAgain', 'true');
|
|
|
+ $('#audioTips').remove();
|
|
|
+}
|
|
|
+
|
|
|
function toggleFullScreen(){
|
|
|
let elem = document.documentElement;
|
|
|
if (!document.fullscreenElement) {
|
|
@@ -71,31 +97,3 @@ function toggleFullScreen(){
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-function measureMJPEGfps(imgId, callback, intervalMs = 1000) {
|
|
|
- let frameCount = 0;
|
|
|
- let lastSrc = '';
|
|
|
- const img = document.getElementById(imgId);
|
|
|
-
|
|
|
- if (!img) {
|
|
|
- console.error('Image element not found');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Listen for src changes (for MJPEG, the src stays the same, but the image data updates)
|
|
|
- img.addEventListener('load', () => {
|
|
|
- frameCount++;
|
|
|
- });
|
|
|
-
|
|
|
- // Periodically report FPS
|
|
|
- setInterval(() => {
|
|
|
- callback(frameCount);
|
|
|
- frameCount = 0;
|
|
|
- }, intervalMs);
|
|
|
-}
|
|
|
-
|
|
|
-// Example usage:
|
|
|
-measureMJPEGfps('remoteCapture', function(fps) {
|
|
|
- document.title = `${fps} fps| DezuKVM`;
|
|
|
-});
|