Skip to content

Commit

Permalink
Lost frame issue and other fixes (BasedHardware#700)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by OSS
Entelligence.AI -->
### Summary by Entelligence.AI

---
- New Feature: Added a mechanism to track and manage the connection
status of audio bytes in the `CaptureProvider` class. This will improve
the reliability of audio streaming.
- Bug Fix: Ensured proper cancellation of existing Bluetooth Low Energy
(BLE) byte streams before initiating new ones, preventing potential
stream conflicts.
- Refactor: Updated URLs for privacy policy and about pages in the
`_SettingsPageState` class for better user information access.
- Chore: Included additional safety checks in the `DeviceProvider` class
to ensure audio bytes are correctly disconnected when necessary.
---
<!-- end of auto-generated comment: release notes by OSS Entelligence.AI
-->
  • Loading branch information
josancamon19 authored Aug 30, 2024
2 parents 1319c3a + 919d663 commit 5c5d6bc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
24 changes: 19 additions & 5 deletions app/lib/pages/settings/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,18 @@ class _SettingsPageState extends State<SettingsPage> {
getItemAddOn('Calendar Integration', () {
routeToPage(context, const CalendarPage());
}, icon: Icons.calendar_month),
Divider(color: Colors.transparent,),
Divider(
color: Colors.transparent,
),
getItemAddOn('Speech Recognition', () {
routeToPage(context, const SpeakerIdPage());
}, icon: Icons.multitrack_audio),
getItemAddOn('Identifying Others', () {
routeToPage(context, const UserPeoplePage());
}, icon: Icons.people),
const Divider(color: Colors.transparent,),
const Divider(
color: Colors.transparent,
),
getItemAddOn('Developer Mode', () async {
MixpanelManager().devModePageOpened();
await routeToPage(context, const DeveloperSettingsPage());
Expand All @@ -284,7 +288,7 @@ class _SettingsPageState extends State<SettingsPage> {
Navigator.of(context).push(
MaterialPageRoute(
builder: (c) => const PageWebView(
url: 'https://basedhardware.com/pages/privacy',
url: 'https://www.omi.me/pages/privacy',
title: 'Privacy Policy',
),
),
Expand All @@ -294,12 +298,22 @@ class _SettingsPageState extends State<SettingsPage> {
Navigator.of(context).push(
MaterialPageRoute(
builder: (c) => const PageWebView(
url: 'https://basedhardware.com/',
title: 'Based Hardware',
url: 'https://www.omi.me/',
title: 'omi',
),
),
);
}, icon: Icons.language_outlined, visibility: true),
getItemAddOn('About omi', () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (c) => const PageWebView(
url: 'https://www.omi.me/pages/about',
title: 'About Us',
),
),
);
}, icon: Icons.people, visibility: true),
const SizedBox(height: 32),
Padding(
padding: const EdgeInsets.all(8),
Expand Down
16 changes: 14 additions & 2 deletions app/lib/providers/capture_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CaptureProvider extends ChangeNotifier with WebSocketMixin, OpenGlassMixin
bool memoryCreating = false;
bool webSocketConnected = false;
bool webSocketConnecting = false;
bool audioBytesConnected = false;

static const quietSecondsForMemoryCreation = 120;

Expand Down Expand Up @@ -100,6 +101,11 @@ class CaptureProvider extends ChangeNotifier with WebSocketMixin, OpenGlassMixin
notifyListeners();
}

void setAudioBytesConnected(bool value) {
audioBytesConnected = value;
notifyListeners();
}

void updateConnectedDevice(BTDeviceStruct? device) {
debugPrint('connected device changed from ${connectedDevice?.id} to ${device?.id}');
connectedDevice = device;
Expand Down Expand Up @@ -282,6 +288,9 @@ class CaptureProvider extends ChangeNotifier with WebSocketMixin, OpenGlassMixin
Future streamAudioToWs(String id, BleAudioCodec codec) async {
print('streamAudioToWs');
audioStorage = WavBytesUtil(codec: codec);
if (_bleBytesStream != null) {
_bleBytesStream?.cancel();
}
_bleBytesStream = await getBleAudioBytesListener(
id,
onAudioBytesReceived: (List<int> value) {
Expand All @@ -296,6 +305,7 @@ class CaptureProvider extends ChangeNotifier with WebSocketMixin, OpenGlassMixin
}
},
);
setAudioBytesConnected(true);
notifyListeners();
}

Expand All @@ -322,9 +332,9 @@ class CaptureProvider extends ChangeNotifier with WebSocketMixin, OpenGlassMixin
if (restartBytesProcessing) {
if (webSocketConnected) {
closeWebSocket();
initiateWebsocket();
await initiateWebsocket();
} else {
initiateWebsocket();
await initiateWebsocket();
}
} else {
closeWebSocket();
Expand Down Expand Up @@ -359,13 +369,15 @@ class CaptureProvider extends ChangeNotifier with WebSocketMixin, OpenGlassMixin
}

Future<void> initiateFriendAudioStreaming() async {
print('inside initiateFriendAudioStreaming');
if (connectedDevice == null) return;
BleAudioCodec codec = await getAudioCodec(connectedDevice!.id);
if (SharedPreferencesUtil().deviceCodec != codec) {
debugPrint('Device codec changed from ${SharedPreferencesUtil().deviceCodec} to $codec');
SharedPreferencesUtil().deviceCodec = codec;
notifyInfo('FIM_CHANGE');
} else {
if (audioBytesConnected) return;
streamAudioToWs(connectedDevice!.id, codec);
}

Expand Down
1 change: 1 addition & 0 deletions app/lib/providers/device_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class DeviceProvider extends ChangeNotifier with WebSocketMixin {
updateConnectingStatus(false);
periodicConnect('coming from onDisconnect');
captureProvider?.resetState(restartBytesProcessing: false);
captureProvider?.setAudioBytesConnected(false);
print('after resetState inside initiateConnectionListener');

InstabugLog.logInfo('Friend Device Disconnected');
Expand Down

0 comments on commit 5c5d6bc

Please sign in to comment.