Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Handle BLE disconnection during active Omi recording #10

Description

@unforced

Problem

When an Omi device disconnects during an active recording, the app doesn't handle the disconnection gracefully. The recording data could be lost without user notification.

Location: lib/services/omi/omi_capture_service.dart:162-168

void _onAudioData(List<int> data) {
  if (!_isRecording || _wavBytesUtil == null) return;
  _wavBytesUtil!.storeFramePacket(data);
}

Expected Behavior

When device disconnects mid-recording:

  1. Detect the disconnection event
  2. Save partial recording (what was captured so far)
  3. Notify user with clear message
  4. Mark recording metadata to indicate it was incomplete

Suggested Implementation

// In OmiCaptureService
StreamSubscription? _disconnectListener;

Future<void> startListening() async {
  // Listen for disconnections
  _disconnectListener = bluetoothService.connectionStateStream
    .where((state) => state == DeviceConnectionState.disconnected)
    .listen((_) => _handleUnexpectedDisconnect());
}

Future<void> _handleUnexpectedDisconnect() async {
  if (_isRecording) {
    debugPrint('[OmiCaptureService] Device disconnected during recording');
    
    // Save partial recording
    await _stopRecordingWithTapCount(_currentButtonTapCount ?? 1);
    
    // Notify user
    onStatusMessage?.call('Device disconnected - partial recording saved');
  }
}

Benefits

  • No data loss on unexpected disconnection
  • Better user experience with clear feedback
  • Partial recordings can still be useful

Priority

High - Affects user data integrity

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions