Skip to content

Commit 6b18cea

Browse files
committed
RU-T47 PR#221 fixes
1 parent 1cb60c3 commit 6b18cea

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/services/bluetooth-audio.service.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class BluetoothAudioService {
5858
private pttPressActive: boolean = false;
5959
private pttReleaseFallbackTimeout: ReturnType<typeof setTimeout> | null = null;
6060
private micApplyRetryTimeout: ReturnType<typeof setTimeout> | null = null;
61+
private retryMicEnabled: boolean | null = null;
6162
private pendingMicEnabled: boolean | null = null;
6263
private isApplyingMicState: boolean = false;
6364

@@ -1218,6 +1219,8 @@ class BluetoothAudioService {
12181219
private startMonitoringWatchdog(deviceId: string): void {
12191220
this.stopMonitoringWatchdog();
12201221

1222+
const watchdogRecoveryThresholdMs = 12000;
1223+
12211224
this.monitoringWatchdogInterval = setInterval(() => {
12221225
if (!this.connectedDevice || this.connectedDevice.id !== deviceId) {
12231226
this.stopMonitoringWatchdog();
@@ -1233,6 +1236,14 @@ class BluetoothAudioService {
12331236
if (!this.monitoringStartedAt) {
12341237
return;
12351238
}
1239+
1240+
const monitoringDurationMs = Date.now() - this.monitoringStartedAt;
1241+
if (monitoringDurationMs < watchdogRecoveryThresholdMs) {
1242+
return;
1243+
}
1244+
1245+
this.monitoringStartedAt = Date.now();
1246+
this.ensurePttInputMonitoring('watchdog');
12361247
}, 4000);
12371248
}
12381249

@@ -2116,7 +2127,7 @@ class BluetoothAudioService {
21162127
}
21172128

21182129
private scheduleMicApplyRetry(enabled: boolean): void {
2119-
this.pendingMicEnabled = enabled;
2130+
this.retryMicEnabled = enabled;
21202131

21212132
if (this.micApplyRetryTimeout) {
21222133
return;
@@ -2125,11 +2136,13 @@ class BluetoothAudioService {
21252136
this.micApplyRetryTimeout = setTimeout(() => {
21262137
this.micApplyRetryTimeout = null;
21272138

2128-
const pendingEnabled = this.pendingMicEnabled;
2139+
const pendingEnabled = this.retryMicEnabled;
2140+
this.retryMicEnabled = null;
21292141
if (pendingEnabled === null) {
21302142
return;
21312143
}
21322144

2145+
this.pendingMicEnabled = pendingEnabled;
21332146
this.requestMicrophoneState(pendingEnabled);
21342147
}, 160);
21352148
}
@@ -2139,6 +2152,8 @@ class BluetoothAudioService {
21392152
clearTimeout(this.micApplyRetryTimeout);
21402153
this.micApplyRetryTimeout = null;
21412154
}
2155+
2156+
this.retryMicEnabled = null;
21422157
}
21432158

21442159
private requestMicrophoneState(enabled: boolean): void {
@@ -2301,6 +2316,7 @@ class BluetoothAudioService {
23012316
this.pttPressActive = false;
23022317
this.clearPttReleaseFallback();
23032318
this.clearMicApplyRetry();
2319+
this.retryMicEnabled = null;
23042320
this.pendingMicEnabled = null;
23052321
this.stopMonitoringWatchdog();
23062322
this.stopReadPollingFallback();
@@ -2319,6 +2335,7 @@ class BluetoothAudioService {
23192335
this.pttPressActive = false;
23202336
this.clearPttReleaseFallback();
23212337
this.clearMicApplyRetry();
2338+
this.retryMicEnabled = null;
23222339
this.pendingMicEnabled = null;
23232340
this.stopMonitoringWatchdog();
23242341
this.stopReadPollingFallback();
@@ -2401,6 +2418,7 @@ class BluetoothAudioService {
24012418
useBluetoothAudioStore.getState().setIsHeadsetButtonMonitoring(false);
24022419
this.clearPttReleaseFallback();
24032420
this.clearMicApplyRetry();
2421+
this.retryMicEnabled = null;
24042422
this.pendingMicEnabled = null;
24052423
this.stopMonitoringWatchdog();
24062424
this.stopReadPollingFallback();
@@ -2453,6 +2471,7 @@ class BluetoothAudioService {
24532471
store.setIsHeadsetButtonMonitoring(false);
24542472
this.clearPttReleaseFallback();
24552473
this.clearMicApplyRetry();
2474+
this.retryMicEnabled = null;
24562475
this.pendingMicEnabled = null;
24572476
this.stopMonitoringWatchdog();
24582477
this.stopReadPollingFallback();

0 commit comments

Comments
 (0)