diff options
author | Maurice Kalinowski <maurice.kalinowski@qt.io> | 2019-01-29 14:40:51 +0100 |
---|---|---|
committer | Maurice Kalinowski <maurice.kalinowski@qt.io> | 2019-01-30 08:49:15 +0000 |
commit | 6ca1681204f28f0ecfcbacc64d457593822e1520 (patch) | |
tree | 3321343409c2da0611c78f843dde8fd6ab070611 | |
parent | 845d4804905c82d76d0fed8f7d0e9ee333c32116 (diff) |
Add platform plugin parameter for websockerserver
When using the webgl backend in a container, one needs to specify the
port of the websocket server in addition to the http server.
While using QT_WEBGL_WEBSOCKETSERVER is an option, it requires to pass a
hostname in addition.
Change-Id: Iefce12f049a81711a52586d60dd34bddbb9de12e
Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
6 files changed, 27 insertions, 10 deletions
diff --git a/src/plugins/platforms/webgl/qwebglintegration.cpp b/src/plugins/platforms/webgl/qwebglintegration.cpp index 1b4214a..08a432c 100644 --- a/src/plugins/platforms/webgl/qwebglintegration.cpp +++ b/src/plugins/platforms/webgl/qwebglintegration.cpp @@ -70,12 +70,13 @@ QWebGLIntegrationPrivate *QWebGLIntegrationPrivate::instance() return static_cast<QWebGLIntegration *>(platformIntegration)->d_ptr.data(); } -QWebGLIntegration::QWebGLIntegration(quint16 port) : +QWebGLIntegration::QWebGLIntegration(quint16 port, quint16 wssport) : d_ptr(new QWebGLIntegrationPrivate) { Q_D(QWebGLIntegration); d->q_ptr = this; d->httpPort = port; + d->wssPort = wssport; d->touchDevice = new QTouchDevice; d->touchDevice->setName("EmulatedTouchDevice"); d->touchDevice->setType(QTouchDevice::TouchScreen); @@ -112,7 +113,7 @@ void QWebGLIntegration::initialize() d->screen = new QWebGLScreen; screenAdded(d->screen, true); - d->webSocketServer = new QWebGLWebSocketServer; + d->webSocketServer = new QWebGLWebSocketServer(d->wssPort); d->httpServer = new QWebGLHttpServer(d->webSocketServer, this); bool ok = d->httpServer->listen(QHostAddress::Any, d->httpPort); if (!ok) { diff --git a/src/plugins/platforms/webgl/qwebglintegration.h b/src/plugins/platforms/webgl/qwebglintegration.h index 856ccde..f3e22df 100644 --- a/src/plugins/platforms/webgl/qwebglintegration.h +++ b/src/plugins/platforms/webgl/qwebglintegration.h @@ -45,7 +45,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcWebGL) class QWebGLIntegration : public QPlatformIntegration, public QPlatformNativeInterface { public: - QWebGLIntegration(quint16 port); + QWebGLIntegration(quint16 port, quint16 wssport); ~QWebGLIntegration(); static QWebGLIntegration *instance(); diff --git a/src/plugins/platforms/webgl/qwebglintegration_p.h b/src/plugins/platforms/webgl/qwebglintegration_p.h index 06f19fc..106667e 100644 --- a/src/plugins/platforms/webgl/qwebglintegration_p.h +++ b/src/plugins/platforms/webgl/qwebglintegration_p.h @@ -71,6 +71,7 @@ public: mutable QPlatformInputContext *inputContext = nullptr; quint16 httpPort = 0; + quint16 wssPort = 0; #if defined(Q_OS_WIN) mutable QWindowsFontDatabase fontDatabase; #elif defined(Q_OS_MACOS) diff --git a/src/plugins/platforms/webgl/qwebglmain.cpp b/src/plugins/platforms/webgl/qwebglmain.cpp index 6c9c324..ec3e8e5 100644 --- a/src/plugins/platforms/webgl/qwebglmain.cpp +++ b/src/plugins/platforms/webgl/qwebglmain.cpp @@ -47,6 +47,8 @@ QPlatformIntegration* QWebGLIntegrationPlugin::create(const QString& system, const QStringList& paramList) { quint16 port = 8080; + quint16 wssport = 0; + if (!paramList.isEmpty()) { for (const QString ¶meter : qAsConst(paramList)) { const QStringList parts = parameter.split('='); @@ -61,13 +63,23 @@ QPlatformIntegration* QWebGLIntegrationPlugin::create(const QString& system, qCCritical(lcWebGL, "Invalid port number"); return nullptr; } - } - if (parts.first() == QStringLiteral("noloadingscreen")) + } else if (parts.first() == QStringLiteral("wsserverport")) { + if (parts.size() != 2) { + qCCritical(lcWebGL, "Websocket server port specified with no value"); + return nullptr; + } + bool ok; + wssport = parts.last().toUShort(&ok); + if (!ok) { + qCCritical(lcWebGL, "Invalid websocket port number"); + return nullptr; + } + } else if (parts.first() == QStringLiteral("noloadingscreen")) qputenv("QT_WEBGL_LOADINGSCREEN", "0"); } } if (!system.compare(QLatin1String("webgl"), Qt::CaseInsensitive)) - return new QWebGLIntegration(port); + return new QWebGLIntegration(port, wssport); return nullptr; } diff --git a/src/plugins/platforms/webgl/qwebglwebsocketserver.cpp b/src/plugins/platforms/webgl/qwebglwebsocketserver.cpp index dfeaa58..c7fab3b 100644 --- a/src/plugins/platforms/webgl/qwebglwebsocketserver.cpp +++ b/src/plugins/platforms/webgl/qwebglwebsocketserver.cpp @@ -70,12 +70,15 @@ class QWebGLWebSocketServerPrivate { public: QWebSocketServer *server = nullptr; + quint16 initialPort = 0; }; -QWebGLWebSocketServer::QWebGLWebSocketServer(QObject *parent) : +QWebGLWebSocketServer::QWebGLWebSocketServer(quint16 port, QObject *parent) : QObject(parent), d_ptr(new QWebGLWebSocketServerPrivate) -{} +{ + d_ptr->initialPort = port; +} QWebGLWebSocketServer::~QWebGLWebSocketServer() {} @@ -120,7 +123,7 @@ void QWebGLWebSocketServer::create() #endif QWebSocketServer::NonSecureMode); } - if (d->server->listen(hostAddress, url.port(0))) { + if (d->server->listen(hostAddress, url.port(d->initialPort))) { connect(d->server, &QWebSocketServer::newConnection, this, &QWebGLWebSocketServer::onNewConnection); } else { diff --git a/src/plugins/platforms/webgl/qwebglwebsocketserver.h b/src/plugins/platforms/webgl/qwebglwebsocketserver.h index f2bbea0..9330ec0 100644 --- a/src/plugins/platforms/webgl/qwebglwebsocketserver.h +++ b/src/plugins/platforms/webgl/qwebglwebsocketserver.h @@ -55,7 +55,7 @@ public: ChangeTitle }; - QWebGLWebSocketServer(QObject *parent = nullptr); + QWebGLWebSocketServer(quint16 port, QObject *parent = nullptr); ~QWebGLWebSocketServer() override; quint16 port() const; |