@@ -1708,24 +1708,21 @@ class PhotoReasoningViewModel(
17081708 if (signalingClient != null ) {
17091709 return
17101710 }
1711- startHumanExpertSessionInternal(taskText, fromJs = true )
1711+ startHumanExpertSessionInternal(taskText)
17121712 }
17131713
17141714 private fun startHumanExpertSession (taskText : String ) {
1715- startHumanExpertSessionInternal(taskText, fromJs = false )
1715+ startHumanExpertSessionInternal(taskText)
17161716 }
17171717
1718- private fun startHumanExpertSessionInternal (taskText : String , fromJs : Boolean ) {
1718+ private fun startHumanExpertSessionInternal (taskText : String ) {
17191719 if (signalingClient != null ) {
1720- if (! fromJs) postTaskToHumanExpert(taskText)
17211720 return
17221721 }
17231722
1724- if (! fromJs) {
1725- _uiState .value = PhotoReasoningUiState .Loading
1726- _chatState .addMessage(PhotoReasoningMessage (text = " Connecting to Human Expert network..." , participant = PhotoParticipant .MODEL , isPending = true ))
1727- _chatMessagesFlow .value = _chatState .getAllMessages()
1728- }
1723+ _uiState .value = PhotoReasoningUiState .Loading
1724+ _chatState .addMessage(PhotoReasoningMessage (text = " Connecting to Human Expert network..." , participant = PhotoParticipant .MODEL , isPending = true ))
1725+ _chatMessagesFlow .value = _chatState .getAllMessages()
17291726
17301727 // Initialize WebRTC Sender
17311728 webRTCSender = WebRTCSender (getApplication(), object : WebRTCSender .WebRTCSenderListener {
@@ -1739,7 +1736,7 @@ class PhotoReasoningViewModel(
17391736 if (state == " CONNECTED" ) {
17401737 val connectedMsg = com.google.ai.sample.util.UiStringsConfig .get(" msg_expert_connected" , " The connection has been successfully established. The expert is completing the task." )
17411738 _commandExecutionStatus .value = connectedMsg
1742- if ( ! fromJs) replaceAiMessageText(connectedMsg, isPending = false )
1739+ replaceAiMessageText(connectedMsg, isPending = false )
17431740 MainActivity .getInstance()?.notifyHumanExpertStatusToWebView(connectedMsg, true , false , connectedMsg)
17441741 } else if (state == " DISCONNECTED" || state == " FAILED" ) {
17451742 _commandExecutionStatus .value = " Expert disconnected."
@@ -1755,15 +1752,13 @@ class PhotoReasoningViewModel(
17551752 // Handle incoming text from human operator
17561753 override fun onTextReceived (text : String ) {
17571754 viewModelScope.launch(Dispatchers .Main ) {
1758- if (! fromJs) {
1759- val newMessage = PhotoReasoningMessage (
1760- text = " Operator: $text " ,
1761- participant = PhotoParticipant .MODEL ,
1762- isPending = false
1763- )
1764- _chatState .addMessage(newMessage)
1765- _chatMessagesFlow .value = _chatState .getAllMessages()
1766- }
1755+ val newMessage = PhotoReasoningMessage (
1756+ text = " Operator: $text " ,
1757+ participant = PhotoParticipant .MODEL ,
1758+ isPending = false
1759+ )
1760+ _chatState .addMessage(newMessage)
1761+ _chatMessagesFlow .value = _chatState .getAllMessages()
17671762 MainActivity .getInstance()?.notifyHumanExpertMessageToWebView(text)
17681763 }
17691764 }
@@ -1782,7 +1777,7 @@ class PhotoReasoningViewModel(
17821777 override fun onTaskPosted (taskId : String ) {
17831778 viewModelScope.launch(Dispatchers .Main ) {
17841779 val msg = " Task posted. Waiting for an expert to claim it..."
1785- if ( ! fromJs) replaceAiMessageText(msg, isPending = true )
1780+ replaceAiMessageText(msg, isPending = true )
17861781 MainActivity .getInstance()?.notifyHumanExpertStatusToWebView(msg, false , true , msg)
17871782 }
17881783 }
@@ -1791,7 +1786,7 @@ class PhotoReasoningViewModel(
17911786 Log .d(TAG , " Task claimed! Requesting fresh MediaProjection for WebRTC." )
17921787 viewModelScope.launch(Dispatchers .Main ) {
17931788 val foundMsg = com.google.ai.sample.util.UiStringsConfig .get(" msg_expert_found" , " Expert found! Requesting screen capture permission..." )
1794- if ( ! fromJs) replaceAiMessageText(foundMsg, isPending = true )
1789+ replaceAiMessageText(foundMsg, isPending = true )
17951790 MainActivity .getInstance()?.notifyHumanExpertStatusToWebView(foundMsg, false , true , foundMsg)
17961791
17971792 // Request a fresh MediaProjection specifically for WebRTC.
@@ -1802,7 +1797,7 @@ class PhotoReasoningViewModel(
18021797 mainActivity.requestMediaProjectionForWebRTC { _, resultData ->
18031798 Log .d(TAG , " WebRTC MediaProjection granted. Service läuft bereits via KEEP_ALIVE. Starte Screen Capture." )
18041799 val estMsg = com.google.ai.sample.util.UiStringsConfig .get(" msg_establishing_video" , " Establishing video connection..." )
1805- if ( ! fromJs) replaceAiMessageText(estMsg, isPending = true )
1800+ replaceAiMessageText(estMsg, isPending = true )
18061801 MainActivity .getInstance()?.notifyHumanExpertStatusToWebView(estMsg, false , true , estMsg)
18071802
18081803 // KEIN startForegroundService() hier - MainActivity hat bereits ACTION_KEEP_ALIVE_FOR_WEBRTC gesendet.
@@ -1852,7 +1847,7 @@ class PhotoReasoningViewModel(
18521847 viewModelScope.launch(Dispatchers .Main ) {
18531848 val msg = com.google.ai.sample.util.UiStringsConfig .get(" msg_expert_disconnected" , " Expert disconnected." )
18541849 _commandExecutionStatus .value = msg
1855- if ( ! fromJs) replaceAiMessageText(msg, isPending = false )
1850+ replaceAiMessageText(msg, isPending = false )
18561851 MainActivity .getInstance()?.notifyHumanExpertStatusToWebView(msg, false , false , msg)
18571852 webRTCSender?.stop()
18581853 webRTCSender = null
0 commit comments