mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 11:39:42 +01:00
Merge pull request #3181 from nextcloud/websocketImprovements
minor Websocket fixes
This commit is contained in:
commit
3a050ab690
@ -1989,7 +1989,7 @@ public class CallActivity extends CallBaseActivity {
|
||||
|
||||
@Override
|
||||
public void onError(@io.reactivex.annotations.NonNull Throwable e) {
|
||||
// unused atm
|
||||
Log.e(TAG, "Error while leaving the call", e);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2216,7 +2216,7 @@ class ChatActivity :
|
||||
Log.d(TAG, "not leaving room (validSessionId is false)")
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "not leaving room...")
|
||||
Log.d(TAG, "not leaving room...")
|
||||
}
|
||||
|
||||
if (mentionAutocomplete != null && mentionAutocomplete!!.isPopupShowing) {
|
||||
|
@ -100,7 +100,7 @@ class ChatViewModel @Inject constructor(private val repository: ChatRepository)
|
||||
}
|
||||
|
||||
override fun onError(e: Throwable) {
|
||||
Log.e(TAG, "Error when fetching room")
|
||||
Log.e(TAG, "Error when joining room")
|
||||
_joinRoomViewState.value = JoinRoomErrorState
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ package com.nextcloud.talk.jobs;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.data.user.model.User;
|
||||
@ -41,6 +42,8 @@ import autodagger.AutoInjector;
|
||||
@AutoInjector(NextcloudTalkApplication.class)
|
||||
public class WebsocketConnectionsWorker extends Worker {
|
||||
|
||||
public static final String TAG = "WebsocketConnectionsWorker";
|
||||
|
||||
@Inject
|
||||
UserManager userManager;
|
||||
|
||||
@ -52,6 +55,8 @@ public class WebsocketConnectionsWorker extends Worker {
|
||||
@NonNull
|
||||
@Override
|
||||
public Result doWork() {
|
||||
Log.d(TAG, "WebsocketConnectionsWorker started ");
|
||||
|
||||
NextcloudTalkApplication.Companion.getSharedApplication().getComponentApplication().inject(this);
|
||||
|
||||
List<User> users = userManager.getUsers().blockingGet();
|
||||
@ -61,9 +66,14 @@ public class WebsocketConnectionsWorker extends Worker {
|
||||
user.getExternalSignalingServer().getExternalSignalingServer() != null &&
|
||||
!TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingServer()) &&
|
||||
!TextUtils.isEmpty(user.getExternalSignalingServer().getExternalSignalingTicket())) {
|
||||
|
||||
Log.d(TAG,
|
||||
"WebsocketConnectionsWorker - getExternalSignalingInstanceForServer for user " + user.getDisplayName());
|
||||
|
||||
webSocketConnectionHelper.getExternalSignalingInstanceForServer(
|
||||
user.getExternalSignalingServer().getExternalSignalingServer(),
|
||||
user, user.getExternalSignalingServer().getExternalSignalingTicket(),
|
||||
user,
|
||||
user.getExternalSignalingServer().getExternalSignalingTicket(),
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ class RoomWebSocketMessage(
|
||||
@JsonField(name = ["roomid"])
|
||||
var roomId: String? = null,
|
||||
@JsonField(name = ["sessionid"])
|
||||
var sessiondId: String? = null,
|
||||
var sessionId: String? = null,
|
||||
@JsonField(name = ["properties"])
|
||||
var roomPropertiesWebSocketMessage: RoomPropertiesWebSocketMessage? = null
|
||||
) : Parcelable {
|
||||
|
@ -20,9 +20,13 @@
|
||||
|
||||
package com.nextcloud.talk.utils.singletons;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.nextcloud.talk.data.user.model.User;
|
||||
|
||||
public class ApplicationWideCurrentRoomHolder {
|
||||
|
||||
public static final String TAG = "ApplicationWideCurrentRoomHolder";
|
||||
private static final ApplicationWideCurrentRoomHolder holder = new ApplicationWideCurrentRoomHolder();
|
||||
private String currentRoomId = "";
|
||||
private String currentRoomToken = "";
|
||||
@ -36,6 +40,7 @@ public class ApplicationWideCurrentRoomHolder {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
Log.d(TAG, "ApplicationWideCurrentRoomHolder was cleared");
|
||||
currentRoomId = "";
|
||||
userInRoom = new User();
|
||||
inCall = false;
|
||||
|
@ -84,12 +84,14 @@ public class WebSocketConnectionHelper {
|
||||
|
||||
WebSocketInstance webSocketInstance;
|
||||
if (userId != -1 && webSocketInstanceMap.containsKey(user.getId()) && (webSocketInstance = webSocketInstanceMap.get(user.getId())) != null) {
|
||||
Log.d(TAG, "webSocketInstanceMap already contained webSocketInstance for userId " + user.getId());
|
||||
return webSocketInstance;
|
||||
} else {
|
||||
if (userId == -1) {
|
||||
deleteExternalSignalingInstanceForUserEntity(userId);
|
||||
}
|
||||
webSocketInstance = new WebSocketInstance(user, generatedURL, webSocketTicket);
|
||||
Log.d(TAG, "created new webSocketInstance for userId " + user.getId());
|
||||
webSocketInstanceMap.put(user.getId(), webSocketInstance);
|
||||
return webSocketInstance;
|
||||
}
|
||||
@ -140,7 +142,7 @@ public class WebSocketConnectionHelper {
|
||||
roomOverallWebSocketMessage.setType("room");
|
||||
RoomWebSocketMessage roomWebSocketMessage = new RoomWebSocketMessage();
|
||||
roomWebSocketMessage.setRoomId(roomId);
|
||||
roomWebSocketMessage.setSessiondId(sessionId);
|
||||
roomWebSocketMessage.setSessionId(sessionId);
|
||||
roomOverallWebSocketMessage.setRoomWebSocketMessage(roomWebSocketMessage);
|
||||
return roomOverallWebSocketMessage;
|
||||
}
|
||||
|
@ -84,6 +84,7 @@ class WebSocketInstance internal constructor(
|
||||
private var internalWebSocket: WebSocket? = null
|
||||
private val connectionUrl: String
|
||||
private var currentRoomToken: String? = null
|
||||
private var currentNormalBackendSession: String? = null
|
||||
private var reconnecting = false
|
||||
private val usersHashMap: HashMap<String?, Participant>
|
||||
private var messagesQueue: MutableList<String> = ArrayList()
|
||||
@ -125,6 +126,7 @@ class WebSocketInstance internal constructor(
|
||||
}
|
||||
|
||||
override fun onOpen(webSocket: WebSocket, response: Response) {
|
||||
Log.d(TAG, "Open webSocket")
|
||||
internalWebSocket = webSocket
|
||||
sendHello()
|
||||
}
|
||||
@ -168,6 +170,7 @@ class WebSocketInstance internal constructor(
|
||||
isConnected = false
|
||||
resumeId = ""
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
} else {
|
||||
@ -213,8 +216,10 @@ class WebSocketInstance internal constructor(
|
||||
}
|
||||
signalingMessageReceiver.process(eventOverallWebSocketMessage.eventMap)
|
||||
}
|
||||
|
||||
Globals.TARGET_PARTICIPANTS ->
|
||||
signalingMessageReceiver.process(eventOverallWebSocketMessage.eventMap)
|
||||
|
||||
else ->
|
||||
Log.i(TAG, "Received unknown/ignored event target: $target")
|
||||
}
|
||||
@ -291,10 +296,7 @@ class WebSocketInstance internal constructor(
|
||||
val (_, roomWebSocketMessage) = LoganSquare.parse(text, JoinedRoomOverallWebSocketMessage::class.java)
|
||||
if (roomWebSocketMessage != null) {
|
||||
currentRoomToken = roomWebSocketMessage.roomId
|
||||
if (
|
||||
roomWebSocketMessage.roomPropertiesWebSocketMessage != null &&
|
||||
!TextUtils.isEmpty(currentRoomToken)
|
||||
) {
|
||||
if (roomWebSocketMessage.roomPropertiesWebSocketMessage != null && !TextUtils.isEmpty(currentRoomToken)) {
|
||||
sendRoomJoinedEvent()
|
||||
}
|
||||
}
|
||||
@ -309,6 +311,7 @@ class WebSocketInstance internal constructor(
|
||||
Log.d(TAG, "WebSocket " + webSocket.hashCode() + " resumeID " + resumeId + " expired")
|
||||
resumeId = ""
|
||||
currentRoomToken = ""
|
||||
currentNormalBackendSession = ""
|
||||
restartWebSocket()
|
||||
} else if ("hello_expected" == message.code) {
|
||||
restartWebSocket()
|
||||
@ -334,16 +337,17 @@ class WebSocketInstance internal constructor(
|
||||
webSocket.send(messagesQueue[i])
|
||||
}
|
||||
messagesQueue = ArrayList()
|
||||
val helloHasHap = HashMap<String, String?>()
|
||||
val helloHashMap = HashMap<String, String?>()
|
||||
if (!TextUtils.isEmpty(oldResumeId)) {
|
||||
helloHasHap["oldResumeId"] = oldResumeId
|
||||
helloHashMap["oldResumeId"] = oldResumeId
|
||||
} else {
|
||||
currentRoomToken = ""
|
||||
currentNormalBackendSession = ""
|
||||
}
|
||||
if (!TextUtils.isEmpty(currentRoomToken)) {
|
||||
helloHasHap[Globals.ROOM_TOKEN] = currentRoomToken
|
||||
helloHashMap[Globals.ROOM_TOKEN] = currentRoomToken
|
||||
}
|
||||
eventBus!!.post(WebSocketCommunicationEvent("hello", helloHasHap))
|
||||
eventBus!!.post(WebSocketCommunicationEvent("hello", helloHashMap))
|
||||
}
|
||||
|
||||
private fun sendRoomJoinedEvent() {
|
||||
@ -357,7 +361,12 @@ class WebSocketInstance internal constructor(
|
||||
}
|
||||
|
||||
override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
|
||||
Log.d(TAG, "Closing : $code / $reason")
|
||||
Log.d(TAG, "onClosing : $code / $reason")
|
||||
}
|
||||
|
||||
override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
|
||||
Log.d(TAG, "onClosed : $code / $reason")
|
||||
isConnected = false
|
||||
}
|
||||
|
||||
override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {
|
||||
@ -380,9 +389,16 @@ class WebSocketInstance internal constructor(
|
||||
if (!isConnected || reconnecting) {
|
||||
messagesQueue.add(message)
|
||||
} else {
|
||||
if (roomToken == currentRoomToken) {
|
||||
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
|
||||
internalWebSocket!!.send(message)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user