feat: functional legacy socket

This commit is contained in:
Adhiraj Singh
2021-12-17 20:58:33 +05:30
parent d8b415a075
commit c803e22e8a
15 changed files with 695 additions and 66 deletions

View File

@@ -16,7 +16,7 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
} = config
const ev = new EventEmitter() as LegacyBaileysEventEmitter
let authInfo = initialAuthInfo || newLegacyAuthCreds()
const authInfo = initialAuthInfo || newLegacyAuthCreds()
const state: ConnectionState = {
legacy: {
@@ -73,7 +73,6 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
socket?.end(
new Boom('Logged Out', { statusCode: DisconnectReason.loggedOut })
)
authInfo = undefined
}
/** Waits for the connection to WA to open up */
const waitForConnection = async(waitInfinitely: boolean = false) => {
@@ -221,11 +220,13 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
const {user, auth} = validateNewConnection(response[1], authInfo, curveKeys)// validate the connection
const isNewLogin = user.id !== state.legacy!.user?.id
authInfo = auth
Object.assign(authInfo, auth)
updateEncKeys()
logger.info({ user }, 'logged in')
ev.emit('creds.update', auth)
updateState({
connection: 'open',
legacy: {
@@ -235,7 +236,6 @@ const makeAuthSocket = (config: LegacySocketConfig) => {
isNewLogin,
qr: undefined
})
ev.emit('creds.update', auth)
}
ws.once('open', async() => {
try {