1
0
mirror of https://gitlab.com/comunic/comunicapiv2 synced 2024-11-25 23:09:22 +00:00

Check if a conversation can be the source for a call

This commit is contained in:
Pierre HUBERT 2020-04-10 11:05:30 +02:00
parent d1235f4f8c
commit 0a778811af
5 changed files with 41 additions and 3 deletions

View File

@ -17,6 +17,8 @@
"token": "SecretToken", "token": "SecretToken",
"iceServers": [ "iceServers": [
"stun:stun.l.google.com:19302" "stun:stun.l.google.com:19302"
] ],
"maxUsersPerCalls": 3,
"allowVideo": true
} }
} }

View File

@ -5,6 +5,7 @@ import { UserHelper } from "../helpers/UserHelper";
import { removeHTMLNodes } from "../utils/StringUtils"; import { removeHTMLNodes } from "../utils/StringUtils";
import { ConversationMessage } from "../entities/ConversationMessage"; import { ConversationMessage } from "../entities/ConversationMessage";
import { UnreadConversation } from "../entities/UnreadConversation"; import { UnreadConversation } from "../entities/UnreadConversation";
import { CallsHelper } from "../helpers/CallsHelper";
/** /**
* Conversations controller * Conversations controller
@ -369,7 +370,8 @@ export class ConversationsController {
name: c.name.length > 0 ? c.name : false, name: c.name.length > 0 ? c.name : false,
following: c.following ? 1 : 0, following: c.following ? 1 : 0,
saw_last_message: c.sawLastMessage ? 1 : 0, saw_last_message: c.sawLastMessage ? 1 : 0,
members: [...c.members] members: [...c.members],
can_have_call: CallsHelper.CanHaveCall(c)
}; };
} }

View File

@ -73,6 +73,13 @@ export class RTCRelayController {
}) })
} }
/**
* Check out wheter a relay is currently connected to the API
*/
public static get IsConnected() : boolean {
return this.currWs && this.currWs.readyState == ws.OPEN;
}
/** /**
* Method called when a websocket connection is closed * Method called when a websocket connection is closed
*/ */

View File

@ -0,0 +1,24 @@
/**
* Calls helper
*
* @author Pierre Hubert
*/
import { Conversation } from "../entities/Conversation";
import { conf } from "./ConfigHelper";
import { RTCRelayController } from "../controllers/RTCRelayController";
export class CallsHelper {
/**
* Check out whether a given conversation can have a call or not
*
* @param conv Target conversation
*/
public static CanHaveCall(conv: Conversation) : boolean {
return (conf().rtc_relay && RTCRelayController.IsConnected
&& conv.members.size > 1
&& conf().rtc_relay.maxUsersPerCalls >= conv.members.size) === true
}
}

View File

@ -18,7 +18,10 @@ export interface DatabaseConfiguration {
export interface RTCRelayConfiguration { export interface RTCRelayConfiguration {
ip ?: string, ip ?: string,
token: string, token: string,
iceServers: string[] iceServers: string[],
maxUsersPerCalls: number,
allowVideo: boolean,
} }
export interface Configuration { export interface Configuration {