Compare commits

..

2 Commits

Author SHA1 Message Date
7a5f3df4c2 feat: use camerax with webrtc lib 2025-04-01 08:07:06 +02:00
160c0ba7b0 feat: listen to websocket 2025-04-01 08:06:09 +02:00
2 changed files with 25 additions and 5 deletions

View File

@ -32,20 +32,24 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.example.tvcontroller.R
import com.example.tvcontroller.Settings
import com.example.tvcontroller.ui.views.SettingsViewModel
import com.example.tvcontroller.ui.views.SettingsViewModel.Companion.CONNECT_CONTROLLER_VIEW
import com.example.tvcontroller.ui.views.SettingsViewModel.Companion.MAIN_SETTINGS_VIEW
import com.example.tvcontroller.services.BluetoothService
import com.example.tvcontroller.services.ControllerService
import com.example.tvcontroller.services.DeviceService
import com.example.tvcontroller.webrtc.RtcPeerConnection
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SettingsView(
deviceService: DeviceService,
bluetoothService: BluetoothService
bluetoothService: BluetoothService,
rtcPeerConnection: RtcPeerConnection
) {
val viewModel = viewModel<SettingsViewModel>(
factory = SettingsViewModel.provideFactory(
deviceService, bluetoothService
deviceService, bluetoothService, rtcPeerConnection
)
)
val navController = rememberNavController()
@ -117,6 +121,13 @@ fun SettingsView(
stringResource(id = R.string.connect_button_label)
)
}
Button(
onClick = { viewModel.connectRtcPeerConnection() },
modifier = Modifier.fillMaxWidth()
) {
Text(text = "Connect RTC Peer")
}
}
}

View File

@ -12,12 +12,14 @@ import com.example.tvcontroller.Settings
import com.example.tvcontroller.data.BluetoothDevice
import com.example.tvcontroller.services.BluetoothService
import com.example.tvcontroller.services.DeviceService
import com.example.tvcontroller.webrtc.RtcPeerConnection
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class SettingsViewModel(
private val deviceService: DeviceService,
private val bluetoothService: BluetoothService
private val bluetoothService: BluetoothService,
private val rtcPeerConnection: RtcPeerConnection
) : ViewModel() {
var serverAddress by mutableStateOf(deviceService.getServerAddress())
private set
@ -56,6 +58,12 @@ class SettingsViewModel(
}
}
fun connectRtcPeerConnection() {
viewModelScope.launch(Dispatchers.IO) {
rtcPeerConnection.connect()
}
}
private fun updateConnectionState() {
Log.i("SettingsViewModel", "Device token: ${deviceService.getToken()}")
connectionState = if (deviceService.getToken().isEmpty()) {
@ -105,11 +113,12 @@ class SettingsViewModel(
fun provideFactory(
deviceService: DeviceService,
bluetoothService: BluetoothService
bluetoothService: BluetoothService,
rtcPeerConnection: RtcPeerConnection
) = object : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return SettingsViewModel(deviceService, bluetoothService) as T
return SettingsViewModel(deviceService, bluetoothService, rtcPeerConnection) as T
}
}
}