mobile: deprecation.

This commit is contained in:
Rajeh Taher
2024-10-14 03:39:46 +03:00
parent 647f8d767f
commit 61a0ff3178
18 changed files with 47 additions and 533 deletions

View File

@@ -8,9 +8,6 @@ import {
DEF_TAG_PREFIX,
INITIAL_PREKEY_COUNT,
MIN_PREKEY_COUNT,
MOBILE_ENDPOINT,
MOBILE_NOISE_HEADER,
MOBILE_PORT,
NOISE_WA_HEADER
} from '../Defaults'
import { DisconnectReason, SocketConfig } from '../Types'
@@ -24,7 +21,6 @@ import {
derivePairingCodeKey,
generateLoginNode,
generateMdTagPrefix,
generateMobileNode,
generateRegistrationNode,
getCodeFromWSError,
getErrorCodeFromStreamError,
@@ -45,7 +41,7 @@ import {
jidEncode,
S_WHATSAPP_NET
} from '../WABinary'
import { MobileSocketClient, WebSocketClient } from './Client'
import { WebSocketClient } from './Client'
/**
* Connects to WA servers and performs:
@@ -69,19 +65,18 @@ export const makeSocket = (config: SocketConfig) => {
makeSignalRepository,
} = config
let url = typeof waWebSocketUrl === 'string' ? new URL(waWebSocketUrl) : waWebSocketUrl
const url = typeof waWebSocketUrl === 'string' ? new URL(waWebSocketUrl) : waWebSocketUrl
config.mobile = config.mobile || url.protocol === 'tcp:'
if(config.mobile && url.protocol !== 'tcp:') {
url = new URL(`tcp://${MOBILE_ENDPOINT}:${MOBILE_PORT}`)
if(config.mobile || url.protocol === 'tcp:') {
throw new Boom('Mobile API is not supported anymore', { statusCode: DisconnectReason.loggedOut })
}
if(!config.mobile && url.protocol === 'wss' && authState?.creds?.routingInfo) {
if(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)
const ws = config.socket ? config.socket : new WebSocketClient(url, config)
ws.connect()
@@ -91,8 +86,7 @@ export const makeSocket = (config: SocketConfig) => {
/** WA noise protocol wrapper */
const noise = makeNoiseHandler({
keyPair: ephemeralKeyPair,
NOISE_HEADER: config.mobile ? MOBILE_NOISE_HEADER : NOISE_WA_HEADER,
mobile: config.mobile,
NOISE_HEADER: NOISE_WA_HEADER,
logger,
routingInfo: authState?.creds?.routingInfo
})
@@ -247,9 +241,7 @@ export const makeSocket = (config: SocketConfig) => {
const keyEnc = noise.processHandshake(handshake, creds.noiseKey)
let node: proto.IClientPayload
if(config.mobile) {
node = generateMobileNode(config)
} else if(!creds.me) {
if(!creds.me) {
node = generateRegistrationNode(creds, config)
logger.info({ node }, 'not logged in, attempting registration...')
} else {