Skip to content

Commit

Permalink
Fix switch camera side not working (#67)
Browse files Browse the repository at this point in the history
* Add switch camera feat

* Fix switching camera
  • Loading branch information
shepeliev authored Aug 17, 2022
1 parent 224415b commit 71cb101
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,29 @@ fun VideoScreen(room: Room) {
}
}

Row(
Column(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
horizontalAlignment = Alignment.CenterHorizontally,
) {
if (roomModel.roomId == null) {
Button(onClick = room::createRoom, enabled = !roomModel.isJoining) {
Text("Create")
}

JoinRoomButton(onJoin = room::joinRoom, enabled = !roomModel.isJoining)
Button(onClick = room::switchCamera) {
Text("Switch camera")
}

Button(onClick = room::hangup) {
Text("Hangup")
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) {
if (roomModel.roomId == null) {
Button(onClick = room::createRoom, enabled = !roomModel.isJoining) {
Text("Create")
}

JoinRoomButton(onJoin = room::joinRoom, enabled = !roomModel.isJoining)
}

Button(onClick = room::hangup) {
Text("Hangup")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Room {
val model: Value<Model>

fun openUserMedia()
fun switchCamera()
fun createRoom()
fun joinRoom(roomId: String)
fun hangup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ class RoomComponent(
}
}

override fun switchCamera() {
logger.i { "Switch camera" }
scope.launch {
model.value.localStream?.videoTracks?.first()?.switchCamera()
logger.i { "Camera switched" }
}
}

override fun createRoom() {
logger.i { "Create room" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ internal class CameraVideoCaptureController(
}

override fun onCameraClosed() {
videoCapturerErrorListener.onError("Camera closed")
// Do nothing
}
}
}

0 comments on commit 71cb101

Please sign in to comment.