Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Socket/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
addTransactionCapability,
aesEncryptCTR,
bindWaitForConnectionUpdate,
buildPairingQRData,
bytesToCrockford,
configureSuccessfulPairing,
Curve,
Expand All @@ -28,6 +29,7 @@
generateMdTagPrefix,
generateRegistrationNode,
getCodeFromWSError,
getCompanionPlatformId,
getErrorCodeFromStreamError,
getNextPreKeysNode,
makeEventBuffer,
Expand All @@ -36,7 +38,6 @@
signedKeyPair,
xmppSignedPreKey
} from '../Utils'
import { getPlatformId } from '../Utils/browser-utils'
import {
assertNodeErrorFree,
type BinaryNode,
Expand Down Expand Up @@ -206,7 +207,7 @@

const msgId = node.attrs.id

const result = await promiseTimeout<any>(timeoutMs, async (resolve, reject) => {

Check warning on line 210 in src/Socket/socket.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
const result = waitForMessage(msgId, timeoutMs).catch(reject)
sendNode(node)
.then(async () => resolve(await result))
Expand Down Expand Up @@ -790,7 +791,7 @@
{
tag: 'companion_platform_id',
attrs: {},
content: getPlatformId(browser[1])
content: getCompanionPlatformId(browser)
},
{
tag: 'companion_platform_display',
Expand Down Expand Up @@ -840,7 +841,7 @@
ws.on('open', async () => {
try {
await validateConnection()
} catch (err: any) {

Check warning on line 844 in src/Socket/socket.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
logger.error({ err }, 'error in validating connection')
void end(err)
}
Expand Down Expand Up @@ -883,7 +884,7 @@
}

const ref = (refNode.content as Buffer).toString('utf-8')
const qr = [ref, noiseKeyB64, identityKeyB64, advB64].join(',')
const qr = buildPairingQRData(ref, noiseKeyB64, identityKeyB64, advB64, browser)

ev.emit('connection.update', { qr })

Expand Down Expand Up @@ -911,7 +912,7 @@

await sendNode(reply)
void sendUnifiedSession()
} catch (error: any) {

Check warning on line 915 in src/Socket/socket.ts

View workflow job for this annotation

GitHub Actions / check-lint

Unexpected any. Specify a different type
logger.info({ trace: error.stack }, 'error in pairing')
void end(error)
}
Expand Down
45 changes: 45 additions & 0 deletions src/Utils/companion-reg-client-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { WABrowserDescription } from '../Types'

export enum CompanionWebClientType {
UNKNOWN = 0,
CHROME = 1,
EDGE = 2,
FIREFOX = 3,
IE = 4,
OPERA = 5,
SAFARI = 6,
ELECTRON = 7,
UWP = 8,
OTHER_WEB_CLIENT = 9
}

const BROWSER_TO_COMPANION_WEB_CLIENT: Record<string, CompanionWebClientType> = {
Chrome: CompanionWebClientType.CHROME,
Edge: CompanionWebClientType.EDGE,
Firefox: CompanionWebClientType.FIREFOX,
IE: CompanionWebClientType.IE,
Opera: CompanionWebClientType.OPERA,
Safari: CompanionWebClientType.SAFARI
}

export const getCompanionWebClientType = ([os, browserName]: WABrowserDescription): CompanionWebClientType => {
if (browserName === 'Desktop') {
return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON
}

return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT
}

export const getCompanionPlatformId = (browser: WABrowserDescription): string => {
return getCompanionWebClientType(browser).toString()
}

export const buildPairingQRData = (
ref: string,
noiseKeyB64: string,
identityKeyB64: string,
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

}
1 change: 1 addition & 0 deletions src/Utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export * from './event-buffer'
export * from './process-message'
export * from './message-retry-manager'
export * from './browser-utils'
export * from './companion-reg-client-utils'
export * from './identity-change-handler'
export * from './stanza-ack'
Loading