Skip to content

Commit

Permalink
Implement enableCamera feature
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Feb 23, 2023
1 parent ef33012 commit 9538b90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ fun VideoCallScreen() {
val localVideoTrackState by sessionManager.localVideoTrackFlow.collectAsState(null)
val localVideoTrack = localVideoTrackState

var callMediaState by remember { mutableStateOf(CallMediaState()) }

if (remoteVideoTrack != null) {
VideoRenderer(
videoTrack = remoteVideoTrack,
Expand All @@ -68,7 +70,7 @@ fun VideoCallScreen() {
)
}

if (localVideoTrack != null) {
if (localVideoTrack != null && callMediaState.isCameraEnabled) {
FloatingVideoRenderer(
modifier = Modifier
.size(width = 150.dp, height = 210.dp)
Expand All @@ -81,7 +83,6 @@ fun VideoCallScreen() {
}

val activity = (LocalContext.current as? Activity)
var callMediaState by remember { mutableStateOf(CallMediaState()) }

VideoCallControls(
modifier = Modifier
Expand All @@ -98,6 +99,7 @@ fun VideoCallScreen() {
is CallAction.ToggleCamera -> {
val enabled = callMediaState.isCameraEnabled.not()
callMediaState = callMediaState.copy(isCameraEnabled = enabled)
sessionManager.enableCamera(enabled)
}
CallAction.FlipCamera -> sessionManager.flipCamera()
CallAction.LeaveCall -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ interface WebRtcSessionManager {

fun enableMicrophone(enabled: Boolean)

fun enableCamera(enabled: Boolean)

fun disconnect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ class WebRtcSessionManagerImpl(
audioManager?.isMicrophoneMute = !enabled
}

override fun enableCamera(enabled: Boolean) {
if (enabled) {
videoCapturer.startCapture(resolution.width, resolution.height, 30)
} else {
videoCapturer.stopCapture()
}
}

override fun disconnect() {
// dispose audio & video tracks.
remoteVideoTrackFlow.replayCache.forEach { videoTrack ->
Expand Down

0 comments on commit 9538b90

Please sign in to comment.