mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-06 22:29:09 +00:00
Move setupWebsocket() to onAttach() in ChatController
Add toast warning for debug mode Rename "magic" stuff Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
6d181860d0
commit
39441ae075
@ -182,6 +182,7 @@ class NextcloudTalkApplication : MultiDexApplication(), LifecycleObserver {
|
||||
HALF_DAY,
|
||||
TimeUnit.HOURS
|
||||
).build()
|
||||
|
||||
val capabilitiesUpdateWork = OneTimeWorkRequest.Builder(CapabilitiesWorker::class.java).build()
|
||||
val signalingSettingsWork = OneTimeWorkRequest.Builder(SignalingSettingsWorker::class.java).build()
|
||||
|
||||
|
@ -1783,6 +1783,7 @@ class ChatController(args: Bundle) :
|
||||
|
||||
eventBus.register(this)
|
||||
|
||||
setupWebsocket()
|
||||
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
|
||||
|
||||
if (conversationUser?.userId != "?" &&
|
||||
@ -2002,11 +2003,6 @@ class ChatController(args: Bundle) :
|
||||
|
||||
logConversationInfos("joinRoomWithPassword#onNext")
|
||||
|
||||
// FIXME The web socket should be set up in onAttach(). It is currently setup after joining the
|
||||
// room to "ensure" (rather, increase the chances) that the WebsocketConnectionsWorker job
|
||||
// was able to finish and, therefore, that the web socket instance can be got.
|
||||
setupWebsocket()
|
||||
|
||||
// Ensure that the listener is added if the web socket instance was not set up yet when
|
||||
// onAttach() was called.
|
||||
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
|
||||
@ -2225,10 +2221,13 @@ class ChatController(args: Bundle) :
|
||||
return
|
||||
}
|
||||
|
||||
webSocketInstance = WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id!!)
|
||||
webSocketInstance = WebSocketConnectionHelper.getWebSocketInstanceForUserId(conversationUser.id!!)
|
||||
|
||||
if (webSocketInstance == null) {
|
||||
Log.d(TAG, "magicWebSocketInstance became null")
|
||||
Log.e(TAG, "failed to setup webSocketInstance")
|
||||
if (BuildConfig.DEBUG) {
|
||||
Toast.makeText(context, "failed to setup webSocketInstance", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ import okhttp3.OkHttpClient;
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class WebSocketConnectionHelper {
|
||||
public static final String TAG = "WebSocketConnectionHelper";
|
||||
private static Map<Long, WebSocketInstance> magicWebSocketInstanceMap = new HashMap<>();
|
||||
private static Map<Long, WebSocketInstance> webSocketInstanceMap = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
OkHttpClient okHttpClient;
|
||||
@ -59,11 +59,11 @@ public class WebSocketConnectionHelper {
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
public static synchronized WebSocketInstance getMagicWebSocketInstanceForUserId(long userId) {
|
||||
WebSocketInstance webSocketInstance = magicWebSocketInstanceMap.get(userId);
|
||||
public static synchronized WebSocketInstance getWebSocketInstanceForUserId(long userId) {
|
||||
WebSocketInstance webSocketInstance = webSocketInstanceMap.get(userId);
|
||||
|
||||
if (webSocketInstance == null) {
|
||||
Log.d(TAG, "No magicWebSocketInstance found for user " + userId);
|
||||
Log.e(TAG, "No webSocketInstance found for user " + userId);
|
||||
}
|
||||
|
||||
return webSocketInstance;
|
||||
@ -83,24 +83,24 @@ public class WebSocketConnectionHelper {
|
||||
long userId = isGuest ? -1 : user.getId();
|
||||
|
||||
WebSocketInstance webSocketInstance;
|
||||
if (userId != -1 && magicWebSocketInstanceMap.containsKey(user.getId()) && (webSocketInstance = magicWebSocketInstanceMap.get(user.getId())) != null) {
|
||||
if (userId != -1 && webSocketInstanceMap.containsKey(user.getId()) && (webSocketInstance = webSocketInstanceMap.get(user.getId())) != null) {
|
||||
return webSocketInstance;
|
||||
} else {
|
||||
if (userId == -1) {
|
||||
deleteExternalSignalingInstanceForUserEntity(userId);
|
||||
}
|
||||
webSocketInstance = new WebSocketInstance(user, generatedURL, webSocketTicket);
|
||||
magicWebSocketInstanceMap.put(user.getId(), webSocketInstance);
|
||||
webSocketInstanceMap.put(user.getId(), webSocketInstance);
|
||||
return webSocketInstance;
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized void deleteExternalSignalingInstanceForUserEntity(long id) {
|
||||
WebSocketInstance webSocketInstance;
|
||||
if ((webSocketInstance = magicWebSocketInstanceMap.get(id)) != null) {
|
||||
if ((webSocketInstance = webSocketInstanceMap.get(id)) != null) {
|
||||
if (webSocketInstance.isConnected()) {
|
||||
webSocketInstance.sendBye();
|
||||
magicWebSocketInstanceMap.remove(id);
|
||||
webSocketInstanceMap.remove(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user