File: index.html

package info (click to toggle)
glaze 6.5.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,948 kB
  • sloc: cpp: 121,839; sh: 99; ansic: 26; makefile: 13
file content (287 lines) | stat: -rw-r--r-- 8,345 bytes parent folder | download
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Glaze WebSocket + HTTP Server</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            margin: 0;
            padding: 20px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
        }

        .container {
            max-width: 900px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }

        .header {
            background: #2c3e50;
            color: white;
            padding: 20px;
            text-align: center;
        }

        .content {
            padding: 20px;
        }

        #messages {
            height: 400px;
            overflow-y: auto;
            border: 2px solid #ecf0f1;
            padding: 15px;
            background: #f8f9fa;
            margin: 20px 0;
            border-radius: 5px;
            font-family: 'Courier New', monospace;
            font-size: 14px;
        }

        .message {
            margin: 8px 0;
            padding: 8px;
            border-radius: 4px;
        }

        .system {
            background: #e8f4fd;
            color: #2980b9;
            border-left: 4px solid #3498db;
        }

        .user {
            background: #e8f5e8;
            color: #27ae60;
            border-left: 4px solid #2ecc71;
        }

        .server {
            background: #fef9e7;
            color: #f39c12;
            border-left: 4px solid #f1c40f;
        }

        .error {
            background: #fadbd8;
            color: #e74c3c;
            border-left: 4px solid #e74c3c;
        }

        .input-group {
            display: flex;
            gap: 10px;
            margin: 20px 0;
        }

        input[type="text"] {
            flex: 1;
            padding: 12px;
            border: 2px solid #bdc3c7;
            border-radius: 5px;
            font-size: 16px;
        }

        input[type="text"]:focus {
            border-color: #3498db;
            outline: none;
        }

        button {
            padding: 12px 20px;
            background: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            transition: background 0.3s;
        }

        button:hover {
            background: #2980b9;
        }

        button:disabled {
            background: #bdc3c7;
            cursor: not-allowed;
        }

        .status {
            padding: 10px;
            border-radius: 5px;
            margin: 10px 0;
            font-weight: bold;
        }

        .connected {
            background: #d5f4e6;
            color: #27ae60;
        }

        .disconnected {
            background: #fadbd8;
            color: #e74c3c;
        }

        .commands {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 5px;
            margin: 20px 0;
        }

        .commands h3 {
            margin-top: 0;
        }

        .commands code {
            background: #e9ecef;
            padding: 2px 6px;
            border-radius: 3px;
            font-family: 'Courier New', monospace;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="header">
            <h1>🚀 Glaze WebSocket + HTTP Server</h1>
            <p>Real-time communication with header-only C++ WebSocket implementation</p>
        </div>

        <div class="content">
            <div id="status" class="status disconnected">🔴 Disconnected</div>

            <div class="commands">
                <h3>Available Commands:</h3>
                <ul>
                    <li><code>/ping</code> - Send a ping to the server</li>
                    <li><code>/clients</code> - Get number of connected clients</li>
                    <li><code>/echo [message]</code> - Echo a message back</li>
                    <li>Any other text will be broadcast to all clients</li>
                </ul>
            </div>

            <div id="messages"></div>

            <div class="input-group">
                <input id="messageInput" type="text" placeholder="Type your message here..." disabled />
                <button id="sendButton" onclick="sendMessage()" disabled>Send</button>
                <button onclick="sendPing()">Ping</button>
                <button onclick="getClientCount()">Count</button>
            </div>
        </div>
    </div>

    <script>
        let ws;
        const messages = document.getElementById('messages');
        const input = document.getElementById('messageInput');
        const sendButton = document.getElementById('sendButton');
        const status = document.getElementById('status');

        function addMessage(text, type = 'system') {
            const div = document.createElement('div');
            div.className = 'message ' + type;
            const timestamp = new Date().toLocaleTimeString();
            div.innerHTML = `<strong>${timestamp}</strong> - ${text}`;
            messages.appendChild(div);
            messages.scrollTop = messages.scrollHeight;
        }

        function updateStatus(connected) {
            if (connected) {
                status.textContent = '🟢 Connected to WebSocket server';
                status.className = 'status connected';
                input.disabled = false;
                sendButton.disabled = false;
            } else {
                status.textContent = '🔴 Disconnected from server';
                status.className = 'status disconnected';
                input.disabled = true;
                sendButton.disabled = true;
            }
        }

        function connect() {
            try {
                addMessage('🔄 Connecting to WebSocket server...', 'system');
                ws = new WebSocket('ws://localhost:8080/ws');

                ws.onopen = function () {
                    addMessage('✅ Connected successfully!', 'system');
                    updateStatus(true);
                };

                ws.onmessage = function (event) {
                    if (event.data.startsWith('📢')) {
                        addMessage(event.data, 'system');
                    } else if (event.data.startsWith('🔄') || event.data.startsWith('🏓') || event.data.startsWith('👥')) {
                        addMessage(event.data, 'server');
                    } else {
                        addMessage(event.data, 'server');
                    }
                };

                ws.onclose = function () {
                    addMessage('❌ Connection closed. Attempting to reconnect in 3 seconds...', 'system');
                    updateStatus(false);
                    setTimeout(connect, 3000);
                };

                ws.onerror = function () {
                    addMessage('🚨 Connection error occurred', 'error');
                };

            } catch (error) {
                addMessage('❌ Failed to connect: ' + error.message, 'error');
                setTimeout(connect, 5000);
            }
        }

        function sendMessage() {
            if (ws && ws.readyState === WebSocket.OPEN && input.value.trim()) {
                const message = input.value.trim();
                ws.send(message);
                addMessage('You: ' + message, 'user');
                input.value = '';
            }
        }

        function sendPing() {
            if (ws && ws.readyState === WebSocket.OPEN) {
                ws.send('/ping');
                addMessage('You: /ping', 'user');
            }
        }

        function getClientCount() {
            if (ws && ws.readyState === WebSocket.OPEN) {
                ws.send('/clients');
                addMessage('You: /clients', 'user');
            }
        }

        // Event listeners
        input.addEventListener('keypress', function (e) {
            if (e.key === 'Enter') {
                sendMessage();
            }
        });

        // Auto-connect on page load
        connect();
    </script>
</body>

</html>