-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest.html
More file actions
176 lines (151 loc) · 6.71 KB
/
test.html
File metadata and controls
176 lines (151 loc) · 6.71 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NumQuest Test</title>
<script src="https://cdn.socket.io/4.7.4/socket.io.min.js"></script>
<style>
body { font-family: Arial, sans-serif; padding: 20px; background: #1a1a1a; color: white; }
.test-section { margin: 20px 0; padding: 20px; border: 1px solid #333; border-radius: 8px; }
button { padding: 10px 20px; margin: 5px; background: #78b95f; color: white; border: none; border-radius: 4px; cursor: pointer; }
input { padding: 8px; margin: 5px; border-radius: 4px; border: 1px solid #333; background: #333; color: white; }
.log { background: #000; padding: 10px; border-radius: 4px; font-family: monospace; max-height: 300px; overflow-y: auto; }
.success { color: #78b95f; }
.error { color: #ff6b6b; }
.info { color: #4ecdc4; }
</style>
</head>
<body>
<h1>🔧 NumQuest Connection Test</h1>
<div class="test-section">
<h3>📡 Socket.IO Connection Test</h3>
<button onclick="testConnection()">Test Connection</button>
<button onclick="disconnect()">Disconnect</button>
<div id="connection-status">Not connected</div>
</div>
<div class="test-section">
<h3>👤 Player Join Test</h3>
<input type="text" id="test-username" placeholder="Username" value="TestUser">
<select id="test-avatar">
<option value="👤">👤 Player</option>
<option value="🎮">🎮 Gamer</option>
<option value="🚀">🚀 Rocket</option>
</select>
<button onclick="testPlayerJoin()">Test Player Join</button>
<div id="player-status">No player data</div>
</div>
<div class="test-section">
<h3>🏠 Room Creation Test</h3>
<button onclick="testCreateRoom()">Test Create Room</button>
<div id="room-status">No room data</div>
</div>
<div class="test-section">
<h3>📋 Console Log</h3>
<button onclick="clearLog()">Clear Log</button>
<div id="log" class="log"></div>
</div>
<script>
let socket = null;
let player = null;
let currentRoom = null;
function log(message, type = 'info') {
const logDiv = document.getElementById('log');
const timestamp = new Date().toLocaleTimeString();
const logEntry = document.createElement('div');
logEntry.className = type;
logEntry.textContent = `[${timestamp}] ${message}`;
logDiv.appendChild(logEntry);
logDiv.scrollTop = logDiv.scrollHeight;
console.log(`[${type.toUpperCase()}] ${message}`);
}
function testConnection() {
log('🔌 Testing Socket.IO connection...', 'info');
try {
socket = io('http://localhost:3000', {
transports: ['websocket', 'polling'],
timeout: 10000
});
socket.on('connect', () => {
log('✅ Connected to server!', 'success');
document.getElementById('connection-status').textContent = 'Connected';
document.getElementById('connection-status').className = 'success';
});
socket.on('connect_error', (error) => {
log(`❌ Connection error: ${error.message}`, 'error');
document.getElementById('connection-status').textContent = `Error: ${error.message}`;
document.getElementById('connection-status').className = 'error';
});
socket.on('disconnect', (reason) => {
log(`❌ Disconnected: ${reason}`, 'error');
document.getElementById('connection-status').textContent = 'Disconnected';
document.getElementById('connection-status').className = 'error';
});
socket.on('player_joined', (playerData) => {
log(`👤 Player joined: ${JSON.stringify(playerData)}`, 'success');
player = playerData;
document.getElementById('player-status').textContent = `Player: ${playerData.username}`;
});
socket.on('room_created', (room) => {
log(`🏠 Room created: ${JSON.stringify(room)}`, 'success');
currentRoom = room;
document.getElementById('room-status').textContent = `Room: ${room.id}`;
});
socket.on('error', (error) => {
log(`❌ Server error: ${error.message}`, 'error');
});
} catch (error) {
log(`❌ Failed to initialize Socket.IO: ${error.message}`, 'error');
}
}
function disconnect() {
if (socket) {
socket.disconnect();
log('🔌 Disconnected from server', 'info');
document.getElementById('connection-status').textContent = 'Disconnected';
document.getElementById('connection-status').className = 'error';
}
}
function testPlayerJoin() {
if (!socket || !socket.connected) {
log('❌ Not connected to server', 'error');
return;
}
const username = document.getElementById('test-username').value.trim();
const avatar = document.getElementById('test-avatar').value;
if (!username) {
log('❌ Please enter a username', 'error');
return;
}
log(`👤 Joining as ${username} with avatar ${avatar}`, 'info');
socket.emit('player_join', { username, avatar });
}
function testCreateRoom() {
if (!socket || !socket.connected) {
log('❌ Not connected to server', 'error');
return;
}
if (!player) {
log('❌ Must join as player first', 'error');
return;
}
log('🏠 Creating test room...', 'info');
socket.emit('create_room', {
mode: 'competitive',
settings: {
maxRounds: 3,
timeLimit: 60,
numberRange: { min: 1, max: 100 }
}
});
}
function clearLog() {
document.getElementById('log').innerHTML = '';
}
// Auto-test connection on page load
window.addEventListener('load', () => {
log('🚀 Page loaded, ready for testing', 'info');
});
</script>
</body>
</html>