Skip to content
Snippets Groups Projects
Unverified Commit 0f3257e6 authored by Florian Raith's avatar Florian Raith Committed by GitHub
Browse files

Add hand signals (#23)


* Implement hand signal

* Remove hand signal from the teacher's room view

* Fix getting student

---------

Co-authored-by: default avatarneda_moshki <uzijb@student.kit.edu>
parent 857cceff
No related branches found
No related tags found
No related merge requests found
......@@ -104,6 +104,7 @@ export class ChannelGateway implements OnGatewayConnection {
name: student.name,
video: student.video,
audio: student.audio,
handSignal: student.handSignal,
}));
return {
......@@ -178,6 +179,24 @@ export class ChannelGateway implements OnGatewayConnection {
return true;
}
@SubscribeMessage('update-handSignal')
@UseRequestContext()
public async updateHandSignal(
@ConnectedSocket() client: Socket,
@MessageBody() payload: { handSignal: boolean },
) {
const channel = await this.channels.fromClientOrFail(client);
channel.updateHandSignal(client, payload.handSignal);
this.server.to(channel.id).emit('update-handSignal', {
id: client.id,
handSignal: payload.handSignal,
});
return true;
}
public async handleConnection(client: Socket) {
/*
* This is a workaround for getting the client's rooms in the disconnecting event.
......
......@@ -15,6 +15,7 @@ export interface Teacher extends ChannelUser {
export interface Student extends ChannelUser {
name: string;
handSignal: boolean;
}
export class Channel {
......@@ -32,7 +33,13 @@ export class Channel {
public async joinAsStudent(client: Socket, name: string) {
await client.join(this.id);
const student = { name, client, video: true, audio: true };
const student = {
name,
client,
video: true,
audio: true,
handSignal: false,
};
this.students.set(client.id, student);
client.broadcast.to(this.id).emit('student-joined', {
......@@ -40,6 +47,7 @@ export class Channel {
name: student.name,
video: true,
audio: true,
handSignal: false,
});
}
......@@ -100,6 +108,16 @@ export class Channel {
throw new WsException(`User not found in ${this}`);
}
public getStudent(clientId: string): Student {
const student = this.students.get(clientId);
if (student) {
return student;
}
throw new WsException(`User not found in ${this}`);
}
public changeName(client: Socket, name: string) {
const student = this.students.get(client.id);
......@@ -117,6 +135,14 @@ export class Channel {
}
}
public updateHandSignal(client: Socket, handSignal: boolean) {
const student = this.getStudent(client.id);
if (student) {
student.handSignal = handSignal;
}
}
public toString(): string {
return `Channel{${this.id}}`;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment