Complete implementation ready for Coolify: - Node.js 22 + Fastify + socket.io backend - PostgreSQL 16 + Redis 7 services - Docker Compose configuration - Deployment scripts and documentation Co-Authored-By: Paperclip <noreply@paperclip.ing>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
#!/usr/bin/env tsx
|
|
import { io } from 'socket.io-client';
|
|
|
|
// Manual socket.io client test for J4
|
|
// Usage: npm run dev (in one terminal), then tsx scripts/test-socket-client.ts <jwt>
|
|
// To get a JWT: curl -X POST http://localhost:3000/api/v1/sessions -H 'Content-Type: application/json' -d '{"apiToken": "ah_live_XXXX_..."}'
|
|
|
|
const jwt = process.argv[2];
|
|
if (!jwt) {
|
|
console.error('Usage: tsx scripts/test-socket-client.ts <jwt>');
|
|
process.exit(1);
|
|
}
|
|
|
|
const socket = io('http://localhost:3000/agents', {
|
|
auth: { jwt },
|
|
});
|
|
|
|
socket.on('connect', () => {
|
|
console.log('✅ Connected to /agents namespace');
|
|
});
|
|
|
|
socket.on('agent:hello-ack', (payload) => {
|
|
console.log('✅ Received agent:hello-ack:', JSON.stringify(payload, null, 2));
|
|
});
|
|
|
|
socket.on('presence:update', (payload) => {
|
|
console.log('👁️ Received presence:update:', JSON.stringify(payload, null, 2));
|
|
});
|
|
|
|
socket.on('error', (payload) => {
|
|
console.error('❌ Received error:', JSON.stringify(payload, null, 2));
|
|
});
|
|
|
|
socket.on('connect_error', (err) => {
|
|
console.error('❌ Connection error:', err.message);
|
|
process.exit(1);
|
|
});
|
|
|
|
socket.on('disconnect', (reason) => {
|
|
console.log('🔌 Disconnected:', reason);
|
|
});
|
|
|
|
// Test room:join with a non-existent room (should fail)
|
|
setTimeout(() => {
|
|
console.log('\n🧪 Testing room:join with invalid room...');
|
|
socket.emit('room:join', {
|
|
roomId: '00000000-0000-0000-0000-000000000000',
|
|
requestId: 'test-req-1',
|
|
});
|
|
}, 2000);
|
|
|
|
// Keep alive
|
|
process.on('SIGINT', () => {
|
|
console.log('\n👋 Disconnecting...');
|
|
socket.disconnect();
|
|
process.exit(0);
|
|
});
|