summaryrefslogtreecommitdiff
path: root/examples/qwebchannel/standalone/websocketclientwrapper.cpp
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-07-16 17:39:31 +0200
committerSumedha Widyadharma <sumedha.widyadharma@basyskom.com>2014-08-01 09:16:16 +0200
commitb84e46090b5230d7ebcdbdabd8c03a9ae5d2f860 (patch)
tree9687c3b47f4e77e931916a8afe1d516d3b280101 /examples/qwebchannel/standalone/websocketclientwrapper.cpp
parent5051411b92b4aca4ed5ec462e7b0e52af4d3951e (diff)
downloadqtwebchannel-b84e46090b5230d7ebcdbdabd8c03a9ae5d2f860.tar.gz
Add documentation for the QtWebChannel module.
Please proof-read it and tell me what needs to be improved. I assume most people will probably not use the QWebChannel directly. Rather, they will only consume its features indirectly through the integration in QtWebKit/QtWebEngine. Thus the documentation here is for QWebChannel as a library. User-end documentation should be added to QtWebKit, I think. Change-Id: I259c204e24331271b8dc74ea11695988234a79d3 Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Diffstat (limited to 'examples/qwebchannel/standalone/websocketclientwrapper.cpp')
-rw-r--r--examples/qwebchannel/standalone/websocketclientwrapper.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/examples/qwebchannel/standalone/websocketclientwrapper.cpp b/examples/qwebchannel/standalone/websocketclientwrapper.cpp
new file mode 100644
index 0000000..0e776e1
--- /dev/null
+++ b/examples/qwebchannel/standalone/websocketclientwrapper.cpp
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Milian Wolff <milian.wolff@kdab.com>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWebChannel module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "websocketclientwrapper.h"
+
+#include <QtWebSockets/QWebSocketServer>
+
+#include "websockettransport.h"
+
+/*!
+ \brief Wrapps connected QWebSockets clients in WebSocketTransport objects.
+
+ This code is all that is required to connect incoming WebSockets to the WebChannel. Any kind
+ of remote JavaScript client that supports WebSockets can thus receive messages and access the
+ published objects.
+*/
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ Construct the client wrapper with the given parent.
+
+ All clients connecting to the QWebSocketServer will be automatically wrapped
+ in WebSocketTransport objects.
+*/
+WebSocketClientWrapper::WebSocketClientWrapper(QWebSocketServer *server, QObject *parent)
+ : QObject(parent)
+ , m_server(server)
+{
+ connect(server, &QWebSocketServer::newConnection,
+ this, &WebSocketClientWrapper::handleNewConnection);
+}
+
+/*!
+ Wrap an incoming WebSocket connection in a WebSocketTransport object.
+*/
+void WebSocketClientWrapper::handleNewConnection()
+{
+ emit clientConnected(new WebSocketTransport(m_server->nextPendingConnection()));
+}
+
+QT_END_NAMESPACE