feat: 添加双人对练语音通话功能
Some checks failed
continuous-integration/drone/push Build is failing

- 后端:扩展 SSE 支持 WebRTC 信令消息转发
- 前端:创建 WebRTC 连接管理模块 (webrtc.ts)
- 前端:创建 useVoiceCall 组合式函数
- 前端:在对练房间添加语音通话 UI
- 集成 Web Speech API 实现语音转文字
This commit is contained in:
yuliang_guo
2026-01-28 15:45:47 +08:00
parent c27ad55e95
commit c5d460b413
6 changed files with 1254 additions and 19 deletions

View File

@@ -76,17 +76,35 @@ export interface RoomDetailResponse {
is_host: boolean
}
export type MessageType =
| 'chat'
| 'system'
| 'join'
| 'leave'
| 'start'
| 'end'
| 'voice_start'
| 'voice_offer'
| 'voice_answer'
| 'ice_candidate'
| 'voice_end'
export interface RoomMessage {
id: number
room_id: number
user_id?: number
message_type: 'chat' | 'system' | 'join' | 'leave' | 'start' | 'end'
message_type: MessageType
content?: string
role_name?: string
sequence: number
created_at: string
}
export interface WebRTCSignalRequest {
signal_type: 'voice_start' | 'voice_offer' | 'voice_answer' | 'ice_candidate' | 'voice_end'
payload: Record<string, any>
}
export interface MessagesResponse {
messages: RoomMessage[]
room_status: string
@@ -185,3 +203,20 @@ export function generateShareLink(roomCode: string): string {
const baseUrl = window.location.origin
return `${baseUrl}/trainee/duo-practice/join/${roomCode}`
}
/**
* 发送 WebRTC 信令
*/
export function sendSignal(roomCode: string, signalType: string, payload: Record<string, any>) {
return request.post(`/api/v1/practice/rooms/${roomCode}/signal`, {
signal_type: signalType,
payload
})
}
/**
* 获取对练报告
*/
export function getPracticeReport(roomCode: string) {
return request.get(`/api/v1/practice/rooms/${roomCode}/report`)
}