Failower attempt when radio servers are unstable
This commit is contained in:
parent
483b8da4e8
commit
3c7f0bd111
@ -20,6 +20,7 @@ Item {
|
||||
property string _useragent: "AllRadio/2.0.0 (test) (SailfishOS; Linux) nesnomis@gmail.com"
|
||||
property int _tags: 0
|
||||
property int _countries: 0
|
||||
property int _c: 0
|
||||
// Properties to be used in application -------------------------------------------------
|
||||
property ListModel serversModel : ListModel { id: serversModel }
|
||||
property ListModel votedModel : ListModel {id: votedModel}
|
||||
@ -34,9 +35,44 @@ Item {
|
||||
//property int viewTagCount: tagsModel.maxCount
|
||||
property int countryCount: 0
|
||||
property bool loading: stationCount !== 0 && tagCount !== 0 && countryCount !== 0 ? false : true
|
||||
property string lookup: "http://all.api.radio-browser.info/json/servers"
|
||||
|
||||
property int serverIndex: 0
|
||||
property int connectIndex: -1
|
||||
property string lookup: sModel.get(serverIndex).url //"http://fi2.api.radio-browser.info/json/servers"
|
||||
// ---------------------------------------------------------------------------------------
|
||||
Timer {
|
||||
id: sTimer
|
||||
interval: 2000; running: false; repeat: false
|
||||
onTriggered: {
|
||||
if (serverIndex < sModel.count-1) serverIndex = serverIndex + 1; else serverIndex = 0
|
||||
getList()
|
||||
}
|
||||
}
|
||||
//onServerIndexChanged: console.log(" ******* LOOKUP ******** ")+serverIndex
|
||||
|
||||
ListModel {
|
||||
id: sModel
|
||||
|
||||
ListElement {
|
||||
name: "all.api.radio-browser.info"
|
||||
url: "http://all.api.radio-browser.info/json/servers"
|
||||
}
|
||||
ListElement {
|
||||
name: "de1.api.radio-browser.info"
|
||||
url: "http://de1.api.radio-browser.info/json/servers"
|
||||
}
|
||||
ListElement {
|
||||
name: "de2.api.radio-browser.info"
|
||||
url: "http://de2.api.radio-browser.info/json/servers"
|
||||
}
|
||||
ListElement {
|
||||
name: "fi1.api.radio-browser.info"
|
||||
url: "http://fi1.api.radio-browser.info/json/servers"
|
||||
}
|
||||
ListElement {
|
||||
name: "fi3.api.radio-browser.info"
|
||||
url: "http://fi3.api.radio-browser.info/json/servers"
|
||||
}
|
||||
}
|
||||
|
||||
onOnlineChanged: {
|
||||
if (online && serverUrl !== "") {
|
||||
@ -54,12 +90,12 @@ Item {
|
||||
} */
|
||||
|
||||
// Choose a random server from available servers
|
||||
function getRandom() {
|
||||
function getRandom(url) {
|
||||
if (serversModel.count > 0) {
|
||||
var random = Math.floor((Math.random() * serversModel.count) + 1) - 1
|
||||
serverUrl = serversModel.get(random).serverUrl
|
||||
server = serversModel.get(random).server
|
||||
if (serverUrl.length > 7) getStats(); else getRandom();
|
||||
if (serverUrl.length > 7 && url !== serverUrl) {sTimer.running=false;getStats();} else getRandom();
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,14 +104,24 @@ Item {
|
||||
var req = new XMLHttpRequest();
|
||||
req.onreadystatechange = function () {
|
||||
if (req.readyState === 4 && req.status < 300) {
|
||||
|
||||
var obj = JSON.parse(req.responseText)
|
||||
serversModel.clear()
|
||||
for (var key in obj) {
|
||||
addIfNotExist(obj[key])
|
||||
}
|
||||
getRandom()
|
||||
} else if (req.readyState === 4 && req.status > 299) {lookup="http://de2.api.radio-browser.info/json/servers";getList();}
|
||||
sTimer.running = false
|
||||
//console.log(" *** lookup *** "+serverIndex+": "+lookup)
|
||||
getRandom(lookup)
|
||||
} else if (req.readyState === 4 && req.status > 299) {
|
||||
if (serverIndex < sModel.count-1) serverIndex=serverIndex+1; else serverIndex=0;
|
||||
lookup=sModel.get(serverIndex).url
|
||||
//console.log(" *** lookup *** "+serverIndex+": "+lookup)
|
||||
getList();
|
||||
}
|
||||
};
|
||||
sTimer.running = true
|
||||
//console.log(" *** START : "+lookup)
|
||||
req.open("get", lookup);
|
||||
req.setRequestHeader('User-Agent',_useragent);
|
||||
req.send();
|
||||
|
@ -7,9 +7,10 @@ Column {
|
||||
id: column
|
||||
spacing: Theme.paddingMedium
|
||||
anchors.centerIn: parent
|
||||
property QDtimer timer: QDtimer {
|
||||
Timer {
|
||||
id: spTimer
|
||||
interval: 10000; running: visible ? true : false; repeat: false
|
||||
onTriggered: radioBrowser.getRandom(radioBrowser.serverUrl)
|
||||
}
|
||||
|
||||
Image {
|
||||
@ -27,11 +28,13 @@ Column {
|
||||
}
|
||||
|
||||
BusyLabel {
|
||||
width: parent.width
|
||||
text: radioBrowser.serversModel.count > 0 ? qsTr("Found")+": "+radioBrowser.serversModel.count + " "+qsTr("servers") : qsTr("Searching servers")
|
||||
running: radioBrowser.serversModel.count < 1
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
BusyLabel {
|
||||
width: parent.width
|
||||
visible: radioBrowser.serversModel.count > 0
|
||||
running: visible
|
||||
text: qsTr("Connecting")
|
||||
@ -44,12 +47,12 @@ Column {
|
||||
color: Theme.highlightColor
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
Button {
|
||||
/* Button {
|
||||
visible: radioBrowser.serversModel.count > 1 && !spTimer.running
|
||||
anchors.topMargin: Theme.paddingLarge
|
||||
text: qsTr("Try another server")
|
||||
onClicked: radioBrowser.getRandom()
|
||||
onClicked: radioBrowser.getRandom(radioBrowser.serverUrl)
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
} */
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user