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