Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Add delay for camera status update #270

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ class ControlBarViewModel: ObservableObject {
private let logger: Logger
private let localizationProvider: LocalizationProviderProtocol
private let dispatch: ActionDispatch
private var isCameraStateUpdating: Bool = false
private(set) var cameraButtonViewModel: IconButtonViewModel!

@Published var cameraPermission: AppPermission.Status = .unknown
@Published var isAudioDeviceSelectionDisplayed: Bool = false
@Published var isConfirmLeaveListDisplayed: Bool = false

let audioDevicesListViewModel: AudioDevicesListViewModel

var cameraButtonViewModel: IconButtonViewModel!
var micButtonViewModel: IconButtonViewModel!
var audioDeviceButtonViewModel: IconButtonViewModel!
var hangUpButtonViewModel: IconButtonViewModel!
Expand Down Expand Up @@ -102,6 +103,11 @@ class ControlBarViewModel: ObservableObject {
}

func cameraButtonTapped() {
guard !isCameraStateUpdating else {
return
}

isCameraStateUpdating = true
let action: Action = cameraState.operation == .on ?
LocalUserAction.CameraOffTriggered() : LocalUserAction.CameraOnTriggered()
dispatch(action)
Expand All @@ -122,7 +128,8 @@ class ControlBarViewModel: ObservableObject {
}

func isCameraDisabled() -> Bool {
cameraPermission == .denied || cameraState.operation == .pending || callingStatus == .localHold
cameraPermission == .denied || cameraState.operation == .pending ||
callingStatus == .localHold || isCameraStateUpdating
vhuseinova-msft marked this conversation as resolved.
Show resolved Hide resolved
}

func isMicDisabled() -> Bool {
Expand Down Expand Up @@ -180,6 +187,9 @@ class ControlBarViewModel: ObservableObject {
}

cameraState = localUserState.cameraState
if isCameraStateUpdating {
vhuseinova-msft marked this conversation as resolved.
Show resolved Hide resolved
isCameraStateUpdating = cameraState.operation != .on && cameraState.operation != .off
}
cameraButtonViewModel.update(iconName: cameraState.operation == .on ? .videoOn : .videoOff)
cameraButtonViewModel.update(accessibilityLabel: cameraState.operation == .on
? localizationProvider.getLocalizedString(.videoOnAccessibilityLabel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,10 @@ class CallingMiddlewareHandler: CallingMiddlewareHandling {
dispatch(PermissionAction.CameraPermissionRequested())
} else {
callingService.startLocalVideoStream()
.delay(for: 1.0, scheduler: DispatchQueue.main)
vhuseinova-msft marked this conversation as resolved.
Show resolved Hide resolved
.map { videoStream in
LocalUserAction.CameraOnSucceeded(videoStreamIdentifier: videoStream)
}.sink(receiveCompletion: {completion in
}.sink(receiveCompletion: { completion in
switch completion {
case .failure(let error):
dispatch(LocalUserAction.CameraOnFailed(error: error))
Expand Down Expand Up @@ -232,6 +233,7 @@ class CallingMiddlewareHandler: CallingMiddlewareHandling {

func requestCameraSwitch(state: ReduxState?, dispatch: @escaping ActionDispatch) {
callingService.switchCamera()
.delay(for: 1.0, scheduler: DispatchQueue.main)
.map { cameraDevice in
LocalUserAction.CameraSwitchSucceeded(cameraDevice: cameraDevice)
}.sink(receiveCompletion: {completion in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,11 @@ class ControlBarViewModelTests: XCTestCase {
XCTAssertTrue(self?.storeFactory.actions.first is LocalUserAction.CameraOffTriggered)
expectation.fulfill()
}.store(in: cancellable)
sut.cameraState = LocalUserState.CameraState(operation: .on,
device: .front,
transmission: .local)
sut.update(localUserState: LocalUserState(cameraState: LocalUserState.CameraState(operation: .on,
device: .front,
transmission: .local)),
permissionState: PermissionState(),
callingState: CallingState())
sut.cameraButtonTapped()
wait(for: [expectation], timeout: 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
### Bugs Fixed
- Fixed issue where header was still selectable with voiceover on and overlay visible. [#256](https://github.com/Azure/communication-ui-library-ios/pull/256)
- Fixed hold overlay to have a solid colour. [#262](https://github.com/Azure/communication-ui-library-ios/pull/262)
- Fix the issue that resume a call without internet could stop user from exit. [#268](https://github.com/Azure/communication-ui-library-ios/pull/268
- Fixed the issue that resume a call without internet could stop user from exit. [#268](https://github.com/Azure/communication-ui-library-ios/pull/268
vhuseinova-msft marked this conversation as resolved.
Show resolved Hide resolved

## 1.0.0-beta.2 (2022-06-13)
### New Features
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Release History

[AzureCommunicationUICalling](https://github.com/Azure/communication-ui-library-ios/tree/main/AzureCommunicationUI/sdk/AzureCommunicationUICalling/CHANGELOG.md)
[AzureCommunicationUICalling](AzureCommunicationUI/sdk/AzureCommunicationUICalling/CHANGELOG.md)