From a0594fa9688d2aff254ef1b90ce1843078efc490 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 14 Apr 2020 09:39:43 +0200 Subject: [PATCH] Avoid duplicate code --- src/controllers/CallsController.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/controllers/CallsController.ts b/src/controllers/CallsController.ts index 9636904..afca5b3 100644 --- a/src/controllers/CallsController.ts +++ b/src/controllers/CallsController.ts @@ -277,23 +277,13 @@ export class CallsController { // Notify RTC relay // User main stream (sender) - await RTCRelayController.SendMessage({ - title: "close_conn", - callHash: this.genCallHash(convID, c.userID), - peerId: "0", - data: "" - }) + await this.CloseCallStream(convID, c.userID, c.userID); // Receiver stream (on other user streams) for(const conn of UserWebSocketController.active_clients.filter( (f) => f.activeCalls.has(convID) && f.userID != c.userID)) { - await RTCRelayController.SendMessage({ - title: "close_conn", - callHash: this.genCallHash(convID, conn.userID), - peerId: String(c.userID), - data: "" - }) + await this.CloseCallStream(convID, conn.userID, c.userID) } @@ -306,6 +296,22 @@ export class CallsController { }) ) } + + /** + * Ask to close a stream + * + * @param callID Call ID + * @param userID User whose we stream content + * @param peerID Peer receiving / emitting content + */ + private static async CloseCallStream(callID: number, userID: number, peerID: number) { + await RTCRelayController.SendMessage({ + title: "close_conn", + callHash: this.genCallHash(callID, userID), + peerId: userID == peerID ? "0" : String(peerID), + data: "" + }) + } } // Listen for websocket closed