forked from MirrorHub/synapse
Send multiple candidates at once instead of all individually. Changes spec to include multiple candidates in a candidate(s) message.
This commit is contained in:
parent
14975ce5bc
commit
842898df15
2 changed files with 58 additions and 9 deletions
|
@ -47,6 +47,10 @@ angular.module('MatrixCall', [])
|
||||||
this.call_id = "c" + new Date().getTime();
|
this.call_id = "c" + new Date().getTime();
|
||||||
this.state = 'fledgling';
|
this.state = 'fledgling';
|
||||||
this.didConnect = false;
|
this.didConnect = false;
|
||||||
|
|
||||||
|
// a queue for candidates waiting to go out. We try to amalgamate candidates into a single candidate message where possible
|
||||||
|
this.candidateSendQueue = [];
|
||||||
|
this.candidateSendTries = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixCall.prototype.createPeerConnection = function() {
|
MatrixCall.prototype.createPeerConnection = function() {
|
||||||
|
@ -174,12 +178,7 @@ angular.module('MatrixCall', [])
|
||||||
MatrixCall.prototype.gotLocalIceCandidate = function(event) {
|
MatrixCall.prototype.gotLocalIceCandidate = function(event) {
|
||||||
console.log(event);
|
console.log(event);
|
||||||
if (event.candidate) {
|
if (event.candidate) {
|
||||||
var content = {
|
this.sendCandidate(event.candidate);
|
||||||
version: 0,
|
|
||||||
call_id: this.call_id,
|
|
||||||
candidate: event.candidate
|
|
||||||
};
|
|
||||||
this.sendEventWithRetry('m.call.candidate', content);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,5 +369,53 @@ angular.module('MatrixCall', [])
|
||||||
}, delayMs);
|
}, delayMs);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Sends candidates with are sent in a special way because we try to amalgamate them into one message
|
||||||
|
MatrixCall.prototype.sendCandidate = function(content) {
|
||||||
|
this.candidateSendQueue.push(content);
|
||||||
|
var self = this;
|
||||||
|
if (this.candidateSendTries == 0) $timeout(function() { self.sendCandidateQueue(); }, 100);
|
||||||
|
};
|
||||||
|
|
||||||
|
MatrixCall.prototype.sendCandidateQueue = function(content) {
|
||||||
|
if (this.candidateSendQueue.length == 0) return;
|
||||||
|
|
||||||
|
var cands = this.candidateSendQueue;
|
||||||
|
this.candidateSendQueue = [];
|
||||||
|
++this.candidateSendTries;
|
||||||
|
var content = {
|
||||||
|
version: 0,
|
||||||
|
call_id: this.call_id,
|
||||||
|
candidates: cands
|
||||||
|
};
|
||||||
|
var self = this;
|
||||||
|
console.log("Attempting to send "+cands.length+" candidates");
|
||||||
|
matrixService.sendEvent(self.room_id, 'm.call.candidates', undefined, content).then(function() { self.candsSent(); }, function(error) { self.candsSendFailed(cands, error); } );
|
||||||
|
};
|
||||||
|
|
||||||
|
MatrixCall.prototype.candsSent = function() {
|
||||||
|
this.candidateSendTries = 0;
|
||||||
|
this.sendCandidateQueue();
|
||||||
|
};
|
||||||
|
|
||||||
|
MatrixCall.prototype.candsSendFailed = function(cands, error) {
|
||||||
|
for (var i = 0; i < cands.length; ++i) {
|
||||||
|
this.candidateSendQueue.push(cands[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.candidateSendTries > 5) {
|
||||||
|
console.log("Failed to send candidates on attempt "+ev.tries+". Giving up for now.");
|
||||||
|
this.candidateSendTries = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var delayMs = 500 * Math.pow(2, this.candidateSendTries);
|
||||||
|
++this.candidateSendTries;
|
||||||
|
console.log("Failed to send candidates. Retrying in "+delayMs+"ms");
|
||||||
|
var self = this;
|
||||||
|
$timeout(function() {
|
||||||
|
self.sendCandidateQueue();
|
||||||
|
}, delayMs);
|
||||||
|
};
|
||||||
|
|
||||||
return MatrixCall;
|
return MatrixCall;
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -77,13 +77,15 @@ angular.module('matrixPhoneService', [])
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
call.receivedAnswer(msg);
|
call.receivedAnswer(msg);
|
||||||
} else if (event.type == 'm.call.candidate') {
|
} else if (event.type == 'm.call.candidates') {
|
||||||
var call = matrixPhoneService.allCalls[msg.call_id];
|
var call = matrixPhoneService.allCalls[msg.call_id];
|
||||||
if (!call) {
|
if (!call) {
|
||||||
console.log("Got candidate for unknown call ID "+msg.call_id);
|
console.log("Got candidates for unknown call ID "+msg.call_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
call.gotRemoteIceCandidate(msg.candidate);
|
for (var i = 0; i < msg.candidates.length; ++i) {
|
||||||
|
call.gotRemoteIceCandidate(msg.candidates[i]);
|
||||||
|
}
|
||||||
} else if (event.type == 'm.call.hangup') {
|
} else if (event.type == 'm.call.hangup') {
|
||||||
var call = matrixPhoneService.allCalls[msg.call_id];
|
var call = matrixPhoneService.allCalls[msg.call_id];
|
||||||
if (!call) {
|
if (!call) {
|
||||||
|
|
Loading…
Reference in a new issue