diff --git a/src/routes/idaa/(idaa)/video_conferences/+page.svelte b/src/routes/idaa/(idaa)/video_conferences/+page.svelte index d0c77228..119464f1 100644 --- a/src/routes/idaa/(idaa)/video_conferences/+page.svelte +++ b/src/routes/idaa/(idaa)/video_conferences/+page.svelte @@ -9,15 +9,6 @@ let jitsi_api: any = null; const jitsi_container_id = 'jitsi_meet_external_api_container'; - // Hardcoded moderator list, as in the original HTML file. - const novi_jitsi_mod_li = [ - '2b078deb-b4e7-4203-99da-9f7cd62159a5', - 'c9ea07b5-06b0-4a43-a2d0-8d06558c8a82', - '58db22ee-4b0a-49a7-9f34-53d2ba85a84b', - '5724aad7-6d89-47e7-8943-966fd22911bd', - '182d1db3-caa9-41bc-b04a-2facc6859aeb' - ]; - async function getJitsiJwt( display_name: string, email: string, @@ -25,7 +16,7 @@ room_name: string, user_id: string ) { - const tokenEndpoint = 'https://dev-api.oneskyit.com/api/jitsi_token'; + const token_endpoint = 'https://dev-api.oneskyit.com/api/jitsi_token'; const payload = { name: display_name, @@ -55,7 +46,7 @@ }; try { - const response = await fetch(tokenEndpoint, { + const response = await fetch(token_endpoint, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) @@ -74,13 +65,83 @@ onMount(async () => { const url_params = data.params; - const user_id = url_params.uuid; - const display_name = url_params.full_name ?? 'Guest'; + // --- Start with fallback data from URL --- + let user_id = url_params.uuid; + let display_name = url_params.full_name ?? 'Guest'; let email = (url_params.email ?? 'guest@example.com').replace(/\s+/g, '+'); + let is_moderator = false; const room_name = url_params.room ?? 'Default-Room'; const domain = url_params.domain ?? 'jitsi.dgrzone.com'; - const is_moderator = novi_jitsi_mod_li.includes(user_id); + if (!user_id) { + const container = document.getElementById(jitsi_container_id); + if (container) { + container.innerHTML = + '

User ID (uuid) is missing. Cannot start meeting.

'; + } + return; + } + + // --- Fetch dynamic data from Novi API --- + const novi_api_key = 'CmNdWgdPmgluBWjiTd8xsUCk5mio8F1O9DYAh0pVDcg='; + const novi_api_headers = new Headers(); + novi_api_headers.append('Authorization', `Basic ${novi_api_key}`); + const requestOptions = { + method: 'GET', + headers: novi_api_headers + }; + + try { + // Fetch the list of moderators from the Novi group + const mod_group_guid = 'd76d2c00-962d-40f6-a2e8-ed9c85594d96'; + const mod_list_url = `https://www.idaa.org/api/groups/${mod_group_guid}/members?pageSize=200`; + console.log(`Fetching moderator list from Novi API: ${mod_list_url}`); + const mods_response = await fetch(mod_list_url, requestOptions); + + if (mods_response.ok) { + const moderatorsRaw = await mods_response.json(); + console.log('Fetched moderators raw:', moderatorsRaw); + + // Normalise the payload: support both Array and { Results: Array } shapes + let modList: any[] = []; + if (Array.isArray(moderatorsRaw)) { + modList = moderatorsRaw; + } else if (Array.isArray(moderatorsRaw.Results)) { + modList = moderatorsRaw.Results; + } else if (Array.isArray(moderatorsRaw.Members)) { + modList = moderatorsRaw.Members; + } else { + console.warn('Moderator list format is unexpected. Falling back to empty list.', moderatorsRaw); + modList = []; + } + + // Build a set of normalized IDs from a few possible fields + const modIdSet = new Set( + modList + .map((m: any) => (m?.UniqueID ?? m?.UniqueId ?? m?.DuesPayerUniqueID ?? m?.id ?? '')) + .filter(Boolean) + .map((id: string) => id.toLowerCase().trim()) + ); + + const normalizedUserId = String(user_id ?? '').toLowerCase().trim(); + + console.log(`Moderator IDs (${modIdSet.size}) sample:`, Array.from(modIdSet).slice(0, 10)); + if (normalizedUserId && modIdSet.has(normalizedUserId)) { + is_moderator = true; + console.log(`User ${user_id} is a moderator (matched by UniqueID).`); + } else { + // Also check by matching name/email if needed (optional) + console.log(`User ${user_id} is not a moderator.`); + } + } else { + console.warn('Could not fetch moderator list from Novi API.'); + } + } catch (error) { + console.error('Error fetching data from Novi API:', error); + // Fallback to data from URL params is the default behavior + } + + // --- Initialize Jitsi --- let jwtToken = null; if (is_moderator) { jwtToken = await getJitsiJwt(display_name, email, is_moderator, room_name, user_id); diff --git a/src/routes/idaa/+layout.svelte b/src/routes/idaa/+layout.svelte index 9ae30fd5..9b2f164c 100644 --- a/src/routes/idaa/+layout.svelte +++ b/src/routes/idaa/+layout.svelte @@ -41,12 +41,12 @@ let { data, children }: Props = $props(); - if (browser) { - add_activity_log({ - action: 'idaa_root_layout', - action_with: 'browser' - }); - } + // if (browser) { + // add_activity_log({ + // action: 'idaa_root_layout', + // action_with: 'browser' + // }); + // } function add_activity_log({ action = 'idaa_root_layout',