@@ -1310,7 +1310,7 @@ class BluetoothAudioService {
13101310 }
13111311
13121312 private async startNotificationsForButtonControls ( deviceId : string , peripheralInfo : PeripheralInfo ) : Promise < void > {
1313- const subscribedPairs = new Set < string > ( ) ;
1313+ const successfullySubscribed = new Set < string > ( ) ;
13141314 this . monitoredReadCharacteristics = [ ] ;
13151315 const isSpecializedDevice = Boolean ( this . connectedDevice && this . connectedDevice . id === deviceId && this . getDeviceType ( this . connectedDevice ) === 'specialized' ) ;
13161316
@@ -1342,7 +1342,7 @@ class BluetoothAudioService {
13421342 }
13431343
13441344 await BleManager . startNotification ( deviceId , config . service , config . characteristic ) ;
1345- subscribedPairs . add ( `${ config . service . toUpperCase ( ) } ::${ config . characteristic . toUpperCase ( ) } ` ) ;
1345+ successfullySubscribed . add ( `${ config . service . toUpperCase ( ) } ::${ config . characteristic . toUpperCase ( ) } ` ) ;
13461346 this . registerReadPollingCharacteristic ( config . service , config . characteristic ) ;
13471347 logger . info ( {
13481348 message : 'Started notifications for button control' ,
@@ -1378,13 +1378,13 @@ class BluetoothAudioService {
13781378 const pairKey = `${ String ( serviceUuid ) . toUpperCase ( ) } ::${ String ( characteristicUuid ) . toUpperCase ( ) } ` ;
13791379 const shouldSubscribe = isSpecializedDevice ? true : this . isLikelyButtonCharacteristic ( serviceUuid , characteristicUuid ) || this . hasNotificationOrReadCapability ( characteristic ?. properties ) ;
13801380
1381- if ( ! shouldSubscribe || subscribedPairs . has ( pairKey ) ) {
1381+ if ( ! shouldSubscribe || successfullySubscribed . has ( pairKey ) ) {
13821382 continue ;
13831383 }
13841384
13851385 try {
13861386 await BleManager . startNotification ( deviceId , serviceUuid , characteristicUuid ) ;
1387- subscribedPairs . add ( pairKey ) ;
1387+ successfullySubscribed . add ( pairKey ) ;
13881388
13891389 if ( isSpecializedDevice || this . hasReadCapability ( characteristic ?. properties ) ) {
13901390 this . registerReadPollingCharacteristic ( serviceUuid , characteristicUuid ) ;
@@ -1422,11 +1422,16 @@ class BluetoothAudioService {
14221422 continue ;
14231423 }
14241424
1425+ const pairKey = `${ String ( serviceUuid ) . toUpperCase ( ) } ::${ String ( characteristicUuid ) . toUpperCase ( ) } ` ;
1426+ if ( ! successfullySubscribed . has ( pairKey ) ) {
1427+ continue ;
1428+ }
1429+
14251430 this . registerReadPollingCharacteristic ( serviceUuid , characteristicUuid ) ;
14261431 }
14271432 }
14281433
1429- if ( subscribedPairs . size > 0 ) {
1434+ if ( successfullySubscribed . size > 0 ) {
14301435 useBluetoothAudioStore . getState ( ) . setIsHeadsetButtonMonitoring ( true ) ;
14311436 this . startReadPollingFallback ( deviceId ) ;
14321437 } else {
@@ -1488,6 +1493,11 @@ class BluetoothAudioService {
14881493 continue ;
14891494 }
14901495
1496+ if ( entry . lastHexValue === null ) {
1497+ entry . lastHexValue = nextHexValue ;
1498+ continue ;
1499+ }
1500+
14911501 if ( entry . lastHexValue === nextHexValue ) {
14921502 continue ;
14931503 }
@@ -2106,13 +2116,21 @@ class BluetoothAudioService {
21062116 }
21072117
21082118 private scheduleMicApplyRetry ( enabled : boolean ) : void {
2119+ this . pendingMicEnabled = enabled ;
2120+
21092121 if ( this . micApplyRetryTimeout ) {
21102122 return ;
21112123 }
21122124
21132125 this . micApplyRetryTimeout = setTimeout ( ( ) => {
21142126 this . micApplyRetryTimeout = null ;
2115- this . requestMicrophoneState ( enabled ) ;
2127+
2128+ const pendingEnabled = this . pendingMicEnabled ;
2129+ if ( pendingEnabled === null ) {
2130+ return ;
2131+ }
2132+
2133+ this . requestMicrophoneState ( pendingEnabled ) ;
21162134 } , 160 ) ;
21172135 }
21182136
0 commit comments