|
@@ -16,57 +16,33 @@
|
16
|
16
|
|
17
|
17
|
package org.jitsi.meet.sdk;
|
18
|
18
|
|
19
|
|
-import android.app.Activity;
|
20
|
19
|
import android.content.Context;
|
21
|
|
-import android.content.Intent;
|
22
|
|
-import android.net.Uri;
|
23
|
20
|
import android.os.Bundle;
|
24
|
21
|
import android.support.annotation.NonNull;
|
25
|
22
|
import android.support.annotation.Nullable;
|
26
|
23
|
import android.util.Log;
|
27
|
|
-import android.widget.FrameLayout;
|
28
|
24
|
|
29
|
|
-import com.facebook.react.ReactInstanceManager;
|
30
|
|
-import com.facebook.react.ReactRootView;
|
31
|
|
-import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
|
32
|
|
-import com.rnimmersive.RNImmersiveModule;
|
|
25
|
+import com.facebook.react.bridge.ReadableMap;
|
33
|
26
|
|
34
|
27
|
import org.jitsi.meet.sdk.invite.InviteController;
|
35
|
28
|
|
|
29
|
+import java.lang.reflect.Method;
|
36
|
30
|
import java.net.URL;
|
37
|
|
-import java.util.Collections;
|
38
|
|
-import java.util.Set;
|
39
|
|
-import java.util.UUID;
|
40
|
|
-import java.util.WeakHashMap;
|
|
31
|
+import java.util.Map;
|
41
|
32
|
|
42
|
|
-public class JitsiMeetView extends FrameLayout {
|
|
33
|
+public class JitsiMeetView extends BaseReactView {
|
43
|
34
|
/**
|
44
|
|
- * Background color used by {@code JitsiMeetView} and the React Native root
|
45
|
|
- * view.
|
|
35
|
+ * The {@code Method}s of {@code JitsiMeetViewListener} by event name i.e.
|
|
36
|
+ * redux action types.
|
46
|
37
|
*/
|
47
|
|
- private static final int BACKGROUND_COLOR = 0xFF111111;
|
|
38
|
+ private static final Map<String, Method> LISTENER_METHODS
|
|
39
|
+ = ListenerUtils.slurpListenerMethods(JitsiMeetViewListener.class);
|
48
|
40
|
|
49
|
41
|
/**
|
50
|
42
|
* The {@link Log} tag which identifies the source of the log messages of
|
51
|
43
|
* {@code JitsiMeetView}.
|
52
|
44
|
*/
|
53
|
|
- private final static String TAG = JitsiMeetView.class.getSimpleName();
|
54
|
|
-
|
55
|
|
- private static final Set<JitsiMeetView> views
|
56
|
|
- = Collections.newSetFromMap(new WeakHashMap<JitsiMeetView, Boolean>());
|
57
|
|
-
|
58
|
|
- public static JitsiMeetView findViewByExternalAPIScope(
|
59
|
|
- String externalAPIScope) {
|
60
|
|
- synchronized (views) {
|
61
|
|
- for (JitsiMeetView view : views) {
|
62
|
|
- if (view.externalAPIScope.equals(externalAPIScope)) {
|
63
|
|
- return view;
|
64
|
|
- }
|
65
|
|
- }
|
66
|
|
- }
|
67
|
|
-
|
68
|
|
- return null;
|
69
|
|
- }
|
|
45
|
+ private static final String TAG = JitsiMeetView.class.getSimpleName();
|
70
|
46
|
|
71
|
47
|
/**
|
72
|
48
|
* Loads a specific URL {@code String} in all existing
|
|
@@ -78,130 +54,19 @@ public class JitsiMeetView extends FrameLayout {
|
78
|
54
|
* at least one {@code JitsiMeetView}, then {@code true}; otherwise,
|
79
|
55
|
* {@code false}.
|
80
|
56
|
*/
|
81
|
|
- private static boolean loadURLStringInViews(String urlString) {
|
|
57
|
+ public static boolean loadURLStringInViews(String urlString) {
|
|
58
|
+ boolean loaded = false;
|
|
59
|
+
|
82
|
60
|
synchronized (views) {
|
83
|
|
- if (!views.isEmpty()) {
|
84
|
|
- for (JitsiMeetView view : views) {
|
85
|
|
- view.loadURLString(urlString);
|
|
61
|
+ for (BaseReactView view : views) {
|
|
62
|
+ if (view instanceof JitsiMeetView) {
|
|
63
|
+ ((JitsiMeetView)view).loadURLString(urlString);
|
|
64
|
+ loaded = true;
|
86
|
65
|
}
|
87
|
|
-
|
88
|
|
- return true;
|
89
|
66
|
}
|
90
|
67
|
}
|
91
|
68
|
|
92
|
|
- return false;
|
93
|
|
- }
|
94
|
|
-
|
95
|
|
- /**
|
96
|
|
- * Activity lifecycle method which should be called from
|
97
|
|
- * {@code Activity.onBackPressed} so we can do the required internal
|
98
|
|
- * processing.
|
99
|
|
- *
|
100
|
|
- * @return {@code true} if the back-press was processed; {@code false},
|
101
|
|
- * otherwise. If {@code false}, the application should call the parent's
|
102
|
|
- * implementation.
|
103
|
|
- */
|
104
|
|
- public static boolean onBackPressed() {
|
105
|
|
- ReactInstanceManager reactInstanceManager
|
106
|
|
- = ReactInstanceManagerHolder.getReactInstanceManager();
|
107
|
|
-
|
108
|
|
- if (reactInstanceManager == null) {
|
109
|
|
- return false;
|
110
|
|
- } else {
|
111
|
|
- reactInstanceManager.onBackPressed();
|
112
|
|
- return true;
|
113
|
|
- }
|
114
|
|
- }
|
115
|
|
-
|
116
|
|
- /**
|
117
|
|
- * Activity lifecycle method which should be called from
|
118
|
|
- * {@code Activity.onDestroy} so we can do the required internal
|
119
|
|
- * processing.
|
120
|
|
- *
|
121
|
|
- * @param activity {@code Activity} being destroyed.
|
122
|
|
- */
|
123
|
|
- public static void onHostDestroy(Activity activity) {
|
124
|
|
- ReactInstanceManager reactInstanceManager
|
125
|
|
- = ReactInstanceManagerHolder.getReactInstanceManager();
|
126
|
|
-
|
127
|
|
- if (reactInstanceManager != null) {
|
128
|
|
- reactInstanceManager.onHostDestroy(activity);
|
129
|
|
- }
|
130
|
|
- }
|
131
|
|
-
|
132
|
|
- /**
|
133
|
|
- * Activity lifecycle method which should be called from
|
134
|
|
- * {@code Activity.onPause} so we can do the required internal processing.
|
135
|
|
- *
|
136
|
|
- * @param activity {@code Activity} being paused.
|
137
|
|
- */
|
138
|
|
- public static void onHostPause(Activity activity) {
|
139
|
|
- ReactInstanceManager reactInstanceManager
|
140
|
|
- = ReactInstanceManagerHolder.getReactInstanceManager();
|
141
|
|
-
|
142
|
|
- if (reactInstanceManager != null) {
|
143
|
|
- reactInstanceManager.onHostPause(activity);
|
144
|
|
- }
|
145
|
|
- }
|
146
|
|
-
|
147
|
|
- /**
|
148
|
|
- * Activity lifecycle method which should be called from
|
149
|
|
- * {@code Activity.onResume} so we can do the required internal processing.
|
150
|
|
- *
|
151
|
|
- * @param activity {@code Activity} being resumed.
|
152
|
|
- */
|
153
|
|
- public static void onHostResume(Activity activity) {
|
154
|
|
- onHostResume(activity, new DefaultHardwareBackBtnHandlerImpl(activity));
|
155
|
|
- }
|
156
|
|
-
|
157
|
|
- /**
|
158
|
|
- * Activity lifecycle method which should be called from
|
159
|
|
- * {@code Activity.onResume} so we can do the required internal processing.
|
160
|
|
- *
|
161
|
|
- * @param activity {@code Activity} being resumed.
|
162
|
|
- * @param defaultBackButtonImpl a {@code DefaultHardwareBackBtnHandler} to
|
163
|
|
- * handle invoking the back button if no {@code JitsiMeetView} handles it.
|
164
|
|
- */
|
165
|
|
- public static void onHostResume(
|
166
|
|
- Activity activity,
|
167
|
|
- DefaultHardwareBackBtnHandler defaultBackButtonImpl) {
|
168
|
|
- ReactInstanceManager reactInstanceManager
|
169
|
|
- = ReactInstanceManagerHolder.getReactInstanceManager();
|
170
|
|
-
|
171
|
|
- if (reactInstanceManager != null) {
|
172
|
|
- reactInstanceManager.onHostResume(activity, defaultBackButtonImpl);
|
173
|
|
- }
|
174
|
|
- }
|
175
|
|
-
|
176
|
|
- /**
|
177
|
|
- * Activity lifecycle method which should be called from
|
178
|
|
- * {@code Activity.onNewIntent} so we can do the required internal
|
179
|
|
- * processing. Note that this is only needed if the activity's "launchMode"
|
180
|
|
- * was set to "singleTask". This is required for deep linking to work once
|
181
|
|
- * the application is already running.
|
182
|
|
- *
|
183
|
|
- * @param intent {@code Intent} instance which was received.
|
184
|
|
- */
|
185
|
|
- public static void onNewIntent(Intent intent) {
|
186
|
|
- // XXX At least twice we received bug reports about malfunctioning
|
187
|
|
- // loadURL in the Jitsi Meet SDK while the Jitsi Meet app seemed to
|
188
|
|
- // functioning as expected in our testing. But that was to be expected
|
189
|
|
- // because the app does not exercise loadURL. In order to increase the
|
190
|
|
- // test coverage of loadURL, channel deep linking through loadURL.
|
191
|
|
- Uri uri;
|
192
|
|
-
|
193
|
|
- if (Intent.ACTION_VIEW.equals(intent.getAction())
|
194
|
|
- && (uri = intent.getData()) != null
|
195
|
|
- && loadURLStringInViews(uri.toString())) {
|
196
|
|
- return;
|
197
|
|
- }
|
198
|
|
-
|
199
|
|
- ReactInstanceManager reactInstanceManager
|
200
|
|
- = ReactInstanceManagerHolder.getReactInstanceManager();
|
201
|
|
-
|
202
|
|
- if (reactInstanceManager != null) {
|
203
|
|
- reactInstanceManager.onNewIntent(intent);
|
204
|
|
- }
|
|
69
|
+ return loaded;
|
205
|
70
|
}
|
206
|
71
|
|
207
|
72
|
/**
|
|
@@ -211,14 +76,6 @@ public class JitsiMeetView extends FrameLayout {
|
211
|
76
|
*/
|
212
|
77
|
private URL defaultURL;
|
213
|
78
|
|
214
|
|
- /**
|
215
|
|
- * The unique identifier of this {@code JitsiMeetView} within the process
|
216
|
|
- * for the purposes of {@link ExternalAPI}. The name scope was inspired by
|
217
|
|
- * postis which we use on Web for the similar purposes of the iframe-based
|
218
|
|
- * external API.
|
219
|
|
- */
|
220
|
|
- private final String externalAPIScope;
|
221
|
|
-
|
222
|
79
|
/**
|
223
|
80
|
* The entry point into the invite feature of Jitsi Meet. The Java
|
224
|
81
|
* counterpart of the JavaScript {@code InviteButton}.
|
|
@@ -238,11 +95,6 @@ public class JitsiMeetView extends FrameLayout {
|
238
|
95
|
*/
|
239
|
96
|
private Boolean pictureInPictureEnabled;
|
240
|
97
|
|
241
|
|
- /**
|
242
|
|
- * React Native root view.
|
243
|
|
- */
|
244
|
|
- private ReactRootView reactRootView;
|
245
|
|
-
|
246
|
98
|
/**
|
247
|
99
|
* The URL of the current conference.
|
248
|
100
|
*/
|
|
@@ -258,34 +110,33 @@ public class JitsiMeetView extends FrameLayout {
|
258
|
110
|
public JitsiMeetView(@NonNull Context context) {
|
259
|
111
|
super(context);
|
260
|
112
|
|
261
|
|
- setBackgroundColor(BACKGROUND_COLOR);
|
262
|
|
-
|
263
|
|
- ReactInstanceManagerHolder.initReactInstanceManager(
|
264
|
|
- ((Activity) context).getApplication());
|
265
|
|
-
|
266
|
|
- // Hook this JitsiMeetView into ExternalAPI.
|
267
|
|
- externalAPIScope = UUID.randomUUID().toString();
|
268
|
|
- synchronized (views) {
|
269
|
|
- views.add(this);
|
270
|
|
- }
|
271
|
|
-
|
272
|
113
|
// The entry point into the invite feature of Jitsi Meet. The Java
|
273
|
114
|
// counterpart of the JavaScript InviteButton.
|
274
|
115
|
inviteController = new InviteController(externalAPIScope);
|
275
|
116
|
}
|
276
|
117
|
|
277
|
118
|
/**
|
278
|
|
- * Releases the React resources (specifically the {@link ReactRootView})
|
279
|
|
- * associated with this view.
|
|
119
|
+ * Enters Picture-In-Picture mode, if possible. This method is designed to
|
|
120
|
+ * be called from the {@code Activity.onUserLeaveHint} method.
|
280
|
121
|
*
|
281
|
|
- * This method MUST be called when the Activity holding this view is
|
282
|
|
- * destroyed, typically in the {@code onDestroy} method.
|
|
122
|
+ * This is currently not mandatory, but if used will provide automatic
|
|
123
|
+ * handling of the picture in picture mode when user minimizes the app. It
|
|
124
|
+ * will be probably the most useful in case the app is using the welcome
|
|
125
|
+ * page.
|
283
|
126
|
*/
|
284
|
|
- public void dispose() {
|
285
|
|
- if (reactRootView != null) {
|
286
|
|
- removeView(reactRootView);
|
287
|
|
- reactRootView.unmountReactApplication();
|
288
|
|
- reactRootView = null;
|
|
127
|
+ public void enterPictureInPicture() {
|
|
128
|
+ if (getPictureInPictureEnabled() && getURL() != null) {
|
|
129
|
+ PictureInPictureModule pipModule
|
|
130
|
+ = ReactInstanceManagerHolder.getNativeModule(
|
|
131
|
+ PictureInPictureModule.class);
|
|
132
|
+
|
|
133
|
+ if (pipModule != null) {
|
|
134
|
+ try {
|
|
135
|
+ pipModule.enterPictureInPicture();
|
|
136
|
+ } catch (RuntimeException re) {
|
|
137
|
+ Log.e(TAG, "onUserLeaveHint: failed to enter PiP mode", re);
|
|
138
|
+ }
|
|
139
|
+ }
|
289
|
140
|
}
|
290
|
141
|
}
|
291
|
142
|
|
|
@@ -294,7 +145,7 @@ public class JitsiMeetView extends FrameLayout {
|
294
|
145
|
* partial URL (e.g. a room name only) is specified to
|
295
|
146
|
* {@link #loadURLString(String)} or {@link #loadURLObject(Bundle)}. If not
|
296
|
147
|
* set or if set to {@code null}, the default built in JavaScript is used:
|
297
|
|
- * {@link https://meet.jit.si}
|
|
148
|
+ * https://meet.jit.si
|
298
|
149
|
*
|
299
|
150
|
* @return The default base {@code URL} or {@code null}.
|
300
|
151
|
*/
|
|
@@ -337,7 +188,7 @@ public class JitsiMeetView extends FrameLayout {
|
337
|
188
|
return
|
338
|
189
|
PictureInPictureModule.isPictureInPictureSupported()
|
339
|
190
|
&& (pictureInPictureEnabled == null
|
340
|
|
- || pictureInPictureEnabled.booleanValue());
|
|
191
|
+ || pictureInPictureEnabled);
|
341
|
192
|
}
|
342
|
193
|
|
343
|
194
|
/**
|
|
@@ -395,9 +246,6 @@ public class JitsiMeetView extends FrameLayout {
|
395
|
246
|
props.putString("defaultURL", defaultURL.toString());
|
396
|
247
|
}
|
397
|
248
|
|
398
|
|
- // externalAPIScope
|
399
|
|
- props.putString("externalAPIScope", externalAPIScope);
|
400
|
|
-
|
401
|
249
|
// inviteController
|
402
|
250
|
InviteController inviteController = getInviteController();
|
403
|
251
|
|
|
@@ -434,17 +282,7 @@ public class JitsiMeetView extends FrameLayout {
|
434
|
282
|
// per loadURLObject: invocation.
|
435
|
283
|
props.putLong("timestamp", System.currentTimeMillis());
|
436
|
284
|
|
437
|
|
- if (reactRootView == null) {
|
438
|
|
- reactRootView = new ReactRootView(getContext());
|
439
|
|
- reactRootView.startReactApplication(
|
440
|
|
- ReactInstanceManagerHolder.getReactInstanceManager(),
|
441
|
|
- "App",
|
442
|
|
- props);
|
443
|
|
- reactRootView.setBackgroundColor(BACKGROUND_COLOR);
|
444
|
|
- addView(reactRootView);
|
445
|
|
- } else {
|
446
|
|
- reactRootView.setAppProperties(props);
|
447
|
|
- }
|
|
285
|
+ createReactRootView("App", props);
|
448
|
286
|
}
|
449
|
287
|
|
450
|
288
|
/**
|
|
@@ -468,65 +306,50 @@ public class JitsiMeetView extends FrameLayout {
|
468
|
306
|
}
|
469
|
307
|
|
470
|
308
|
/**
|
471
|
|
- * Activity lifecycle method which should be called from
|
472
|
|
- * {@code Activity.onUserLeaveHint} so we can do the required internal
|
473
|
|
- * processing.
|
|
309
|
+ * The internal processing for the URL of the current conference set on the
|
|
310
|
+ * associated {@link JitsiMeetView}.
|
474
|
311
|
*
|
475
|
|
- * This is currently not mandatory, but if used will provide automatic
|
476
|
|
- * handling of the picture in picture mode when user minimizes the app. It
|
477
|
|
- * will be probably the most useful in case the app is using the welcome
|
478
|
|
- * page.
|
479
|
|
- */
|
480
|
|
- public void onUserLeaveHint() {
|
481
|
|
- if (getPictureInPictureEnabled() && getURL() != null) {
|
482
|
|
- PictureInPictureModule pipModule
|
483
|
|
- = ReactInstanceManagerHolder.getNativeModule(
|
484
|
|
- PictureInPictureModule.class);
|
485
|
|
-
|
486
|
|
- if (pipModule != null) {
|
487
|
|
- try {
|
488
|
|
- pipModule.enterPictureInPicture();
|
489
|
|
- } catch (RuntimeException re) {
|
490
|
|
- Log.e(TAG, "onUserLeaveHint: failed to enter PiP mode", re);
|
491
|
|
- }
|
|
312
|
+ * @param eventName the name of the external API event to be processed
|
|
313
|
+ * @param eventData the details/specifics of the event to process determined
|
|
314
|
+ * by/associated with the specified {@code eventName}.
|
|
315
|
+ */
|
|
316
|
+ private void maybeSetViewURL(String eventName, ReadableMap eventData) {
|
|
317
|
+ switch(eventName) {
|
|
318
|
+ case "CONFERENCE_WILL_JOIN":
|
|
319
|
+ setURL(eventData.getString("url"));
|
|
320
|
+ break;
|
|
321
|
+
|
|
322
|
+ case "CONFERENCE_FAILED":
|
|
323
|
+ case "CONFERENCE_WILL_LEAVE":
|
|
324
|
+ case "LOAD_CONFIG_ERROR":
|
|
325
|
+ String url = eventData.getString("url");
|
|
326
|
+
|
|
327
|
+ if (url != null && url.equals(getURL())) {
|
|
328
|
+ setURL(null);
|
492
|
329
|
}
|
|
330
|
+ break;
|
493
|
331
|
}
|
494
|
332
|
}
|
495
|
333
|
|
496
|
334
|
/**
|
497
|
|
- * Called when the window containing this view gains or loses focus.
|
|
335
|
+ * Handler for {@link ExternalAPIModule} events.
|
498
|
336
|
*
|
499
|
|
- * @param hasFocus If the window of this view now has focus, {@code true};
|
500
|
|
- * otherwise, {@code false}.
|
|
337
|
+ * @param name - Name of the event.
|
|
338
|
+ * @param data - Event data.
|
501
|
339
|
*/
|
502
|
340
|
@Override
|
503
|
|
- public void onWindowFocusChanged(boolean hasFocus) {
|
504
|
|
- super.onWindowFocusChanged(hasFocus);
|
505
|
|
-
|
506
|
|
- // https://github.com/mockingbot/react-native-immersive#restore-immersive-state
|
507
|
|
-
|
508
|
|
- // FIXME The singleton pattern employed by RNImmersiveModule is not
|
509
|
|
- // advisable because a react-native mobule is consumable only after its
|
510
|
|
- // BaseJavaModule#initialize() has completed and here we have no
|
511
|
|
- // knowledge of whether the precondition is really met.
|
512
|
|
- RNImmersiveModule immersive = RNImmersiveModule.getInstance();
|
513
|
|
-
|
514
|
|
- if (hasFocus && immersive != null) {
|
515
|
|
- try {
|
516
|
|
- immersive.emitImmersiveStateChangeEvent();
|
517
|
|
- } catch (RuntimeException re) {
|
518
|
|
- // FIXME I don't know how to check myself whether
|
519
|
|
- // BaseJavaModule#initialize() has been invoked and thus
|
520
|
|
- // RNImmersiveModule is consumable. A safe workaround is to
|
521
|
|
- // swallow the failure because the whole full-screen/immersive
|
522
|
|
- // functionality is brittle anyway, akin to the icing on the
|
523
|
|
- // cake, and has been working without onWindowFocusChanged for a
|
524
|
|
- // very long time.
|
525
|
|
- Log.e(
|
526
|
|
- TAG,
|
527
|
|
- "RNImmersiveModule#emitImmersiveStateChangeEvent() failed!",
|
528
|
|
- re);
|
529
|
|
- }
|
|
341
|
+ public void onExternalAPIEvent(String name, ReadableMap data) {
|
|
342
|
+ // XXX The JitsiMeetView property URL was introduced in order to address
|
|
343
|
+ // an exception in the Picture-in-Picture functionality which arose
|
|
344
|
+ // because of delays related to bridging between JavaScript and Java. To
|
|
345
|
+ // reduce these delays do not wait for the call to be transferred to the
|
|
346
|
+ // UI thread.
|
|
347
|
+ maybeSetViewURL(name, data);
|
|
348
|
+
|
|
349
|
+ JitsiMeetViewListener listener = getListener();
|
|
350
|
+ if (listener != null) {
|
|
351
|
+ ListenerUtils.runListenerMethod(
|
|
352
|
+ listener, LISTENER_METHODS, name, data);
|
530
|
353
|
}
|
531
|
354
|
}
|
532
|
355
|
|
|
@@ -563,7 +386,7 @@ public class JitsiMeetView extends FrameLayout {
|
563
|
386
|
* {@code true}; otherwise, {@code false}.
|
564
|
387
|
*/
|
565
|
388
|
public void setPictureInPictureEnabled(boolean pictureInPictureEnabled) {
|
566
|
|
- this.pictureInPictureEnabled = Boolean.valueOf(pictureInPictureEnabled);
|
|
389
|
+ this.pictureInPictureEnabled = pictureInPictureEnabled;
|
567
|
390
|
}
|
568
|
391
|
|
569
|
392
|
/**
|