Nicer message when you are alone, fix server URL

This commit is contained in:
arne 2024-03-23 22:31:34 +01:00
commit 706a92a9a6

View file

@ -2,7 +2,7 @@ import './style.css'
const presenceInfo = document.querySelector<HTMLDivElement>('#presence-info')! const presenceInfo = document.querySelector<HTMLDivElement>('#presence-info')!
const canvas = document.querySelector<HTMLCanvasElement>('#canvas')! const canvas = document.querySelector<HTMLCanvasElement>('#canvas')!
const socket = new WebSocket(`ws://${window.location.hostname}:3000`) const socket = new WebSocket(`${window.location.protocol.replace('http', 'ws')}//${window.location.hostname}/server`)
type Message = type Message =
| { type: 'presence-information', others: number } | { type: 'presence-information', others: number }
@ -95,7 +95,7 @@ socket.addEventListener('message', (e) => {
state.others = data.others state.others = data.others
// TODO: Would be nicer to have this DOM update elsewhere // TODO: Would be nicer to have this DOM update elsewhere
presenceInfo.innerText = 'You see a pond. ' + (state.others === 0 presenceInfo.innerText = 'You see a pond. ' + (state.others === 0
? 'You are currently alone here.' ? 'The place is empty and quiet.'
: state.others === 1 : state.others === 1
? 'Somebody else is also here.' ? 'Somebody else is also here.'
: `There are ${state.others} others with you.`) : `There are ${state.others} others with you.`)