// Server-side only — imported exclusively from API route handlers. // configManager reads from node:fs/promises and cannot run in the browser. if (typeof window !== "undefined") { throw new Error("lib/vnctalk/client.ts is server-only"); } import { configManager } from "@/lib/admin/config-manager"; export interface CreateVncMeetingParams { name: string; start: string; end: string; invitees: string[]; password?: string; description?: string; } export interface CreateVncMeetingResult { meetingUrl: string; meetingId: string; } export async function createVncMeeting( params: CreateVncMeetingParams ): Promise { const serverUrl = configManager.get("vnctalkServerUrl") || process.env.VNCTALK_SERVER_URL || ""; if (!serverUrl) { throw new Error("VNCTALK_SERVER_URL is not configured"); } const endpoint = `${serverUrl.replace(/\/+$/, "")}/api/createnewmeeting`; const response = await fetch(endpoint, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: params.name, start: params.start, end: params.end, invitees: params.invitees, password: params.password, description: params.description, }), }); if (!response.ok) { const text = await response.text().catch(() => ""); throw new Error(`VNCtalk API error ${response.status}: ${text}`); } const data = await response.json(); const meetingUrl: string = data.meetingUrl || data.meeting_url || data.url || ""; const meetingId: string = data.meetingId || data.meeting_id || data.id || ""; if (!meetingUrl) { throw new Error("VNCtalk API did not return a meeting URL"); } return { meetingUrl, meetingId }; }