* frontend: update icons for Rooms and Recordings in console navigation * frontend: enhance overview component with user stats and improved layout * frontend: implement theme service and design tokens for light/dark mode support - Added ThemeService to manage theme preferences and system theme detection. - Introduced design tokens for consistent styling across light and dark themes. - Updated components to utilize the new navigation service for routing. - Replaced SecurityPreferencesComponent with PreferencesComponent for settings. - Enhanced UI with new styles and improved navigation structure. - Added tests for ThemeService to ensure functionality. * frontend: enhance overview component with title styling and icon integration * frontend: remove unused Router import from overview component * frontend: implement developers settings with API key and webhook configuration * frontend: update styles and structure for console navigation and overview components * frontend: simplify API key checks and integrate notification service for user feedback * frontend: update openvidu-components-angular to version 3.3.0-dev2 and simplify Material Symbols stylesheet link * frontend: adjust padding and gap for stat card and actions in overview component * frontend: update import paths to use relative paths for better module resolution * frontend: enhance sync-types.sh script with advanced options and detailed usage instructions * typings: update TypeScript declaration files and improve sync-types.sh script for better clarity and functionality * webcomponent: webcomponent typings are now moved to typings directory * Revert "typings: update TypeScript declaration files and improve sync-types.sh script for better clarity and functionality" This reverts commit 7da952bc44be20c3f74ffb82bf941b96b78ad019. * typings: improve sync-types.sh script for clarity and consistency * test: update error message for empty downloaded file check * frontend: update outbound event message types in video room and web component manager services * frontend: enhance styling for console component and adjust nav item border radius * style: update comments in disabled class for clarity and consistency; refactor import paths in room-form component * typings: update import paths in message.type.ts to include file extensions * frontend: enhance rooms management interface with improved loading states, search functionality, and table features * frontend: enhance loading state with improved UI and animations for room loading process * frontend: enhance rooms table with auto-deletion feature and improve status display * frontend: update import paths for services and add containsRoute method to NavigationService * frontend: remove unused components and associated files from shared-meet-components * frontend: add logo selector component and enhance preferences settings with access controls * frontend: add SessionStorageService import to extract query params guard * frontend: add margin-bottom utility class to overview container * frontend: update description for creating a room in the overview component * frontend: Added recording list component * frontend: update padding in mat-sidenav entry to use spacing variable * frontend: update text for delete room button to use lowercase * frontend: enhance console navigation with tooltips and active item styling * frontend: refactor styles in console navigation for consistency and improved theming * frontend: add border to card header for improved visual separation * frontend: created room list reusable component * frontend: adjust vertical alignment of table cells in recording lists * frontend: enhance room status and auto-deletion indicators with tooltips and improved styling * frontend: enhance HTTP service methods to include status codes in responses * frontend: fix duration formatting to use integer seconds instead of fixed-point * frontend: refactor icon styles in status badge for consistency * Add modular SCSS structure for design tokens, mixins, animations, and utility classes - Introduced _animations.scss for keyframes and animation utility classes. - Refactored _design-tokens.scss to import modular design system files for better maintainability. - Created _mixins-components.scss for component-specific mixins like cards and buttons. - Added _mixins-layout.scss for layout-related mixins and responsive design utilities. - Established _mixins-responsive.scss for breakpoint mixins to facilitate responsive design. - Introduced _tokens-core.scss for core design tokens including colors, spacing, and typography. - Created _tokens-themes.scss for theme-specific design tokens for light and dark modes. - Added _utilities.scss for reusable utility classes to streamline common styling patterns. * frontend: Refactor styles for settings preferences component and enhance utility classes - Simplified SCSS for preferences.component.scss by utilizing utility classes for layout and styling. - Introduced new utility classes for Material components, including slide toggle and navigation list. - Enhanced form section styling with consistent spacing and layout adjustments. - Added responsive design patterns for toolbar and table components. - Improved loading and empty state styles for better user experience. * frontend: standardize page layout and loading states across components * frontend: enhance status badge and action button styles for consistency * ci: update unit test workflow to include typings setup * test: update import path for WebComponentCommand to typings directory * frontend: refactor dialog component structure and enhance styles for improved accessibility and responsiveness * frontend: rename batchDelete methods to bulkDelete for consistency * frontend: implement confirmation dialog for room deletion with improved error handling * frontend: extract feature-specific API logic from HttpService into dedicated services * frontend: extract common recording actions into RecordingManagerService * frontend: refactor navigation handling for improved consistency * backend: add endpoint to download multiple recordings in a zip file and refactor bulkDeleteRecordings to delete only recordings from the same room if recording token is provided * openapi: add download endpoint for recordings and update bulk delete logic to enforce room constraints * frontend: enhance recording media URL generation and add bulk delete and download functionalities * frontend: rename 'batchDownload' to 'bulkDownload' for consistency and implement missing methods in RecordingsComponent * frontend: Implement Room Creation Wizard with Step Indicator and Navigation - Added StepIndicatorComponent for visual step tracking in the wizard. - Created WizardNavComponent for navigation controls (Next, Previous, Cancel, Finish). - Developed RoomWizardComponent to manage the wizard's state and steps. - Introduced WizardStateService to handle the wizard's data and navigation logic. - Defined WizardStep and WizardNavigationConfig models for step management. - Implemented basic structure for individual steps: Basic Info, Recording Settings, Recording Trigger, Recording Layout, and Preferences. - Integrated components into the room creation flow, allowing users to navigate through steps. - Added unit tests for all new components and services to ensure functionality. * feat(wizard): enhance wizard functionality and UI - Added validation form groups to WizardStep interface for better form handling. - Updated WizardNavigationConfig to include customizable button labels and states. - Implemented step navigation with event handling in room-wizard component. - Refactored basic info step into a standalone component with reactive form support. - Improved styling for the basic info step and action buttons. - Enhanced wizard state management to handle dynamic step visibility based on user input. - Added methods for loading existing data and saving form changes automatically. - Updated tests to reflect changes in component structure and functionality. * feat(recording-preferences): implement recording preferences step with form and options * feat(room-wizard): add recording trigger step with selectable options and form handling * feat(recording-preferences): refactor option selection to use SelectableCard component and update styles * test: add tests for download recordings endpoint and update tests for bulk delete recordings * openapi: improve descriptions for bulk delete operations and add new response for marked rooms * frontend: update bulk actions and add sharing functionality in RecordingsComponent, and enhace RecordingListsComponent * frontend: implement bulkDeleteRooms method and enhace RoomsComponent and RoomListsComponent * typings: add MeetApiKey interface * backend: update API key handling to use MeetApiKey type * openapi: create API key schema and update response references * backend: add webhook URL testing functionality and validation * frontend: simplify HTTP request methods by removing response observation * frontend: streamline OverviewComponent by removing unused observables and simplifying data loading * frontend: add API key management methods to AuthService * frontend: enhance GlobalPreferencesService by adding webhook preferences management * frontend: refactor DevelopersSettingsComponent to improve API key handling and streamline webhook configuration * openapi: add webhook URL testing endpoint with request and response schemas * test: add tests for webhook URL validation * frontend: enhance PreferencesComponent and add changePassword method in AuthService * feat(recording-preferences): add recording access control options and enhance UI animations * feat(recording-layout): implement recording layout selection step with form handling and visual options * feat(room-preferences): implement room preferences step with form handling and toggle options * feat(room-wizard): enhance form handling and default value saving across components * feat(layouts): add new layout images for grid, single speaker, and speaker configurations * feat(developers): adjust API key field button padding and update spacing in API key display * feat(rooms-lists): enhance button formatting and add tooltips for room status and auto-deletion * feat(room-wizard): update room creation logic and form field names for consistency * feat(room-wizard): add skip button functionality and enhance navigation handling * feat(basic-info): simplify form layout by removing action buttons and related styles * fix(wizard-navigation): change currentStepId type from string to number for consistency * feat(styles): enhance button padding and hover effect in batch actions for improved usability * fix(wizard-navigation): adjust padding for improved layout consistency * feat(basic-info): add clear button for deletion date and enhance time selection layout * feat(rooms-list): enhance deletion date display with new styling and structure * fix(basic-info): remove debugger statement from saveFormData method * refactor(step-indicator): remove commented-out styles for cleaner code * feat(step-indicator): enhance responsive layout handling and emit layout changes * feat(overview): improve loading state handling and update stats management * feat(step-indicator): enable navigation between steps and improve layout handling * feat(room-wizard): refactor state management to use MeetRoomOptions and improve data handling across components * feat(step-indicator): enhance layout handling and improve text overflow management for better responsiveness * feat(step-indicator): update step properties to enhance navigation and state management * feat(room-wizard): add 'Create Room' label to finish button in navigation config * openapi: add force-deletion parameter to delete room endpoint * frontend: split code in ContextService into domain specific services and rename it to AppDataSerivce * frontend: enhace FeatureConfigurationService to use signal-based approach and remove unused preferences and permissions * feat(basic-info): update deletion hint icon and improve warning color consistency * feat(room-service): rename saveRoomPreferences to updateRoom and adjust API path for preference updates * feat(room-wizard): implement edit mode for room configuration, allowing users to update existing room settings * feat(pro-feature-badge): create ProFeatureBadge component and integrate into logo selector and selectable card * fix(recording): adjust compression level for zip archive in downloadRecordingsZip * fix(internal-config): remove FIXME comments related to LK bug for meeting timeouts * frontend: reorganize imports and remove unused components * refactor(console): rename 'Developers' to 'Embedded' in navigation and update related routes * fix(console-nav): update toolbar title from 'OpenVidu Console' to 'OpenVidu Meet' * feat(users-permissions): create UsersPermissions component and update routing * feat(users-permissions): add pro feature badge to user authentication section * fix(overview): update navigation and text from 'Developers' to 'Embedded' * feat(overview): update authentication configuration card and navigation * frontend: refactor RoomRecordingsComponent to use RecordingListsComponent * refactor: update API paths to remove 'meet' prefix for consistency * frontend: update navigation paths to remove 'console' prefix for consistency * feat(video-room): add leave and end meeting functionality with toolbar buttons * fix(overview): remove unnecessary comment on initial loading state * feat(wizard): enable quick create functionality in wizard navigation * feat(step-indicator): implement safe current step index handling for edit mode * feat(wizard): update quick create visibility to show only on first step in edit mode * feat(users-permissions): refactor admin password handling and validation * webcomponent: update Playwright dependencies and refactor leaveRoom functionality - Updated Playwright and Playwright Test versions in package.json to 1.53.2. - Refactored leaveRoom function to accept a role parameter, allowing for different behavior based on user role (moderator or publisher). - Updated E2E tests to utilize the new leaveRoom function, ensuring proper cleanup and behavior for both roles. - Removed unnecessary afterEach cleanup in UI Feature Preferences tests. * frontend: add IDs to leave and end meeting buttons for better accessibility * testapp: update package-lock.json and refactor ConfigService constructor for improved environment variable handling * frontend: update background colors for improved visual consistency * chore: add tslib dependency and enhance target directory validation in sync-types.sh * frontend: enhance accessibility by adding IDs to toolbar and form elements --------- Co-authored-by: juancarmore <juancar_more2@hotmail.com>
721 lines
19 KiB
TypeScript
721 lines
19 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
import { expect } from '@jest/globals';
|
|
import { ChildProcess, spawn } from 'child_process';
|
|
import { Express } from 'express';
|
|
import ms, { StringValue } from 'ms';
|
|
import request, { Response } from 'supertest';
|
|
import { container } from '../../src/config/index.js';
|
|
import INTERNAL_CONFIG from '../../src/config/internal-config.js';
|
|
import {
|
|
LIVEKIT_API_KEY,
|
|
LIVEKIT_API_SECRET,
|
|
MEET_ADMIN_SECRET,
|
|
MEET_ADMIN_USER,
|
|
MEET_API_KEY
|
|
} from '../../src/environment.js';
|
|
import { createApp, registerDependencies } from '../../src/server.js';
|
|
import { RecordingService, RoomService } from '../../src/services/index.js';
|
|
import {
|
|
AuthMode,
|
|
AuthType,
|
|
MeetRecordingAccess,
|
|
MeetRoom,
|
|
MeetRoomOptions,
|
|
WebhookPreferences
|
|
} from '../../src/typings/ce/index.js';
|
|
|
|
const CREDENTIALS = {
|
|
admin: {
|
|
username: MEET_ADMIN_USER,
|
|
password: MEET_ADMIN_SECRET
|
|
}
|
|
};
|
|
|
|
let app: Express;
|
|
const fakeParticipantsProcesses = new Map<string, ChildProcess>();
|
|
|
|
export const sleep = (time: StringValue) => {
|
|
return new Promise((resolve) => setTimeout(resolve, ms(time)));
|
|
};
|
|
|
|
export const startTestServer = (): Express => {
|
|
if (app) {
|
|
return app;
|
|
}
|
|
|
|
registerDependencies();
|
|
app = createApp();
|
|
return app;
|
|
};
|
|
|
|
export const generateApiKey = async (): Promise<string> => {
|
|
checkAppIsRunning();
|
|
|
|
const adminCookie = await loginUser();
|
|
const response = await request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/auth/api-keys`)
|
|
.set('Cookie', adminCookie)
|
|
.send();
|
|
expect(response.status).toBe(201);
|
|
expect(response.body).toHaveProperty('key');
|
|
return response.body.key;
|
|
};
|
|
|
|
export const getApiKeys = async () => {
|
|
checkAppIsRunning();
|
|
|
|
const adminCookie = await loginUser();
|
|
const response = await request(app)
|
|
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/auth/api-keys`)
|
|
.set('Cookie', adminCookie)
|
|
.send();
|
|
return response;
|
|
};
|
|
|
|
export const getAppearancePreferences = async () => {
|
|
checkAppIsRunning();
|
|
|
|
const adminCookie = await loginUser();
|
|
const response = await request(app)
|
|
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/preferences/appearance`)
|
|
.set('Cookie', adminCookie)
|
|
.send();
|
|
return response;
|
|
};
|
|
|
|
export const updateAppearancePreferences = async (preferences: any) => {
|
|
checkAppIsRunning();
|
|
|
|
const adminCookie = await loginUser();
|
|
const response = await request(app)
|
|
.put(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/preferences/appearance`)
|
|
.set('Cookie', adminCookie)
|
|
.send(preferences);
|
|
return response;
|
|
};
|
|
|
|
export const getWebbhookPreferences = async () => {
|
|
checkAppIsRunning();
|
|
|
|
const adminCookie = await loginUser();
|
|
const response = await request(app)
|
|
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/preferences/webhooks`)
|
|
.set('Cookie', adminCookie)
|
|
.send();
|
|
return response;
|
|
};
|
|
|
|
export const updateWebbhookPreferences = async (preferences: WebhookPreferences) => {
|
|
checkAppIsRunning();
|
|
|
|
const adminCookie = await loginUser();
|
|
const response = await request(app)
|
|
.put(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/preferences/webhooks`)
|
|
.set('Cookie', adminCookie)
|
|
.send(preferences);
|
|
|
|
return response;
|
|
};
|
|
|
|
export const testWebhookUrl = async (url: string) => {
|
|
checkAppIsRunning();
|
|
|
|
const response = await request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/preferences/webhooks/test`)
|
|
.send({ url });
|
|
return response;
|
|
};
|
|
|
|
export const getSecurityPreferences = async () => {
|
|
checkAppIsRunning();
|
|
|
|
const adminCookie = await loginUser();
|
|
const response = await request(app)
|
|
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/preferences/security`)
|
|
.set('Cookie', adminCookie)
|
|
.send();
|
|
return response;
|
|
};
|
|
|
|
export const updateSecurityPreferences = async (preferences: any) => {
|
|
checkAppIsRunning();
|
|
|
|
const adminCookie = await loginUser();
|
|
const response = await request(app)
|
|
.put(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/preferences/security`)
|
|
.set('Cookie', adminCookie)
|
|
.send(preferences);
|
|
return response;
|
|
};
|
|
|
|
export const changeSecurityPreferences = async (authMode: AuthMode) => {
|
|
const response = await updateSecurityPreferences({
|
|
authentication: {
|
|
authMethod: {
|
|
type: AuthType.SINGLE_USER
|
|
},
|
|
authModeToAccessRoom: authMode
|
|
}
|
|
});
|
|
expect(response.status).toBe(200);
|
|
};
|
|
|
|
/**
|
|
* Logs in a user and returns the access token cookie
|
|
*/
|
|
export const loginUser = async (): Promise<string> => {
|
|
checkAppIsRunning();
|
|
|
|
const response = await request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/auth/login`)
|
|
.send(CREDENTIALS.admin)
|
|
.expect(200);
|
|
|
|
const cookies = response.headers['set-cookie'] as unknown as string[];
|
|
const accessTokenCookie = cookies.find((cookie) =>
|
|
cookie.startsWith(`${INTERNAL_CONFIG.ACCESS_TOKEN_COOKIE_NAME}=`)
|
|
) as string;
|
|
return accessTokenCookie;
|
|
};
|
|
|
|
export const getProfile = async (cookie: string) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/users/profile`)
|
|
.set('Cookie', cookie)
|
|
.send();
|
|
};
|
|
|
|
export const changePassword = async (newPassword: string, cookie: string) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/users/change-password`)
|
|
.set('Cookie', cookie)
|
|
.send({ newPassword });
|
|
};
|
|
|
|
export const createRoom = async (options: MeetRoomOptions = {}): Promise<MeetRoom> => {
|
|
checkAppIsRunning();
|
|
|
|
const response = await request(app)
|
|
.post(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/rooms`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY)
|
|
.send(options)
|
|
.expect(201);
|
|
return response.body;
|
|
};
|
|
|
|
export const getRooms = async (query: Record<string, any> = {}) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/rooms`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY)
|
|
.query(query);
|
|
};
|
|
|
|
/**
|
|
* Retrieves information about a specific room from the API.
|
|
*
|
|
* @param roomId - The unique identifier of the room to retrieve
|
|
* @param fields - Optional fields to filter in the response
|
|
* @returns A Promise that resolves to the room data
|
|
* @throws Error if the app instance is not defined
|
|
*/
|
|
export const getRoom = async (roomId: string, fields?: string) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/rooms/${roomId}`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY)
|
|
.query({ fields });
|
|
};
|
|
|
|
export const getRoomPreferences = async (roomId: string, cookie: string) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/rooms/${roomId}/preferences`)
|
|
.set('Cookie', cookie)
|
|
.send();
|
|
};
|
|
|
|
export const updateRoomPreferences = async (roomId: string, preferences: any) => {
|
|
checkAppIsRunning();
|
|
|
|
const adminCookie = await loginUser();
|
|
return await request(app)
|
|
.put(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/rooms/${roomId}`)
|
|
.set('Cookie', adminCookie)
|
|
.send(preferences);
|
|
};
|
|
|
|
export const updateRecordingAccessPreferencesInRoom = async (roomId: string, recordingAccess: MeetRecordingAccess) => {
|
|
const response = await updateRoomPreferences(roomId, {
|
|
recordingPreferences: {
|
|
enabled: true,
|
|
allowAccessTo: recordingAccess
|
|
},
|
|
chatPreferences: {
|
|
enabled: true
|
|
},
|
|
virtualBackgroundPreferences: {
|
|
enabled: true
|
|
}
|
|
});
|
|
expect(response.status).toBe(200);
|
|
};
|
|
|
|
export const deleteRoom = async (roomId: string, query: Record<string, any> = {}) => {
|
|
checkAppIsRunning();
|
|
|
|
const result = await request(app)
|
|
.delete(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/rooms/${roomId}`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY)
|
|
.query(query);
|
|
await sleep('1s');
|
|
return result;
|
|
};
|
|
|
|
export const bulkDeleteRooms = async (roomIds: any[], force?: any) => {
|
|
checkAppIsRunning();
|
|
|
|
const result = await request(app)
|
|
.delete(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/rooms`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY)
|
|
.query({ roomIds: roomIds.join(','), force });
|
|
await sleep('1s');
|
|
return result;
|
|
};
|
|
|
|
export const deleteAllRooms = async () => {
|
|
checkAppIsRunning();
|
|
|
|
let nextPageToken: string | undefined;
|
|
|
|
do {
|
|
const response: any = await request(app)
|
|
.get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/rooms`)
|
|
.query({ fields: 'roomId', maxItems: 100, nextPageToken })
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY)
|
|
.expect(200);
|
|
|
|
nextPageToken = response.body.pagination?.nextPageToken ?? undefined;
|
|
const roomIds = response.body.rooms.map((room: { roomId: string }) => room.roomId);
|
|
|
|
if (roomIds.length === 0) {
|
|
break;
|
|
}
|
|
|
|
await request(app)
|
|
.delete(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/rooms`)
|
|
.query({ roomIds: roomIds.join(','), force: true })
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY);
|
|
} while (nextPageToken);
|
|
|
|
await sleep('1s');
|
|
};
|
|
|
|
/**
|
|
* Runs the room garbage collector to delete expired rooms.
|
|
*
|
|
* This function retrieves the RoomService from the dependency injection container
|
|
* and calls its deleteExpiredRooms method to clean up expired rooms.
|
|
* It then waits for 1 second before completing.
|
|
*/
|
|
export const runRoomGarbageCollector = async () => {
|
|
checkAppIsRunning();
|
|
|
|
const roomService = container.get(RoomService);
|
|
await (roomService as any)['deleteExpiredRooms']();
|
|
};
|
|
|
|
export const runReleaseActiveRecordingLock = async (roomId: string) => {
|
|
checkAppIsRunning();
|
|
|
|
const recordingService = container.get(RecordingService);
|
|
await recordingService.releaseRecordingLockIfNoEgress(roomId);
|
|
};
|
|
|
|
export const getRoomRoles = async (roomId: string) => {
|
|
checkAppIsRunning();
|
|
|
|
const response = await request(app)
|
|
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/rooms/${roomId}/roles`)
|
|
.send();
|
|
return response;
|
|
};
|
|
|
|
export const getRoomRoleBySecret = async (roomId: string, secret: string) => {
|
|
checkAppIsRunning();
|
|
|
|
const response = await request(app)
|
|
.get(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/rooms/${roomId}/roles/${secret}`)
|
|
.send();
|
|
return response;
|
|
};
|
|
|
|
export const generateParticipantToken = async (participantOptions: any) => {
|
|
checkAppIsRunning();
|
|
|
|
// Disable authentication to generate the token
|
|
await changeSecurityPreferences(AuthMode.NONE);
|
|
|
|
// Generate the participant token
|
|
const response = await request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/participants/token`)
|
|
.send(participantOptions);
|
|
return response;
|
|
};
|
|
|
|
/**
|
|
* Generates a participant token for a room and returns the cookie containing the token
|
|
*/
|
|
export const generateParticipantTokenCookie = async (
|
|
roomId: string,
|
|
participantName: string,
|
|
secret: string
|
|
): Promise<string> => {
|
|
// Generate the participant token
|
|
const response = await generateParticipantToken({
|
|
roomId,
|
|
participantName,
|
|
secret
|
|
});
|
|
expect(response.status).toBe(200);
|
|
|
|
// Return the participant token cookie
|
|
const cookies = response.headers['set-cookie'] as unknown as string[];
|
|
const participantTokenCookie = cookies.find((cookie) =>
|
|
cookie.startsWith(`${INTERNAL_CONFIG.PARTICIPANT_TOKEN_COOKIE_NAME}=`)
|
|
) as string;
|
|
return participantTokenCookie;
|
|
};
|
|
|
|
export const refreshParticipantToken = async (participantOptions: any) => {
|
|
checkAppIsRunning();
|
|
|
|
// Disable authentication to generate the token
|
|
await changeSecurityPreferences(AuthMode.NONE);
|
|
|
|
const response = await request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/participants/token/refresh`)
|
|
.send(participantOptions);
|
|
return response;
|
|
};
|
|
|
|
/**
|
|
* Adds a fake participant to a LiveKit room for testing purposes.
|
|
*
|
|
* @param roomId The ID of the room to join
|
|
* @param participantName The name for the fake participant
|
|
*/
|
|
export const joinFakeParticipant = async (roomId: string, participantName: string) => {
|
|
await ensureLivekitCliInstalled();
|
|
const process = spawn('lk', [
|
|
'room',
|
|
'join',
|
|
'--identity',
|
|
participantName,
|
|
'--publish-demo',
|
|
roomId,
|
|
'--api-key',
|
|
LIVEKIT_API_KEY,
|
|
'--api-secret',
|
|
LIVEKIT_API_SECRET
|
|
]);
|
|
|
|
// Store the process to be able to terminate it later
|
|
fakeParticipantsProcesses.set(`${roomId}-${participantName}`, process);
|
|
await sleep('1s');
|
|
};
|
|
|
|
/**
|
|
* Verifies that the LiveKit CLI tool 'lk' is installed and accessible
|
|
* @throws Error if 'lk' command is not found
|
|
*/
|
|
const ensureLivekitCliInstalled = async (): Promise<void> => {
|
|
return new Promise((resolve, reject) => {
|
|
const checkProcess = spawn('lk', ['--version'], {
|
|
stdio: 'pipe'
|
|
});
|
|
|
|
let hasResolved = false;
|
|
|
|
const resolveOnce = (success: boolean, message?: string) => {
|
|
if (hasResolved) return;
|
|
|
|
hasResolved = true;
|
|
|
|
if (success) {
|
|
resolve();
|
|
} else {
|
|
reject(new Error(message || 'LiveKit CLI check failed'));
|
|
}
|
|
};
|
|
|
|
checkProcess.on('error', (error) => {
|
|
if (error.message.includes('ENOENT')) {
|
|
resolveOnce(false, '❌ LiveKit CLI tool "lk" is not installed or not in PATH.');
|
|
} else {
|
|
resolveOnce(false, `Failed to check LiveKit CLI: ${error.message}`);
|
|
}
|
|
});
|
|
|
|
checkProcess.on('exit', (code) => {
|
|
if (code === 0) {
|
|
resolveOnce(true);
|
|
} else {
|
|
resolveOnce(false, `LiveKit CLI exited with code ${code}`);
|
|
}
|
|
});
|
|
|
|
// Timeout after 5 seconds
|
|
setTimeout(() => {
|
|
checkProcess.kill();
|
|
resolveOnce(false, 'LiveKit CLI check timed out');
|
|
}, 5000);
|
|
});
|
|
};
|
|
|
|
export const disconnectFakeParticipants = async () => {
|
|
fakeParticipantsProcesses.forEach((process, participantName) => {
|
|
process.kill();
|
|
console.log(`Stopped process for participant ${participantName}`);
|
|
});
|
|
|
|
fakeParticipantsProcesses.clear();
|
|
await sleep('1s');
|
|
};
|
|
|
|
export const deleteParticipant = async (roomId: string, participantName: string, moderatorCookie: string) => {
|
|
checkAppIsRunning();
|
|
|
|
const response = await request(app)
|
|
.delete(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/meetings/${roomId}/participants/${participantName}`)
|
|
.set('Cookie', moderatorCookie)
|
|
.send();
|
|
return response;
|
|
};
|
|
|
|
export const endMeeting = async (roomId: string, moderatorCookie: string) => {
|
|
checkAppIsRunning();
|
|
|
|
const response = await request(app)
|
|
.delete(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/meetings/${roomId}`)
|
|
.set('Cookie', moderatorCookie)
|
|
.send();
|
|
await sleep('1s');
|
|
return response;
|
|
};
|
|
|
|
export const generateRecordingToken = async (roomId: string, secret: string) => {
|
|
checkAppIsRunning();
|
|
|
|
// Disable authentication to generate the token
|
|
await changeSecurityPreferences(AuthMode.NONE);
|
|
|
|
const response = await request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/rooms/${roomId}/recording-token`)
|
|
.send({
|
|
secret
|
|
});
|
|
return response;
|
|
};
|
|
|
|
/**
|
|
* Generates a token for retrieving/deleting recordings from a room and returns the cookie containing the token
|
|
*/
|
|
export const generateRecordingTokenCookie = async (roomId: string, secret: string) => {
|
|
// Generate the recording token
|
|
const response = await generateRecordingToken(roomId, secret);
|
|
expect(response.status).toBe(200);
|
|
|
|
// Return the recording token cookie
|
|
const cookies = response.headers['set-cookie'] as unknown as string[];
|
|
const recordingTokenCookie = cookies.find((cookie) =>
|
|
cookie.startsWith(`${INTERNAL_CONFIG.RECORDING_TOKEN_COOKIE_NAME}=`)
|
|
) as string;
|
|
return recordingTokenCookie;
|
|
};
|
|
|
|
export const startRecording = async (roomId: string, moderatorCookie = '') => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings`)
|
|
.set('Cookie', moderatorCookie)
|
|
.send({
|
|
roomId
|
|
});
|
|
};
|
|
|
|
export const stopRecording = async (recordingId: string, moderatorCookie = '') => {
|
|
checkAppIsRunning();
|
|
|
|
const response = await request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings/${recordingId}/stop`)
|
|
.set('Cookie', moderatorCookie)
|
|
.send();
|
|
await sleep('2.5s');
|
|
|
|
return response;
|
|
};
|
|
|
|
export const getRecording = async (recordingId: string) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/${recordingId}`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY);
|
|
};
|
|
|
|
export const getRecordingMedia = async (recordingId: string, range?: string) => {
|
|
checkAppIsRunning();
|
|
|
|
const req = request(app)
|
|
.get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/${recordingId}/media`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY);
|
|
|
|
if (range) {
|
|
req.set('range', range);
|
|
}
|
|
|
|
return await req;
|
|
};
|
|
|
|
export const getRecordingUrl = async (recordingId: string, privateAccess = false) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/${recordingId}/url`)
|
|
.query({ privateAccess })
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY);
|
|
};
|
|
|
|
export const deleteRecording = async (recordingId: string) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.delete(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/${recordingId}`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY);
|
|
};
|
|
|
|
export const bulkDeleteRecordings = async (recordingIds: any[], recordingTokenCookie?: string): Promise<Response> => {
|
|
checkAppIsRunning();
|
|
|
|
const req = request(app)
|
|
.delete(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings`)
|
|
.query({ recordingIds: recordingIds.join(',') });
|
|
|
|
if (recordingTokenCookie) {
|
|
req.set('Cookie', recordingTokenCookie);
|
|
} else {
|
|
req.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY);
|
|
}
|
|
|
|
return await req;
|
|
};
|
|
|
|
export const downloadRecordings = async (
|
|
recordingIds: string[],
|
|
asBuffer = true,
|
|
recordingTokenCookie?: string
|
|
): Promise<Response> => {
|
|
checkAppIsRunning();
|
|
|
|
const req = request(app)
|
|
.get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings/download`)
|
|
.query({ recordingIds: recordingIds.join(',') });
|
|
|
|
if (recordingTokenCookie) {
|
|
req.set('Cookie', recordingTokenCookie);
|
|
} else {
|
|
req.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY);
|
|
}
|
|
|
|
if (asBuffer) {
|
|
return await req.buffer().parse((res, cb) => {
|
|
const data: Buffer[] = [];
|
|
res.on('data', (chunk) => data.push(chunk));
|
|
res.on('end', () => cb(null, Buffer.concat(data)));
|
|
});
|
|
}
|
|
|
|
return await req;
|
|
};
|
|
|
|
export const stopAllRecordings = async (moderatorCookie: string) => {
|
|
checkAppIsRunning();
|
|
|
|
const response = await getAllRecordings({ fields: 'recordingId' });
|
|
const recordingIds: string[] = response.body.recordings.map(
|
|
(recording: { recordingId: string }) => recording.recordingId
|
|
);
|
|
|
|
if (recordingIds.length === 0) {
|
|
return;
|
|
}
|
|
|
|
console.log(`Stopping ${recordingIds.length} recordings...`);
|
|
const tasks = recordingIds.map((recordingId: string) =>
|
|
request(app)
|
|
.post(`${INTERNAL_CONFIG.INTERNAL_API_BASE_PATH_V1}/recordings/${recordingId}/stop`)
|
|
.set('Cookie', moderatorCookie)
|
|
.send()
|
|
);
|
|
await Promise.all(tasks);
|
|
await sleep('1s');
|
|
};
|
|
|
|
export const getAllRecordings = async (query: Record<string, any> = {}) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app)
|
|
.get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings`)
|
|
.set(INTERNAL_CONFIG.API_KEY_HEADER, MEET_API_KEY)
|
|
.query(query);
|
|
};
|
|
|
|
export const getAllRecordingsFromRoom = async (recordingTokenCookie: string) => {
|
|
checkAppIsRunning();
|
|
|
|
return await request(app).get(`${INTERNAL_CONFIG.API_BASE_PATH_V1}/recordings`).set('Cookie', recordingTokenCookie);
|
|
};
|
|
|
|
export const deleteAllRecordings = async () => {
|
|
checkAppIsRunning();
|
|
|
|
let nextPageToken: string | undefined;
|
|
|
|
do {
|
|
const response: any = await getAllRecordings({
|
|
fields: 'recordingId',
|
|
maxItems: 100,
|
|
nextPageToken
|
|
});
|
|
expect(response.status).toBe(200);
|
|
|
|
nextPageToken = response.body.pagination?.nextPageToken ?? undefined;
|
|
const recordingIds = response.body.recordings.map(
|
|
(recording: { recordingId: string }) => recording.recordingId
|
|
);
|
|
|
|
if (recordingIds.length === 0) {
|
|
break;
|
|
}
|
|
|
|
await bulkDeleteRecordings(recordingIds);
|
|
} while (nextPageToken);
|
|
};
|
|
|
|
// PRIVATE METHODS
|
|
|
|
const checkAppIsRunning = () => {
|
|
if (!app) {
|
|
throw new Error('App instance is not defined');
|
|
}
|
|
};
|