工作不正常
问题描述:
我使用SimpleWebRTC库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);
}
});
答
你必须把声明加入到readyToCall听众:
webrtc.on('readyToCall', function() {
webrtc.joinRoom('roomname');
})
或
把joinRoom中的呼叫setTimout功能。