diff --git a/public/index.html b/public/index.html index be5e2de..72ad5d7 100755 --- a/public/index.html +++ b/public/index.html @@ -54,6 +54,7 @@ + diff --git a/public/scripts/client-info.js b/public/scripts/client-info.js new file mode 100755 index 0000000..b31a0bb --- /dev/null +++ b/public/scripts/client-info.js @@ -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}`); +}); diff --git a/src/player-connection.ts b/src/player-connection.ts index eb5627a..d95a512 100755 --- a/src/player-connection.ts +++ b/src/player-connection.ts @@ -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, + }), + ); } }