-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-socket.js
More file actions
45 lines (36 loc) · 1.09 KB
/
test-socket.js
File metadata and controls
45 lines (36 loc) · 1.09 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
const { io } = require('socket.io-client');
console.log('Testing socket connection...');
const socket = io('http://localhost:5000', {
forceNew: true,
transports: ['websocket', 'polling'],
timeout: 5000
});
socket.on('connect', () => {
console.log('✅ Socket connected successfully:', socket.id);
socket.emit('join', { roomId: 'test-room', username: 'test-user' });
});
socket.on('connect_error', (error) => {
console.error('❌ Socket connection error:', error);
});
socket.on('disconnect', (reason) => {
console.log('🔌 Socket disconnected:', reason);
});
socket.on('joined', (data) => {
console.log('👥 Joined room:', data);
});
socket.on('code-change', (data) => {
console.log('📝 Code change received:', data);
});
// Test code change
setTimeout(() => {
if (socket.connected) {
console.log('📤 Sending test code change...');
socket.emit('code-change', { roomId: 'test-room', code: 'console.log("Hello World");' });
}
}, 2000);
// Clean up after 10 seconds
setTimeout(() => {
console.log('🧹 Cleaning up...');
socket.disconnect();
process.exit(0);
}, 10000);