1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-12-26 13:38:52 +00:00

Avoid duplicate code

This commit is contained in:
Pierre HUBERT 2020-04-14 09:39:43 +02:00
parent 1e1c2050a2
commit a0594fa968

View File

@ -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