Skip to content

Commit 7963bb3

Browse files
authored
Merge pull request #1620 from matrix-org/dbkr/log_turn_cred_expiry
Log when turn creds expire
2 parents 14d3882 + d075630 commit 7963bb3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/client.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ export function MatrixClient(opts) {
393393
this._clientWellKnown = undefined;
394394
this._clientWellKnownPromise = undefined;
395395

396+
this._turnServers = [];
397+
this._turnServersExpiry = null;
398+
396399
// The SDK doesn't really provide a clean way for events to recalculate the push
397400
// actions for themselves, so we have to kinda help them out when they are encrypted.
398401
// We do this so that push rules are correctly executed on events in their decrypted
@@ -4942,6 +4945,15 @@ MatrixClient.prototype.getTurnServers = function() {
49424945
return this._turnServers || [];
49434946
};
49444947

4948+
/**
4949+
* Get the unix timestamp (in seconds) at which the current
4950+
* TURN credentials (from getTurnServers) expire
4951+
* @return {number} The expiry timestamp, in seconds, or null if no credentials
4952+
*/
4953+
MatrixClient.prototype.getTurnServersExpiry = function() {
4954+
return this._turnServersExpiry;
4955+
};
4956+
49454957
/**
49464958
* Set whether to allow a fallback ICE server should be used for negotiating a
49474959
* WebRTC connection if the homeserver doesn't provide any servers. Defaults to
@@ -5437,6 +5449,7 @@ function checkTurnServers(client) {
54375449
credential: res.password,
54385450
};
54395451
client._turnServers = [servers];
5452+
client._turnServersExpiry = Date.now() + res.ttl;
54405453
// re-fetch when we're about to reach the TTL
54415454
client._checkTurnServersTimeoutID = setTimeout(() => {
54425455
checkTurnServers(client);

src/webrtc/callEventHandler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ export class CallEventHandler {
138138
);
139139
}
140140

141+
const timeUntilTurnCresExpire = this.client.getTurnServersExpiry() - Date.now();
142+
logger.info("Current turn creds expire in " + timeUntilTurnCresExpire + " seconds");
141143
call = createNewMatrixCall(this.client, event.getRoomId(), {
142144
forceTURN: this.client._forceTURN,
143145
});

0 commit comments

Comments
 (0)