Skip to content

Commit 661818c

Browse files
fix missing properties on BluetoothDevice (#358)
When manipulating the object via spread operator or destructure, class methods will not work due to being non-enumerable. By changing them to class fields, they will work as expected in these scenarios
1 parent d7148ae commit 661818c

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/BluetoothDevice.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
5252
* DeviceConnector and DeviceConnection.
5353
* @return Promise resolving true|false whether the connetion was established
5454
*/
55-
async connect<T extends StandardOptions>(options?: T): Promise<boolean> {
55+
connect = <T extends StandardOptions>(options?: T): Promise<boolean> => {
5656
return new Promise(async (resolve, reject) => {
5757
try {
5858
let connected = await this._bluetoothModule.connectToDevice(this.address, options);
@@ -69,7 +69,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
6969
*
7070
* @return Promise resolving true|false based on connection status
7171
*/
72-
async isConnected(): Promise<boolean> {
72+
isConnected = (): Promise<boolean> => {
7373
return this._bluetoothModule.isDeviceConnected(this.address);
7474
}
7575

@@ -78,7 +78,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
7878
*
7979
* @return Promise resolving true|false whether disconnection was successful
8080
*/
81-
async disconnect(): Promise<boolean> {
81+
disconnect = (): Promise<boolean> => {
8282
return this._bluetoothModule.disconnectFromDevice(this.address);
8383
}
8484

@@ -89,7 +89,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
8989
*
9090
* @return Promise resolving the number of messages/data available
9191
*/
92-
async available(): Promise<number> {
92+
available = (): Promise<number> => {
9393
return this._bluetoothModule.availableFromDevice(this.address);
9494
}
9595

@@ -100,7 +100,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
100100
*
101101
* @return Promise resolved with the message content (not including delimited)
102102
*/
103-
async read(): Promise<String> {
103+
read = (): Promise<String> => {
104104
return this._bluetoothModule.readFromDevice(this.address);
105105
}
106106

@@ -110,7 +110,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
110110
*
111111
* @return Promise resolving whether the clear was successful
112112
*/
113-
async clear(): Promise<boolean> {
113+
clear = (): Promise<boolean> => {
114114
return this._bluetoothModule.clearFromDevice(this.address);
115115
}
116116

@@ -122,7 +122,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
122122
* @param data to be written to the device.
123123
* @param encoding the encoding used when wrapping non Buffer data
124124
*/
125-
async write(
125+
write = (
126126
data: string | Buffer,
127127
encoding?:
128128
| 'utf-8'
@@ -136,7 +136,7 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
136136
| 'binary'
137137
| 'hex'
138138
| undefined
139-
): Promise<boolean> {
139+
): Promise<boolean> => {
140140
return this._bluetoothModule.writeToDevice(this.address, data, encoding);
141141
}
142142

@@ -147,9 +147,9 @@ export default class BluetoothDevice implements BluetoothNativeDevice {
147147
*
148148
* @param listener the BluetoothEventListener which will receive incoming data
149149
*/
150-
onDataReceived(
150+
onDataReceived = (
151151
listener: BluetoothEventListener<BluetoothDeviceReadEvent>
152-
): BluetoothEventSubscription {
152+
): BluetoothEventSubscription => {
153153
return this._bluetoothModule.onDeviceRead(this.address, listener);
154154
}
155155
}

0 commit comments

Comments
 (0)