diff --git a/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/imaccess/presenter/RoomPresenterImpl.java b/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/imaccess/presenter/RoomPresenterImpl.java index 4029bcacc10..72e498a037f 100644 --- a/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/imaccess/presenter/RoomPresenterImpl.java +++ b/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/imaccess/presenter/RoomPresenterImpl.java @@ -46,6 +46,7 @@ public class RoomPresenterImpl extends RoomPresenter implements IRoomCallback, R private AccessRoomConstants.SelfRoomStatus mSelfRoomStatus = NO_IN_ROOM; private final TUIRoomDefine.LoginUserInfo mSelfInfo; + private CountDownLatch mLoginLatch; private CountDownLatch mLeaveRoomLatch; private CountDownLatch mJoinRoomLatch; private CountDownLatch mSendMsgLatch; @@ -53,6 +54,19 @@ public class RoomPresenterImpl extends RoomPresenter implements IRoomCallback, R private AtomicBoolean mIsProcess = new AtomicBoolean(false); private RoomPresenterImpl() { + mLoginLatch = new CountDownLatch(1); + RoomEngineManager.loginRoomEngine(new TUIRoomDefine.ActionCallback() { + @Override + public void onSuccess() { + mLoginLatch.countDown(); + } + + @Override + public void onError(TUICommonDefine.Error error, String message) { + Log.e(TAG, "loginRoomEngine onError error=" + error + " message=" + message); + mLoginLatch.countDown(); + } + }); addObserver(); mRoomManager = new RoomManagerImpl(); mRoomTaskStoreHouse = new RoomTaskStoreHouse(); @@ -83,6 +97,7 @@ public void createRoom() { mRoomTaskStoreHouse.postTask(new Runnable() { @Override public void run() { + waitUntilLogin(); processCreateRoom(); } }); @@ -103,6 +118,14 @@ private void processCreateRoom() { mIsProcess.set(false); } + private void waitUntilLogin() { + try { + mLoginLatch.await(WAIT_TIME_S, TimeUnit.SECONDS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + private void waitUntilExitPreRoom() { waitUntilGiveUpRoomOwner(); Log.d(TAG, "waitUntilExitPreRoom"); @@ -235,6 +258,7 @@ public void enterRoom(RoomMsgData roomMsgData) { mRoomTaskStoreHouse.postTask(new Runnable() { @Override public void run() { + waitUntilLogin(); processEnterRoom(roomMsgData); } }); @@ -305,6 +329,7 @@ public void inviteOtherMembersToJoin(RoomMsgData roomMsgData) { mRoomTaskStoreHouse.postTask(new Runnable() { @Override public void run() { + waitUntilLogin(); mRoomManager.inviteOtherMembersToJoin(roomMsgData, mSelfInfo); } }); diff --git a/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/model/manager/RoomEngineManager.java b/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/model/manager/RoomEngineManager.java index dbe385246d7..301b52e4fb5 100644 --- a/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/model/manager/RoomEngineManager.java +++ b/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/model/manager/RoomEngineManager.java @@ -58,6 +58,11 @@ public static RoomEngineManager sharedInstance(Context context) { return sInstance; } + public static void loginRoomEngine(TUIRoomDefine.ActionCallback callback) { + TUIRoomEngine.login(TUILogin.getAppContext(), TUILogin.getSdkAppId(), TUILogin.getUserId(), + TUILogin.getUserSig(), callback); + } + public void startScreenCapture() { if (!DrawOverlaysPermissionUtil.isGrantedDrawOverlays()) { Log.w(TAG, "startScreenCapture no permission"); diff --git a/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/service/RoomServiceInitializer.java b/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/service/RoomServiceInitializer.java index 094a43ea1c4..130e3cf51df 100644 --- a/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/service/RoomServiceInitializer.java +++ b/Android/TUIKit/TUIRoomKit/tuiroomkit/src/main/java/com/tencent/cloud/tuikit/roomkit/service/RoomServiceInitializer.java @@ -51,7 +51,6 @@ public void init(Context context) { initExtension(); initRoomMessage(); initSignalingListener(); - initLoginObserver(); } private void initExtension() { @@ -71,37 +70,6 @@ private void initRoomMessage() { } - private void initLoginObserver() { - TUICore.registerEvent(EVENT_LOGIN_STATE_CHANGED, EVENT_SUB_KEY_USER_LOGIN_SUCCESS, new ITUINotification() { - @Override - public void onNotifyEvent(String key, String subKey, Map param) { - if (TextUtils.equals(key, EVENT_LOGIN_STATE_CHANGED) && TextUtils.equals(subKey, - EVENT_SUB_KEY_USER_LOGIN_SUCCESS)) { - loginRoomEngine(); - } - } - }); - } - - private void loginRoomEngine() { - int sdkAppId = TUILogin.getSdkAppId(); - String userId = TUILogin.getUserId(); - String userSig = TUILogin.getUserSig(); - Log.i(TAG, "TUIRoomEngine.login sdkAppId: " + sdkAppId + " userId=" + userId + " userSig=" + !TextUtils.isEmpty( - userSig) + " thread.name=" + Thread.currentThread().getName()); - TUIRoomEngine.login(TUILogin.getAppContext(), sdkAppId, userId, userSig, new TUIRoomDefine.ActionCallback() { - @Override - public void onSuccess() { - Log.i(TAG, "TUIRoomEngine.login onSuccess thread.name=" + Thread.currentThread().getName()); - } - - @Override - public void onError(TUICommonDefine.Error code, String message) { - Log.e(TAG, "TUIRoomEngine.login onError code=" + code + " message=" + message); - } - }); - } - private void initSignalingListener() { V2TIMManager.getSignalingManager().addSignalingListener(new V2TIMSignalingListener() { @Override