-
Notifications
You must be signed in to change notification settings - Fork 676
/
Copy pathcommon.js
145 lines (122 loc) · 4.13 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* The UI can also be run locally, but you have to set the IP of your devide accordingly.
* And you also might have to disable CORS in your webbrowser!
* Keep empty to disable using it. Enabling it will break access through a forwared port, see
* https://github.com/jomjol/AI-on-the-edge-device/issues/2681 */
var domainname_for_testing = "";
//var domainname_for_testing = "192.168.1.151";
/* Returns the domainname with prepended protocol.
Eg. http://watermeter.fritz.box or http://192.168.1.5 */
function getDomainname(){
var host = window.location.hostname;
if (domainname_for_testing != "") {
console.log("Using pre-defined domainname for testing: " + domainname_for_testing);
domainname = "http://" + domainname_for_testing
}
else
{
domainname = window.location.protocol + "//" + host;
if (window.location.port != "") {
domainname = domainname + ":" + window.location.port;
}
}
return domainname;
}
function UpdatePage(_dosession = true){
var zw = location.href;
zw = zw.substr(0, zw.indexOf("?"));
if (_dosession) {
window.location = zw + '?session=' + Math.floor((Math.random() * 1000000) + 1);
}
else {
window.location = zw;
}
}
function LoadHostname() {
_domainname = getDomainname();
var xhttp = new XMLHttpRequest();
xhttp.addEventListener('load', function(event) {
if (xhttp.status >= 200 && xhttp.status < 300) {
hostname = xhttp.responseText;
document.title = hostname + " - AI on the edge";
document.getElementById("id_title").innerHTML = "Digitizer - AI on the edge - " + hostname;
}
else {
console.warn(request.statusText, request.responseText);
}
});
// var xhttp = new XMLHttpRequest();
try {
url = _domainname + '/info?type=Hostname';
xhttp.open("GET", url, true);
xhttp.send();
}
catch (error)
{
// alert("Loading Hostname failed");
}
}
var fwVersion = "";
var webUiVersion = "";
function LoadFwVersion() {
_domainname = getDomainname();
var xhttp = new XMLHttpRequest();
xhttp.addEventListener('load', function(event) {
if (xhttp.status >= 200 && xhttp.status < 300) {
fwVersion = xhttp.responseText;
document.getElementById("Version").innerHTML = fwVersion;
console.log(fwVersion);
compareVersions();
}
else {
console.warn(request.statusText, request.responseText);
fwVersion = "NaN";
}
});
try {
url = _domainname + '/info?type=FirmwareVersion';
xhttp.open("GET", url, true);
xhttp.send();
}
catch (error) {
fwVersion = "NaN";
}
}
function LoadWebUiVersion() {
_domainname = getDomainname();
var xhttp = new XMLHttpRequest();
xhttp.addEventListener('load', function(event) {
if (xhttp.status >= 200 && xhttp.status < 300) {
webUiVersion = xhttp.responseText;
console.log("Web UI Version: " + webUiVersion);
compareVersions();
}
else {
console.warn(request.statusText, request.responseText);
webUiVersion = "NaN";
}
});
try {
url = _domainname + '/info?type=HTMLVersion';
console.log("url");
xhttp.open("GET", url, true);
xhttp.send();
}
catch (error) {
webUiVersion = "NaN";
}
}
function compareVersions() {
if (fwVersion == "" || webUiVersion == "") {
return;
}
arr = fwVersion.split(" ");
fWGitHash = arr[arr.length - 1].substring(0, 7);
arr = webUiVersion.split(" ");
webUiHash = arr[arr.length - 1].substring(0, 7);
console.log("FW Hash: " + fWGitHash + ", Web UI Hash: " + webUiHash);
if (fWGitHash != webUiHash) {
firework.launch("The version of the web interface (" + webUiHash +
") does not match the firmware version (" +
fWGitHash + ")! It is suggested to keep them on the same version!", 'warning', 30000);
}
}