1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-22 05:19:22 +00:00

Forward signals for web app to rtc proxy

This commit is contained in:
Pierre HUBERT 2020-04-11 09:40:00 +02:00
parent 18dbc6fd9f
commit 2e6461c34a
4 changed files with 53 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import { EventsHelper } from "../helpers/EventsHelper";
import * as ws from 'ws'
import { WsMessage } from "../entities/WsMessage";
import { conf } from "../helpers/ConfigHelper";
import { RTCRelayController } from "./RTCRelayController";
/**
* Legacy calls controller
@ -104,6 +105,39 @@ export class CallsController {
).map(f => f.userID))
}
/**
* Handles client signal
*
* @param h Request handler
*/
public static async OnClientSignal(h: UserWebSocketRequestsHandler) {
const callID = h.postCallId("callID");
const peerID = h.postCallPeerID(callID, "peerID");
const type = h.postString("type");
const data = h.postJSON("data");
if(type !== "SDP" && type !== "CANDIDATE")
h.error(401, "Invalid candidate type");
if(type == "SDP" && (!data.hasOwnProperty("type") || data.type !== "offer" || !data.hasOwnProperty("sdp")))
h.error(401, "Invalid SDP signal!")
if(type == "CANDIDATE" && (!data.hasOwnProperty("candidate") || !data.hasOwnProperty("sdpMLineIndex") || !data.hasOwnProperty("sdpMid")))
h.error(401, "Invalid candidate signal!")
await RTCRelayController.SendMessage({
title: "signal",
callHash: callID+"-"+peerID,
peerId: String(peerID === h.getUserId() ? 0 : peerID),
data: {
type: type,
data: data
}
});
h.success()
}
/**
* Make the client leave the call
*

View File

@ -102,7 +102,7 @@ export class RTCRelayController {
* @param title The title of the message to send
* @param content The content of the message
*/
private static async SendMessage(msg: RTCSocketMessage) {
public static async SendMessage(msg: RTCSocketMessage) {
this.currWs.send(JSON.stringify({
title: msg.title,
callHash: msg.callHash,

View File

@ -40,4 +40,6 @@ export const UserWebSocketRoutes: UserWebSocketRoute[] = [
{title: "calls/leave", handler: (h) => CallsController.LeaveCall(h)},
{title: "calls/members", handler: (h) => CallsController.GetMembersList(h)},
{title: "calls/signal", handler: (h) => CallsController.OnClientSignal(h)},
]

View File

@ -80,4 +80,20 @@ export class UserWebSocketRequestsHandler extends BaseRequestsHandler {
return convID;
}
/**
* Get the ID of a peer of a call included in the WebSocket request
*
* @param callID Target call ID
* @param name The name of the POST field
*/
public postCallPeerID(callID: number, name: string) : number{
const peerID = this.postInt(name);
if(peerID != this.getUserId() && UserWebSocketController.active_clients.find(
(e) => e.userID == peerID && e.activeCalls.has(callID)) === undefined)
this.error(401, "This peer is not a member of the call!");
return peerID;
}
}