Skip to content

Commit

Permalink
Add safeCall to MediaStreamTrack.trySetEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
liviu-timar committed Oct 17, 2024
1 parent 7e622d2 commit e7739a1
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class MicrophoneManager(
if (fromUser) {
_status.value = DeviceStatus.Enabled
}
safeCall { mediaManager.audioTrack.trySetEnabled(true) }
mediaManager.audioTrack.trySetEnabled(true)
}
}

Expand Down Expand Up @@ -397,7 +397,7 @@ class MicrophoneManager(
if (fromUser) {
_status.value = DeviceStatus.Disabled
}
safeCall { mediaManager.audioTrack.trySetEnabled(false) }
mediaManager.audioTrack.trySetEnabled(false)
}
}

Expand Down Expand Up @@ -557,7 +557,7 @@ public class CameraManager(
if (fromUser) {
_status.value = DeviceStatus.Enabled
}
safeCall { mediaManager.videoTrack.trySetEnabled(true) }
mediaManager.videoTrack.trySetEnabled(true)
startCapture()
}

Expand Down Expand Up @@ -591,7 +591,7 @@ public class CameraManager(
if (fromUser) {
_status.value = DeviceStatus.Disabled
}
safeCall { mediaManager.videoTrack.trySetEnabled(false) }
mediaManager.videoTrack.trySetEnabled(false)
videoCapturer.stopCapture()
isCapturingVideo = false
}
Expand Down Expand Up @@ -880,10 +880,4 @@ class MediaManagerImpl(
}
}

fun MediaStreamTrack.trySetEnabled(enabled: Boolean) {
try {
setEnabled(enabled)
} catch (t: Throwable) {
// No-op
}
}
fun MediaStreamTrack.trySetEnabled(enabled: Boolean) = safeCall { setEnabled(enabled) }

0 comments on commit e7739a1

Please sign in to comment.