Skip to content

Commit

Permalink
[Refactor] Add delay for camera status update (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
vhuseinova-msft authored Jun 17, 2022
1 parent bbd06a9 commit d7ff79b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
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
}

func isMicDisabled() -> Bool {
Expand Down Expand Up @@ -179,6 +186,11 @@ class ControlBarViewModel: ObservableObject {
cameraPermission = permissionState.cameraPermission
}

if isCameraStateUpdating,
cameraState.operation != localUserState.cameraState.operation {
isCameraStateUpdating = localUserState.cameraState.operation != .on &&
localUserState.cameraState.operation != .off
}
cameraState = localUserState.cameraState
cameraButtonViewModel.update(iconName: cameraState.operation == .on ? .videoOn : .videoOff)
cameraButtonViewModel.update(accessibilityLabel: cameraState.operation == .on
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: .seconds(1.0), scheduler: DispatchQueue.main)
.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: .seconds(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,10 @@
### 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)

### Other Changes
- Added delay for camera status update. [#270](https://github.com/Azure/communication-ui-library-ios/pull/270)

## 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)

0 comments on commit d7ff79b

Please sign in to comment.