Web Bluetooth bypass Pairing Screen for a known device id - javascript

Is it possible to connect a bluetooth device whose ID I know without the pairing screen?
classic:
navigator.bluetooth.requestDevice ({filters: [{services: ['heart_rate']}]})
.then (device => {
this.device = device;
return device.gatt.connect ();
instead I would like to do device.gatt.connect () without navigator.bluetooth.requestDevice .. at least for the device that I have already connected once or of which I know the ID.
can someone help me? ..thank you!

The Bluetooth Permissions API integration section of the Web Bluetooth spec does specify a way to do this using a device ID. However, it is not currently implemented in any browser.
There is ongoing work in Chrome to implement a getDevices() method that can return a list of previously granted Bluetooth devices. The status of that API can be checked in Chrome Platform Status.
6/22/20 Edit:
I recently implemented a new permissions backend as well as two APIs that will enable previously permitted Bluetooth devices to be used.
The new permissions backend is implemented behind the chrome://flags/#enable-web-bluetooth-new-permissions-backend. The new backend will persist device permissions granted through requestDevice() until the permission is reset in Site Settings or the Page Info dialog box.
The getDevices() and watchAdvertisements() are implemented behind the chrome://flags/#enable-experimental-web-platform-features flag for Chrome 85.0.4165.0 or greater. The recommended use of these APIs is to use getDevices() to retrieve an array of permitted BluetoothDevices and then calling watchAdvertisements() on these devices to start a scan. When advertisement packets are detected from the devices, the advertisementreceived Event will be fired on the device that it corresponds to. At this point, the Bluetooth device is in range and can be connected to.
Please give this new feature a try, and file any bugs at https://crbug.com using the Blink>Bluetooth component.

Related

How to work around lack WebRTC support in a browser?

Some browsers (mobile Mi Browser, for instance) don't support WebRTC - they have no RTCPeerConnection API. So the users of your WebRTC web app have to open it in another one.
Is there a way to make your WebRTC app work without an explicit browser-change action from the user, especially on a mobile device?
I tried to investigate the following:
Deep Link. Looks like we can't redirect the user to another browser using deep link (I haven't found Chrome deep link for mobile).
Send WebRTC sources to browser / use third-party WebRTC lib. This won't work either, you need WebRTC support in the browser source code.
WebRTC is a framework based on a set of standards. It includes not only capability to get information about user input/output devices, but also set of network protocols which based on UDP (from getting client's IP to transfer arbitrary data through data channel using SCTP protocol). So, as you already may guess, it's impossible to support in a browser which doesn't have it, this is why point (2) will not work.
In case of point (1 - Open Chrome). On iOS exists custom protocol to open URL in chrome "googlechromes://stackoverflow.com", but it's better to explicitly say user that current browser doesn't support required functionality; And provide links on list of popular browsers for download (Chrome, Firefox, etc.); And already on these websites user will be redirected to the proper store for downloading native app.

How to check if any bluetooth device is connected in react native

I've been attempting to detect whether a bluetooth device is connected to an android phone once a button is clicked. If detected, I would like to interact with this device from within my app. The device I'm talking about is http://www.senanetworks.com/sd1000-01.html .
I've used the example code of https://www.npmjs.com/package/react-native-ble-manager to test it out, but unfortunately, it's not picking up this device even though the regular settings app does. Additionally, checking for already connected peripherals does not work if I connected to the device outside of the app. Any tips on how to do this?
The device you are using, the Parani-SD1000 Bluetooth Serial Adapter, does state in its specs that it uses Bluetooth 2.0. You are using a library for Bluetooth Low Energy devices, but BLE was only introduced with Bluetooth 4.0.
Your devices definitely uses Bluetooth Classic (also nown as Bluetooth Serial), thats also the reason why it shows up in the settings of your mobile phone. You need to use a library like react-native-bluetooth-serial. You can use the isConnected() method to detect wether or not it is connected.

How to find correct USB device configuration and interface for use in WebUSB?

In WebUSB to connect to a device we must select a configuration and interface.
There's also the option to using an alternate interface.
How can I know which ones to use?
Do I need to know this beforehand or can I try to detect for each device?
if (!device.configuration) await device.selectConfiguration(0);
await device.claimInterface(device.configuration.interfaces[0].interfaceNumber)
Lets say I can have thermal printers and cameras for example, would I be able to detect for each one?
Also, how can I check if a device is already claimed? Do I have to check every interface?
How can I know which ones to use? Do I need to know this beforehand or
can I try to detect for each device?
As https://web.dev/devices-introduction/#:~:text=human-readable%20protocol.-,With,-WebUSB%2C%20without%20clear says, without clear documentation for this device and what USB commands this device supports, it's hard but still possible with lucky guessing.
Watch Exploring WebUSB and its exciting potential from Suz Hinton. You can also reverse-engineer this device by capturing raw USB traffic and inspecting USB descriptors with external tools like Wireshark and built-in browser tools such as the internal page about://usb-internals in Chromium-based browsers.
Lets say I can have thermal printers and cameras for example, would I
be able to detect for each one?
Camera will likely be blocked. Inspecting your device in about://usb-internals/ will tell you as you should see "Blocked by WebUSB" when it's the case.
Also, how can I check if a device is already claimed? Do I have to check every interface?
In general, I'd recommend https://web.dev/usb/ and https://www.beyondlogic.org/usbnutshell/usb1.shtml to start respectively with WebUSB and USB.
For your specific questions, device.open() and device.claimInterface() promises will fail if those actions can't be performed.

How do you detect 3G vs. Wifi connection on mobile safari?

I am specifically asking about javascript on a mobile webpage, not an objective-c application. Is there something like Apple Reachability for javascript so I can tell when Edge, 3G or Wifi connection is made or changed?
Not unless browsers start giving this information away through the DOM which, currently, they don't. There is a navigator javascript objects which holds many things but not what you're looking for. I've also read in the news recently that some cellular carrier was adding cookies to HTTP requests made on their phones. They were found to be adding customer IDs to cookies (huge security breach!!).
Mobile Safari does add some new DOM additions but not what you're asking for.
Short of these options, you can't. Layers of the Internet Protocol are meant to encapsulate & hide the details of the bottom layers. You can't detect Edge, 3G or Wifi any more than you can detect cable, DSL or finer optics.
Finally, even if you could get this information, it wouldn't do you any good unless you had details of every single node in your TCP connection. For example, I could have the following setup :
iPad ---WiFi----> iPhone's Hotspot ---3G---> Carrier ---unknown--->>>
Addendum
In 2012-2013, the W3C was fleshing out The Network Information API which was aimed at providing "an interface for web applications to access the underlying connection information of the device". At the time, the API stipulated that an "estimated" bandwidth for the browser would be obtainable via navigator.connection.bandwidth. As of April 2014, that work has since been discontinued!!
Update 1: As of 20th October 2015, work continues on this API. You can find the latest Editor's drafts for the Network Information API on the W3C's github pages.
Update 2: In June 2020, Apple declined to implement the Network Information API in Safari due to privacy concerns
Although you cannot use data from a browser to detect if the user is on Wifi or a cellular connection - capturing the user's IP may be one way to differentiate between a Wifi and Cellular connection.
In this article about how cellular impacts your IP address (http://classroom.synonym.com/wifi-change-ip-17586.html) it states the following:
While on Wi-Fi, your device's public IP will match all other computers on your network, and your router assigns a local IP. While using a cellular connection, your cell carrier assigns a public IP. Connecting to the cellular Internet does not use a router, so your device won't have a local IP.
IF ip = localIp, then connection = wifiConnection
IF ip = publicIp, then connection = cellularConnection
Here's a screenshot of my IP when I'm on cellular:
Here's a screenshot of my IP (right after turning off cellular) on Wifi:
This could be one answer to the problem without browser help.
At the moment this limitation has improved, but there are still restrictions with the Network Information API supported in the different browsers ( mobile or not ), https://caniuse.com/#search=network
If this helps you, In our case as our specific mobile application is hybrid and developed using Ionic, we have been able to do it on either iOs or Android using this cordova plugin: https://github.com/apache/cordova-plugin-network-information that works like a charm.

Can a mobile Web app obtain Android device identification information?

At a recent event a developer working for one of the top US mobile operators told me that "an HTML5 Web app can obtain unique device identification information on any Android device it runs in." The comment was about Web-native apps in cell phones, not HTML5 running inside a WebView in a Java app.
How can this be done? Unfortunately, I don't have access to the developer to ask.
At a minimum, I would consider any of the following to be uniquely identifying the device: ANDROID_ID, phone number and IMEI for GSM or MEID/ESN for CDMA. There may be other types of identifiers I'm not familiar with.
You can't get those details from the browser. I'd be concerned if you could!
You could use cookies to uniquely identify a user, but there's no way to personally identify them. Even then cookies can be cleared.

Categories