-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6caca5e
commit 2ad47b2
Showing
8 changed files
with
151 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
src/main/java/net/acomputerdog/webchat/net/handler/ChatHandler.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
body { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: flex-start; | ||
align-items: stretch; | ||
|
||
padding: 10px; | ||
margin: 0; | ||
|
||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
} | ||
|
||
#sendContainer { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: stretch; | ||
align-items: flex-start; | ||
|
||
padding: 0; | ||
margin: 10px 0 0; | ||
|
||
} | ||
|
||
#sendText { | ||
flex-grow: 1; | ||
flex-shrink: 1; | ||
} | ||
|
||
#sendButton { | ||
margin-left: 10px; | ||
} | ||
|
||
#chatbox { | ||
flex-grow: 1; | ||
flex-shrink: 1; | ||
|
||
resize: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const DEFAULT_TIMEOUT = 500; | ||
const MAX_TIMEOUT = 5000; | ||
const TIMEOUT_INCREASE = 100; | ||
|
||
let chatTimer; | ||
let version = 0; | ||
let timeout = DEFAULT_TIMEOUT; | ||
|
||
function sendChat() { | ||
let sendBox = document.getElementById("sendText"); | ||
if (sendBox) { | ||
let http = new XMLHttpRequest(); | ||
http.open("POST", "send", true); | ||
http.send("message=" + sendBox.value); | ||
|
||
sendBox.value = ""; | ||
|
||
clearTimeout(chatTimer); | ||
timeout = DEFAULT_TIMEOUT; | ||
setTimeout(refreshChat, timeout); | ||
} | ||
} | ||
|
||
function updateChat(response) { | ||
let chatbox = document.getElementById("chatbox"); | ||
if (chatbox) { | ||
chatbox.value = response; | ||
} | ||
} | ||
|
||
function refreshChat() { | ||
let http = new XMLHttpRequest(); | ||
http.onreadystatechange = function () { | ||
if (http.readyState === 4) { | ||
if (http.status === 200) { | ||
timeout = DEFAULT_TIMEOUT; | ||
updateChat(http.responseText); | ||
refreshVersion(); | ||
} else if (timeout < MAX_TIMEOUT) { | ||
timeout += TIMEOUT_INCREASE; | ||
} | ||
//set timeout for next chat query | ||
chatTimer = window.setTimeout(refreshChat, timeout); | ||
} | ||
}; | ||
http.open("GET", "updatechat" + "?version=" + version, true); // true for asynchronous | ||
http.send(); | ||
} | ||
|
||
function refreshVersion() { | ||
let http = new XMLHttpRequest(); | ||
http.onreadystatechange = function () { | ||
if (http.readyState === 4 && http.status === 200) { | ||
version = http.responseText; | ||
} | ||
}; | ||
http.open("GET", "chatversion", true); | ||
http.send(); | ||
} | ||
|
||
function onPost() { | ||
setTimeout(function () { | ||
let messageBox = document.getElementById("message"); | ||
if (messageBox) { | ||
messageBox.value = ""; | ||
} | ||
}, 100); | ||
clearTimeout(chatTimer); | ||
timeout = DEFAULT_TIMEOUT; | ||
setTimeout(refreshChat, 100); | ||
return true; | ||
} | ||
|
||
function onSendKey(key) { | ||
if (key === 13) { | ||
sendChat() | ||
} | ||
} | ||
|
||
//start everything going | ||
refreshChat(); |
Oops, something went wrong.