#35: README — Go engine + yeni SDK yapısı

- /script → /sdk/index.js ES modül import örnekleri
- WebRTC API kullanım örneği (connect/addStream/track/sendFile)
- Studio UI kullanım örneği
- Env değişkenleri tablosu (MWSE_HOST/PORT/PUBLIC_DIR/SDK_DIR vs.)
- Mimari şeması: sdk/webrtc/ ve sdk/studio/ alt klasörleriyle güncellendi
- Durum tablosu: sanal IP alt ağı, WebRTC kütüphanesi, Studio UI eklendi
- TypeScript / npm / Parcel referansları kaldırıldı

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
abdussamedulutas 2026-06-17 13:05:38 +03:00
parent 777f422873
commit 0d21d8c8b3
1 changed files with 102 additions and 49 deletions

151
README.md
View File

@ -8,12 +8,12 @@ görüşme yazılımları için gerçek zamanlı altyapı sağlamak amacıyla ku
Sunucu cihazları sanallaştırdığı için eşler birbirlerinin gerçek IP adresini veya
cihaz bilgisini bilmeden düşük gecikmeli, çift yönlü iletişim kurabilir.
## Durum (Go engine, v0.1.0 paritesi ✅)
## Durum (Go engine, v1.0.0)
Motor Node.js'ten **Go** ile yeniden yazıldı. Concurrency modeli goroutine +
`sync.RWMutex` + bağlantı başına tek-yazıcı (actor) deseni üzerine kuruludur;
Node.js'teki "leave-while-send" race condition ve EventPool promise takılması
(#33) giderildi.
Node.js'teki "leave-while-send" race condition ve EventPool promise takılması (#33)
giderildi. Yük testi: 150 bağlantı, ~210 k msg/s relay, RSS ~43 MB.
| Özellik | Durum |
|---|---|
@ -24,40 +24,38 @@ Node.js'teki "leave-while-send" race condition ve EventPool promise takılması
| Veri senkronizasyonu (data/sync, sync/pool) | ✅ |
| Bildirim + suit yanıtı (notify/send, notify/reply) | ✅ |
| 3. parti sunucu köprüsü (bridge) | ✅ |
| Sanal IP / numara / kısa kod + alt ağ | ✅ |
| WebRTC kütüphanesi (perfect negotiation, çoklu track) | ✅ |
| Studio UI (Miller kolonlar) | ✅ |
| İkili çerçeveleme (binary framing) | ⏳ 2.5.0 |
| Studio (akış/WebRTC sunucusu) | ⏳ 2.0.0 |
| SRS entegrasyonu (binlerce izleyici) | ⏳ 2.0.0 |
## Kurulum ve çalıştırma
### Gereksinimler
- Go 1.22+
- (Opsiyonel) TypeScript — SDK derlemek için `npm run build`
### Sunucuyu başlat
```bash
# Bağımlılıklar
go mod tidy
# Çalıştır (varsayılan: 0.0.0.0:7707)
go run .
# Yapılandırma env değişkenleriyle:
MWSE_ADDR=:8080 \
MWSE_OUTBOUND_BUFFER=2048 \
MWSE_MAX_MESSAGE_SIZE=33554432 \
go run .
# Varsayılan: 0.0.0.0:7707
```
### Ortam değişkenleri
| Değişken | Varsayılan | Açıklama |
|---|---|---|
| `MWSE_ADDR` | `:7707` | Dinleme adresi |
| `MWSE_HOST` | `0.0.0.0` | Bind adresi |
| `MWSE_PORT` | `7707` | Dinleme portu |
| `MWSE_PUBLIC_DIR` | `./public` | Statik dosyalar (`/status.xml` vb.) |
| `MWSE_SDK_DIR` | `./sdk` | ES modül SDK (`/sdk/`) |
| `MWSE_OUTBOUND_BUFFER` | `1024` | Bağlantı başına gönderim kuyruğu |
| `MWSE_MAX_MESSAGE_SIZE` | `16777216` | Maksimum gelen frame boyutu (bayt) |
| `MWSE_PING_INTERVAL` | `10s` | Heartbeat ping aralığı |
| `MWSE_SHUTDOWN_TIMEOUT` | `10s` | Graceful shutdown bekleme süresi |
| `BRIDGE_APPROVE_URL` | — | Bağlantı onay URL'i (3. parti köprü) |
| `BRIDGE_TRIGGER_URL` | — | Suit yanıtı push URL'i |
| `BRIDGE_INBOX` | — | `1` ile inbox'ı etkinleştir |
@ -70,22 +68,17 @@ go test -race ./...
## Frontend SDK entegrasyonu
SDK, TypeScript ile yazılmış ve derlenmiş JavaScript olarak `/script`
endpoint'inden sunulur. Herhangi bir bundler gerekmez.
SDK saf vanilla ES modülü olarak `/sdk/` endpoint'inden sunulur. Bundler gerekmez;
native `import` ile çalışır.
```html
<!-- Sunucu çalışırken -->
<script src="http://localhost:7707/script"></script>
<script type="module">
import MWSE from 'http://localhost:7707/sdk/index.js';
<script>
const mwse = new MWSE({
endpoint: "ws://localhost:7707",
autoReconnect: true
});
const mwse = new MWSE(); // endpoint: otomatik aynı sunucudan
mwse.on('scope', async () => {
console.log('Bağlandı:', mwse.me.socketId);
// Oda oluştur / katıl
const room = mwse.room({ name: 'genel', joinType: 'free', ifexistsJoin: true });
await room.createRoom();
room.on('message', (pack, peer) => console.log(peer.socketId, ':', pack));
@ -94,20 +87,60 @@ mwse.on('scope', async () => {
</script>
```
### WebRTC (P2P ses/video/dosya)
```js
import MWSE from '/sdk/index.js';
import { MediaSources } from '/sdk/webrtc/index.js';
const mwse = new MWSE();
mwse.me.on('accepted/pair', async peer => {
const polite = mwse.me.socketId < peer.socketId;
peer.rtc.connect({ polite });
// Kamera + mikrofon
const stream = await MediaSources.cameraAndMic();
peer.rtc.addStream('cam', stream);
// Gelen video/ses
peer.rtc.on('track', (track, streams) => {
const video = document.createElement('video');
video.srcObject = streams[0];
video.autoplay = true;
document.body.appendChild(video);
});
// Dosya gönderme
await peer.rtc.sendFile(file);
});
```
### Studio UI
```js
import MWSE from '/sdk/index.js';
import Studio from '/sdk/studio/index.js';
const mwse = new MWSE();
const studio = new Studio(mwse, '#app');
mwse.on('scope', () => studio.mount());
```
## Demo dosyaları
| Demo | Yol | Açıklama |
Sunucu çalışırken `http://localhost:7707/demos/` altında:
| Demo | Dosya | Açıklama |
|---|---|---|
| Chat | `/demos/chat.html` | ~20 satır JS ile odalı sohbet |
| Sesli görüşme | `/demos/audio.html` | P2P WebRTC ses (eşler arası) |
| Video görüşme | `/demos/video.html` | P2P WebRTC video (kamera ızgara görünümü) |
| Chat | `chat.html` | ~20 satır JS ile odalı gerçek zamanlı sohbet |
| Sesli görüşme | `audio.html` | P2P WebRTC mikrofon (çift yönlü) |
| Video görüşme | `video.html` | P2P WebRTC kamera ızgara görünümü |
## API kontrolü (/api)
API anahtarı al, sonra kullan:
```bash
# Anahtar al
# API anahtarı al
KEY=$(curl -s -X POST localhost:7707/api/auth/key \
-H 'Content-Type: application/json' \
-d '{"domain":"myapp"}' | jq -r .key)
@ -129,33 +162,53 @@ curl -s -X POST localhost:7707/api/bridge/inbox \
## Mimari
```
Client (WebSocket)
Tarayıcı (WebSocket)
ws.Hub (router + registry)
├─ services/auth.go Pairing, IP adresi, erişilebilirlik
├─ services/room.go Oda oluşturma / yönetimi
ws.Hub — router + client registry
├─ services/yourid.go Bağlantıılınca wsts/hello + id sinyalleri
├─ services/auth.go Pairing, erişilebilirlik
├─ services/room.go Oda oluşturma / yönetimi
├─ services/datatransfer.go pack/to, request/to, response/to tünelleri
├─ services/notify.go Store-and-forward bildirim + suit yanıtı
├─ services/datastore.go Aktif senkronizasyon (CRUD broadcast)
│ Pasif senkronizasyon (hash-dedup merge pool)
├─ services/bridge.go 3. parti sunucu inbox (bridge/send)
└─ services/ippressure.go Sanal IP basıncı
├─ services/notify.go Store-and-forward bildirim + suit yanıtı
├─ services/datastore.go Aktif & pasif veri senkronizasyonu
├─ services/bridge.go 3. parti sunucu inbox
├─ services/ippressure.go Sanal IP / numara / kısa kod + alt ağ (/24)
└─ services/session.go Oturum bayrakları (readable/writable/pairinfo)
httpserver
├─ GET/POST /api/* Kontrol düzlemi (API anahtarı, oda/istemci yönetimi)
├─ POST /api/bridge/inbox 3. parti sunucu inbox boşaltma
└─ /* (WebSocket değilse) SDK (script/index.js) + statik dosyalar
├─ GET /sdk.js → /sdk/index.js (301 yönlendirme)
├─ GET /sdk/* ES modül SDK dosyaları
├─ GET /demos/* Demo HTML dosyaları
├─ GET|POST /api/* Kontrol düzlemi
└─ GET /* Statik public/ dosyaları
sdk/
├─ index.js MWSE ana sınıf (bağlantı + sinyal yönlendirme)
├─ webrtc/ WebRTC kütüphanesi
│ ├─ index.js RTCEngine (PeerConnection yönetimi, ICE restart)
│ ├─ PeerConnection.js RTCPeerConnection wrapper + full event izleme
│ ├─ Negotiator.js Perfect negotiation (RFC 8829)
│ ├─ StreamManager.js addStream/replaceTrack/setEncodings
│ ├─ DataChannel.js Birincil veri kanalı + oto-yeniden bağlanma
│ ├─ MediaSources.js getUserMedia/getDisplayMedia/AudioContext fabrikaları
│ ├─ FileSender.js Paralel DataChannel dosya transferi
│ └─ CanvasCompositor.js Çoklu video track birleştirme (grid/pip/focus)
└─ studio/
├─ index.js Studio UI giriş noktası
├─ ColumnView.js Miller kolon yöneticisi
├─ Column.js Tek kolon (başlık + arama + liste)
└─ style.css Koyu masaüstü teması
```
## Güvenlik
- Bağlı cihazların mesajları **sokete iletilmeden önce** kullanıcılar tarafından
manipüle edilebilir; MWSE bu doğrulamayı yapmaz. Hassas veriler için
uygulama katmanında imzalama/şifreleme ekleyin.
- İstemci mesajları **uygulama katmanında doğrulanmaz**. Hassas veriler için
imzalama/şifreleme ekleyin.
- 3. parti köprü (`BRIDGE_APPROVE_URL`) kullanılıyorsa bağlantı onayı uygulama
sunucusuna delege edilir (fail-closed: onay gelmezse bağlantı reddedilir).
sunucusuna delege edilir (fail-closed).
- `.gitea-auth.json` dosyası commit'e asla girmez (`.gitignore`'da).
## Geliştirici dökümanı
Tüm wiki sayfaları: <https://git.saqut.com/saqut/MWSE/wiki>
Wiki: <https://git.saqut.com/saqut/MWSE/wiki>