Web Bluetooth - Auto Connect to paired device - javascript

Is there a way to auto connect to a paired device with the web Bluetooth ?
So i can get rid of the annoying pop up device selector from google..

As of this moment, I have implemented navigator.bluetooth.getDevices() behind a flag in Chrome. To use the API, the Experimental Web Platform features flag in chrome://flags needs to be enabled. Please follow Issue 577953: bluetooth: Get permitted devices for updates on getDevices().
For reconnecting to a device, I'm also implementing the watchAdvertisements() API to allow apps to receive an Event when system perceives an advertisement packet from device on which this was called on. Please follow Issue 654897: bluetooth: Implement watchAdvertisements() for updates on this API.
These two are part of a bigger project for implementing persistent permissions for Web Bluetooth to allow sites to reconnect to devices that they already had permission to connect to via the device chooser prompt.

Related

Open/Listen to COM-Port client sided on mobile device, is it possible?

So I am using navigator.serial in my reactjs PWA to access the COM-Ports and receive information from a external bluetooth GNSS receiver.
This works perfect on any Windows device but fails on any mobile device that are using android/ios.
I found out that the serial API is not implemented on mobile, is there a workaround to this other than the bluetooth web API`? Any other way to listen to COM-Ports on mobile?

Is it possible to automatically enable bluetooth connection of user's device after launching my web application?

I'm developing a web application (using node js and javascript) that needs to enable bluetooth connection of the device he/she is using before accessing the application. I've been looking for codes regarding to bluetooth enabling in web app but so far, I've only seen answers for android application which is not applicable to the language that I'm using.
When you lauch my web app in a browser, it will ask first a permission to a user to open/enable the bluetooth connection of his/her device then afterwards, she/he can access the application but if she/he cancel, the web app will be closed.
I hope my case is clear. I'm new to the web application.
The enabling of Bluetooth is different depending on the device(iPhone, Android). It is possible to enable Bluetooth when a connection is made, but as I said the enabling differs from device to device. With all respect for you being new to web-developing, I suggest you take a look at more basic web-developing before you ask a question here. Also, this question involves other topics than node.js and Bluetooth. I suggest you add the tags for every platform you want to be compatible with your app.
Good luck!

Remembering the device and reconnecting to it

I'm currently doing a project with the web bluetooth in js and I wonder if there is a way to save the device object and automatically connecting to it instead of choosing the device in the pop up every time.
I've tried saving the device in the local storage and tried to get it in the cookies but they both failed.
There is a way, but it implies enabling some Chrome feature flags on a Chrome 85+
You can have a look at the documentation.
To sum it up, after enabling those two feature-flags in chrome://flags :
#enable-experimental-web-platform-features
#web-bluetooth-new-permissions-backend
The Web Bluetooth spec will be updated with the algorithm for getDevices(). The devices returned by getDevices() may contain devices that are not currently in range and connected. The BluetoothDevice::watchAdvertisements() API can be used to detect when Bluetooth devices come into range of the Bluetooth radio. Then calling BluetoothRemoteGATTServer.connect() should resolve successfully if the device is able to be connected to.

How to initiate a new device pairing using the Chrome web bluetooth API?

Using navigator.bluetooth.requestDevice(), I can access bluetooth devices I've already set up a pair with using native OSX bluetooth pairing, but no previously-unpaired devices appear, even when their attributes match my generic query. Available devices show up in a Chrome modal requesting user consent to pair, but the only device that shows up is the one I've already paired with.
Am I misunderstanding the intended use case here, or is there another way to establish a connection with a nearby (previously unpaired) device from Chrome?
Docs: https://webbluetoothcg.github.io/web-bluetooth/
(See Example 2)
function bluetoothConnect() {
navigator.bluetooth.requestDevice({filters: [{services: ['generic_access']}]})
.then(device => {console.log(`Connected to: ${device.name}`)})
.catch(console.error);
}
First, Mac OS X is not yet fully implemented as we speak. Only discovery and GATT server connect/disconnect are working for now. See the Chrome Implementation status at https://github.com/WebBluetoothCG/web-bluetooth/blob/gh-pages/implementation-status.md. Check out Chrome OS, Linux and Android M (Android Lollipop workaround).
Regarding your specific issue, I believe that generic_access is not broadcasted by a nearby BLE device but is found because you've already paired (cached) this device. If your device is named "foo" for instance, you can go to https://googlechrome.github.io/samples/web-bluetooth/device-info.html and fill "foo" as the Device Name and hit "Get Bluetooth Device Info" button.
I would recommend you give a try to all Web Bluetooth samples at https://googlechrome.github.io/samples/web-bluetooth/index.html as well.
To complement the other answer, please be aware of the Chrome's chrome://bluetooth-internals tab/tool. This tool can not only list available devices and their services (which I don't think you can do with the Web Bluetooth API unless you requested the services in optionalServices or filters/services) and the characteristics of those services.
In the device list, there is a Forget button which becomes active once you connect to the devices GATT server using the Inspect button. This should allow you to full unpair and pair again in cases where you need to test the flow end to end.
Edit: Actually after doing some experimentation around this, the device still remains paired even after using the Forget button. Probably a bug in Chrome, however, the cache of the paired devices seems to be per-profile. This means the real answer is to:
Use the Incognito mode and in there the pairing flow will initiate from the get-go for each new Incognito session.

Dealing with iOS Captive Network Support

So, I'm building a Guest Internet portal for a public hotspot in a hotel. This means the portal is served through a Network Access Gateway (a Nomadix) that redirects all outgoing traffic to the portal page. The portal needs to be able to set cookies on the browser so that Guests can be automatically logged back in after they idle timeout.
The Problem:
iOS4+ and OS X (10.7+) Devices have a feature called Captive Network Support. This feature continuously scans for Wifi SSIDs, connects to them, and curls http://www.apple.com/library/test/success.html to see if the device is connected to the internet. If it doesn't get the Success response, these devices pop open whats called a Captive Network Portal. This portal is not a true version of Safari Mobile and you cannot save cookies on this browser.
I would like an authoritative answer to the following question:
With client-side javascript/markup can I?
A) Save cookies within the Captive Network (popup) browser
B) Prevent the Captive Network browser from popping up in the first place without whitelisting apple.com
This is kinda the wrong site in the StackExchange network for sysadmin stuff; you may wish to try ServerFault. In my experience as a user, there are WiFi portals out there that manage reauthentication without cookies; perhaps ServerFault can help you find such.
That said, there's one possible solution in terms of iOS client-side development: There are CaptiveNetwork APIs which allow a third-party app to inform the system that it's assumed responsibility for authenticating to particular SSIDs, suppressing the web sheet. It's likely not a desirable solution, since it requires your users to install an app, but it's there.
You could try serving "http://www.apple.com/library/test/success.html" locally when ever an iOS device is detected. This will make the CNA not pop up and then the user could login through mobile safari, in which you can save cookies.
iOS 14 has a new API for work with a captive portal. Btw, Android supports it too

Categories

Resources