mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-25 06:49:23 +00:00
Request connections to be closed
This commit is contained in:
parent
2f12197ec0
commit
798b67bd7f
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user