所以,我试图建立一个webrtc客户网络网络,所有这些客户端都通过peerconnectinons与数据通道相互连接。我面临的问题在于同伴之间的联系。在两个对等体之间交换候选者的过程中,我使用remoteID来声明候选者的接收者。但是,此代码不足以连接到多个并发连接的对等端。
var startSendingCandidates = function(remoteID) {
peerConnection[remoteID].oniceconnectionstatechange = handleICEConnectionStateChange;//Irrelevant
peerConnection[remoteID].onicecandidate = handleICECandidate;//Is it possible to override this function to reach remoteID that is reachable in the statSendingCandidates function?
remote=remoteID;//Saving the recipients ID in a global variable that will may be overwritten and faced with race-conditions if more than 1 peerconnections tries to reach it when sending candidates to the recipient.
};
var handleICECandidate = function(event) {
var candidate = event.candidate;
console.log(event.candidate);
if (candidate) {
candidate.type = 'candidate';
console.log('Sending candidate to ' + remote);
sendSignalChannelMessage(candidate, remote);
} else {
console.log('All candidates sent');
}
};
总结一下:
可以在https://github.com/a12aleny/exjobb/tree/master/p2p
找到包含用于审核完整代码的文件的回购感谢您阅读并希望提供答案