# Hi2Chat Build 03.1 - Real-Time Foundation

## Added

- Socket.IO realtime gateway
- JWT-authenticated websocket connections
- Online/offline presence events
- Last seen update on disconnect
- Lobby join/leave events
- Typing start/stop events
- Presence REST endpoints

## New REST APIs

- `GET /api/v1/presence/online`
- `GET /api/v1/presence/last-seen`
- `GET /api/v1/presence/top-ranked`

## WebSocket Namespace

- `ws://localhost:3000/realtime`

## WebSocket Auth

Send JWT token after login:

```js
const socket = io('http://localhost:3000/realtime', {
  auth: { token: 'YOUR_ACCESS_TOKEN' },
});
```

## Events

Client sends:

- `presence:ping`
- `presence:list`
- `lobby:join`
- `lobby:leave`
- `typing:start`
- `typing:stop`

Server emits:

- `connection:success`
- `connection:error`
- `presence:online`
- `presence:offline`
- `lobby:user-joined`
- `lobby:user-left`
- `typing:start`
- `typing:stop`

## Install

```bash
npm install
npm run build
npx tsc --noEmit
npm run start:dev
```

## Required dependencies added

- `@nestjs/websockets`
- `@nestjs/platform-socket.io`
- `socket.io`

## Git commit

```bash
git add .
git commit -m "Build 03.1 - Realtime foundation with Socket.IO presence"
git push
```
