Pussy
This commit is contained in:
parent
8202a8b88d
commit
56b6f0e138
43
frontend/static/js/views/Chat.js
Normal file
43
frontend/static/js/views/Chat.js
Normal file
@ -0,0 +1,43 @@
|
||||
import AbstractView from "./AbstractView.js";
|
||||
|
||||
export default class extends AbstractView {
|
||||
constructor(params) {
|
||||
super(params);
|
||||
this.setTitle("Chat");
|
||||
|
||||
let url = `ws://${window.location.host}/ws/socket-server/`
|
||||
|
||||
this.chatSocket = new WebSocket(url)
|
||||
this.chatSocket.onmessage = function(e){
|
||||
let data = JSON.parse(e.data)
|
||||
console.log('Data:', data)
|
||||
}
|
||||
}
|
||||
|
||||
async postInit() {
|
||||
let form = document.getElementById('form')
|
||||
form.addEventListener('submit', (e)=> {
|
||||
e.preventDefault()
|
||||
let message = e.target.message.value
|
||||
this.chatSocket.send(JSON.stringify({
|
||||
'message':message
|
||||
}))
|
||||
form.reset()
|
||||
})
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
return `
|
||||
<h1>Chat</h1>
|
||||
|
||||
<form id="form">
|
||||
<input type="text" name="message" />
|
||||
</form>
|
||||
|
||||
<div id="messages">
|
||||
|
||||
</div>
|
||||
|
||||
`;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user