File tree Expand file tree Collapse file tree 2 files changed +21
-4
lines changed
Expand file tree Collapse file tree 2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,20 @@ var advertise = function (options) {
1717 if ( ! options . manufacturer )
1818 options . manufacturer = false ;
1919 }
20+ var adv = clone ( Bangle . bleAdvert ) ;
2021 try {
21- NRF . setAdvertising ( clone ( Bangle . bleAdvert ) , options ) ;
22+ NRF . setAdvertising ( adv , options ) ;
2223 }
2324 catch ( e ) {
24- console . log ( "ble_advert error" , e ) ;
25+ if ( e . toString ( ) . includes ( "INVALID_LENGTH" ) ) {
26+ options . showName = false ;
27+ try {
28+ NRF . setAdvertising ( adv , options ) ;
29+ }
30+ catch ( e ) {
31+ console . log ( "ble_advert error" , e ) ;
32+ }
33+ }
2534 }
2635} ;
2736var manyAdv = function ( bleAdvert ) {
Original file line number Diff line number Diff line change @@ -41,10 +41,18 @@ const advertise = (options: SetAdvertisingOptions) => {
4141 // taking effect for later calls.
4242 //
4343 // This also allows us to identify previous adverts correctly by id.
44+ let adv = clone ( ( Bangle as BangleWithAdvert ) . bleAdvert ) ;
4445 try {
45- NRF . setAdvertising ( clone ( ( Bangle as BangleWithAdvert ) . bleAdvert ) , options ) ;
46+ NRF . setAdvertising ( adv , options ) ;
4647 } catch ( e ) {
47- console . log ( "ble_advert error" , e ) ;
48+ if ( ( e as Error ) . toString ( ) . includes ( "INVALID_LENGTH" ) ) {
49+ options . showName = false ; // if the advertising is too long, automatically remove the Bangle's name from advertisements
50+ try {
51+ NRF . setAdvertising ( adv , options ) ;
52+ } catch ( e ) {
53+ console . log ( "ble_advert error" , e ) ;
54+ }
55+ }
4856 }
4957} ;
5058
You can’t perform that action at this time.
0 commit comments