Skip to content

Commit fe4ce0f

Browse files
m144 (#68)
Co-authored-by: davidliu <davidliu@deviange.net>
1 parent 4260d54 commit fe4ce0f

8 files changed

Lines changed: 48 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Software encode/decode factories have been enabled by default.
4343

4444
## WebRTC Revision
4545

46-
* Currently used revision: [M125](https://github.com/webrtc-sdk/webrtc/tree/m125_release)
46+
* Currently used revision: [M144](https://github.com/webrtc-sdk/webrtc/tree/m144_release)
4747
* Supported architectures
4848
* Android: armeabi-v7a, arm64-v8a, x86, x86_64
4949
* iOS: arm64, x86_64

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ android {
3131

3232
dependencies {
3333
implementation "com.facebook.react:react-android:+"
34-
api 'io.github.webrtc-sdk:android:137.7151.05'
34+
api 'io.github.webrtc-sdk:android:144.7559.01'
3535
implementation "androidx.core:core:1.7.0"
3636
}

android/src/main/java/com/oney/WebRTCModule/RTCCryptoManager.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.webrtc.FrameCryptor;
1616
import org.webrtc.FrameCryptorAlgorithm;
1717
import org.webrtc.FrameCryptorFactory;
18+
import org.webrtc.FrameCryptorKeyDerivationAlgorithm;
1819
import org.webrtc.FrameCryptorKeyProvider;
1920
import org.webrtc.RtpReceiver;
2021
import org.webrtc.RtpSender;
@@ -92,6 +93,17 @@ private FrameCryptorAlgorithm frameCryptorAlgorithmFromInt(int algorithm) {
9293
}
9394
}
9495

96+
private FrameCryptorKeyDerivationAlgorithm keyDerivationAlgorithmFromInt(int algorithm) {
97+
switch (algorithm) {
98+
case 0:
99+
return FrameCryptorKeyDerivationAlgorithm.PBKDF2;
100+
case 1:
101+
return FrameCryptorKeyDerivationAlgorithm.HKDF;
102+
default:
103+
return FrameCryptorKeyDerivationAlgorithm.PBKDF2;
104+
}
105+
}
106+
95107
public String frameCryptorFactoryCreateFrameCryptor(ReadableMap params) {
96108
String keyProviderId = params.getString("keyProviderId");
97109
FrameCryptorKeyProvider keyProvider = keyProviders.get(keyProviderId);
@@ -238,13 +250,17 @@ public String frameCryptorFactoryCreateKeyProvider(ReadableMap keyProviderOption
238250
int keyRingSize = (int) keyProviderOptions.getInt("keyRingSize");
239251
boolean discardFrameWhenCryptorNotReady =
240252
(boolean) keyProviderOptions.getBoolean("discardFrameWhenCryptorNotReady");
253+
int keyDerivationAlgorithm = keyProviderOptions.hasKey("keyDerivationAlgorithm")
254+
? keyProviderOptions.getInt("keyDerivationAlgorithm")
255+
: 0;
241256
FrameCryptorKeyProvider keyProvider = FrameCryptorFactory.createFrameCryptorKeyProvider(sharedKey,
242257
ratchetSalt,
243258
ratchetWindowSize,
244259
uncryptedMagicBytes,
245260
failureTolerance,
246261
keyRingSize,
247-
discardFrameWhenCryptorNotReady);
262+
discardFrameWhenCryptorNotReady,
263+
keyDerivationAlgorithmFromInt(keyDerivationAlgorithm));
248264
keyProviders.put(keyProviderId, keyProvider);
249265
return keyProviderId;
250266
}

ios/RCTWebRTC/WebRTCModule+RTCFrameCryptor.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ - (RTCCryptorAlgorithm)getAlgorithm:(NSNumber *)algorithm {
2626
}
2727
}
2828

29+
- (RTCKeyDerivationAlgorithm)getKeyDerivationAlgorithm:(NSNumber *)algorithm {
30+
switch ([algorithm intValue]) {
31+
case 0:
32+
return RTCKeyDerivationAlgorithmPBKDF2;
33+
case 1:
34+
return RTCKeyDerivationAlgorithmHKDF;
35+
default:
36+
return RTCKeyDerivationAlgorithmPBKDF2;
37+
}
38+
}
39+
2940
- (NSData *)bytesFromMap:(NSDictionary *)map key:(NSString *)key isBase64Key:(nullable NSString *)isBase64Key {
3041
BOOL isBase64 = YES;
3142
if (isBase64Key) {
@@ -257,6 +268,7 @@ - (NSData *)bytesFromMap:(NSDictionary *)map key:(NSString *)key isBase64Key:(nu
257268

258269
NSNumber *keyRingSize = keyProviderOptions[@"keyRingSize"];
259270
NSNumber *discardFrameWhenCryptorNotReady = keyProviderOptions[@"discardFrameWhenCryptorNotReady"];
271+
NSNumber *keyDerivationAlgorithm = keyProviderOptions[@"keyDerivationAlgorithm"];
260272

261273
RTCFrameCryptorKeyProvider *keyProvider = [[RTCFrameCryptorKeyProvider alloc]
262274
initWithRatchetSalt:ratchetSalt
@@ -267,7 +279,8 @@ - (NSData *)bytesFromMap:(NSDictionary *)map key:(NSString *)key isBase64Key:(nu
267279
keyRingSize:keyRingSize != nil ? [keyRingSize intValue] : 0
268280
discardFrameWhenCryptorNotReady:discardFrameWhenCryptorNotReady != nil
269281
? [discardFrameWhenCryptorNotReady boolValue]
270-
: NO];
282+
: NO
283+
keyDerivationAlgorithm:[self getKeyDerivationAlgorithm:keyDerivationAlgorithm]];
271284
self.keyProviders[keyProviderId] = keyProvider;
272285
return;
273286
});

livekit-react-native-webrtc.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Pod::Spec.new do |s|
1919
s.libraries = 'c', 'sqlite3', 'stdc++'
2020
s.framework = 'AudioToolbox','AVFoundation', 'CoreAudio', 'CoreGraphics', 'CoreVideo', 'GLKit', 'VideoToolbox'
2121
s.dependency 'React-Core'
22-
s.dependency 'WebRTC-SDK', '=137.7151.09'
22+
s.dependency 'WebRTC-SDK', '=144.7559.01'
2323

2424
# Swift/Objective-C compatibility
2525
s.pod_target_xcconfig = {

src/RTCFrameCryptorFactory.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@ export enum RTCFrameCryptorAlgorithm {
1212
// kAesCbc = 1,
1313
}
1414

15+
export enum RTCKeyDerivationAlgorithm {
16+
PBKDF2 = 0,
17+
HKDF = 1,
18+
}
19+
1520
export type RTCKeyProviderOptions = {
1621
sharedKey: boolean,
1722
ratchetSalt: string | Uint8Array,
1823
ratchetWindowSize: number,
1924
uncryptedMagicBytes?: Uint8Array,
2025
failureTolerance?: number,
2126
keyRingSize?: number,
22-
discardFrameWhenCryptorNotReady?: boolean
27+
discardFrameWhenCryptorNotReady?: boolean,
28+
keyDerivationAlgorithm?: RTCKeyDerivationAlgorithm,
2329
}
2430

2531
export default class RTCFrameCryptorFactory {
@@ -74,7 +80,8 @@ export default class RTCFrameCryptorFactory {
7480
'ratchetWindowSize': options.ratchetWindowSize,
7581
'failureTolerance': options.failureTolerance ?? -1,
7682
'keyRingSize': options.keyRingSize ?? 16,
77-
'discardFrameWhenCryptorNotReady': options.discardFrameWhenCryptorNotReady ?? false
83+
'discardFrameWhenCryptorNotReady': options.discardFrameWhenCryptorNotReady ?? false,
84+
'keyDerivationAlgorithm': options.keyDerivationAlgorithm ?? 0
7885
};
7986

8087
if (typeof options.ratchetSalt === 'string') {

src/RTCRtpSendParameters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ type DegradationPreferenceType = 'maintain-framerate'
66
| 'maintain-resolution'
77
| 'balanced'
88
| 'disabled'
9+
| 'maintain-framerate-and-resolution'
910

1011

1112
/**

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ import RTCDataPacketCryptor, { RTCEncryptedPacket } from './RTCDataPacketCryptor
2020
import RTCDataPacketCryptorFactory from './RTCDataPacketCryptorFactory';
2121
import RTCErrorEvent from './RTCErrorEvent';
2222
import RTCFrameCryptor, { RTCFrameCryptorState } from './RTCFrameCryptor';
23-
import RTCFrameCryptorFactory, { RTCFrameCryptorAlgorithm, RTCKeyProviderOptions } from './RTCFrameCryptorFactory';
23+
import RTCFrameCryptorFactory, {
24+
RTCFrameCryptorAlgorithm, RTCKeyDerivationAlgorithm, RTCKeyProviderOptions,
25+
} from './RTCFrameCryptorFactory';
2426
import RTCIceCandidate from './RTCIceCandidate';
2527
import RTCKeyProvider from './RTCKeyProvider';
2628
import RTCPIPView, { startIOSPIP, stopIOSPIP } from './RTCPIPView';
@@ -64,6 +66,7 @@ export {
6466
RTCFrameCryptor,
6567
RTCFrameCryptorAlgorithm,
6668
RTCFrameCryptorState,
69+
RTCKeyDerivationAlgorithm,
6770
RTCFrameCryptorFactory,
6871
RTCKeyProvider,
6972
RTCKeyProviderOptions,

0 commit comments

Comments
 (0)