Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

2.1 KB
Raw Blame
import {realm} from "./state_data.ts";

export type OAuthCallProvider = "google_meet" | "webex" | "zoom";

export function current_oauth_call_provider(): OAuthCallProvider | null {
    const available_providers = realm.realm_available_video_chat_providers;
    const realm_provider = realm.realm_video_chat_provider;
    switch (realm_provider) {
        case available_providers.google_meet?.id:
            return "google_meet";
        case available_providers.webex?.id:
            return "webex";
        case available_providers.zoom?.id:
        case available_providers.zoom_server_to_server?.id:
            return "zoom";
        default:
            return null;
    }
}

export function get_jitsi_server_url(video_call_id?: string): URL | null {
    const base_url = realm.realm_jitsi_server_url ?? realm.server_jitsi_server_url;
    if (!base_url) {
        return null;
    }
    const url = new URL(base_url);
    if (video_call_id !== undefined) {
        const separator = url.pathname.endsWith("/") ? "" : "/";
        url.pathname += `${separator}${video_call_id}`;
    }
    return url;
}

export function compute_show_video_chat_button(): boolean {
    const available_providers = realm.realm_available_video_chat_providers;
    if (realm.realm_video_chat_provider === available_providers.disabled.id) {
        return false;
    }

    if (
        realm.realm_video_chat_provider === available_providers.jitsi_meet.id &&
        !get_jitsi_server_url()
    ) {
        return false;
    }

    return true;
}

export function compute_show_audio_chat_button(): boolean {
    const available_providers = realm.realm_available_video_chat_providers;
    if (
        (realm.realm_video_chat_provider === available_providers.jitsi_meet?.id &&
            get_jitsi_server_url() !== null) ||
        realm.realm_video_chat_provider === available_providers.zoom?.id ||
        realm.realm_video_chat_provider === available_providers.big_blue_button?.id ||
        realm.realm_video_chat_provider === available_providers.zoom_server_to_server?.id
    ) {
        return true;
    }
    return false;
}