wsmini
Version:
Minimalist WebSocket client and server for real-time applications with RPC, PubSub, Rooms and Game state synchronization.
119 lines • 2.81 kB
HTML
<html>
<head>
<meta charset='utf-8'>
<title>Games</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script src='gamesWithInterpolation.js' type="module"></script>
<style>
* {
box-sizing: border-box;
font-family: Consolas, 'Courier New', Courier, monospace;
}
body, the-lobby {
display: flex;
flex-direction: column;
height: calc(100dvh - 3rem);
justify-content: space-between;
background-color: #333;
color: #fff;
}
h1 {
text-align: center;
text-transform: uppercase;
}
#users { margin: 0.5rem 0 }
a-user::before { content: '[' }
a-user::after { content: ']' }
input {
background-color: #555;
color: #fff;
border: none;
padding: 0.5rem;
}
button {
background-color: #007bff;
color: #fff;
border: none;
padding: 0.5rem;
margin: 0.5rem 0;
cursor: pointer;
}
#leave {
background-color: #dc3545;
}
the-listing {
padding: 0.5rem;
overflow-y: auto;
height: 100%;
width: 100%;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border-bottom: 1px solid #555;
padding: 0.5rem;
text-align: left;
}
.hidden { display: none }
the-room {
display: grid;
grid-template-rows: 1fr 5fr 3fr;
gap: 1rem;
height: 100vh;
max-height: 100vh;
padding: 1rem;
}
the-game, #users {
justify-self: center;
align-self: center;
display: flex;
gap: 1rem;
justify-content: center;
align-items: center;
}
canvas {
width: min(calc(100vh - 13rem), calc(100vw - 13rem));
height: min(calc(100vh - 13rem), calc(100vw - 13rem));
background-color: #222;
box-shadow: 0 0 2rem #222;
}
</style>
</head>
<body>
<the-lobby>
<h1>Games</h1>
<form id="room-form">
<input id="name" type="text" required placeholder="Room name">
<button>Create a game</button>
<error-message></error-message>
</form>
<the-listing>
<table id="room-listing">
<thead>
<tr>
<th>Name</th>
<th>Users</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</the-listing>
</the-lobby>
<the-room class="hidden">
<h1 id="room-name"></h1>
<the-game>
<canvas id="game"></canvas>
</the-game>
<div id="users">
Players:
<the-users-list></the-users-list>
<button id="leave">Exit</button>
</div>
</the-room>
</body>
</html>