Newer
Older
//////////////////
//////////////////
transports: ['websocket'],
path: "/web/socket"
});
let first_camera_update = true
let first_camera_update = true
socket.on('connect', function() {
console.log('Connected to server');
});
socket.on('disconnect', function() {
console.log('Disconnected from server');
});
socket.on('timestamp', function(server_unix_time) {
Davide Ricci
committed
var diff = difftime(server_unix_time)
$('[data-status=timestamp-diff]').text(diff)
Davide Ricci
committed
//console.log(diff)
//////////////////
/// Dome stream
//////////////////
// Disable if not /ping:
if (e["dome-ping"].raw !== true) {
$("#Dome").addClass("pe-none").css({"opacity":"0.4"})
.find('*')
.attr('tabindex', '-1')
} else {
$("#Dome").removeClass("pe-none").css({"opacity": "1.0"})
.find('*')
.removeAttr('tabindex')
var elem = $("[data-status="+k+"]")
if (elem) {
elem.text(v.response)
}
$("[data-status="+k+"-azimuth]").text(e[k].response.azimuth)
$("[data-status="+k+"-parked]").text(e[k].response.parked)
});
////////////////////
/// Telescope stream
////////////////////
// Disable if not /ping:
if (e["telescope-ping"].raw !== true) {
$("#Telescope").addClass("pe-none").css({"opacity":"0.4"})
.find('*')
.attr('tabindex', '-1')
} else {
$("#Telescope").removeClass("pe-none").css({"opacity": "1.0"})
.find('*')
.removeAttr('tabindex')
$.each(e, function(k,v){
var elem = $("[data-status="+k+"]")
/// Depth 1
if (elem) {
//console.log(k)
elem.text(v.response)
}
$("[data-status="+k+"-ra]").text(e[k].response.radec[0])
$("[data-status="+k+"-dec]").text(e[k].response.radec[1])
$("[data-status="+k+"-alt]").text(e[k].response.altaz[0].toFixed(3))
$("[data-status="+k+"-az]").text(e[k].response.altaz[1].toFixed(3))
$("[data-status="+k+"-ha]").text(e[k].response.ha)
$("[data-status="+k+"-lst]").text(e[k].response.lst)
$("[data-status="+k+"-zd]").text((e[k].response[0]*3600).toFixed(1))
$("[data-status="+k+"-az]").text((e[k].response[1]*3600).toFixed(1))
}
//////////////////
/// Camera stream
//////////////////
socket.on("all-camera",function(e) {
// Disable if not /ping:
if (e["camera-ping"].raw !== true) {
$("#Camera").addClass("pe-none").css({"opacity":"0.4"})
.find('*')
.attr('tabindex', '-1')
} else {
$("#Camera").removeClass("pe-none").css({"opacity": "1.0"})
.find('*')
.removeAttr('tabindex')
// Update the input fields with the real data, at first page load
if (first_camera_update) {
$('#filter').prop("value", e["camera-filter"].response)
$("#binning").prop("value", e["camera-settings"].response.binning[0]) // [0,0]
$('#x0').prop("value", e["camera-settings"].response.xystart[0])
$('#y0').prop("value", e["camera-settings"].response.xystart[1])
$('#xf').prop("value", e["camera-settings"].response.xyend[0])
$('#yf').prop("value", e["camera-settings"].response.xyend[1])
first_camera_update = false
}
}
/// Depth 1
var elem = $("[data-status="+k+"]")
if (elem) {
elem.text(v.response)
}
if (k == "camera-settings") {
$.each(v.response, function(kk,vv){
var elem = $("[data-status=camera-"+kk+"]")
if (elem) {
elem.text(vv)
}
<<<<<<< HEAD
});
=======
});
>>>>>>> ad7097fa78c2d07b3ce9cdefe7259b19595547d6
Davide Ricci
committed
});
});
/////////////////////
/// Sequencer stream
/////////////////////
var res = e //JSON.parse(e.data)
$.each(res.response, function(k,v){ /// sequencer has just 1 response
var elem = $("[data-status=sequencer-"+k)
if (elem) {
elem.text(v)
}
});
/// For the JS9 display
var auto_display = $("#auto-display").prop("checked")
if (auto_display) {
if (typeof JS9 != "undefined") {
JS9.Load("/static/temp.fits", {refresh:true, colormap:"heat"} )
}
}
/// For the d3.js focus output
var auto_output = $("#auto-output").prop("checked")
if (auto_output) {
if (res.response.output && res.response.output.focus) {
const focus = res.response.output.focus
const data = focus.m2.map((x, i) => ({ x, y: focus.fwhm[i] }));
chart1.update(data);
}
}
}
});
///////////////////////
/// Environment stream
///////////////////////
var res = e //JSON.parse(e.data)
Davide Ricci
committed
// console.log(res)
if (res && res.external) {
$.each(res.external, function(k,v){
Davide Ricci
committed
var elem = $("[data-status=environment-external-"+k)
if (elem) {
elem.text(v)
}
});
}
if (res && res.internal) {
Davide Ricci
committed
$.each(res.internal, function(k,v){
var elem = $("[data-status=environment-internal-"+k)
if (elem) {
elem.text(v)
}
});
Davide Ricci
committed
}
///////////////////////
///////////////////////
const elem = $("[data-status=webcam-snapshot")
if (e) {
const url = btoa(String.fromCharCode(...new Uint8Array(e)));
elem.attr("src", 'data:image/jpeg;base64,' + url)
} else {
console.log("no image?")
}
Davide Ricci
committed
});
///////////////////////
/// Logfile stream
///////////////////////
var log_level_list = ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"];
var log_level = "";
$.each(log_level_list, function(index, value) {
//console.log(lines)
if (lines.indexOf(value) !== -1) {
log_level = value+'-level-line';
return false;
}
});
$("#stream-output").prepend(
'<div class="'+log_level+'">'+ansi_up.ansi_to_html(line)+'</div>'
);
})
///////////////////////
/// Pulse on changes
///////////////////////
function pulse(selector) {
// var done = "bg-success"
// var delay = 200
selector.fadeTo('slow', 0.5, function() {
selector.fadeTo('slow', 1.0) //.removeClass(done);
});
// setTimeout(function() {
// selector.removeClass(done);
// }, delay);
}
$(document).ready(function(){
// Select all elements with data-status attribute
const elements = document.querySelectorAll('[data-status]');
// Object to store previous text content of each element
const previousTextContent = {};
// Function to monitor text changes
function observeChanges(element) {
const observer = new MutationObserver(mutationsList => {
for (let mutation of mutationsList) {
if (mutation.type === 'childList') {
const previousText = previousTextContent[element.getAttribute('data-status')];
const currentText = element.textContent.trim();
if (previousText !== currentText) {
pulse($(element))
previousTextContent[element.getAttribute('data-status')] = currentText;
}
}
}
});
observer.observe(element, { subtree: true, childList: true });
}
// Apply observeChanges function to each element
elements.forEach(element => {
previousTextContent[element.getAttribute('data-status')] = element.textContent.trim();
observeChanges(element);
});