Fix more behaviors view
This commit is contained in:
1 parent
f6462f05b8
commit
acb58142d9
4 files changed
+87
-20
No files matched your search
+60
-15
@@ -20,15 +20,24 @@ QtObject {
|
||||
currentServer = { name: server.name, address: server.address };
|
||||
}
|
||||
|
||||
// Ajoute (ou retrouve) un serveur à partir de l'adresse saisie.
|
||||
// TODO API : valider via GET <adresse>/System/Info/Public et utiliser ServerName.
|
||||
function connectToServer(rawAddress, callback) {
|
||||
var address = normalizeAddress(rawAddress);
|
||||
if (address === "") {
|
||||
// Ajoute (ou retrouve) un serveur à partir de l'hôte saisi et d'un port facultatif.
|
||||
// Le clavier de la box n'a ni « : » ni « / » : le protocole et le port sont
|
||||
// détectés en essayant chaque adresse de serverCandidates() dans l'ordre.
|
||||
function connectToServer(host, port, callback) {
|
||||
if ((host || "").trim() === "") {
|
||||
callback("Veuillez saisir l'adresse du serveur.");
|
||||
return;
|
||||
}
|
||||
_simulate(function () {
|
||||
var portText = (port || "").trim();
|
||||
if (portText !== "" && !isValidPort(portText)) {
|
||||
callback("Le port doit être un nombre entre 1 et 65535.");
|
||||
return;
|
||||
}
|
||||
_probeCandidates(serverCandidates(host, portText), 0, function (err, address) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
var index = _indexOfServer(address);
|
||||
if (index < 0) {
|
||||
servers.insert(0, { name: _hostOf(address), address: address, discovered: false });
|
||||
@@ -39,6 +48,51 @@ QtObject {
|
||||
});
|
||||
}
|
||||
|
||||
// Adresses à essayer, de la plus probable à la moins probable
|
||||
// (même logique que les clients Jellyfin officiels).
|
||||
function serverCandidates(host, port) {
|
||||
var text = (host || "").trim().replace(/\/+$/, "");
|
||||
if (text === "")
|
||||
return [];
|
||||
// Adresse complète (saisie depuis un clavier qui a « : ») : utilisée telle quelle.
|
||||
if (/^https?:\/\//i.test(text)) {
|
||||
if (port && !/:\d+$/.test(text.replace(/^https?:\/\//i, "")))
|
||||
text += ":" + port;
|
||||
return [text];
|
||||
}
|
||||
if (port)
|
||||
return ["https://" + text + ":" + port, "http://" + text + ":" + port];
|
||||
// Port déjà inclus dans l'hôte (ex. 192.168.1.20:8096).
|
||||
if (/:\d+$/.test(text))
|
||||
return ["https://" + text, "http://" + text];
|
||||
return [
|
||||
"https://" + text,
|
||||
"http://" + text + ":8096",
|
||||
"https://" + text + ":8920",
|
||||
"http://" + text
|
||||
];
|
||||
}
|
||||
|
||||
// Essaie les adresses une par une ; renvoie la première qui répond.
|
||||
// TODO API : GET <adresse>/System/Info/Public, accepter si la réponse contient un Id,
|
||||
// et utiliser ServerName comme nom. Simulation : la première adresse « répond ».
|
||||
function _probeCandidates(candidates, index, callback) {
|
||||
if (index >= candidates.length) {
|
||||
callback("Aucun serveur Jellyfin trouvé à cette adresse.");
|
||||
return;
|
||||
}
|
||||
_simulate(function () {
|
||||
callback(null, candidates[index]);
|
||||
});
|
||||
}
|
||||
|
||||
function isValidPort(text) {
|
||||
if (!/^\d+$/.test(text))
|
||||
return false;
|
||||
var value = parseInt(text, 10);
|
||||
return value >= 1 && value <= 65535;
|
||||
}
|
||||
|
||||
// TODO API : GET /Users/Public
|
||||
function publicUsers() {
|
||||
return [
|
||||
@@ -78,15 +132,6 @@ QtObject {
|
||||
_latency.stop();
|
||||
}
|
||||
|
||||
function normalizeAddress(text) {
|
||||
var address = (text || "").trim();
|
||||
if (address === "")
|
||||
return "";
|
||||
if (!/^https?:\/\//i.test(address))
|
||||
address = "http://" + address;
|
||||
return address.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
function _hostOf(address) {
|
||||
return address.replace(/^https?:\/\//i, "").split(/[:\/]/)[0];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user