You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-18 05:42:00 +03:00
Use TURN servers when placing/receiving calls.
This commit is contained in:
@@ -1096,6 +1096,14 @@ MatrixClient.prototype.turnServer = function(callback) {
|
||||
return this._http.authedRequest(callback, "GET", "/voip/turnServer");
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the TURN servers for this home server.
|
||||
* @return {Array<Object>} The servers or an empty list.
|
||||
*/
|
||||
MatrixClient.prototype.getTurnServers = function() {
|
||||
return this._turnServers || [];
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {boolean} true if there is a valid access_token for this client.
|
||||
*/
|
||||
@@ -1570,13 +1578,21 @@ function setupCallEventHandler(client) {
|
||||
}
|
||||
|
||||
function checkTurnServers(client) {
|
||||
if (!client._supportsVoip || !client.running) {
|
||||
if (!client._supportsVoip) {
|
||||
return;
|
||||
}
|
||||
client.turnServers().done(function(res) {
|
||||
client.turnServer().done(function(res) {
|
||||
if (res.uris) {
|
||||
console.log("Got TURN URIs: " + res.uris);
|
||||
client._turnServers = res;
|
||||
console.log("Got TURN URIs: " + res.uris + " refresh in " +
|
||||
res.ttl + " secs");
|
||||
// map the response to a format that can be fed to
|
||||
// RTCPeerConnection
|
||||
var servers = {
|
||||
urls: res.uris,
|
||||
username: res.username,
|
||||
credential: res.password
|
||||
};
|
||||
client._turnServers = [servers];
|
||||
// re-fetch when we're about to reach the TTL
|
||||
setTimeout(function() { checkTurnServers(client); },
|
||||
(res.ttl || (60 * 60)) * 1000 * 0.9
|
||||
@@ -1584,7 +1600,6 @@ function checkTurnServers(client) {
|
||||
}
|
||||
}, function(err) {
|
||||
console.error("Failed to get TURN URIs");
|
||||
client._turnServers = {};
|
||||
setTimeout(function() { checkTurnServers(client); }, 60000);
|
||||
});
|
||||
}
|
||||
|
@@ -25,9 +25,12 @@ function MatrixCall(opts) {
|
||||
this.webRtc = opts.webRtc;
|
||||
this.URL = opts.URL;
|
||||
// Array of Objects with urls, username, credential keys
|
||||
this.turnServers = opts.turnServers || [{
|
||||
this.turnServers = opts.turnServers || [];
|
||||
if (this.turnServers.length === 0) {
|
||||
this.turnServers.push({
|
||||
urls: [MatrixCall.FALLBACK_STUN_SERVER]
|
||||
}];
|
||||
});
|
||||
};
|
||||
utils.forEach(this.turnServers, function(server) {
|
||||
utils.checkObjectHasKeys(server, ["urls"]);
|
||||
});
|
||||
@@ -899,7 +902,8 @@ module.exports.createNewMatrixCall = function(client, roomId) {
|
||||
webRtc: webRtc,
|
||||
client: client,
|
||||
URL: w.URL,
|
||||
roomId: roomId
|
||||
roomId: roomId,
|
||||
turnServers: client.getTurnServers()
|
||||
};
|
||||
return new MatrixCall(opts);
|
||||
};
|
||||
|
Reference in New Issue
Block a user