-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using gwamp to connect to crossbar #6195
Conversation
@@ -28,6 +28,8 @@ if(NOT TOKEN_AUTH_ONLY) | |||
endif() | |||
endif() | |||
|
|||
find_package(Qt5WebSockets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qwamp needs it - hmmm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we patch qwamp to work without the qwebsocket dependency
@@ -47,6 +49,13 @@ if(APPLE AND NOT TOKEN_AUTH_ONLY) | |||
set (QT_LIBRARIES ${QT_LIBRARIES} ${Qt5MacExtras_LIBRARIES}) | |||
endif() | |||
|
|||
if(Qt5WebSockets_FOUND) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
src/CMakeLists.txt
Outdated
@@ -26,8 +26,11 @@ elseif(UNIX AND NOT APPLE) | |||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now") | |||
endif() | |||
|
|||
find_package(Qt5Qml REQUIRED) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
src/gui/CMakeLists.txt
Outdated
@@ -292,7 +301,7 @@ endif() | |||
|
|||
add_library(updater STATIC ${updater_SRCS} ${updaterMoc}) | |||
target_link_libraries(updater ${synclib_NAME}) | |||
qt5_use_modules(updater Widgets Network Xml) | |||
qt5_use_modules(updater Widgets Network Xml Qml) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
@@ -157,6 +157,13 @@ set(3rdparty_SRC | |||
../3rdparty/qtsingleapplication/qtlocalpeer.cpp | |||
../3rdparty/qtsingleapplication/qtsingleapplication.cpp | |||
../3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp | |||
../3rdparty/qmsgpack/src/msgpack.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure there is a nicer way ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's fine.
The ideal way would be to have that in a separate .cmake file included in the qmsgpack repository, but since it's not the case, then so be it.
@@ -157,6 +157,13 @@ set(3rdparty_SRC | |||
../3rdparty/qtsingleapplication/qtlocalpeer.cpp | |||
../3rdparty/qtsingleapplication/qtsingleapplication.cpp | |||
../3rdparty/qtsingleapplication/qtsinglecoreapplication.cpp | |||
../3rdparty/qmsgpack/src/msgpack.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's fine.
The ideal way would be to have that in a separate .cmake file included in the qmsgpack repository, but since it's not the case, then so be it.
src/gui/folder.cpp
Outdated
session->start(); | ||
}); | ||
|
||
QObject::connect(_webSocket.data(), QOverload<QAbstractSocket::SocketError>::of(&QAbstractSocket::error), [&](QAbstractSocket::SocketError err){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QOverload requires Qt 5.7 (before that, we'd have to use static_cast)
(Actually, i've been thinking about copying QOverload within some header so we can use it while still being compatible with Qt 5.6)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well - what ever works - tell me whyt to do
@@ -218,6 +218,10 @@ add_definitions( -D_WIN32_WINNT=0x0600) | |||
add_definitions( -DWINVER=0x0600) | |||
endif( WIN32 ) | |||
|
|||
set(CMAKE_CXX_STANDARD 14) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay, \o/ finally i'd be able to use auto in lamda :-)
I guess we can do that because we stopped supporting these old debian and centOS that did not even have GCC 4.8
although this is not strictly required for your patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no - not required - but much more fun coding ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI fails
@DeepDiver1975 you can build with tests to reproduce |
.gitmodules
Outdated
url = git@github.com:unitednetworks/qwamp.git | ||
[submodule "src/3rdparty/qmsgpack"] | ||
path = src/3rdparty/qmsgpack | ||
url = git@github.com:romixlab/qmsgpack.git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads-up to @hodyroff regarding licenses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/unitednetworks/qwamp
says Apache 2.0 correct? Thats perfect and I'll add it to the list.
https://github.com/romixlab/qmsgpack/blob/master/LICENSE
is MIT right? Also perfect ... I do need to add both, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes both
@@ -218,6 +218,10 @@ add_definitions( -D_WIN32_WINNT=0x0600) | |||
add_definitions( -DWINVER=0x0600) | |||
endif( WIN32 ) | |||
|
|||
set(CMAKE_CXX_STANDARD 14) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/gui/folder.cpp
Outdated
qDebug() << "Session joined to realm1 with session ID " << s; | ||
|
||
session->subscribe("etag-changed-channel", [&](const QVariantList& args, const QVariantMap& options){ | ||
qDebug() << "Event received"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While in general I think the lambdas are cool, we should not become a nodejs with 3x nested callbacks :-)
@@ -353,6 +353,7 @@ private slots: | |||
bool _csyncUnavail; | |||
bool _proxyDirty; | |||
QPointer<RequestEtagJob> _requestEtagJob; | |||
QScopedPointer<QTcpSocket> _webSocket; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QSslSocket?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guide me - can QSslSocket also establish a non-ssl connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use one of those depending on the account URL http vs https or how would this work? I wonder if the websocket URL should come from capabilities though so the server admin can scale it differently..
Things to keep in mind is the sslErrors signal. We have a AbstractSslErrorHandler
that you can use.
The question is if websockets could return different ssl errors or not. Maybe as first implementation you assume they return the same error as the normal account WebDAV calls ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The server would expose the websocket url via a capability. The Url will either be ws:// or wss://.
So depending on using ssl or not I either call connectToHost or connectToHostEncrypted ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll postpone the ssl topic - websockets with self signed certificates are not working.
Hard to test at the moment.
https://github.com/romixlab/qmsgpack
Is QString serialized to the same kind of string as you will emit from the server side? So it's interoperable with non-Qt code using WAMP?
|
In my non-representative local test the string as sent by the server popped up in the client the same way. |
3896aa1
to
5ba6e6f
Compare
the windows build hates me - qt version? compiler used? |
location of error: https://github.com/DeepDiver1975/qwamp/blob/782e65859617e52fa0d92d56551fc05da62c1f8f/qwamp.h#L415 compiler error:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are lots of unrelated whitespace changes.
QString Capabilities::getWebSocketUrl() const | ||
{ | ||
if (!_capabilities.contains("websocket")) { | ||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return QString()
(Otherwise you make a useless conversion from char*)
Also later.
_session.reset(new QWamp::Session(sessionName, *_webSocket.data(), QWamp::Session::MessageFormat::Msgpack, true)); | ||
|
||
QObject::connect(_session.data(), &QWamp::Session::joined, [&](qint64 s) { | ||
qDebug() << "Session joined to realm1 with session ID " << s; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is only temporary and you are going to clean up. In the final PR there should be no qDebug without categories.
// TODO: add current userid | ||
_session->subscribe("files.root-etag-changed.admin", [&](const QVariantList& args, const QVariantMap& options) { | ||
qDebug() << "Event received"; | ||
QString notificationEtag = args.at(0).toString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QList::at
crashes if the list don't have enough argument, which can happen, i guess, if the server is sending garbage.
So you can use value()
which will return an empty variant if out of bounds. or you should check if there is enough element in the list before.
} | ||
//initialize wamp connection | ||
_webSocket.reset(new QTcpSocket()); | ||
QUrl webSocketUrl(wsUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also probably need to handle the disconnect case, and re try to connect. Also handle error such as timeout and other kind.
So you will need to move this connection code somewhere else so you can call it when you want to re-connect.
}); | ||
|
||
QObject::connect(_webSocket.data(), static_cast<void (QAbstractSocket::*)(QAbstractSocket::SocketError err)>(&QAbstractSocket::error), [&](QAbstractSocket::SocketError err) { | ||
qInfo() << "tcp error: " << err; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably deserve to be a qCWarning. Don't forget to add a category. Also keep it in one line.
qInfo() << _webSocket->errorString(); | ||
}); | ||
qInfo() << "Connecting to websocket " << wsUrl; | ||
_webSocket->abort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abort?
if (webSocketUrl.scheme() == "ws") { | ||
_webSocket->connectToHost(webSocketUrl.host(), webSocketUrl.port()); | ||
} else { | ||
qCCritical(lcFolder) << "Invalid web socket scheme: " << webSocketUrl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qCWarning... critical is a bit too high.
ToDo
💟 I really love lambdas in C++ - nice to see the language evolving 💟