Ping again if stream goes to sleep soon after connection
This commit is contained in:
parent
01101c1272
commit
4b3c411f2f
17
user.go
17
user.go
@ -62,6 +62,7 @@ type User struct {
|
|||||||
|
|
||||||
cleanDisconnection bool
|
cleanDisconnection bool
|
||||||
batteryWarningsSent int
|
batteryWarningsSent int
|
||||||
|
lastReconnection int64
|
||||||
|
|
||||||
chatListReceived chan struct{}
|
chatListReceived chan struct{}
|
||||||
syncPortalsDone chan struct{}
|
syncPortalsDone chan struct{}
|
||||||
@ -480,6 +481,7 @@ func (user *User) postConnPing() bool {
|
|||||||
|
|
||||||
func (user *User) intPostLogin() {
|
func (user *User) intPostLogin() {
|
||||||
defer user.syncWait.Done()
|
defer user.syncWait.Done()
|
||||||
|
user.lastReconnection = time.Now().Unix()
|
||||||
user.createCommunity()
|
user.createCommunity()
|
||||||
user.tryAutomaticDoublePuppeting()
|
user.tryAutomaticDoublePuppeting()
|
||||||
|
|
||||||
@ -502,6 +504,21 @@ func (user *User) intPostLogin() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (user *User) HandleStreamEvent(evt whatsappExt.StreamEvent) {
|
||||||
|
if evt.Type == whatsappExt.StreamSleep {
|
||||||
|
if user.lastReconnection+60 > time.Now().Unix() {
|
||||||
|
user.lastReconnection = 0
|
||||||
|
user.log.Infoln("Stream went to sleep soon after reconnection, making new post-connection ping in 20 seconds")
|
||||||
|
go func() {
|
||||||
|
time.Sleep(20 * time.Second)
|
||||||
|
user.postConnPing()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
user.log.Infofln("Stream event: %+v", evt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (user *User) HandleChatList(chats []whatsapp.Chat) {
|
func (user *User) HandleChatList(chats []whatsapp.Chat) {
|
||||||
user.log.Infoln("Chat list received")
|
user.log.Infoln("Chat list received")
|
||||||
chatMap := make(map[string]whatsapp.Chat)
|
chatMap := make(map[string]whatsapp.Chat)
|
||||||
|
@ -31,8 +31,11 @@ const (
|
|||||||
|
|
||||||
type StreamEvent struct {
|
type StreamEvent struct {
|
||||||
Type StreamType
|
Type StreamType
|
||||||
Boolean bool
|
|
||||||
|
IsOutdated bool
|
||||||
Version string
|
Version string
|
||||||
|
|
||||||
|
Extra []json.RawMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
type StreamEventHandler interface {
|
type StreamEventHandler interface {
|
||||||
@ -48,9 +51,14 @@ func (ext *ExtendedConn) handleMessageStream(message []json.RawMessage) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if event.Type == StreamUpdate && len(message) > 4 {
|
if event.Type == StreamUpdate && len(message) >= 3 {
|
||||||
json.Unmarshal(message[1], event.Boolean)
|
_ = json.Unmarshal(message[1], &event.IsOutdated)
|
||||||
json.Unmarshal(message[2], event.Version)
|
_ = json.Unmarshal(message[2], &event.Version)
|
||||||
|
if len(message) >= 4 {
|
||||||
|
event.Extra = message[3:]
|
||||||
|
}
|
||||||
|
} else if len(message) >= 2 {
|
||||||
|
event.Extra = message[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, handler := range ext.handlers {
|
for _, handler := range ext.handlers {
|
||||||
|
Loading…
Reference in New Issue
Block a user