aboutsummaryrefslogtreecommitdiffstats
path: root/examples/websockets/simplechat/chatclient.html
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2017-09-25 16:16:58 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2017-09-28 13:21:27 +0000
commit71b5fc5dd10e9edce8db886f6c05b7950b3cca6e (patch)
treeff3b1a8543aae7abd3d1270eb7336c662bdf5c5c /examples/websockets/simplechat/chatclient.html
parentfdb6d8370f9ae8fa148124289317c108399853c3 (diff)
Revamp WebSocket's simple-chat examplev5.10.0-beta1
- Replace Q_* macros with their 'modern' substitutes - Replace a usage of qDebug with QTextStream - Print a little piece of text whenever a client connects - Add a textbox to the html page to set the host to connect to - Enable/disable disconnect and send button based on connection Task-number: QTBUG-60656 Change-Id: Ieec571c3964f94cd464912054acda3208c02c898 Reviewed-by: Liang Qi <liang.qi@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'examples/websockets/simplechat/chatclient.html')
-rw-r--r--examples/websockets/simplechat/chatclient.html15
1 files changed, 11 insertions, 4 deletions
diff --git a/examples/websockets/simplechat/chatclient.html b/examples/websockets/simplechat/chatclient.html
index 511d05b..d2dbf47 100644
--- a/examples/websockets/simplechat/chatclient.html
+++ b/examples/websockets/simplechat/chatclient.html
@@ -5,17 +5,20 @@
<body>
<h1>WebSocket Chat Client</h1>
<p>
+ Host: <input id="webSocketHost" type="text" value="localhost:1234"/>
+ </p>
+ <p>
<button onClick="initWebSocket();">Connect</button>
- <button onClick="stopWebSocket();">Disconnect</button>
+ <button id="disconnectButton" onClick="stopWebSocket();" disabled>Disconnect</button>
<button onClick="checkSocket();">State</button>
</p>
<p>
- <textarea id="debugTextArea" style="width:400px;height:200px;"></textarea>
+ <textarea id="debugTextArea" style="width:400px;height:200px;" readonly></textarea>
</p>
<p>
<input type="text" id="inputNick" value="nickname" />
<input type="text" id="inputText" onkeydown="if(event.keyCode==13)sendMessage();"/>
- <button onClick="sendMessage();">Send</button>
+ <button id="sendButton" onClick="sendMessage();" disabled>Send</button>
</p>
<script type="text/javascript">
@@ -38,7 +41,6 @@
}
}
- var wsUri = "ws://localhost:1234";
var websocket = null;
function initWebSocket() {
@@ -47,12 +49,17 @@
WebSocket = MozWebSocket;
if ( websocket && websocket.readyState == 1 )
websocket.close();
+ var wsUri = "ws://" + document.getElementById("webSocketHost").value;
websocket = new WebSocket( wsUri );
websocket.onopen = function (evt) {
debug("CONNECTED");
+ document.getElementById("disconnectButton").disabled = false;
+ document.getElementById("sendButton").disabled = false;
};
websocket.onclose = function (evt) {
debug("DISCONNECTED");
+ document.getElementById("disconnectButton").disabled = true;
+ document.getElementById("sendButton").disabled = true;
};
websocket.onmessage = function (evt) {
console.log( "Message received :", evt.data );