| 1 |
// Copyright (C) 2016 basysKom GmbH, author Bernd Lamecker <[email protected]> |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only |
| 3 |
|
| 4 |
/*! |
| 5 |
\example chatclient-html |
| 6 |
\title Qt WebChannel ChatClient HTML Example |
| 7 |
\ingroup qtwebchannel-examples |
| 8 |
\examplecategory {Web Technologies} |
| 9 |
\brief A HTML/JavaScript client that communicates over a WebSocket with a QWebChannel server. |
| 10 |
|
| 11 |
|
| 12 |
\image chatclient-html.png |
| 13 |
|
| 14 |
\e{ChatClient HTML} provides a simple QWebChannel client implemented using JavaScript and HTML. |
| 15 |
|
| 16 |
\section1 Running the Example |
| 17 |
|
| 18 |
To run the example, open the \c chatclient.html file in a browser. |
| 19 |
|
| 20 |
\section1 Implementing a Web Channel Client |
| 21 |
|
| 22 |
The client initializes a WebSocket connection to the chat server and receives an object |
| 23 |
containing all the necessary signals, slots, and properties for implementing a chat client. |
| 24 |
|
| 25 |
After login, the client can invoke the method \c sendMessage and receive the signal \c newMessage |
| 26 |
to send and receive messages. Furthermore, a \c userList property provides the names of |
| 27 |
all other connected clients. The list is automatically updated when its contents change. |
| 28 |
Also, the client responds to the server's keep alive signal which is needed to detect disconnected |
| 29 |
clients and remove them from the \c userList property. |
| 30 |
|
| 31 |
The example shows how basic elements can be used with the client JavaScript implementation of |
| 32 |
QWebChannel, like connecting to signals (\c newMessage), calling slots (\c sendMessage), and handling |
| 33 |
property changes (\c userList). |
| 34 |
|
| 35 |
The client is able to work with \l{Qt WebChannel ChatServer Example}. |
| 36 |
|
| 37 |
|
| 38 |
\sa {Qt WebChannel ChatServer Example}, {Qt WebChannel ChatClient QML Application} |
| 39 |
|
| 40 |
*/ |