Fix message display and add voice note debugging

- Fix escaped backslashes in timestamp and sender name display
- Add comprehensive logging for voice note transmission pipeline
- Add peripheral write completion logging
- Track broadcast success/failure for central updates
- Log audio recorder creation and preparation steps
- Better diagnostics for troubleshooting voice note issues
This commit is contained in:
jack
2025-07-03 23:28:07 +02:00
parent 78ddb36db7
commit 8346ecd2a7
4 changed files with 23 additions and 6 deletions
@@ -72,10 +72,14 @@ class AudioRecordingService: NSObject, ObservableObject {
audioRecorder?.delegate = self audioRecorder?.delegate = self
audioRecorder?.prepareToRecord() // Important: prepare before recording audioRecorder?.prepareToRecord() // Important: prepare before recording
print("[AUDIO] Created recorder with URL: \(audioFilename)")
print("[AUDIO] Recorder prepared: \(audioRecorder?.prepareToRecord() ?? false)")
if audioRecorder?.record() == true { if audioRecorder?.record() == true {
isRecording = true isRecording = true
recordingStartTime = Date() recordingStartTime = Date()
recordingTime = 0 recordingTime = 0
print("[AUDIO] Recording started successfully")
// Start timer to update recording time and enforce max duration // Start timer to update recording time and enforce max duration
recordingTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] _ in recordingTimer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { [weak self] _ in
+12 -3
View File
@@ -373,10 +373,19 @@ class BluetoothMeshService: NSObject {
// Send to subscribed centrals (as peripheral) // Send to subscribed centrals (as peripheral)
if characteristic != nil && !subscribedCentrals.isEmpty { if characteristic != nil && !subscribedCentrals.isEmpty {
peripheralManager.updateValue(data, for: characteristic, onSubscribedCentrals: subscribedCentrals) let success = peripheralManager.updateValue(data, for: characteristic, onSubscribedCentrals: subscribedCentrals)
print("[BROADCAST] Sent to \(subscribedCentrals.count) subscribed centrals") if success {
print("[BROADCAST] Successfully sent to \(subscribedCentrals.count) subscribed centrals")
} else {
print("[BROADCAST] Failed to send to centrals - queue full, will retry on delegate callback")
}
} else { } else {
print("[BROADCAST] No subscribed centrals to send to") if characteristic == nil {
print("[BROADCAST] No characteristic available")
}
if subscribedCentrals.isEmpty {
print("[BROADCAST] No subscribed centrals")
}
} }
} }
+4
View File
@@ -631,6 +631,8 @@ extension ChatViewModel: BitchatDelegate {
} }
func sendVoiceNote(_ audioData: Data, duration: TimeInterval) { func sendVoiceNote(_ audioData: Data, duration: TimeInterval) {
print("[VIEWMODEL] sendVoiceNote called with audio data: \(audioData.count) bytes, duration: \(duration)s")
let message = BitchatMessage( let message = BitchatMessage(
sender: nickname, sender: nickname,
content: "🎤 \(String(format: "%.1f", duration))s", content: "🎤 \(String(format: "%.1f", duration))s",
@@ -642,6 +644,8 @@ extension ChatViewModel: BitchatDelegate {
) )
messages.append(message) messages.append(message)
print("[VIEWMODEL] Added voice note to local messages, sending via mesh...")
// Send via mesh // Send via mesh
meshService.sendVoiceNote(audioData, duration: duration) meshService.sendVoiceNote(audioData, duration: duration)
} }
+3 -3
View File
@@ -370,7 +370,7 @@ struct ContentView: View {
// Regular messages with tappable sender name // Regular messages with tappable sender name
HStack(alignment: .top, spacing: 0) { HStack(alignment: .top, spacing: 0) {
// Timestamp // Timestamp
Text("[\\(viewModel.formatTimestamp(message.timestamp))] ") Text("[\(viewModel.formatTimestamp(message.timestamp))] ")
.font(.system(size: 12, design: .monospaced)) .font(.system(size: 12, design: .monospaced))
.foregroundColor(secondaryTextColor) .foregroundColor(secondaryTextColor)
@@ -382,14 +382,14 @@ struct ContentView: View {
} }
}) { }) {
let senderColor = viewModel.getSenderColor(for: message, colorScheme: colorScheme) let senderColor = viewModel.getSenderColor(for: message, colorScheme: colorScheme)
Text("<\\(message.sender)>") Text("<\(message.sender)>")
.font(.system(size: 12, weight: .medium, design: .monospaced)) .font(.system(size: 12, weight: .medium, design: .monospaced))
.foregroundColor(senderColor) .foregroundColor(senderColor)
} }
.buttonStyle(.plain) .buttonStyle(.plain)
} else { } else {
// Own messages not tappable // Own messages not tappable
Text("<\\(message.sender)>") Text("<\(message.sender)>")
.font(.system(size: 12, weight: .medium, design: .monospaced)) .font(.system(size: 12, weight: .medium, design: .monospaced))
.foregroundColor(textColor) .foregroundColor(textColor)
} }