Commit b68617d7 authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

allow bot to clear connection if disconnected

parent 8f4d0dc9
......@@ -30,9 +30,12 @@ const room = arguments[0];
robotController = {
$scope: angular.element(document.body).scope().$root,
$injector: angular.element(document.body).injector(),
chatService: angular.element(document.body).injector().get('chat'),
getWebRTCAdapter: () => robotController.$injector.get('easyRTCAdapter'),
getMyId: () => {
return easyrtc.myEasyrtcid;
},
......
......@@ -35,6 +35,7 @@ robot = {
recordedParticipantsWS: {},
participantsMediaRecorders: {},
isDisconnected: false,
intervalList: [],
processAudio(stream, callback, interval) {
const mediaRecorder = new MediaRecorder(stream);
......@@ -130,6 +131,30 @@ robot = {
}
},
clearConnection() {
for (let i = 0; i < robot.intervalList.length; i++) {
clearInterval(robot.intervalList[i]);
}
const keyMap = Object.keys(robot.recordedParticipantsWS);
if (!keyMap) {
for (let i = 0; i < keyMap.length; i++) {
if (!keyMap[i]) {
robot.stopRecordParticipant(keyMap[i]);
}
}
}
},
reconnect() {
robotController.getWebRTCAdapter().addDisconnectCallback(() => {
function restart() {
robot.clearConnection();
robot.onConnection();
}
restart();
});
},
start: () => {
robotLib.stt = robotLib.stt(config);
robotLib.reco = robotLib.reco(config);
......@@ -144,6 +169,11 @@ robot = {
robot.checkDisconnect();
};
robot.reconnect();
robot.onConnection();
},
onConnection: () => {
const recoStartRetry = () => {
if (robotLib.reco.start(room)) {
clearInterval(robot.recoInterval);
......@@ -151,11 +181,12 @@ robot = {
};
robot.recoInterval = setInterval(recoStartRetry, 8000);
setInterval(
() => robotLib.reco.getOnlineReco(room)
robot.intervalList.push(robot.recoInterval);
robot.intervalList.push(
setInterval(() => robotLib.reco.getOnlineReco(room)
.then(robot.processReco)
.catch(console.error),
8000);
8000));
// Record current participants already present in the room
// (except the robot itself)
......@@ -166,11 +197,12 @@ robot = {
}
// Wait 5 minute before leaving a room if alone
setInterval(robot.checkDisconnect, 300000);
robot.intervalList.push(setInterval(robot.checkDisconnect, 300000));
},
stop: () => {
robot.isDisconnected = true;
robot.clearConnection();
robotController.disconnect();
}
};
......
......@@ -81,7 +81,10 @@ describe('client/robot', () => {
getRemoteStream: id => ({type: 'RemoteStream', id}),
disconnect: () => {
global.isDisconnected = true;
}
},
getWebRTCAdapter: () => ({
addDisconnectCallback: () => {}
})
};
global.robotLib = {
......
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