Why on onDeviceDiscovered the type is BluetoothDeviceEvent but when print the result is different? #262
Replies: 3 comments 5 replies
-
a) Attempt to just use The response from that should actually be, something like:
To match the rest of the event data.
It would also need to be added to the Java version of |
Beta Was this translation helpful? Give feedback.
-
I want to create a PR but to fix this typed issue there are to modify the https://github.com/kenjdavidson/react-native-bluetooth-classic/blob/main/src/BluetoothModule.ts#L484? |
Beta Was this translation helpful? Give feedback.
-
While I was changing my code I decided to try some use cases like connecting while the device is already connected but I noticed that it gives me this error This is my code: const connectDevice = (device: BluetoothNativeDevice): Promise<void> => {
return new Promise(async (resolve, reject) => {
try {
const connectionSuccess = await RNBluetoothClassic.connectToDevice(
device.address,
{
connectionType: 'binary',
delimiter: '\r\n',
},
);
if (!connectionSuccess)
throw new Error(`Error al intentar conectar ${device.name}`);
const readDevice = RNBluetoothClassic.onDeviceRead(
device.address,
onReceiveData,
);
const onDisconnect = RNBluetoothClassic.onDeviceDisconnected(
(event: any) => {
readDevice.remove();
onDisconnect.remove();
dispatch(removeDevice(event.address));
ToastAndroid.show(`${event.name} se ha desconectado`, 3000);
},
);
dispatch(
addListener({
address: device.address,
listener: readDevice,
}),
);
dispatch(setConnectedDevice(device));
resolve();
} catch (error) {
reject(error);
}
});
}; The |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello
I have tried to use the
onDeviceDiscovered
function to save the devices as it finds them, but the type of the parameter returned by the callback is BluetoothDeviceEvent but when I print the result to the console, it returns something like this:I notice that there is an interface called
BluetoothNativeDevice
, very similar to what theonDeviceDiscovered
listener prints. Is this really the type of value that it returns as a parameter in the listener?As another question, I see that in types like
BluetoothDevice
there is the rssi as the value of the interface, but it is really printed normally within the value of extra. Is there something that makes it change?Thanks for your help :D
Beta Was this translation helpful? Give feedback.
All reactions