Skip to content

Commit f34052f

Browse files
authored
Merge pull request #1646 from matrix-org/dbkr/more_call_fixes
More VoIP connectivity fixes
2 parents 12050b1 + 27d75a2 commit f34052f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/webrtc/call.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ export class MatrixCall extends EventEmitter {
541541
this.chooseOpponent(event);
542542
try {
543543
await this.peerConn.setRemoteDescription(invite.offer);
544+
await this.addBufferedIceCandidates();
544545
} catch (e) {
545546
logger.debug("Failed to set remote description", e);
546547
this.terminate(CallParty.Local, CallErrorCode.SetRemoteDescription, false);
@@ -985,7 +986,7 @@ export class MatrixCall extends EventEmitter {
985986
private gotLocalIceCandidate = (event: RTCPeerConnectionIceEvent) => {
986987
if (event.candidate) {
987988
logger.debug(
988-
"Got local ICE " + event.candidate.sdpMid + " candidate: " +
989+
"Call " + this.callId + " got local ICE " + event.candidate.sdpMid + " candidate: " +
989990
event.candidate.candidate,
990991
);
991992

@@ -1019,7 +1020,7 @@ export class MatrixCall extends EventEmitter {
10191020
}
10201021
};
10211022

1022-
onRemoteIceCandidatesReceived(ev: MatrixEvent) {
1023+
async onRemoteIceCandidatesReceived(ev: MatrixEvent) {
10231024
if (this.callHasEnded()) {
10241025
//debuglog("Ignoring remote ICE candidate because call has ended");
10251026
return;
@@ -1051,15 +1052,18 @@ export class MatrixCall extends EventEmitter {
10511052
return;
10521053
}
10531054

1054-
this.addIceCandidates(cands);
1055+
await this.addIceCandidates(cands);
10551056
}
10561057

10571058
/**
10581059
* Used by MatrixClient.
10591060
* @param {Object} msg
10601061
*/
10611062
async onAnswerReceived(event: MatrixEvent) {
1063+
logger.debug(`Got answer for call ID ${this.callId} from party ID ${event.getContent().party_id}`);
1064+
10621065
if (this.callHasEnded()) {
1066+
logger.debug(`Ignoring answer because call ID ${this.callId} has ended`);
10631067
return;
10641068
}
10651069

@@ -1072,6 +1076,7 @@ export class MatrixCall extends EventEmitter {
10721076
}
10731077

10741078
this.chooseOpponent(event);
1079+
await this.addBufferedIceCandidates();
10751080

10761081
this.setState(CallState.Connecting);
10771082

@@ -1722,6 +1727,8 @@ export class MatrixCall extends EventEmitter {
17221727
// I choo-choo-choose you
17231728
const msg = ev.getContent();
17241729

1730+
logger.debug(`Choosing party ID ${msg.party_id} for call ID ${this.callId}`);
1731+
17251732
this.opponentVersion = msg.version;
17261733
if (this.opponentVersion === 0) {
17271734
// set to null to indicate that we've chosen an opponent, but because
@@ -1735,30 +1742,32 @@ export class MatrixCall extends EventEmitter {
17351742
}
17361743
this.opponentCaps = msg.capabilities || {};
17371744
this.opponentMember = ev.sender;
1745+
}
17381746

1747+
private async addBufferedIceCandidates() {
17391748
const bufferedCands = this.remoteCandidateBuffer.get(this.opponentPartyId);
17401749
if (bufferedCands) {
17411750
logger.info(`Adding ${bufferedCands.length} buffered candidates for opponent ${this.opponentPartyId}`);
1742-
this.addIceCandidates(bufferedCands);
1751+
await this.addIceCandidates(bufferedCands);
17431752
}
17441753
this.remoteCandidateBuffer = null;
17451754
}
17461755

1747-
private addIceCandidates(cands: RTCIceCandidate[]) {
1756+
private async addIceCandidates(cands: RTCIceCandidate[]) {
17481757
for (const cand of cands) {
17491758
if (
17501759
(cand.sdpMid === null || cand.sdpMid === undefined) &&
17511760
(cand.sdpMLineIndex === null || cand.sdpMLineIndex === undefined)
17521761
) {
17531762
logger.debug("Ignoring remote ICE candidate with no sdpMid or sdpMLineIndex");
1754-
return;
1763+
continue;
17551764
}
1756-
logger.debug("Got remote ICE " + cand.sdpMid + " candidate: " + cand.candidate);
1765+
logger.debug("Call " + this.callId + " got remote ICE " + cand.sdpMid + " candidate: " + cand.candidate);
17571766
try {
1758-
this.peerConn.addIceCandidate(cand);
1767+
await this.peerConn.addIceCandidate(cand);
17591768
} catch (err) {
17601769
if (!this.ignoreOffer) {
1761-
logger.info("Failed to add remore ICE candidate", err);
1770+
logger.info("Failed to add remote ICE candidate", err);
17621771
}
17631772
}
17641773
}

0 commit comments

Comments
 (0)