-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.html
More file actions
191 lines (167 loc) · 5.33 KB
/
message.html
File metadata and controls
191 lines (167 loc) · 5.33 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Chat</title>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600&family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<style>
/* General styling for the body */
body {
font-family: 'Open Sans', sans-serif;
margin: 0;
padding: 0;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-direction: column;
position: relative;
background: url('img/background-image.png') no-repeat center center fixed; /* Page background image (PNG) */
background-size: cover; /* Ensures the image covers the entire page */
}
/* Chat box styling */
#chat-box {
width: 100%;
max-width: 600px;
background-color: rgba(5, 108, 234, 0.8); /* Transparent background */
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
overflow: hidden;
backdrop-filter: blur(10px); /* Adds a frosted-glass effect */
background: url('img/chatbox-background.png') no-repeat center center fixed; /* Chatbox background image (PNG) */
background-size: cover;
}
/* The rest of your CSS remains unchanged */
#messages {
padding: 20px;
height: 400px;
overflow-y: auto;
background-color: #0d67e3;
border-bottom: 1px solid #0d67e3;
flex-grow: 1;
}
#messages div {
background-color: #0d67e3;
border-radius: 15px;
padding: 10px;
margin-bottom: 10px;
max-width: 80%;
box-sizing: border-box;
transition: background-color 0.3s ease;
}
#messages .user-message {
background-color: #2b066b;
color: #f8f8fa;
margin-left: auto;
}
#messages .bot-message {
background-color: #2196F3;
color: #0d67e3;
margin-right: auto;
}
#input-area {
display: flex;
padding: 15px;
border-top: 1px solid #0d67e3;
background-color: #0d67e3;
box-sizing: border-box;
}
#input-area input {
flex: 1;
padding: 10px;
font-size: 16px;
border: 1px solid #0946ef;
border-radius: 30px;
outline: none;
transition: border-color 0.3s ease;
}
#input-area input:focus {
border-color: #4CAF50;
}
#input-area button {
padding: 10px 20px;
background-color: #21184e;
color: white;
border: none;
border-radius: 30px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
#input-area button:hover {
background-color: #21184e;
}
#messages::-webkit-scrollbar {
width: 8px;
}
#messages::-webkit-scrollbar-thumb {
background-color: hwb(122 30% 31%);
border-radius: 4px;
}
#messages::-webkit-scrollbar-thumb:hover {
background-color: #21184e;
}
.typing-indicator {
font-style: italic;
color: #aaa;
margin-left: 10px;
margin-top: 10px;
animation: typing 1s steps(4) infinite;
}
@keyframes typing {
0% { content: ''; }
50% { content: '.'; }
100% { content: '..'; }
}
</style>
</head>
<body>
<div id="chat-box">
<div id="messages"></div>
<div class="typing-indicator" id="typing-indicator"></div>
<div id="input-area">
<input id="message" type="text" placeholder="Type a message..." />
<button id="send">Send</button>
</div>
</div>
<!-- Include Socket.IO client library -->
<script src="https://cdn.socket.io/4.5.1/socket.io.min.js"></script>
<script>
// Connect to the server via Socket.IO
const socket = io();
const sendButton = document.getElementById('send');
const messageInput = document.getElementById('message');
const messagesDiv = document.getElementById('messages');
const typingIndicator = document.getElementById('typing-indicator');
// Show typing indicator when the user is typing
messageInput.addEventListener('input', () => {
socket.emit('typing', true);
});
// Send message when 'Send' button is clicked
sendButton.addEventListener('click', () => {
const message = messageInput.value;
if (message.trim()) {
socket.emit('chat message', message); // Send message to server
messageInput.value = ''; // Clear input field
socket.emit('typing', false); // Stop typing indicator
}
});
// Listen for messages from the server and display them
socket.on('chat message', (msg, isUserMessage) => {
const msgElement = document.createElement('div');
msgElement.textContent = msg;
msgElement.classList.add(isUserMessage ? 'user-message' : 'bot-message');
messagesDiv.appendChild(msgElement);
messagesDiv.scrollTop = messagesDiv.scrollHeight; // Scroll to the bottom
});
// Listen for typing indicator events from the server
socket.on('typing', (isTyping) => {
typingIndicator.style.display = isTyping ? 'block' : 'none';
});
</script>
</body>
</html>