javascript - WebRTC 流在第一帧后卡住

标签 javascript google-chrome video-streaming webrtc chromium

这是交易,我有一个 WebRTC 一对一对话,使用:

一切似乎都很好,但有一个问题:

Chrom* 浏览器仅显示视频的第一帧,然后视频和音频卡住。查看 Chromium 进程网络和 CPU 使用情况,它正在获取和解码视频,但没有显示。这是我的代码:

window.webrtc = new SimpleWebRTC({
    localVideoEl: 'local',
    remoteVideosEl: 'remote',
    autoRequestMedia: true,
    debug: true,
    url: 'https://server.server:8888/'
});

window.webrtc.on('videoAdded', function (video, peer) {
    var remotes = document.getElementById('remote');
    if (remotes) {
        var container = document.createElement('div');
        container.className = 'videoContainer';
        container.id = 'container_' + webrtc.getDomId(peer);
        container.appendChild(video);

        video.oncontextmenu = function () {
            return false;
        };

        remotes.appendChild(container);

        if (peer) {
            peer.on('iceConnectionStateChange', function (event) {
                switch (peer.pc.iceConnectionState) {
                    case 'checking':
                        $('#status').text('Connecting...');
                        break;
                    case 'connected':
                    case 'completed': // on caller side
                        $('#status').text('Connected');
                        break;
                    case 'disconnected':
                        $('#status').text('Disconnected');
                        break;
                    case 'failed':
                        $('#status').text('Failed to connect');
                        break;
                    case 'closed':
                        $('#status').text('Connection closed');
                        $('#remote').empty();
                        break;
                }
            });
        }
    }
});

window.webrtc.on('readyToCall', $.ajax({
    url: '/getroom.php',
    success: function (data) {
        window.webrtc.joinRoom(data);
    }
}));

<p id="status">Waiting...</p>
<video id="local" width="300" height="225" autoplay></video>
<div id="remote"></div>

信号主管:

{
    "uid": "nobody",
    "isDev": true,
    "logLevel": 3,
    "server": {
            "port": 8888,
            "secure": true,
            "key": "key.key",
            "cert": "cer.cer"
    },
    "stunservers" : [
            {
                    "url": "stun:server.server:3478"
            }
    ],
    "turnservers" : [
            {
                    "url": "turn:server.server:3478",
                    "secret": "qgJeuJuIyeqX",
                    "expiry": 86400
            }
    ]
}

CoTurn 服务器配置为 qgJeuJuIyeqX key 和 server.server 领域,其他一切都是默认的。

最佳答案

这似乎是 Chrome 中的一个问题,重新附加视频元素会导致视频卡住。解决方案是只添加一次视频元素。我通过将 remoteVideosEl 部分留空来解决这个问题:

window.webrtc = new SimpleWebRTC({
    localVideoEl: 'local',
    remoteVideosEl: '',
    autoRequestMedia: true,
    debug: true,
    url: 'https://server.server:8888/'
});

这样 SimpleWebRTC 不会自动为您附加视频元素,因此当调用“videoAdded”方法时,您可以第一次附加视频。

关于javascript - WebRTC 流在第一帧后卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28728634/

相关文章:

javascript - 多 View 布局框架7 混合应用程序

javascript - 使用 jQuery addClass 更改背景图像

音频托管平台/服务器端软件

java - 开发网络摄像头聊天应用程序

iphone - 如何使用 libavcodec (ffmpeg) 读取 http 视频流

javascript - 对象可能是 'null' : TypeScript, React useRef & Formik innerRef

php - 从 Javascript 函数返回一个值

javascript - 屏幕关闭时,HTML5 音频/javascript 在 android(谷歌浏览器)上停止工作

php - 内容类型导致 chrome 调用函数两次

javascript - 使用 page_action 时未出现弹出窗口