【m】修改渲染顺序

This commit is contained in:
2026-04-11 19:05:19 +08:00
parent f4ab50b73e
commit cb32582c98
3 changed files with 75 additions and 54 deletions

View File

@@ -182,6 +182,34 @@ class CallStateManager {
const audioTracks = this.state.localStream.getAudioTracks();
console.log('New audio tracks:', audioTracks);
// 更新音频轨道
if (audioTracks.length > 0) {
const newAudioTrack = audioTracks[0];
console.log('Using new audio track:', newAudioTrack);
if (audioTransceivers.length > 0) {
// 替换现有的音频轨道
for (const transceiver of audioTransceivers) {
try {
console.log('Replacing audio track in transceiver:', transceiver);
await transceiver.sender.replaceTrack(newAudioTrack);
console.log('Successfully replaced audio track');
} catch (error) {
console.error('Error replacing audio track:', error);
}
}
} else {
// 添加新的音频收发器
try {
console.log('Adding new audio transceiver');
const transceiver = this.renderstreaming.addTransceiver(newAudioTrack, { direction: 'sendonly' });
console.log('Added new audio transceiver:', transceiver);
} catch (error) {
console.error('Error adding new audio transceiver:', error);
}
}
}
// 更新视频轨道
if (videoTracks.length > 0) {
const newVideoTrack = videoTracks[0];
@@ -210,33 +238,7 @@ class CallStateManager {
}
}
// 更新音频轨道
if (audioTracks.length > 0) {
const newAudioTrack = audioTracks[0];
console.log('Using new audio track:', newAudioTrack);
if (audioTransceivers.length > 0) {
// 替换现有的音频轨道
for (const transceiver of audioTransceivers) {
try {
console.log('Replacing audio track in transceiver:', transceiver);
await transceiver.sender.replaceTrack(newAudioTrack);
console.log('Successfully replaced audio track');
} catch (error) {
console.error('Error replacing audio track:', error);
}
}
} else {
// 添加新的音频收发器
try {
console.log('Adding new audio transceiver');
const transceiver = this.renderstreaming.addTransceiver(newAudioTrack, { direction: 'sendonly' });
console.log('Added new audio transceiver:', transceiver);
} catch (error) {
console.error('Error adding new audio transceiver:', error);
}
}
}
// 延迟设置编解码器偏好,确保收发器已完全创建
setTimeout(() => {
@@ -294,6 +296,7 @@ class CallStateManager {
// 设置状态为连接中
this.state.session.status = 'connecting';
this.notify({ type: 'CALL_STATUS_CHANGE', status: 'connecting' });
// 确保本地流已经初始化
if (!this.state.localStream) {
console.log('Local stream not available, waiting for initialization...');