Skip to content

Commit f0a7404

Browse files
authored
feat: add LiveKitReactNative setup methods (#75)
* feat: add LiveKitReactNative setup methods updated @lk/react-native-webrtc to 104.0.1 * chore: update github actions to ignore md files * chore: update README.md
1 parent 5f53153 commit f0a7404

19 files changed

Lines changed: 131 additions & 101 deletions

File tree

.github/workflows/native_build.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ name: Test
22
on:
33
push:
44
branches: [ main ]
5+
paths-ignore:
6+
- '**.md'
57
pull_request:
68
branches: [ main ]
9+
paths-ignore:
10+
- '**.md'
711

812
jobs:
913
android-compile:

.github/workflows/test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ name: Test
22
on:
33
push:
44
branches: [ main ]
5+
paths-ignore:
6+
- '**.md'
57
pull_request:
68
branches: [ main ]
9+
paths-ignore:
10+
- '**.md'
711

812
jobs:
913
test:

README.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,16 @@ Once the `@livekit/react-native-webrtc` dependency is installed, one last step i
3838
In your [MainApplication.java](https://github.com/livekit/client-sdk-react-native/blob/main/example/android/app/src/main/java/com/example/livekitreactnative/MainApplication.java) file:
3939

4040
```
41-
import com.livekit.reactnative.video.SimulcastVideoEncoderFactoryWrapper;
42-
import com.oney.WebRTCModule.WebRTCModuleOptions;
43-
import com.oney.WebRTCModule.webrtcutils.H264AndSoftwareVideoDecoderFactory;
44-
45-
import org.webrtc.*;
41+
import com.livekit.reactnative.LiveKitReactNative;
4642
4743
public class MainApplication extends Application implements ReactApplication {
4844
4945
@Override
5046
public void onCreate() {
5147
// Place this above any other RN related initialization
52-
WebRTCModuleOptions options = WebRTCModuleOptions.getInstance();
53-
options.videoEncoderFactory = new SimulcastVideoEncoderFactoryWrapper(null, true, true);
54-
options.videoDecoderFactory = new H264AndSoftwareVideoDecoderFactory(null);
55-
// ...
48+
LiveKitReactNative.setup();
49+
50+
//...
5651
}
5752
}
5853
```
@@ -62,19 +57,15 @@ public class MainApplication extends Application implements ReactApplication {
6257
In your [AppDelegate.m](https://github.com/livekit/client-sdk-react-native/blob/main/example/ios/LivekitReactNativeExample/AppDelegate.mm) file:
6358

6459
```
65-
#import "WebRTCModule.h"
66-
#import "WebRTCModuleOptions.h"
60+
#import "LivekitReactNative.h"
6761
6862
@implementation AppDelegate
6963
7064
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
7165
{
7266
// Place this above any other RN related initialization
73-
RTCDefaultVideoEncoderFactory *videoEncoderFactory = [[RTCDefaultVideoEncoderFactory alloc] init];
74-
RTCVideoEncoderFactorySimulcast *simulcastVideoEncoderFactory =
75-
[[RTCVideoEncoderFactorySimulcast alloc] initWithPrimary:videoEncoderFactory fallback:videoEncoderFactory];
76-
WebRTCModuleOptions *options = [WebRTCModuleOptions sharedInstance];
77-
options.videoEncoderFactory = simulcastVideoEncoderFactory;
67+
[LivekitReactNative setup];
68+
7869
//...
7970
}
8071
```

android/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,6 @@ dependencies {
131131
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
132132
api 'com.github.davidliu:audioswitch:c498d866c57f1d88056d5e7e7a78d622e3b0c046'
133133
api 'io.github.webrtc-sdk:android:104.5112.09'
134+
implementation project(':livekit_react-native-webrtc')
134135
implementation "androidx.annotation:annotation:1.4.0"
135136
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.livekit.reactnative
2+
3+
import com.livekit.reactnative.video.SimulcastVideoEncoderFactoryWrapper
4+
import com.livekit.reactnative.video.WrappedVideoDecoderFactoryProxy
5+
import com.oney.WebRTCModule.WebRTCModuleOptions
6+
7+
8+
object LiveKitReactNative {
9+
10+
@JvmStatic
11+
fun setup() {
12+
val options = WebRTCModuleOptions.getInstance()
13+
options.videoEncoderFactory = SimulcastVideoEncoderFactoryWrapper(null, true, true)
14+
options.videoDecoderFactory = WrappedVideoDecoderFactoryProxy()
15+
}
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.livekit.reactnative.video
2+
3+
import com.oney.WebRTCModule.EglUtils
4+
import org.webrtc.VideoCodecInfo
5+
import org.webrtc.VideoDecoder
6+
import org.webrtc.VideoDecoderFactory
7+
import org.webrtc.WrappedVideoDecoderFactory
8+
9+
class WrappedVideoDecoderFactoryProxy : VideoDecoderFactory {
10+
11+
private val factory by lazy { WrappedVideoDecoderFactory(EglUtils.getRootEglBaseContext()) }
12+
override fun createDecoder(codecInfo: VideoCodecInfo): VideoDecoder? {
13+
return factory.createDecoder(codecInfo)
14+
}
15+
16+
override fun getSupportedCodecs(): Array<VideoCodecInfo> {
17+
return factory.supportedCodecs
18+
}
19+
}

ci/android/app/src/main/java/com/ci/MainApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
99
import com.facebook.react.defaults.DefaultReactNativeHost;
1010
import com.facebook.soloader.SoLoader;
11+
import com.livekit.reactnative.LiveKitReactNative;
1112
import java.util.List;
1213

1314
public class MainApplication extends Application implements ReactApplication {
@@ -51,6 +52,7 @@ public ReactNativeHost getReactNativeHost() {
5152

5253
@Override
5354
public void onCreate() {
55+
LiveKitReactNative.setup();
5456
super.onCreate();
5557
SoLoader.init(this, /* native exopackage */ false);
5658
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {

ci/ios/ci/AppDelegate.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#import "AppDelegate.h"
2-
2+
#import "LivekitReactNative.h"
33
#import <React/RCTBundleURLProvider.h>
44

55
@implementation AppDelegate
66

77
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
88
{
9+
[LivekitReactNative setup];
910
self.moduleName = @"ci";
1011
// You can add your custom initial props in the dictionary below.
1112
// They will be passed down to the ViewController used by React Native.

ci/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
},
1313
"dependencies": {
1414
"@livekit/react-native": "*",
15-
"@livekit/react-native-webrtc": "^104.0.0",
15+
"@livekit/react-native-webrtc": "^104.0.1",
1616
"react": "18.2.0",
1717
"react-native": "0.71.10"
1818
},

ci/yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1506,7 +1506,7 @@
15061506
"@jridgewell/resolve-uri" "3.1.0"
15071507
"@jridgewell/sourcemap-codec" "1.4.14"
15081508

1509-
"@livekit/react-native-webrtc@^104.0.0":
1509+
"@livekit/react-native-webrtc@^104.0.1":
15101510
version "104.0.1"
15111511
resolved "https://registry.yarnpkg.com/@livekit/react-native-webrtc/-/react-native-webrtc-104.0.1.tgz#1ff7d2db984e9b00dbf29aabca0c1f037f845415"
15121512
integrity sha512-mlp0gsOEOQAhAeWsTZpw+m+dcLLWXdrU5wndQ3AT8kLrIaMqgyNJw11ybpDIJNRaHVIL35oOJKYgnIllwBT4tw==

0 commit comments

Comments
 (0)