diff --git a/src/channel/channel.gateway.ts b/src/channel/channel.gateway.ts index 6d12be3d6ed8ae663d0d29a78e4aaaa83078a9aa..0844336e510ce328e8757bb7bb12fd8f2fb130ab 100644 --- a/src/channel/channel.gateway.ts +++ b/src/channel/channel.gateway.ts @@ -51,17 +51,24 @@ export class ChannelGateway implements OnGatewayConnection { payload: { name: string; channelId: string; + password?: string; }, ) { if (!this.channels.exists(payload.channelId)) { return { error: 'Der Raum konnte nicht gefunden werden' }; } - const channel = await this.channels.joinAsStudent( - client, - payload.channelId, - payload.name, - ); + let channel; + try { + channel = await this.channels.joinAsStudent( + client, + payload.channelId, + payload.name, + payload.password, + ); + } catch (e) { + return { error: e.message }; + } return this.channelState(channel); } diff --git a/src/channel/channel.service.ts b/src/channel/channel.service.ts index d4386e1ab905ed848f9e806132e2c9afda09db5e..7c01a6378e450b2f77a0fe392ccb9e1b93808e6d 100644 --- a/src/channel/channel.service.ts +++ b/src/channel/channel.service.ts @@ -56,6 +56,7 @@ export class ChannelService { client: Socket, channelId: string, name: string, + password?: string, ): Promise<Channel> { const channel = this.channels[channelId]; @@ -63,6 +64,10 @@ export class ChannelService { throw new WsException('Channel not found'); } + if (channel.room.password && channel.room.password !== password) { + throw new WsException('Wrong password'); + } + await channel.joinAsStudent(client, name); channel.clearCloseTimeout();