0
我使用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);
}
});