简体   繁体   English

通过webrtc调用进行视频和音频流控制

[英]Video and audio stream control duirng the webrtc call

I can make the webrtc call between 2 parties with video and audio stream together. 我可以在两方之间通过视频和音频流进行webrtc通话。 Is there any way to give user to stop sharing only video or audio during the call? 有没有办法让用户在通话期间停止仅共享视频或音频?

Assume 假设

A and B are in a webrtc call A和B在webrtc调用中

during the Call A just stop his video channel so b can only listen the A's voice/audio not video. 在通话期间,只需停止他的视频频道,这样b只能收听A的语音/音频而不是视频。 When A resume video again B can see A face again. 当A再次恢复视频时B可以再次看到A面。

Can anyone help? 有人可以帮忙吗?

I have already solved it in a efficient way. 我已经以有效的方式解决了这个问题。 I have hanlded the local stream audio and video to pasue and resume. 我已经将本地流音频和视频用于处理和恢复。 See my below way 见下面的方式

To pause a local video steam to connected partner: mediastream.getVideoTracks()[0].enabled = false; 暂停本地视频流到连接的伙伴:mediastream.getVideoTracks()[0] .enabled = false;

To resume a local video steam to connected partner: mediastream.getVideoTracks()[0].enabled = true; 要将本地视频流恢复到连接的伙伴:mediastream.getVideoTracks()[0] .enabled = true;

for audio: pasue: mediastream.getAudioTracks()[0].enabled = false; for audio:pasue:mediastream.getAudioTracks()[0] .enabled = false;

resume: mediastream.getAudioTracks()[0].enabled = true; resume:mediastream.getAudioTracks()[0] .enabled = true;

It is working perfectly in my project. 它在我的项目中完美运行。

The Suman's answer kind of solves the problem but it's not efficient. 苏曼的答案解决了这个问题,但效率不高。 You're still transmitting the data, just not displaying it. 你仍在传输数据,只是没有显示它。 It's a pure waste, which may be problematic in case of devices with limited bandwidth. 这是纯粹的浪费,在带宽有限的设备的情况下可能会有问题。 Please note that by default WebRTC will go as high as 2Mbps for video. 请注意,默认情况下,WebRTC的视频速度最高可达2Mbps。

The proper solution to this problem would be to renegotiate offer/answer between the peers and mark particular media as sendonly/recvonly. 解决此问题的正确方法是重新协商对等方之间的提供/回答,并将特定媒体标记为sendonly / recvonly。

To do so, you need to store somewhere the SDP offer and when there is a need to stop sending media of particular type, you need to replace line 为此,您需要存储SDP提供的某个地方,当需要停止发送特定类型的媒体时,您需要更换线路

a=sendrecv with a=recvonly a = sendrecv,a = recvonly

like: 喜欢:

var localDescr = peerConnection.localDescription;
localDescr = makeRecvOnly(localDescr);
peerConnection.setLocalDescription(localDescr,function(){});
someWebSocketTransport.sendUpdateStreamingStatus(localDescr)

then the other end should handle this sendUpdateStreamingStatus and set the received description using 然后另一端应该处理这个sendUpdateStreamingStatus并使用设置接收的描述

peerConnection.setRemoteDescription(receivedRemoteDescr, function() {})

Hope this helps. 希望这可以帮助。

Suppose when user(A) click on stop button for hide video. 假设用户(A)点击停止按钮隐藏视频。 You will apply the css video {display:none } to video( local/remote ) element, and send that command to server for other user(B), when other user get this command, on his side video( local/remote ) would be hidden with video{display:none} . 您将css video {display:none }应用于视频( 本地/远程 )元素,并将该命令发送给服务器以供其他用户(B),当其他用户获得此命令时,在他的侧视频( 本地/远程 )将隐藏video{display:none}

As a result the video would be hidden, and you(A) and other(B) can hear each other voice, when you click on show button just do the video{display : block} to video element on your and other's browser respectively. 因此,视频将被隐藏,并且您(A)和其他(B)可以听到彼此的声音,当您单击“显示”按钮时,只需在您和其他浏览器上分别对视频元素执行video{display : block}

But in this case if any user does video{display:block} through the inspect element from browser then video would appear on his side. 但在这种情况下,如果任何用户通过浏览器中的inspect元素执行video{display:block} ,那么视频就会显示在他身边。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM