mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-20 03:25:02 +00:00
server 正向代理功能完成
This commit is contained in:
parent
eef4da59c9
commit
77d6c930d4
4 changed files with 33 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.6.2, 2018-10-11T19:35:50. -->
|
||||
<!-- Written by QtCreator 4.6.2, 2018-10-11T22:14:16. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
@ -292,7 +292,7 @@
|
|||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">QtScrcpy.pro</value>
|
||||
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default"></value>
|
||||
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">G:/mygitcode/QtScrcpy/build-QtScrcpy-Desktop_Qt_5_9_6_MSVC2015_32bit-Debug</value>
|
||||
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
|
|
|
@ -9,6 +9,11 @@ Dialog::Dialog(QWidget *parent) :
|
|||
{
|
||||
ui->setupUi(this);
|
||||
server = new Server();
|
||||
connect(server, &Server::serverStartResult, this, [this](bool success){
|
||||
if (success) {
|
||||
server->connectTo();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Dialog::~Dialog()
|
||||
|
@ -28,6 +33,7 @@ void Dialog::on_adbProcess_clicked()
|
|||
void Dialog::on_startServerBtn_clicked()
|
||||
{
|
||||
server->start("P7C0218510000537", 27183, 0, 8000000, "");
|
||||
//server->start("P7CDU17C23010875", 27183, 0, 8000000, "");
|
||||
}
|
||||
|
||||
void Dialog::on_stopServerBtn_clicked()
|
||||
|
|
|
@ -149,20 +149,31 @@ bool Server::start(const QString& serial, quint16 localPort, quint16 maxSize, qu
|
|||
return startServerByStep();
|
||||
}
|
||||
|
||||
void Server::connectTo()
|
||||
bool Server::connectTo()
|
||||
{
|
||||
if (SSS_RUNNING != m_serverStartStep) {
|
||||
qWarning("server not run");
|
||||
return false;
|
||||
}
|
||||
if (m_tunnelForward) {
|
||||
m_deviceSocket = new QTcpSocket(this);
|
||||
connect(m_deviceSocket, &QTcpSocket::disconnected, m_deviceSocket, &QTcpSocket::deleteLater);
|
||||
//connect(m_deviceSocket, &QTcpSocket::error, m_deviceSocket, &QTcpSocket::deleteLater);
|
||||
connect(m_deviceSocket, &QTcpSocket::readyRead, this, [this](){
|
||||
qDebug() << "ready read";
|
||||
m_deviceSocket->readAll();
|
||||
static quint64 count = 0;
|
||||
qDebug() << count << "ready read";
|
||||
count++;
|
||||
});
|
||||
|
||||
// wait for devices server start
|
||||
QTimer::singleShot(1000, this, [this](){
|
||||
if (m_deviceSocket) {
|
||||
m_deviceSocket->connectToHost(QHostAddress::LocalHost, m_localPort);
|
||||
}
|
||||
});
|
||||
m_deviceSocket->connectToHost(QHostAddress::LocalHost, m_localPort);
|
||||
}
|
||||
|
||||
QTimer::singleShot(300, this, [this](){
|
||||
QTimer::singleShot(1200, this, [this](){
|
||||
if (!m_deviceSocket) {
|
||||
emit connectToResult(false);
|
||||
return;
|
||||
|
@ -204,9 +215,11 @@ void Server::connectTo()
|
|||
} else {
|
||||
disableTunnelReverse();
|
||||
}
|
||||
m_tunnelEnabled = false;
|
||||
}
|
||||
emit connectToResult(success);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
void Server::stop()
|
||||
|
@ -219,9 +232,12 @@ void Server::stop()
|
|||
} else {
|
||||
disableTunnelReverse();
|
||||
}
|
||||
m_tunnelForward = false;
|
||||
m_tunnelEnabled = false;
|
||||
}
|
||||
if (m_serverCopiedToDevice) {
|
||||
removeServer();
|
||||
m_serverCopiedToDevice = false;
|
||||
}
|
||||
m_serverSocket.close();
|
||||
if (m_deviceSocket) {
|
||||
|
@ -325,7 +341,7 @@ void Server::onWorkProcessResult(AdbProcess::ADB_EXEC_RESULT processResult)
|
|||
if (sender() == &m_serverProcess) {
|
||||
if (SSS_EXECUTE_SERVER == m_serverStartStep) {
|
||||
if (AdbProcess::AER_SUCCESS_START == processResult) {
|
||||
m_serverStartStep = SSS_NULL;
|
||||
m_serverStartStep = SSS_RUNNING;
|
||||
m_tunnelEnabled = true;
|
||||
emit serverStartResult(true);
|
||||
} else if (AdbProcess::AER_ERROR_START == processResult){
|
||||
|
|
|
@ -18,12 +18,13 @@ class Server : public QObject
|
|||
SSS_ENABLE_TUNNEL_REVERSE,
|
||||
SSS_ENABLE_TUNNEL_FORWARD,
|
||||
SSS_EXECUTE_SERVER,
|
||||
SSS_RUNNING,
|
||||
};
|
||||
public:
|
||||
explicit Server(QObject *parent = nullptr);
|
||||
|
||||
bool start(const QString& serial, quint16 localPort, quint16 maxSize, quint32 bitRate, const QString& crop);
|
||||
void connectTo();
|
||||
bool connectTo();
|
||||
void stop();
|
||||
|
||||
signals:
|
||||
|
@ -44,6 +45,7 @@ private:
|
|||
bool execute();
|
||||
bool startServerByStep();
|
||||
|
||||
private:
|
||||
QString m_serverPath = "";
|
||||
AdbProcess m_workProcess;
|
||||
QString m_serial = "";
|
||||
|
|
Loading…
Add table
Reference in a new issue