Bael 389 - Chat-like app using the Java API for WebSocket (#1265)
* Project for " A Guide to the Java API for WebSocket" article * Setting dependencies correctly * Formatting adjustments * Removing tomcat7 maven plugin * Applying formatt - No spaces
This commit is contained in:
committed by
Zeger Hendrikse
parent
181688a765
commit
c83c449fa5
23
java-websocket/src/main/webapp/websocket.js
Normal file
23
java-websocket/src/main/webapp/websocket.js
Normal file
@@ -0,0 +1,23 @@
|
||||
var ws;
|
||||
|
||||
function connect() {
|
||||
var username = document.getElementById("username").value;
|
||||
ws = new WebSocket("ws://" + document.location.host + "/java-websocket/chat/" + username);
|
||||
|
||||
|
||||
ws.onmessage = function(event) {
|
||||
var log = document.getElementById("log");
|
||||
console.log(event.data);
|
||||
var message = JSON.parse(event.data);
|
||||
log.innerHTML += message.from + " : " + message.content + "\n";
|
||||
};
|
||||
}
|
||||
|
||||
function send() {
|
||||
var content = document.getElementById("msg").value;
|
||||
var json = JSON.stringify({
|
||||
"content":content
|
||||
});
|
||||
|
||||
ws.send(json);
|
||||
}
|
||||
Reference in New Issue
Block a user