Skip to content

Commit 6e25b13

Browse files
committed
Send / add end-of-candidates messages
1 parent 94c5e37 commit 6e25b13

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/webrtc/call.ts

+30-9
Original file line numberDiff line numberDiff line change
@@ -1362,9 +1362,8 @@ export class MatrixCall extends EventEmitter {
13621362
// We have just taken the local description from the peerConn which will
13631363
// contain all the local candidates added so far, so we can discard any candidates
13641364
// we had queued up because they'll be in the answer.
1365-
logger.info(`Call ${this.callId} Discarding ${
1366-
this.candidateSendQueue.length} candidates that will be sent in answer`);
1367-
this.candidateSendQueue = [];
1365+
const discardCount = this.discardDuplicateCandidates();
1366+
logger.info(`Call ${this.callId} Discarding ${discardCount} candidates that will be sent in answer`);
13681367

13691368
try {
13701369
await this.sendVoipEvent(EventType.CallAnswer, answerContent);
@@ -1764,9 +1763,8 @@ export class MatrixCall extends EventEmitter {
17641763

17651764
// Get rid of any candidates waiting to be sent: they'll be included in the local
17661765
// description we just got and will send in the offer.
1767-
logger.info(`Call ${this.callId} Discarding ${
1768-
this.candidateSendQueue.length} candidates that will be sent in offer`);
1769-
this.candidateSendQueue = [];
1766+
const discardCount = this.discardDuplicateCandidates();
1767+
logger.info(`Call ${this.callId} Discarding ${discardCount} candidates that will be sent in offer`);
17701768

17711769
try {
17721770
await this.sendVoipEvent(eventType, content);
@@ -2082,6 +2080,27 @@ export class MatrixCall extends EventEmitter {
20822080
}
20832081
}
20842082

2083+
// Discard all non-end-of-candidates messages
2084+
// Return the number of candidate messages that were discarded.
2085+
// Call this method before sending an invite or answer message
2086+
private discardDuplicateCandidates(): number {
2087+
let discardCount = 0;
2088+
const newQueue = [];
2089+
2090+
for (let i = 0; i < this.candidateSendQueue.length; i++) {
2091+
const candidate = this.candidateSendQueue[i];
2092+
if (candidate.candidate === "") {
2093+
newQueue.push(candidate);
2094+
} else {
2095+
discardCount++;
2096+
}
2097+
}
2098+
2099+
this.candidateSendQueue = newQueue;
2100+
2101+
return discardCount;
2102+
}
2103+
20852104
/*
20862105
* Transfers this call to another user
20872106
*/
@@ -2389,10 +2408,12 @@ export class MatrixCall extends EventEmitter {
23892408
(candidate.sdpMid === null || candidate.sdpMid === undefined) &&
23902409
(candidate.sdpMLineIndex === null || candidate.sdpMLineIndex === undefined)
23912410
) {
2392-
logger.debug(`Call ${this.callId} ignoring remote ICE candidate with no sdpMid or sdpMLineIndex`);
2393-
continue;
2411+
logger.debug(`Call ${this.callId} got remote ICE end-of-candidates`);
2412+
} else {
2413+
logger.debug(`Call ${this.callId} got remote ICE ${
2414+
candidate.sdpMid} candidate: ${candidate.candidate}`);
23942415
}
2395-
logger.debug(`Call ${this.callId} got remote ICE ${candidate.sdpMid} candidate: ${candidate.candidate}`);
2416+
23962417
try {
23972418
await this.peerConn.addIceCandidate(candidate);
23982419
} catch (err) {

0 commit comments

Comments
 (0)