-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadminchat.html
72 lines (64 loc) · 1.93 KB
/
adminchat.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/adminchat.css">
<title>Admin Chat</title>
</head>
<body>
<!-- Admin Dashboard HTML -->
<div class="admin-container">
<div class="admin-header">
<h1>Admin Dashboard</h1>
</div>
<div class="chat-section">
<h2>Active Chats</h2>
<ul id="chat-list">
<!-- Chat conversations will be listed here -->
</ul>
</div>
<div class="chat-box" id="admin-chat-box">
<div class="chat-header">
<h3>Chat with User</h3>
</div>
<div class="chat-body" id="admin-chat-body">
<!-- Messages will appear here -->
</div>
<div class="chat-footer">
<input type="text" id="admin-message-input" placeholder="Type your message...">
<button onclick="sendAdminMessage()">Send</button>
</div>
</div>
</div>
<script>
const ws = new WebSocket("ws://localhost:9090");
// Event listener for incoming messages
ws.onmessage = function(event) {
const chat = document.getElementById("chat");
chat.innerHTML += `<p>Client: ${event.data}</p>`;
chat.scrollTop = chat.scrollHeight; // Scroll to the bottom
};
// Function to send messages
function sendAdminMessage() {
const adminMessageInput = document.getElementById("admin-message-input");
if (adminMessageInput.value) {
ws.send("Admin: " + adminMessageInput.value);
adminMessageInput.value = '';
}
}
ws.onopen = function() {
console.log("Connected to WebSocket server.");
};
ws.onmessage = function(event) {
console.log("Message received: " + event.data);
};
ws.onerror = function(error) {
console.error("WebSocket error: ", error);
};
ws.onclose = function(event) {
console.log("WebSocket connection closed: ", event.reason);
};
</script>
</body>
</html>