Commit 3d51d240 authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

refactoring disconnect

parent 3fd2e9f5
Pipeline #3621 passed with stage
in 39 seconds
......@@ -17,23 +17,19 @@ robotController = {
return easyrtc.myEasyrtcid;
},
getParticipants: () => {
return easyrtc.getRoomOccupantsAsArray(room);
},
getRemoteStream: participant => {
return easyrtc.getRemoteStream(participant);
},
getRemoteStreams: () => {
const participants = robotController.getParticipants();
const res = {};
getParticipants: () => {
const participants = easyrtc.getRoomOccupantsAsArray(room);
const res = [];
for (let i = 0; i < participants.length; i++) {
const participant = participants[i];
try {
const mediaStream = robotController.getRemoteStream(participant);
if (mediaStream !== null) {
res[participant] = mediaStream;
res.push(participant);
}
} catch (err) {
console.error('could not get remote stream for %s', participant);
......
......@@ -20,9 +20,19 @@ const angular = {
})
};
const easyRTCMock = participants => ({
getRoomOccupantsAsArray: () => participants,
getRemoteStream: participant => ({origin: participant})
const easyRTCMock = (participantsWithStream, participantsWithoutStream = []) => ({
getRoomOccupantsAsArray: () => participantsWithStream
.concat(participantsWithoutStream),
getRemoteStream: participant => {
// Participant must be in list of participants AND not be in the list
// of participants without stream.
if (participantsWithStream.indexOf(participant) !== -1) {
return {
origin: participant
};
}
return null;
}
});
const document = {
......@@ -50,18 +60,18 @@ describe('client/controller', () => {
expect(participants).toHaveLength(3);
});
test('should not return participants without stream', () => {
global.easyrtc = easyRTCMock(['p1', 'p2', 'p3'], ['nostream']);
const participants = global.robotController.getParticipants();
expect(participants).not.toEqual(expect.arrayContaining(['nostream']));
});
test('should return the Streams of the participant', () => {
const stream = global.robotController.getRemoteStream('p2');
expect(stream.origin).toBe('p2');
});
test('should return the Streams of all the participants', () => {
const streams = global.robotController.getRemoteStreams();
expect(streams).toHaveProperty('p1');
expect(streams).toHaveProperty('p2');
expect(streams).toHaveProperty('p3');
});
test('should call listener on push events', () => {
let eventFired = false;
......
......@@ -83,32 +83,13 @@ robot = {
robot.getUserStream(easyrtcid);
},
getParticipantNumber() {
const participants = robotController.getParticipants();
let participantsNumber = participants.length;
for (let i = 0; i < participants.length; i++) {
const participant = participants[i];
try {
const mediaStream = robotController.getRemoteStream(participant);
if (mediaStream === null) {
participantsNumber--;
}
} catch (err) {
console.error('could not get remote stream for %s', participant);
console.error(err);
}
}
return participantsNumber;
},
stopRecordParticipant(easyrtcid) {
robot.participantsMediaRecorders[easyrtcid].stop();
robot.recordedParticipantsWS[easyrtcid].close();
},
disconnectRobot() {
if (robot.getParticipantNumber() === 1) {
checkDisconnect() {
if (robotController.getParticipantNumber().length === 1) {
robotController.disconnect();
}
},
......@@ -124,7 +105,7 @@ robot = {
robotController.onAttendeeRemove = (e, data) => {
robot.stopRecordParticipant(data.easyrtcid);
robot.disconnectRobot();
robot.checkDisconnect();
};
function recoStartRetry() {
......@@ -150,7 +131,7 @@ robot = {
}
// Wait 5 minute before leaving a room if alone
setTimeout(robot.disconnectRobot(), 300000);
setTimeout(robot.checkDisconnect(), 300000);
}
};
......
......@@ -51,7 +51,9 @@ describe('client/robot', () => {
'someid1',
'someid2'
],
getRemoteStream: id => ({type: 'RemoteStream', id})
getRemoteStream: id => ({type: 'RemoteStream', id}),
getParticipantNumber: () => 3,
disconnect: () => {}
};
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