diff --git a/config.json b/config.json index 799586b..2962e47 100644 --- a/config.json +++ b/config.json @@ -17,6 +17,8 @@ "token": "SecretToken", "iceServers": [ "stun:stun.l.google.com:19302" - ] + ], + "maxUsersPerCalls": 3, + "allowVideo": true } } \ No newline at end of file diff --git a/src/controllers/ConversationsController.ts b/src/controllers/ConversationsController.ts index 431abe4..7ba8e57 100644 --- a/src/controllers/ConversationsController.ts +++ b/src/controllers/ConversationsController.ts @@ -5,6 +5,7 @@ import { UserHelper } from "../helpers/UserHelper"; import { removeHTMLNodes } from "../utils/StringUtils"; import { ConversationMessage } from "../entities/ConversationMessage"; import { UnreadConversation } from "../entities/UnreadConversation"; +import { CallsHelper } from "../helpers/CallsHelper"; /** * Conversations controller @@ -369,7 +370,8 @@ export class ConversationsController { name: c.name.length > 0 ? c.name : false, following: c.following ? 1 : 0, saw_last_message: c.sawLastMessage ? 1 : 0, - members: [...c.members] + members: [...c.members], + can_have_call: CallsHelper.CanHaveCall(c) }; } diff --git a/src/controllers/RTCRelayController.ts b/src/controllers/RTCRelayController.ts index c36ede3..497e235 100644 --- a/src/controllers/RTCRelayController.ts +++ b/src/controllers/RTCRelayController.ts @@ -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 */ diff --git a/src/helpers/CallsHelper.ts b/src/helpers/CallsHelper.ts new file mode 100644 index 0000000..2af369b --- /dev/null +++ b/src/helpers/CallsHelper.ts @@ -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 + } + +} \ No newline at end of file diff --git a/src/helpers/ConfigHelper.ts b/src/helpers/ConfigHelper.ts index 0a91d51..06bdab4 100644 --- a/src/helpers/ConfigHelper.ts +++ b/src/helpers/ConfigHelper.ts @@ -18,7 +18,10 @@ export interface DatabaseConfiguration { export interface RTCRelayConfiguration { ip ?: string, token: string, - iceServers: string[] + iceServers: string[], + + maxUsersPerCalls: number, + allowVideo: boolean, } export interface Configuration {