m
All checks were successful
/ upload (release) Successful in 21s

This commit is contained in:
pavel 2026-02-24 00:55:49 +01:00
commit f35fdda7a2

View file

@ -675,9 +675,7 @@ function ensurePeerConnection(peerId) {
pc.onnegotiationneeded = async () => { pc.onnegotiationneeded = async () => {
try { try {
if (shouldInitiateOffer(peerId)) { await sendOffer(peerId);
await sendOffer(peerId);
}
} catch (err) { } catch (err) {
console.error("negotiation failed", err); console.error("negotiation failed", err);
} }
@ -701,25 +699,43 @@ async function sendOffer(peerId) {
async function handleSignal(fromPeerId, kind, data) { async function handleSignal(fromPeerId, kind, data) {
const pc = ensurePeerConnection(fromPeerId); const pc = ensurePeerConnection(fromPeerId);
const polite = !shouldInitiateOffer(fromPeerId);
if (kind === "offer") { try {
await pc.setRemoteDescription(new RTCSessionDescription(data)); if (kind === "offer") {
const answer = await pc.createAnswer(); const offerCollision = (pc.signalingState !== "stable");
await pc.setLocalDescription(answer); if (offerCollision) {
state.voice.ws.send(JSON.stringify({ if (!polite) return;
type: "signal", await Promise.all([
to_user_id: fromPeerId, pc.setLocalDescription({ type: "rollback" }),
kind: "answer", pc.setRemoteDescription(new RTCSessionDescription(data))
data: answer, ]);
})); } else {
} else if (kind === "answer") { await pc.setRemoteDescription(new RTCSessionDescription(data));
await pc.setRemoteDescription(new RTCSessionDescription(data)); }
} else if (kind === "ice") { const answer = await pc.createAnswer();
try { await pc.setLocalDescription(answer);
await pc.addIceCandidate(data ? new RTCIceCandidate(data) : null); state.voice.ws.send(JSON.stringify({
} catch (err) { type: "signal",
console.warn("failed to add ice candidate", err); to_user_id: fromPeerId,
kind: "answer",
data: answer,
}));
} else if (kind === "answer") {
await pc.setRemoteDescription(new RTCSessionDescription(data));
} else if (kind === "ice") {
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);
} }
} }