Skip to content

Commit 6cfd98b

Browse files
committed
Add socket events to the client code
1 parent 6b25bac commit 6cfd98b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@
2525
socket.onopen = (e) => console.log('Connected to ' + e.target.url)
2626
// The client get a message
2727
socket.onmessage = (e) => addMessage(e.data)
28+
// The connection is closing
29+
socket.onclose = (e) => {
30+
if (e.wasClean) console.log(`Connection closed cleanly, code=${event.code} reason=${event.reason}`)
31+
else console.error('Connection die !', e)
32+
}
33+
// A socket error is occured
34+
socket.onerror = (e) => {
35+
console.error('An error is occured !', e)
36+
alert(`Error : ${error.message}`)
37+
}
2838

2939
// Send message from the form
3040
document.getElementById(FORM_ID).onsubmit = (e) => {

0 commit comments

Comments
 (0)