Commit f22bef0f authored by Tom Jorquera's avatar Tom Jorquera
Browse files

client: robot close resources when client leaves

Robot will now stop recording and close websocket when a participant leaves the
room.
parent 8ba31799
......@@ -11,7 +11,8 @@ const config = arguments[1];
robotController.external.load(config);
robot = {
recordedParticipants: {},
recordedParticipantsWS: {},
participantsMediaRecorders: {},
processAudio(stream, callback, interval) {
const mediaRecorder = new MediaRecorder(stream);
......@@ -64,8 +65,12 @@ robot = {
text: e.from + '\t' + e.until + '\t' + easyrtcid + '\t' + e.text
});
});
robot.processAudio(stream, e => ws.send(e.data), 100);
robot.recordedParticipants[easyrtcid] = ws;
robot.participantsMediaRecorders[easyrtcid] = robot.processAudio(stream, e => ws.send(e.data), 100);
robot.recordedParticipantsWS[easyrtcid] = ws;
},
stopRecordParticipant(easyrtcid) {
robot.participantsMediaRecorders[easyrtcid].stop();
robot.recordedParticipantsWS[easyrtcid].close();
},
start: () => {
......@@ -77,6 +82,10 @@ robot = {
robot.recordParticipant(data.easyrtcid);
};
robotController.onAttendeeRemove = (e, data) => {
robot.stopRecordParticipant(data.easyrtcid);
};
robotLib.reco.start(room);
setInterval(
() => robotLib.reco.getOnlineReco(room)
......
......@@ -7,10 +7,15 @@ describe('client/robot', () => {
type: 'mediaRecorder',
stream,
started: false,
stopped: false,
interval: null,
start(interval) {
this.started = true;
this.interval = interval;
},
stop() {
this.started = false;
this.stopped = true;
}
};
global.MediaRecorder.instances[stream.id] = res;
......@@ -28,10 +33,14 @@ describe('client/robot', () => {
global.robotLib = {
sttDataSent: [],
closed: false,
stt: () => ({
getTranscriptSocket: () => ({
send(data) {
global.robotLib.sttDataSent.push(data);
},
close() {
global.robotLib.closed = true;
}
})
}),
......@@ -95,4 +104,12 @@ describe('client/robot', () => {
global.MediaRecorder.instances.testid.ondataavailable(e);
expect(global.robotLib.sttDataSent[0]).toBe(e.data);
});
test('should stop transcribing stream on user disconnect', () => {
global.robot.start();
global.robotController.onAttendeeRemove({}, {easyrtcid: 'someid1'});
expect(global.MediaRecorder.instances.someid1.stopped).toBeTruthy();
expect(global.robotLib.closed).toBeTruthy();
});
});
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