-
Notifications
You must be signed in to change notification settings - Fork 22.6k
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
Add docs on SerialPort.connected and Bluetooth port event support #37002
Add docs on SerialPort.connected and Bluetooth port event support #37002
Conversation
Preview URLs
(comment last updated: 2024-11-29 12:50:58) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nits
The following snippet invokes {{domxref("Serial.requestPort()")}} when the user presses a {{htmlelement("button")}}, prompting them to choose a serial port to connect to, then logs a message to the console reporting the connection status: | ||
|
||
```js | ||
requestPortButton.onclick = async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our docs recommend addEventListener
: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#other_event_listener_mechanisms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call; I've changed them to use addEventListener()
.
|
||
```js | ||
navigator.serial.onconnect = ({ target: port }) => { | ||
console.log(`onconnect event fired. Connected: ${port.connected}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log(`onconnect event fired. Connected: ${port.connected}`); | |
console.log(`connect event fired. Connected: ${port.connected}`); |
...etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated both instances that were dubious.
When a wireless device goes out of range of the host, any wireless serial port opened by a web app automatically closes, even though it stays logically connected. In such cases, the web app could attempt to reopen the port using {{domxref("SerialPort.open()")}}. | ||
|
||
However, if the wireless device was intentionally disconnected (for example, if the user chose to disconnect it using the operating system control panel), the web app should refrain from reopening the port to prevent reconnecting to the wireless device. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really the key message about this PR AIUI. It would be good to have this in the description of "logically connected" instead of buried in an example down the page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense. I've moved this example and description up to a "Description" section up-top.
// The port is logically connected | ||
// automatically try to connect to the Bluetooth device |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are connected, why are we trying to connect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, that should have been "automatically try to reopen the port" — updated. It should make more sense now.
…mills/content into web-serial-connected-property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks Chris, I'm happy with this. I'm leaving this open in case @beaufortfrancois has more comments but happy for you to merge when you're ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Chrome 130 supports the
SerialPort.connected
attribute, a boolean that reports whether a serial port is logically connected.Another part of this work item is that the
SerialPort
connect
anddisconnect
events were previously only fired by physical/wired serial ports. With this change, wireless Bluetooth RFCOMM serial ports also fire these events when they connect and disconnect.This PR updates the docs to add a
connected
reference page and update the event pages to cover the Bluetooth support.Motivation
Additional details
Related issues and pull requests
See https://chromestatus.com/feature/5118102654418944.