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 () => {
try {
if (shouldInitiateOffer(peerId)) {
await sendOffer(peerId);
}
await sendOffer(peerId);
} catch (err) {
console.error("negotiation failed", err);
}
@ -701,25 +699,43 @@ async function sendOffer(peerId) {
async function handleSignal(fromPeerId, kind, data) {
const pc = ensurePeerConnection(fromPeerId);
const polite = !shouldInitiateOffer(fromPeerId);
if (kind === "offer") {
await pc.setRemoteDescription(new RTCSessionDescription(data));
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
state.voice.ws.send(JSON.stringify({
type: "signal",
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) {
console.warn("failed to add ice candidate", err);
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({
type: "signal",
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);
}
}