更换摄像头和麦克风后如何恢复协商? [英] how to restore the negotiation after changing the camera and microphone?

查看:36
本文介绍了更换摄像头和麦克风后如何恢复协商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大约一个月前,一位 Stackoverflow 合作伙伴帮我解决了一个大问题,比如在会议期间更换摄像头和麦克风.该问题已在以下链接中得到解答:

About a month ago, a Stackoverflow partner helped me with a big question, like changing the camera and the microphone during a conference. That question was answered in the following link:

使用WebRTC如何选择麦克风和摄像头?

更换摄像头和麦克风后,之前的媒体流仍然有效.所以会议中的其他人无法以某种方式接收到我的新流量.

After changing the camera and microphone, the previous media flow remains active. So the other people in the conference can not receive the new flow I have in some way.

如有必要,我想知道如何重新协商这个新流程.

I would like to know how to renegotiate this new flow, if necessary.

我在项目中用于 webRTC 实现的库是simplewebRTC",目前已废弃.

The library that I use for webRTC implementation in the project is "simplewebRTC" currently in disuse.

我用来更换设备的代码完全基于我在上一个问题中取得的成果......

The code I use to change devices is based entirely on what was achieved in my previous question ...

推荐答案

我不知道 simpleWebRTC,但在普通的 WebRTC 中不需要重新协商.

I don't know about simpleWebRTC, but in plain WebRTC renegotiation is not necessary.

只需使用 sender.replaceTrack().它是异步的,所以要同时切换摄像头和麦克风:

Just use sender.replaceTrack(). It's async, so to switch both camera and mic at the same time:

navigator.mediaDevices.getUserMedia(constraints) 
  .then(stream => {
    video.srcObject = stream;
    return Promise.all(stream.getTracks().map(track => {
      const sender = pc.getSenders().find((s => s.track.kind == track.kind);
      return sender.replaceTrack(track);
    }));
  })
  .catch(err => console.log(err));

这应该会立即导致发送者切换到从您的新摄像头和麦克风发送媒体.对方不会知道其中的区别.

This should instantly cause the sender to switch to sending media from your new camera and microphone. The other side won't know the difference.

这篇关于更换摄像头和麦克风后如何恢复协商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆