From b72dfa1646aa097bb38a779b6caff4aa39a8b6c6 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 10 Apr 2020 16:39:01 +0200 Subject: [PATCH] Can get the list of members of a call --- src/controllers/CallsController.ts | 15 +++++++++++++++ src/controllers/UserWebSocketRoutes.ts | 2 ++ src/entities/WebSocketRequestHandler.ts | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/controllers/CallsController.ts b/src/controllers/CallsController.ts index c9286f3..3e4182f 100644 --- a/src/controllers/CallsController.ts +++ b/src/controllers/CallsController.ts @@ -69,6 +69,21 @@ export class CallsController { h.success(); } + /** + * Get the list of members for a call + * + * The user must have joined the call to get this information + * + * @param h Request handler + */ + public static async GetMembersList(h: UserWebSocketRequestsHandler) { + const convID = h.postCallId("callID"); + + h.send(UserWebSocketController.active_clients.filter( + (f) => f.activeCalls.has(convID) + ).map(f => f.userID)) + } + /** * Make the client leave the call * diff --git a/src/controllers/UserWebSocketRoutes.ts b/src/controllers/UserWebSocketRoutes.ts index f37f5cb..6dfa574 100644 --- a/src/controllers/UserWebSocketRoutes.ts +++ b/src/controllers/UserWebSocketRoutes.ts @@ -36,4 +36,6 @@ export const UserWebSocketRoutes: UserWebSocketRoute[] = [ {title: "calls/join", handler: (h) => CallsController.JoinCall(h)}, {title: "calls/leave", handler: (h) => CallsController.LeaveCall(h)}, + + {title: "calls/members", handler: (h) => CallsController.GetMembersList(h)}, ] \ No newline at end of file diff --git a/src/entities/WebSocketRequestHandler.ts b/src/entities/WebSocketRequestHandler.ts index b6f22d8..49c9b28 100644 --- a/src/entities/WebSocketRequestHandler.ts +++ b/src/entities/WebSocketRequestHandler.ts @@ -64,4 +64,20 @@ export class UserWebSocketRequestsHandler extends BaseRequestsHandler { this.sentResponse = true; } + + + /** + * Get the ID of a call included in WebSocket request + * + * @param name The name of the parameter + */ + public postCallId(name: string) : number { + const convID = this.postInt(name); + + // Check if the user is a member of this call + if(!this.wsClient.activeCalls.has(convID)) + this.error(401, "You do not belong to this call!") + + return convID; + } } \ No newline at end of file