Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
tweak the test html
Browse files Browse the repository at this point in the history
  • Loading branch information
jmazzitelli committed Jul 14, 2015
1 parent e8c0be0 commit ef90d92
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 94 deletions.
91 changes: 1 addition & 90 deletions modules/feed-comm/feed-comm-war/README.adoc
Original file line number Diff line number Diff line change
@@ -1,92 +1,3 @@
= Feed Communications Server-Side WAR

You can use the following simple .html file to send messages via WebSockets to the server-side.

[source,html]
----
<!DOCTYPE html>
<html>
<head>
<title>WebSockets Client</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
Enter text to send to the websocket server:
<div id="send">
<input type="text" id="data" size="100"/><br>
<input type="button" id="sendtext" value="send text"/>
</div>
<div id="output"></div>
</body>
</html>
<script>
jQuery(function($){
if (!("WebSocket" in window)) {
alert("Your browser does not support web sockets");
}else{
setup();
}
function setup(){
// Note: You have to change the host var
// if your client runs on a different machine than the websocket server
var host = "ws://localhost:8080/hawkular/feed-comm/123-456";
var socket = new WebSocket(host);
//console.log("socket status: " + socket.readyState);
var $txt = $("#data");
var $btnSend = $("#sendtext");
$txt.focus();
// event handlers for UI
$btnSend.on('click',function(){
var text = $txt.val();
if(text == ""){
return;
}
socket.send(text);
$txt.val("");
});
$txt.keypress(function(evt){
if(evt.which == 13){
$btnSend.click();
}
});
// event handlers for websocket
if(socket){
socket.onopen = function(){
//alert("connection opened....");
}
socket.onmessage = function(msg){
showServerResponse(msg.data);
}
socket.onclose = function(){
//alert("connection closed....");
showServerResponse("The connection has been closed.");
}
}else{
console.log("invalid socket");
}
function showServerResponse(txt){
var p = document.createElement('p');
p.innerHTML = txt;
document.getElementById('output').appendChild(p);
}
}
});
</script>
----
You can use websocket-test-client.html to send messages via WebSockets to the server-side. It can mimic a UI client or a feed.
9 changes: 5 additions & 4 deletions modules/feed-comm/feed-comm-war/websocket-test-client.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
Enter text to send to the websocket server:
<div id="send">
<input type="text" id="data" size="100"/><br>
URL Context (a feed ID or 'ui')<input type="text" id="urlcontext" size="25"/><br>
Message (Hawkular JSON):<input type="text" id="data" size="100"/><br>
<input type="button" id="sendtext" value="send text"/>
</div>
<div id="output"></div>
Expand All @@ -28,7 +28,8 @@
// Note: You have to change the host var
// if your client runs on a different machine than the websocket server

var host = "ws://localhost:8080/hawkular/feed-comm";
var $urlcontext = $("#urlcontext");
var host = "ws://localhost:8080/hawkular/feed-comm/" + $urlcontext.val();
var socket = new WebSocket(host);
//console.log("socket status: " + socket.readyState);

Expand All @@ -44,7 +45,7 @@
return;
}
socket.send(text);
$txt.val("");
//$txt.val("");
});

$txt.keypress(function(evt){
Expand Down

0 comments on commit ef90d92

Please sign in to comment.