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
|
* Handles client signal
|
||||||
*
|
*
|
||||||
@ -124,7 +134,7 @@ export class CallsController {
|
|||||||
if(type !== "SDP" && type !== "CANDIDATE")
|
if(type !== "SDP" && type !== "CANDIDATE")
|
||||||
h.error(401, "Invalid candidate type");
|
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!")
|
h.error(401, "Invalid SDP signal!")
|
||||||
|
|
||||||
if(type == "CANDIDATE" && (!data.hasOwnProperty("candidate") || !data.hasOwnProperty("sdpMLineIndex") || !data.hasOwnProperty("sdpMid")))
|
if(type == "CANDIDATE" && (!data.hasOwnProperty("candidate") || !data.hasOwnProperty("sdpMLineIndex") || !data.hasOwnProperty("sdpMid")))
|
||||||
@ -132,7 +142,7 @@ export class CallsController {
|
|||||||
|
|
||||||
await RTCRelayController.SendMessage({
|
await RTCRelayController.SendMessage({
|
||||||
title: "signal",
|
title: "signal",
|
||||||
callHash: callID+"-"+peerID,
|
callHash: this.genCallHash(callID, peerID),
|
||||||
peerId: String(peerID === h.getUserId() ? 0 : h.getUserId()),
|
peerId: String(peerID === h.getUserId() ? 0 : h.getUserId()),
|
||||||
data: {
|
data: {
|
||||||
type: type,
|
type: type,
|
||||||
@ -204,6 +214,29 @@ export class CallsController {
|
|||||||
if(c.ws.readyState == ws.OPEN)
|
if(c.ws.readyState == ws.OPEN)
|
||||||
UserWebSocketController.SendToClient(c, WsMessage.NoIDMessage("call_closed",convID));
|
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
|
// Notify all other users
|
||||||
await UserWebSocketController.SendToSpecifcClients(
|
await UserWebSocketController.SendToSpecifcClients(
|
||||||
(c) => c.activeCalls.has(convID),
|
(c) => c.activeCalls.has(convID),
|
||||||
|
Loading…
Reference in New Issue
Block a user