From 0944a99a713c957513742f5b5fadd547f21564f9 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 15 Apr 2020 07:55:59 +0200 Subject: [PATCH] Can check if conversation is allowed to have a call or not --- src/controllers/CallsController.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/controllers/CallsController.ts b/src/controllers/CallsController.ts index c92d713..0e90de6 100644 --- a/src/controllers/CallsController.ts +++ b/src/controllers/CallsController.ts @@ -6,6 +6,8 @@ import * as ws from 'ws' import { WsMessage } from "../entities/WsMessage"; import { conf } from "../helpers/ConfigHelper"; import { RTCRelayController } from "./RTCRelayController"; +import { ConversationsHelper } from "../helpers/ConversationsHelper"; +import { CallsHelper } from "../helpers/CallsHelper"; /** * Legacy calls controller @@ -60,6 +62,11 @@ export class CallsController { public static async JoinCall(h: UserWebSocketRequestsHandler) { const convID = await h.postConversationId("convID"); + // Check if the conversation is authorized to have a call + const conv = await ConversationsHelper.GetSingle(convID, h.getUserId()); + if(!CallsHelper.CanHaveCall(conv)) + h.error(401, "This conversation is not allowed to have a call!"); + // If the user was active in any other calls, remove him for(const c of UserWebSocketController.active_clients.filter((f) => f.userID == h.getUserId() && f.activeCalls.has(convID))) await this.MakeUserLeaveCall(convID, c)