@@ -15,9 +15,9 @@ export class BluetoothManager implements IBluetoothManager {
1515 ) ;
1616 this . registeredByAPlugin = new Signal <
1717 this,
18- BluetoothManager . DeviceRegistry
18+ BluetoothManager . DeviceTypeRegistry
1919 > ( this ) ;
20- this . _registry = new BluetoothManager . DeviceRegistry ( ) ;
20+ this . _deviceTypeRegistry = new BluetoothManager . DeviceTypeRegistry ( ) ;
2121 this . _deviceList = [ ] ;
2222 this . _identifierRegistry = [ ] ;
2323 }
@@ -26,54 +26,50 @@ export class BluetoothManager implements IBluetoothManager {
2626 return this . _deviceList ;
2727 }
2828
29- get registry ( ) : BluetoothManager . DeviceRegistry {
30- return this . _registry ;
29+ get deviceTypeRegistry ( ) : BluetoothManager . DeviceTypeRegistry {
30+ return this . _deviceTypeRegistry ;
3131 }
3232
33- get identifierRegistry ( ) : Array < string > {
34- return this . _identifierRegistry ;
35- }
36-
37- async connectDevice (
38- registryItem : IDeviceRegistryItem
33+ async connect (
34+ registryItem : IDeviceTypeRegistryItem
3935 ) : Promise < BluetoothManager . Device | undefined > {
4036 const native = await this . requestDevice ( registryItem ) ;
4137 if ( native ) {
4238 const device = await registryItem . factory ( native ) ;
4339 if ( device && device . isConnected ) {
44- this . addDeviceToList ( device ) ;
40+ this . _addDeviceToList ( device ) ;
4541 device . disconnected . connect ( async ( ) => {
46- this . removeDeviceFromList ( device ) ;
42+ this . _removeDeviceFromList ( device ) ;
4743 } ) ;
4844 return device ;
4945 }
5046 }
5147 }
5248
53- async disconnectDevice ( device : BluetoothManager . Device ) {
49+ async disconnect ( device : BluetoothManager . Device ) {
5450 await device . disconnect ( ) ;
5551 device . dispose ( ) ;
5652 }
5753
5854 // Method to add a device to the list
59- addDeviceToList ( device : BluetoothManager . Device ) : void {
55+ private _addDeviceToList ( device : BluetoothManager . Device ) : void {
6056 const identifier = buildCompleteIdentifier ( device . native ) ;
61- if ( this . identifierRegistry . includes ( identifier ) === false ) {
57+ if ( this . _identifierRegistry . includes ( identifier ) === false ) {
6258 this . _deviceList . push ( device ) ;
63- this . identifierRegistry . push ( identifier ) ;
59+ this . _identifierRegistry . push ( identifier ) ;
6460 } else {
65- console . warn ( 'The device is already in the identifierRegistry ' ) ;
61+ console . warn ( 'The device is already in the registry of identifiers ' ) ;
6662 }
6763 // Emit the signal when the list changes
6864 this . deviceListChanged . emit ( this . _deviceList ) ;
6965 }
7066
7167 // Method to remove a device from the list
72- removeDeviceFromList ( device : BluetoothManager . Device ) : void {
68+ private _removeDeviceFromList ( device : BluetoothManager . Device ) : void {
7369 const index = this . _deviceList . indexOf ( device ) ;
7470 if ( index > - 1 ) {
7571 this . _deviceList . splice ( index , 1 ) ;
76- this . identifierRegistry . splice ( index , 1 ) ;
72+ this . _identifierRegistry . splice ( index , 1 ) ;
7773 // Emit the signal when the list changes
7874 this . deviceListChanged . emit ( this . _deviceList ) ;
7975 }
@@ -82,20 +78,11 @@ export class BluetoothManager implements IBluetoothManager {
8278
8379 removeAllDevices ( ) {
8480 this . _deviceList . forEach ( ( device , index ) => {
85- this . removeDeviceFromList ( device ) ;
81+ this . _removeDeviceFromList ( device ) ;
8682 this . deviceListChanged . emit ( this . _deviceList ) ;
8783 } ) ;
8884 }
8985
90- register ( registryItem : IDeviceRegistryItem ) {
91- this . _registry . add ( registryItem ) ;
92- this . registeredByAPlugin . emit ( this . _registry ) ;
93- console . warn (
94- `New item from category ${ registryItem . deviceType } is added to the registry.`
95- ) ;
96- return this . _registry ;
97- }
98-
9986 async checkWebBluetoothSupport ( ) : Promise < boolean > {
10087 const isWebBluetoothSupported : boolean = navigator . bluetooth ? true : false ;
10188 if ( isWebBluetoothSupported === false ) {
@@ -109,7 +96,7 @@ export class BluetoothManager implements IBluetoothManager {
10996 }
11097
11198 async requestDevice (
112- registryItem : IDeviceRegistryItem
99+ registryItem : IDeviceTypeRegistryItem
113100 ) : Promise < BluetoothDevice | undefined > {
114101 const isWebBluetoothSupported = await this . checkWebBluetoothSupport ( ) ;
115102 if ( isWebBluetoothSupported ) {
@@ -126,9 +113,9 @@ export class BluetoothManager implements IBluetoothManager {
126113 public deviceListChanged : Signal < this, Array < BluetoothManager . Device > > ;
127114 public registeredByAPlugin : Signal <
128115 BluetoothManager ,
129- BluetoothManager . DeviceRegistry
116+ BluetoothManager . DeviceTypeRegistry
130117 > ;
131- private _registry : BluetoothManager . DeviceRegistry ;
118+ private _deviceTypeRegistry : BluetoothManager . DeviceTypeRegistry ;
132119 private _identifierRegistry : Array < string > ;
133120}
134121
@@ -283,18 +270,18 @@ export namespace BluetoothManager {
283270 }
284271 }
285272
286- export class DeviceRegistry implements IDeviceRegistry {
287- private _registry : Array < IDeviceRegistryItem > ;
288- public registryItem : IDeviceRegistryItem ;
273+ export class DeviceTypeRegistry implements IDeviceTypeRegistry {
274+ private _deviceTypeRegistry : Array < IDeviceTypeRegistryItem > ;
275+ public registryItem : IDeviceTypeRegistryItem ;
289276 constructor ( ) {
290- this . _registry = [ ] ;
277+ this . _deviceTypeRegistry = [ ] ;
291278 }
292279
293- add ( registryItem : IDeviceRegistryItem ) {
294- this . _registry . push ( registryItem ) ;
280+ add ( registryItem : IDeviceTypeRegistryItem ) {
281+ this . _deviceTypeRegistry . push ( registryItem ) ;
295282 }
296- get itemsList ( ) : Array < IDeviceRegistryItem > {
297- return this . _registry ;
283+ get itemsList ( ) : Array < IDeviceTypeRegistryItem > {
284+ return this . _deviceTypeRegistry ;
298285 }
299286 }
300287}
@@ -303,33 +290,29 @@ export namespace BluetoothManager {
303290 * Interface for the bluetooth manager.
304291 */
305292export interface IBluetoothManager {
306- addDeviceToList ( Device : BluetoothManager . Device ) : void ;
307- removeDeviceFromList ( Device : BluetoothManager . Device ) : void ;
308293 removeAllDevices ( Devices : Array < BluetoothManager . Device > ) : void ;
309- register ( registryItem : IDeviceRegistryItem ) : BluetoothManager . DeviceRegistry ;
310- connectDevice ( registryItem : IDeviceRegistryItem ) : any ;
311- disconnectDevice ( device : BluetoothManager . Device ) : void ;
294+ connect ( registryItem : IDeviceTypeRegistryItem ) : any ;
295+ disconnect ( device : BluetoothManager . Device ) : void ;
312296 deviceListChanged : Signal < BluetoothManager , Array < BluetoothManager . Device > > ;
313297 registeredByAPlugin : Signal <
314298 BluetoothManager ,
315- BluetoothManager . DeviceRegistry
299+ BluetoothManager . DeviceTypeRegistry
316300 > ;
317301 get deviceList ( ) : Array < BluetoothManager . Device > ;
318- get registry ( ) : BluetoothManager . DeviceRegistry ;
319- get identifierRegistry ( ) : Array < string > ;
302+ get deviceTypeRegistry ( ) : BluetoothManager . DeviceTypeRegistry ;
320303}
321304
322- export interface IDeviceRegistryItem {
305+ export interface IDeviceTypeRegistryItem {
323306 deviceType : string ;
324307 factory : (
325308 native : BluetoothDevice
326309 ) => Promise < BluetoothManager . Device | undefined > ;
327310 options : IDeviceOptions ;
328311}
329312
330- export interface IDeviceRegistry {
331- add : ( registryItem : IDeviceRegistryItem ) => void ;
332- get itemsList ( ) : Array < IDeviceRegistryItem > ;
313+ export interface IDeviceTypeRegistry {
314+ add : ( registryItem : IDeviceTypeRegistryItem ) => void ;
315+ get itemsList ( ) : Array < IDeviceTypeRegistryItem > ;
333316}
334317
335318export const IBluetoothManager = new Token < IBluetoothManager > (
0 commit comments