feat(im): 群通话发起/接听时主动同步胶囊条,避免依赖 webhook 延迟

im
YunaiV 2026-05-17 20:27:43 +08:00
parent 5d222bdf48
commit 85207bec98
1 changed files with 43 additions and 0 deletions

View File

@ -146,6 +146,8 @@ export const useRtcStore = defineStore('imRtc', () => {
*/
function startInviting(data: ImRtcCallRespVO) {
call.value = data
// 群通话场景写入本地胶囊条缓存
syncGroupActiveCall(data)
// 更新 stage 状态
if (data.conversationType === ImConversationType.GROUP) {
stage.value = ImRtcCallStage.RUNNING
@ -163,14 +165,55 @@ export const useRtcStore = defineStore('imRtc', () => {
function showIncoming(payload: ImRtcCallNotification) {
incomingPayload.value = payload
stage.value = ImRtcCallStage.INCOMING
// 按 inviter 兜底首次填充胶囊条
syncGroupActiveCall({
conversationType: payload.conversationType,
room: payload.room,
groupId: payload.groupId,
mediaType: payload.mediaType,
inviterId: payload.inviterUserId ?? 0,
joinedUserIds: payload.inviterUserId ? [payload.inviterUserId] : [],
inviteeIds: payload.inviteeIds
})
}
/** 进入通话中阶段 */
function enterRunning(data: ImRtcCallRespVO) {
call.value = data
// 离开 INCOMING 阶段;清空来电载荷
incomingPayload.value = null
stage.value = ImRtcCallStage.RUNNING
startedAt.value = Date.now()
// 接通后用 RespVO 完整覆盖胶囊条
syncGroupActiveCall(data)
}
/**
* groupActiveCalls groupId
* webhook RTC_PARTICIPANT_CONNECTED
* joinedUserIds getActiveCall /
*/
function syncGroupActiveCall(input: {
conversationType: number
room: string
groupId?: number
mediaType: number
inviterId: number
joinedUserIds?: number[]
inviteeIds?: number[]
}) {
if (input.conversationType !== ImConversationType.GROUP || !input.groupId) {
return
}
// 写入或更新群活跃通话缓存
setGroupCall({
room: input.room,
groupId: input.groupId,
mediaType: input.mediaType,
inviterId: input.inviterId,
joinedUserIds: input.joinedUserIds ?? [],
inviteeIds: input.inviteeIds ?? []
})
}
/** 重置;通话结束统一调用 */