Cleaning up the code for this page. Separate out the Novi calls.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
/** @type {import('./$types').LayoutData} */
|
/** @type {import('./$types').LayoutData} */
|
||||||
// /** @type {import('./$types').LayoutProps} */
|
// /** @type {import('./$types').LayoutProps} */
|
||||||
|
|
||||||
let log_lvl: number = 1;
|
let log_lvl: number = 0;
|
||||||
|
|
||||||
// *** Import Svelte specific
|
// *** Import Svelte specific
|
||||||
// import { tick } from 'svelte';
|
// import { tick } from 'svelte';
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
let jitsi_api: any = null;
|
let jitsi_api: any = null;
|
||||||
const jitsi_container_id = 'jitsi_meet_external_api_container';
|
const jitsi_container_id = 'jitsi_meet_external_api_container';
|
||||||
|
|
||||||
async function getJitsiJwt(
|
async function get_jitsi_jwt(
|
||||||
display_name: string,
|
display_name: string,
|
||||||
email: string,
|
email: string,
|
||||||
is_moderator: boolean,
|
is_moderator: boolean,
|
||||||
@@ -75,132 +75,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(() => {
|
||||||
console.log('Jitsi: onMount - starting initialization...');
|
init_jitsi();
|
||||||
const url_params = data.params;
|
|
||||||
console.log('Jitsi: url_params:', url_params);
|
|
||||||
|
|
||||||
// --- Start with fallback data from URL ---
|
|
||||||
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
|
|
||||||
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}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!user_id) {
|
|
||||||
const container = document.getElementById(jitsi_container_id);
|
|
||||||
if (container) {
|
|
||||||
container.innerHTML = '<h1>User ID (uuid) is missing. Cannot start meeting.</h1>';
|
|
||||||
}
|
|
||||||
console.error('Jitsi: User ID (uuid) is missing. Cannot start meeting.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- 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;
|
|
||||||
|
|
||||||
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}`);
|
|
||||||
}
|
|
||||||
if (member_details.email) {
|
|
||||||
email = member_details.email;
|
|
||||||
console.log(`Jitsi: Updated email based on Novi: ${email}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for moderator status
|
|
||||||
const novi_idaa_group_guid_li = $ae_loc.site_cfg_json?.novi_idaa_group_guid_li ?? [];
|
|
||||||
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)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (normalizedUserId && moderatorIdSet.has(normalizedUserId)) {
|
|
||||||
is_moderator = true;
|
|
||||||
console.log(`Jitsi: User ${user_id} is a moderator.`);
|
|
||||||
} else {
|
|
||||||
console.log(`Jitsi: User ${user_id} is not a moderator.`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.warn(
|
|
||||||
'Jitsi: Novi API URL or Key is not configured. Skipping user details fetch and moderator check.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- Initialize Jitsi ---
|
|
||||||
let jwt_token = null;
|
|
||||||
console.log(`Jitsi: User is_moderator: ${is_moderator}`);
|
|
||||||
if (is_moderator) {
|
|
||||||
console.log('Jitsi: Attempting to get JWT token for moderator...');
|
|
||||||
jwt_token = await getJitsiJwt(display_name, email, is_moderator, room_name, user_id);
|
|
||||||
if (!jwt_token) {
|
|
||||||
const container = document.getElementById(jitsi_container_id);
|
|
||||||
if (container) {
|
|
||||||
container.innerHTML = '<h1>Authentication Failed. Please try again.</h1>';
|
|
||||||
}
|
|
||||||
console.error('Jitsi: Authentication failed. JWT token not received.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
console.log('Jitsi: Successfully received JWT token.');
|
|
||||||
} else {
|
|
||||||
console.log('Jitsi: User is not a moderator, proceeding without JWT token.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const disabled_sounds = [
|
|
||||||
url_params.incoming_msg_sound === 'true' ? 'INCOMING_MSG_SOUND' : null,
|
|
||||||
url_params.participant_joined_sound === 'true' ? 'PARTICIPANT_JOINED_SOUND' : null,
|
|
||||||
url_params.participant_left_sound === 'true' ? 'PARTICIPANT_LEFT_SOUND' : null,
|
|
||||||
url_params.reaction_sound === 'true' ? 'REACTION_SOUND' : null,
|
|
||||||
url_params.raise_hand_sound === 'true' ? 'RAISE_HAND_SOUND' : null
|
|
||||||
].filter((sound) => sound);
|
|
||||||
|
|
||||||
console.log('Jitsi: Jitsi options being set up...');
|
|
||||||
const options = {
|
|
||||||
roomName: room_name,
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
parentNode: document.getElementById(jitsi_container_id),
|
|
||||||
userInfo: { displayName: display_name, email: email },
|
|
||||||
configOverwrite: {
|
|
||||||
prejoinPageEnabled: false,
|
|
||||||
startWithAudioMuted: true,
|
|
||||||
startWithVideoMuted: true,
|
|
||||||
enableLobby: is_moderator,
|
|
||||||
disableReactionsModeration: false,
|
|
||||||
disabledSounds: disabled_sounds
|
|
||||||
},
|
|
||||||
interfaceConfigOverwrite: {
|
|
||||||
DISABLE_JOIN_LEAVE_NOTIFICATIONS: true,
|
|
||||||
NOTIFICATION_SOUND_URL: ''
|
|
||||||
},
|
|
||||||
jwt: jwt_token
|
|
||||||
};
|
|
||||||
console.log('Jitsi: Jitsi options:', options);
|
|
||||||
|
|
||||||
console.log('Jitsi: Initializing JitsiMeetExternalAPI...');
|
|
||||||
// @ts-ignore
|
|
||||||
jitsi_api = new JitsiMeetExternalAPI(domain, options);
|
|
||||||
console.log('Jitsi: JitsiMeetExternalAPI initialized:', jitsi_api);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
if (jitsi_api) {
|
if (jitsi_api) {
|
||||||
|
console.log('Jitsi: Disposing of Jitsi API instance on component destroy.');
|
||||||
jitsi_api.dispose();
|
jitsi_api.dispose();
|
||||||
|
jitsi_api = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -320,10 +203,126 @@
|
|||||||
return modIdSet;
|
return modIdSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes or re-initializes the Jitsi meeting.
|
||||||
|
* This function handles fetching user/moderator data, getting JWTs, and configuring/loading the Jitsi external API.
|
||||||
|
* If an existing Jitsi instance is present, it will be disposed of before creating a new one.
|
||||||
|
*/
|
||||||
|
async function init_jitsi() {
|
||||||
|
// Dispose of any existing Jitsi instance to allow for a clean restart
|
||||||
|
if (jitsi_api) {
|
||||||
|
console.log('Jitsi: Disposing of existing Jitsi API instance before re-initialization.');
|
||||||
|
jitsi_api.dispose();
|
||||||
|
jitsi_api = null;
|
||||||
|
}
|
||||||
|
|
||||||
// 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.
|
console.log('Jitsi: Starting initialization...');
|
||||||
function init_jitsi() {
|
const url_params = data.params;
|
||||||
// Placeholder for code from onMount
|
console.log('Jitsi: url_params:', url_params);
|
||||||
|
|
||||||
|
// --- Start with fallback data from URL ---
|
||||||
|
user_id = url_params.uuid; // Novi Customer GUID
|
||||||
|
display_name = url_params.full_name ?? 'Guest'; // May be overridden
|
||||||
|
email = (url_params.email ?? 'guest@example.com').replace(/\s+/g, '+'); // May be overridden
|
||||||
|
room_name = url_params.room ?? 'Default-Room';
|
||||||
|
domain = url_params.domain ?? 'jitsi.dgrzone.com';
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`Jitsi: Initial data: 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>';
|
||||||
|
}
|
||||||
|
console.error('Jitsi: User ID (uuid) is missing. Cannot start meeting.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 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;
|
||||||
|
|
||||||
|
if (novi_api_root_url && novi_api_key) {
|
||||||
|
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 from Novi: ${display_name}`);
|
||||||
|
}
|
||||||
|
if (member_details.email) {
|
||||||
|
email = member_details.email;
|
||||||
|
console.log(`Jitsi: Updated email from Novi: ${email}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const novi_idaa_group_guid_li = $ae_loc.site_cfg_json?.novi_idaa_group_guid_li ?? [];
|
||||||
|
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();
|
||||||
|
|
||||||
|
if (normalizedUserId && moderatorIdSet.has(normalizedUserId)) {
|
||||||
|
is_moderator = true;
|
||||||
|
console.log(`Jitsi: User ${user_id} is a moderator.`);
|
||||||
|
} else {
|
||||||
|
is_moderator = false; // Explicitly set to false if not in the set
|
||||||
|
console.log(`Jitsi: User ${user_id} is not a moderator.`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.warn('Jitsi: Novi API not configured. Skipping user details/moderator check.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Initialize Jitsi ---
|
||||||
|
let jwt_token = null;
|
||||||
|
if (is_moderator) {
|
||||||
|
console.log('Jitsi: Attempting to get JWT for moderator...');
|
||||||
|
jwt_token = await get_jitsi_jwt(display_name, email, is_moderator, room_name, user_id);
|
||||||
|
if (!jwt_token) {
|
||||||
|
const container = document.getElementById(jitsi_container_id);
|
||||||
|
if (container) container.innerHTML = '<h1>Authentication Failed. Please try again.</h1>';
|
||||||
|
console.error('Jitsi: Authentication failed. JWT not received.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log('Jitsi: Successfully received JWT.');
|
||||||
|
} else {
|
||||||
|
console.log('Jitsi: Not a moderator, proceeding without JWT.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const disabled_sounds = [
|
||||||
|
url_params.incoming_msg_sound === 'true' ? 'INCOMING_MSG_SOUND' : null,
|
||||||
|
url_params.participant_joined_sound === 'true' ? 'PARTICIPANT_JOINED_SOUND' : null,
|
||||||
|
url_params.participant_left_sound === 'true' ? 'PARTICIPANT_LEFT_SOUND' : null,
|
||||||
|
url_params.reaction_sound === 'true' ? 'REACTION_SOUND' : null,
|
||||||
|
url_params.raise_hand_sound === 'true' ? 'RAISE_HAND_SOUND' : null
|
||||||
|
].filter((sound) => sound);
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
roomName: room_name,
|
||||||
|
width: '100%',
|
||||||
|
height: '100%',
|
||||||
|
parentNode: document.getElementById(jitsi_container_id),
|
||||||
|
userInfo: { displayName: display_name, email: email },
|
||||||
|
configOverwrite: {
|
||||||
|
prejoinPageEnabled: false,
|
||||||
|
startWithAudioMuted: true,
|
||||||
|
startWithVideoMuted: true,
|
||||||
|
enableLobby: is_moderator,
|
||||||
|
disableReactionsModeration: false,
|
||||||
|
disabledSounds: disabled_sounds
|
||||||
|
},
|
||||||
|
interfaceConfigOverwrite: {
|
||||||
|
DISABLE_JOIN_LEAVE_NOTIFICATIONS: true,
|
||||||
|
NOTIFICATION_SOUND_URL: ''
|
||||||
|
},
|
||||||
|
jwt: jwt_token
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log('Jitsi: Initializing JitsiMeetExternalAPI with options:', options);
|
||||||
|
// @ts-ignore
|
||||||
|
jitsi_api = new JitsiMeetExternalAPI(domain, options);
|
||||||
|
console.log('Jitsi: JitsiMeetExternalAPI initialized:', jitsi_api);
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@@ -337,23 +336,67 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if show_jitsi_tools}
|
{#if show_jitsi_tools}
|
||||||
<div class="jitsi-tools text-sm">
|
<div class="jitsi-tools text-sm max-w-xl">
|
||||||
<p><strong>Jitsi Tools</strong></p>
|
<h1 class="text-base">Jitsi Tools and Settings</h1>
|
||||||
|
<ul>
|
||||||
{#if display_name && email}
|
{#if display_name && email}
|
||||||
<p class="z-50 bg-amber-50">{display_name} ({email})</p>
|
<li class="z-50 bg-amber-50">{display_name} ({email})</li>
|
||||||
{/if}
|
{/if}
|
||||||
<p>Room: {room_name}</p>
|
<li>Room: {room_name}</li>
|
||||||
<p>Domain: {domain}</p>
|
<li>Domain: {domain}</li>
|
||||||
<p>User ID: {user_id}</p>
|
<li>User ID: {user_id}</li>
|
||||||
<p>Moderator: {is_moderator ? 'Yes' : 'No'}</p>
|
<li>Moderator: {is_moderator ? 'Yes' : 'No'}</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<!-- margin-top: 1.5em; border-top: 2px dashed #ccc; padding: 1em; background-color: pink; -->
|
||||||
|
<div
|
||||||
|
class="
|
||||||
|
mt-2 pt-2 border-t-2 border-dashed border-gray-400
|
||||||
|
flex flex-col lg:flex-row gap-05
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<strong>Jitsi Sound Settings:</strong>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="incoming_msg_sound_checkbox" checked disabled />
|
||||||
|
Disable Incoming Message Sound
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="participant_joined_sound_checkbox" disabled />
|
||||||
|
Disable Participant Joined Sound
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="participant_left_sound_checkbox" disabled />
|
||||||
|
Disable Participant Left Sound
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="reaction_sound_checkbox" checked disabled />
|
||||||
|
Disable Reaction Sound
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="raise_hand_sound_checkbox" checked disabled />
|
||||||
|
Disable Raise Hand Sound
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="mt-2 px-2 py-1 bg-orange-500 text-white rounded hover:bg-orange-600"
|
||||||
|
onclick={() => init_jitsi()}
|
||||||
|
>
|
||||||
|
Re-initialize Jitsi
|
||||||
|
</button>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
class="mt-2 px-2 py-1 bg-blue-500 text-white rounded hover:bg-blue-600"
|
class="mt-2 px-2 py-1 bg-blue-500 text-white rounded hover:bg-blue-600"
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
// Placeholder for re-initialization logic
|
// Placeholder for function calls to update Novi data
|
||||||
// Should the member details and group lists be re-fetched too?
|
console.log('Re-sync Novi Data button clicked. Implement as needed.');
|
||||||
// init_jitsi();
|
|
||||||
}}
|
}}
|
||||||
>Re-initialize Jitsi</button>
|
>
|
||||||
|
Re-sync Novi Data
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user