将发件人使用套接字发送的视频流分配给WebRTC中的接收者视频标签会产生错误

时间:2015-11-24 06:13:18

标签: sockets video-streaming webrtc

我正在尝试实施WebRTC。截至目前,我可以使用socket发送视频流。

//This is called when any client connects to the server.
wsServer.on('request', function(request) {
var connection = request.accept(null, request.origin);
clients.push(connection);

//All the messages are handled here
connection.on('message', function(message) {
    if (message.type === 'utf8') {
        // Display the received message
        console.log(' Received utf8 Message ' + message.utf8Data);

        //Broadcast to all the users connected.
        clients.forEach(function (outputConnection) {
            if (outputConnection != connection) {
                outputConnection.send(message.utf8Data, sendCallback);
            }
        });
    }
});

connection.on('close', function(connection) {
    // close user connection
    console.log((new Date()) + " Peer disconnected.");        
});
});

但是,我遗漏了一些东西阻止我使用以下代码在接收者的视频端看到该视频流:

// accept connection request
socket.addEventListener("message", onMessage, false);
  function onMessage(evt) {
    var remotevid = document.getElementById('remotevideo');
    console.log("RECEIVED: ", evt.data);
    if (!started) {
      createPeerConnection();
      window.RTCPeerConnection.addStream(localStream);
      started = true;
    } else {
        //Mostly control comes here
        remotevid.src = evt.data;
        remotevid.play();
    }
}

我想听听我完全错过的内容。一些帮助真的很明显。提前谢谢!

1 个答案:

答案 0 :(得分:0)

您不应该将收到的数据分配到src标记的VIDEO属性(我怀疑#remotevideoVIDEO标记)。 请检查RTCPeerConnection.onaddstream,然后您应该从流中创建一个网址,并将其分配给src代码的VIDEO属性。