@@ -52,7 +52,13 @@ export function bluetoothEnabled(target: Object, propertyKey: string, descriptor
52
52
return descriptor ;
53
53
}
54
54
55
- const pattern = / 0 0 0 0 ( .{ 4 } ) - 0 0 0 0 - 1 0 0 0 - 8 0 0 0 - 0 0 8 0 5 f 9 b 3 4 f b / ;
55
+ // BT assigned-numbers: https://www.bluetooth.com/specifications/assigned-numbers/
56
+ const patternBtAssignedNumbers = / 0 0 0 0 ( .{ 4 } ) - 0 0 0 0 - 1 0 0 0 - 8 0 0 0 - 0 0 8 0 5 f 9 b 3 4 f b / i;
57
+ export function shortenUuidIfAssignedNumber ( uuid : string ) {
58
+ const matcher = uuid . toLowerCase ( ) . match ( patternBtAssignedNumbers ) ;
59
+ return ( matcher && matcher . length > 0 ? matcher [ 1 ] : uuid ) ;
60
+ }
61
+
56
62
export function prepareArgs ( target : Object , propertyKey : string , descriptor : TypedPropertyDescriptor < any > ) {
57
63
const originalMethod = descriptor . value as Function ; // save a reference to the original method
58
64
@@ -65,13 +71,9 @@ export function prepareArgs(target: Object, propertyKey: string, descriptor: Typ
65
71
const value = paramsToCheck [ k ] ;
66
72
if ( value ) {
67
73
if ( Array . isArray ( value ) ) {
68
- paramsToCheck [ k ] = paramsToCheck [ k ] . map ( v => {
69
- const matcher = ( v as string ) . match ( pattern ) ;
70
- return ( matcher && matcher . length > 0 ? matcher [ 1 ] : v ) . toLowerCase ( ) ;
71
- } ) ;
74
+ paramsToCheck [ k ] = paramsToCheck [ k ] . map ( v => shortenUuidIfAssignedNumber ( v ) ) ;
72
75
} else {
73
- const matcher = ( paramsToCheck [ k ] as string ) . match ( pattern ) ;
74
- paramsToCheck [ k ] = ( matcher && matcher . length > 0 ? matcher [ 1 ] : paramsToCheck [ k ] ) . toLowerCase ( ) ;
76
+ paramsToCheck [ k ] = shortenUuidIfAssignedNumber ( paramsToCheck [ k ] ?? '' ) ;
75
77
}
76
78
}
77
79
} ) ;
@@ -531,7 +533,7 @@ export interface DiscoverCharacteristicsOptions extends DiscoverOptions {
531
533
}
532
534
533
535
// tslint:disable-next-line:no-empty-interface
534
- export interface StopNotifyingOptions extends CRUDOptions { }
536
+ export interface StopNotifyingOptions extends CRUDOptions { }
535
537
536
538
export interface StartNotifyingOptions extends CRUDOptions {
537
539
onNotify : ( data : ReadResult ) => void ;
0 commit comments