Merge pull request #5 from jullrich/StoringCameraHostname

adding javascript to store hostname in local storage between restart
This commit is contained in:
DylanSpeiser 2025-02-24 10:37:57 -05:00 committed by GitHub
commit 53fd2ebd3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,8 +19,14 @@ var unsavedChanges = [];
// Set everything up // Set everything up
function bodyOnLoad() { function bodyOnLoad() {
defaultControlsHTML = document.getElementById("allCamerasContainer").innerHTML; defaultControlsHTML = document.getElementById("allCamerasContainer").innerHTML;
// prefill camera hostname (or IP address)
document.getElementById("hostnameInput").value = localStorage.getItem("camerahostname_"+ci.toString());
if ( localStorage.getItem("camerasecurity_"+ci.toString()) === 'true' ) {
document.getElementById("secureCheckbox").checked = true
}
} }
// Checks the hostname, if it replies successfully then a new BMCamera object // Checks the hostname, if it replies successfully then a new BMCamera object
// is made and gets put in the array at ind // is made and gets put in the array at ind
function initCamera() { function initCamera() {
@ -35,13 +41,16 @@ function initCamera() {
if (response.status < 300) { if (response.status < 300) {
// Success, make a new camera, get all relevant info, and populate the UI // Success, make a new camera, get all relevant info, and populate the UI
cameras[ci] = new BMCamera(hostname, security); cameras[ci] = new BMCamera(hostname, security);
// Save camera hostname and security status in local storage
localStorage.setItem("camerahostname_"+ci, hostname)
localStorage.setItem("camerasecurity_"+ci, security)
cameras[ci].updateUI = updateUIAll; cameras[ci].updateUI = updateUIAll;
cameras[ci].active = true; cameras[ci].active = true;
document.getElementById("connectionErrorSpan").innerHTML = "Connected."; document.getElementById("connectionErrorSpan").innerHTML = "Connected.";
document.getElementById("connectionErrorSpan").setAttribute("style","color: #6e6e6e;"); document.getElementById("connectionErrorSpan").setAttribute("style","color: #6e6e6e;");
} else { } else {
// Something has gone wrong, tell the user // Something has gone wrong, tell the user
document.getElementById("connectionErrorSpan").innerHTML = response.statusText; document.getElementById("connectionErrorSpan").innerHTML = response.statusText;
@ -320,7 +329,10 @@ function switchCamera(index) {
document.getElementById("cameraNumberLabel").innerHTML = "CAM"+(ci+1); document.getElementById("cameraNumberLabel").innerHTML = "CAM"+(ci+1);
document.getElementById("cameraName").innerHTML = "CAMERA NAME"; document.getElementById("cameraName").innerHTML = "CAMERA NAME";
document.getElementById("hostnameInput").value = localStorage.getItem("camerahostname_"+ci.toString());
if ( localStorage.getItem("camerasecurity_"+ci.toString()) === 'true' ) {
document.getElementById("secureCheckbox").checked = true
}
if (cameras[ci]) { if (cameras[ci]) {
cameras[ci].active = true; cameras[ci].active = true;
} }