【m】禁用视频功能接入
This commit is contained in:
@@ -120,16 +120,69 @@ class CallStateManager {
|
||||
// 如果是开启视频,重新获取摄像头资源
|
||||
if (mediaType === 'video' && value) {
|
||||
if (this.state.localStream) {
|
||||
// 停止当前的媒体流
|
||||
if (this.state.localStream) {
|
||||
this.state.localStream.getTracks().forEach(track => track.stop());
|
||||
}
|
||||
this.state.localStream = null;
|
||||
}
|
||||
//if(this.state.localStream.getVideoTracks().length==0){
|
||||
// 请求摄像头权限并获取媒体流
|
||||
this.state.localStream = await navigator.mediaDevices.getUserMedia({
|
||||
video: true,
|
||||
audio: true
|
||||
});
|
||||
// }
|
||||
await this.getLocalStream();
|
||||
|
||||
// 更新WebRTC连接中的视频轨道
|
||||
if (this.renderstreaming) {
|
||||
console.log('Updating video track in WebRTC connection');
|
||||
|
||||
// 获取所有收发器
|
||||
const transceivers = this.renderstreaming.getTransceivers();
|
||||
console.log('All transceivers:', transceivers);
|
||||
|
||||
// 查找现有的视频收发器
|
||||
const videoTransceivers = transceivers.filter(t => {
|
||||
return t.sender && t.sender.track && t.sender.track.kind === 'video';
|
||||
});
|
||||
console.log('Found video transceivers:', videoTransceivers);
|
||||
|
||||
// 获取新的视频轨道
|
||||
const videoTracks = this.state.localStream.getVideoTracks();
|
||||
console.log('New video tracks:', videoTracks);
|
||||
|
||||
if (videoTracks.length > 0) {
|
||||
const newVideoTrack = videoTracks[0];
|
||||
console.log('Using new video track:', newVideoTrack);
|
||||
|
||||
if (videoTransceivers.length > 0) {
|
||||
// 替换现有的视频轨道
|
||||
for (const transceiver of videoTransceivers) {
|
||||
try {
|
||||
console.log('Replacing video track in transceiver:', transceiver);
|
||||
await transceiver.sender.replaceTrack(newVideoTrack);
|
||||
console.log('Successfully replaced video track');
|
||||
} catch (error) {
|
||||
console.error('Error replacing video track:', error);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 添加新的视频收发器
|
||||
try {
|
||||
console.log('Adding new video transceiver');
|
||||
const transceiver = this.renderstreaming.addTransceiver(newVideoTrack, { direction: 'sendonly' });
|
||||
console.log('Added new video transceiver:', transceiver);
|
||||
} catch (error) {
|
||||
console.error('Error adding new video transceiver:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// 延迟设置编解码器偏好,确保收发器已完全创建
|
||||
setTimeout(() => {
|
||||
this.setCodecPreferences();
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 直接更新媒体状态
|
||||
this.state.session.localUser.mediaState[mediaType] = value;
|
||||
@@ -231,9 +284,23 @@ class CallStateManager {
|
||||
if (this.state.remoteStream == null) {
|
||||
this.state.remoteStream = new MediaStream();
|
||||
}
|
||||
|
||||
// 检查是否已经有相同类型的轨道
|
||||
const existingTracks = this.state.remoteStream.getTracks().filter(track => track.kind === data.track.kind);
|
||||
|
||||
// 移除旧的轨道
|
||||
existingTracks.forEach(track => {
|
||||
this.state.remoteStream.removeTrack(track);
|
||||
console.log('Removed old track:', track.kind);
|
||||
});
|
||||
|
||||
// 添加新的轨道
|
||||
this.state.remoteStream.addTrack(data.track);
|
||||
console.log('Added new track:', data.track.kind);
|
||||
|
||||
// 通知UI远程流已更新
|
||||
this.notify({ type: 'REMOTE_STREAM_OBTAINED', stream: this.state.remoteStream });
|
||||
console.log('Notified UI about remote stream update');
|
||||
|
||||
// 如果是音频轨道,启动远程音频活动检测
|
||||
if (data.track.kind === 'audio') {
|
||||
|
||||
Reference in New Issue
Block a user