Delete during broadcasting (#7227)

This commit is contained in:
Yoan Pintas
2023-01-06 22:36:55 +01:00
committed by GitHub
parent a7172fca68
commit 43fe62b251
4 changed files with 48 additions and 1 deletions
@@ -50,6 +50,10 @@ final class VoiceBroadcastRecorderCoordinator: Coordinator, Presentable {
recorderService: voiceBroadcastRecorderService)
voiceBroadcastRecorderViewModel = viewModel
}
deinit {
voiceBroadcastRecorderService.cancelRecordingVoiceBroadcast()
}
// MARK: - Public
@@ -33,7 +33,19 @@ import Foundation
}
}
}
var coordinatorsForEventIdentifiers = [String: VoiceBroadcastRecorderCoordinator]()
private var coordinatorsForEventIdentifiers = [String: VoiceBroadcastRecorderCoordinator]() {
didSet {
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
}
}
}
private var redactionsListener: Any?
// MARK: Private
private var currentEventIdentifier: String?
@@ -83,4 +95,17 @@ import Foundation
return coordinatorsForEventIdentifiers[currentEventIdentifier]
}
private func handleRedactedEvent(event: MXEvent, direction: MXTimelineDirection, customObject: Any?) {
if direction == .backwards {
// ignore backwards events
return
}
var coordinator = coordinatorsForEventIdentifiers.removeValue(forKey: event.redacts)
coordinator?.toPresentable().dismiss(animated: false) {
coordinator = nil
}
}
}
@@ -151,6 +151,21 @@ class VoiceBroadcastRecorderService: VoiceBroadcastRecorderServiceProtocol {
})
}
func cancelRecordingVoiceBroadcast() {
MXLog.debug("[VoiceBroadcastRecorderService] Cancel recording voice broadcast")
audioEngine.stop()
audioEngine.inputNode.removeTap(onBus: audioNodeBus)
UIApplication.shared.isIdleTimerDisabled = false
// Remove current chunk
if self.chunkFile != nil {
self.deleteRecording(at: self.chunkFile.url)
self.chunkFile = nil
}
self.tearDownVoiceBroadcastService()
}
// MARK: - Private
/// Reset chunk values.
private func resetValues() {
@@ -36,4 +36,7 @@ protocol VoiceBroadcastRecorderServiceProtocol {
/// Resume voice broadcast recording after paused it.
func resumeRecordingVoiceBroadcast()
/// Cancel voice broadcast recording after redacted it.
func cancelRecordingVoiceBroadcast()
}