Set voice broadcast recording to pause when the app goes in background and when the RVC will disappear

This commit is contained in:
Philippe Loriaux 2022-10-20 17:42:09 +02:00
parent 75f195f319
commit 36c0a83542
4 changed files with 34 additions and 8 deletions

View file

@ -610,6 +610,9 @@ NSString *const AppDelegateUniversalLinkDidChangeNotification = @"AppDelegateUni
// Analytics: Force to send the pending actions
[[DecryptionFailureTracker sharedInstance] dispatch];
[Analytics.shared forceUpload];
// Pause Voice Broadcast recording if needed
[VoiceBroadcastRecorderProvider.shared pauseRecording];
}
- (void)applicationWillEnterForeground:(UIApplication *)application

View file

@ -598,6 +598,7 @@ static CGSize kThreadListBarButtonItemImageSize;
isAppeared = NO;
[VoiceMessageMediaServiceProvider.sharedProvider pauseAllServices];
[VoiceBroadcastRecorderProvider.shared pauseRecording];
// Stop the loading indicator even if the session is still in progress
[self stopLoadingUserIndicator];

View file

@ -63,6 +63,10 @@ final class VoiceBroadcastRecorderCoordinator: Coordinator, Presentable {
VectorHostingController(rootView: VoiceBroadcastRecorderView(viewModel: voiceBroadcastRecorderViewModel.context),
forceZeroSafeAreaInsets: true)
}
func pauseRecording() {
voiceBroadcastRecorderViewModel.context.send(viewAction: .pause)
}
// MARK: - Private
}

View file

@ -17,33 +17,40 @@
import Foundation
import AVFoundation
class VoiceBroadcastRecorderProvider {
@objc public class VoiceBroadcastRecorderProvider: NSObject {
// MARK: - Constants
static let shared = VoiceBroadcastRecorderProvider()
@objc public static let shared = VoiceBroadcastRecorderProvider()
// MARK: - Properties
// MARK: Public
var session: MXSession?
var currentEventIdentifier: String?
var coordinatorsForEventIdentifiers = [String: VoiceBroadcastRecorderCoordinator]()
// MARK: - Setup
private init() { }
private override init() { }
// MARK: - Public
/// Create or retrieve the voiceBroadcast timeline coordinator for this event and return
/// a view to be displayed in the timeline
func buildVoiceBroadcastRecorderViewForEvent(_ event: MXEvent, senderDisplayName: String?) -> UIView? {
guard let session = session, let room = session.room(withRoomId: event.roomId) else {
guard let session = session,
let room = session.room(withRoomId: event.roomId) else {
return nil
}
self.currentEventIdentifier = event.eventId
if let coordinator = coordinatorsForEventIdentifiers[event.eventId] {
return coordinator.toPresentable().view
}
let parameters = VoiceBroadcastRecorderCoordinatorParameters(session: session, room: room, voiceBroadcastStartEvent: event, senderDisplayName: senderDisplayName)
let parameters = VoiceBroadcastRecorderCoordinatorParameters(session: session,
room: room,
voiceBroadcastStartEvent: event,
senderDisplayName: senderDisplayName)
let coordinator = VoiceBroadcastRecorderCoordinator(parameters: parameters)
coordinatorsForEventIdentifiers[event.eventId] = coordinator
@ -51,8 +58,19 @@ class VoiceBroadcastRecorderProvider {
return coordinator.toPresentable().view
}
/// Retrieve the voiceBroadcast timeline coordinator for the given event or nil if it hasn't been created yet
func voiceBroadcastRecorderControllerForEventIdentifier(_ eventIdentifier: String) -> VoiceBroadcastRecorderCoordinator? {
coordinatorsForEventIdentifiers[eventIdentifier]
/// Pause current voice broadcast recording.
@objc public func pauseRecording() {
voiceBroadcastRecorderCoordinatorForCurrentEvent()?.pauseRecording()
}
// MARK: - Private
/// Retrieve the voiceBroadcast recorder coordinator for the current event or nil if it hasn't been created yet
private func voiceBroadcastRecorderCoordinatorForCurrentEvent() -> VoiceBroadcastRecorderCoordinator? {
guard let currentEventIdentifier = currentEventIdentifier else {
return nil
}
return coordinatorsForEventIdentifiers[currentEventIdentifier]
}
}