67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
/**
|
||
* API для работы с LiveKit
|
||
*/
|
||
|
||
import apiClient from '@/lib/api-client';
|
||
|
||
export interface LiveKitRoomResponse {
|
||
room_name: string;
|
||
ws_url: string;
|
||
access_token: string;
|
||
server_url: string;
|
||
ice_servers?: Array<{
|
||
urls: string[];
|
||
username?: string;
|
||
credential?: string;
|
||
}>;
|
||
video_room_id?: number;
|
||
is_admin?: boolean;
|
||
lesson?: {
|
||
id: number;
|
||
title: string;
|
||
start_time: string;
|
||
end_time: string;
|
||
};
|
||
}
|
||
|
||
export interface LiveKitConfig {
|
||
server_url: string;
|
||
ice_servers?: Array<{
|
||
urls: string[];
|
||
username?: string;
|
||
credential?: string;
|
||
}>;
|
||
}
|
||
|
||
/**
|
||
* Создать LiveKit комнату для занятия
|
||
*/
|
||
export async function createLiveKitRoom(lessonId: number): Promise<LiveKitRoomResponse> {
|
||
const res = await apiClient.post<LiveKitRoomResponse>('/video/livekit/create-room/', {
|
||
lesson_id: lessonId,
|
||
});
|
||
return res.data;
|
||
}
|
||
|
||
/**
|
||
* Получить конфигурацию LiveKit
|
||
*/
|
||
export async function getLiveKitConfig(): Promise<LiveKitConfig> {
|
||
const res = await apiClient.get<LiveKitConfig>('/video/livekit/config/');
|
||
return res.data;
|
||
}
|
||
|
||
/**
|
||
* Отметить подключение участника к видеокомнате (для метрик).
|
||
* lessonId — резерв при 404 по room_name (например, если room.name отличается от БД).
|
||
*/
|
||
export async function participantConnected(params: {
|
||
roomName: string;
|
||
lessonId?: number | null;
|
||
}): Promise<void> {
|
||
const { roomName, lessonId } = params;
|
||
const body: { room_name: string; lesson_id?: number } = { room_name: roomName };
|
||
if (lessonId != null) body.lesson_id = lessonId;
|
||
await apiClient.post('/video/livekit/participant-connected/', body);
|
||
}
|