3c2b68bbc3
- Add --unsafely-treat-insecure-origin-as-secure flag for dev/uat URLs - Set auto-granted permission handlers for mic/camera in main process - Adapt useVoiceRoom error message for Electron (no Chrome flags hint) - Add debug logging to voice-token service and frontend voice API Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
// src/api/voice.ts
|
|
import { pb } from './pocketbase'
|
|
|
|
const LIVEKIT_URL = import.meta.env.VITE_LIVEKIT_URL || 'ws://192.168.1.14:7880'
|
|
|
|
export function getLiveKitUrl(): string {
|
|
return LIVEKIT_URL
|
|
}
|
|
|
|
export async function fetchVoiceToken(sessionId: string): Promise<string> {
|
|
const user = pb.authStore.model
|
|
if (!user) throw new Error('未登录')
|
|
|
|
const token = pb.authStore.token
|
|
console.log('[voice] fetching token for session:', sessionId, 'token prefix:', token?.slice(0, 20))
|
|
|
|
const res = await fetch(`/voice-api/voice-token/${sessionId}`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: token,
|
|
},
|
|
})
|
|
|
|
console.log('[voice] token service response status:', res.status)
|
|
if (!res.ok) {
|
|
const data = await res.json().catch(() => ({ error: '语音服务暂不可用' }))
|
|
console.log('[voice] token service error:', data)
|
|
throw new Error(data.error || data.detail || '语音服务暂不可用')
|
|
}
|
|
|
|
const data = await res.json()
|
|
return data.token
|
|
}
|