Skip to content

Commit

Permalink
feat: add keyRingSize/discardFrameWhenCryptorNotReady to KeyProviderO…
Browse files Browse the repository at this point in the history
…ptions. (#493)

* feat: add keyRingSize/discardFrameWhenCryptorNotReady to KeyProviderOptions.

* update.

* bug fix.

* bump version.

* update e2ee worker js.

* bump version for flutter-webrtc.
  • Loading branch information
cloudwebrtc authored Apr 9, 2024
1 parent 8ee3341 commit 7a1d23d
Show file tree
Hide file tree
Showing 13 changed files with 3,457 additions and 3,350 deletions.
6,462 changes: 3,194 additions & 3,268 deletions example/web/e2ee.worker.dart.js

Large diffs are not rendered by default.

215 changes: 173 additions & 42 deletions example/web/e2ee.worker.dart.js.deps

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions example/web/e2ee.worker.dart.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ios/livekit_client.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'livekit_client'
s.version = '2.1.0'
s.version = '2.1.1'
s.summary = 'Open source platform for real-time audio and video.'
s.description = 'Open source platform for real-time audio and video.'
s.homepage = 'https://livekit.io/'
Expand All @@ -16,5 +16,5 @@ Pod::Spec.new do |s|
s.static_framework = true

s.dependency 'Flutter'
s.dependency 'WebRTC-SDK', '114.5735.08'
s.dependency 'WebRTC-SDK', '114.5735.09'
end
2 changes: 1 addition & 1 deletion lib/src/core/room.dart
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
}
}
}
notifyListeners();
events.emit(const RoomReconnectedEvent());
notifyListeners();
})
..on<EngineResumingEvent>((event) async {
await _sendSyncState();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/livekit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
/// Main entry point to connect to a room.
/// {@category Room}
class LiveKitClient {
static const version = '2.1.0';
static const version = '2.1.1';
}
2 changes: 1 addition & 1 deletion lib/src/track/web/_audio_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Future<dynamic> startAudio(String id, rtc.MediaStreamTrack track) async {
final audioStream = web.MediaStream();
audioStream.addTrack(track.jsTrack);
audioElement.srcObject = audioStream;
return audioElement.play();
return audioElement.play().toDart;
}

Future<bool> startAllAudioElement() async {
Expand Down
4 changes: 2 additions & 2 deletions macos/livekit_client.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'livekit_client'
s.version = '2.1.0'
s.version = '2.1.1'
s.summary = 'Open source platform for real-time audio and video.'
s.description = 'Open source platform for real-time audio and video.'
s.homepage = 'https://livekit.io/'
Expand All @@ -16,5 +16,5 @@ Pod::Spec.new do |s|
s.static_framework = true

s.dependency 'FlutterMacOS'
s.dependency 'WebRTC-SDK', '114.5735.08'
s.dependency 'WebRTC-SDK', '114.5735.09'
end
70 changes: 51 additions & 19 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ packages:
dependency: "direct main"
description:
name: dart_webrtc
sha256: "5cbc40bd9b33d0c9b8004cff52e9883c71f0f54799afc8faca77535eeb9ef857"
sha256: "8bcc17fa56101524e3539a4703f2471f20abf349130ed988430db9914bd38174"
url: "https://pub.dev"
source: hosted
version: "1.2.1"
version: "1.3.2"
dbus:
dependency: transitive
description:
Expand Down Expand Up @@ -236,10 +236,10 @@ packages:
dependency: "direct main"
description:
name: flutter_webrtc
sha256: "2f17fb96e0c9c6ff75f6b1c36d94755461fc7f36a5c28386f5ee5a18b98688c8"
sha256: "80ee0de0550a60337c728940cd073e9b54b08ea1a2a61ffd8ccee35036f000e1"
url: "https://pub.dev"
source: hosted
version: "0.9.48+hotfix.1"
version: "0.10.2"
glob:
dependency: transitive
description:
Expand All @@ -252,10 +252,10 @@ packages:
dependency: "direct main"
description:
name: http
sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba
sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
version: "1.2.1"
http_parser:
dependency: transitive
description:
Expand All @@ -280,6 +280,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.6.7"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa"
url: "https://pub.dev"
source: hosted
version: "10.0.0"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0
url: "https://pub.dev"
source: hosted
version: "2.0.1"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints:
dependency: transitive
description:
Expand All @@ -300,26 +324,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: "direct main"
description:
name: meta
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
sha256: d584fa6707a52763a52446f02cc621b077888fb63b93bbcb1143a7be5a0c0c04
url: "https://pub.dev"
source: hosted
version: "1.10.0"
version: "1.11.0"
mockito:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -348,10 +372,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
path_provider:
dependency: transitive
description:
Expand Down Expand Up @@ -565,6 +589,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957
url: "https://pub.dev"
source: hosted
version: "13.0.0"
watcher:
dependency: transitive
description:
Expand All @@ -577,18 +609,18 @@ packages:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
version: "0.5.1"
webrtc_interface:
dependency: transitive
description:
name: webrtc_interface
sha256: "2efbd3e4e5ebeb2914253bcc51dafd3053c4b87b43f3076c74835a9deecbae3a"
sha256: abec3ab7956bd5ac539cf34a42fa0c82ea26675847c0966bb85160400eea9388
url: "https://pub.dev"
source: hosted
version: "1.1.2"
version: "1.2.0"
win32:
dependency: transitive
description:
Expand Down Expand Up @@ -630,5 +662,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.2.0 <4.0.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.10.0"
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
name: livekit_client
description: Flutter Client SDK for LiveKit.
Build real-time video and audio into your apps. Supports iOS, Android, and Web.
version: 2.1.0
version: 2.1.1
homepage: https://github.com/livekit/client-sdk-flutter

environment:
Expand All @@ -38,11 +38,11 @@ dependencies:
uuid: '>=3.0.6'
synchronized: ^3.0.0+3
protobuf: ^3.0.0
flutter_webrtc: ^0.10.1
flutter_webrtc: ^0.10.3
device_info_plus: '>=8.0.0'
js: ^0.6.4
platform_detect: ^2.0.7
dart_webrtc: ^1.3.0
dart_webrtc: ^1.4.0
sdp_transform: ^0.3.2

dev_dependencies:
Expand Down
6 changes: 6 additions & 0 deletions web/e2ee.cryptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ class FrameCryptor {
if (!enabled ||
// skip for encryption for empty dtx frames
buffer.isEmpty) {
if (keyOptions.discardFrameWhenCryptorNotReady) {
return;
}
controller.enqueue(frame);
return;
}
Expand Down Expand Up @@ -419,6 +422,9 @@ class FrameCryptor {
// skip for encryption for empty dtx frames
buffer.isEmpty) {
sifGuard.recordUserFrame();
if (keyOptions.discardFrameWhenCryptorNotReady) {
return;
}
controller.enqueue(frame);
return;
}
Expand Down
17 changes: 13 additions & 4 deletions web/e2ee.keyhandler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,25 @@ import 'crypto.dart' as crypto;
import 'e2ee.logger.dart';
import 'e2ee.utils.dart';

const KEYRING_SIZE = 16;

class KeyOptions {
KeyOptions({
required this.sharedKey,
required this.ratchetSalt,
required this.ratchetWindowSize,
this.uncryptedMagicBytes,
this.failureTolerance = -1,
this.keyRingSze = KEYRING_SIZE,
this.discardFrameWhenCryptorNotReady = false,
});
bool sharedKey;
Uint8List ratchetSalt;
int ratchetWindowSize = 0;
int failureTolerance;
Uint8List? uncryptedMagicBytes;
int keyRingSze;
bool discardFrameWhenCryptorNotReady;

@override
String toString() {
Expand Down Expand Up @@ -91,8 +97,6 @@ class KeyProvider {
}
}

const KEYRING_SIZE = 16;

class KeySet {
KeySet(this.material, this.encryptionKey);
web.CryptoKey material;
Expand All @@ -104,10 +108,15 @@ class ParticipantKeyHandler {
required this.worker,
required this.keyOptions,
required this.participantIdentity,
});
}) {
if (keyOptions.keyRingSze <= 0 || keyOptions.keyRingSze > 255) {
throw Exception('Invalid key ring size');
}
cryptoKeyRing = List.filled(keyOptions.keyRingSze, null);
}
int currentKeyIndex = 0;

List<KeySet?> cryptoKeyRing = List.filled(KEYRING_SIZE, null);
late List<KeySet?> cryptoKeyRing;

bool _hasValidKey = false;

Expand Down
5 changes: 4 additions & 1 deletion web/e2ee.worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ void main() async {
uncryptedMagicBytes: options['uncryptedMagicBytes'] != null
? Uint8List.fromList(
base64Decode(options['uncryptedMagicBytes'] as String))
: null);
: null,
keyRingSze: options['keyRingSize'] ?? KEYRING_SIZE,
discardFrameWhenCryptorNotReady:
options['discardFrameWhenCryptorNotReady'] ?? false);
logger.config(
'Init with keyProviderOptions:\n ${keyProviderOptions.toString()}');

Expand Down

0 comments on commit 7a1d23d

Please sign in to comment.