User Agent string in fetch requests

This commit is contained in:
Adhiraj
2020-07-27 22:48:40 +05:30
parent efb66d66f6
commit 18cffdaa17
7 changed files with 24 additions and 9 deletions

View File

@@ -59,8 +59,9 @@ export default class WAConnectionBase {
protected pendingRequests: (() => void)[] = []
protected reconnectLoop: () => Promise<void>
protected referenceDate = new Date () // used for generating tags
protected userAgentString: string
constructor () {
this.userAgentString = Utils.userAgentString (this.browserDescription[1])
this.registerCallback (['Cmd', 'type:disconnect'], json => this.unexpectedDisconnect(json[1].kind))
}
async unexpectedDisconnect (error: string) {

View File

@@ -3,6 +3,7 @@ import HKDF from 'futoin-hkdf'
import Decoder from '../Binary/Decoder'
import {platform, release} from 'os'
import { BaileysError } from './Constants'
import UserAgent from 'user-agents'
const platformMap = {
'aix': 'AIX',
@@ -17,6 +18,10 @@ export const Browsers = {
/** The appropriate browser based on your OS & release */
appropriate: browser => [ platformMap [platform()] || 'Ubuntu', browser, release() ] as [string, string, string]
}
export function userAgentString (browser) {
const agent = new UserAgent (new RegExp(browser))
return agent.toString ()
}
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
export function aesDecrypt(buffer: Buffer, key: Buffer) {
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16))