UNPKG

wsmini

Version:

Minimalist WebSocket client and server for real-time applications with RPC, PubSub, Rooms and Game state synchronization.

108 lines 2.43 kB
<!DOCTYPE html> <html> <head> <meta charset='utf-8'> <title>Rooms</title> <meta name='viewport' content='width=device-width, initial-scale=1'> <script src='rooms.js' type="module"></script> <style> * { box-sizing: border-box; font-family: Consolas, 'Courier New', Courier, monospace; } body, the-lobby, the-room { 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; } #chat { overflow-y: auto; height: 100%; width: 100%; } #message { width: 100% } p { margin: 0 } #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 } </style> </head> <body> <the-lobby> <h1>Rooms</h1> <form id="room-form"> <input id="name" type="text"> <button>Create a room</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> <div id="chat"></div> <div id="users"> In the room: <the-users-list></the-users-list> </div> <form id="chat-form"> <input id="message" type="text"> <button>Send</button> </form> <div> <button id="leave">Exit</button> </div> </the-room> </body> </html>