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