mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-21 20:45:29 +03:00
add logging and minor refactoring
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
1f2d759307
commit
fe9224dbe0
4 changed files with 43 additions and 48 deletions
|
@ -2473,7 +2473,7 @@ class ChatActivity :
|
|||
if (conversationUser == null) {
|
||||
return
|
||||
}
|
||||
webSocketInstance = WebSocketConnectionHelper.getWebSocketInstanceForUserId(conversationUser!!.id!!)
|
||||
webSocketInstance = WebSocketConnectionHelper.getWebSocketInstanceForUser(conversationUser!!)
|
||||
|
||||
if (webSocketInstance == null) {
|
||||
Log.d(TAG, "webSocketInstance not set up. This should only happen when not using the HPB")
|
||||
|
|
|
@ -60,21 +60,21 @@ public class WebsocketConnectionsWorker extends Worker {
|
|||
NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
|
||||
|
||||
List<User> users = userManager.getUsers().blockingGet();
|
||||
WebSocketConnectionHelper webSocketConnectionHelper = new WebSocketConnectionHelper();
|
||||
for (User user : users) {
|
||||
if (user.getExternalSignalingServer() != null &&
|
||||
user.getExternalSignalingServer().getExternalSignalingServer() != null &&
|
||||
!TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingServer()) &&
|
||||
!TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingTicket())) {
|
||||
|
||||
Log.d(TAG,
|
||||
"WebsocketConnectionsWorker - getExternalSignalingInstanceForServer for user " + user.getDisplayName());
|
||||
Log.d(TAG, "trying to getExternalSignalingInstanceForServer for user " + user.getDisplayName());
|
||||
|
||||
webSocketConnectionHelper.getExternalSignalingInstanceForServer(
|
||||
WebSocketConnectionHelper.getExternalSignalingInstanceForServer(
|
||||
user.getExternalSignalingServer().getExternalSignalingServer(),
|
||||
user,
|
||||
user.getExternalSignalingServer().getExternalSignalingTicket(),
|
||||
false);
|
||||
} else {
|
||||
Log.d(TAG, "skipped to getExternalSignalingInstanceForServer for user " + user.getDisplayName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,11 +59,15 @@ public class WebSocketConnectionHelper {
|
|||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
public static synchronized WebSocketInstance getWebSocketInstanceForUserId(long userId) {
|
||||
WebSocketInstance webSocketInstance = webSocketInstanceMap.get(userId);
|
||||
public static synchronized WebSocketInstance getWebSocketInstanceForUser(User user) {
|
||||
WebSocketInstance webSocketInstance = webSocketInstanceMap.get(user.getId());
|
||||
|
||||
if (webSocketInstance == null) {
|
||||
Log.e(TAG, "No webSocketInstance found for user " + userId);
|
||||
Log.d(TAG, "No webSocketInstance found for user " + user.getDisplayName() +
|
||||
" (userId:" + user.getId() + ")");
|
||||
} else {
|
||||
Log.d(TAG, "Existing webSocketInstance found for user " + user.getDisplayName() +
|
||||
" (userId:" + user.getId() + ")");
|
||||
}
|
||||
|
||||
return webSocketInstance;
|
||||
|
@ -71,7 +75,8 @@ public class WebSocketConnectionHelper {
|
|||
|
||||
public static synchronized WebSocketInstance getExternalSignalingInstanceForServer(String url,
|
||||
User user,
|
||||
String webSocketTicket, boolean isGuest) {
|
||||
String webSocketTicket,
|
||||
boolean isGuest) {
|
||||
String generatedURL = url.replace("https://", "wss://").replace("http://", "ws://");
|
||||
|
||||
if (generatedURL.endsWith("/")) {
|
||||
|
@ -82,7 +87,7 @@ public class WebSocketConnectionHelper {
|
|||
|
||||
long userId = isGuest ? -1 : user.getId();
|
||||
|
||||
WebSocketInstance webSocketInstance = webSocketInstanceMap.get(user.getId());
|
||||
WebSocketInstance webSocketInstance = getWebSocketInstanceForUser(user);
|
||||
|
||||
if (userId != -1 && webSocketInstance != null && webSocketInstance.isConnected()) {
|
||||
return webSocketInstance;
|
||||
|
|
|
@ -148,8 +148,6 @@ class WebSocketInstance internal constructor(
|
|||
|
||||
fun restartWebSocket() {
|
||||
reconnecting = true
|
||||
|
||||
// TODO when improving logging, keep in mind this issue: https://github.com/nextcloud/talk-android/issues/1013
|
||||
Log.d(TAG, "restartWebSocket: $connectionUrl")
|
||||
val request = Request.Builder().url(connectionUrl).build()
|
||||
okHttpClient!!.newWebSocket(request, this)
|
||||
|
@ -371,7 +369,7 @@ class WebSocketInstance internal constructor(
|
|||
}
|
||||
|
||||
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
||||
Log.d(TAG, "Error : WebSocket " + webSocket.hashCode() + " onFailure: " + t.message)
|
||||
Log.e(TAG, "Error : WebSocket " + webSocket.hashCode(), t)
|
||||
closeWebSocket(webSocket)
|
||||
}
|
||||
|
||||
|
@ -387,32 +385,20 @@ class WebSocketInstance internal constructor(
|
|||
val message = LoganSquare.serialize(
|
||||
webSocketConnectionHelper.getAssembledJoinOrLeaveRoomModel(roomToken, normalBackendSession)
|
||||
)
|
||||
if (!isConnected || reconnecting) {
|
||||
messagesQueue.add(message)
|
||||
|
||||
if (!reconnecting) {
|
||||
restartWebSocket()
|
||||
}
|
||||
if (roomToken == "") {
|
||||
Log.d(TAG, "sending 'leave room' via websocket")
|
||||
currentNormalBackendSession = ""
|
||||
sendMessage(message)
|
||||
} else if (roomToken == currentRoomToken && normalBackendSession == currentNormalBackendSession) {
|
||||
Log.d(TAG, "roomToken & session are unchanged. Joining locally without to send websocket message")
|
||||
sendRoomJoinedEvent()
|
||||
} else {
|
||||
if (roomToken == "") {
|
||||
Log.d(TAG, "sending 'leave room' via websocket")
|
||||
currentNormalBackendSession = ""
|
||||
internalWebSocket!!.send(message)
|
||||
} else if (roomToken == currentRoomToken && normalBackendSession == currentNormalBackendSession) {
|
||||
Log.d(TAG, "roomToken&session are unchanged. Joining locally without to send websocket message")
|
||||
sendRoomJoinedEvent()
|
||||
} else {
|
||||
Log.d(TAG, "Sending join room message via websocket")
|
||||
currentNormalBackendSession = normalBackendSession
|
||||
|
||||
if (!internalWebSocket!!.send(message)) {
|
||||
messagesQueue.add(message)
|
||||
restartWebSocket()
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "Sending join room message via websocket")
|
||||
currentNormalBackendSession = normalBackendSession
|
||||
sendMessage(message)
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, e.message, e)
|
||||
Log.e(TAG, "Failed to serialize signaling message", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,23 +407,27 @@ class WebSocketInstance internal constructor(
|
|||
val message = LoganSquare.serialize(
|
||||
webSocketConnectionHelper.getAssembledCallMessageModel(ncSignalingMessage)
|
||||
)
|
||||
if (!isConnected || reconnecting) {
|
||||
messagesQueue.add(message)
|
||||
|
||||
if (!reconnecting) {
|
||||
restartWebSocket()
|
||||
}
|
||||
} else {
|
||||
if (!internalWebSocket!!.send(message)) {
|
||||
messagesQueue.add(message)
|
||||
restartWebSocket()
|
||||
}
|
||||
}
|
||||
sendMessage(message)
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "Failed to serialize signaling message", e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendMessage(message: String) {
|
||||
if (!isConnected || reconnecting) {
|
||||
messagesQueue.add(message)
|
||||
|
||||
if (!reconnecting) {
|
||||
restartWebSocket()
|
||||
}
|
||||
} else {
|
||||
if (!internalWebSocket!!.send(message)) {
|
||||
messagesQueue.add(message)
|
||||
restartWebSocket()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun sendBye() {
|
||||
if (isConnected) {
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue