webrtc 视频流停止共享 [英] webrtc video stream stop sharing

查看:85
本文介绍了webrtc 视频流停止共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了基于 webrtc 的视频聊天,起诉 peerjs.

I have created webrtc based video chat suing peerjs.

使用控件创建本地和远程视频元素:

The local and remote video element is created using control:

本地:'video id= [local_peer_id] autoplay="true" controls="true">'

local: 'video id= [local_peer_id] autoplay="true" controls="true">'

远程:和'video id= [remote_peer_id] autoplay="true" controls="true">'

remote: and 'video id= [remote_peer_id] autoplay="true" controls="true">'

现在在视频聊天期间,如果本地用户静音 auido 远程用户听不到任何声音并且它的工作完美.

Now during the video chat if local user mute auido remote user can not hear anything and its working perfect.

视频有问题.如果本地用户暂停自己的视频,他可以看到视频被暂停,但远程用户仍然可以看到他的视频直播.

Problem is with the video. If local user pause his own video he can see the video is paused but remote user still can see his video live.

另一方面,如果远程用户暂停他的视频,本地用户仍然可以看到他的视频直播.

on the other hand if remote user pause his video, local user still can see his video live.

任何人告诉部署该功能需要做什么

Any one tell what need to do to deploy the feathure

暂停"和恢复"视频对双方都是实时的?

"Pause" and "resume" video that works real time for both peer?

推荐答案

你需要知道 HTML 标签和 WebRTC 流的区别...

You need to know the difference between the HTML tags and the WebRTC streams...

您可以运行流,而无需将它们附加到任何 HTML 标签,并且每个对等点仍然可以发送和接收媒体.因此,每个对等点都可以将流附加到音频/视频标签,并且该标签将仅充当您用来播放已在运行的流的播放器.

You can have streams running, without having them attached to any HTML tag, and the media can still be sent and received by each peer. So, each peer can attach the stream to a audio/video tag, and the tag will only act as a player that you use to play a stream that is already running.

因此,如果您静音 HTML 标签,您只会静音播放器,而不是流.如果你想让任何东西对另一个对等点产生影响,你需要在流或对等连接中做一些事情.

So, if you mute the HTML tag, you will only be muting the player, and not the stream. If you want to make anything to have effect on the other peer, you need to do stuff on the stream or in the peer connection.

特别是要静音和恢复音频或视频,您需要切换媒体流中的媒体轨道

In particular, to mute and resume audio or video, you need to toggle the media tracks in the media stream

    // create a button to toggle video 
    var button = document.createElement("button");
    button.appendChild(document.createTextNode("Toggle Hold"));

    button.onclick = function(){
        mediaStream.getVideoTracks()[0].enabled =
         !(mediaStream.getVideoTracks()[0].enabled);
    }

要暂停/恢复音频,请改用 getAudioTracks().

To pause/resume audio, use getAudioTracks() instead.

这篇关于webrtc 视频流停止共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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