mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2024-11-25 23:09:22 +00:00
Send ICE configuration to server
This commit is contained in:
parent
e8a0e70ffe
commit
6aec00b3f4
@ -14,6 +14,9 @@
|
|||||||
|
|
||||||
"rtc_relay": {
|
"rtc_relay": {
|
||||||
"ip": "::ffff:127.0.0.1",
|
"ip": "::ffff:127.0.0.1",
|
||||||
"token": "SecretToken"
|
"token": "SecretToken",
|
||||||
|
"iceServers": [
|
||||||
|
"stun:stun.l.google.com:19302"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,7 +24,7 @@ export class RTCRelayController {
|
|||||||
public static async OpenWS(req: Request, ws: ws) {
|
public static async OpenWS(req: Request, ws: ws) {
|
||||||
|
|
||||||
// First, check if sockets are enabled
|
// First, check if sockets are enabled
|
||||||
if(!conf().rtc_relay) {
|
if (!conf().rtc_relay) {
|
||||||
ws.send("rtc relay not configured!");
|
ws.send("rtc relay not configured!");
|
||||||
ws.close();
|
ws.close();
|
||||||
return;
|
return;
|
||||||
@ -33,21 +33,21 @@ export class RTCRelayController {
|
|||||||
const cnf = conf().rtc_relay;
|
const cnf = conf().rtc_relay;
|
||||||
|
|
||||||
// Then check remote IP address
|
// Then check remote IP address
|
||||||
if(cnf.ip && cnf.ip != req.ip) {
|
if (cnf.ip && cnf.ip != req.ip) {
|
||||||
ws.send("unkown IP address : "+req.ip)
|
ws.send("unkown IP address : " + req.ip)
|
||||||
ws.close();
|
ws.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, check access token
|
// Finally, check access token
|
||||||
if(!req.query.hasOwnProperty("token") || req.query.token !== cnf.token) {
|
if (!req.query.hasOwnProperty("token") || req.query.token !== cnf.token) {
|
||||||
ws.send("invalid token!");
|
ws.send("invalid token!");
|
||||||
ws.close();
|
ws.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close previous connection
|
// Close previous connection
|
||||||
if(this.currWs && this.currWs.readyState == ws.OPEN) {
|
if (this.currWs && this.currWs.readyState == ws.OPEN) {
|
||||||
this.currWs.close();
|
this.currWs.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +55,38 @@ export class RTCRelayController {
|
|||||||
this.currWs = ws;
|
this.currWs = ws;
|
||||||
|
|
||||||
// Register to events
|
// Register to events
|
||||||
|
ws.addEventListener("close", () => this.WSClosed());
|
||||||
|
|
||||||
|
// Send ice configuration to server
|
||||||
|
this.SendMessage("config", {
|
||||||
|
iceServers: cnf.iceServers
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method called when a websocket connection is closed
|
||||||
|
*/
|
||||||
|
private static async WSClosed() {
|
||||||
|
|
||||||
|
// Check if this is caused to a new connection
|
||||||
|
if (this.currWs.readyState != ws.OPEN)
|
||||||
|
this.currWs = null;
|
||||||
|
|
||||||
|
console.info("Closed a connection to RTC relay");
|
||||||
|
|
||||||
|
// TODO : do cleanup
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a new message to the server
|
||||||
|
*
|
||||||
|
* @param title The title of the message to send
|
||||||
|
* @param content The content of the message
|
||||||
|
*/
|
||||||
|
private static async SendMessage(title: string, content: any) {
|
||||||
|
this.currWs.send(JSON.stringify({
|
||||||
|
title: title,
|
||||||
|
data: content
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ export interface DatabaseConfiguration {
|
|||||||
export interface RTCRelayConfiguration {
|
export interface RTCRelayConfiguration {
|
||||||
ip ?: string,
|
ip ?: string,
|
||||||
token: string,
|
token: string,
|
||||||
|
iceServers: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Configuration {
|
export interface Configuration {
|
||||||
|
Loading…
Reference in New Issue
Block a user