Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(android) make application more akin to a greenfield RN app
Saúl Ibarra Corretgée61ccc956f17
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xmlindex a82b9f9a25..27122663ea 100644--- a/android/app/src/main/AndroidManifest.xml+++ b/android/app/src/main/AndroidManifest.xml@@ -7,6 +7,7 @@android:extractNativeLibs="true"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"+ android:name=".MainApplication"android:networkSecurityConfig="@xml/network_security_config"android:theme="@style/AppTheme"><meta-datadiff --git a/android/app/src/main/java/org/jitsi/meet/MainApplication.java b/android/app/src/main/java/org/jitsi/meet/MainApplication.javanew file mode 100644index 0000000000..f79d1ffdd6--- /dev/null+++ b/android/app/src/main/java/org/jitsi/meet/MainApplication.java@@ -0,0 +1,47 @@+/*+ * Copyright @ 2022-present 8x8, Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.jitsi.meet;++import android.app.Application;+import android.util.Log;++import com.facebook.react.ReactApplication;+import com.facebook.react.ReactNativeHost;++import org.jitsi.meet.sdk.JitsiReactNativeHost;++/**+ * Application class for Jitsi Meet. The only reason why this exists is for Detox+ * to believe our app is a "greenfield" app. SDK users need not use this.+ */+public class MainApplication extends Application implements ReactApplication {+ private final ReactNativeHost mReactNativeHost = new JitsiReactNativeHost(this);++ @Override+ public ReactNativeHost getReactNativeHost() {+ return mReactNativeHost;+ }++ @Override+ public void onCreate() {+ super.onCreate();++ // Initialize RN+ Log.d(this.getClass().getCanonicalName(), "app onCreate");+ getReactNativeHost().getReactInstanceManager();+ }+}diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiInitializer.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiInitializer.javaindex 4630d6b769..6b09c62240 100644--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiInitializer.java+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiInitializer.java@@ -16,6 +16,7 @@package org.jitsi.meet.sdk;import android.content.Context;+import android.util.Log;import androidx.annotation.NonNull;import androidx.startup.Initializer;@@ -30,6 +31,8 @@ public class JitsiInitializer implements Initializer<Boolean> {@NonNull@Overridepublic Boolean create(@NonNull Context context) {+ Log.d(this.getClass().getCanonicalName(), "create");+SoLoader.init(context, /* native exopackage */ false);// Register our uncaught exception handler.diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiReactNativeHost.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiReactNativeHost.javanew file mode 100644index 0000000000..2237151a17--- /dev/null+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiReactNativeHost.java@@ -0,0 +1,41 @@+package org.jitsi.meet.sdk;++import android.app.Application;++import com.facebook.react.ReactInstanceManager;+import com.facebook.react.ReactNativeHost;+import com.facebook.react.ReactPackage;++import java.util.List;++/**+ * This is the minimal implementation of ReactNativeHost that will make things like the+ * Detox testing framework believe we are a "greenfield" app.+ *+ * Generally speaking, apps using the SDK (other than the Jitsi Meet app itself) should not+ * need to use this because the+ */+public class JitsiReactNativeHost extends ReactNativeHost {+ public JitsiReactNativeHost(Application application) {+ super(application);+ }++ @Override+ public boolean getUseDeveloperSupport() {+ // Unused since we override `createReactInstanceManager`.+ return false;+ }++ @Override+ protected List<ReactPackage> getPackages() {+ // Unused since we override `createReactInstanceManager`.+ return null;+ }++ @Override+ protected ReactInstanceManager createReactInstanceManager() {+ ReactInstanceManagerHolder.initReactInstanceManager(this.getApplication());++ return ReactInstanceManagerHolder.getReactInstanceManager();+ }+}diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.javaindex b84e364a8c..ea6007aed1 100644--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java@@ -17,6 +17,8 @@package org.jitsi.meet.sdk;import android.app.Activity;+import android.app.Application;+import android.util.Log;import androidx.annotation.Nullable;@@ -99,6 +101,69 @@ class ReactInstanceManagerHolder {);}+ static List<ReactPackage> getReactNativePackages() {+ List<ReactPackage> packages+ = new ArrayList<>(Arrays.asList(+ new com.reactnativecommunity.asyncstorage.AsyncStoragePackage(),+ new com.ocetnik.timer.BackgroundTimerPackage(),+ new com.calendarevents.RNCalendarEventsPackage(),+ new com.corbt.keepawake.KCKeepAwakePackage(),+ new com.facebook.react.shell.MainReactPackage(),+ new com.reactnativecommunity.clipboard.ClipboardPackage(),+ new com.reactnativecommunity.netinfo.NetInfoPackage(),+ new com.reactnativepagerview.PagerViewPackage(),+ new com.oblador.performance.PerformancePackage(),+ new com.reactnativecommunity.slider.ReactSliderPackage(),+ new com.brentvatne.react.ReactVideoPackage(),+ new com.swmansion.reanimated.ReanimatedPackage(),+ new org.reactnative.maskedview.RNCMaskedViewPackage(),+ new com.reactnativecommunity.webview.RNCWebViewPackage(),+ new com.kevinresol.react_native_default_preference.RNDefaultPreferencePackage(),+ new com.learnium.RNDeviceInfo.RNDeviceInfo(),+ new com.swmansion.gesturehandler.react.RNGestureHandlerPackage(),+ new org.linusu.RNGetRandomValuesPackage(),+ new com.rnimmersive.RNImmersivePackage(),+ new com.swmansion.rnscreens.RNScreensPackage(),+ new com.zmxv.RNSound.RNSoundPackage(),+ new com.th3rdwave.safeareacontext.SafeAreaContextPackage(),+ new com.horcrux.svg.SvgPackage(),+ new ReactPackageAdapter() {+ @Override+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {+ return ReactInstanceManagerHolder.createNativeModules(reactContext);+ }+ @Override+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {+ return ReactInstanceManagerHolder.createViewManagers(reactContext);+ }+ }));++ // AmplitudeReactNativePackage+ try {+ Class<?> amplitudePackageClass = Class.forName("com.amplitude.reactnative.AmplitudeReactNativePackage");+ Constructor constructor = amplitudePackageClass.getConstructor();+ packages.add((ReactPackage)constructor.newInstance());+ } catch (Exception e) {+ // Ignore any error, the module is not compiled when LIBRE_BUILD is enabled.+ }++ // RNGoogleSignInPackage+ try {+ Class<?> googlePackageClass = Class.forName("com.reactnativegooglesignin.RNGoogleSigninPackage");+ Constructor constructor = googlePackageClass.getConstructor();+ packages.add((ReactPackage)constructor.newInstance());+ } catch (Exception e) {+ // Ignore any error, the module is not compiled when LIBRE_BUILD is enabled.+ }++ return packages;+ }++ static JSCExecutorFactory getReactNativeJSFactory() {+ // Keep on using JSC, the jury is out on Hermes.+ return new JSCExecutorFactory("", "");+ }+/*** Helper function to send an event to JavaScript.*@@ -165,70 +230,43 @@ class ReactInstanceManagerHolder {* time. All {@code ReactRootView} instances will be tied to the one and* only {@code ReactInstanceManager}.*- * @param activity {@code Activity} current running Activity.+ * This method is only meant to be called when integrating with {@code JitsiReactNativeHost}.+ *+ * @param app {@code Application} current running Application.*/- static void initReactInstanceManager(Activity activity) {+ static void initReactInstanceManager(Application app) {if (reactInstanceManager != null) {return;}- List<ReactPackage> packages- = new ArrayList<>(Arrays.asList(- new com.reactnativecommunity.asyncstorage.AsyncStoragePackage(),- new com.ocetnik.timer.BackgroundTimerPackage(),- new com.calendarevents.RNCalendarEventsPackage(),- new com.corbt.keepawake.KCKeepAwakePackage(),- new com.facebook.react.shell.MainReactPackage(),- new com.reactnativecommunity.clipboard.ClipboardPackage(),- new com.reactnativecommunity.netinfo.NetInfoPackage(),- new com.reactnativepagerview.PagerViewPackage(),- new com.oblador.performance.PerformancePackage(),- new com.reactnativecommunity.slider.ReactSliderPackage(),- new com.brentvatne.react.ReactVideoPackage(),- new com.swmansion.reanimated.ReanimatedPackage(),- new org.reactnative.maskedview.RNCMaskedViewPackage(),- new com.reactnativecommunity.webview.RNCWebViewPackage(),- new com.kevinresol.react_native_default_preference.RNDefaultPreferencePackage(),- new com.learnium.RNDeviceInfo.RNDeviceInfo(),- new com.swmansion.gesturehandler.react.RNGestureHandlerPackage(),- new org.linusu.RNGetRandomValuesPackage(),- new com.rnimmersive.RNImmersivePackage(),- new com.swmansion.rnscreens.RNScreensPackage(),- new com.zmxv.RNSound.RNSoundPackage(),- new com.th3rdwave.safeareacontext.SafeAreaContextPackage(),- new com.horcrux.svg.SvgPackage(),- new ReactPackageAdapter() {- @Override- public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {- return ReactInstanceManagerHolder.createNativeModules(reactContext);- }- @Override- public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {- return ReactInstanceManagerHolder.createViewManagers(reactContext);- }- }));+ Log.d(ReactInstanceManagerHolder.class.getCanonicalName(), "initializing RN with Application");- // AmplitudeReactNativePackage- try {- Class<?> amplitudePackageClass = Class.forName("com.amplitude.reactnative.AmplitudeReactNativePackage");- Constructor constructor = amplitudePackageClass.getConstructor();- packages.add((ReactPackage)constructor.newInstance());- } catch (Exception e) {- // Ignore any error, the module is not compiled when LIBRE_BUILD is enabled.- }+ reactInstanceManager+ = ReactInstanceManager.builder()+ .setApplication(app)+ .setBundleAssetName("index.android.bundle")+ .setJSMainModulePath("index.android")+ .setJavaScriptExecutorFactory(getReactNativeJSFactory())+ .addPackages(getReactNativePackages())+ .setUseDeveloperSupport(BuildConfig.DEBUG)+ .setInitialLifecycleState(LifecycleState.BEFORE_CREATE)+ .build();+ }- // RNGoogleSigninPackage- try {- Class<?> googlePackageClass = Class.forName("com.reactnativegooglesignin.RNGoogleSigninPackage");- Constructor constructor = googlePackageClass.getConstructor();- packages.add((ReactPackage)constructor.newInstance());- } catch (Exception e) {- // Ignore any error, the module is not compiled when LIBRE_BUILD is enabled.+ /**+ * Internal method to initialize the React Native instance manager. We+ * create a single instance in order to load the JavaScript bundle a single+ * time. All {@code ReactRootView} instances will be tied to the one and+ * only {@code ReactInstanceManager}.+ *+ * @param activity {@code Activity} current running Activity.+ */+ static void initReactInstanceManager(Activity activity) {+ if (reactInstanceManager != null) {+ return;}- // Keep on using JSC, the jury is out on Hermes.- JSCExecutorFactory jsFactory- = new JSCExecutorFactory("", "");+ Log.d(ReactInstanceManagerHolder.class.getCanonicalName(), "initializing RN with Activity");reactInstanceManager= ReactInstanceManager.builder()@@ -236,8 +274,8 @@ class ReactInstanceManagerHolder {.setCurrentActivity(activity).setBundleAssetName("index.android.bundle").setJSMainModulePath("index.android")- .setJavaScriptExecutorFactory(jsFactory)- .addPackages(packages)+ .setJavaScriptExecutorFactory(getReactNativeJSFactory())+ .addPackages(getReactNativePackages()).setUseDeveloperSupport(BuildConfig.DEBUG).setInitialLifecycleState(LifecycleState.RESUMED).build();