@dusted/anqst 1.7.2 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ #pragma once
2
+
3
+ #include "AnQstHostBridgeFacade.h"
4
+
5
+ #include <QHostAddress>
6
+ #include <QHash>
7
+ #include <QObject>
8
+ #include <QString>
9
+ #include <QUrl>
10
+
11
+ class QTcpServer;
12
+ class QTcpSocket;
13
+
14
+ namespace ANQST_WEBBASE_NAMESPACE {
15
+
16
+ class AngularHttpBaseServer : public QObject {
17
+ Q_OBJECT
18
+
19
+ public:
20
+ enum class ContentRootMode {
21
+ Unset,
22
+ Qrc,
23
+ Filesystem
24
+ };
25
+ Q_ENUM(ContentRootMode)
26
+
27
+ explicit AngularHttpBaseServer(QObject* parent = nullptr);
28
+ ~AngularHttpBaseServer() override;
29
+
30
+ void setFacade(AnQstHostBridgeFacade* facade);
31
+ void setBridgeObjectName(const QString& name);
32
+ bool configureContent(ContentRootMode mode, const QString& contentRoot, const QString& entryPoint);
33
+ bool configureProxyTarget(const QUrl& targetBaseUrl, const QString& entryPoint = QStringLiteral("index.html"));
34
+ bool start(bool allowLan = false, quint16 startPort = 43000);
35
+ void stop();
36
+ void notifyWidgetReattached();
37
+ bool isRunning() const;
38
+
39
+ QString url() const;
40
+ quint16 httpPort() const;
41
+ quint16 wsPort() const;
42
+ QString websocketUrl() const;
43
+
44
+ signals:
45
+ void serverError(const QVariantMap& payload);
46
+ void clientAttached(const QString& peer);
47
+ void clientDetached();
48
+
49
+ private:
50
+ enum class ServeMode {
51
+ LocalContent,
52
+ ProxyTarget
53
+ };
54
+
55
+ void emitServerError(const QString& code, const QString& message, const QVariantMap& context = QVariantMap());
56
+ bool startHttp(const QHostAddress& bindAddress, quint16 startPort);
57
+ bool startWebSocket(const QHostAddress& bindAddress);
58
+ void stopHttp();
59
+ void stopWebSocket();
60
+
61
+ void handleHttpNewConnection();
62
+ void handleHttpClient(QTcpSocket* socket);
63
+ bool isWebSocketUpgradeRequest(const QList<QByteArray>& lines) const;
64
+ void handleProxyHttpRequest(QTcpSocket* clientSocket, const QByteArray& rawRequest, const QString& requestTarget);
65
+ void handleProxyWebSocketUpgrade(QTcpSocket* clientSocket, const QByteArray& rawRequest, const QString& requestTarget);
66
+ void closeProxyPeer(QTcpSocket* socket);
67
+ QByteArray readHttpAsset(const QString& requestPath, QString* contentType, int* statusCode) const;
68
+ QByteArray readHttpProxy(const QString& method, const QString& requestPath, const QByteArray& body, QString* contentType, int* statusCode) const;
69
+ QString resolveFilePath(const QString& requestPath) const;
70
+
71
+ void handleWebSocketConnected();
72
+ void wireClient(QTcpSocket* socket);
73
+ void handleWebSocketSocketData();
74
+ bool tryCompleteWebSocketHandshake();
75
+ bool tryConsumeWebSocketFrame(QString* outMessage);
76
+ void detachCurrentClient();
77
+ void sendJsonToClient(const QVariantMap& payload);
78
+
79
+ QTcpServer* m_httpServer;
80
+ QTcpServer* m_wsServer;
81
+ QTcpSocket* m_client;
82
+ QByteArray m_wsReadBuffer;
83
+ bool m_wsHandshakeComplete;
84
+ AnQstHostBridgeFacade* m_facade;
85
+ ContentRootMode m_contentRootMode;
86
+ QString m_contentRoot;
87
+ QString m_entryPoint;
88
+ QString m_bridgeObjectName;
89
+ QHostAddress m_bindAddress;
90
+ quint16 m_httpPort;
91
+ quint16 m_wsPort;
92
+ ServeMode m_serveMode;
93
+ QUrl m_proxyBaseUrl;
94
+ QHash<QTcpSocket*, QTcpSocket*> m_proxyPeers;
95
+ };
96
+
97
+ } // namespace ANQST_WEBBASE_NAMESPACE
@@ -0,0 +1,235 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>AnQstWidgetBaseClassDialog</class>
4
+ <widget class="QDialog" name="AnQstWidgetBaseClassDialog">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>656</width>
10
+ <height>233</height>
11
+ </rect>
12
+ </property>
13
+ <property name="windowTitle">
14
+ <string>Debug Widget &lt;WidgetName&gt;</string>
15
+ </property>
16
+ <layout class="QVBoxLayout" name="verticalLayout">
17
+ <item>
18
+ <widget class="QTabWidget" name="tabWidget">
19
+ <property name="currentIndex">
20
+ <number>0</number>
21
+ </property>
22
+ <widget class="QWidget" name="tabWidgetHost" native="true">
23
+ <attribute name="title">
24
+ <string>WidgetHost</string>
25
+ </attribute>
26
+ <layout class="QVBoxLayout" name="verticalLayout_3">
27
+ <item>
28
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
29
+ <item>
30
+ <widget class="QLabel" name="label_4">
31
+ <property name="text">
32
+ <string>Widget host</string>
33
+ </property>
34
+ </widget>
35
+ </item>
36
+ <item>
37
+ <widget class="QComboBox" name="cbAnQstAngularAppHost">
38
+ <item>
39
+ <property name="text">
40
+ <string>Application</string>
41
+ </property>
42
+ </item>
43
+ <item>
44
+ <property name="text">
45
+ <string>Browser</string>
46
+ </property>
47
+ </item>
48
+ </widget>
49
+ </item>
50
+ <item>
51
+ <widget class="QCheckBox" name="rbOpenBrowser">
52
+ <property name="text">
53
+ <string>Open in browser</string>
54
+ </property>
55
+ </widget>
56
+ </item>
57
+ </layout>
58
+ </item>
59
+ <item>
60
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
61
+ <item>
62
+ <widget class="QLabel" name="label">
63
+ <property name="text">
64
+ <string>Resource</string>
65
+ </property>
66
+ </widget>
67
+ </item>
68
+ <item>
69
+ <widget class="QComboBox" name="cbWidgetResource">
70
+ <item>
71
+ <property name="text">
72
+ <string>Builtin (QRC)</string>
73
+ </property>
74
+ </item>
75
+ <item>
76
+ <property name="text">
77
+ <string>Local directory</string>
78
+ </property>
79
+ </item>
80
+ <item>
81
+ <property name="text">
82
+ <string>Webserver (HTTP)</string>
83
+ </property>
84
+ </item>
85
+ </widget>
86
+ </item>
87
+ </layout>
88
+ </item>
89
+ <item>
90
+ <layout class="QVBoxLayout" name="vlayoutURL">
91
+ <item>
92
+ <layout class="QHBoxLayout" name="horizontalLayout">
93
+ <item>
94
+ <widget class="QLabel" name="label_2">
95
+ <property name="text">
96
+ <string>URL</string>
97
+ </property>
98
+ </widget>
99
+ </item>
100
+ <item>
101
+ <widget class="QLineEdit" name="leURL"/>
102
+ </item>
103
+ </layout>
104
+ </item>
105
+ <item>
106
+ <widget class="QLabel" name="lblURLStatusMsg">
107
+ <property name="text">
108
+ <string/>
109
+ </property>
110
+ </widget>
111
+ </item>
112
+ </layout>
113
+ </item>
114
+ <item>
115
+ <layout class="QHBoxLayout" name="vlayoutDIR">
116
+ <item>
117
+ <widget class="QLabel" name="label_3">
118
+ <property name="text">
119
+ <string>Directory</string>
120
+ </property>
121
+ </widget>
122
+ </item>
123
+ <item>
124
+ <widget class="QLineEdit" name="leDirectory"/>
125
+ </item>
126
+ <item>
127
+ <widget class="QToolButton" name="btnBrowseDirectory">
128
+ <property name="text">
129
+ <string>...</string>
130
+ </property>
131
+ </widget>
132
+ </item>
133
+ </layout>
134
+ </item>
135
+ </layout>
136
+ </widget>
137
+ <widget class="QWidget" name="tabJSConsole">
138
+ <attribute name="title">
139
+ <string>JS Console</string>
140
+ </attribute>
141
+ <layout class="QVBoxLayout" name="verticalLayout_2">
142
+ <property name="spacing">
143
+ <number>0</number>
144
+ </property>
145
+ <item>
146
+ <widget class="QPlainTextEdit" name="txtEditJSLog">
147
+ <property name="focusPolicy">
148
+ <enum>Qt::StrongFocus</enum>
149
+ </property>
150
+ <property name="autoFillBackground">
151
+ <bool>false</bool>
152
+ </property>
153
+ <property name="undoRedoEnabled">
154
+ <bool>false</bool>
155
+ </property>
156
+ <property name="readOnly">
157
+ <bool>true</bool>
158
+ </property>
159
+ <property name="backgroundVisible">
160
+ <bool>false</bool>
161
+ </property>
162
+ </widget>
163
+ </item>
164
+ <item>
165
+ <widget class="QLineEdit" name="lineEditJSConsoleInput">
166
+ <property name="focusPolicy">
167
+ <enum>Qt::NoFocus</enum>
168
+ </property>
169
+ </widget>
170
+ </item>
171
+ </layout>
172
+ </widget>
173
+ </widget>
174
+ </item>
175
+ <item>
176
+ <widget class="QDialogButtonBox" name="buttonBox">
177
+ <property name="orientation">
178
+ <enum>Qt::Horizontal</enum>
179
+ </property>
180
+ <property name="standardButtons">
181
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
182
+ </property>
183
+ </widget>
184
+ </item>
185
+ <item>
186
+ <spacer name="verticalSpacer">
187
+ <property name="orientation">
188
+ <enum>Qt::Vertical</enum>
189
+ </property>
190
+ <property name="sizeHint" stdset="0">
191
+ <size>
192
+ <width>20</width>
193
+ <height>40</height>
194
+ </size>
195
+ </property>
196
+ </spacer>
197
+ </item>
198
+ </layout>
199
+ </widget>
200
+ <resources/>
201
+ <connections>
202
+ <connection>
203
+ <sender>buttonBox</sender>
204
+ <signal>accepted()</signal>
205
+ <receiver>AnQstWidgetBaseClassDialog</receiver>
206
+ <slot>accept()</slot>
207
+ <hints>
208
+ <hint type="sourcelabel">
209
+ <x>248</x>
210
+ <y>254</y>
211
+ </hint>
212
+ <hint type="destinationlabel">
213
+ <x>157</x>
214
+ <y>274</y>
215
+ </hint>
216
+ </hints>
217
+ </connection>
218
+ <connection>
219
+ <sender>buttonBox</sender>
220
+ <signal>rejected()</signal>
221
+ <receiver>AnQstWidgetBaseClassDialog</receiver>
222
+ <slot>reject()</slot>
223
+ <hints>
224
+ <hint type="sourcelabel">
225
+ <x>316</x>
226
+ <y>260</y>
227
+ </hint>
228
+ <hint type="destinationlabel">
229
+ <x>286</x>
230
+ <y>274</y>
231
+ </hint>
232
+ </hints>
233
+ </connection>
234
+ </connections>
235
+ </ui>
@@ -0,0 +1,22 @@
1
+ find_package(Catch2 CONFIG REQUIRED)
2
+ find_package(Qt5 REQUIRED COMPONENTS Test)
3
+
4
+ add_executable(anqstwebhostbase_tests
5
+ test_AnQstWebHostBase.cpp
6
+ )
7
+
8
+ target_link_libraries(anqstwebhostbase_tests
9
+ PRIVATE
10
+ ${ANQST_WEBBASE_TARGET}
11
+ Catch2::Catch2
12
+ Qt5::Test
13
+ )
14
+
15
+ anqst_configure_qt_runtime(anqstwebhostbase_tests)
16
+
17
+ include(CTest)
18
+ add_test(NAME anqstwebhostbase_tests COMMAND anqstwebhostbase_tests)
19
+ set_tests_properties(anqstwebhostbase_tests PROPERTIES
20
+ ENVIRONMENT "QTWEBENGINE_DISABLE_SANDBOX=1;QT_QPA_PLATFORM=offscreen;QTWEBENGINE_CHROMIUM_FLAGS=--no-sandbox"
21
+ )
22
+