parent
5f92356a9a
commit
f35fdda7a2
1 changed files with 36 additions and 20 deletions
|
|
@ -675,9 +675,7 @@ function ensurePeerConnection(peerId) {
|
|||
|
||||
pc.onnegotiationneeded = async () => {
|
||||
try {
|
||||
if (shouldInitiateOffer(peerId)) {
|
||||
await sendOffer(peerId);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("negotiation failed", err);
|
||||
}
|
||||
|
|
@ -701,9 +699,20 @@ async function sendOffer(peerId) {
|
|||
|
||||
async function handleSignal(fromPeerId, kind, data) {
|
||||
const pc = ensurePeerConnection(fromPeerId);
|
||||
const polite = !shouldInitiateOffer(fromPeerId);
|
||||
|
||||
try {
|
||||
if (kind === "offer") {
|
||||
const offerCollision = (pc.signalingState !== "stable");
|
||||
if (offerCollision) {
|
||||
if (!polite) return;
|
||||
await Promise.all([
|
||||
pc.setLocalDescription({ type: "rollback" }),
|
||||
pc.setRemoteDescription(new RTCSessionDescription(data))
|
||||
]);
|
||||
} else {
|
||||
await pc.setRemoteDescription(new RTCSessionDescription(data));
|
||||
}
|
||||
const answer = await pc.createAnswer();
|
||||
await pc.setLocalDescription(answer);
|
||||
state.voice.ws.send(JSON.stringify({
|
||||
|
|
@ -718,9 +727,16 @@ async function handleSignal(fromPeerId, kind, data) {
|
|||
try {
|
||||
await pc.addIceCandidate(data ? new RTCIceCandidate(data) : null);
|
||||
} catch (err) {
|
||||
if (pc.signalingState !== "stable") {
|
||||
// Ignore ICE candidates during negotiation
|
||||
} else {
|
||||
console.warn("failed to add ice candidate", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("handleSignal failed", err);
|
||||
}
|
||||
}
|
||||
|
||||
async function joinVoice() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue