initial
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
export * from './token.js';
|
||||
export * from './types.js';
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user