# Socket.io İletişim - FikoYT

## 🔗 Mimari

**Real-time Communication:**
- **Framework:** Socket.io
- **Backend:** Go Fiber integration
- **Frontend:** Angular service
- **Port:** 9000

## 📡 Client Service

**SocketFikoYT:**
```typescript
export class SocketFikoYT extends Socket {
    bagli: WritableSignal<boolean> = signal(false);
    nameSpaces = new Map();

    // Connection headers
    extraHeaders: {
        uygulama: "FikoYT Yeni Çağ",
        cihaz_kimlik: string,
        kullanici_kimlik: string,
        cihaz_tipi: "desktop|mobile|tablet"
    }
}
```

## 🔄 Event Handling

**Connection Management:**
```typescript
// Connect
this.fromEvent('connect').subscribe(() => {
    this.bagli.set(true);
    await this.gonder("FikoYT.sistem.io.cihaz.baglandi");
});

// Disconnect
this.fromEvent('disconnect').subscribe(() => {
    this.bagli.set(false);
});
```

**Send/Receive:**
```typescript
// Send with acknowledgment
async gonder<T>(eventName: string, data: any): Promise<T> {
    const FikoYTData = {
        "FikoYT": {
            kullanici_kimlik: this.FikoYT.kimlik.aktifKullaniciJson()?._id,
            cihaz_kimlik: this.FikoYT.cihaz.kimlik,
            uygulama: "FikoYT Yeni Çağ"
        }
    };
    return await super.emitWithAck(eventName, data, FikoYTData);
}

// Listen events
this.fromEvent("FikoYT.sistem.cihaz.bağlandı.toplamlar")
    .subscribe(data => this.kimlik.cihazlar.set(data[0]));
```

## 🏠 Namespace System

**Dynamic Namespaces:**
```typescript
override of(namespace: string) {
    if (this.nameSpaces.has(namespace)) {
        return this.nameSpaces.get(namespace);
    }

    const socket = new Socket({
        url: 'http://localhost:9000/' + namespace,
        options: { extraHeaders }
    });

    this.nameSpaces.set(namespace, socket);
    return socket;
}
```

## 👥 Multi-Device Support

**Device Tracking:**
- **Cihaz Kimlik:** UUID based
- **Session:** MongoDB backed
- **Type:** Desktop/mobile/tablet
- **Authentication:** User + device level

## ⚡ Real-time Features

**3D Collaboration:**
- Model synchronization
- Shared cursors
- Selection sync
- Camera view sharing

## ⚠️ Kritik

- **Authentication:** Required
- **Port:** 9000
- **CORS:** Configured
- **Timeout:** 30s

---
2025-11-06
