WebRTC-无法设置远程应答sdp:在错误状态下调用:进程中的状态

WebRTC-无法设置远程应答sdp:在错误状态下调用:进程中的状态,webrtc,Webrtc,我在这里举一个例子: 我修改了代码,因为我只需要单向流: var configuration = null; //{ "iceServers": [{ "urls": "stuns:stun.example.org" }] }; var peerConnection; var outboundPeerStream = null; var outboundPeerStreamSessionId = null; var createPeerConnection = function () {

我在这里举一个例子:

我修改了代码,因为我只需要单向流:

var configuration = null; //{ "iceServers": [{ "urls": "stuns:stun.example.org" }] };
var peerConnection;

var outboundPeerStream = null;
var outboundPeerStreamSessionId = null;

var createPeerConnection = function () {
    if (peerConnection)
        return;

    peerConnection = new RTCPeerConnection(configuration);

    // send any ice candidates to the other peer
    peerConnection.onicecandidate = function (event) {
        signalrModule.sendClientNotification(JSON.stringify({ "candidate": event.candidate }));
    };

    // let the "negotiationneeded" event trigger offer generation
    peerConnection.onnegotiationneeded = peerStreamingModule.sendOfferToPeers;

    // once remote track arrives, show it in the remote video element
    peerConnection.ontrack = function (event) {
        var inboundPeerStream = event.streams[0];
        remoteStreamHelper.pushStreamToDom(inboundPeerStream, foo);
    }
}

// this gets called either on negotiationNeeded and every 30s to ensure all peers have the offer from the stream originator
peerStreamingModule.sendOfferToPeers = function () {
    peerConnection.createOffer().then(function (offer) {
        return peerConnection.setLocalDescription(offer);
    }).then(function () {
        // send the offer to the other peer
        signalrModule.sendClientNotification(JSON.stringify({ "desc": peerConnection.localDescription}));
    }).catch(logger.internalLog);
};

// this gets called by the stream originator when the stream is available to initiate streaming to peers
peerStreamingModule.initializeWithStream = function (outboundStream, sessionId) {
    outboundPeerStream = outboundStream;
    outboundPeerStreamSessionId = sessionId;
    createPeerConnection();
    peerConnection.addStream(outboundStream);
    //peerStreamingModule.sendOfferToPeers(); I don't think I need this...
}

peerStreamingModule.handleP2PEvent = function (notification) {
    if (!peerConnection)
        createPeerConnection();

    if (notification.desc) {
        var desc = notification.desc;
        // if we get an offer, we need to reply with an answer
        if (desc.type == "offer") {
            peerConnection.setRemoteDescription(desc).then(function () {
                return peerConnection.createAnswer();
            }).then(function (answer) {
                return peerConnection.setLocalDescription(answer);
            }).then(function () {
               signalrModule.sendClientNotification(JSON.stringify({ "desc": peerConnection.localDescription, "sessionId": sessionManager.thisSession().deviceSessionId() }), app.username());
            }).catch(logger.internalLog);
        } else if (desc.type == "answer") {

  peerConnection.setRemoteDescription(desc).catch(logger.internalLog);
        } else {
            logger.internalLog("Unsupported SDP type. Your code may differ here.");
        }
    } else
        pc.addIceCandidate(notification.candidate).catch(logger.internalLog);
}
这似乎有效,但我被两部分难住了:

1)
WebRTC-无法设置远程应答sdp:在错误状态下调用:state\u INPROGRESS
-这会不时出现在我的日志中-我是否在上面做了一些错误的事情导致了这一情况

2) 我是否正确地实现了
sendofferoPeers
初始化WithStream
?恐怕发起者间隔触发的
sendOfferToPeers
不是规范的预期用途;我的目标是确保所有同龄人最终都能收到一份报价,无论他们何时加入,或者他们是否面临失去原始报价/谈判的连接问题

//这会在需要协商时调用,并且每30秒调用一次,以确保所有对等方都有报价

您不能向多个对等方发送相同的报价。这是点对点,而不是点对点。一对多要求每个参与者至少有一个连接,可能还需要一个媒体服务器来扩展

此外,SDP不适用于。提供/应答交换只是两个端点之间的脆弱协商,以建立单一连接


在建立WebRTC连接之前,您应该先解决谁在连接谁。

谢谢。我刚刚更新了我的实现,为每个“对等对”创建了两个连接。这似乎在某种程度上是可行的,但我现在面临着多个同行的问题-如果您有任何意见,我将不胜感激: