mirror of
				https://git.wownero.com/wowlet/wowlet.git
				synced 2024-08-15 01:03:14 +00:00 
			
		
		
		
	Websocket: keep connection alive
This commit is contained in:
		
							parent
							
								
									45b3f1ebde
								
							
						
					
					
						commit
						41a0fb3b10
					
				
					 2 changed files with 9 additions and 0 deletions
				
			
		| 
						 | 
					@ -21,6 +21,14 @@ WSClient::WSClient(AppContext *ctx, const QUrl &url, QObject *parent) :
 | 
				
			||||||
    connect(&this->webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), this, &WSClient::onError);
 | 
					    connect(&this->webSocket, QOverload<QAbstractSocket::SocketError>::of(&QWebSocket::error), this, &WSClient::onError);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_tor = url.host().endsWith(".onion");
 | 
					    m_tor = url.host().endsWith(".onion");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Keep websocket connection alive
 | 
				
			||||||
 | 
					    connect(&m_pingTimer, &QTimer::timeout, [this]{
 | 
				
			||||||
 | 
					        if (this->webSocket.state() == QAbstractSocket::ConnectedState)
 | 
				
			||||||
 | 
					            this->webSocket.ping();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					    m_pingTimer.setInterval(30 * 1000);
 | 
				
			||||||
 | 
					    m_pingTimer.start();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WSClient::sendMsg(const QByteArray &data) {
 | 
					void WSClient::sendMsg(const QByteArray &data) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,7 @@ private slots:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    QTimer m_connectionTimer;
 | 
					    QTimer m_connectionTimer;
 | 
				
			||||||
 | 
					    QTimer m_pingTimer;
 | 
				
			||||||
    AppContext *m_ctx;
 | 
					    AppContext *m_ctx;
 | 
				
			||||||
    bool m_tor = true;
 | 
					    bool m_tor = true;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue