1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Log when turn creds expire

This commit is contained in:
David Baker
2021-02-26 14:47:27 +00:00
parent a8b9d8e3ae
commit d07563013b
2 changed files with 15 additions and 0 deletions

View File

@@ -393,6 +393,9 @@ export function MatrixClient(opts) {
this._clientWellKnown = undefined;
this._clientWellKnownPromise = undefined;
this._turnServers = [];
this._turnServersExpiry = null;
// The SDK doesn't really provide a clean way for events to recalculate the push
// actions for themselves, so we have to kinda help them out when they are encrypted.
// We do this so that push rules are correctly executed on events in their decrypted
@@ -4942,6 +4945,15 @@ MatrixClient.prototype.getTurnServers = function() {
return this._turnServers || [];
};
/**
* Get the unix timestamp (in seconds) at which the current
* TURN credentials (from getTurnServers) expire
* @return {number} The expiry timestamp, in seconds, or null if no credentials
*/
MatrixClient.prototype.getTurnServersExpiry = function() {
return this._turnServersExpiry;
};
/**
* Set whether to allow a fallback ICE server should be used for negotiating a
* WebRTC connection if the homeserver doesn't provide any servers. Defaults to
@@ -5437,6 +5449,7 @@ function checkTurnServers(client) {
credential: res.password,
};
client._turnServers = [servers];
client._turnServersExpiry = Date.now() + res.ttl;
// re-fetch when we're about to reach the TTL
client._checkTurnServersTimeoutID = setTimeout(() => {
checkTurnServers(client);

View File

@@ -138,6 +138,8 @@ export class CallEventHandler {
);
}
const timeUntilTurnCresExpire = this.client.getTurnServersExpiry() - Date.now();
logger.info("Current turn creds expire in " + timeUntilTurnCresExpire + " seconds");
call = createNewMatrixCall(this.client, event.getRoomId(), {
forceTURN: this.client._forceTURN,
});