Add user prefix.

This commit is contained in:
emil28092005
2026-01-14 02:48:16 +03:00
parent 975aea12c9
commit ad38c6aeed
6 changed files with 39 additions and 16 deletions
+4 -3
View File
@@ -21,21 +21,22 @@
}
input { padding: 8px; width: 300px; }
button { padding: 8px 15px; cursor: pointer; }
select { padding: 8px; width: 320px; } /* ← для комнат */
select { padding: 8px; width: 320px; }
#roomsList { margin: 10px 0; }
</style>
</head>
<body>
<h1>📱 Shagram Chat</h1>
<!-- ← НОВЫЙ БЛОК С КОМНАТАМИ -->
<div id="roomsList">
<select id="roomSelect">
<option value="general">general</option>
</select>
<button onclick="loadRooms()">🔄 Refresh</button>
<input type="text" id="userInput" placeholder="Your name" value="Эмиль" maxlength="20">
<button onclick="loadRooms()">🔄</button>
<button onclick="connectRoom()">Connect</button>
</div>
<div id="messages"></div>
+7 -1
View File
@@ -88,12 +88,18 @@ function connectRoom() {
function sendMessage() {
const text = messageInput.value.trim();
const usernameInput = document.getElementById('userInput');
const username = usernameInput ? usernameInput.value.trim() || 'Anonymous' : 'Anonymous';
if (!text || !ws || ws.readyState !== WebSocket.OPEN) {
alert('Not connected or empty message');
return;
}
ws.send(JSON.stringify({text: text}));
ws.send(JSON.stringify({
text: text,
user: username,
}));
messageInput.value = '';
}