I am developing a basic web app interfacing the Nordic BLE devkit. I am new to javascript development and came across a rather common but a weird problem for me while testing my app. Basically, I have 2 html pages and a common javascript file. First page finds the nearby BLE devices and connects with it and then stores it's characteristics and services which are needed for the communication. (Processing done in the javascript file) After a button press on the first html the app runs location.replace("path for second html") and switches the activity to the second html file. Here I noticed that after transferring to the second page the devkit is disconnected. I have few buttons on the second page which when pressed invokes routines in the javascript file. Now since the device is disconnected the characteristics and the services read earlier were lost and the app crashes.
I know this is a typical binding problem but I am quite not familiar with the exact javascript concepts that I need to be looking at in order to have more information for this issue.
Can anyone help me with this?
It is not currently possible to transfer a BluetoothDevice
or any of the other associated objects to a new page during a navigation (which is what happens when you call location.replace()
). If possible you should keep the user on the same page for the entire time that it is connected to a device.
There is upcoming work on Chromium issue 974879 which will make it possible to keep the permission the user granted your site to connect to the device across navigations and sessions but you will still have to reconnect on each page.