我正在尝试实施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();
}
}
我想听听我完全错过的内容。一些帮助真的很明显。提前谢谢!
答案 0 :(得分:0)
您不应该将收到的数据分配到src
标记的VIDEO
属性(我怀疑#remotevideo
是VIDEO
标记)。
请检查RTCPeerConnection.onaddstream
,然后您应该从流中创建一个网址,并将其分配给src
代码的VIDEO
属性。