Skip to content

Commit

Permalink
Provide federation values to external signaling server in chat
Browse files Browse the repository at this point in the history
Otherwise the WebSocket configuration and session clashes with the one
from the CallActivity, which already uses the federated settings.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
  • Loading branch information
danxuliu committed Sep 13, 2024
1 parent 7feb17d commit 0985052
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ import com.nextcloud.talk.jobs.ShareOperationWorker
import com.nextcloud.talk.jobs.UploadAndShareFilesWorker
import com.nextcloud.talk.location.LocationPickerActivity
import com.nextcloud.talk.messagesearch.MessageSearchActivity
import com.nextcloud.talk.models.ExternalSignalingServer
import com.nextcloud.talk.models.domain.ConversationModel
import com.nextcloud.talk.models.json.capabilities.SpreedCapability
import com.nextcloud.talk.models.json.chat.ReadStatus
import com.nextcloud.talk.models.json.conversations.ConversationEnums
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall
import com.nextcloud.talk.polls.ui.PollCreateDialogFragment
import com.nextcloud.talk.remotefilebrowser.activities.RemoteFileBrowserActivity
import com.nextcloud.talk.shareditems.activities.SharedItemsActivity
Expand Down Expand Up @@ -177,6 +179,8 @@ import com.stfalcon.chatkit.messages.MessageHolders
import com.stfalcon.chatkit.messages.MessageHolders.ContentChecker
import com.stfalcon.chatkit.messages.MessagesListAdapter
import com.stfalcon.chatkit.utils.DateFormatter
import io.reactivex.Observer
import io.reactivex.disposables.Disposable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.collect
Expand Down Expand Up @@ -302,6 +306,7 @@ class ChatActivity :

var webSocketInstance: WebSocketInstance? = null
var signalingMessageSender: SignalingMessageSender? = null
var externalSignalingServer: ExternalSignalingServer? = null

var getRoomInfoTimerHandler: Handler? = null

Expand Down Expand Up @@ -628,10 +633,12 @@ class ChatActivity :

logConversationInfos("joinRoomWithPassword#onNext")

setupWebsocket()
if (webSocketInstance != null) {
webSocketInstance?.joinRoomWithRoomTokenAndSession(
roomToken,
sessionIdAfterRoomJoined
sessionIdAfterRoomJoined,
externalSignalingServer?.federation
)
}
if (startCallFromNotification != null && startCallFromNotification) {
Expand Down Expand Up @@ -941,7 +948,6 @@ class ChatActivity :

pullChatMessagesPending = false

setupWebsocket()
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
webSocketInstance?.getSignalingMessageReceiver()?.addListener(conversationMessageListener)

Expand Down Expand Up @@ -2368,10 +2374,12 @@ class ChatActivity :
} else {
Log.d(TAG, "sessionID was valid -> skip joinRoom")

setupWebsocket()
if (webSocketInstance != null) {
webSocketInstance?.joinRoomWithRoomTokenAndSession(
roomToken,
sessionIdAfterRoomJoined
sessionIdAfterRoomJoined,
externalSignalingServer?.federation
)
}
}
Expand Down Expand Up @@ -2400,16 +2408,57 @@ class ChatActivity :
}

private fun setupWebsocket() {
if (conversationUser == null) {
if (currentConversation == null || conversationUser == null) {
return
}
webSocketInstance = WebSocketConnectionHelper.getWebSocketInstanceForUser(conversationUser!!)

if (currentConversation!!.remoteServer != null) {
val apiVersion = ApiUtils.getSignalingApiVersion(conversationUser!!, intArrayOf(ApiUtils.API_V3, 2, 1))
ncApi!!.getSignalingSettings(credentials, ApiUtils.getUrlForSignalingSettings(apiVersion, conversationUser!!.baseUrl,
roomToken!!)).blockingSubscribe(object : Observer<SignalingSettingsOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
}

override fun onNext(signalingSettingsOverall: SignalingSettingsOverall) {
if (signalingSettingsOverall.ocs!!.settings!!.externalSignalingServer == null) {
return
}

externalSignalingServer = ExternalSignalingServer()
externalSignalingServer!!.externalSignalingServer = signalingSettingsOverall.ocs!!.settings!!
.externalSignalingServer
externalSignalingServer!!.externalSignalingTicket = signalingSettingsOverall.ocs!!.settings!!
.externalSignalingTicket
externalSignalingServer!!.federation = signalingSettingsOverall.ocs!!.settings!!.federation

webSocketInstance = WebSocketConnectionHelper.getExternalSignalingInstanceForServer(
externalSignalingServer!!.externalSignalingServer,
conversationUser,
externalSignalingServer!!.externalSignalingTicket,
TextUtils.isEmpty(credentials)
)
}

override fun onError(e: Throwable) {
Log.e(CallActivity.TAG, e.message, e)
}

override fun onComplete() {
// unused atm
}
})
} else {
webSocketInstance = WebSocketConnectionHelper.getWebSocketInstanceForUser(conversationUser!!)
}

if (webSocketInstance == null) {
Log.d(TAG, "webSocketInstance not set up. This should only happen when not using the HPB")
}

signalingMessageSender = webSocketInstance?.signalingMessageSender
webSocketInstance?.getSignalingMessageReceiver()?.addListener(localParticipantMessageListener)
webSocketInstance?.getSignalingMessageReceiver()?.addListener(conversationMessageListener)
}

private fun processCallStartedMessages(chatMessageList: List<ChatMessage>) {
Expand Down

0 comments on commit 0985052

Please sign in to comment.