From d07563013b0705589868c930003d62bb659336aa Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 26 Feb 2021 14:47:27 +0000 Subject: [PATCH] Log when turn creds expire --- src/client.js | 13 +++++++++++++ src/webrtc/callEventHandler.ts | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/client.js b/src/client.js index 5e224a5bf..16c79895d 100644 --- a/src/client.js +++ b/src/client.js @@ -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); diff --git a/src/webrtc/callEventHandler.ts b/src/webrtc/callEventHandler.ts index ba4452ea8..304eacfdd 100644 --- a/src/webrtc/callEventHandler.ts +++ b/src/webrtc/callEventHandler.ts @@ -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, });