WebSocket & Real-Time Architecture
Real-time communication using Socket.IO for live updates and notifications.
Overviewโ
Gauzy uses Socket.IO for real-time features:
- Live time tracker status updates
- Instant notifications
- Real-time dashboard data
- Team activity feeds
Architectureโ
Gateway Setupโ
@WebSocketGateway({
cors: { origin: "*" },
namespace: "/ws",
})
export class NotificationGateway implements OnGatewayConnection {
@WebSocketServer()
server: Server;
handleConnection(client: Socket) {
const user = this.validateToken(client.handshake.auth.token);
client.join(`tenant:${user.tenantId}`);
}
@SubscribeMessage("start-timer")
handleStartTimer(client: Socket, data: any) {
this.server.to(`tenant:${data.tenantId}`).emit("timer-started", data);
}
}
Eventsโ
| Event | Direction | Description |
|---|---|---|
timer-started | Server โ Client | Employee started timer |
timer-stopped | Server โ Client | Employee stopped timer |
screenshot-taken | Server โ Client | New screenshot available |
notification | Server โ Client | New notification |
task-updated | Server โ Client | Task status changed |
Redis Adapter (Multi-Instance)โ
For multi-server deployments, WebSocket events are broadcast through Redis:
import { createAdapter } from "@socket.io/redis-adapter";
const pubClient = new Redis(config.redis);
const subClient = pubClient.duplicate();
server.adapter(createAdapter(pubClient, subClient));
Client Connectionโ
import { io } from "socket.io-client";
const socket = io("wss://api.example.com/ws", {
auth: { token: "jwt-token" },
});
socket.on("notification", (data) => {
console.log("New notification:", data);
});
Related Pagesโ
- Scaling & High Availability โ multi-instance WebSocket
- Redis & Caching โ Redis infrastructure
- Employee Notifications โ notifications