Skip to content

Commit

Permalink
Remove unused import and update comments to English
Browse files Browse the repository at this point in the history
Removed an unused @PreviewLightDark import from HomeScreen.android.kt and updated all French comments to English in Log.nativeJvmAndroid.kt for consistency and readability. Added TODO annotations for future handling of sending exceptions.
  • Loading branch information
kdroidFilter committed Nov 8, 2024
1 parent 1cac924 commit 6c50c40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.kdroid.kmplog.client.presentation.screens.home

import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.PreviewLightDark
import com.kdroid.kmplog.client.features.screens.home.HomeScreen
import com.kdroid.kmplog.client.features.screens.home.HomeState

@PreviewLightDark
@Composable
fun HomeScreenPreview() {
HomeScreen(homeState = HomeState.previewState, {}, {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import kotlinx.serialization.protobuf.ProtoBuf
import kotlin.time.Duration.Companion.seconds


// Variables globales pour gérer les connexions WebSocket
// Global variables to manage WebSocket connections
internal var webSocketChannel: SendChannel<Frame>? = null
internal val connections = mutableSetOf<DefaultWebSocketServerSession>()
internal val mutex = Mutex()
Expand Down Expand Up @@ -57,40 +57,40 @@ actual fun startServer() {
webSocket("/log") {
webSocketChannel = this.outgoing

// Ajouter la nouvelle connexion au set
// Add the new connection to the set
mutex.withLock {
connections += this
}

try {
// Écouter les frames entrants
// Listen for incoming frames
for (frame in incoming) {
if (frame is Frame.Binary) {
// Désérialiser le message Protobuf
// Deserialize the Protobuf message
val logMessage = ProtoBuf.decodeFromByteArray<LogMessage>(frame.readBytes())

// Diffuser le message reçu à tous les clients connectés
// Broadcast the received message to all connected clients
mutex.withLock {
connections.forEach { session ->
launch {
try {
// Sérialiser le message en Protobuf pour diffusion
// Serialize the message to Protobuf for broadcast
val serializedMessage = ProtoBuf.encodeToByteArray(logMessage)
session.outgoing.send(Frame.Binary(true, serializedMessage))
} catch (e: Exception) {
// Gérer les exceptions d'envoi
// TODO Handle sending exceptions
}
}
}
}
}
}
} catch (e: ClosedReceiveChannelException) {
// Client déconnecté
// Client disconnected
} catch (e: Exception) {
// Gérer d'autres exceptions
// Handle other exceptions
} finally {
// Supprimer la connexion lorsqu'elle se ferme
// Delete the connection when it closes
mutex.withLock {
connections -= this
}
Expand All @@ -101,7 +101,7 @@ actual fun startServer() {
}
}

// Fonction pour envoyer un message en Protobuf à tous les clients WebSocket connectés
// Function to send a message in Protobuf to all connected WebSocket clients
@OptIn(ExperimentalSerializationApi::class)
actual suspend fun sendMessageToWebSocket(logMessage: LogMessage) {
val serializedMessage = ProtoBuf.encodeToByteArray(logMessage)
Expand All @@ -110,7 +110,7 @@ actual suspend fun sendMessageToWebSocket(logMessage: LogMessage) {
try {
session.outgoing.send(Frame.Binary(true, serializedMessage))
} catch (e: Exception) {
// Gérer les exceptions d'envoi
// TODO Handle sending exceptions
}
}
}
Expand Down

0 comments on commit 6c50c40

Please sign in to comment.