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
android: add JitsiMeetActivity
Saúl Ibarra Corretgébf3bcd65d63e
diff --git a/android/app/src/main/java/org/jitsi/meet/MainActivity.java b/android/app/src/main/java/org/jitsi/meet/MainActivity.javaindex 3d919d6fec..5d8b0d93b4 100644--- a/android/app/src/main/java/org/jitsi/meet/MainActivity.java+++ b/android/app/src/main/java/org/jitsi/meet/MainActivity.java@@ -20,34 +20,31 @@ package org.jitsi.meet;import android.content.Intent;import android.net.Uri;import android.os.Build;-import android.os.Bundle;import android.provider.Settings;import android.support.annotation.Nullable;-import android.support.v4.app.FragmentActivity;+import android.util.Log;import android.view.KeyEvent;import org.jitsi.meet.sdk.JitsiMeet;-import org.jitsi.meet.sdk.JitsiMeetActivityInterface;-import org.jitsi.meet.sdk.JitsiMeetActivityDelegate;-import org.jitsi.meet.sdk.JitsiMeetFragment;+import org.jitsi.meet.sdk.JitsiMeetActivity;import org.jitsi.meet.sdk.JitsiMeetConferenceOptions;import com.crashlytics.android.Crashlytics;-import com.facebook.react.modules.core.PermissionListener;import com.google.firebase.dynamiclinks.FirebaseDynamicLinks;import io.fabric.sdk.android.Fabric;import java.net.MalformedURLException;import java.net.URL;+import java.util.Map;/**- * The one and only {@link FragmentActivity} that the Jitsi Meet app needs. The+ * The one and only Activity that the Jitsi Meet app needs. The* {@code Activity} is launched in {@code singleTask} mode, so it will be* created upon application initialization and there will be a single instance* of it. Further attempts at launching the application once it was already- * launched will result in {@link FragmentActivity#onNewIntent(Intent)} being called.+ * launched will result in {@link MainActivity#onNewIntent(Intent)} being called.*/-public class MainActivity extends FragmentActivity implements JitsiMeetActivityInterface {+public class MainActivity extends JitsiMeetActivity {/*** The request code identifying requests for the permission to draw on top* of other apps. The value must be 16-bit and is arbitrarily chosen here.@@ -55,19 +52,49 @@ public class MainActivity extends FragmentActivity implements JitsiMeetActivityIprivate static final int OVERLAY_PERMISSION_REQUEST_CODE= (int) (Math.random() * Short.MAX_VALUE);- private JitsiMeetFragment getFragment() {- return (JitsiMeetFragment) getSupportFragmentManager().findFragmentById(R.id.jitsiFragment);- }+ // JitsiMeetActivity overrides+ //- private @Nullable URL buildURL(String urlStr) {- try {- return new URL(urlStr);- } catch (MalformedURLException e) {- return null;+ @Override+ protected boolean extraInitialize() {+ // Setup Crashlytics and Firebase Dynamic Links+ if (BuildConfig.GOOGLE_SERVICES_ENABLED) {+ Fabric.with(this, new Crashlytics());++ FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent())+ .addOnSuccessListener(this, pendingDynamicLinkData -> {+ Uri dynamicLink = null;++ if (pendingDynamicLinkData != null) {+ dynamicLink = pendingDynamicLinkData.getLink();+ }++ if (dynamicLink != null) {+ join(dynamicLink.toString());+ }+ });+ }++ // In Debug builds React needs permission to write over other apps in+ // order to display the warning and error overlays.+ if (BuildConfig.DEBUG) {+ if (canRequestOverlayPermission() && !Settings.canDrawOverlays(this)) {+ Intent intent+ = new Intent(+ Settings.ACTION_MANAGE_OVERLAY_PERMISSION,+ Uri.parse("package:" + getPackageName()));++ startActivityForResult(intent, OVERLAY_PERMISSION_REQUEST_CODE);++ return true;+ }}++ return false;}- private void initialize() {+ @Override+ protected void initialize() {// Set default optionsJitsiMeetConferenceOptions defaultOptions= new JitsiMeetConferenceOptions.Builder()@@ -76,36 +103,27 @@ public class MainActivity extends FragmentActivity implements JitsiMeetActivityI.build();JitsiMeet.setDefaultConferenceOptions(defaultOptions);- // Join the room specified by the URL the app was launched with.- // Joining without the room option displays the welcome page.- join(getIntentUrl(getIntent()));+ super.initialize();}- private void join(@Nullable String url) {- JitsiMeetConferenceOptions options- = new JitsiMeetConferenceOptions.Builder()- .setRoom(url)- .build();- getFragment().getJitsiView().join(options);+ @Override+ public void onConferenceFailed(Map<String, Object> data) {+ Log.d(TAG, "Conference failed: " + data);}- private @Nullable String getIntentUrl(Intent intent) {- Uri uri;-- if (Intent.ACTION_VIEW.equals(intent.getAction())- && (uri = intent.getData()) != null) {- return uri.toString();- }-- return null;+ @Override+ public void onConferenceLeft(Map<String, Object> data) {+ Log.d(TAG, "Conference left: " + data);}- private boolean canRequestOverlayPermission() {- return- Build.VERSION.SDK_INT >= Build.VERSION_CODES.M- && getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.M;+ @Override+ public void onLoadConfigError(Map<String, Object> data) {+ Log.d(TAG, "Error loading config: " + data);}+ // Activity lifecycle method overrides+ //+@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {if (requestCode == OVERLAY_PERMISSION_REQUEST_CODE@@ -120,11 +138,6 @@ public class MainActivity extends FragmentActivity implements JitsiMeetActivityIsuper.onActivityResult(requestCode, resultCode, data);}- @Override- public void onBackPressed() {- JitsiMeetActivityDelegate.onBackPressed();- }-// ReactAndroid/src/main/java/com/facebook/react/ReactActivity.java@Overridepublic boolean onKeyUp(int keyCode, KeyEvent event) {@@ -136,68 +149,20 @@ public class MainActivity extends FragmentActivity implements JitsiMeetActivityIreturn super.onKeyUp(keyCode, event);}- @Override- public void onNewIntent(Intent intent) {- String url;-- if ((url = getIntentUrl(intent)) != null) {- join(url);- return;- }-- JitsiMeetActivityDelegate.onNewIntent(intent);- }-- @Override- protected void onUserLeaveHint() {- getFragment().getJitsiView().enterPictureInPicture();- }-- @Override- protected void onCreate(Bundle savedInstanceState) {- super.onCreate(savedInstanceState);-- // Set the Activity's content view.- setContentView(R.layout.main_layout);-- // Setup Crashlytics and Firebase Dynamic Links- if (BuildConfig.GOOGLE_SERVICES_ENABLED) {- Fabric.with(this, new Crashlytics());-- FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent())- .addOnSuccessListener(this, pendingDynamicLinkData -> {- Uri dynamicLink = null;-- if (pendingDynamicLinkData != null) {- dynamicLink = pendingDynamicLinkData.getLink();- }-- if (dynamicLink != null) {- join(dynamicLink.toString());- }- });- }+ // Helper methods+ //- // In Debug builds React needs permission to write over other apps in- // order to display the warning and error overlays.- if (BuildConfig.DEBUG) {- if (canRequestOverlayPermission() && !Settings.canDrawOverlays(this)) {- Intent intent- = new Intent(- Settings.ACTION_MANAGE_OVERLAY_PERMISSION,- Uri.parse("package:" + getPackageName()));-- startActivityForResult(intent, OVERLAY_PERMISSION_REQUEST_CODE);- return;- }+ private @Nullable URL buildURL(String urlStr) {+ try {+ return new URL(urlStr);+ } catch (MalformedURLException e) {+ return null;}-- initialize();}- @Override- public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {- JitsiMeetActivityDelegate.requestPermissions(this, permissions, requestCode, listener);+ private boolean canRequestOverlayPermission() {+ return+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.M+ && getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.M;}-}diff --git a/android/sdk/src/main/AndroidManifest.xml b/android/sdk/src/main/AndroidManifest.xmlindex 5ff31b4abd..1137f44a67 100644--- a/android/sdk/src/main/AndroidManifest.xml+++ b/android/sdk/src/main/AndroidManifest.xml@@ -1,37 +1,42 @@-<manifest- xmlns:android="http://schemas.android.com/apk/res/android"+<?xml version="1.0" encoding="utf-8"?>+<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="org.jitsi.meet.sdk">- <!-- XXX ACCESS_NETWORK_STATE is required by WebRTC. -->- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />- <uses-permission android:name="android.permission.BLUETOOTH" />- <uses-permission android:name="android.permission.CAMERA" />- <uses-permission android:name="android.permission.INTERNET" />- <uses-permission android:name="android.permission.MANAGE_OWN_CALLS"/>- <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />- <uses-permission android:name="android.permission.RECORD_AUDIO" />- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />- <uses-permission android:name="android.permission.WAKE_LOCK" />- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />+ <!-- XXX ACCESS_NETWORK_STATE is required by WebRTC. -->+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />+ <uses-permission android:name="android.permission.BLUETOOTH" />+ <uses-permission android:name="android.permission.CAMERA" />+ <uses-permission android:name="android.permission.INTERNET" />+ <uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />+ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />+ <uses-permission android:name="android.permission.RECORD_AUDIO" />+ <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />+ <uses-permission android:name="android.permission.WAKE_LOCK" />+ <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />- <uses-feature android:glEsVersion="0x00020000" android:required="true" />- <uses-feature- android:name="android.hardware.camera"- android:required="false" />- <uses-feature- android:name="android.hardware.camera.autofocus"- android:required="false" />+ <uses-feature+ android:glEsVersion="0x00020000"+ android:required="true" />+ <uses-feature+ android:name="android.hardware.camera"+ android:required="false" />+ <uses-feature+ android:name="android.hardware.camera.autofocus"+ android:required="false" />- <application- android:allowBackup="true"- android:label="@string/app_name"- android:supportsRtl="true">- <activity- android:name="com.facebook.react.devsupport.DevSettingsActivity" />- <service android:name="org.jitsi.meet.sdk.ConnectionService"- android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">- <intent-filter>- <action android:name="android.telecom.ConnectionService" />- </intent-filter>- </service>- </application>-</manifest>+ <application+ android:allowBackup="true"+ android:label="@string/app_name"+ android:supportsRtl="true">+ <activity android:name=".JitsiMeetActivity"></activity>+ <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />++ <service+ android:name=".ConnectionService"+ android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">+ <intent-filter>+ <action android:name="android.telecom.ConnectionService" />+ </intent-filter>+ </service>+ </application>++</manifest>\ No newline at end of filediff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.javanew file mode 100644index 0000000000..2cb52515a7--- /dev/null+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java@@ -0,0 +1,189 @@+/*+ * Copyright @ 2019-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.sdk;++import android.content.Intent;+import android.net.Uri;+import android.os.Bundle;+import android.support.annotation.Nullable;+import android.support.v4.app.FragmentActivity;+import android.util.Log;++import com.facebook.react.modules.core.PermissionListener;++import java.util.Map;+++/**+ * A base activity for SDK users to embed. It uses {@link JitsiMeetFragment} to do the heavy+ * lifting and wires the remaining Activity lifecycle methods so it works out of the box.+ */+public class JitsiMeetActivity extends FragmentActivity+ implements JitsiMeetActivityInterface, JitsiMeetViewListener {++ protected static final String TAG = JitsiMeetActivity.class.getSimpleName();++ // Overrides+ //++ @Override+ protected void onCreate(Bundle savedInstanceState) {+ super.onCreate(savedInstanceState);++ setContentView(R.layout.activity_jitsi_meet);++ if (!extraInitialize()) {+ initialize();+ }+ }++ @Override+ public void finish() {+ getJitsiView().leave();++ super.finish();+ }++ // Helper methods+ //++ protected JitsiMeetView getJitsiView() {+ JitsiMeetFragment fragment+ = (JitsiMeetFragment) getSupportFragmentManager().findFragmentById(R.id.jitsiFragment);+ return fragment.getJitsiView();+ }++ protected void join(@Nullable String url) {+ JitsiMeetConferenceOptions options+ = new JitsiMeetConferenceOptions.Builder()+ .setRoom(url)+ .build();+ join(options);+ }++ protected void join(JitsiMeetConferenceOptions options) {+ getJitsiView().join(options);+ }++ private @Nullable JitsiMeetConferenceOptions getConferenceOptions(Intent intent) {+ Uri uri;++ if (Intent.ACTION_VIEW.equals(intent.getAction())+ && (uri = intent.getData()) != null) {+ JitsiMeetConferenceOptions options+ = new JitsiMeetConferenceOptions.Builder()+ .setRoom(uri.toString())+ .build();+ return options;+ }++ // TODO: accept JitsiMeetConferenceOptions directly.++ return null;+ }++ /**+ * Helper function called during activity initialization. If {@code true} is returned, the+ * initialization is delayed and the {@link JitsiMeetActivity#initialize()} method is not+ * called. In this case, it's up to the subclass to call the initialize method when ready.+ *+ * This is mainly required so we do some extra initialization in the Jitsi Meet app.+ *+ * @return {@code true} if the initialization will be delayed, {@code false} otherwise.+ */+ protected boolean extraInitialize() {+ return false;+ }++ protected void initialize() {+ // Listen for conference events.+ getJitsiView().setListener(this);++ // Join the room specified by the URL the app was launched with.+ // Joining without the room option displays the welcome page.+ join(getConferenceOptions(getIntent()));+ }++ // Activity lifecycle methods+ //++ @Override+ public void onBackPressed() {+ JitsiMeetActivityDelegate.onBackPressed();+ }++ @Override+ public void onNewIntent(Intent intent) {+ JitsiMeetConferenceOptions options;++ if ((options = getConferenceOptions(intent)) != null) {+ join(options);+ return;+ }++ JitsiMeetActivityDelegate.onNewIntent(intent);+ }++ @Override+ protected void onUserLeaveHint() {+ getJitsiView().enterPictureInPicture();+ }++ // JitsiMeetActivityInterface+ //++ @Override+ public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {+ JitsiMeetActivityDelegate.requestPermissions(this, permissions, requestCode, listener);+ }++ // JitsiMeetViewListener+ //++ @Override+ public void onConferenceFailed(Map<String, Object> data) {+ Log.d(TAG, "Conference failed: " + data);+ finish();+ }++ @Override+ public void onConferenceJoined(Map<String, Object> data) {+ Log.d(TAG, "Conference joined: " + data);+ }++ @Override+ public void onConferenceLeft(Map<String, Object> data) {+ Log.d(TAG, "Conference left: " + data);+ finish();+ }++ @Override+ public void onConferenceWillJoin(Map<String, Object> data) {+ Log.d(TAG, "Conference will join: " + data);+ }++ @Override+ public void onConferenceWillLeave(Map<String, Object> data) {+ Log.d(TAG, "Conference will leave: " + data);+ }++ @Override+ public void onLoadConfigError(Map<String, Object> data) {+ Log.d(TAG, "Error loading config: " + data);+ finish();+ }+}diff --git a/android/app/src/main/res/layout/main_layout.xml b/android/sdk/src/main/res/layout/activity_jitsi_meet.xmlsimilarity index 70%rename from android/app/src/main/res/layout/main_layout.xmlrename to android/sdk/src/main/res/layout/activity_jitsi_meet.xmlindex 79e9aa1961..46cf5d5208 100644--- a/android/app/src/main/res/layout/main_layout.xml+++ b/android/sdk/src/main/res/layout/activity_jitsi_meet.xml@@ -1,10 +1,12 @@<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"+ xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"- android:layout_height="match_parent">+ android:layout_height="match_parent"+ tools:context=".JitsiMeetActivity"><fragmentandroid:layout_width="match_parent"android:layout_height="match_parent"android:name="org.jitsi.meet.sdk.JitsiMeetFragment"android:id="@+id/jitsiFragment"/>-</FrameLayout>+</FrameLayout>\ No newline at end of file