mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Add some logs to allow debugging of voice messages in rageshake (#1967)
This commit is contained in:
@@ -959,20 +959,21 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
switch error {
|
switch error {
|
||||||
case .audioRecorderError(.recordPermissionNotGranted):
|
case .audioRecorderError(.recordPermissionNotGranted):
|
||||||
|
MXLog.info("permission to record audio has not been granted.")
|
||||||
state.bindings.confirmationAlertInfo = .init(id: .init(),
|
state.bindings.confirmationAlertInfo = .init(id: .init(),
|
||||||
title: L10n.dialogPermissionMicrophoneTitleIos(InfoPlistReader.main.bundleDisplayName),
|
title: L10n.dialogPermissionMicrophoneTitleIos(InfoPlistReader.main.bundleDisplayName),
|
||||||
message: L10n.dialogPermissionMicrophoneDescriptionIos,
|
message: L10n.dialogPermissionMicrophoneDescriptionIos,
|
||||||
primaryButton: .init(title: L10n.commonSettings, action: { [weak self] in self?.openSystemSettings() }),
|
primaryButton: .init(title: L10n.commonSettings, action: { [weak self] in self?.openSystemSettings() }),
|
||||||
secondaryButton: .init(title: L10n.actionNotNow, role: .cancel, action: nil))
|
secondaryButton: .init(title: L10n.actionNotNow, role: .cancel, action: nil))
|
||||||
default:
|
default:
|
||||||
MXLog.error("failed to start voice message recording: \(error)")
|
MXLog.error("failed to start voice message recording. \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func stopRecordingVoiceMessage() async {
|
private func stopRecordingVoiceMessage() async {
|
||||||
if case .failure(let error) = await voiceMessageRecorder.stopRecording() {
|
if case .failure(let error) = await voiceMessageRecorder.stopRecording() {
|
||||||
MXLog.error("failed to stop the recording", context: error)
|
MXLog.error("failed to stop the recording. \(error)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1012,7 +1013,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
case .success:
|
case .success:
|
||||||
await deleteCurrentVoiceMessage()
|
await deleteCurrentVoiceMessage()
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
MXLog.error("failed to send the voice message", context: error)
|
MXLog.error("failed to send the voice message. \(error)")
|
||||||
actionsSubject.send(.composer(action: .setMode(mode: .previewVoiceMessage(state: audioPlayerState, waveform: .url(recordingURL), isUploading: false))))
|
actionsSubject.send(.composer(action: .setMode(mode: .previewVoiceMessage(state: audioPlayerState, waveform: .url(recordingURL), isUploading: false))))
|
||||||
displayError(.alert(L10n.errorFailedUploadingVoiceMessage))
|
displayError(.alert(L10n.errorFailedUploadingVoiceMessage))
|
||||||
}
|
}
|
||||||
@@ -1020,7 +1021,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
|
|||||||
|
|
||||||
private func startPlayingRecordedVoiceMessage() async {
|
private func startPlayingRecordedVoiceMessage() async {
|
||||||
if case .failure(let error) = await voiceMessageRecorder.startPlayback() {
|
if case .failure(let error) = await voiceMessageRecorder.startPlayback() {
|
||||||
MXLog.error("failed to play recorded voice message", context: error)
|
MXLog.error("failed to play recorded voice message. \(error)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,14 +144,19 @@ class AudioRecorder: NSObject, AudioRecorderProtocol, AVAudioRecorderDelegate {
|
|||||||
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default)
|
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default)
|
||||||
try AVAudioSession.sharedInstance().setActive(true)
|
try AVAudioSession.sharedInstance().setActive(true)
|
||||||
let url = URL.temporaryDirectory.appendingPathComponent("voice-message-\(recordID.identifier).m4a")
|
let url = URL.temporaryDirectory.appendingPathComponent("voice-message-\(recordID.identifier).m4a")
|
||||||
audioRecorder = try AVAudioRecorder(url: url, settings: settings)
|
let audioRecorder = try AVAudioRecorder(url: url, settings: settings)
|
||||||
audioRecorder?.delegate = self
|
audioRecorder.delegate = self
|
||||||
audioRecorder?.isMeteringEnabled = true
|
audioRecorder.isMeteringEnabled = true
|
||||||
audioRecorder?.record()
|
if audioRecorder.record() {
|
||||||
completion(.success(()))
|
self.audioRecorder = audioRecorder
|
||||||
|
completion(.success(()))
|
||||||
|
} else {
|
||||||
|
MXLog.error("audio recording failed to start")
|
||||||
|
completion(.failure(.recordingFailed))
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
MXLog.error("audio recording failed: \(error)")
|
MXLog.error("audio recording failed to start. \(error)")
|
||||||
completion(.failure(.genericError))
|
completion(.failure(.internalError(error: error)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,12 +192,14 @@ class AudioRecorder: NSObject, AudioRecorderProtocol, AVAudioRecorderDelegate {
|
|||||||
if success {
|
if success {
|
||||||
actionsSubject.send(.didStopRecording)
|
actionsSubject.send(.didStopRecording)
|
||||||
} else {
|
} else {
|
||||||
|
MXLog.error("audio recorder did finish recording with an error.")
|
||||||
actionsSubject.send(.didFailWithError(error: AudioRecorderError.genericError))
|
actionsSubject.send(.didFailWithError(error: AudioRecorderError.genericError))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func audioRecorderEncodeErrorDidOccur(_ recorder: AVAudioRecorder, error: Error?) {
|
func audioRecorderEncodeErrorDidOccur(_ recorder: AVAudioRecorder, error: Error?) {
|
||||||
try? AVAudioSession.sharedInstance().setActive(false)
|
try? AVAudioSession.sharedInstance().setActive(false)
|
||||||
|
MXLog.error("audio recorder encode error did occur. \(error?.localizedDescription ?? "")")
|
||||||
actionsSubject.send(.didFailWithError(error: error ?? AudioRecorderError.genericError))
|
actionsSubject.send(.didFailWithError(error: error ?? AudioRecorderError.genericError))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ extension AudioRecordingIdentifier {
|
|||||||
|
|
||||||
enum AudioRecorderError: Error {
|
enum AudioRecorderError: Error {
|
||||||
case genericError
|
case genericError
|
||||||
|
case internalError(error: Error)
|
||||||
case recordPermissionNotGranted
|
case recordPermissionNotGranted
|
||||||
|
case recordingFailed
|
||||||
case recordingCancelled
|
case recordingCancelled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class VoiceMessageCache: VoiceMessageCacheProtocol {
|
|||||||
do {
|
do {
|
||||||
try cacheFile(source: fileURL, destination: url, move: move)
|
try cacheFile(source: fileURL, destination: url, move: move)
|
||||||
} catch {
|
} catch {
|
||||||
MXLog.error("Failed storing file in cache", context: error)
|
MXLog.error("Failed storing file in cache. \(error)")
|
||||||
return .failure(.failedStoringFileInCache)
|
return .failure(.failedStoringFileInCache)
|
||||||
}
|
}
|
||||||
return .success(url)
|
return .success(url)
|
||||||
@@ -46,7 +46,7 @@ class VoiceMessageCache: VoiceMessageCacheProtocol {
|
|||||||
do {
|
do {
|
||||||
try FileManager.default.removeItem(at: temporaryFilesFolderURL)
|
try FileManager.default.removeItem(at: temporaryFilesFolderURL)
|
||||||
} catch {
|
} 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)
|
// linearly normalized to [0, 1] (1 -> -50 dB)
|
||||||
waveformData = samples.map { UInt16(max(0, (1 - $0) * 1024)) }
|
waveformData = samples.map { UInt16(max(0, (1 - $0) * 1024)) }
|
||||||
} catch {
|
} catch {
|
||||||
MXLog.error("Waveform analysis failed: \(error)")
|
MXLog.error("Waveform analysis failed. \(error)")
|
||||||
}
|
}
|
||||||
return .success(waveformData)
|
return .success(waveformData)
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ class VoiceMessageRecorder: VoiceMessageRecorderProtocol {
|
|||||||
do {
|
do {
|
||||||
size = try UInt64(FileManager.default.sizeForItem(at: oggFile))
|
size = try UInt64(FileManager.default.sizeForItem(at: oggFile))
|
||||||
} catch {
|
} 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)
|
return .failure(.failedSendingVoiceMessage)
|
||||||
}
|
}
|
||||||
let audioInfo = AudioInfo(duration: recordingDuration, size: size, mimetype: "audio/ogg")
|
let audioInfo = AudioInfo(duration: recordingDuration, size: size, mimetype: "audio/ogg")
|
||||||
@@ -170,7 +170,7 @@ class VoiceMessageRecorder: VoiceMessageRecorderProtocol {
|
|||||||
try? FileManager.default.removeItem(at: oggFile)
|
try? FileManager.default.removeItem(at: oggFile)
|
||||||
|
|
||||||
if case .failure(let error) = result {
|
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)
|
return .failure(.failedSendingVoiceMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user