mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-07 06:39:45 +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,
|
HALF_DAY,
|
||||||
TimeUnit.HOURS
|
TimeUnit.HOURS
|
||||||
).build()
|
).build()
|
||||||
|
|
||||||
val capabilitiesUpdateWork = OneTimeWorkRequest.Builder(CapabilitiesWorker::class.java).build()
|
val capabilitiesUpdateWork = OneTimeWorkRequest.Builder(CapabilitiesWorker::class.java).build()
|
||||||
val signalingSettingsWork = OneTimeWorkRequest.Builder(SignalingSettingsWorker::class.java).build()
|
val signalingSettingsWork = OneTimeWorkRequest.Builder(SignalingSettingsWorker::class.java).build()
|
||||||
|
|
||||||
|
@ -1783,6 +1783,7 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
eventBus.register(this)
|
eventBus.register(this)
|
||||||
|
|
||||||
|
setupWebsocket()
|
||||||
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
|
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
|
||||||
|
|
||||||
if (conversationUser?.userId != "?" &&
|
if (conversationUser?.userId != "?" &&
|
||||||
@ -2002,11 +2003,6 @@ class ChatController(args: Bundle) :
|
|||||||
|
|
||||||
logConversationInfos("joinRoomWithPassword#onNext")
|
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
|
// Ensure that the listener is added if the web socket instance was not set up yet when
|
||||||
// onAttach() was called.
|
// onAttach() was called.
|
||||||
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
|
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
|
||||||
@ -2225,10 +2221,13 @@ class ChatController(args: Bundle) :
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
webSocketInstance = WebSocketConnectionHelper.getMagicWebSocketInstanceForUserId(conversationUser.id!!)
|
webSocketInstance = WebSocketConnectionHelper.getWebSocketInstanceForUserId(conversationUser.id!!)
|
||||||
|
|
||||||
if (webSocketInstance == null) {
|
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)
|
@AutoInjector(NextcloudTalkApplication.class)
|
||||||
public class WebSocketConnectionHelper {
|
public class WebSocketConnectionHelper {
|
||||||
public static final String TAG = "WebSocketConnectionHelper";
|
public static final String TAG = "WebSocketConnectionHelper";
|
||||||
private static Map<Long, WebSocketInstance> magicWebSocketInstanceMap = new HashMap<>();
|
private static Map<Long, WebSocketInstance> webSocketInstanceMap = new HashMap<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
OkHttpClient okHttpClient;
|
OkHttpClient okHttpClient;
|
||||||
@ -59,11 +59,11 @@ public class WebSocketConnectionHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("LongLogTag")
|
@SuppressLint("LongLogTag")
|
||||||
public static synchronized WebSocketInstance getMagicWebSocketInstanceForUserId(long userId) {
|
public static synchronized WebSocketInstance getWebSocketInstanceForUserId(long userId) {
|
||||||
WebSocketInstance webSocketInstance = magicWebSocketInstanceMap.get(userId);
|
WebSocketInstance webSocketInstance = webSocketInstanceMap.get(userId);
|
||||||
|
|
||||||
if (webSocketInstance == null) {
|
if (webSocketInstance == null) {
|
||||||
Log.d(TAG, "No magicWebSocketInstance found for user " + userId);
|
Log.e(TAG, "No webSocketInstance found for user " + userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return webSocketInstance;
|
return webSocketInstance;
|
||||||
@ -83,24 +83,24 @@ public class WebSocketConnectionHelper {
|
|||||||
long userId = isGuest ? -1 : user.getId();
|
long userId = isGuest ? -1 : user.getId();
|
||||||
|
|
||||||
WebSocketInstance webSocketInstance;
|
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;
|
return webSocketInstance;
|
||||||
} else {
|
} else {
|
||||||
if (userId == -1) {
|
if (userId == -1) {
|
||||||
deleteExternalSignalingInstanceForUserEntity(userId);
|
deleteExternalSignalingInstanceForUserEntity(userId);
|
||||||
}
|
}
|
||||||
webSocketInstance = new WebSocketInstance(user, generatedURL, webSocketTicket);
|
webSocketInstance = new WebSocketInstance(user, generatedURL, webSocketTicket);
|
||||||
magicWebSocketInstanceMap.put(user.getId(), webSocketInstance);
|
webSocketInstanceMap.put(user.getId(), webSocketInstance);
|
||||||
return webSocketInstance;
|
return webSocketInstance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void deleteExternalSignalingInstanceForUserEntity(long id) {
|
public static synchronized void deleteExternalSignalingInstanceForUserEntity(long id) {
|
||||||
WebSocketInstance webSocketInstance;
|
WebSocketInstance webSocketInstance;
|
||||||
if ((webSocketInstance = magicWebSocketInstanceMap.get(id)) != null) {
|
if ((webSocketInstance = webSocketInstanceMap.get(id)) != null) {
|
||||||
if (webSocketInstance.isConnected()) {
|
if (webSocketInstance.isConnected()) {
|
||||||
webSocketInstance.sendBye();
|
webSocketInstance.sendBye();
|
||||||
magicWebSocketInstanceMap.remove(id);
|
webSocketInstanceMap.remove(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user