我使用的是这里的SimpleWebRTC库:https://simplewebrtc.com
我让信号主机运行,它正确配置了STUN/TURN。它能够检测到其他对等点,所以我假设STUN/TURN是有效的。我的问题是,当一个对等点开始他们的本地视频时,其他对等点不会发现它,除非他们重新加载页面。我想要它,这样它就会自动推送到其他同行,而不需要重新加载页面。我认为这与下面的代码(我从示例中提取)有关,但我不确定。
我将autoRequestMedia设置为false的原因是,我希望用户能够在不必打开自己的设备的情况下查看其他同行的摄像头(也是为什么我在readyToCall事件中没有webrtc.joinRoom的原因)。
目前,用户点击一个按钮,它将触发startLocalVideo();视频将在元素中创建。问题是,除非其他对等点重新加载页面,否则不会向其他对等点推送任何内容。希望这能解释一切,如果你需要更多细节,请让我知道。
var webrtc = new SimpleWebRTC({
// the id/element dom element that will hold "our" video
localVideoEl: 'localCam',
// the id/element dom element that will hold remote videos
remoteVideosEl: '',
// immediately ask for camera access
autoRequestMedia: false,
autoRemoveVideos: true,
url: 'MY SIGNAL-MASTER URL HERE',
localVideo: {
autoplay: true, // automatically play the video stream on the page
mirror: false, // flip the local video to mirror mode (for UX)
muted: true // mute local video stream to prevent echo
}
});
webrtc.joinRoom('testchannel');
// a peer video has been added
webrtc.on('videoAdded', function (video, peer) {
console.log('video added', peer);
var remotes = document.getElementById('remoteCams');
if (remotes) {
var container = document.createElement('div');
container.className = 'videoContainer';
container.id = 'container_' + webrtc.getDomId(peer);
container.appendChild(video);
// suppress contextmenu
// video.oncontextmenu = function () { return false; };
remotes.appendChild(container);
}
});
// a peer video was removed
webrtc.on('videoRemoved', function (video, peer) {
console.log('video removed ', peer.nick);
var remotes = document.getElementById('remoteCams');
var el = document.getElementById(peer ? 'container_' + webrtc.getDomId(peer) : 'localScreenContainer');
if (remotes && el) {
remotes.removeChild(el);
}
});发布于 2017-07-10 23:43:48
您必须将join语句放入readyToCall侦听器中:
webrtc.on('readyToCall', function() {
webrtc.joinRoom('roomname');
})或
将joinRoom调用放在一个setTimout函数中。
https://stackoverflow.com/questions/43578472
复制相似问题