mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat(add-routing-info): initial commit (#773)
This commit is contained in:
@@ -76,6 +76,10 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
url = new URL(`tcp://${MOBILE_ENDPOINT}:${MOBILE_PORT}`)
|
||||
}
|
||||
|
||||
if(!config.mobile && url.protocol === 'wss' && authState?.creds?.routingInfo) {
|
||||
url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'))
|
||||
}
|
||||
|
||||
const ws = config.socket ? config.socket : config.mobile ? new MobileSocketClient(url, config) : new WebSocketClient(url, config)
|
||||
|
||||
ws.connect()
|
||||
@@ -88,7 +92,8 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
keyPair: ephemeralKeyPair,
|
||||
NOISE_HEADER: config.mobile ? MOBILE_NOISE_HEADER : NOISE_WA_HEADER,
|
||||
mobile: config.mobile,
|
||||
logger
|
||||
logger,
|
||||
routingInfo: authState?.creds?.routingInfo
|
||||
})
|
||||
|
||||
const { creds } = authState
|
||||
@@ -671,6 +676,14 @@ export const makeSocket = (config: SocketConfig) => {
|
||||
end(new Boom('Multi-device beta not joined', { statusCode: DisconnectReason.multideviceMismatch }))
|
||||
})
|
||||
|
||||
ws.on('CB:ib,,edge_routing', (node: BinaryNode) => {
|
||||
const edgeRoutingNode = getBinaryNodeChild(node, 'edge_routing')
|
||||
const routingInfo = getBinaryNodeChild(edgeRoutingNode, 'routing_info')
|
||||
if(routingInfo?.content) {
|
||||
authState.creds.routingInfo = Buffer.from(routingInfo?.content as Uint8Array)
|
||||
}
|
||||
})
|
||||
|
||||
let didStartBuffer = false
|
||||
process.nextTick(() => {
|
||||
if(creds.me?.id) {
|
||||
|
||||
@@ -69,6 +69,7 @@ export type AuthenticationCreds = SignalCreds & {
|
||||
registration: RegistrationOptions
|
||||
pairingCode: string | undefined
|
||||
lastPropHash: string | undefined
|
||||
routingInfo: Buffer | undefined
|
||||
}
|
||||
|
||||
export type SignalDataTypeMap = {
|
||||
|
||||
@@ -217,5 +217,6 @@ export const initAuthCreds = (): AuthenticationCreds => {
|
||||
registration: {} as never,
|
||||
pairingCode: undefined,
|
||||
lastPropHash: undefined,
|
||||
routingInfo: undefined,
|
||||
}
|
||||
}
|
||||
@@ -18,11 +18,13 @@ export const makeNoiseHandler = ({
|
||||
NOISE_HEADER,
|
||||
mobile,
|
||||
logger,
|
||||
routingInfo
|
||||
}: {
|
||||
keyPair: KeyPair
|
||||
NOISE_HEADER: Uint8Array
|
||||
mobile: boolean
|
||||
logger: Logger
|
||||
routingInfo?: Buffer | undefined
|
||||
}) => {
|
||||
logger = logger.child({ class: 'ns' })
|
||||
|
||||
@@ -133,11 +135,25 @@ export const makeNoiseHandler = ({
|
||||
data = encrypt(data)
|
||||
}
|
||||
|
||||
const introSize = sentIntro ? 0 : NOISE_HEADER.length
|
||||
let header: Buffer
|
||||
|
||||
if(routingInfo) {
|
||||
header = Buffer.alloc(7)
|
||||
header.write('ED', 0, 'utf8')
|
||||
header.writeUint8(0, 2)
|
||||
header.writeUint8(1, 3)
|
||||
header.writeUint8(routingInfo.byteLength >> 16, 4)
|
||||
header.writeUint16BE(routingInfo.byteLength & 65535, 5)
|
||||
header = Buffer.concat([header, routingInfo, NOISE_HEADER])
|
||||
} else {
|
||||
header = Buffer.from(NOISE_HEADER)
|
||||
}
|
||||
|
||||
const introSize = sentIntro ? 0 : header.length
|
||||
const frame = Buffer.alloc(introSize + 3 + data.byteLength)
|
||||
|
||||
if(!sentIntro) {
|
||||
frame.set(NOISE_HEADER)
|
||||
frame.set(header)
|
||||
sentIntro = true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user