1
以下是我獲取流並將其發送到同一臺計算機的代碼。流式傳輸到同一臺電腦 - webRTC
我得到一個流,使用視頻標記顯示它,然後試圖發送流並在同一頁面中顯示另一個視頻標記。
有什麼我在這裏失蹤?或者我有完全錯誤的概念嗎?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<video autoplay width="1280" height="720"></video>
<br />
<video id="rec" autoplay width="1280" height="720"></video>
<script>
var peerConnection1 = new webkitRTCPeerConnection(null);
var peerConnection2 = new webkitRTCPeerConnection(null);
var p1desc,p2desc
peerConnection1.createOffer(success1,function(e){},{'offerToReceiveAudio':true,'offerToReceiveVideo':true});
function success1(desc)
{
peerConnection1.setLocalDescription(desc);
p2srd(desc);
}
function p2srd(desc)
{
peerConnection2.setRemoteDescription(desc);
peerConnection2.createAnswer(success2);
}
function success2(desc)
{
peerConnection2.setLocalDescription(desc);
p1srd(desc);
}
function p1srd(desc)
{
peerConnection1.setRemoteDescription(desc);
begin();
}
function begin()
{
var p = navigator.mediaDevices.getUserMedia({ audio: true, video: true });
p.then(function(mediaStream) {
peerConnection1.addStream(mediaStream);
var video = document.querySelector('video');
video.src = window.URL.createObjectURL(mediaStream);
video.onloadedmetadata = function(e) {
};
});
p.catch(function(err) { console.log(err.name); });
peerConnection2.onaddstream = function (e){
var vidr = document.getElementById('rec');
vidr.src = window.URL.createObjectURL(e.stream);
};
}