chore: allow clients to set their own voip key delays

This commit is contained in:
td 2024-06-22 07:34:16 +05:30
parent 4af9ea38f9
commit 53c75a8dbf
No known key found for this signature in database
GPG Key ID: 62A30523D4D6CE28
2 changed files with 15 additions and 4 deletions

View File

@ -10,6 +10,16 @@ class LiveKitBackend extends CallBackend {
final String livekitServiceUrl; final String livekitServiceUrl;
final String livekitAlias; final String livekitAlias;
/// A delay after a member leaves before we create and publish a new key, because people
/// tend to leave calls at the same time
final Duration makeKeyDelay;
/// The delay between creating and sending a new key and starting to encrypt with it. This gives others
/// a chance to receive the new key to minimise the chance they don't get media they can't decrypt.
/// The total time between a member leaving and the call switching to new keys is therefore
/// makeKeyDelay + useKeyDelay
final Duration useKeyDelay;
@override @override
final bool e2eeEnabled; final bool e2eeEnabled;
@ -18,6 +28,8 @@ class LiveKitBackend extends CallBackend {
required this.livekitAlias, required this.livekitAlias,
super.type = 'livekit', super.type = 'livekit',
this.e2eeEnabled = true, this.e2eeEnabled = true,
this.makeKeyDelay = CallTimeouts.makeKeyDelay,
this.useKeyDelay = CallTimeouts.useKeyDelay,
}); });
Timer? _memberLeaveEncKeyRotateDebounceTimer; Timer? _memberLeaveEncKeyRotateDebounceTimer;
@ -165,7 +177,7 @@ class LiveKitBackend extends CallBackend {
if (delayBeforeUsingKeyOurself) { if (delayBeforeUsingKeyOurself) {
// now wait for the key to propogate and then set it, hopefully users can // now wait for the key to propogate and then set it, hopefully users can
// stil decrypt everything // stil decrypt everything
final useKeyTimeout = Future.delayed(CallTimeouts.useKeyDelay, () async { final useKeyTimeout = Future.delayed(useKeyDelay, () async {
Logs().i( Logs().i(
'[VOIP E2EE] setting key changed event for ${participant.id} idx $encryptionKeyIndex key $encryptionKeyBin'); '[VOIP E2EE] setting key changed event for ${participant.id} idx $encryptionKeyIndex key $encryptionKeyBin');
await groupCall.voip.delegate.keyProvider?.onSetEncryptionKey( await groupCall.voip.delegate.keyProvider?.onSetEncryptionKey(
@ -421,8 +433,7 @@ class LiveKitBackend extends CallBackend {
if (_memberLeaveEncKeyRotateDebounceTimer != null) { if (_memberLeaveEncKeyRotateDebounceTimer != null) {
_memberLeaveEncKeyRotateDebounceTimer!.cancel(); _memberLeaveEncKeyRotateDebounceTimer!.cancel();
} }
_memberLeaveEncKeyRotateDebounceTimer = _memberLeaveEncKeyRotateDebounceTimer = Timer(makeKeyDelay, () async {
Timer(CallTimeouts.makeKeyDelay, () async {
await _makeNewSenderKey(groupCall, true); await _makeNewSenderKey(groupCall, true);
}); });
} }

View File

@ -35,7 +35,7 @@ class CallTimeouts {
/// a chance to receive the new key to minimise the chance they don't get media they can't decrypt. /// a chance to receive the new key to minimise the chance they don't get media they can't decrypt.
/// The total time between a member leaving and the call switching to new keys is therefore /// The total time between a member leaving and the call switching to new keys is therefore
/// makeKeyDelay + useKeyDelay /// makeKeyDelay + useKeyDelay
static const useKeyDelay = Duration(seconds: 6); static const useKeyDelay = Duration(seconds: 4);
} }
class CallConstants { class CallConstants {