2024-11-10 15:42:46 -05:00
|
|
|
/**
|
|
|
|
|
* @template T
|
|
|
|
|
* @typedef {import('../../types/room').RoomInfo} RoomInfo
|
|
|
|
|
* @typedef {import('../../types/room').RoomOptions} RoomOptions
|
|
|
|
|
* @typedef {import('../../types/room').BaseProviderConfig} BaseProviderConfig
|
|
|
|
|
*/
|
|
|
|
|
|
2024-11-12 01:22:54 -05:00
|
|
|
const MIN_NB_SECONDS_BEFORE_CLEANUP = process.env.MIN_NB_SECONDS_BEFORE_CLEANUP || 60
|
|
|
|
|
|
2024-11-10 15:42:46 -05:00
|
|
|
class BaseRoomProvider {
|
|
|
|
|
constructor(config = {}, roomRepository) {
|
|
|
|
|
this.config = config;
|
|
|
|
|
this.roomRepository = roomRepository;
|
2024-11-12 01:22:54 -05:00
|
|
|
|
|
|
|
|
this.quiz_docker_image = process.env.QUIZROOM_IMAGE || "evaluetonsavoir-quizroom";
|
2024-11-12 02:33:19 -05:00
|
|
|
this.quiz_docker_port = process.env.QUIZROOM_PORT || 4500;
|
|
|
|
|
this.quiz_expose_port = process.env.QUIZROOM_EXPOSE_PORT || false;
|
2024-11-10 15:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async createRoom(roomId, options) {
|
2024-11-12 02:33:19 -05:00
|
|
|
throw new Error("Fonction non-implantée - classe abstraite");
|
2024-11-10 15:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async deleteRoom(roomId) {
|
2024-11-12 02:33:19 -05:00
|
|
|
throw new Error("Fonction non-implantée - classe abstraite");
|
2024-11-10 15:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getRoomStatus(roomId) {
|
2024-11-12 02:33:19 -05:00
|
|
|
throw new Error("Fonction non-implantée - classe abstraite");
|
2024-11-10 15:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async listRooms() {
|
2024-11-12 02:33:19 -05:00
|
|
|
throw new Error("Fonction non-implantée - classe abstraite");
|
2024-11-10 15:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async cleanup() {
|
2024-11-12 02:33:19 -05:00
|
|
|
throw new Error("Fonction non-implantée - classe abstraite");
|
2024-11-10 15:42:46 -05:00
|
|
|
}
|
|
|
|
|
|
2024-11-12 01:22:54 -05:00
|
|
|
async syncInstantiatedRooms(){
|
2024-11-12 02:33:19 -05:00
|
|
|
throw new Error("Fonction non-implantée - classe abstraite");
|
2024-11-12 01:22:54 -05:00
|
|
|
}
|
2024-11-10 15:42:46 -05:00
|
|
|
|
2024-11-12 01:22:54 -05:00
|
|
|
async updateRoomsInfo() {
|
|
|
|
|
const rooms = await this.roomRepository.getAll();
|
|
|
|
|
for(var room of rooms){
|
|
|
|
|
const url = `${room.host}/health`;
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(url);
|
|
|
|
|
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
room.mustBeCleaned = true;
|
|
|
|
|
await this.roomRepository.update(room);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const json = await response.json();
|
|
|
|
|
room.nbStudents = json.connections;
|
|
|
|
|
room.mustBeCleaned = room.nbStudents === 0 && json.uptime >MIN_NB_SECONDS_BEFORE_CLEANUP;
|
2024-11-10 15:42:46 -05:00
|
|
|
|
2024-11-12 01:22:54 -05:00
|
|
|
await this.roomRepository.update(room);
|
|
|
|
|
} catch (error) {
|
2024-11-12 02:33:19 -05:00
|
|
|
room.mustBeCleaned = true;
|
|
|
|
|
await this.roomRepository.update(room);
|
2024-11-10 15:42:46 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getRoomInfo(roomId) {
|
|
|
|
|
const info = await this.roomRepository.get(roomId);
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = BaseRoomProvider;
|