zulip/web/src/compose_call.ts
Anders Kaseorg b9e62c7af8 page_params: Split out state data for realm.
For spectators, the chunk of page_params that originates from
do_events_register isn’t assigned until ui_init.js.  That means the
TypeScript type of page_params is mostly a lie during module load
time: reading a parameter too early silently results in undefined
rather than the declared type, with unpredictable results later on.

We want to make such an early read into an immediate runtime error,
for both users and spectators consistently, and pave the way for
runtime validation of the page_params type.  As a second step, split
out the subset of fields that pertain to the entire realm.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-02-15 10:22:52 -08:00

47 lines
1.4 KiB
TypeScript

import {realm} from "./state_data";
export const zoom_token_callbacks = new Map();
export const video_call_xhrs = new Map();
export function get_jitsi_server_url(): string | null {
return realm.realm_jitsi_server_url ?? realm.server_jitsi_server_url;
}
export function abort_video_callbacks(edit_message_id = ""): void {
zoom_token_callbacks.delete(edit_message_id);
if (video_call_xhrs.has(edit_message_id)) {
video_call_xhrs.get(edit_message_id).abort();
video_call_xhrs.delete(edit_message_id);
}
}
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 (
(available_providers.jitsi_meet &&
get_jitsi_server_url() !== null &&
realm.realm_video_chat_provider === available_providers.jitsi_meet.id) ||
(available_providers.zoom &&
realm.realm_video_chat_provider === available_providers.zoom.id)
) {
return true;
}
return false;
}