This commit is contained in:
2026-04-18 23:11:35 +02:00
commit f7cfd2a86e
196 changed files with 35538 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
export * from './token.js';
export * from './types.js';
+27
View File
@@ -0,0 +1,27 @@
import type { AppSupabaseClient } from '../supabase/client.js';
import type { LivekitToken } from './types.js';
// Fetch a short-lived LiveKit access token via the mint-livekit-token
// edge function. The server-side RLS check lives inside that function.
export async function fetchLivekitToken(
client: AppSupabaseClient,
conversationId: string,
): Promise<LivekitToken> {
const { data, error } = await client.functions.invoke('mint-livekit-token', {
body: { conversationId },
});
if (error) throw error;
if (!data || typeof data !== 'object') {
throw new Error('invalid token response');
}
const d = data as Partial<LivekitToken>;
if (!d.token || !d.url || !d.roomName || !d.identity) {
throw new Error('incomplete token response');
}
return {
token: d.token,
url: d.url,
roomName: d.roomName,
identity: d.identity,
};
}
+56
View File
@@ -0,0 +1,56 @@
// Call signaling + token types. Realtime broadcast payloads live on a
// per-user channel (`call-signals:<userId>`) so incoming invites surface
// even if the recipient isn't currently on the relevant chat route.
export type CallKind = 'audio' | 'video';
export interface CallInvitePayload {
type: 'invite';
callId: string;
conversationId: string;
fromUserId: string;
kind: CallKind;
sentAt: string; // ISO
}
export interface CallAcceptPayload {
type: 'accept';
callId: string;
byUserId: string;
}
export interface CallRejectPayload {
type: 'reject';
callId: string;
byUserId: string;
}
export interface CallCancelPayload {
type: 'cancel';
callId: string;
byUserId: string;
}
export interface CallEndPayload {
type: 'end';
callId: string;
byUserId: string;
}
export type CallSignal =
| CallInvitePayload
| CallAcceptPayload
| CallRejectPayload
| CallCancelPayload
| CallEndPayload;
export function signalTopic(userId: string): string {
return 'call-signals:' + userId;
}
export interface LivekitToken {
token: string;
url: string;
roomName: string;
identity: string;
}