Skip to content

Conversation

@haslinghuis
Copy link
Member

@haslinghuis haslinghuis commented Jun 10, 2025

Summary by CodeRabbit

  • New Features
    • The send functionality now supports an optional callback, providing immediate feedback on the success or failure of sending data via WebSocket and WebBluetooth.

@haslinghuis haslinghuis added this to the 11.0 milestone Jun 10, 2025
@haslinghuis haslinghuis self-assigned this Jun 10, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

Walkthrough

The send methods in both Websocket and WebBluetooth classes were updated to accept an optional callback cb. After attempting to send data, these methods invoke the callback with success or error details and updated bytesSent. The methods still return their respective results synchronously.

Changes

File(s) Change Summary
src/js/protocols/WebSocket.js Modified Websocket.send to invoke optional callback cb with error and bytesSent info after sending data.
src/js/protocols/WebBluetooth.js Updated WebBluetooth.send signature to accept optional cb; callback invoked with error/success and bytesSent; restructured send logic to await previous writes and handle errors.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Websocket

    Caller->>Websocket: send(data, cb)
    Websocket->>Websocket: Attempt to send data
    alt Send successful
        Websocket->>Websocket: Update bytesSent
    else Send failed
        Websocket->>Websocket: Catch error
    end
    alt cb is provided
        Websocket->>Caller: Invoke cb(error or null, bytesSent)
    end
    Websocket-->>Caller: Return { bytesSent }
Loading
sequenceDiagram
    participant Caller
    participant WebBluetooth

    Caller->>WebBluetooth: send(data, cb)
    alt No writable characteristic
        WebBluetooth->>Caller: Invoke cb(error, 0)
        WebBluetooth-->>Caller: Return { bytesSent: 0, resultCode }
    else Writable characteristic available
        WebBluetooth->>WebBluetooth: Await lastWrite
        WebBluetooth->>WebBluetooth: Write data
        WebBluetooth->>WebBluetooth: Update lastWrite and bytesSent
        alt Write successful
            WebBluetooth->>Caller: Invoke cb(null, bytesSent)
        else Write failed
            WebBluetooth->>Caller: Invoke cb(error, 0)
        end
        WebBluetooth-->>Caller: Return { bytesSent, resultCode }
    end
Loading

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 242240c and 5a5b2ce.

📒 Files selected for processing (2)
  • src/js/protocols/WebBluetooth.js (1 hunks)
  • src/js/protocols/WebSocket.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/js/protocols/WebBluetooth.js
  • src/js/protocols/WebSocket.js
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@haslinghuis haslinghuis moved this to App in 2025.12.0 Jun 10, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dafacbd and 7b72504.

📒 Files selected for processing (1)
  • src/js/protocols/WebSocket.js (1 hunks)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 472b210 and beb4724.

📒 Files selected for processing (1)
  • src/js/protocols/WebBluetooth.js (1 hunks)
🔇 Additional comments (2)
src/js/protocols/WebBluetooth.js (2)

346-346: LGTM! Callback parameter added correctly.

The method signature properly adds the optional callback parameter, aligning with the PR objective.


348-356: LGTM! Proper error handling for unavailable write characteristic.

The early return case correctly invokes the callback with an appropriate error object and logs the error for debugging.

@haslinghuis haslinghuis changed the title Add missing callback Fix missing callback Jun 11, 2025
Copy link
Member

@nerdCopter nerdCopter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • approving untested

@VitroidFPV
Copy link
Member

VitroidFPV commented Jun 14, 2025

Stuck at Waitng for data... when using Bluetooth on SPEEDYBEEF405MINI, master branch works as expected

@sonarqubecloud
Copy link

@github-actions
Copy link
Contributor

Preview URL: https://5a5b2ce4.betaflight-configurator.pages.dev

@haslinghuis
Copy link
Member Author

haslinghuis commented Jun 14, 2025

Have rebased and works here 😕

Web Bluetooth is experimental on this platform. See https://github.com/WebBluetoothCG/web-bluetooth/blob/main/implementation-status.md
main-CoWdMYL5.js:3863 [PORTHANDLER] Requesting permission for webbluetooth device...
main-CoWdMYL5.js:3863 [PORTHANDLER] webbluetooth device added: Object
DarkTheme-CNJ5iv5u.js:468 [BLUETOOTH] User selected Bluetooth device from permissions: bluetooth_1
main-CoWdMYL5.js:3863 [PORTHANDLER] Permission granted for webbluetooth device: Object
main-CoWdMYL5.js:3863 [PORTHANDLER] Automatically selected device is 'bluetooth_1' - suggested: Object
main-CoWdMYL5.js:3863 [PORTHANDLER] Found bluetooth port(s) Array(1)
main-CoWdMYL5.js:3863 [PORTHANDLER] Automatically selected device is 'bluetooth_1' - suggested: Object
main-CoWdMYL5.js:3896 [SERIAL-BACKEND] Connecting to: bluetooth_1
DarkTheme-CNJ5iv5u.js:468 [SERIAL] Using bluetooth protocol (based on port path: bluetooth_1)
DarkTheme-CNJ5iv5u.js:468 [SERIAL] Protocol switched successfully to: WebBluetooth
DarkTheme-CNJ5iv5u.js:468 [SERIAL] Connecting to port: bluetooth_1 with options: Object
DarkTheme-CNJ5iv5u.js:468 [BLUETOOTH] Opening connection with ID: bluetooth_1, Baud: 115200
DarkTheme-CNJ5iv5u.js:468 [BLUETOOTH] Connecting to GATT Server
DarkTheme-CNJ5iv5u.js:468 [BLUETOOTH] Get primary services
DarkTheme-CNJ5iv5u.js:468 [BLUETOOTH] Connected to service: 0000abf0-0000-1000-8000-00805f9b34fb
DarkTheme-CNJ5iv5u.js:468 [BLUETOOTH] Connection opened with ID: undefined, Baud: 115200
main-CoWdMYL5.js:3896 [SERIAL-BACKEND] Requesting configuration data

@VitroidFPV
Copy link
Member

I'm testing on mobile, don't have Bluetooth on my desktop... I'll have to set up remote debugging again tomorrow

@haslinghuis
Copy link
Member Author

Tested SPBE F405MINI and F7V3

@haslinghuis haslinghuis merged commit 01503dc into betaflight:master Jun 15, 2025
8 checks passed
@haslinghuis haslinghuis deleted the fix-callback branch June 15, 2025 21:01
@github-project-automation github-project-automation bot moved this from App to Done in 2025.12.0 Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants