Added offline check for isOnWhatsApp

This commit is contained in:
Adhiraj Singh
2020-11-20 12:50:14 +05:30
parent ba8b8c693a
commit 9f8f244b66
5 changed files with 78 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ import WS from 'ws'
import * as Utils from './Utils'
import Encoder from '../Binary/Encoder'
import Decoder from '../Binary/Decoder'
import fetch from 'node-fetch'
import fetch, { RequestRedirect } from 'node-fetch'
import {
AuthenticationCredentials,
WAUser,
@@ -31,7 +31,7 @@ const logger = pino({ prettyPrint: { levelFirst: true, ignore: 'hostname', trans
export class WAConnection extends EventEmitter {
/** The version of WhatsApp Web we're telling the servers we are */
version: [number, number, number] = [2, 2045, 19]
version: [number, number, number] = [2, 2047, 10]
/** The Browser we're telling the WhatsApp Web servers we are */
browserDescription: [string, string, string] = Utils.Browsers.baileys ('Chrome')
/** Metadata like WhatsApp id, name set on WhatsApp etc. */
@@ -406,10 +406,11 @@ export class WAConnection extends EventEmitter {
/**
* Does a fetch request with the configuration of the connection
*/
protected fetchRequest = (endpoint: string, method: string = 'GET', body?: any, agent?: Agent, headers?: {[k: string]: string}) => (
protected fetchRequest = (endpoint: string, method: string = 'GET', body?: any, agent?: Agent, headers?: {[k: string]: string}, redirect: RequestRedirect = 'follow') => (
fetch(endpoint, {
method,
body,
redirect,
headers: { Origin: DEFAULT_ORIGIN, ...(headers || {}) },
agent: agent || this.connectOptions.fetchAgent
})