feat(android) use JitsiMeetView instead of JitsiMeetFragment
This commit is contained in:
parent
cb2b2436eb
commit
6a1067733a
|
@ -20,6 +20,7 @@ package org.jitsi.meet.sdk;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.AttributeSet;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
@ -93,7 +94,7 @@ public abstract class BaseReactView<ListenerT>
|
||||||
* inspired by postis which we use on Web for the similar purposes of the
|
* inspired by postis which we use on Web for the similar purposes of the
|
||||||
* iframe-based external API.
|
* iframe-based external API.
|
||||||
*/
|
*/
|
||||||
protected final String externalAPIScope;
|
protected String externalAPIScope;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The listener (e.g. {@link JitsiMeetViewListener}) instance for reporting
|
* The listener (e.g. {@link JitsiMeetViewListener}) instance for reporting
|
||||||
|
@ -109,16 +110,17 @@ public abstract class BaseReactView<ListenerT>
|
||||||
|
|
||||||
public BaseReactView(@NonNull Context context) {
|
public BaseReactView(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
initialize((Activity)context);
|
||||||
|
}
|
||||||
|
|
||||||
setBackgroundColor(BACKGROUND_COLOR);
|
public BaseReactView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
initialize((Activity)context);
|
||||||
|
}
|
||||||
|
|
||||||
ReactInstanceManagerHolder.initReactInstanceManager((Activity)context);
|
public BaseReactView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
super(context, attrs, defStyle);
|
||||||
// Hook this BaseReactView into ExternalAPI.
|
initialize((Activity)context);
|
||||||
externalAPIScope = UUID.randomUUID().toString();
|
|
||||||
synchronized (views) {
|
|
||||||
views.add(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,4 +225,16 @@ public abstract class BaseReactView<ListenerT>
|
||||||
public void setListener(ListenerT listener) {
|
public void setListener(ListenerT listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initialize(Activity activity) {
|
||||||
|
setBackgroundColor(BACKGROUND_COLOR);
|
||||||
|
|
||||||
|
ReactInstanceManagerHolder.initReactInstanceManager(activity);
|
||||||
|
|
||||||
|
// Hook this BaseReactView into ExternalAPI.
|
||||||
|
externalAPIScope = UUID.randomUUID().toString();
|
||||||
|
synchronized (views) {
|
||||||
|
views.add(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.jitsi.meet.sdk;
|
package org.jitsi.meet.sdk;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -32,11 +33,16 @@ import com.facebook.react.modules.core.PermissionListener;
|
||||||
import org.jitsi.meet.sdk.log.JitsiMeetLogger;
|
import org.jitsi.meet.sdk.log.JitsiMeetLogger;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import android.app.Activity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base activity for SDK users to embed. It uses {@link JitsiMeetFragment} to do the heavy
|
* A base activity for SDK users to embed. It contains all the required wiring
|
||||||
* lifting and wires the remaining Activity lifecycle methods so it works out of the box.
|
* between the {@code JitsiMeetView} and the Activity lifecycle methods.
|
||||||
|
*
|
||||||
|
* In this activity we use a single {@code JitsiMeetView} instance. This
|
||||||
|
* instance gives us access to a view which displays the welcome page and the
|
||||||
|
* conference itself. All lifecycle methods associated with this Activity are
|
||||||
|
* hooked to the React Native subsystem via proxy calls through the
|
||||||
|
* {@code JitsiMeetActivityDelegate} static methods.
|
||||||
*/
|
*/
|
||||||
public class JitsiMeetActivity extends AppCompatActivity
|
public class JitsiMeetActivity extends AppCompatActivity
|
||||||
implements JitsiMeetActivityInterface {
|
implements JitsiMeetActivityInterface {
|
||||||
|
@ -52,6 +58,12 @@ public class JitsiMeetActivity extends AppCompatActivity
|
||||||
onBroadcastReceived(intent);
|
onBroadcastReceived(intent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instance of the {@link JitsiMeetView} which this activity will display.
|
||||||
|
*/
|
||||||
|
private JitsiMeetView jitsiView;
|
||||||
|
|
||||||
// Helpers for starting the activity
|
// Helpers for starting the activity
|
||||||
//
|
//
|
||||||
|
|
||||||
|
@ -79,6 +91,7 @@ public class JitsiMeetActivity extends AppCompatActivity
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.activity_jitsi_meet);
|
setContentView(R.layout.activity_jitsi_meet);
|
||||||
|
this.jitsiView = findViewById(R.id.jitsiView);
|
||||||
|
|
||||||
registerForBroadcastMessages();
|
registerForBroadcastMessages();
|
||||||
|
|
||||||
|
@ -87,6 +100,18 @@ public class JitsiMeetActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
JitsiMeetActivityDelegate.onHostResume(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
JitsiMeetActivityDelegate.onHostPause(this);
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
// Here we are trying to handle the following corner case: an application using the SDK
|
// Here we are trying to handle the following corner case: an application using the SDK
|
||||||
|
@ -97,6 +122,9 @@ public class JitsiMeetActivity extends AppCompatActivity
|
||||||
// be operational so the external API won't be able to notify the native side that the
|
// be operational so the external API won't be able to notify the native side that the
|
||||||
// conference terminated. Thus, try our best to clean up.
|
// conference terminated. Thus, try our best to clean up.
|
||||||
leave();
|
leave();
|
||||||
|
|
||||||
|
this.jitsiView = null;
|
||||||
|
|
||||||
if (AudioModeModule.useConnectionService()) {
|
if (AudioModeModule.useConnectionService()) {
|
||||||
ConnectionService.abortConnections();
|
ConnectionService.abortConnections();
|
||||||
}
|
}
|
||||||
|
@ -104,6 +132,8 @@ public class JitsiMeetActivity extends AppCompatActivity
|
||||||
|
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
|
||||||
|
|
||||||
|
JitsiMeetActivityDelegate.onHostDestroy(this);
|
||||||
|
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,9 +148,7 @@ public class JitsiMeetActivity extends AppCompatActivity
|
||||||
//
|
//
|
||||||
|
|
||||||
protected JitsiMeetView getJitsiView() {
|
protected JitsiMeetView getJitsiView() {
|
||||||
JitsiMeetFragment fragment
|
return jitsiView;
|
||||||
= (JitsiMeetFragment) getSupportFragmentManager().findFragmentById(R.id.jitsiFragment);
|
|
||||||
return fragment != null ? fragment.getJitsiView() : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void join(@Nullable String url) {
|
public void join(@Nullable String url) {
|
||||||
|
@ -132,20 +160,16 @@ public class JitsiMeetActivity extends AppCompatActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
public void join(JitsiMeetConferenceOptions options) {
|
public void join(JitsiMeetConferenceOptions options) {
|
||||||
JitsiMeetView view = getJitsiView();
|
if (this.jitsiView != null) {
|
||||||
|
this.jitsiView .join(options);
|
||||||
if (view != null) {
|
|
||||||
view.join(options);
|
|
||||||
} else {
|
} else {
|
||||||
JitsiMeetLogger.w("Cannot join, view is null");
|
JitsiMeetLogger.w("Cannot join, view is null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leave() {
|
public void leave() {
|
||||||
JitsiMeetView view = getJitsiView();
|
if (this.jitsiView != null) {
|
||||||
|
this.jitsiView .leave();
|
||||||
if (view != null) {
|
|
||||||
view.leave();
|
|
||||||
} else {
|
} else {
|
||||||
JitsiMeetLogger.w("Cannot leave, view is null");
|
JitsiMeetLogger.w("Cannot leave, view is null");
|
||||||
}
|
}
|
||||||
|
@ -252,10 +276,8 @@ public class JitsiMeetActivity extends AppCompatActivity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onUserLeaveHint() {
|
protected void onUserLeaveHint() {
|
||||||
JitsiMeetView view = getJitsiView();
|
if (this.jitsiView != null) {
|
||||||
|
this.jitsiView .enterPictureInPicture();
|
||||||
if (view != null) {
|
|
||||||
view.enterPictureInPicture();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
package org.jitsi.meet.sdk;
|
package org.jitsi.meet.sdk;
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
@ -37,7 +36,10 @@ import android.view.ViewGroup;
|
||||||
* conference itself. All lifecycle methods associated with this Fragment are
|
* conference itself. All lifecycle methods associated with this Fragment are
|
||||||
* hooked to the React Native subsystem via proxy calls through the
|
* hooked to the React Native subsystem via proxy calls through the
|
||||||
* {@code JitsiMeetActivityDelegate} static methods.
|
* {@code JitsiMeetActivityDelegate} static methods.
|
||||||
|
*
|
||||||
|
* @deprecated use {@link JitsiMeetActivity} or directly {@link JitsiMeetView}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public class JitsiMeetFragment extends Fragment {
|
public class JitsiMeetFragment extends Fragment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,6 +18,8 @@ package org.jitsi.meet.sdk;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -28,7 +30,6 @@ import org.jitsi.meet.sdk.log.JitsiMeetLogger;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener>
|
public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener>
|
||||||
implements OngoingConferenceTracker.OngoingConferenceListener {
|
implements OngoingConferenceTracker.OngoingConferenceListener {
|
||||||
|
|
||||||
|
@ -95,14 +96,17 @@ public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener>
|
||||||
|
|
||||||
public JitsiMeetView(@NonNull Context context) {
|
public JitsiMeetView(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
initialize(context);
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the parent Activity implements JitsiMeetActivityInterface,
|
public JitsiMeetView(Context context, AttributeSet attrs) {
|
||||||
// otherwise things may go wrong.
|
super(context, attrs);
|
||||||
if (!(context instanceof JitsiMeetActivityInterface)) {
|
initialize(context);
|
||||||
throw new RuntimeException("Enclosing Activity must implement JitsiMeetActivityInterface");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
OngoingConferenceTracker.getInstance().addListener(this);
|
public JitsiMeetView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
super(context, attrs, defStyle);
|
||||||
|
initialize(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -207,4 +211,14 @@ public class JitsiMeetView extends BaseReactView<JitsiMeetViewListener>
|
||||||
dispose();
|
dispose();
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initialize(@NonNull Context context) {
|
||||||
|
// Check if the parent Activity implements JitsiMeetActivityInterface,
|
||||||
|
// otherwise things may go wrong.
|
||||||
|
if (!(context instanceof JitsiMeetActivityInterface)) {
|
||||||
|
throw new RuntimeException("Enclosing Activity must implement JitsiMeetActivityInterface");
|
||||||
|
}
|
||||||
|
|
||||||
|
OngoingConferenceTracker.getInstance().addListener(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/jitsi_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".JitsiMeetActivity">
|
tools:context=".JitsiMeetActivity">
|
||||||
<fragment
|
|
||||||
|
<org.jitsi.meet.sdk.JitsiMeetView
|
||||||
|
android:id="@+id/jitsiView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent" />
|
||||||
android:name="org.jitsi.meet.sdk.JitsiMeetFragment"
|
|
||||||
android:id="@+id/jitsiFragment"/>
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
Loading…
Reference in New Issue