Saving changes as we keep cleaning up the Novi specific code.
This commit is contained in:
@@ -84,17 +84,17 @@
|
||||
user_id = url_params.uuid; // Novi Customer GUID
|
||||
display_name = url_params.full_name ?? 'Guest'; // May be overridden after fetching from Novi API
|
||||
email = (url_params.email ?? 'guest@example.com').replace(/\s+/g, '+'); // May be overridden after fetching from Novi API
|
||||
// is_moderator = false; // May be overridden after fetching from Novi API
|
||||
room_name = url_params.room ?? 'Default-Room';
|
||||
domain = url_params.domain ?? 'jitsi.dgrzone.com';
|
||||
|
||||
console.log(`Jitsi: From URL params for: user_id: ${user_id}, display_name: ${display_name}, email: ${email}, room_name: ${room_name}, domain: ${domain}`);
|
||||
console.log(
|
||||
`Jitsi: From URL params for: user_id: ${user_id}, display_name: ${display_name}, email: ${email}, room_name: ${room_name}, domain: ${domain}`
|
||||
);
|
||||
|
||||
if (!user_id) {
|
||||
const container = document.getElementById(jitsi_container_id);
|
||||
if (container) {
|
||||
container.innerHTML =
|
||||
'<h1>User ID (uuid) is missing. Cannot start meeting.</h1>';
|
||||
container.innerHTML = '<h1>User ID (uuid) is missing. Cannot start meeting.</h1>';
|
||||
}
|
||||
console.error('Jitsi: User ID (uuid) is missing. Cannot start meeting.');
|
||||
return;
|
||||
@@ -102,107 +102,44 @@
|
||||
|
||||
// --- Fetch dynamic data from Novi API ---
|
||||
const novi_api_root_url = $ae_loc.site_cfg_json?.novi_api_root_url;
|
||||
const novi_api_key = $ae_loc.site_cfg_json?.novi_idaa_api_key; // For IDAA's Novi site
|
||||
const novi_api_headers = new Headers();
|
||||
novi_api_headers.append('Authorization', `Basic ${novi_api_key}`);
|
||||
const requestOptions = {
|
||||
method: 'GET',
|
||||
headers: novi_api_headers
|
||||
};
|
||||
const novi_api_key = $ae_loc.site_cfg_json?.novi_idaa_api_key;
|
||||
|
||||
console.log('Jitsi: Attempting to fetch IDAA member (Novi customer) details based on Novi customer GUID using Novi API...');
|
||||
|
||||
const full_novi_url_customers_guid = `${novi_api_root_url}/customers/${user_id}`;
|
||||
|
||||
await fetch(full_novi_url_customers_guid, requestOptions)
|
||||
.then((response) => response.json())
|
||||
.then((result) => {
|
||||
let novi_current_user_obj = result;
|
||||
console.log(`Jitsi: Novi's Current User Obj:`, novi_current_user_obj);
|
||||
|
||||
let full_name = novi_current_user_obj?.Name;
|
||||
let first_name = novi_current_user_obj?.FirstName;
|
||||
let last_initial = novi_current_user_obj?.LastName
|
||||
? novi_current_user_obj.LastName.charAt(0).toUpperCase() + '.'
|
||||
: '';
|
||||
if (last_initial) {
|
||||
full_name = `${first_name} ${last_initial}`;
|
||||
if (novi_api_root_url && novi_api_key) {
|
||||
// Update user details from Novi
|
||||
const member_details = await get_novi_member_details(user_id, novi_api_root_url, novi_api_key);
|
||||
if (member_details.display_name) {
|
||||
display_name = member_details.display_name;
|
||||
console.log(`Jitsi: Updated display_name based on Novi: ${display_name}`);
|
||||
}
|
||||
|
||||
let novi_email = novi_current_user_obj?.Email;
|
||||
if (novi_email) {
|
||||
email = novi_email.replace(/\s+/g, '+');
|
||||
if (member_details.email) {
|
||||
email = member_details.email;
|
||||
console.log(`Jitsi: Updated email based on Novi: ${email}`);
|
||||
}
|
||||
|
||||
display_name = full_name;
|
||||
console.log(`Jitsi: Updated display_name and email based on Novi: ${full_name} / ${email}`);
|
||||
})
|
||||
.catch((error) => console.log('error', error));
|
||||
|
||||
console.log('Jitsi: Attempting to fetch moderator (Novi group members) list based on Novi group GUID using Novi API... There may be multiple groups to check.');
|
||||
|
||||
try {
|
||||
// Fetch the list of moderators from the Novi group
|
||||
// Check for moderator status
|
||||
const novi_idaa_group_guid_li = $ae_loc.site_cfg_json?.novi_idaa_group_guid_li ?? [];
|
||||
let allModeratorsRaw: any[] = [];
|
||||
|
||||
if (novi_idaa_group_guid_li.length === 0) {
|
||||
console.warn('Jitsi: novi_idaa_group_guid_li is empty. No moderator groups to check.');
|
||||
}
|
||||
|
||||
for (const group_guid of novi_idaa_group_guid_li) {
|
||||
// const novi_url_groups_members = `/groups/members/${group_guid}/members`;
|
||||
const full_novi_url_groups_members = `${novi_api_root_url}/groups/${group_guid}/members?pageSize=200`;
|
||||
console.log(`Jitsi: Fetching moderator list from Novi API for group: ${group_guid} from URL: ${full_novi_url_groups_members}`);
|
||||
|
||||
const mods_response = await fetch(full_novi_url_groups_members, requestOptions);
|
||||
|
||||
if (mods_response.ok) {
|
||||
const groupModeratorsRaw = await mods_response.json();
|
||||
// Normalize the payload and combine
|
||||
let groupModList: any[] = [];
|
||||
if (Array.isArray(groupModeratorsRaw)) {
|
||||
groupModList = groupModeratorsRaw;
|
||||
} else if (Array.isArray(groupModeratorsRaw.Results)) {
|
||||
groupModList = groupModeratorsRaw.Results;
|
||||
} else if (Array.isArray(groupModeratorsRaw.Members)) {
|
||||
groupModList = groupModeratorsRaw.Members;
|
||||
} else {
|
||||
console.warn(`Jitsi: Moderator list format is unexpected for group ${group_guid}. Falling back to empty list for this group.`, groupModeratorsRaw);
|
||||
}
|
||||
allModeratorsRaw = allModeratorsRaw.concat(groupModList);
|
||||
console.log(`Jitsi: Fetched ${groupModList.length} moderators from group ${group_guid}. Total: ${allModeratorsRaw.length}`);
|
||||
} else {
|
||||
console.warn(`Jitsi: Could not fetch moderator list from Novi API for group: ${group_guid}. Status: ${mods_response.status}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (allModeratorsRaw.length === 0) {
|
||||
console.warn('Jitsi: No moderators fetched across all specified Novi groups. Falling back to empty list.');
|
||||
}
|
||||
console.log('Jitsi: Fetched all moderators raw (combined):', allModeratorsRaw);
|
||||
|
||||
// Build a set of normalized IDs from a few possible fields using allModeratorsRaw
|
||||
const modIdSet = new Set(
|
||||
allModeratorsRaw
|
||||
.map((m: any) => (m?.UniqueID ?? m?.UniqueId ?? m?.DuesPayerUniqueID ?? m?.id ?? ''))
|
||||
.filter(Boolean)
|
||||
.map((id: string) => id.toLowerCase().trim())
|
||||
const moderatorIdSet = await get_novi_group_moderators(
|
||||
novi_idaa_group_guid_li,
|
||||
novi_api_root_url,
|
||||
novi_api_key
|
||||
);
|
||||
|
||||
const normalizedUserId = String(user_id ?? '').toLowerCase().trim();
|
||||
console.log(
|
||||
`Jitsi: Moderator IDs (${moderatorIdSet.size}) sample:`,
|
||||
Array.from(moderatorIdSet).slice(0, 10)
|
||||
);
|
||||
|
||||
console.log(`Jitsi: Moderator IDs (${modIdSet.size}) sample:`, Array.from(modIdSet).slice(0, 10));
|
||||
if (normalizedUserId && modIdSet.has(normalizedUserId)) {
|
||||
if (normalizedUserId && moderatorIdSet.has(normalizedUserId)) {
|
||||
is_moderator = true;
|
||||
console.log(`Jitsi: User ${user_id} is a moderator (matched by UniqueID).`);
|
||||
console.log(`Jitsi: User ${user_id} is a moderator.`);
|
||||
} else {
|
||||
console.log(`Jitsi: User ${user_id} is not a moderator.`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Jitsi: Error fetching data from Novi API:', error);
|
||||
// Fallback to data from URL params is the default behavior
|
||||
} else {
|
||||
console.warn(
|
||||
'Jitsi: Novi API URL or Key is not configured. Skipping user details fetch and moderator check.'
|
||||
);
|
||||
}
|
||||
|
||||
// --- Initialize Jitsi ---
|
||||
@@ -267,44 +204,157 @@
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Fetches member details from the Novi API.
|
||||
* @param user_id - The Novi Customer GUID.
|
||||
* @param api_root_url - The root URL of the Novi API.
|
||||
* @param api_key - The API key for authorization.
|
||||
* @returns An object with the user's display name and email, or null if not found.
|
||||
*/
|
||||
async function get_novi_member_details(
|
||||
user_id: string,
|
||||
api_root_url: string,
|
||||
api_key: string
|
||||
): Promise<{ display_name: string | null; email: string | null }> {
|
||||
if (!user_id || !api_root_url || !api_key) {
|
||||
console.error('get_novi_member_details: Missing required arguments.');
|
||||
return { display_name: null, email: null };
|
||||
}
|
||||
|
||||
// Get Novi member details
|
||||
// args: novi_customer_uid
|
||||
// returns: novi member object
|
||||
function get_novi_member_details() {
|
||||
// Placeholder function if needed in the future
|
||||
const headers = new Headers();
|
||||
headers.append('Authorization', `Basic ${api_key}`);
|
||||
const requestOptions = { method: 'GET', headers: headers };
|
||||
const url = `${api_root_url}/customers/${user_id}`;
|
||||
|
||||
console.log('Jitsi: Fetching Novi member details from:', url);
|
||||
|
||||
try {
|
||||
const response = await fetch(url, requestOptions);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Novi API request failed with status ${response.status}`);
|
||||
}
|
||||
const result = await response.json();
|
||||
console.log(`Jitsi: Novi's Current User Obj:`, result);
|
||||
|
||||
let full_name = result?.Name;
|
||||
const first_name = result?.FirstName;
|
||||
const last_initial = result?.LastName ? `${result.LastName.charAt(0).toUpperCase()}.` : '';
|
||||
|
||||
if (first_name && last_initial) {
|
||||
full_name = `${first_name} ${last_initial}`;
|
||||
}
|
||||
|
||||
const novi_email = result?.Email ? result.Email.replace(/\s+/g, '+') : null;
|
||||
|
||||
return { display_name: full_name, email: novi_email };
|
||||
} catch (error) {
|
||||
console.error('Error fetching Novi member details:', error);
|
||||
return { display_name: null, email: null };
|
||||
}
|
||||
}
|
||||
|
||||
// Get Novi group moderators
|
||||
// args: novi_group_guid
|
||||
// returns: array of novi member objects
|
||||
function get_novi_group_moderators() {
|
||||
// Placeholder function if needed in the future
|
||||
/**
|
||||
* Fetches a set of moderator IDs from Novi group(s).
|
||||
* @param group_guid_li - A list of Novi group GUIDs to check for moderators.
|
||||
* @param api_root_url - The root URL of the Novi API.
|
||||
* @param api_key - The API key for authorization.
|
||||
* @returns A Set of normalized (lowercase, trimmed) moderator UniqueIDs.
|
||||
*/
|
||||
async function get_novi_group_moderators(
|
||||
group_guid_li: string[],
|
||||
api_root_url: string,
|
||||
api_key: string
|
||||
): Promise<Set<string>> {
|
||||
if (!group_guid_li || group_guid_li.length === 0 || !api_root_url || !api_key) {
|
||||
console.warn('get_novi_group_moderators: Missing required arguments or empty group list.');
|
||||
return new Set();
|
||||
}
|
||||
|
||||
const headers = new Headers();
|
||||
headers.append('Authorization', `Basic ${api_key}`);
|
||||
const requestOptions = { method: 'GET', headers: headers };
|
||||
let allModeratorsRaw: any[] = [];
|
||||
|
||||
console.log('Jitsi: Fetching Novi group moderators...');
|
||||
|
||||
for (const group_guid of group_guid_li) {
|
||||
const url = `${api_root_url}/groups/${group_guid}/members?pageSize=200`;
|
||||
console.log(`Jitsi: Fetching moderator list for group ${group_guid} from: ${url}`);
|
||||
|
||||
try {
|
||||
const response = await fetch(url, requestOptions);
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
let groupModList: any[] = [];
|
||||
|
||||
if (Array.isArray(result)) groupModList = result;
|
||||
else if (Array.isArray(result.Results)) groupModList = result.Results;
|
||||
else if (Array.isArray(result.Members)) groupModList = result.Members;
|
||||
else console.warn(`Jitsi: Moderator list format unexpected for group ${group_guid}.`, result);
|
||||
|
||||
allModeratorsRaw = allModeratorsRaw.concat(groupModList);
|
||||
console.log(
|
||||
`Jitsi: Fetched ${groupModList.length} moderators from group ${group_guid}. Total: ${allModeratorsRaw.length}`
|
||||
);
|
||||
} else {
|
||||
console.warn(
|
||||
`Jitsi: Failed to fetch moderators for group ${group_guid}. Status: ${response.status}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Jitsi: Error fetching moderators for group ${group_guid}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
if (allModeratorsRaw.length === 0) {
|
||||
console.warn('Jitsi: No moderators found across all specified Novi groups.');
|
||||
}
|
||||
console.log('Jitsi: Fetched all raw moderators (combined):', allModeratorsRaw);
|
||||
|
||||
const modIdSet = new Set(
|
||||
allModeratorsRaw
|
||||
.map((m: any) => m?.UniqueID ?? m?.UniqueId ?? m?.DuesPayerUniqueID ?? m?.id ?? '')
|
||||
.filter(Boolean)
|
||||
.map((id: string) => String(id).toLowerCase().trim())
|
||||
);
|
||||
return modIdSet;
|
||||
}
|
||||
|
||||
|
||||
// Move the code from onMount to here so that it can be called multiple times. There will be a reset/restart button later. The users should also be able to change a few setting that may require a re-init.
|
||||
function init_jitsi() {
|
||||
// Placeholder for code from onMount
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<script src="https://jitsi.dgrzone.com/external_api.js"></script>
|
||||
</svelte:head>
|
||||
|
||||
|
||||
{#if show_jitsi_container}
|
||||
<div id="{jitsi_container_id}" class="jitsi-container"></div>
|
||||
<div id="{jitsi_container_id}" class="jitsi-container"></div>
|
||||
{/if}
|
||||
|
||||
{#if show_jitsi_tools}
|
||||
<div class="jitsi-tools text-sm">
|
||||
<p><strong>Jitsi Tools</strong></p>
|
||||
{#if display_name && email}
|
||||
<p class="z-50 bg-amber-50">{display_name} ({email})</p>
|
||||
{/if}
|
||||
<p>Room: {room_name}</p>
|
||||
<p>Domain: {domain}</p>
|
||||
<p>User ID: {user_id}</p>
|
||||
<p>Moderator: {is_moderator ? 'Yes' : 'No'}</p>
|
||||
</div>
|
||||
<div class="jitsi-tools text-sm">
|
||||
<p><strong>Jitsi Tools</strong></p>
|
||||
{#if display_name && email}
|
||||
<p class="z-50 bg-amber-50">{display_name} ({email})</p>
|
||||
{/if}
|
||||
<p>Room: {room_name}</p>
|
||||
<p>Domain: {domain}</p>
|
||||
<p>User ID: {user_id}</p>
|
||||
<p>Moderator: {is_moderator ? 'Yes' : 'No'}</p>
|
||||
<button
|
||||
class="mt-2 px-2 py-1 bg-blue-500 text-white rounded hover:bg-blue-600"
|
||||
onclick={() => {
|
||||
// Placeholder for re-initialization logic
|
||||
// Should the member details and group lists be re-fetched too?
|
||||
// init_jitsi();
|
||||
}}
|
||||
>Re-initialize Jitsi</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
@@ -327,4 +377,4 @@
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user