Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Scratch-Link with Web-Bluetooth API #194

Open
nathanrona opened this issue Apr 14, 2021 · 13 comments
Open

Replace Scratch-Link with Web-Bluetooth API #194

nathanrona opened this issue Apr 14, 2021 · 13 comments
Labels

Comments

@nathanrona
Copy link

nathanrona commented Apr 14, 2021

With the Web-bluetooth API (https://web.dev/bluetooth/)the need to install Scratch-link helper program on computer in order to access bluetooth interface. I.e. the use of Scratch-link can be replaced with using the Bluetooth API to directly connect to Bluetooth. The API is currently supported in Chrome (with derivatives such as Edge and Brave), Opera and Samsung browsers.

There are several advantages:

  1. No need for download and install.
  2. Multi-platform. While Shratch-link supports only windows and macOs, this will support any OS with browser supporting API (i.e. also Linux, Unix and Android)
  3. Much simpler.

/Nathan

@nathanrona nathanrona changed the title Replace scrach-link with Web-Bluetooth API Replace Scratch-Link with Web-Bluetooth API Apr 14, 2021
@apple502j
Copy link

WebBluetooth is not supported on any of the four main browsers that Scratch support (Edge 16, Chrome 63, Firefox 57, Safari 11) - and three of the four doesn't have it on latest version either. (note that we still fully support Legacy Edge)

Opera, Vivaldi, and Samsung Browser are not supported.

@nathanrona
Copy link
Author

nathanrona commented Apr 14, 2021 via email

@nathanrona
Copy link
Author

nathanrona commented Apr 14, 2021 via email

@notAPanda
Copy link

I have recently bought Lego Boost. Scratch Link does not work (unable to connect) on macOS. I managed to connect using Web Bluetooth API and everything works... The problem is... my son is not able to use it because it's javascript (not scratch).

In my opinion... If scratch-link does not work for me... it's better to use something universal like Web Bluetooth.

@arivero
Copy link

arivero commented Jan 24, 2022

Hi notAPanda, could you link a gist of your code?

@nathanrona
Copy link
Author

@arivero
Copy link

arivero commented Jan 24, 2022

thanks!

An argument against the idea is that one wants it to work not only in the browser but also in the scratch offline app. And Scratch-Link is expected to link other devices not only BLE... So perhaps the point could be to try to change the BLE module in Scratch Link to work via the web bluetooth api?? Not sure, just thinking aloud.

@nathanrona
Copy link
Author

nathanrona commented Jan 25, 2022

@arivero , don't understand that argument. Given that scratch-desktop is based on Chromium, which include the API, why should web-ble API not work for scratch-desktop?

@arivero
Copy link

arivero commented Jan 25, 2022

Well, you are correct that desktop and web is the same. In fact now that I have compiled scratch-link I find easy to connect from chrome than from the desktop app, because both of them reject the self-signed certificate, but it is easier to tell chrome to proceed.

My main argument was that all device management, not only ble, was supposed to be delegated in an external app, namely this one, scratch link. In theory this is more flexible as allows for usb and wifi connected robots. In practice, one must keep updated versions of everything.

@nathanrona
Copy link
Author

There is a web-API for usb as well https://developer.mozilla.org/en-US/docs/Web/API/USB. As for wifi, no need for browser API (or scratch link) as it is IP communication to begin with.

@nathanrona
Copy link
Author

Basically what is needed to adapt to web-ble is to rewrite https://github.com/LLK/scratch-vm/blob/5aa83b912ff09b4f2d57a31fe37fcbb4c43fab43/src/io/ble.js#L3 to use the the web-ble api instead of scratch-link web-socket. I've forked and try to see what I can do.

@arivero
Copy link

arivero commented Jan 25, 2022 via email

@nathanrona
Copy link
Author

Not the extension but the ble io-class of the core (also bt class). Extensions such as microbit and lego uses this class methods to establish link, so if you rewrite it there is no need to modify the extensions themself.
If you look in io liberary you see that other IO classes such as mouse and keyboard input are using native functions so it is only natural that BLE and BT should as well.
As for Mac/iPad, it's a problem that Safari and Webkit don't support web-ble API, for desktop you can still use through Chrome-browser but on iPad that's not a option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants