@@ -1362,9 +1362,8 @@ export class MatrixCall extends EventEmitter {
1362
1362
// We have just taken the local description from the peerConn which will
1363
1363
// contain all the local candidates added so far, so we can discard any candidates
1364
1364
// 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` ) ;
1368
1367
1369
1368
try {
1370
1369
await this . sendVoipEvent ( EventType . CallAnswer , answerContent ) ;
@@ -1764,9 +1763,8 @@ export class MatrixCall extends EventEmitter {
1764
1763
1765
1764
// Get rid of any candidates waiting to be sent: they'll be included in the local
1766
1765
// 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` ) ;
1770
1768
1771
1769
try {
1772
1770
await this . sendVoipEvent ( eventType , content ) ;
@@ -2082,6 +2080,27 @@ export class MatrixCall extends EventEmitter {
2082
2080
}
2083
2081
}
2084
2082
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
+
2085
2104
/*
2086
2105
* Transfers this call to another user
2087
2106
*/
@@ -2389,10 +2408,12 @@ export class MatrixCall extends EventEmitter {
2389
2408
( candidate . sdpMid === null || candidate . sdpMid === undefined ) &&
2390
2409
( candidate . sdpMLineIndex === null || candidate . sdpMLineIndex === undefined )
2391
2410
) {
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 } `) ;
2394
2415
}
2395
- logger . debug ( `Call ${ this . callId } got remote ICE ${ candidate . sdpMid } candidate: ${ candidate . candidate } ` ) ;
2416
+
2396
2417
try {
2397
2418
await this . peerConn . addIceCandidate ( candidate ) ;
2398
2419
} catch ( err ) {
0 commit comments