gpt4 book ai didi

WebRTC - 无法设置远程应答 sdp : Called in wrong state: STATE_INPROGRESS

转载 作者:行者123 更新时间:2023-12-01 23:16:42 24 4
gpt4 key购买 nike

我正在按照这里的示例进行操作:https://www.w3.org/TR/webrtc/#simple-peer-to-peer-example

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

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 - Failed to set remote answer sdp: Called in wrong state: STATE_INPROGRESS - 这不时出现在我的日志中 - 我在上面做错了什么导致这种情况吗?

2) 我是否正确实现 sendOfferToPeersinitializeWithStream ?恐怕 sendOfferToPeers从发起者的时间间隔触发并不是规范的使用方式;我的目标是确保所有对等方最终都能收到报价,无论他们何时加入,或者是否面临放弃原始报价/协商的连接问题。

最佳答案

// this gets called either on negotiationNeeded and every 30s to ensure all peers have the offer



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

此外,SDP 不适用于 discovery .报价/答案交换是脆弱的 state-machine仅在两个端点之间协商,以建立单个连接。

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

关于WebRTC - 无法设置远程应答 sdp : Called in wrong state: STATE_INPROGRESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44114925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com