[Android] Use loadURL in the app

This commit is contained in:
Lyubo Marinov 2017-08-01 12:07:22 -05:00
parent 6b2a93909b
commit 1ad8436cb5
2 changed files with 54 additions and 4 deletions

View File

@ -20,6 +20,7 @@ import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
@ -53,11 +54,13 @@ public class JitsiMeetView extends FrameLayout {
public static JitsiMeetView findViewByExternalAPIScope( public static JitsiMeetView findViewByExternalAPIScope(
String externalAPIScope) { String externalAPIScope) {
synchronized (views) {
for (JitsiMeetView view : views) { for (JitsiMeetView view : views) {
if (view.externalAPIScope.equals(externalAPIScope)) { if (view.externalAPIScope.equals(externalAPIScope)) {
return view; return view;
} }
} }
}
return null; return null;
} }
@ -91,6 +94,30 @@ public class JitsiMeetView extends FrameLayout {
.build(); .build();
} }
/**
* Loads a specific URL {@code String} in all existing
* {@code JitsiMeetView}s.
*
* @param urlString - The URL {@code String} to load in all existing
* {@code JitsiMeetView}s.
* @return If the specified {@code urlString} was submitted for loading in
* at least one {@code JitsiMeetView}, then {@code true}; otherwise,
* {@code false}.
*/
private static boolean loadURLStringInViews(String urlString) {
synchronized (views) {
if (!views.isEmpty()) {
for (JitsiMeetView view : views) {
view.loadURLString(urlString);
}
return true;
}
}
return false;
}
/** /**
* Activity lifecycle method which should be called from * Activity lifecycle method which should be called from
* <tt>Activity.onBackPressed</tt> so we can do the required internal * <tt>Activity.onBackPressed</tt> so we can do the required internal
@ -156,6 +183,19 @@ public class JitsiMeetView extends FrameLayout {
* @param intent - <tt>Intent</tt> instance which was received. * @param intent - <tt>Intent</tt> instance which was received.
*/ */
public static void onNewIntent(Intent intent) { public static void onNewIntent(Intent intent) {
// XXX At least twice we received bug reports about malfunctioning
// loadURL in the Jitsi Meet SDK while the Jitsi Meet app seemed to
// functioning as expected in our testing. But that was to be expected
// because the app does not exercise loadURL. In order to increase the
// test coverage of loadURL, channel deep linking through loadURL.
Uri uri;
if (Intent.ACTION_VIEW.equals(intent.getAction())
&& (uri = intent.getData()) != null
&& loadURLStringInViews(uri.toString())) {
return;
}
if (reactInstanceManager != null) { if (reactInstanceManager != null) {
reactInstanceManager.onNewIntent(intent); reactInstanceManager.onNewIntent(intent);
} }
@ -196,8 +236,10 @@ public class JitsiMeetView extends FrameLayout {
// Hook this JitsiMeetView into ExternalAPI. // Hook this JitsiMeetView into ExternalAPI.
externalAPIScope = UUID.randomUUID().toString(); externalAPIScope = UUID.randomUUID().toString();
synchronized (views) {
views.add(this); views.add(this);
} }
}
/** /**
* Releases the React resources (specifically the {@link ReactRootView}) * Releases the React resources (specifically the {@link ReactRootView})

View File

@ -269,6 +269,14 @@ static NSMapTable<NSString *, JitsiMeetView *> *views;
#pragma mark Private methods #pragma mark Private methods
/**
* Loads a specific {@link NSURL} in all existing {@code JitsiMeetView}s.
*
* @param url - The {@code NSURL} to load in all existing
* {@code JitsiMeetView}s.
* @return {@code YES} if the specified {@code url} was submitted for loading
* in at least one {@code JitsiMeetView}; otherwise, {@code NO}.
*/
+ (BOOL)loadURLInViews:(NSURL *)url { + (BOOL)loadURLInViews:(NSURL *)url {
BOOL handled = NO; BOOL handled = NO;