This commit is contained in:
Халимов Рустам
2026-04-14 10:48:07 +03:00
parent dc051fa9ae
commit d8b0d86534
19 changed files with 504 additions and 184 deletions
@@ -10,6 +10,9 @@ import chats.data.remote.dto.MessageDto
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton
@@ -18,6 +21,7 @@ class ChatHubClient @Inject constructor() {
private var hubConnection: HubConnection? = null
private val _events = MutableSharedFlow<ChatEvent>(extraBufferCapacity = 64)
val events: SharedFlow<ChatEvent> = _events.asSharedFlow()
private val scope = CoroutineScope(Dispatchers.IO)
fun connect(baseUrl: String, accessToken: String) {
if (hubConnection?.connectionState == HubConnectionState.CONNECTED) return
@@ -30,9 +34,17 @@ class ChatHubClient @Inject constructor() {
hubConnection?.onClosed { exception ->
Log.e("ChatHubClient", "Connection closed", exception)
// Optional: Reconnect logic
}
hubConnection?.start()?.blockingAwait()
scope.launch {
try {
hubConnection?.start()?.blockingAwait()
Log.d("ChatHubClient", "SignalR Connected")
} catch (e: Exception) {
Log.e("ChatHubClient", "SignalR Connection Error", e)
}
}
}
private fun setupHandlers() {