Compare commits

..

3 Commits

Author SHA1 Message Date
3d3f8710f2 feat: use camerax with webrtc lib 2025-04-01 08:20:16 +02:00
645f8e2f04 chore: upgrade project dependencies 2025-04-01 08:14:41 +02:00
60f146afbc feat: listen to websocket 2025-04-01 08:13:06 +02:00
2 changed files with 5 additions and 25 deletions

View File

@ -32,24 +32,20 @@ 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,
rtcPeerConnection: RtcPeerConnection
bluetoothService: BluetoothService
) {
val viewModel = viewModel<SettingsViewModel>(
factory = SettingsViewModel.provideFactory(
deviceService, bluetoothService, rtcPeerConnection
deviceService, bluetoothService
)
)
val navController = rememberNavController()
@ -121,13 +117,6 @@ fun SettingsView(
stringResource(id = R.string.connect_button_label)
)
}
Button(
onClick = { viewModel.connectRtcPeerConnection() },
modifier = Modifier.fillMaxWidth()
) {
Text(text = "Connect RTC Peer")
}
}
}

View File

@ -12,14 +12,12 @@ 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 rtcPeerConnection: RtcPeerConnection
private val bluetoothService: BluetoothService
) : ViewModel() {
var serverAddress by mutableStateOf(deviceService.getServerAddress())
private set
@ -58,12 +56,6 @@ 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()) {
@ -113,12 +105,11 @@ class SettingsViewModel(
fun provideFactory(
deviceService: DeviceService,
bluetoothService: BluetoothService,
rtcPeerConnection: RtcPeerConnection
bluetoothService: BluetoothService
) = object : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return SettingsViewModel(deviceService, bluetoothService, rtcPeerConnection) as T
return SettingsViewModel(deviceService, bluetoothService) as T
}
}
}