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
|
user_id = url_params.uuid; // Novi Customer GUID
|
||||||
display_name = url_params.full_name ?? 'Guest'; // May be overridden after fetching from Novi API
|
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
|
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';
|
room_name = url_params.room ?? 'Default-Room';
|
||||||
domain = url_params.domain ?? 'jitsi.dgrzone.com';
|
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) {
|
if (!user_id) {
|
||||||
const container = document.getElementById(jitsi_container_id);
|
const container = document.getElementById(jitsi_container_id);
|
||||||
if (container) {
|
if (container) {
|
||||||
container.innerHTML =
|
container.innerHTML = '<h1>User ID (uuid) is missing. Cannot start meeting.</h1>';
|
||||||
'<h1>User ID (uuid) is missing. Cannot start meeting.</h1>';
|
|
||||||
}
|
}
|
||||||
console.error('Jitsi: User ID (uuid) is missing. Cannot start meeting.');
|
console.error('Jitsi: User ID (uuid) is missing. Cannot start meeting.');
|
||||||
return;
|
return;
|
||||||
@@ -102,107 +102,44 @@
|
|||||||
|
|
||||||
// --- Fetch dynamic data from Novi API ---
|
// --- Fetch dynamic data from Novi API ---
|
||||||
const novi_api_root_url = $ae_loc.site_cfg_json?.novi_api_root_url;
|
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_key = $ae_loc.site_cfg_json?.novi_idaa_api_key;
|
||||||
const novi_api_headers = new Headers();
|
|
||||||
novi_api_headers.append('Authorization', `Basic ${novi_api_key}`);
|
|
||||||
const requestOptions = {
|
|
||||||
method: 'GET',
|
|
||||||
headers: novi_api_headers
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log('Jitsi: Attempting to fetch IDAA member (Novi customer) details based on Novi customer GUID using Novi API...');
|
if (novi_api_root_url && novi_api_key) {
|
||||||
|
// Update user details from Novi
|
||||||
const full_novi_url_customers_guid = `${novi_api_root_url}/customers/${user_id}`;
|
const member_details = await get_novi_member_details(user_id, novi_api_root_url, novi_api_key);
|
||||||
|
if (member_details.display_name) {
|
||||||
await fetch(full_novi_url_customers_guid, requestOptions)
|
display_name = member_details.display_name;
|
||||||
.then((response) => response.json())
|
console.log(`Jitsi: Updated display_name based on Novi: ${display_name}`);
|
||||||
.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 (member_details.email) {
|
||||||
let novi_email = novi_current_user_obj?.Email;
|
email = member_details.email;
|
||||||
if (novi_email) {
|
|
||||||
email = novi_email.replace(/\s+/g, '+');
|
|
||||||
console.log(`Jitsi: Updated email based on Novi: ${email}`);
|
console.log(`Jitsi: Updated email based on Novi: ${email}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
display_name = full_name;
|
// Check for moderator status
|
||||||
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
|
|
||||||
const novi_idaa_group_guid_li = $ae_loc.site_cfg_json?.novi_idaa_group_guid_li ?? [];
|
const novi_idaa_group_guid_li = $ae_loc.site_cfg_json?.novi_idaa_group_guid_li ?? [];
|
||||||
let allModeratorsRaw: any[] = [];
|
const moderatorIdSet = await get_novi_group_moderators(
|
||||||
|
novi_idaa_group_guid_li,
|
||||||
if (novi_idaa_group_guid_li.length === 0) {
|
novi_api_root_url,
|
||||||
console.warn('Jitsi: novi_idaa_group_guid_li is empty. No moderator groups to check.');
|
novi_api_key
|
||||||
}
|
|
||||||
|
|
||||||
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 normalizedUserId = String(user_id ?? '').toLowerCase().trim();
|
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 && moderatorIdSet.has(normalizedUserId)) {
|
||||||
if (normalizedUserId && modIdSet.has(normalizedUserId)) {
|
|
||||||
is_moderator = true;
|
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 {
|
} else {
|
||||||
console.log(`Jitsi: User ${user_id} is not a moderator.`);
|
console.log(`Jitsi: User ${user_id} is not a moderator.`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} else {
|
||||||
console.error('Jitsi: Error fetching data from Novi API:', error);
|
console.warn(
|
||||||
// Fallback to data from URL params is the default behavior
|
'Jitsi: Novi API URL or Key is not configured. Skipping user details fetch and moderator check.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Initialize Jitsi ---
|
// --- 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
|
const headers = new Headers();
|
||||||
// args: novi_customer_uid
|
headers.append('Authorization', `Basic ${api_key}`);
|
||||||
// returns: novi member object
|
const requestOptions = { method: 'GET', headers: headers };
|
||||||
function get_novi_member_details() {
|
const url = `${api_root_url}/customers/${user_id}`;
|
||||||
// Placeholder function if needed in the future
|
|
||||||
|
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
|
* Fetches a set of moderator IDs from Novi group(s).
|
||||||
// returns: array of novi member objects
|
* @param group_guid_li - A list of Novi group GUIDs to check for moderators.
|
||||||
function get_novi_group_moderators() {
|
* @param api_root_url - The root URL of the Novi API.
|
||||||
// Placeholder function if needed in the future
|
* @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>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
<script src="https://jitsi.dgrzone.com/external_api.js"></script>
|
<script src="https://jitsi.dgrzone.com/external_api.js"></script>
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
|
|
||||||
{#if show_jitsi_container}
|
{#if show_jitsi_container}
|
||||||
<div id="{jitsi_container_id}" class="jitsi-container"></div>
|
<div id="{jitsi_container_id}" class="jitsi-container"></div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if show_jitsi_tools}
|
{#if show_jitsi_tools}
|
||||||
<div class="jitsi-tools text-sm">
|
<div class="jitsi-tools text-sm">
|
||||||
<p><strong>Jitsi Tools</strong></p>
|
<p><strong>Jitsi Tools</strong></p>
|
||||||
{#if display_name && email}
|
{#if display_name && email}
|
||||||
<p class="z-50 bg-amber-50">{display_name} ({email})</p>
|
<p class="z-50 bg-amber-50">{display_name} ({email})</p>
|
||||||
{/if}
|
{/if}
|
||||||
<p>Room: {room_name}</p>
|
<p>Room: {room_name}</p>
|
||||||
<p>Domain: {domain}</p>
|
<p>Domain: {domain}</p>
|
||||||
<p>User ID: {user_id}</p>
|
<p>User ID: {user_id}</p>
|
||||||
<p>Moderator: {is_moderator ? 'Yes' : 'No'}</p>
|
<p>Moderator: {is_moderator ? 'Yes' : 'No'}</p>
|
||||||
</div>
|
<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}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -327,4 +377,4 @@
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user