From 53722fd2e625613a2029dd24b961ff2c4e940569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Wed, 6 Mar 2019 15:11:34 +0100 Subject: [PATCH] android: remove ReactContextUtils In practice, we are never going to be in a position where we don't have a ReactContext but we do have some React Native code running. So let's not expect the impossible. --- .../org/jitsi/meet/sdk/ConnectionService.java | 6 +-- .../org/jitsi/meet/sdk/ReactContextUtils.java | 43 ------------------- .../meet/sdk/ReactInstanceManagerHolder.java | 14 +++--- 3 files changed, 10 insertions(+), 53 deletions(-) delete mode 100644 android/sdk/src/main/java/org/jitsi/meet/sdk/ReactContextUtils.java diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/ConnectionService.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ConnectionService.java index 18af5dd9a..702618ff5 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/ConnectionService.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/ConnectionService.java @@ -332,8 +332,7 @@ public class ConnectionService extends android.telecom.ConnectionService { Log.d(TAG, "onDisconnect " + getCallUUID()); WritableNativeMap data = new WritableNativeMap(); data.putString("callUUID", getCallUUID()); - ReactContextUtils.emitEvent( - null, + ReactInstanceManagerHolder.emitEvent( "org.jitsi.meet:features/connection_service#disconnect", data); // The JavaScript side will not go back to the native with @@ -353,8 +352,7 @@ public class ConnectionService extends android.telecom.ConnectionService { Log.d(TAG, "onAbort " + getCallUUID()); WritableNativeMap data = new WritableNativeMap(); data.putString("callUUID", getCallUUID()); - ReactContextUtils.emitEvent( - null, + ReactInstanceManagerHolder.emitEvent( "org.jitsi.meet:features/connection_service#abort", data); // The JavaScript side will not go back to the native with diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactContextUtils.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactContextUtils.java deleted file mode 100644 index da4fc35e8..000000000 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactContextUtils.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright @ 2017-present Atlassian Pty Ltd - * - * 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.sdk; - -import android.support.annotation.Nullable; - -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.modules.core.DeviceEventManagerModule; - -public class ReactContextUtils { - public static boolean emitEvent( - ReactContext reactContext, - String eventName, - @Nullable Object data) { - if (reactContext == null) { - // XXX If no ReactContext is specified, emit through the - // ReactContext of ReactInstanceManager. ReactInstanceManager - // cooperates with ReactContextUtils i.e. ReactInstanceManager will - // not invoke ReactContextUtils without a ReactContext. - return ReactInstanceManagerHolder.emitEvent(eventName, data); - } - - reactContext - .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) - .emit(eventName, data); - - return true; - } -} 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.java index 79400910b..f32d85d10 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 @@ -24,6 +24,7 @@ import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.common.LifecycleState; +import com.facebook.react.modules.core.DeviceEventManagerModule; import java.util.ArrayList; import java.util.Arrays; @@ -81,12 +82,13 @@ class ReactInstanceManagerHolder { ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); - return - reactContext != null - && ReactContextUtils.emitEvent( - reactContext, - eventName, - data); + if (reactContext != null) { + reactContext + .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) + .emit(eventName, data); + + return true; + } } return false;