Minor Edit and clear one file
This commit is contained in:
parent
c16d281892
commit
7b6a8ba57b
@ -31,6 +31,7 @@ class ChatConsumer(WebsocketConsumer):
|
||||
|
||||
self.send(text_data=json.dumps({
|
||||
'type':'chat',
|
||||
'username':self.scope["user"].pk,
|
||||
'message':message
|
||||
}))
|
||||
|
||||
|
@ -14,8 +14,9 @@ export default class extends AbstractView {
|
||||
if (data.type === 'chat') {
|
||||
let messages = document.getElementById('messages')
|
||||
|
||||
let username = data.username === null ? "NoName" : data.username;
|
||||
messages.insertAdjacentHTML('beforeend', `
|
||||
<div><p>${data.message}</p></div>
|
||||
<div><p>${username}: ${data.message}</p></div>
|
||||
`)
|
||||
}
|
||||
|
||||
@ -32,6 +33,7 @@ export default class extends AbstractView {
|
||||
}))
|
||||
form.reset()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
|
@ -1,24 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8'>
|
||||
<title>Chat</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Chat</h1>
|
||||
|
||||
<form id="form">
|
||||
<input type="text" name="message" />
|
||||
</form>
|
||||
|
||||
<script type="text/javascript">
|
||||
let url = `ws://${window.location.host}/ws/socket-server/`
|
||||
|
||||
const chatSocket = new WebSocket(url)
|
||||
chatSocket.onmessage = function(e){
|
||||
let data = JSON.parse(e.data)
|
||||
console.log('Data:', data)
|
||||
}
|
||||
|
||||
</script>
|
||||
</b
|
Loading…
Reference in New Issue
Block a user