2024-11-27 18:36:59 -05:00
|
|
|
import { RoomParticipant } from './roomParticipant.js';
|
2024-11-15 17:46:01 -05:00
|
|
|
|
2024-11-27 18:36:59 -05:00
|
|
|
export class Teacher extends RoomParticipant {
|
2024-11-28 15:09:22 -05:00
|
|
|
|
|
|
|
|
nbrMessageReceived = 0;
|
|
|
|
|
|
2024-11-15 17:46:01 -05:00
|
|
|
constructor(username, roomName) {
|
2024-11-27 18:36:59 -05:00
|
|
|
super(username, roomName);
|
|
|
|
|
this.ready = false;
|
2024-11-15 17:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
connectToRoom(baseUrl) {
|
2024-11-28 15:09:22 -05:00
|
|
|
return super.connectToRoom(baseUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onConnected() {
|
|
|
|
|
this.createRoom();
|
|
|
|
|
this.listenForStudentMessage();
|
2024-11-15 17:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
createRoom() {
|
|
|
|
|
if (this.socket) {
|
2024-11-27 18:36:59 -05:00
|
|
|
this.socket.emit('create-room', this.roomName);
|
2024-11-15 17:46:01 -05:00
|
|
|
}
|
|
|
|
|
}
|
2024-11-26 17:04:22 -05:00
|
|
|
|
2024-11-27 18:36:59 -05:00
|
|
|
broadcastMessage(message) {
|
2024-11-28 15:09:22 -05:00
|
|
|
if (this.socket) {
|
2024-11-27 18:36:59 -05:00
|
|
|
this.socket.emit('message-from-teacher', {
|
|
|
|
|
roomName: this.roomName,
|
|
|
|
|
message
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
console.warn(`Teacher ${this.username} not ready to broadcast yet`);
|
2024-11-26 17:04:22 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 18:36:59 -05:00
|
|
|
listenForStudentMessage() {
|
2024-11-26 17:04:22 -05:00
|
|
|
if (this.socket) {
|
2024-11-27 18:36:59 -05:00
|
|
|
this.socket.on('message-sent-student', ({ message }) => {
|
|
|
|
|
//console.log(`Teacher ${this.username} received: "${message}"`);
|
2024-11-28 15:09:22 -05:00
|
|
|
this.nbrMessageReceived++;
|
2024-11-26 17:04:22 -05:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-27 18:36:59 -05:00
|
|
|
}
|