Commit 042f3c36 authored by Tom Jorquera's avatar Tom Jorquera
Browse files

client: online reco start is now fault-tolerant

Online reco method will now return a boolean indicating of the method succeded
or failed.
When starting online reco, if it fails, it will be tried again at fixed
intervals.
parent 5fdeac0f
......@@ -27,45 +27,59 @@ robotLib.reco = function (config) {
return {
start: confid => {
const xhttp = new XMLHttpRequest();
xhttp.open('GET', 'http://' + config.reco.host + ':' + config.reco.port + '/stream?action=START&id=' + confid, false);
xhttp.send();
},
stop: confid => {
const xhttp = new XMLHttpRequest();
xhttp.open('GET', 'http://' + config.reco.host + ':' + config.reco.port + '/stream?action=STOP&id=' + confid, false);
xhttp.send();
},
send: content => {
if (connected) {
recoStompClient.send('/app/chat', {}, JSON.stringify(content));
const xhttp = new XMLHttpRequest();
xhttp.open('GET', 'http://' + config.reco.host + ':' + config.reco.port + '/stream?action=START&id=' + confid, false);
xhttp.send();
return true;
} else {
console.error('Online reco: not connected but trying to send %j', content);
console.error('Online reco: not connected but trying to send start to conf %s', confid);
return false;
}
},
getOnlineReco: confId => {
return new Promise((resolve, reject) => {
const xmlHttp = new XMLHttpRequest();
stop: confid => {
if (connected) {
const xhttp = new XMLHttpRequest();
xhttp.open('GET', 'http://' + config.reco.host + ':' + config.reco.port + '/stream?action=STOP&id=' + confid, false);
xhttp.send();
return true;
} else {
console.error('Online reco: not connected but trying to send stop to conf %s', confid);
return false;
}
},
xmlHttp.onreadystatechange = () => {
if (xmlHttp.readyState === 4) {
if (xmlHttp.status === 200) {
resolve(xmlHttp.responseText);
} else {
console.error('Online reco: error trying to reach http://%s:%s/resources', config.reco.host, config.reco.port);
reject(xmlHttp.statusText);
}
send: content => {
if (connected) {
recoStompClient.send('/app/chat', {}, JSON.stringify(content));
return true;
} else {
console.error('Online reco: not connected but trying to send %j', content);
return false;
}
},
getOnlineReco: confId => {
return new Promise((resolve, reject) => {
const xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = () => {
if (xmlHttp.readyState === 4) {
if (xmlHttp.status === 200) {
resolve(xmlHttp.responseText);
} else {
console.error('Online reco: error trying to reach http://%s:%s/resources', config.reco.host, config.reco.port);
reject(xmlHttp.statusText);
}
};
}
};
const url = 'http://' + config.reco.host + ':' + config.reco.port + '/resources?id=' + confId + '&resources=keywords;wiki';
xmlHttp.open('GET', url, true);
xmlHttp.setRequestHeader('Content-type', 'application/json');
xmlHttp.send(null);
});
}
const url = 'http://' + config.reco.host + ':' + config.reco.port + '/resources?id=' + confId + '&resources=keywords;wiki';
xmlHttp.open('GET', url, true);
xmlHttp.setRequestHeader('Content-type', 'application/json');
xmlHttp.send(null);
});
}
};
};
......@@ -101,7 +101,14 @@ robot = {
robot.stopRecordParticipant(data.easyrtcid);
};
robotLib.reco.start(room);
function recoStartRetry() {
if (!robotLib.reco.start(room)) {
setTimeout(recoStartRetry, 8000);
}
}
// If start fails, schedule retry at fixed interval until success
recoStartRetry();
setInterval(
() => robotLib.reco.getOnlineReco(room)
.then(robot.processReco)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment