From 431463967b6f317d5aa921133d6c6e4e73aa4c47 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 10 Apr 2020 16:19:46 +0200 Subject: [PATCH] Propagate closing of RTC websocket --- src/controllers/CallsController.ts | 8 +++++++- src/controllers/RTCRelayController.ts | 4 +++- src/helpers/EventsHelper.ts | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/controllers/CallsController.ts b/src/controllers/CallsController.ts index 91e7d99..c9286f3 100644 --- a/src/controllers/CallsController.ts +++ b/src/controllers/CallsController.ts @@ -95,4 +95,10 @@ EventsHelper.Listen("user_ws_closed", async w => { await CallsController.MakeUserLeaveCall(convID, w.client) }); -// TODO : close all call when RTC WS is closed \ No newline at end of file +// Close all call when RTC WS is closed +EventsHelper.Listen("rtc_relay_ws_closed", async () => { + for(const client of UserWebSocketController.active_clients) { + for(const convID of client.activeCalls) + await CallsController.MakeUserLeaveCall(convID, client); + } +}) diff --git a/src/controllers/RTCRelayController.ts b/src/controllers/RTCRelayController.ts index 497e235..17a09f7 100644 --- a/src/controllers/RTCRelayController.ts +++ b/src/controllers/RTCRelayController.ts @@ -1,6 +1,7 @@ import * as ws from 'ws'; import { Request } from 'express'; import { conf } from '../helpers/ConfigHelper'; +import { EventsHelper } from '../helpers/EventsHelper'; /** * RTC WebSocket relay controller @@ -91,7 +92,8 @@ export class RTCRelayController { console.info("Closed a connection to RTC relay"); - // TODO : do cleanup + // Propagate information + await EventsHelper.Emit("rtc_relay_ws_closed", {}); } /** diff --git a/src/helpers/EventsHelper.ts b/src/helpers/EventsHelper.ts index 8e5a2c0..ad36e81 100644 --- a/src/helpers/EventsHelper.ts +++ b/src/helpers/EventsHelper.ts @@ -9,6 +9,9 @@ import { ActiveClient } from "../controllers/UserWebSocketController"; * @author Pierre Hubert */ +// When RTC Relay WebSocket is closed +export interface ClosedRelayWebSocketEvent {} + // When a user sign out export interface DestroyedLoginTokensEvent { userID: number, @@ -64,6 +67,7 @@ export interface CommentDeletedEvent { * Global map of all possible events */ export interface EventsMap { + "rtc_relay_ws_closed": ClosedRelayWebSocketEvent, "destroyed_login_tokens": DestroyedLoginTokensEvent, "user_ws_closed": UserWebSocketClosedEvent, "updated_number_notifications": UpdatedNotificationsNumberEvent,