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