mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Add some logs to allow debugging of voice messages in rageshake (#1967)
This commit is contained in:
@@ -144,14 +144,19 @@ class AudioRecorder: NSObject, AudioRecorderProtocol, AVAudioRecorderDelegate {
|
||||
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default)
|
||||
try AVAudioSession.sharedInstance().setActive(true)
|
||||
let url = URL.temporaryDirectory.appendingPathComponent("voice-message-\(recordID.identifier).m4a")
|
||||
audioRecorder = try AVAudioRecorder(url: url, settings: settings)
|
||||
audioRecorder?.delegate = self
|
||||
audioRecorder?.isMeteringEnabled = true
|
||||
audioRecorder?.record()
|
||||
completion(.success(()))
|
||||
let audioRecorder = try AVAudioRecorder(url: url, settings: settings)
|
||||
audioRecorder.delegate = self
|
||||
audioRecorder.isMeteringEnabled = true
|
||||
if audioRecorder.record() {
|
||||
self.audioRecorder = audioRecorder
|
||||
completion(.success(()))
|
||||
} else {
|
||||
MXLog.error("audio recording failed to start")
|
||||
completion(.failure(.recordingFailed))
|
||||
}
|
||||
} catch {
|
||||
MXLog.error("audio recording failed: \(error)")
|
||||
completion(.failure(.genericError))
|
||||
MXLog.error("audio recording failed to start. \(error)")
|
||||
completion(.failure(.internalError(error: error)))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -187,12 +192,14 @@ class AudioRecorder: NSObject, AudioRecorderProtocol, AVAudioRecorderDelegate {
|
||||
if success {
|
||||
actionsSubject.send(.didStopRecording)
|
||||
} else {
|
||||
MXLog.error("audio recorder did finish recording with an error.")
|
||||
actionsSubject.send(.didFailWithError(error: AudioRecorderError.genericError))
|
||||
}
|
||||
}
|
||||
|
||||
func audioRecorderEncodeErrorDidOccur(_ recorder: AVAudioRecorder, error: Error?) {
|
||||
try? AVAudioSession.sharedInstance().setActive(false)
|
||||
MXLog.error("audio recorder encode error did occur. \(error?.localizedDescription ?? "")")
|
||||
actionsSubject.send(.didFailWithError(error: error ?? AudioRecorderError.genericError))
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,9 @@ extension AudioRecordingIdentifier {
|
||||
|
||||
enum AudioRecorderError: Error {
|
||||
case genericError
|
||||
case internalError(error: Error)
|
||||
case recordPermissionNotGranted
|
||||
case recordingFailed
|
||||
case recordingCancelled
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class VoiceMessageCache: VoiceMessageCacheProtocol {
|
||||
do {
|
||||
try cacheFile(source: fileURL, destination: url, move: move)
|
||||
} catch {
|
||||
MXLog.error("Failed storing file in cache", context: error)
|
||||
MXLog.error("Failed storing file in cache. \(error)")
|
||||
return .failure(.failedStoringFileInCache)
|
||||
}
|
||||
return .success(url)
|
||||
@@ -46,7 +46,7 @@ class VoiceMessageCache: VoiceMessageCacheProtocol {
|
||||
do {
|
||||
try FileManager.default.removeItem(at: temporaryFilesFolderURL)
|
||||
} catch {
|
||||
MXLog.error("Failed clearing cached disk files", context: error)
|
||||
MXLog.error("Failed clearing cached disk files. \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ class VoiceMessageRecorder: VoiceMessageRecorderProtocol {
|
||||
// linearly normalized to [0, 1] (1 -> -50 dB)
|
||||
waveformData = samples.map { UInt16(max(0, (1 - $0) * 1024)) }
|
||||
} catch {
|
||||
MXLog.error("Waveform analysis failed: \(error)")
|
||||
MXLog.error("Waveform analysis failed. \(error)")
|
||||
}
|
||||
return .success(waveformData)
|
||||
}
|
||||
@@ -154,7 +154,7 @@ class VoiceMessageRecorder: VoiceMessageRecorderProtocol {
|
||||
do {
|
||||
size = try UInt64(FileManager.default.sizeForItem(at: oggFile))
|
||||
} catch {
|
||||
MXLog.error("Failed to get the recording file size", context: error)
|
||||
MXLog.error("Failed to get the recording file size. \(error)")
|
||||
return .failure(.failedSendingVoiceMessage)
|
||||
}
|
||||
let audioInfo = AudioInfo(duration: recordingDuration, size: size, mimetype: "audio/ogg")
|
||||
@@ -170,7 +170,7 @@ class VoiceMessageRecorder: VoiceMessageRecorderProtocol {
|
||||
try? FileManager.default.removeItem(at: oggFile)
|
||||
|
||||
if case .failure(let error) = result {
|
||||
MXLog.error("Failed to send the voice message.", context: error)
|
||||
MXLog.error("Failed to send the voice message. \(error)")
|
||||
return .failure(.failedSendingVoiceMessage)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user