Implement sending info messages to client
This commit is contained in:
parent
fcc2bdd5f0
commit
23d99b2758
|
@ -54,6 +54,7 @@
|
|||
<script src="scripts/handle-redirects.js"></script>
|
||||
<script src="scripts/make-sounds.js"></script>
|
||||
<script src="scripts/make-animations.js"></script>
|
||||
<script src="scripts/client-info.js"></script>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
document.addEventListener('htmx:wsAfterMessage', function (e) {
|
||||
let msg;
|
||||
try {
|
||||
msg = JSON.parse(e.detail.message);
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
if (msg.type !== 'client-info') {
|
||||
return;
|
||||
}
|
||||
console.log(`Message from server: ${msg.message}`);
|
||||
});
|
|
@ -15,6 +15,11 @@ export class PlayerConnection {
|
|||
|
||||
public sendMessage(severity: 'info' | 'error', message: string) {
|
||||
console.log(`Sending message ${message} to player ${this.id}`);
|
||||
// TODO
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
type: 'client-info',
|
||||
message: message,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue