会话错误说明:无法在RTP通道上设置DTLS-SRTP

时间:2017-07-28 22:10:39

标签: javascript webrtc p2p

由于会话描述中存在错误,我目前正面临无法设置远程SDP的错误 - Couldn't set up DTLS-SRTP on RTP channel

此外,由于onnegotiationneeded两次点火,在点对点(不应该)中发生两轮提议/回答。这在多对等连接中的视频会议设置期间发生,否则在多对等连接(用于流外部视频)中设置的数据通道工作正常。下面的代码启动对等连接 -

// Initiating peer connection with the host
function initiatePeerConnection(currentPeer, callback){
    peerConnection[currentPeer] = new RTCPeerConnection(serverConfig); // Initiation of RTC connection of peers other than host

    console.log(peerConnection[currentPeer]);
    console.log(currentPeer);


    peerConnection[currentPeer].onicecandidate = function(evt){
        console.log("ice candidate");
        console.log(peerID);
        signalServer.send(JSON.stringify({"candidate": evt.candidate, "peerID": peerID, "senderID": senderID, "sendTo": currentPeer}));
    };

    peerConnection[currentPeer].onnegotiationneeded = function(){
        console.log("negotiation initiated"+currentPeer.toString());
        peerConnection[currentPeer].createOffer()
        .then(function(offer){
            peerConnection[currentPeer].setLocalDescription(offer)
        })
        .then(function(){
            console.log("offer sent to "+currentPeer.toString());
            console.log(peerID);
            console.log(peerConnection[currentPeer].localDescription);
            signalServer.send(JSON.stringify({"sessionDescriptionProtocol": peerConnection[currentPeer].localDescription, "peerID": peerID, "senderID": senderID, "sendTo": currentPeer}));
            console.log("Done negotiation");
        })
        .catch(logError)
    };
    // console.log(localStream);
    // peerConnection[currentPeer].addStream(localStream);
    // peerConnection[currentPeer].ontrack = gotRemoteStream;
    navigator.getUserMedia(constraints, function(stream){
        localStream = stream;
        console.log(localStream);
        gotLocalStream(localStream, currentPeer);
    }, fallbackUserMedia);

    peerConnection[currentPeer].ontrack = function(e){
        console.log("on track");
        gotRemoteStream(e);
    };
    callback(currentPeer, setupChannel); // callback is createDataChannel. calling the callback with setupChannel
}

以下代码回答了从服务器收到的要约/消息 -

if(message.sessionDescriptionProtocol) {
        console.log(message.sessionDescriptionProtocol.type)
        if(message.sessionDescriptionProtocol.type == 'offer') {
            peerConnection[currentPeer].setRemoteDescription(message.sessionDescriptionProtocol)
            .then(function(){
                return peerConnection[currentPeer].createAnswer();
            })
            .then(function(answer){
                createLocalDescription(answer);
            })
            .catch(logError)
        }else{
            console.log(currentPeer);
            peerConnection[currentPeer].setRemoteDescription(message.sessionDescriptionProtocol)
            .catch(logError);
        }

    // });
} else if(message.candidate) {
    console.log("adding");
    peerConnection[currentPeer].addIceCandidate(message.candidate);
    console.log("added");
}

function createLocalDescription(answer){
    peerConnection[currentPeer].setLocalDescription(answer)
    .then(function(){
        console.log("answer sent to "+currentPeer.toString());
        console.log(peerID);
        console.log(peerConnection[currentPeer].localDescription);
        signalServer.send(JSON.stringify({"sessionDescriptionProtocol": peerConnection[currentPeer].localDescription, "peerID": peerID, "senderID": senderID, "sendTo": currentPeer}));
        console.log("Done");
    })

}

如果需要,这是指向repository的链接

提前致谢:D

0 个答案:

没有答案