0

我正在使用这里找到的 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);
    }
});
4

1 回答 1

1

您必须将 join 语句放入 readyToCall 监听器:

webrtc.on('readyToCall', function() {
     webrtc.joinRoom('roomname');
})

或者

将 joinRoom 调用放在 setTimout 函数中。

于 2017-07-10T15:43:47.640 回答