From 798b67bd7fdedc2783f8a77fb519c51b740d3b38 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 11 Apr 2020 17:46:38 +0200 Subject: [PATCH] Request connections to be closed --- src/controllers/CallsController.ts | 37 ++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/controllers/CallsController.ts b/src/controllers/CallsController.ts index 1d6738c..372f993 100644 --- a/src/controllers/CallsController.ts +++ b/src/controllers/CallsController.ts @@ -110,6 +110,16 @@ export class CallsController { }})) } + /** + * Generate call hash + * + * @param callID Target call ID + * @param peerID Target peer ID + */ + private static genCallHash(callID: number, peerID: number): string { + return callID+"-"+peerID; + } + /** * Handles client signal * @@ -124,7 +134,7 @@ export class CallsController { if(type !== "SDP" && type !== "CANDIDATE") h.error(401, "Invalid candidate type"); - if(type == "SDP" && (!data.hasOwnProperty("type") || data.type !== "offer" || !data.hasOwnProperty("sdp"))) + if(type == "SDP" && (!data.hasOwnProperty("type") || (data.type !== "offer" && data.type !== "answer") || !data.hasOwnProperty("sdp"))) h.error(401, "Invalid SDP signal!") if(type == "CANDIDATE" && (!data.hasOwnProperty("candidate") || !data.hasOwnProperty("sdpMLineIndex") || !data.hasOwnProperty("sdpMid"))) @@ -132,7 +142,7 @@ export class CallsController { await RTCRelayController.SendMessage({ title: "signal", - callHash: callID+"-"+peerID, + callHash: this.genCallHash(callID, peerID), peerId: String(peerID === h.getUserId() ? 0 : h.getUserId()), data: { type: type, @@ -204,6 +214,29 @@ export class CallsController { if(c.ws.readyState == ws.OPEN) UserWebSocketController.SendToClient(c, WsMessage.NoIDMessage("call_closed",convID)); + // Notify RTC relay + + // User main stream (sender) + await RTCRelayController.SendMessage({ + title: "close_conn", + callHash: this.genCallHash(convID, c.userID), + peerId: "0", + data: "" + }) + + // 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: "" + }) + } + + // Notify all other users await UserWebSocketController.SendToSpecifcClients( (c) => c.activeCalls.has(convID),