-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix inconsistent naming of WebSocket rejections
- Loading branch information
1 parent
68e44fa
commit a1b28fe
Showing
3 changed files
with
61 additions
and
58 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
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 |
---|---|---|
@@ -1,52 +1,52 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Websocket Chat</title> | ||
</head> | ||
<body> | ||
<h1>Websocket Chat Example</h1> | ||
|
||
<input id="username" style="display:block; width:100px; box-sizing: border-box" type="text" placeholder="username"> | ||
<button id="join-chat" type="button">Join Chat</button> | ||
<textarea id="chat" style="display:block; width:600px; height:400px; box-sizing: border-box" cols="30" rows="10"></textarea> | ||
<input id="input" style="display:block; width:600px; box-sizing: border-box" type="text" placeholder="chat"> | ||
|
||
<script> | ||
const username = document.querySelector("#username"); | ||
const join_btn = document.querySelector("#join-chat"); | ||
const textarea = document.querySelector("#chat"); | ||
const input = document.querySelector("#input"); | ||
|
||
join_btn.addEventListener("click", function(e) { | ||
this.disabled = true; | ||
|
||
const websocket = new WebSocket("ws://localhost:3000/websocket"); | ||
|
||
websocket.onopen = function() { | ||
console.log("connection opened"); | ||
websocket.send(username.value); | ||
} | ||
|
||
const btn = this; | ||
|
||
websocket.onclose = function() { | ||
console.log("connection closed"); | ||
btn.disabled = false; | ||
} | ||
|
||
websocket.onmessage = function(e) { | ||
console.log("received message: "+e.data); | ||
textarea.value += e.data+"\r\n"; | ||
} | ||
|
||
input.onkeydown = function(e) { | ||
if (e.key == "Enter") { | ||
websocket.send(input.value); | ||
input.value = ""; | ||
} | ||
} | ||
}); | ||
</script> | ||
</body> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>WebSocket Chat</title> | ||
</head> | ||
<body> | ||
<h1>WebSocket Chat Example</h1> | ||
|
||
<input id="username" style="display:block; width:100px; box-sizing: border-box" type="text" placeholder="username"> | ||
<button id="join-chat" type="button">Join Chat</button> | ||
<textarea id="chat" style="display:block; width:600px; height:400px; box-sizing: border-box" cols="30" rows="10"></textarea> | ||
<input id="input" style="display:block; width:600px; box-sizing: border-box" type="text" placeholder="chat"> | ||
|
||
<script> | ||
const username = document.querySelector("#username"); | ||
const join_btn = document.querySelector("#join-chat"); | ||
const textarea = document.querySelector("#chat"); | ||
const input = document.querySelector("#input"); | ||
|
||
join_btn.addEventListener("click", function(e) { | ||
this.disabled = true; | ||
|
||
const websocket = new WebSocket("ws://localhost:3000/websocket"); | ||
|
||
websocket.onopen = function() { | ||
console.log("connection opened"); | ||
websocket.send(username.value); | ||
} | ||
|
||
const btn = this; | ||
|
||
websocket.onclose = function() { | ||
console.log("connection closed"); | ||
btn.disabled = false; | ||
} | ||
|
||
websocket.onmessage = function(e) { | ||
console.log("received message: "+e.data); | ||
textarea.value += e.data+"\r\n"; | ||
} | ||
|
||
input.onkeydown = function(e) { | ||
if (e.key == "Enter") { | ||
websocket.send(input.value); | ||
input.value = ""; | ||
} | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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