Rhymen / go-whatsapp

WhatsApp Web API
MIT License
2.07k stars 492 forks source link

Only works with the phone screen on and whatsapp open #521

Closed Valdenirmezadri closed 3 years ago

Valdenirmezadri commented 3 years ago

Good morning!

I've done several tests and I can't figure out why, WhatsApp web works well with WhatsApp closed and the mobile screen off, but this lib does not. I can't figure out why.

After a few minutes with the screen off, the lib stops receiving and sending messages, working again if I turn on the screen. When you are going to restore the session for the first time it does not connect, but whatsapp web can

Did anyone manage to resovler this problem, or managed to find out how WhatsApp Web does not have this problem?

Valdenirmezadri commented 3 years ago

I've been debugging for three days, it was just opening the issue that I believe solved the problem

change 5 to 60 on start: whatsapp.NewConn(60 * time.Second)

Saving the Session again on db: newSession, err := w.conn.RestoreWithSession(*session) newSesson to save...

And then in the library I commented on these lines: image We need to create a PR for this change

Now I can log in to whatsapp, and the lib is working, sending and receiving messages even with the phone with the screen off and whatsapp closed

hrizal commented 3 years ago

actually, as long as you haven't signed out, the libs stay connected (wac.IsConnected ())

If you receive the 'asleep' (handlejsonmessage) notification, you will not be able to receive messages until the mobile application is active. and this lib takes care of that very well, messages directly coming in upon awakening from sleep

always use the latest sessions. and it can continue to be used, until you sign out of the mobile device.