Skip to content

Commit

Permalink
Fix dhcp not checked
Browse files Browse the repository at this point in the history
use /getStation and /getStationsFrom commands with websocket for
downloading stations
Timezone has number type
  • Loading branch information
bazooka07 committed Jan 29, 2020
1 parent 3d79568 commit 23f0e6e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 22 deletions.
80 changes: 65 additions & 15 deletions assets/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var instantPlaying = false;
var saveAsText = null;
var currentStationId = null;
var isConnected = false;
var wsPrior = false;
var wsVersion = -1;

var isLoading = false; // displayed webradios are not saving in the Ka-Radio device if true

Expand Down Expand Up @@ -302,6 +302,9 @@ function openSocket() {
if (websocket != null) {
websocket.onopen = function (event) {
console.log(this.url + ' opened');
if(wsVersion > 0) {
loadStationsList();
}
}

websocket.onmessage = function (event) {
Expand All @@ -321,6 +324,32 @@ function openSocket() {
}
return;
}
if('stations' in msg && typeof msg.stations.forEach != 'undefined') {
if(msg.stations.length > 0) {
let i = 0;
msg.stations.forEach(function(item) {
console.log(item);
addStation(item.station, item);
progressBar.value = i;
if(i<item.station) {
i = item.station;
}
});
i++;
if(i<MAX_STATIONS) {
if(wsVersion >= 2) {
this.send('getStationsFrom=' + i);
} else {
this.send('getStation=' + i);
}
} else {
stationsBtn.disabled = false;
}
} else {
progressBar.value = MAX_STATIONS;
}
return;
}
if(!'wsrssi' in msg) {
console.log('websocket:', msg);
}
Expand Down Expand Up @@ -354,11 +383,6 @@ function openSocket() {
if (caption != null) {
caption.textContent = msg.monitor;
}

if(stationsList != null && stationsList.rows.length == 0) {
wsPrior = ('curst' in msg);
loadStationsList();
}
return;
}

Expand Down Expand Up @@ -505,7 +529,7 @@ function addStation(stationId, datas) {
let newStation = (stationId == null || stationId.length === 0);
if (newStation) {
let rows = stationsList.rows;
stationId = 0;
stationId = -1;
// searches the max value for stationId
for (let i = 0, iMax = rows.length; i < iMax; i++) {
if (rows[i].id.startsWith('station-')) {
Expand All @@ -530,8 +554,10 @@ function addStation(stationId, datas) {
}
}
datas.fullUrl = datas.URL + port + datas.File;
/*
} else {
datas.fullUrl = '';
* */
}

let tr = document.createElement('TR');
Expand Down Expand Up @@ -717,7 +743,7 @@ xhr.wifi = function (valid) {
const el = elements.namedItem(field + col);
if(field == 'dhcp') {
dhcp = el.checked; // type="checkbox"
const value = (dhcp) ? 'true' : ''; // Hack against Ka-Radio
const value = (dhcp) ? 'true' : 'false'; // Hack against Ka-Radio
params.push('dhcp' + col + '=' + value);
} else {
params.push(el.name + '=' + el.value);
Expand Down Expand Up @@ -778,8 +804,9 @@ xhr.onreadystatechange = function () {
}

if(this.getResponseHeader('Content-Type').startsWith('text/plain')) {
const PATTERN = /^release\b.*?(\d+)\.(\d+).*?(\d+).*/i;
const PATTERN = /^release\b.*?(\d+)\.(\d+).*?(\d+)(.*)/i;
if(PATTERN.test(this.responseText)) {
console.log('Version inside the ESP32 : ', this.responseText); // = version. Don't comment !!!
const el = document.getElementById('version');
el.textContent = this.responseText.trim().replace(PATTERN, 'Ver. $1.$2.$3');

Expand All @@ -789,7 +816,14 @@ xhr.onreadystatechange = function () {
displayCurrentStation();
displayHardware();
setRssiInterval();
// loadStationsList(); look at : websocket.send('wsmonitor')
const suffixe = this.responseText.trim().replace(PATTERN, '$4');
if(suffixe.length == 0) {
wsVersion = -1;
loadStationsList();
} else {
// use websocket for downloading the playlist quickly
wsVersion = suffixe.replace(/.*\b(\d+)\b.*/, '$1');
}
return;
}
console.error('Unattented response from '+ this.responseURL, this.responseText);
Expand Down Expand Up @@ -947,10 +981,15 @@ function loadStationsList() {
stationsList.innerHTML = '';
stationsSelect.innerHTML = '';
progressBar.max = MAX_STATIONS;
if(wsPrior) {
websocket.send('getStation=0');
} else {
xhrSta.loadStation(0);
switch(wsVersion) {
case '1' :
websocket.send('getStation=0');
break;
case '2' :
websocket.send('getStationsFrom=0');
break;
default:
xhrSta.loadStation(0);
}
}

Expand Down Expand Up @@ -1053,20 +1092,31 @@ function saveStationsList(changedOnly) {

// Push stations with empty url at the end of the list
let j = -1;
let id = 0;
const buf = new Array();
for(let i=stationsList.rows.length - 2; i>=0; i--) {
const row = stationsList.rows[i];
const url = row.cells[2].textContent.trim();
if(url.length == 0) {
buf.push(row);
stationsList.removeChild(row);
stationsList.appendChild(row);
j = i;
id = parseInt(row.id.replace(/.*-(\d+)/, '$1'));
}
}
if(buf.length > 0) {
for(let i=0, iMax = buf.length; i<iMax; i++) {
stationsList.appendChild(buf[i]);
}
}

if(changedOnly) {
if(j>=0) {
for(let i=j, iMax=stationsList.rows.length; i<iMax; i++) {
stationsList.rows[i].classList.add('has-changed');
stationsList.rows[i].cells[0].textContent = id;
stationsList.rows[i].id = 'station-' + id;
id++;
}
}
xhrPlaylistSave.saveStation();
Expand Down
15 changes: 8 additions & 7 deletions extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" >
<meta name="apple-mobile-web-app-status-bar-style" content="default" >
<link rel="apple-touch-icon" type="image/png" href="logo.png" >
<meta name="application-name" content="Ka-Radio32" />
<meta name="keywords" content="esp32,vs-1053,webradio,ka-radio32" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<link rel="apple-touch-icon" type="image/png" href="logo.png" />
<link rel="icon" type="image/png" href="favicon.png" />
<link type="text/css" rel="stylesheet" title="base" href="https://bazooka07.github.io/Ka-Radio32/assets/extensions.css" />
<!-- link type="text/css" rel="stylesheet" title="base" href="assets/extensions.css" / -->
<title>Karadio, the ultimate Wifi Webradio</title>
</head><body>
<header class="no-print" id="header">
<div title="Click on the logo to change the theme">
<div>
<img id="logo" alt="Ka-Radio" src="logo.png" />
</div><div id="icy-meta" class="center no-print">
Ka-Radio
Expand Down Expand Up @@ -177,7 +178,7 @@ <h2>Output audio & reboot</h2>
<span id="treble_span">0 dB</span>
<span>Treble freq.</span>
<input type="range" id="icy-tfreq" name="treblefreq" min="1" max="15" class="no-cursor" />
<span id="treblefreq_span">0 Hz</span>
<span id="treblefreq_span">0 KHz</span>
<span>Spacial</span>
<div>
<input type="radio" id="id_spacial0" name="spacial" value="0" checked /><label for="id_spacial0">Off</label>
Expand Down Expand Up @@ -229,7 +230,7 @@ <h2>Wifi & Network</h2>
<span>Hostname</span>
<input name="host" />
<span>Time zone</span>
<input name="tzo" />
<input type="number" name="tzo" min="-12" max="13" step="1" />
</div>
</fieldset>
</div>
Expand Down

0 comments on commit 23f0e6e

Please sign in to comment.