pwshub.com

Bluetooth RFCOMM updates in Web Serial

Stay organized with collections Save and categorize content based on your preferences.

François Beaufort

The Web Serial API supports communicating with RFCOMM services on paired Bluetooth Classic devices from Chrome 117 on desktop. For example, this allows wireless earbuds to use RFCOMM to manage audio settings and firmware updates. Check out Serial over Bluetooth on the web to learn more.

From Chrome 130 for desktop, an improvement to the Web Serial API lets web apps detect when a Bluetooth RFCOMM serial port is available, without having to open the port. This prevents unnecessary reconnections when the wireless device was intentionally disconnected.

When a wireless device goes out of range of the host, any wireless serial port opened by a web app automatically closes. In such cases, the web app may attempt to reopen the port with the SerialPort open() method. However, if the wireless device was intentionally disconnected (for example, by the user from the operating system control panel), the web app should refrain from reopening the port to prevent reconnecting to the wireless device.

By exposing the logical connection state of the wireless device hosting the wireless serial port through a new boolean SerialPort connected attribute, web apps can now distinguish these cases, and only reconnect if the disconnection was unintentional.

The SerialPort connected attribute is true for wireless serial ports if the wireless device hosting the port has any active connections to the system. For wired serial ports, it is true if the port is physically attached to the system.

The following snippet shows you how to check which devices are available and potentially connect to them automatically.

const ports = await navigator.serial.getPorts();
for (const port of ports) {
  if (port.connected) {
    // Automatically try to connect to the Bluetooth device.
    await port.open({ baudRate: 9600 });
  } else {
    // Otherwise, when the port is not logically connected:
    // 1. Prompt the user to make sure the Bluetooth device is available.
    // 2. Show a "connect" button to try opening the port.
  }
}

Previously, only wired serial ports dispatched connect and disconnect events. Bluetooth RFCOMM serial ports now dispatch these events when the port becomes logically connected or disconnected.

Demo

SerialPort connected demo.

Resources

Acknowledgments

Thanks to Jack Hsieh and Reilly Grant for their reviews.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-09-16 UTC.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }] {"lastModified": "Last updated 2024-09-16 UTC."}

Source: developer.chrome.com

Related stories
1 month ago - If you are not connecting your machine via cable, it’s possible that your Cricut Maker machine won’t connect to your Mac via Bluetooth. If the Bluetooth connection suddenly drops and won’t reconnect, it happens more often than you might...
1 week ago - Looking for a powerful new Linux laptop? The new KDE Slimbook VI may very well appeal. Unveiled at Akademy 2024, KDE’s annual community get-together, the KDE Slimbook VI marks a major refresh from earlier models in the KDE Slimbook line....
1 month ago - And we’re go – Linux Mint 22 ‘Wilma’ has been officially released and made available to download. This major update is the first version to be based on the latest Ubuntu 24.04 LTS This major update is built on Ubuntu 24.04 LTS and sees...
1 month ago - Ever wished you could use your Raspberry Pi 5, Android smartphone, or mini PC as a laptop? The CrowView Note, which hit Kickstarter last week, allows you to do precisely that. From a cursory glance Elecrow’s CrowView Note looks a lot like...
1 week ago - There are so many resources out there about passkeys and each vendor has its own implementation of the standard. Let’s answer some of your frequently asked questions about passkeys at Auth0!
Other stories
1 hour ago - Ubuntu 24.10 ‘Oracular Oriole’ is released on October 13th, and as you’d expect from a new version of Ubuntu, it’s packed with new features. As a short-term release, Ubuntu 24.10 gets 9 months of ongoing updates, security patches, and...
3 hours ago - Did you know that CSS can play a significant role in web accessibility? While CSS primarily handles the visual presentation of a webpage, when you use it properly it can enhance the user’s experience and improve accessibility. In this...
4 hours ago - Design thinking workshops are your key to turning big problems into clear solutions. In this blog, I share how to run them efficiently and keep your team aligned. The post How to run a design thinking workshop appeared first on LogRocket...
4 hours ago - New memory-optimized X8g instances offer up to 3 TiB DDR5 memory, 192 vCPUs, and 50 Gbps network bandwidth, designed for memory-intensive workloads like databases, analytics, and caching with unparalleled price/performance and efficiency.
4 hours ago - Gain indispensable data engineering expertise through a hands-on specialization by DeepLearning.AI and AWS. This professional certificate covers ingestion, storage, querying, modeling, and more.