added message_from_user socket

This commit is contained in:
Mathieu B 2022-12-04 15:29:57 +01:00
parent 2ecfa708e6
commit 9aa03fc03f
3 changed files with 13 additions and 3 deletions

View File

@ -45,6 +45,8 @@ class MainActivity : ComponentActivity() {
SocketHandler.getSocket()
.on("message_from_jarvis") { SocketHandler.messageFromJarvis(it, uiState) }
SocketHandler.getSocket()
.on("message_from_user") { SocketHandler.messageFromUser(it, uiState) }
super.onCreate(savedInstanceState)

View File

@ -208,6 +208,8 @@ fun processAudio(audioFile: File): String {
}
fun processMessage(text: String, navController: NavController, uiState: ConversationUiState) {
uiState.addMessage(Message(false, text))
navController.context.mainExecutor.execute {
SocketHandler.processMessage(
text,
@ -217,8 +219,6 @@ fun processMessage(text: String, navController: NavController, uiState: Conversa
)
)
}
uiState.addMessage(Message(false, text))
}

View File

@ -57,4 +57,12 @@ object SocketHandler {
}
}
fun messageFromUser(data: Array<Any>, uiState: ConversationUiState) {
if (data[0].toString().contains("data")) {
val result: JSONObject = data[0] as JSONObject
uiState.addMessage(Message(false, result.getString("data")))
}
}
}