scratchfoundation / scratch-link

Device interoperability layer for Windows and MacOS
BSD 3-Clause "New" or "Revised" License
102 stars 83 forks source link

Replace Scratch-Link with Web-Bluetooth API #194

Open nathanrona opened 3 years ago

nathanrona commented 3 years ago

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

apple502j commented 3 years ago

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 commented 3 years ago

According to following link, it is supported on Chrome from version 56, Edge 79, opera 43 and Samsung 6.0. https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API

On Wed, Apr 14, 2021 at 7:23 PM apple502j @.***> wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/LLK/scratch-link/issues/194#issuecomment-819647049, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAREYOKP5UB5JYLDTF67S3TTIW6OVANCNFSM4246574A .

nathanrona commented 3 years ago

Given that Chrome alone has a market share around 70%, I think that using web-bt api should at least be offered as alternative to installing Scratch-link (keeping Scratch-link for browsers not supporting bt api).

This will give support for platforms not currently supported, Android, Linux, smart tv (Chrome, opera, Samsung browsers)

My personal experience with Scratch-link has not been great, with it often failing to find Mindstorm EV.

בתאריך יום ד׳, 14 באפר׳ 2021, 20:44, מאת Nathan Rona @.***

:

According to following link, it is supported on Chrome from version 56, Edge 79, opera 43 and Samsung 6.0. https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API

On Wed, Apr 14, 2021 at 7:23 PM apple502j @.***> wrote:

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.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/LLK/scratch-link/issues/194#issuecomment-819647049, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAREYOKP5UB5JYLDTF67S3TTIW6OVANCNFSM4246574A .

notAPanda commented 2 years ago

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 commented 2 years ago

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

nathanrona commented 2 years ago

This is the javascript I used to make a Unity plugin for web-blutooth https://github.com/healthGamez/WebBTCscSensorPlugin--public/blob/main/Assets/HealthGamez/WebBTCycleSpeedCadencePlugin/Plugins/jspre.jspre

arivero commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Ah I see what you mean. I had expected scratch link to act as a central hub for the extensions, but no, it only provides communication. So really the point is to rewrite the ble-based extensions to use web-ble. It makes sense.

Meanwhile, at bricklife it seems they are trying to update scratch-link to work in newer versions on MacOS.

El mar, 25 ene 2022 a las 15:49, Nathan Rona @.***>) escribió:

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.

— Reply to this email directly, view it on GitHub https://github.com/LLK/scratch-link/issues/194#issuecomment-1021260353, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAKRJR4GQX2FYGONEHOJE3UX2Z6PANCNFSM4246574A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

nathanrona commented 2 years ago

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.