From b8c19a8875bc29bdf86f41a0261233a96b0f733a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 11 Apr 2020 08:19:52 +0200 Subject: [PATCH] Returns calls configuration to client --- src/controllers/CallsController.ts | 17 +++++++++++++++++ src/controllers/UserWebSocketRoutes.ts | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/controllers/CallsController.ts b/src/controllers/CallsController.ts index a6728d4..8f78d75 100644 --- a/src/controllers/CallsController.ts +++ b/src/controllers/CallsController.ts @@ -4,6 +4,7 @@ import { ActiveClient, UserWebSocketController } from "./UserWebSocketController import { EventsHelper } from "../helpers/EventsHelper"; import * as ws from 'ws' import { WsMessage } from "../entities/WsMessage"; +import { conf } from "../helpers/ConfigHelper"; /** * Legacy calls controller @@ -22,6 +23,22 @@ export class CallsController { }); } + /** + * Get call configuration + * + * @param h Request handler + */ + public static async GetConfig(h: UserWebSocketRequestsHandler) { + + // Check if user is member of at least one call + if(h.wsClient.activeCalls.size == 0) + h.error(401, "You do not belong to any call for now!") + + h.send({ + iceServers: conf().rtc_relay.iceServers + }) + } + /** * Join a call * diff --git a/src/controllers/UserWebSocketRoutes.ts b/src/controllers/UserWebSocketRoutes.ts index 6dfa574..868c289 100644 --- a/src/controllers/UserWebSocketRoutes.ts +++ b/src/controllers/UserWebSocketRoutes.ts @@ -33,6 +33,8 @@ export const UserWebSocketRoutes: UserWebSocketRoute[] = [ // Calls controller + {title: "calls/config", handler: (h) => CallsController.GetConfig(h)}, + {title: "calls/join", handler: (h) => CallsController.JoinCall(h)}, {title: "calls/leave", handler: (h) => CallsController.LeaveCall(h)},