This commit is contained in:
2026-04-25 19:26:39 +08:00
parent bd3698d508
commit bcd55f9dac
3 changed files with 88 additions and 170 deletions

View File

@@ -480,13 +480,30 @@ class CallStateManager {
}
// 通知UI远程流已更新
this.notify({
type: 'REMOTE_STREAM_OBTAINED',
stream: targetStream,
connectionId: trackParticipantId,
isHost: isHost
});
console.log('Notified UI about remote stream update');
// 关键优化:如果是音频轨道先到达且流中尚无视频轨道,
// 延迟通知UI等待视频轨道到达避免音频先触发的UI更新导致黑屏
const notifyStreamUpdate = () => {
this.notify({
type: 'REMOTE_STREAM_OBTAINED',
stream: targetStream,
connectionId: trackParticipantId,
isHost: isHost
});
console.log('Notified UI about remote stream update');
};
if (data.track.kind === 'audio' && targetStream.getVideoTracks().length === 0) {
// 音频先到视频尚未到达延迟200ms通知给视频轨道到达的机会
console.log('Audio track arrived first, delaying stream notification for video track...');
setTimeout(() => {
const nowHasVideo = targetStream.getVideoTracks().length > 0;
console.log(`After delay, stream has video: ${nowHasVideo}`);
notifyStreamUpdate();
}, 200);
} else {
// 视频轨道到达,或音频视频同时存在:立即通知
notifyStreamUpdate();
}
// 只有当收到远程流时才更新远程用户状态为在线
if (this.state.session.remoteUser.status !== 'online') {
this.updateRemoteUserStatus('online');