Skip to content

Commit

Permalink
4.4.0-conference-java
Browse files Browse the repository at this point in the history
  • Loading branch information
vdovbnya-qb committed Nov 4, 2021
1 parent 9178794 commit 225ebf8
Show file tree
Hide file tree
Showing 18 changed files with 558 additions and 338 deletions.
4 changes: 2 additions & 2 deletions sample-conference-java/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ android {
applicationId "com.quickblox.sample.videochat.conference.java"
minSdkVersion 16
targetSdkVersion 29
versionCode 433000
versionName '4.3.3-java'
versionCode 440000
versionName '4.4.0'
multiDexEnabled true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.crashlytics.android.Crashlytics;
import com.quickblox.auth.session.QBSettings;
import com.quickblox.conference.ConferenceConfig;
import com.quickblox.core.ServiceZone;
import com.quickblox.sample.videochat.conference.java.managers.ActivityLifecycle;
import com.quickblox.sample.videochat.conference.java.managers.BackgroundListener;
import com.quickblox.sample.videochat.conference.java.managers.ChatHelper;
Expand Down Expand Up @@ -43,10 +42,7 @@ public class App extends Application {
private static final String AUTH_KEY = "";
private static final String AUTH_SECRET = "";
private static final String ACCOUNT_KEY = "";

private static final String JANUS_SERVER_URL = "";

// TODO Firebase keys in - google-services.json
private static final String SERVER_URL = "";

public static final String USER_DEFAULT_PASSWORD = "quickblox";

Expand Down Expand Up @@ -145,8 +141,8 @@ private void initCredentials() {
}

private void initConferenceConfig() {
if (!TextUtils.isEmpty(JANUS_SERVER_URL)) {
ConferenceConfig.setUrl(JANUS_SERVER_URL);
if (!TextUtils.isEmpty(SERVER_URL)) {
ConferenceConfig.setUrl(SERVER_URL);
} else {
throw new AssertionError(getString(R.string.error_server_url_null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.snackbar.Snackbar;
import com.quickblox.chat.QBChatService;
import com.quickblox.core.QBEntityCallback;
Expand All @@ -26,10 +30,6 @@
import com.quickblox.users.QBUsers;
import com.quickblox.users.model.QBUser;

import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;


public abstract class BaseActivity extends AppCompatActivity {
private static final String TAG = BaseActivity.class.getSimpleName();
Expand Down Expand Up @@ -131,6 +131,7 @@ protected void hideProgressDialog() {
if (progressDialog != null && progressDialog.isShowing()) {
try {
progressDialog.dismiss();
progressDialog = null;
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,28 @@
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.quickblox.conference.ConferenceSession;
import com.quickblox.conference.WsException;
import com.quickblox.conference.WsHangUpException;
import com.quickblox.conference.WsNoResponseException;
import com.quickblox.conference.callbacks.ConferenceSessionCallbacks;
import com.quickblox.core.QBEntityCallback;
import com.quickblox.core.exception.QBResponseException;
import com.quickblox.sample.videochat.conference.java.R;
import com.quickblox.sample.videochat.conference.java.fragments.ConversationFragment;
import com.quickblox.sample.videochat.conference.java.fragments.ConversationFragmentCallback;
import com.quickblox.sample.videochat.conference.java.fragments.ReconnectionCallback;
import com.quickblox.sample.videochat.conference.java.fragments.ScreenShareFragment;
import com.quickblox.sample.videochat.conference.java.managers.WebRtcSessionManager;
import com.quickblox.sample.videochat.conference.java.services.CallService;
import com.quickblox.sample.videochat.conference.java.utils.Consts;
import com.quickblox.sample.videochat.conference.java.utils.SettingsUtils;
import com.quickblox.sample.videochat.conference.java.utils.ToastUtils;
import com.quickblox.users.QBUsers;
import com.quickblox.users.model.QBUser;
import com.quickblox.videochat.webrtc.BaseSession;
import com.quickblox.videochat.webrtc.QBRTCScreenCapturer;
import com.quickblox.videochat.webrtc.callbacks.QBRTCSessionStateCallback;
Expand All @@ -41,11 +43,9 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import java.util.Set;

public class CallActivity extends BaseActivity implements QBRTCSessionStateCallback<ConferenceSession>, ConferenceSessionCallbacks,
ConversationFragmentCallback, ScreenShareFragment.OnSharingEvents {
Expand All @@ -65,6 +65,9 @@ public class CallActivity extends BaseActivity implements QBRTCSessionStateCallb
private ArrayList<CallService.CurrentCallStateCallback> currentCallStateCallbackList = new ArrayList<>();
private volatile boolean connectedToJanus;
private CallService callService;
private final Set<ReconnectionCallback> reconnectionCallbacks = new HashSet<>();
private final ReconnectionListenerImpl reconnectionListener = new ReconnectionListenerImpl(TAG);
private LinearLayout reconnectingLayout;

public static void start(Context context, String roomID, String roomTitle, String dialogID,
List<Integer> occupants, boolean listenerRole) {
Expand All @@ -84,6 +87,16 @@ public static void start(Context context) {
context.startActivity(intent);
}

@Override
public void addReconnectionCallback(ReconnectionCallback reconnectionCallback) {
reconnectionCallbacks.add(reconnectionCallback);
}

@Override
public void removeReconnectionCallback(ReconnectionCallback reconnectionCallback) {
reconnectionCallbacks.remove(reconnectionCallback);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -95,6 +108,8 @@ protected void onCreate(Bundle savedInstanceState) {
PreferenceManager.setDefaultValues(this, R.xml.preferences_video, false);
PreferenceManager.setDefaultValues(this, R.xml.preferences_audio, false);

reconnectingLayout = findViewById(R.id.llReconnecting);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window w = getWindow();
w.setStatusBarColor(ContextCompat.getColor(this, R.color.color_new_blue));
Expand All @@ -116,8 +131,12 @@ private void initScreen() {
currentSession = sessionManager.getCurrentSession();
initListeners(currentSession);

if (callService.isSharingScreenState()) {
startScreenSharing(null);
if (callService != null && callService.isSharingScreenState()) {
if (callService.getReconnectionState() == CallService.ReconnectionState.COMPLETED) {
QBRTCScreenCapturer.requestPermissions(this);
} else {
startScreenSharing(null);
}
} else {
startConversationFragment();
}
Expand All @@ -128,6 +147,27 @@ protected void onResume() {
super.onResume();
settingsSharedPref = PreferenceManager.getDefaultSharedPreferences(this);
bindCallService();
if (callService != null) {
switch (callService.getReconnectionState()) {
case COMPLETED:
reconnectingLayout.setVisibility(View.GONE);
for (ReconnectionCallback reconnectionCallback : reconnectionCallbacks) {
reconnectionCallback.completed();
}
break;
case IN_PROGRESS:
reconnectingLayout.setVisibility(View.VISIBLE);
for (ReconnectionCallback reconnectionCallback : reconnectionCallbacks) {
reconnectionCallback.inProgress();
}
break;
case FAILED:
ToastUtils.shortToast(getApplicationContext(), R.string.reconnection_failed);
callService.leaveCurrentSession();
finish();
break;
}
}
}

@Override
Expand All @@ -137,6 +177,8 @@ protected void onPause() {
unbindService(callServiceConnection);
callServiceConnection = null;
}

callService.unsubscribeReconnectionListener(reconnectionListener);
removeListeners();
}

Expand All @@ -161,6 +203,7 @@ private void bindCallService() {

private void leaveCurrentSession() {
callService.leaveCurrentSession();
finish();
}

private void initListeners(ConferenceSession session) {
Expand Down Expand Up @@ -324,23 +367,23 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
&& resultCode == Activity.RESULT_OK && data != null) {
startScreenSharing(data);
Log.i(TAG, "Starting Screen Capture");
} else if (requestCode == QBRTCScreenCapturer.REQUEST_MEDIA_PROJECTION && resultCode == Activity.RESULT_CANCELED) {
callService.stopScreenSharing();
startConversationFragment();
}
if (requestCode == REQUEST_CODE_OPEN_CONVERSATION_CHAT) {
Log.d(TAG, "Returning back from ChatActivity");
}
}

private void startScreenSharing(final Intent data) {
Fragment fragmentByTag = getSupportFragmentManager().findFragmentByTag(ScreenShareFragment.class.getSimpleName());
if (!(fragmentByTag instanceof ScreenShareFragment)) {
ScreenShareFragment screenShareFragment = ScreenShareFragment.newInstance();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
screenShareFragment, ScreenShareFragment.class.getSimpleName())
.commitAllowingStateLoss();

callService.setVideoEnabled(true);
callService.startScreenSharing(data);
}
ScreenShareFragment screenShareFragment = ScreenShareFragment.newInstance();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
screenShareFragment, ScreenShareFragment.class.getSimpleName())
.commitAllowingStateLoss();

callService.setVideoEnabled(true);
callService.startScreenSharing(data);
}

@Override
Expand Down Expand Up @@ -408,9 +451,6 @@ public void onError(WsException exception) {
@Override
public void onSessionClosed(final ConferenceSession session) {
Log.d(TAG, "Session " + session.getSessionID() + " start stop session");
if (session.equals(currentSession)) {
finish();
}
}

private class CallServiceConnection implements ServiceConnection {
Expand All @@ -425,27 +465,66 @@ public void onServiceConnected(ComponentName name, IBinder service) {
callService = binder.getService();
if (callService.currentSessionExist()) {
currentDialogID = callService.getDialogID();
login();
if (callService.getReconnectionState() != CallService.ReconnectionState.IN_PROGRESS){
initScreen();
}
} else {
//we have already currentSession == null, so it's no reason to do further initialization
CallService.stop(CallActivity.this);
finish();
}
callService.subscribeReconnectionListener(reconnectionListener);
}
}

private void login() {
QBUser qbUser = getSharedPrefsHelper().getQbUser();
QBUsers.signIn(qbUser).performAsync(new QBEntityCallback<QBUser>() {
@Override
public void onSuccess(QBUser qbUser, Bundle bundle) {
initScreen();
}
private class ReconnectionListenerImpl implements CallService.ReconnectionListener {
private final String tag;

@Override
public void onError(QBResponseException e) {
ReconnectionListenerImpl(String tag) {
this.tag = tag;
}

@Override
public void onChangedState(CallService.ReconnectionState reconnectionState) {
switch (reconnectionState) {
case COMPLETED:
reconnectingLayout.setVisibility(View.GONE);
for (ReconnectionCallback reconnectionCallback : reconnectionCallbacks) {
reconnectionCallback.completed();
}
initScreen();
callService.setReconnectionState(CallService.ReconnectionState.DEFAULT);
break;
case IN_PROGRESS:
reconnectingLayout.setVisibility(View.VISIBLE);
for (ReconnectionCallback reconnectionCallback : reconnectionCallbacks) {
reconnectionCallback.inProgress();
}
break;
case FAILED:
ToastUtils.shortToast(getApplicationContext(), R.string.reconnection_failed);
callService.leaveCurrentSession();
finish();
}
});
break;
}
}

@Override
public int hashCode() {
int hash = 3;
hash = 53 * hash + tag.hashCode();
return hash;
}

@Override
public boolean equals(Object obj) {
boolean equals;
if (obj instanceof ReconnectionListenerImpl) {
equals = TAG.equals(((ReconnectionListenerImpl) obj).tag);
} else {
equals = super.equals(obj);
}
return equals;
}
}
}
Loading

0 comments on commit 225ebf8

Please sign in to comment.