2022-11-25 19:46:41 +01:00
|
|
|
// Timeline drag and drop elements default attributes
|
|
|
|
const tl_cont_attr = {id:"tl_cont", ondrop: "drop(event, this)", ondragover:"allow_drop(event)"};
|
2022-10-06 20:08:04 +02:00
|
|
|
const tl_drag_attr = {id:"tl_drag", draggable:"true", ondragstart:"drag(event, this)"};
|
|
|
|
|
2022-10-08 16:49:45 +02:00
|
|
|
// Config
|
2022-11-25 19:46:41 +01:00
|
|
|
var DEBUG = 0;
|
|
|
|
var cmd_port = "8888";
|
2022-10-08 16:49:45 +02:00
|
|
|
var timeline_color_cursor = "#FF8839";
|
2022-11-25 19:46:41 +01:00
|
|
|
var timeline_color_bg = "#2EB8E600";
|
|
|
|
var scan_interval = 3000;
|
|
|
|
var status_all = "Searching network for live hosts...";
|
2022-11-12 18:17:25 +01:00
|
|
|
// Global vars
|
2022-11-25 19:46:41 +01:00
|
|
|
var src_elem = "";
|
2022-10-08 16:49:45 +02:00
|
|
|
var medias_status = {};
|
2022-11-12 18:17:25 +01:00
|
|
|
var fileButtons = [];
|
2022-11-25 19:46:41 +01:00
|
|
|
var freeze_timeline_update = 0;
|
2022-10-06 20:08:04 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function sleep(ms) {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function update_playlist(host){
|
|
|
|
var media_count = document.getElementById("timeline_" + host).children.length;
|
|
|
|
// Reversed loop
|
2022-10-06 20:08:04 +02:00
|
|
|
for (i=media_count,l=0;i>l;i--) {
|
2022-11-25 19:46:41 +01:00
|
|
|
//~ for (i=0,l=media_count;i<l;i++) {
|
|
|
|
// Find current's timeline element children's 'media_id' value
|
|
|
|
toShift = document.getElementById("timeline_" + host).children[i-1].children[0].getAttribute("media_id");
|
|
|
|
console.log(toShift + " : " + document.getElementById("timeline_" + host).children[i-1].children[0].innerText);
|
|
|
|
// Move 'toShift' after element with id '1'
|
|
|
|
// In VLC's playlist XML representation, playlist gets id '1', so moving to that id
|
|
|
|
// really means moving to the the very start of the playlist.
|
|
|
|
send_ajax_cmd("/" + host + "/move/" + toShift + "/1");
|
|
|
|
await sleep(80);
|
|
|
|
}
|
|
|
|
// Un-freeze timeline update flag
|
|
|
|
freeze_timeline_update = 0;
|
2022-10-06 20:08:04 +02:00
|
|
|
}
|
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function find_target_index(element, index, array, thisArg){
|
2022-11-12 18:17:25 +01:00
|
|
|
if (element == this) {
|
2022-11-25 19:46:41 +01:00
|
|
|
return index + 1;
|
2022-11-12 18:17:25 +01:00
|
|
|
}
|
|
|
|
return 0;
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-10-06 20:08:04 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function shift_elements(target_elem) {
|
|
|
|
// Shift elements in the timeline UI
|
|
|
|
//
|
|
|
|
// Get a list of current element siblings
|
|
|
|
var elem_list = Array.from(src_elem.parentElement.children);
|
|
|
|
// Initiate slice
|
2022-10-06 20:08:04 +02:00
|
|
|
var elem_list_slice = elem_list;
|
2022-11-25 19:46:41 +01:00
|
|
|
// Find indexes of source and target elements in the timeline
|
|
|
|
var source_idx = elem_list.findIndex(find_target_index, src_elem);
|
|
|
|
var target_idx = elem_list.findIndex(find_target_index, target_elem);
|
2022-10-06 20:08:04 +02:00
|
|
|
var idx;
|
2022-11-25 19:46:41 +01:00
|
|
|
// idx is the index where the elements should be inserted back
|
|
|
|
// Target element is on the left of the source element
|
|
|
|
if (source_idx < target_idx){
|
|
|
|
elem_list_slice = elem_list.slice(source_idx + 1, target_idx + 1);
|
|
|
|
idx = source_idx;
|
2022-10-06 20:08:04 +02:00
|
|
|
} else {
|
2022-11-25 19:46:41 +01:00
|
|
|
// Target element is on the right of the source element
|
|
|
|
elem_list_slice = elem_list.slice(target_idx, source_idx );
|
|
|
|
idx = target_idx + 1;
|
2022-10-06 20:08:04 +02:00
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
// Shift elements according to idx
|
|
|
|
for (i=0, l=elem_list_slice.length; i<l;i++){
|
|
|
|
elem_list[idx + i].appendChild(elem_list_slice[i].children[0]);
|
2022-10-06 20:08:04 +02:00
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
return target_elem;
|
|
|
|
}
|
2022-10-06 20:08:04 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function allow_drop(ev) {
|
2022-11-12 18:17:25 +01:00
|
|
|
ev.preventDefault();
|
|
|
|
drop_id = ev.dataTransfer.getData("text");
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-10-06 20:08:04 +02:00
|
|
|
|
|
|
|
function drag(ev, source) {
|
2022-11-25 19:46:41 +01:00
|
|
|
// Freeze timeline update flag
|
|
|
|
freeze_timeline_update = 1;
|
|
|
|
src_elem = ev.target.parentElement;
|
|
|
|
if (DEBUG) {
|
|
|
|
console.log(src_elem.children[0].getAttribute("media_id") + " : " + src_elem.children[0].innerText);
|
|
|
|
}
|
2022-11-12 18:17:25 +01:00
|
|
|
ev.dataTransfer.setData("text", ev.target.id);
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-10-06 20:08:04 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function drop(ev, target_elem) {
|
|
|
|
// If the currently dragged element is dropped on another element, shift HTML elements in the timeline to the left or right from the target element.
|
|
|
|
//
|
2022-11-12 18:17:25 +01:00
|
|
|
ev.preventDefault();
|
2022-11-25 19:46:41 +01:00
|
|
|
// Get dragged element id
|
2022-11-12 18:17:25 +01:00
|
|
|
var data = ev.dataTransfer.getData("text");
|
2022-11-25 19:46:41 +01:00
|
|
|
// Only shift if not dropping on self
|
|
|
|
if (src_elem.id != target_elem.id) {
|
|
|
|
dropTarget = shift_elements(target_elem);
|
2022-10-06 20:08:04 +02:00
|
|
|
if (dropTarget) {
|
2022-11-25 19:46:41 +01:00
|
|
|
//
|
2022-10-06 20:08:04 +02:00
|
|
|
dropTarget.appendChild(document.getElementById(data));
|
2022-11-25 19:46:41 +01:00
|
|
|
// Update VLC playlist according to UI timeline
|
|
|
|
// TODO : This currently sends the move cmd to all instances. Fix it to specify which host to send the cmd to.
|
|
|
|
update_playlist("10.42.0.10");
|
2022-11-12 18:17:25 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
send_ajax_cmd("/all/list");
|
|
|
|
//~ setTimeout(function(){ freeze_timeline_update = 0; console.log("shwing!"); }, 2000);
|
|
|
|
|
|
|
|
}
|
2022-10-06 20:08:04 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function adjust_timeline() {
|
|
|
|
// Adapt timeline's UI elements to fit the width of their parent container.
|
|
|
|
//
|
|
|
|
//~ var child = document.getElementById('timeline').children;
|
|
|
|
var child = document.querySelector('[id^="timeline_"]').children;
|
2022-10-06 20:08:04 +02:00
|
|
|
var divWidth = 100 / child.length;
|
|
|
|
for (i=0, l=child.length;i<l;i++) {
|
|
|
|
child[i].style.width= divWidth + "%";
|
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-10-06 20:08:04 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function add_HTML_attr(id, attr, val , child=-1) {
|
|
|
|
// Add attribute 'attr' with value 'val' to the HTML element with id 'id'.
|
|
|
|
// If child is other than -1, the attribute is applied to the HTML element's child at position 'child'
|
2022-10-08 16:49:45 +02:00
|
|
|
var elem = document.getElementById(id);
|
|
|
|
if (child>-1){
|
|
|
|
elem = elem.children[child];
|
|
|
|
}
|
|
|
|
var att = document.createAttribute(attr);
|
|
|
|
att.value = val;
|
|
|
|
elem.setAttributeNode(att);
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-10-08 16:49:45 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function add_HTML_element(type, attr, meta=0, j=0){
|
|
|
|
// Add HTML element with type 'type' and attributes 'attr'.
|
|
|
|
// 'attr' should be a javascript object
|
|
|
|
// 'meta' should be an array
|
|
|
|
// 'j' is used to pass an increment value when used in a loop
|
|
|
|
//
|
2022-11-12 18:17:25 +01:00
|
|
|
var elem = document.createElement(type);
|
|
|
|
var keys_array = Object.keys(attr);
|
|
|
|
for (i=0, l=keys_array.length;i<l;i++) {
|
|
|
|
var att = document.createAttribute(keys_array[i]);
|
2022-11-25 19:46:41 +01:00
|
|
|
// First iteration
|
2022-11-12 18:17:25 +01:00
|
|
|
if(!i){
|
|
|
|
att.value = Object.values(attr)[i]+j;
|
|
|
|
} else {
|
|
|
|
att.value = Object.values(attr)[i];
|
|
|
|
}
|
|
|
|
elem.setAttributeNode(att);
|
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
// Set media_id attribute if metadata is provided
|
2022-11-12 18:17:25 +01:00
|
|
|
if (meta) {
|
2022-11-25 19:46:41 +01:00
|
|
|
attribute = document.createAttribute("media_id");
|
|
|
|
attribute.value = meta[0];
|
|
|
|
elem.setAttributeNode(attribute);
|
2022-10-06 20:08:04 +02:00
|
|
|
}
|
2022-11-12 18:17:25 +01:00
|
|
|
// Get filename
|
|
|
|
elem.innerText = meta[1];
|
|
|
|
return elem;
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-10-06 11:44:59 +02:00
|
|
|
// Bouttons de commande
|
|
|
|
addEventListener("DOMContentLoaded", function() {
|
2022-11-25 19:46:41 +01:00
|
|
|
//~ send_ajax_cmd("/scan");
|
|
|
|
//~ send_ajax_cmd("/browse_local");
|
|
|
|
//~ setTimeout(send_ajax_cmd, 3000, "/all/browse");
|
|
|
|
//~ setTimeout(send_ajax_cmd, 4000, "/all/rssi");
|
|
|
|
//~ setTimeout(send_ajax_cmd, 1000, "/all/list");
|
|
|
|
adjust_timeline();
|
|
|
|
|
|
|
|
// Get all elements with class 'command'
|
2022-10-06 11:44:59 +02:00
|
|
|
var commandButtons = document.querySelectorAll(".command");
|
|
|
|
for (var i=0, l=commandButtons.length; i<l; i++) {
|
|
|
|
var button = commandButtons[i];
|
2022-11-25 19:46:41 +01:00
|
|
|
// Listen for clicks
|
2022-10-06 11:44:59 +02:00
|
|
|
button.addEventListener("click", function(event) {
|
2022-11-25 19:46:41 +01:00
|
|
|
// Discard signal
|
2022-10-06 11:44:59 +02:00
|
|
|
event.preventDefault();
|
2022-11-25 19:46:41 +01:00
|
|
|
// Get value=""
|
2022-10-06 11:44:59 +02:00
|
|
|
var clickedButton = event.currentTarget;
|
|
|
|
var command = clickedButton.value;
|
2022-11-25 19:46:41 +01:00
|
|
|
// Proceed accordingly
|
2022-10-18 19:54:18 +02:00
|
|
|
if ( command.indexOf("/reboot" ) > -1 || command.indexOf("/poweroff") > -1 ) {
|
2022-10-06 11:44:59 +02:00
|
|
|
if ( !confirm("Êtes vous certain de vouloir effectuer cette action ?") ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
|
2022-10-06 11:44:59 +02:00
|
|
|
} else if ( command == "/scan" ) {
|
2022-11-12 18:17:25 +01:00
|
|
|
document.getElementById("status_all").innerHTML = status_all;
|
|
|
|
|
2022-10-06 11:44:59 +02:00
|
|
|
} else if ( command.indexOf("/sort") > -1 ){
|
|
|
|
if (command.indexOf('/1/') > -1 ) {
|
2022-11-25 19:46:41 +01:00
|
|
|
clickedButton.value = clickedButton.value.replace('/1/','/0/');
|
2022-10-06 11:44:59 +02:00
|
|
|
} else {
|
2022-11-25 19:46:41 +01:00
|
|
|
clickedButton.value = clickedButton.value.replace('/0/','/1/');
|
2022-10-06 11:44:59 +02:00
|
|
|
}
|
2022-11-12 18:17:25 +01:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-10-06 11:44:59 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
// AJAX request
|
2022-10-06 11:44:59 +02:00
|
|
|
var request = new XMLHttpRequest();
|
2022-11-25 19:46:41 +01:00
|
|
|
if ( command == "/scan") {
|
|
|
|
request.onload = send_ajax_cmd(command);
|
|
|
|
} else if ( command.indexOf("/clear") > -1 || command.indexOf("/sort") > -1) {
|
|
|
|
request.onload = send_ajax_cmd(command);
|
2022-11-12 18:17:25 +01:00
|
|
|
} else if ( command == "/sync/all" ) {
|
2022-11-25 19:46:41 +01:00
|
|
|
status_all = "Syncing files...";
|
|
|
|
request.onload = send_ajax_cmd("/sync/status");
|
|
|
|
}
|
2022-11-12 18:17:25 +01:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
// build request
|
2022-10-06 11:44:59 +02:00
|
|
|
request.open("GET", command, true);
|
2022-11-25 19:46:41 +01:00
|
|
|
// send request
|
2022-10-06 11:44:59 +02:00
|
|
|
request.send();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, true);
|
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
// Metadata display
|
|
|
|
function parse_result(command, infos_array) {
|
|
|
|
if (command == "/all/status") {
|
|
|
|
// Requests current status of every instances, especially current media file's name, position and length.
|
|
|
|
// Also retrieves loop and repeat status.
|
|
|
|
//
|
2022-10-06 20:08:04 +02:00
|
|
|
// Iterate over array
|
|
|
|
for (var i = 0, l=infos_array.length; i<l; i++) {
|
2022-10-08 16:49:45 +02:00
|
|
|
// Get filename, time/length
|
2022-11-07 13:28:06 +01:00
|
|
|
if (infos_array[i].status) {
|
|
|
|
document.getElementById("status_"+infos_array[i].host).innerHTML = infos_array[i].file + " <br/> " + infos_array[i].time + " / " + infos_array[i].leng;
|
|
|
|
medias_status[infos_array[i].id] = infos_array[i].pos;
|
2022-11-25 19:46:41 +01:00
|
|
|
|
|
|
|
// Highlight currently playing element
|
|
|
|
timeline_medias_array = Array.from(document.querySelectorAll('[media_id]'));
|
|
|
|
for (var z=0, x=timeline_medias_array.length; z<x;z++){
|
|
|
|
if ( timeline_medias_array[z].getAttribute("media_id") == infos_array[i].id ) {
|
|
|
|
var pos = infos_array[i].pos * 100;
|
|
|
|
var pos1 = pos-1 + "%";
|
|
|
|
pos = pos + "%";
|
|
|
|
var media_url_str = "url(https://" + infos_array[i].host + ":" + cmd_port + "/thumb/" + infos_array[i].file + ")"
|
|
|
|
var media_cssgrad_rule = "linear-gradient(90deg," + timeline_color_bg + " " + pos1 + ", " + timeline_color_cursor + " " + pos + ", " + timeline_color_bg + " " + pos + ")," + media_url_str;
|
|
|
|
timeline_medias_array[z].style.backgroundImage = media_cssgrad_rule;
|
|
|
|
timeline_medias_array[z].style.borderBottom = "4px solid " + timeline_color_cursor;
|
|
|
|
} else {
|
|
|
|
var media_url_str = "url(https://" + infos_array[i].host + ":" + cmd_port + "/thumb/" + timeline_medias_array[z].innerText + ")"
|
|
|
|
timeline_medias_array[z].style.backgroundImage = media_url_str;
|
|
|
|
timeline_medias_array[z].style.borderBottom = "None";
|
|
|
|
}
|
|
|
|
}
|
2022-11-15 17:00:36 +01:00
|
|
|
} else {
|
|
|
|
document.getElementById("status_"+infos_array[i].host).innerHTML = "<br><br>";
|
2022-11-07 13:28:06 +01:00
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
// Toggle loop indicator
|
2022-10-08 16:49:45 +02:00
|
|
|
if (infos_array[i].loop == "true") {
|
2022-11-25 19:46:41 +01:00
|
|
|
document.getElementById("loop_ind_" + infos_array[i].host).style.backgroundColor = "#78E738";
|
2022-10-08 16:49:45 +02:00
|
|
|
} else {
|
2022-11-25 19:46:41 +01:00
|
|
|
document.getElementById("loop_ind_" + infos_array[i].host).style.backgroundColor = "#A42000";
|
|
|
|
}
|
2022-10-08 16:49:45 +02:00
|
|
|
// Toggle repeat indicator
|
|
|
|
if (infos_array[i].repeat == "true") {
|
2022-11-25 19:46:41 +01:00
|
|
|
document.getElementById("repeat_ind_" + infos_array[i].host).style.backgroundColor = "#78E738";
|
2022-10-08 16:49:45 +02:00
|
|
|
} else {
|
2022-11-25 19:46:41 +01:00
|
|
|
document.getElementById("repeat_ind_" + infos_array[i].host).style.backgroundColor = "#A42000";
|
2022-10-18 19:54:18 +02:00
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
|
|
|
} else if ( command.indexOf("/list") > -1 ) {
|
|
|
|
// Requests playlist of every instances
|
|
|
|
//
|
|
|
|
if (!freeze_timeline_update){
|
|
|
|
console.log("Timeline freeze : " + freeze_timeline_update);
|
|
|
|
console.log("Infos array : " + infos_array);
|
|
|
|
for (var i = 0, l=infos_array.length; i<l; i++) {
|
|
|
|
// Playlist infos are displayed in a div ; number of items in list and total duration.
|
|
|
|
//~ document.getElementById("playlist_"+infos_array[i].host).innerHTML = infos_array[i].leng + " item(s) in playlist - " + infos_array[i].duration;
|
|
|
|
// Populate timeline according to the content of the playlist
|
|
|
|
// Get returned items as an array
|
|
|
|
var items_array = Array.from(infos_array[i].items);
|
|
|
|
//console.log(items_array.length);
|
|
|
|
// If playlist is empty, remove all media divs in the timeline UI.
|
|
|
|
if (items_array.length == 0){
|
|
|
|
var child_list = Array.from(document.getElementById("timeline_" + infos_array[i].host).children);
|
|
|
|
for(x=0,y=child_list.length;x<y;x++){
|
|
|
|
document.getElementById("timeline_" + infos_array[i].host).removeChild(child_list[x]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (var j = 0, k=items_array.length; j<k; j++) {
|
|
|
|
// Timeline
|
|
|
|
item_meta = items_array[j].split(';');
|
|
|
|
var child_node = add_HTML_element("div", tl_drag_attr, item_meta, j);
|
|
|
|
var len = document.getElementById("timeline_" + infos_array[i].host).children.length;
|
|
|
|
add_HTML_attr("timeline_" + infos_array[i].host, "length", len);
|
|
|
|
if ( len < items_array.length ) {
|
|
|
|
document.getElementById("timeline_" + infos_array[i].host).appendChild( add_HTML_element("div", tl_cont_attr, 0, len) );
|
|
|
|
}
|
|
|
|
document.getElementById(tl_cont_attr.id + j).replaceChildren(child_node);
|
|
|
|
var media_name = document.getElementById(tl_cont_attr.id + j).children[0].innerText;
|
|
|
|
var media_url_str = "url(https://" + infos_array[i].host + ":" + cmd_port + "/thumb/" + media_name + ")"
|
|
|
|
document.getElementById(tl_cont_attr.id + j).children[0].style.backgroundImage = media_url_str;
|
|
|
|
// Adjust elements width
|
|
|
|
adjust_timeline();
|
2022-10-06 20:08:04 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
|
|
|
} else if ( command == "/scan") {
|
2022-10-06 20:08:04 +02:00
|
|
|
var host_up = infos_array[0];
|
|
|
|
var host_down = infos_array[1];
|
|
|
|
for ( var i=0, l=host_up.length; i<l; i++){
|
2022-10-08 16:49:45 +02:00
|
|
|
document.getElementById(host_up[i]).style.display = 'block';
|
2022-10-06 20:08:04 +02:00
|
|
|
}
|
|
|
|
for ( var i=0, l=host_down.length; i<l; i++){
|
|
|
|
document.getElementById(host_down[i]).style.display = 'none';
|
|
|
|
}
|
2022-10-25 12:53:05 +02:00
|
|
|
if (host_up.length) {
|
2022-11-25 19:46:41 +01:00
|
|
|
scan_interval = 10000;
|
|
|
|
//~ document.getElementById("status_all").innerHTML = "Scan interval set to " + scan_interval;
|
|
|
|
status_all = "Scan interval set to " + scan_interval;
|
2022-10-25 12:53:05 +02:00
|
|
|
}
|
2022-11-12 18:17:25 +01:00
|
|
|
//~ document.getElementById("status_all").innerHTML = host_up.length + " client(s).";
|
|
|
|
status_all = host_up.length + " client(s).";
|
2022-11-25 19:46:41 +01:00
|
|
|
} else if ( command == "/browse_local") {
|
|
|
|
// Display local media files in a table
|
2022-10-06 20:08:04 +02:00
|
|
|
var html_table = "<table>" +
|
|
|
|
"<tr>" +
|
|
|
|
"<th>Filename</th>" +
|
|
|
|
"<th>Duration</th>" +
|
|
|
|
"</tr>";
|
|
|
|
for (var j = 0, k=infos_array.length; j<k; j++) {
|
|
|
|
html_table += "<tr>" +
|
|
|
|
"<td>" + infos_array[j] + "</td>" +
|
|
|
|
"<td>" + "00:00" + "</td>" +
|
|
|
|
"</tr>" ;
|
|
|
|
}
|
|
|
|
html_table += "</table>";
|
2022-11-03 12:48:12 +01:00
|
|
|
document.getElementById("filelist").innerHTML = html_table;
|
2022-11-25 19:46:41 +01:00
|
|
|
} else if ( command == "/all/rssi") {
|
|
|
|
// RSSI strength indicator
|
2022-10-06 20:08:04 +02:00
|
|
|
var signal_color = 40;
|
|
|
|
var best_rssi = 30;
|
|
|
|
var worst_rssi = 70;
|
|
|
|
for (var j = 0, k=infos_array.length; j<k; j++) {
|
|
|
|
var rssi_norm = Math.ceil( (worst_rssi - parseInt(infos_array[j].rssi) ) / ( worst_rssi - best_rssi ) * 4 );
|
|
|
|
signal_color = (rssi_norm-1) * signal_color;
|
|
|
|
// Reset to grey
|
|
|
|
for (i=0, l=4; i<l;i++) {
|
|
|
|
document.getElementById("wl_"+i).style.backgroundColor = "hsl(0, 0%, 65%)";
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-10-06 20:08:04 +02:00
|
|
|
// Color it
|
2022-11-07 13:28:06 +01:00
|
|
|
for (i=0, l=rssi_norm>4?4:rssi_norm; i<l;i++) {
|
2022-10-06 20:08:04 +02:00
|
|
|
document.getElementById("wl_"+i).style.backgroundColor = "hsl(" + signal_color + ", 100%, 50%)";
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( command == "/all/browse") {
|
|
|
|
// Display remote media files in a table
|
2022-11-12 18:17:25 +01:00
|
|
|
for (var i=0, l=infos_array.length; i<l; i++) {
|
|
|
|
hosts = Object.keys(infos_array[i]);
|
|
|
|
//~ console.log(keys);
|
|
|
|
for ( var j=0, k=hosts.length;j<k;j++ ) {
|
|
|
|
keys_ = Object.keys(infos_array[i][hosts[j]]);
|
|
|
|
//~ console.log(infos_array[i][hosts[j]]);
|
|
|
|
for ( var m=0, n=keys_.length;m<n;m++ ) {
|
|
|
|
item_meta = infos_array[i][hosts[j]][keys_[m]];
|
|
|
|
//~ console.log(item_meta);
|
|
|
|
tr = document.createElement("tr");
|
|
|
|
td = document.createElement("td");
|
|
|
|
tr.appendChild(td);
|
|
|
|
tr.setAttribute("class", "file_selection");
|
|
|
|
tr.host = hosts[j];
|
2022-11-25 19:46:41 +01:00
|
|
|
td.innerText = item_meta.name;
|
|
|
|
// Add an event to the created element to send enqueue command when a file is clicked in the list
|
|
|
|
tr.addEventListener("click", enqueue_file, false);
|
2022-11-12 18:17:25 +01:00
|
|
|
document.getElementById("file_sel_"+hosts).appendChild(tr);
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-11-12 18:17:25 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-25 19:46:41 +01:00
|
|
|
} else if ( command == "/sync/status") {
|
2022-11-12 18:17:25 +01:00
|
|
|
status_all = infos_array;
|
2022-11-25 19:46:41 +01:00
|
|
|
} else {
|
|
|
|
setTimeout(send_ajax_cmd, 80, "/all/list");
|
|
|
|
setTimeout(send_ajax_cmd, 120, "/all/status");
|
|
|
|
}
|
|
|
|
}
|
2022-10-06 11:44:59 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function send_ajax_cmd(command) {
|
2022-10-06 11:44:59 +02:00
|
|
|
var request = new XMLHttpRequest();
|
|
|
|
request.onload = function() {
|
|
|
|
if (request.readyState === request.DONE) {
|
|
|
|
if (request.status === 200) {
|
|
|
|
// responseText is a string, use parse to get an array.
|
2022-11-25 19:46:41 +01:00
|
|
|
if (!freeze_timeline_update) {
|
|
|
|
var infos_array = JSON.parse(request.responseText);
|
|
|
|
//console.log(infos_array.length);
|
|
|
|
parse_result(command, infos_array);
|
|
|
|
//return infos_array;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-06 11:44:59 +02:00
|
|
|
};
|
|
|
|
// On construit la commande
|
|
|
|
request.open("GET", command, true);
|
|
|
|
// et on l'envoie
|
|
|
|
request.send();
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
2022-10-06 20:08:04 +02:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function enqueue_file(evt) {
|
2022-11-12 18:17:25 +01:00
|
|
|
//console.log(evt.currentTarget.innerText + evt.currentTarget.host);
|
2022-11-25 19:46:41 +01:00
|
|
|
send_ajax_cmd("/" + evt.currentTarget.host + "/enqueue/" + evt.currentTarget.innerText);
|
|
|
|
//~ send_ajax_cmd("/all/list");
|
|
|
|
setTimeout(send_ajax_cmd, 40, "/" + evt.currentTarget.host + "/list");
|
|
|
|
//~ send_ajax_cmd("/" + evt.currentTarget.host + "/list");
|
|
|
|
}
|
2022-11-12 18:17:25 +01:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
function update_statusall_content() {
|
2022-11-12 18:17:25 +01:00
|
|
|
document.getElementById("status_all").innerHTML = status_all;
|
2022-11-25 19:46:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var scan_hosts = function() {
|
|
|
|
send_ajax_cmd("/scan");
|
|
|
|
update_statusall_content();
|
|
|
|
setTimeout(scan_hosts, scan_interval);
|
|
|
|
}
|
2022-11-12 18:17:25 +01:00
|
|
|
|
2022-11-25 19:46:41 +01:00
|
|
|
send_ajax_cmd("/scan");
|
|
|
|
send_ajax_cmd("/browse_local");
|
|
|
|
setInterval(send_ajax_cmd, 500, "/all/status");
|
|
|
|
setTimeout(send_ajax_cmd, 1000, "/all/list");
|
|
|
|
setTimeout(send_ajax_cmd, 3000, "/all/browse");
|
|
|
|
setInterval(send_ajax_cmd, 20000, "/all/rssi");
|
|
|
|
//~ setInterval(update_statusall_content, 1000);
|
|
|
|
setTimeout(scan_hosts, scan_interval);
|
2022-11-12 18:17:25 +01:00
|
|
|
|
2022-10-06 11:44:59 +02:00
|
|
|
|