Skip to content

feat: add companion registration utilities#2460

Open
jlucaso1 wants to merge 2 commits intomasterfrom
feat-add-browser-to-qr
Open

feat: add companion registration utilities#2460
jlucaso1 wants to merge 2 commits intomasterfrom
feat-add-browser-to-qr

Conversation

@jlucaso1
Copy link
Copy Markdown
Collaborator

@jlucaso1 jlucaso1 commented Apr 1, 2026

backport of tulir/whatsmeow#1110

Summary by CodeRabbit

  • Improvements
    • Improved device pairing: pairing QR codes now include more accurate platform/browser information for better recognition.
    • Broader browser/platform mapping for companions, increasing compatibility across web clients (desktop, mobile, and Electron/UWP scenarios).
    • More reliable pairing payload construction to reduce pairing failures and improve connection reliability.

@whiskeysockets-bot
Copy link
Copy Markdown
Contributor

whiskeysockets-bot commented Apr 1, 2026

Thanks for opening this pull request and contributing to the project!

The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch.

In the meantime, anyone in the community is encouraged to test this pull request and provide feedback.

✅ How to confirm it works

If you’ve tested this PR, please comment below with:

Tested and working ✅

This helps us speed up the review and merge process.

📦 To test this PR locally:

# NPM
npm install @whiskeysockets/baileys@WhiskeySockets/Baileys#feat-add-browser-to-qr

# Yarn (v2+)
yarn add @whiskeysockets/baileys@WhiskeySockets/Baileys#feat-add-browser-to-qr

# PNPM
pnpm add @whiskeysockets/baileys@WhiskeySockets/Baileys#feat-add-browser-to-qr

If you encounter any issues or have feedback, feel free to comment as well.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 21e198ac-9d78-4e47-8947-abce4c09417d

📥 Commits

Reviewing files that changed from the base of the PR and between 2e66776 and 0727f22.

📒 Files selected for processing (1)
  • src/Socket/socket.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Socket/socket.ts

📝 Walkthrough

Walkthrough

Replaces inline companion platform ID and QR string construction in socket pairing with calls to new utility functions getCompanionPlatformId and buildPairingQRData from a newly added companion-reg-client-utils module that also defines companion web client enum/mapping.

Changes

Cohort / File(s) Summary
Socket pairing updates
src/Socket/socket.ts
Removed direct use of getPlatformId(browser[1]); now uses getCompanionPlatformId(browser) and buildPairingQRData(..., browser) when constructing pairing QR payload and companion_platform_id.
Companion registration utilities
src/Utils/companion-reg-client-utils.ts
Added new module defining CompanionWebClientType enum, browser-name → web-client-type mapping, getCompanionWebClientType, getCompanionPlatformId, and buildPairingQRData which includes browser-derived platform id in QR payload.
Utils exports
src/Utils/index.ts
Re-exported the new companion registration utilities (export * from './companion-reg-client-utils').

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through code to tidy the trail,
Moved QR bits into a neat new tale,
Browsers now sorted in enum delight,
Pairing strings bounce clean and light,
A rabbit's patch — compact and hale! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately reflects the main changes: new companion registration utilities are added to support platform identification and QR data construction during pairing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-add-browser-to-qr

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Socket/socket.ts`:
- Around line 24-31: The named imports from "../Utils" in socket.ts are not
alphabetically sorted causing simple-import-sort/imports to fail; reorder the
specifiers (e.g., buildPairingQRData, configureSuccessfulPairing, Curve,
derivePairingCodeKey, generateLoginNode, generateMdTagPrefix,
generateRegistrationNode, getCompanionPlatformId) into proper alphabetical order
within the import statement so the import list is sorted by identifier name.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d972b7b9-334c-4cca-8ee0-ccd19e52b8d1

📥 Commits

Reviewing files that changed from the base of the PR and between 8e5093c and 2e66776.

📒 Files selected for processing (3)
  • src/Socket/socket.ts
  • src/Utils/companion-reg-client-utils.ts
  • src/Utils/index.ts

Comment thread src/Socket/socket.ts Outdated
advB64: string,
browser: WABrowserDescription
): string => {
return [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',')
return ['https://wa.me/settings/linked_devices#', ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',')

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think this has a condition in wa web sources. WAWebNativeCameraQRLinkedDeviceUtils.isNativeCameraQRLinkedDeviceTest. I want to dig more on this to make sure always include this string

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Appears to be a experimental flag 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

but its always present

@github-actions
Copy link
Copy Markdown
Contributor

This PR is stale because it has been open for 14 days with no activity. Remove the stale label or comment or this will be closed in 14 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants