This seems like a good pause point. The new Jitsi reports page is functional. The meetings log various activities and events.
This commit is contained in:
115
src/lib/ae_reports/reports_functions.ts
Normal file
115
src/lib/ae_reports/reports_functions.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
import type { key_val } from '$lib/stores/ae_stores';
|
||||
import { api } from '$lib/api/api';
|
||||
|
||||
/**
|
||||
* @description Queries all Jitsi-related activity logs and processes them into a structured report,
|
||||
* grouped by meeting ID.
|
||||
* @param api_cfg The API configuration object.
|
||||
* @param account_id The account ID to query against.
|
||||
* @param log_lvl The logging level.
|
||||
* @returns A structured array of meeting report objects.
|
||||
*/
|
||||
export async function load_jitsi_report({
|
||||
api_cfg,
|
||||
account_id,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
account_id: string;
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) console.log('*** load_jitsi_report() ***');
|
||||
|
||||
// Step 1: Query all relevant activity logs from the API.
|
||||
const params_json = {
|
||||
or_qry: [
|
||||
{
|
||||
field: 'name',
|
||||
operator: '=',
|
||||
value: 'jitsi_meeting_stats_update'
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
operator: '=',
|
||||
value: 'jitsi_meeting_event'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const flat_log_list = await api.get_ae_obj_li_for_obj_id_crud_v2({
|
||||
api_cfg: api_cfg,
|
||||
obj_type: 'activity_log',
|
||||
for_obj_type: 'account',
|
||||
for_obj_id: account_id,
|
||||
// use_alt_tbl: true,
|
||||
// use_alt_mdl: true,
|
||||
enabled: 'all',
|
||||
hidden: 'all',
|
||||
// order_by_li: { created_on: 'DESC' },
|
||||
limit: 500, // Fetch a reasonable number of recent logs
|
||||
// order_by_li: { created_on: 'DESC' },
|
||||
// params_json: params_json,
|
||||
log_lvl: 2
|
||||
});
|
||||
|
||||
if (!flat_log_list || flat_log_list.length === 0) {
|
||||
if (log_lvl) console.log('No Jitsi activity logs found.');
|
||||
return [];
|
||||
}
|
||||
|
||||
// Step 2: Process the flat list into a structured report.
|
||||
const meetings = new Map<string, any>();
|
||||
|
||||
for (const log of flat_log_list) {
|
||||
const meeting_id = log.external_client_id;
|
||||
if (!meeting_id) continue;
|
||||
|
||||
// Make sure the name field is prefixed with "jitsi_"
|
||||
if (!log.name.startsWith('jitsi_')) continue;
|
||||
|
||||
// Ensure a base entry for the meeting exists
|
||||
if (!meetings.has(meeting_id)) {
|
||||
meetings.set(meeting_id, {
|
||||
meeting_id: meeting_id,
|
||||
room_name: 'Unknown',
|
||||
start_time: log.created_on, // Fallback start time
|
||||
final_duration: '00:00:00',
|
||||
final_participants: [],
|
||||
final_participant_count: 0,
|
||||
events: []
|
||||
});
|
||||
}
|
||||
|
||||
const meeting_report = meetings.get(meeting_id);
|
||||
|
||||
if (log.action === 'jitsi_meeting_init') {
|
||||
// This is the main log entry, containing the final state.
|
||||
meeting_report.room_name = log.description;
|
||||
meeting_report.start_time = log.created_on; // The init log has the true start time
|
||||
if (log.meta_json) {
|
||||
meeting_report.final_duration = log.meta_json.duration;
|
||||
meeting_report.final_participants = log.meta_json.participants;
|
||||
meeting_report.final_participant_count = log.meta_json.participant_count;
|
||||
}
|
||||
} else {
|
||||
// This is a discrete event log.
|
||||
meeting_report.events.push({
|
||||
timestamp: log.created_on,
|
||||
action: log.action,
|
||||
details: log.meta_json
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Sort events within each meeting chronologically
|
||||
for (const report of meetings.values()) {
|
||||
report.events.sort((a: any, b: any) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
||||
}
|
||||
|
||||
const final_report = Array.from(meetings.values());
|
||||
final_report.sort((a,b) => new Date(b.start_time).getTime() - new Date(a.start_time).getTime());
|
||||
|
||||
if (log_lvl) console.log('Final Jitsi report:', final_report);
|
||||
|
||||
return final_report;
|
||||
}
|
||||
Reference in New Issue
Block a user