且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何实现3路电话会议视频聊天WebRTC技术原住民code为Android?

更新时间:2022-02-17 23:19:45

您所遇到的问题是,PeerConnectionClient是的不可以周围PeerConnection这一个包装它的包含 PeerConnection等。

The problem you are having is that PeerConnectionClient is not a wrapper around PeerConnection it contains a PeerConnection.

我注意到这个问题不好回答,所以我想看看我能不能帮了一点。我看着源$ C ​​$ c和PeerConnectionClient是一个遥控器等非常辛苦codeD。您需要创建对象PeerConnection等的集合,而不是这一行:

I noticed this question wasn't answered so I wanted to see if I could help out a bit. I looked into the source code and PeerConnectionClient is very much hard coded for a single remote peer. You would need to create a collection of PeerConnection objects rather then this line:

private PeerConnection peerConnection;

如果你看看周围多一点,你会发现它变得更复杂一些的话

If you look around a bit more you would notice that it gets a bit more complicated then that.

在createPeerConnectionInternal的媒体流的逻辑只能做一次,你需要你的对象PeerConnection等之间共享数据流是这样的:

The mediaStream logic in createPeerConnectionInternal should only be done once and you need to share the stream between your PeerConnection objects like this:

peerConnection.addStream(mediaStream);

您可以咨询 WebRTC技术规格或看看此***问题,以确认该PeerConnection等类型被设计为仅处理一个对等体。它也有些隐约暗示这里

You can consult the WebRTC spec or take a look at this *** question to confirm that the PeerConnection type was designed to only handle one peer. It is also somewhat vaguely implied here.

所以,你只维护一个媒体流的对象:

So you only maintain one mediaStream object:

private MediaStream mediaStream;

所以,再一次的主要想法是MediaStream可对象和PeerConnection等众多对象作为你要连接到同行。所以,你将不会被使用多个PeerConnectionClient对象,而是修改单PeerConnectionClient封装多客户端的处理。如果你想要去的不管什么原因,你就只需要抽象的媒体流的逻辑(这只能一次创建的任何支持的类型)出来的多个PeerConnectionClient对象的设计。

So again the main idea is one MediaStream object and as many PeerConnection objects as you have peers you want to connect to. So you will not be using multiple PeerConnectionClient objects, but rather modify the single PeerConnectionClient to encapsulate the multi-client handling. If you do want to go with a design of multiple PeerConnectionClient objects for whatever reason you would just have to abstract the media stream logic (and any support types that should only be created once) out of it.

您还需要维护多个远程视频轨道而不是在现有的:

You will also need to maintain multiple remote video tracks rather then the existing one:

private VideoTrack remoteVideoTrack;

您显然只关心呈现一个本地的摄像头和远程连接创建多个渲染器。

You would obviously only care to render the one local camera and create multiple renderers for the remote connections.

我希望这是足够的信息让你回到正轨。

I hope this is enough information to get you back on track.