无法使用优惠的sdpOffer显示应答视频。使用WEBRTC

时间:2015-08-20 05:36:07

标签: javascript websocket webrtc sdp

我无法使用优惠的sdpOffer显示应答视频。使用WEBRTC。 这是我的代码。请你帮帮我。我不明白我的代码出了什么问题。

var offer;
function getPeerOffer(video_stream) {
    var message = {
        id : 'Viwer'                       
    }                      
    ws.send(JSON.stringify(message));
    ws.onmessage=function(message){
         var obj = JSON.parse(message.data)                             
         offer = obj.sdpOffer
         answererPeer2(offer, video_stream); 
    }
}

function answererPeer2(offer, video_stream) {

    answerer = new RTCPeerConnection(null);
    answerer.addStream(video_stream);
    answerer.onaddstream =function (event) {                       
        offererToAnswerer.src = URL.createObjectURL(event.stream);
        offererToAnswerer.play();
    };
    answerer.onicecandidate = function (event) {
        if (!event || !event.candidate) return;
        answerer.addIceCandidate(event.candidate);
    };

    var remoteDescription = new RTCSessionDescription(offer);
    answerer.setRemoteDescription(remoteDescription);                  
    answerer.createAnswer(function (answer) {
    answerer.setLocalDescription(answer);
    answerer.addStream(video_stream)
    }, function() {}, video_constraints);
}          

var video_constraints = {
    mandatory: {},
    optional: []
};
function getUserMedia(callback) {
    var n = navigator;
    n.getMedia = n.webkitGetUserMedia || n.mozGetUserMedia;
    n.getMedia({
        audio: true,
        video: true
    }, callback, onerror);
    function onerror(e) {
        alert(JSON.stringify(e, null, '\t'));
    }
}           
getUserMedia(function (video_stream) {                
        getPeerOffer(video_stream)       
    });

}

0 个答案:

没有答案