mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 09:02:44 +02:00
Voice broadcast connection error handling while recording (#7282)
This commit is contained in:
+4
@@ -70,6 +70,10 @@ final class VoiceBroadcastRecorderCoordinator: Coordinator, Presentable {
|
||||
voiceBroadcastRecorderViewModel.context.send(viewAction: .pause)
|
||||
}
|
||||
|
||||
func pauseRecordingOnError() {
|
||||
voiceBroadcastRecorderViewModel.context.send(viewAction: .pauseOnError)
|
||||
}
|
||||
|
||||
func isVoiceBroadcastRecording() -> Bool {
|
||||
return voiceBroadcastRecorderService.isRecording
|
||||
}
|
||||
|
||||
+12
-7
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -38,7 +38,7 @@ import Foundation
|
||||
if !self.coordinatorsForEventIdentifiers.isEmpty && self.redactionsListener == nil {
|
||||
redactionsListener = session?.listenToEvents([MXEventType(identifier: kMXEventTypeStringRoomRedaction)], self.handleRedactedEvent)
|
||||
}
|
||||
|
||||
|
||||
if self.coordinatorsForEventIdentifiers.isEmpty && self.redactionsListener != nil {
|
||||
session?.removeListener(self.redactionsListener)
|
||||
self.redactionsListener = nil
|
||||
@@ -49,7 +49,7 @@ import Foundation
|
||||
|
||||
// MARK: Private
|
||||
private var currentEventIdentifier: String?
|
||||
|
||||
|
||||
// MARK: - Setup
|
||||
private override init() { }
|
||||
|
||||
@@ -85,6 +85,11 @@ import Foundation
|
||||
voiceBroadcastRecorderCoordinatorForCurrentEvent()?.pauseRecording()
|
||||
}
|
||||
|
||||
/// Pause current voice broadcast recording without sending pending events.
|
||||
@objc public func pauseRecordingOnError() {
|
||||
voiceBroadcastRecorderCoordinatorForCurrentEvent()?.pauseRecordingOnError()
|
||||
}
|
||||
|
||||
@objc public func isVoiceBroadcastRecording() -> Bool {
|
||||
guard let coordinator = voiceBroadcastRecorderCoordinatorForCurrentEvent() else {
|
||||
return false
|
||||
@@ -100,7 +105,7 @@ import Foundation
|
||||
guard let currentEventIdentifier = currentEventIdentifier else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
return coordinatorsForEventIdentifiers[currentEventIdentifier]
|
||||
}
|
||||
|
||||
@@ -109,11 +114,11 @@ import Foundation
|
||||
// ignore backwards events
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
var coordinator = coordinatorsForEventIdentifiers.removeValue(forKey: event.redacts)
|
||||
|
||||
|
||||
coordinator?.toPresentable().dismiss(animated: false) {
|
||||
coordinator = nil
|
||||
coordinator = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -116,6 +116,8 @@ class VoiceBroadcastRecorderService: VoiceBroadcastRecorderServiceProtocol {
|
||||
// Discard the service on VoiceBroadcastService error. We keep the service in case of other error type
|
||||
if error as? VoiceBroadcastServiceError != nil {
|
||||
self.tearDownVoiceBroadcastService()
|
||||
} else {
|
||||
AppDelegate.theDelegate().showError(asAlert: error)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -136,6 +138,10 @@ class VoiceBroadcastRecorderService: VoiceBroadcastRecorderServiceProtocol {
|
||||
}
|
||||
}, failure: { error in
|
||||
MXLog.error("[VoiceBroadcastRecorderService] Failed to pause voice broadcast", context: error)
|
||||
// Pause voice broadcast recording without sending pending events.
|
||||
if error is VoiceBroadcastServiceError == false {
|
||||
AppDelegate.theDelegate().showError(asAlert: error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -151,6 +157,9 @@ class VoiceBroadcastRecorderService: VoiceBroadcastRecorderServiceProtocol {
|
||||
UIApplication.shared.isIdleTimerDisabled = true
|
||||
}, failure: { error in
|
||||
MXLog.error("[VoiceBroadcastRecorderService] Failed to resume voice broadcast", context: error)
|
||||
if error is VoiceBroadcastServiceError == false {
|
||||
AppDelegate.theDelegate().showError(asAlert: error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -169,6 +178,15 @@ class VoiceBroadcastRecorderService: VoiceBroadcastRecorderServiceProtocol {
|
||||
self.tearDownVoiceBroadcastService()
|
||||
}
|
||||
|
||||
func pauseOnErrorRecordingVoiceBroadcast() {
|
||||
audioEngine.pause()
|
||||
UIApplication.shared.isIdleTimerDisabled = false
|
||||
invalidateTimer()
|
||||
|
||||
// Update state
|
||||
self.serviceDelegate?.voiceBroadcastRecorderService(self, didUpdateState: .error)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
/// Reset chunk values.
|
||||
private func resetValues() {
|
||||
|
||||
+3
@@ -42,4 +42,7 @@ protocol VoiceBroadcastRecorderServiceProtocol {
|
||||
|
||||
/// Cancel voice broadcast recording after redacted it.
|
||||
func cancelRecordingVoiceBroadcast()
|
||||
|
||||
/// Pause voice broadcast recording without sending pending events.
|
||||
func pauseOnErrorRecordingVoiceBroadcast()
|
||||
}
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct VoiceBroadcastRecorderConnectionErrorView: View {
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var action: (() -> Void)?
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
HStack(spacing: 0) {
|
||||
Image(uiImage: Asset.Images.errorIcon.image)
|
||||
.frame(width: 40, height: 40)
|
||||
Text(VectorL10n.voiceBroadcastRecorderConnectionError)
|
||||
.multilineTextAlignment(.center)
|
||||
.font(theme.fonts.caption1)
|
||||
.foregroundColor(theme.colors.alert)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
}
|
||||
|
||||
struct VoiceBroadcastRecorderConnectionErrorView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VoiceBroadcastRecorderConnectionErrorView()
|
||||
}
|
||||
}
|
||||
+43
-37
@@ -26,7 +26,7 @@ struct VoiceBroadcastRecorderView: View {
|
||||
@State private var showingStopAlert = false
|
||||
|
||||
private var backgroundColor: Color {
|
||||
if viewModel.viewState.recordingState != .paused {
|
||||
if viewModel.viewState.recordingState != .paused, viewModel.viewState.recordingState != .error {
|
||||
return theme.colors.alert
|
||||
}
|
||||
return theme.colors.quarterlyContent
|
||||
@@ -78,47 +78,53 @@ struct VoiceBroadcastRecorderView: View {
|
||||
.accessibilityIdentifier("liveButton")
|
||||
}
|
||||
|
||||
HStack(alignment: .top, spacing: 34.0) {
|
||||
Button {
|
||||
switch viewModel.viewState.recordingState {
|
||||
case .started, .resumed:
|
||||
viewModel.send(viewAction: .pause)
|
||||
case .stopped:
|
||||
viewModel.send(viewAction: .start)
|
||||
case .paused:
|
||||
viewModel.send(viewAction: .resume)
|
||||
if viewModel.viewState.recordingState == .error {
|
||||
VoiceBroadcastRecorderConnectionErrorView()
|
||||
} else {
|
||||
HStack(alignment: .top, spacing: 34.0) {
|
||||
Button {
|
||||
switch viewModel.viewState.recordingState {
|
||||
case .started, .resumed:
|
||||
viewModel.send(viewAction: .pause)
|
||||
case .stopped:
|
||||
viewModel.send(viewAction: .start)
|
||||
case .paused:
|
||||
viewModel.send(viewAction: .resume)
|
||||
case .error:
|
||||
break
|
||||
}
|
||||
} label: {
|
||||
if viewModel.viewState.recordingState == .started || viewModel.viewState.recordingState == .resumed {
|
||||
Image("voice_broadcast_record_pause")
|
||||
.renderingMode(.original)
|
||||
} else {
|
||||
Image("voice_broadcast_record")
|
||||
.renderingMode(.original)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
if viewModel.viewState.recordingState == .started || viewModel.viewState.recordingState == .resumed {
|
||||
Image("voice_broadcast_record_pause")
|
||||
.renderingMode(.original)
|
||||
} else {
|
||||
Image("voice_broadcast_record")
|
||||
.accessibilityIdentifier("recordButton")
|
||||
|
||||
Button {
|
||||
showingStopAlert = true
|
||||
} label: {
|
||||
Image("voice_broadcast_stop")
|
||||
.renderingMode(.original)
|
||||
}
|
||||
.alert(isPresented:$showingStopAlert) {
|
||||
Alert(title: Text(VectorL10n.voiceBroadcastStopAlertTitle),
|
||||
message: Text(VectorL10n.voiceBroadcastStopAlertDescription),
|
||||
primaryButton: .cancel(),
|
||||
secondaryButton: .default(Text(VectorL10n.voiceBroadcastStopAlertAgreeButton),
|
||||
action: {
|
||||
viewModel.send(viewAction: .stop)
|
||||
}))
|
||||
}
|
||||
.accessibilityIdentifier("stopButton")
|
||||
.disabled(viewModel.viewState.recordingState == .stopped)
|
||||
.mask(Color.black.opacity(viewModel.viewState.recordingState == .stopped ? 0.3 : 1.0))
|
||||
}
|
||||
.accessibilityIdentifier("recordButton")
|
||||
|
||||
Button {
|
||||
showingStopAlert = true
|
||||
} label: {
|
||||
Image("voice_broadcast_stop")
|
||||
.renderingMode(.original)
|
||||
}
|
||||
.alert(isPresented:$showingStopAlert) {
|
||||
Alert(title: Text(VectorL10n.voiceBroadcastStopAlertTitle),
|
||||
message: Text(VectorL10n.voiceBroadcastStopAlertDescription),
|
||||
primaryButton: .cancel(),
|
||||
secondaryButton: .default(Text(VectorL10n.voiceBroadcastStopAlertAgreeButton),
|
||||
action: {
|
||||
viewModel.send(viewAction: .stop)
|
||||
}))
|
||||
}
|
||||
.accessibilityIdentifier("stopButton")
|
||||
.disabled(viewModel.viewState.recordingState == .stopped)
|
||||
.mask(Color.black.opacity(viewModel.viewState.recordingState == .stopped ? 0.3 : 1.0))
|
||||
.padding(EdgeInsets(top: 10.0, leading: 0.0, bottom: 10.0, trailing: 0.0))
|
||||
}
|
||||
.padding(EdgeInsets(top: 10.0, leading: 0.0, bottom: 10.0, trailing: 0.0))
|
||||
}
|
||||
.padding(EdgeInsets(top: 12.0, leading: 4.0, bottom: 12.0, trailing: 4.0))
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ enum VoiceBroadcastRecorderViewAction {
|
||||
case stop
|
||||
case pause
|
||||
case resume
|
||||
case pauseOnError
|
||||
}
|
||||
|
||||
enum VoiceBroadcastRecorderState {
|
||||
@@ -28,6 +29,7 @@ enum VoiceBroadcastRecorderState {
|
||||
case stopped
|
||||
case paused
|
||||
case resumed
|
||||
case error
|
||||
}
|
||||
|
||||
struct VoiceBroadcastRecorderDetails {
|
||||
|
||||
@@ -56,6 +56,8 @@ class VoiceBroadcastRecorderViewModel: VoiceBroadcastRecorderViewModelType, Voic
|
||||
pause()
|
||||
case .resume:
|
||||
resume()
|
||||
case .pauseOnError:
|
||||
pauseOnError()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +82,10 @@ class VoiceBroadcastRecorderViewModel: VoiceBroadcastRecorderViewModelType, Voic
|
||||
voiceBroadcastRecorderService.resumeRecordingVoiceBroadcast()
|
||||
}
|
||||
|
||||
private func pauseOnError() {
|
||||
voiceBroadcastRecorderService.pauseOnErrorRecordingVoiceBroadcast()
|
||||
}
|
||||
|
||||
private func updateRemainingTime(_ remainingTime: UInt) {
|
||||
state.currentRecordingState = VoiceBroadcastRecorderViewModel.currentRecordingState(from: remainingTime)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user