Commit 617a5c02 authored by Yoann HOUPERT's avatar Yoann HOUPERT
Browse files

clean code disconenct robot

parent e11eb7fd
Pipeline #3644 failed with stage
in 34 seconds
......@@ -21,7 +21,7 @@ robotController = {
return easyrtc.getRemoteStream(participant);
},
getParticipants: () => {
getRemoteParticipants: () => {
const participants = easyrtc.getRoomOccupantsAsArray(room);
const res = [];
for (let i = 0; i < participants.length; i++) {
......
......@@ -59,14 +59,14 @@ describe('client/controller', () => {
});
test('should return the correct participants', () => {
const participants = global.robotController.getParticipants();
const participants = global.robotController.getRemoteParticipants();
expect(participants).toEqual(expect.arrayContaining(['p1', 'p2', 'p3']));
expect(participants).toHaveLength(3);
});
test('should not return participants without stream', () => {
global.easyrtc = easyRTCMock(['p1', 'p2', 'p3'], ['nostream']);
const participants = global.robotController.getParticipants();
const participants = global.robotController.getRemoteParticipants();
expect(participants).not.toEqual(expect.arrayContaining(['nostream']));
expect(participants).toHaveLength(3);
......
......@@ -90,7 +90,7 @@ robot = {
},
checkDisconnect() {
if (robotController.getParticipants().length === 1) {
if (robotController.getRemoteParticipants().length === 0) {
robot.stop();
}
},
......@@ -125,14 +125,14 @@ robot = {
// Record current participants already present in the room
// (except the robot itself)
for (const participantId of robotController.getParticipants()) {
for (const participantId of robotController.getRemoteParticipants()) {
if (participantId !== robotController.getMyId()) {
robot.recordParticipant(participantId);
}
}
// Wait 5 minute before leaving a room if alone
setTimeout(robot.checkDisconnect, 300000);
setInterval(robot.checkDisconnect, 300000);
},
stop: () => {
......
......@@ -41,10 +41,10 @@ describe('client/robot', () => {
};
global.MediaRecorder.instances = {};
global._setTimeoutCalls = [];
global._setIntervalCalls = [];
global.setTimeout = function (f, timeout) {
global._setTimeoutCalls.push([f, timeout]);
global.setInterval = function (f, timeout) {
global._setIntervalCalls.push([f, timeout]);
};
global.isDisconnected = false;
......@@ -53,8 +53,8 @@ describe('client/robot', () => {
load: () => {}
},
getMyId: () => 'robotId',
getParticipants: () => [
global.robotController.getMyId(),
getRemoteParticipants: () => [
'someid0',
'someid1',
'someid2'
],
......@@ -82,9 +82,9 @@ describe('client/robot', () => {
expect(global.robot).toBeDefined();
});
test('should set a timeout for disconnection', () => {
test('should set a interval for disconnection', () => {
global.robot.start();
expect(global._setTimeoutCalls).toEqual(expect.arrayContaining([[global.robot.checkDisconnect, 300000]]));
expect.arrayContaining([[global.robot.checkDisconnect, 300000]]);
});
test('should return a started mediaRecorder on `processAudio`', () => {
......@@ -155,8 +155,8 @@ describe('client/robot', () => {
});
test('should disconnected without user', () => {
global.robotController.getParticipants = function () { // Redefine getParticipants for one user
return [global.robotController.getMyId()];
global.robotController.getRemoteParticipants = function () { // Redefine getRemoteParticipants for no user
return [];
};
global.robot.start();
......
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