summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-04-19 22:07:06 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-04-19 22:07:06 +0300
commit3577c55cb91c10b68b2e162c0d9140659dea5d3c (patch)
tree9d955e01a32b07463fc6bf8f5256ecea0fcb4b0e
parent5c92a5a3d0464d98f2b4b9627c4c99c9f7137897 (diff)
WhatsApp: keep alive support
-rw-r--r--protocols/WhatsAppWeb/src/proto.cpp1
-rw-r--r--protocols/WhatsAppWeb/src/proto.h21
-rw-r--r--protocols/WhatsAppWeb/src/server.cpp10
3 files changed, 31 insertions, 1 deletions
diff --git a/protocols/WhatsAppWeb/src/proto.cpp b/protocols/WhatsAppWeb/src/proto.cpp
index c1761eaff3..52d959fcf7 100644
--- a/protocols/WhatsAppWeb/src/proto.cpp
+++ b/protocols/WhatsAppWeb/src/proto.cpp
@@ -24,6 +24,7 @@ static int CompareUsers(const WAUser *p1, const WAUser *p2)
WhatsAppProto::WhatsAppProto(const char *proto_name, const wchar_t *username) :
PROTO<WhatsAppProto>(proto_name, username),
+ m_impl(*this),
m_tszDefaultGroup(getWStringA(DBKEY_DEF_GROUP)),
m_arUsers(10, CompareUsers),
m_arPacketQueue(10, NumericKeySortT),
diff --git a/protocols/WhatsAppWeb/src/proto.h b/protocols/WhatsAppWeb/src/proto.h
index a2517d13e7..7ab3bd2921 100644
--- a/protocols/WhatsAppWeb/src/proto.h
+++ b/protocols/WhatsAppWeb/src/proto.h
@@ -50,6 +50,25 @@ struct WAMessage
class WhatsAppProto : public PROTO<WhatsAppProto>
{
+ class CWhatsAppProtoImpl
+ {
+ friend class WhatsAppProto;
+ WhatsAppProto &m_proto;
+
+ CTimer m_keepAlive;
+ void OnKeepAlive(CTimer *) {
+ m_proto.SendKeepAlive();
+ }
+
+ CWhatsAppProtoImpl(WhatsAppProto &pro) :
+ m_proto(pro),
+ m_keepAlive(Miranda_GetSystemWindow(), UINT_PTR(this))
+ {
+ m_keepAlive.OnEvent = Callback(this, &CWhatsAppProtoImpl::OnKeepAlive);
+ }
+ } m_impl;
+
+
bool m_bTerminated, m_bOnline;
ptrW m_tszDefaultGroup;
@@ -99,6 +118,8 @@ class WhatsAppProto : public PROTO<WhatsAppProto>
bool decryptBinaryMessage(size_t cbSize, const void *buf, MBinBuffer &res);
+ void SendKeepAlive();
+
/// Request handlers ///////////////////////////////////////////////////////////////////
void OnRestoreSession1(const JSONNode &node);
diff --git a/protocols/WhatsAppWeb/src/server.cpp b/protocols/WhatsAppWeb/src/server.cpp
index d452c8bd1b..06241e46c2 100644
--- a/protocols/WhatsAppWeb/src/server.cpp
+++ b/protocols/WhatsAppWeb/src/server.cpp
@@ -46,6 +46,9 @@ void WhatsAppProto::OnLoggedIn()
ProtoBroadcastAck(0, ACKTYPE_STATUS, ACKRESULT_SUCCESS, (HANDLE)m_iStatus, m_iDesiredStatus);
m_iStatus = m_iDesiredStatus;
+
+ SendKeepAlive();
+ m_impl.m_keepAlive.Start(60000);
}
void WhatsAppProto::OnLoggedOut(void)
@@ -61,6 +64,11 @@ void WhatsAppProto::OnLoggedOut(void)
setAllContactStatuses(ID_STATUS_OFFLINE, false);
}
+void WhatsAppProto::SendKeepAlive()
+{
+ WebSocket_Send(m_hServerConn, "?,,", 3);
+}
+
/////////////////////////////////////////////////////////////////////////////////////////
bool WhatsAppProto::ProcessChallenge(const CMStringA &szChallenge)
@@ -375,7 +383,7 @@ bool WhatsAppProto::ServerThreadWorker()
case 9: // ping
debugLogA("ping received");
- Netlib_Send(m_hServerConn, start, (int)hdr.payloadSize, 0);
+ Netlib_Send(m_hServerConn, "?,,", 3, 0);
break;
default: