Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 315820d487 | |||
| 878fd1c766 | |||
| 391d9235f1 | |||
| f33440a827 | |||
| 52912327ae | |||
| 7a0664b3c4 | |||
| cea3dccef1 | |||
| c8bb82feb5 | |||
| 3fb5515c3a | |||
| a6bdac1a25 | |||
| db7e683504 | |||
| 98ed8eeb68 | |||
| 39b85e2e3a | |||
| 58e338246f | |||
| 0b9a9f311e | |||
| 6800c73292 | |||
| ef1182d46f | |||
| 0865c2fe33 | |||
| 4a41de79d6 | |||
| 84fa45985a | |||
| 35352923a5 | |||
| b9df9c92f2 | |||
| 8674579b19 | |||
| de2d3300d4 |
63
.agents/skills/caveman/SKILL.md
Normal file
63
.agents/skills/caveman/SKILL.md
Normal file
@@ -0,0 +1,63 @@
|
||||
---
|
||||
name: caveman
|
||||
description: >
|
||||
Ultra-compressed communication mode. Cuts token usage ~75% by speaking like caveman
|
||||
while keeping full technical accuracy. Supports intensity levels: lite, full (default), ultra,
|
||||
wenyan-lite, wenyan-full, wenyan-ultra.
|
||||
Use when user says "caveman mode", "talk like caveman", "use caveman", "less tokens",
|
||||
"be brief", or invokes /caveman. Also auto-triggers when token efficiency is requested.
|
||||
---
|
||||
|
||||
Respond terse like smart caveman. All technical substance stay. Only fluff die.
|
||||
|
||||
Default: **full**. Switch: `/caveman lite|full|ultra`.
|
||||
|
||||
## Rules
|
||||
|
||||
Drop: articles (a/an/the), filler (just/really/basically/actually/simply), pleasantries (sure/certainly/of course/happy to), hedging. Fragments OK. Short synonyms (big not extensive, fix not "implement a solution for"). Technical terms exact. Code blocks unchanged. Errors quoted exact.
|
||||
|
||||
Pattern: `[thing] [action] [reason]. [next step].`
|
||||
|
||||
Not: "Sure! I'd be happy to help you with that. The issue you're experiencing is likely caused by..."
|
||||
Yes: "Bug in auth middleware. Token expiry check use `<` not `<=`. Fix:"
|
||||
|
||||
## Intensity
|
||||
|
||||
| Level | What change |
|
||||
|-------|------------|
|
||||
| **lite** | No filler/hedging. Keep articles + full sentences. Professional but tight |
|
||||
| **full** | Drop articles, fragments OK, short synonyms. Classic caveman |
|
||||
| **ultra** | Abbreviate (DB/auth/config/req/res/fn/impl), strip conjunctions, arrows for causality (X → Y), one word when one word enough |
|
||||
| **wenyan-lite** | Semi-classical. Drop filler/hedging but keep grammar structure, classical register |
|
||||
| **wenyan-full** | Maximum classical terseness. Fully 文言文. 80-90% character reduction. Classical sentence patterns, verbs precede objects, subjects often omitted, classical particles (之/乃/為/其) |
|
||||
| **wenyan-ultra** | Extreme abbreviation while keeping classical Chinese feel. Maximum compression, ultra terse |
|
||||
|
||||
Example — "Why React component re-render?"
|
||||
- lite: "Your component re-renders because you create a new object reference each render. Wrap it in `useMemo`."
|
||||
- full: "New object ref each render. Inline object prop = new ref = re-render. Wrap in `useMemo`."
|
||||
- ultra: "Inline obj prop → new ref → re-render. `useMemo`."
|
||||
- wenyan-lite: "組件頻重繪,以每繪新生對象參照故。以 useMemo 包之。"
|
||||
- wenyan-full: "物出新參照,致重繪。useMemo .Wrap之。"
|
||||
- wenyan-ultra: "新參照→重繪。useMemo Wrap。"
|
||||
|
||||
Example — "Explain database connection pooling."
|
||||
- lite: "Connection pooling reuses open connections instead of creating new ones per request. Avoids repeated handshake overhead."
|
||||
- full: "Pool reuse open DB connections. No new connection per request. Skip handshake overhead."
|
||||
- ultra: "Pool = reuse DB conn. Skip handshake → fast under load."
|
||||
- wenyan-full: "池reuse open connection。不每req新開。skip handshake overhead。"
|
||||
- wenyan-ultra: "池reuse conn。skip handshake → fast。"
|
||||
|
||||
## Auto-Clarity
|
||||
|
||||
Drop caveman for: security warnings, irreversible action confirmations, multi-step sequences where fragment order risks misread, user confused. Resume caveman after clear part done.
|
||||
|
||||
Example — destructive op:
|
||||
> **Warning:** This will permanently delete all rows in the `users` table and cannot be undone.
|
||||
> ```sql
|
||||
> DROP TABLE users;
|
||||
> ```
|
||||
> Caveman resume. Verify backup exist first.
|
||||
|
||||
## Boundaries
|
||||
|
||||
Code/commits/PRs: write normal. "stop caveman" or "normal mode": revert. Level persist until changed or session end.
|
||||
283
.agents/skills/playwright-e2e/SKILL.md
Normal file
283
.agents/skills/playwright-e2e/SKILL.md
Normal file
@@ -0,0 +1,283 @@
|
||||
---
|
||||
name: playwright-e2e
|
||||
description: >
|
||||
Write and run Playwright E2E tests for MetoYou (Angular chat + WebRTC voice/video app).
|
||||
Handles multi-browser-context WebRTC voice testing, fake media devices, signaling validation,
|
||||
audio channel verification, and UI state assertions. Use when: "E2E test", "Playwright",
|
||||
"end-to-end", "browser test", "test voice", "test call", "test WebRTC", "test chat",
|
||||
"test login", "test video", "test screen share", "integration test", "multi-client test".
|
||||
---
|
||||
|
||||
# Playwright E2E Testing — MetoYou
|
||||
|
||||
## Step 1 — Check Project Setup
|
||||
|
||||
Before writing any test, verify the Playwright infrastructure exists:
|
||||
|
||||
```
|
||||
e2e/ # Test root (lives at repo root)
|
||||
├── playwright.config.ts # Config
|
||||
├── fixtures/ # Custom fixtures (multi-client, auth, etc.)
|
||||
├── pages/ # Page Object Models
|
||||
├── tests/ # Test specs
|
||||
│ ├── auth/
|
||||
│ ├── chat/
|
||||
│ ├── voice/
|
||||
│ └── settings/
|
||||
└── helpers/ # Shared utilities (WebRTC introspection, etc.)
|
||||
```
|
||||
|
||||
If missing, scaffold it. See [reference/project-setup.md](./reference/project-setup.md).
|
||||
|
||||
## Step 2 — Identify Test Category
|
||||
|
||||
| Request | Category | Key Patterns |
|
||||
| ------------------------------- | ---------------- | ---------------------------------------------- |
|
||||
| Login, register, invite | **Auth** | Single browser context, form interaction |
|
||||
| Send message, rooms, chat UI | **Chat** | May need 2 clients for real-time sync |
|
||||
| Voice call, mute, deafen, audio | **Voice/WebRTC** | Multi-client, fake media, WebRTC introspection |
|
||||
| Camera, video tiles | **Video** | Multi-client, fake video, stream validation |
|
||||
| Screen share | **Screen Share** | Multi-client, display media mocking |
|
||||
| Settings, themes | **Settings** | Single client, preference persistence |
|
||||
|
||||
For **Voice/WebRTC** and **Multi-client** tests, read [reference/multi-client-webrtc.md](./reference/multi-client-webrtc.md) immediately.
|
||||
|
||||
## Step 3 — Core Conventions
|
||||
|
||||
### Config Essentials
|
||||
|
||||
```typescript
|
||||
// e2e/playwright.config.ts
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './tests',
|
||||
timeout: 60_000, // WebRTC needs longer timeouts
|
||||
expect: { timeout: 10_000 },
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
workers: 1, // Sequential — shared server state
|
||||
reporter: [['html'], ['list']],
|
||||
use: {
|
||||
baseURL: 'http://localhost:4200',
|
||||
trace: 'on-first-retry',
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'on-first-retry',
|
||||
permissions: ['microphone', 'camera']
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
launchOptions: {
|
||||
args: [
|
||||
'--use-fake-device-for-media-stream',
|
||||
'--use-fake-ui-for-media-stream'
|
||||
// Feed a specific audio file as fake mic input:
|
||||
// '--use-file-for-fake-audio-capture=/path/to/audio.wav',
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
webServer: [
|
||||
{
|
||||
command: 'cd server && npm run dev',
|
||||
port: 3001,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 30_000
|
||||
},
|
||||
{
|
||||
command: 'cd toju-app && npx ng serve',
|
||||
port: 4200,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 60_000
|
||||
}
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
### Selector Strategy
|
||||
|
||||
Use in this order — stop at the first that works:
|
||||
|
||||
1. `getByRole('button', { name: 'Mute' })` — accessible, resilient
|
||||
2. `getByLabel('Email')` — form fields
|
||||
3. `getByPlaceholder('Enter email')` — when label missing
|
||||
4. `getByText('Welcome')` — visible text
|
||||
5. `getByTestId('voice-controls')` — last resort, needs `data-testid`
|
||||
6. `locator('app-voice-controls')` — Angular component selectors (acceptable in this project)
|
||||
|
||||
Angular component selectors (`app-*`) are stable in this project and acceptable as locators when semantic selectors are not feasible.
|
||||
|
||||
### Assertions — Always Web-First
|
||||
|
||||
```typescript
|
||||
// ✅ Auto-retries until timeout
|
||||
await expect(page.getByRole('heading')).toBeVisible();
|
||||
await expect(page.getByRole('alert')).toHaveText('Saved');
|
||||
await expect(page).toHaveURL(/\/room\//);
|
||||
|
||||
// ❌ No auto-retry — races with DOM
|
||||
const text = await page.textContent('.msg');
|
||||
expect(text).toBe('Saved');
|
||||
```
|
||||
|
||||
### Anti-Patterns
|
||||
|
||||
| ❌ Don't | ✅ Do | Why |
|
||||
| ------------------------------ | --------------------------------------------------- | ------------------------- |
|
||||
| `page.waitForTimeout(3000)` | `await expect(locator).toBeVisible()` | Hard waits are flaky |
|
||||
| `expect(await el.isVisible())` | `await expect(el).toBeVisible()` | No auto-retry |
|
||||
| `page.$('.btn')` | `page.getByRole('button')` | Fragile selector |
|
||||
| `page.click('.submit')` | `page.getByRole('button', {name:'Submit'}).click()` | Not accessible |
|
||||
| Shared state between tests | `test.beforeEach` for setup | Tests must be independent |
|
||||
| `try/catch` around assertions | Let Playwright handle retries | Swallows real failures |
|
||||
|
||||
### Test Structure
|
||||
|
||||
```typescript
|
||||
import { test, expect } from '../fixtures/base';
|
||||
|
||||
test.describe('Feature Name', () => {
|
||||
test('should do specific thing', async ({ page }) => {
|
||||
await test.step('Navigate to page', async () => {
|
||||
await page.goto('/login');
|
||||
});
|
||||
|
||||
await test.step('Fill form', async () => {
|
||||
await page.getByLabel('Email').fill('test@example.com');
|
||||
});
|
||||
|
||||
await test.step('Verify result', async () => {
|
||||
await expect(page).toHaveURL(/\/search/);
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
Use `test.step()` for readability in complex flows.
|
||||
|
||||
## Step 4 — Page Object Models
|
||||
|
||||
Use POM for any test file with more than 2 tests. Match the app's route structure:
|
||||
|
||||
```typescript
|
||||
// e2e/pages/login.page.ts
|
||||
import { type Page, type Locator } from '@playwright/test';
|
||||
|
||||
export class LoginPage {
|
||||
readonly emailInput: Locator;
|
||||
readonly passwordInput: Locator;
|
||||
readonly submitButton: Locator;
|
||||
|
||||
constructor(private page: Page) {
|
||||
this.emailInput = page.getByLabel('Email');
|
||||
this.passwordInput = page.getByLabel('Password');
|
||||
this.submitButton = page.getByRole('button', { name: /sign in|log in/i });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/login');
|
||||
}
|
||||
|
||||
async login(email: string, password: string) {
|
||||
await this.emailInput.fill(email);
|
||||
await this.passwordInput.fill(password);
|
||||
await this.submitButton.click();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Key pages to model (match `app.routes.ts`):**
|
||||
|
||||
| Route | Page Object | Component |
|
||||
| ------------------- | ------------------ | ----------------------- |
|
||||
| `/login` | `LoginPage` | `LoginComponent` |
|
||||
| `/register` | `RegisterPage` | `RegisterComponent` |
|
||||
| `/search` | `ServerSearchPage` | `ServerSearchComponent` |
|
||||
| `/room/:roomId` | `ChatRoomPage` | `ChatRoomComponent` |
|
||||
| `/settings` | `SettingsPage` | `SettingsComponent` |
|
||||
| `/invite/:inviteId` | `InvitePage` | `InviteComponent` |
|
||||
|
||||
## Step 5 — MetoYou App Architecture Context
|
||||
|
||||
The agent writing tests MUST understand these domain boundaries:
|
||||
|
||||
### Voice/WebRTC Stack
|
||||
|
||||
| Layer | What It Does | Test Relevance |
|
||||
| ----------------------- | ----------------------------------------------------- | -------------------------------- |
|
||||
| `VoiceConnectionFacade` | High-level voice API (connect/disconnect/mute/deafen) | State signals to assert against |
|
||||
| `VoiceSessionFacade` | Session lifecycle, workspace layout | UI mode changes |
|
||||
| `VoiceActivityService` | Speaking detection (RMS threshold 0.015) | `isSpeaking()` signal validation |
|
||||
| `VoicePlaybackService` | Per-peer GainNode (0–200% volume) | Volume level assertions |
|
||||
| `PeerConnectionManager` | RTCPeerConnection lifecycle | Connection state introspection |
|
||||
| `MediaManager` | getUserMedia, mute, gain chain | Track state validation |
|
||||
| `SignalingManager` | WebSocket per signal URL | Connection establishment |
|
||||
|
||||
### Voice UI Components
|
||||
|
||||
| Component | Selector | Contains |
|
||||
| ----------------------------------- | --------------------------------- | ------------------------------------------- |
|
||||
| `VoiceWorkspaceComponent` | `app-voice-workspace` | Stream tiles, layout |
|
||||
| `VoiceControlsComponent` | `app-voice-controls` | Mute, camera, screen share, hang-up buttons |
|
||||
| `FloatingVoiceControlsComponent` | `app-floating-voice-controls` | Floating variant of controls |
|
||||
| `VoiceWorkspaceStreamTileComponent` | `app-voice-workspace-stream-tile` | Per-peer audio/video tile |
|
||||
|
||||
### Voice UI Icons (Lucide)
|
||||
|
||||
| Icon | Meaning |
|
||||
| ------------------------------------ | -------------------- |
|
||||
| `lucideMic` / `lucideMicOff` | Mute toggle |
|
||||
| `lucideVideo` / `lucideVideoOff` | Camera toggle |
|
||||
| `lucideMonitor` / `lucideMonitorOff` | Screen share toggle |
|
||||
| `lucidePhoneOff` | Hang up / disconnect |
|
||||
| `lucideHeadphones` | Deafen state |
|
||||
| `lucideVolume2` / `lucideVolumeX` | Volume indicator |
|
||||
|
||||
### Server & Signaling
|
||||
|
||||
- **Signaling server**: Port `3001` (HTTP by default, HTTPS if `SSL=true`)
|
||||
- **Angular dev server**: Port `4200`
|
||||
- **WebSocket signaling**: Upgrades on same port as server
|
||||
- **Protocol**: `identify` → `server_users` → SDP offer/answer → ICE candidates
|
||||
- **PING/PONG**: Every 30s, 45s timeout
|
||||
|
||||
## Step 6 — Validation Workflow
|
||||
|
||||
After generating any test:
|
||||
|
||||
```
|
||||
1. npx playwright install --with-deps chromium # First time only
|
||||
2. npx playwright test --project=chromium # Run tests
|
||||
3. npx playwright test --ui # Interactive debug
|
||||
4. npx playwright show-report # HTML report
|
||||
```
|
||||
|
||||
If the test involves WebRTC, always verify:
|
||||
|
||||
- Fake media flags are set in config
|
||||
- Timeouts are sufficient (60s+ for connection establishment)
|
||||
- `workers: 1` if tests share server state
|
||||
- Browser permissions granted for microphone/camera
|
||||
|
||||
## Quick Reference — Commands
|
||||
|
||||
```bash
|
||||
npx playwright test # Run all
|
||||
npx playwright test --ui # Interactive UI
|
||||
npx playwright test --debug # Step-through debugger
|
||||
npx playwright test tests/voice/ # Voice tests only
|
||||
npx playwright test --project=chromium # Single browser
|
||||
npx playwright test -g "voice connects" # By test name
|
||||
npx playwright show-report # HTML report
|
||||
npx playwright codegen http://localhost:4200 # Record test
|
||||
```
|
||||
|
||||
## Reference Files
|
||||
|
||||
| File | When to Read |
|
||||
| ---------------------------------------------------------------------- | ------------------------------------------------------------------ |
|
||||
| [reference/multi-client-webrtc.md](./reference/multi-client-webrtc.md) | Voice/video/WebRTC tests, multi-browser contexts, audio validation |
|
||||
| [reference/project-setup.md](./reference/project-setup.md) | First-time scaffold, dependency installation, config creation |
|
||||
536
.agents/skills/playwright-e2e/reference/multi-client-webrtc.md
Normal file
536
.agents/skills/playwright-e2e/reference/multi-client-webrtc.md
Normal file
@@ -0,0 +1,536 @@
|
||||
# Multi-Client WebRTC Testing
|
||||
|
||||
This reference covers the hardest E2E testing scenario in MetoYou: verifying that voice/video connections actually work between multiple clients.
|
||||
|
||||
## Core Concept: Multiple Browser Contexts
|
||||
|
||||
Playwright can create multiple **independent** browser contexts within a single test. Each context is an isolated session (separate cookies, storage, WebRTC state). This is how we simulate multiple users.
|
||||
|
||||
```typescript
|
||||
import { test, expect, chromium } from '@playwright/test';
|
||||
|
||||
test('two users can voice chat', async () => {
|
||||
const browser = await chromium.launch({
|
||||
args: [
|
||||
'--use-fake-device-for-media-stream',
|
||||
'--use-fake-ui-for-media-stream',
|
||||
'--use-file-for-fake-audio-capture=e2e/fixtures/test-tone-440hz.wav',
|
||||
],
|
||||
});
|
||||
|
||||
const contextA = await browser.newContext({
|
||||
permissions: ['microphone', 'camera'],
|
||||
});
|
||||
const contextB = await browser.newContext({
|
||||
permissions: ['microphone', 'camera'],
|
||||
});
|
||||
|
||||
const alice = await contextA.newPage();
|
||||
const bob = await contextB.newPage();
|
||||
|
||||
// ... test logic with alice and bob ...
|
||||
|
||||
await contextA.close();
|
||||
await contextB.close();
|
||||
await browser.close();
|
||||
});
|
||||
```
|
||||
|
||||
## Custom Fixture: Multi-Client
|
||||
|
||||
Create a reusable fixture for multi-client tests:
|
||||
|
||||
```typescript
|
||||
// e2e/fixtures/multi-client.ts
|
||||
import { test as base, chromium, type Page, type BrowserContext, type Browser } from '@playwright/test';
|
||||
|
||||
type Client = {
|
||||
page: Page;
|
||||
context: BrowserContext;
|
||||
};
|
||||
|
||||
type MultiClientFixture = {
|
||||
createClient: () => Promise<Client>;
|
||||
browser: Browser;
|
||||
};
|
||||
|
||||
export const test = base.extend<MultiClientFixture>({
|
||||
browser: async ({}, use) => {
|
||||
const browser = await chromium.launch({
|
||||
args: [
|
||||
'--use-fake-device-for-media-stream',
|
||||
'--use-fake-ui-for-media-stream',
|
||||
],
|
||||
});
|
||||
await use(browser);
|
||||
await browser.close();
|
||||
},
|
||||
|
||||
createClient: async ({ browser }, use) => {
|
||||
const clients: Client[] = [];
|
||||
|
||||
const factory = async (): Promise<Client> => {
|
||||
const context = await browser.newContext({
|
||||
permissions: ['microphone', 'camera'],
|
||||
baseURL: 'http://localhost:4200',
|
||||
});
|
||||
const page = await context.newPage();
|
||||
clients.push({ page, context });
|
||||
return { page, context };
|
||||
};
|
||||
|
||||
await use(factory);
|
||||
|
||||
// Cleanup
|
||||
for (const client of clients) {
|
||||
await client.context.close();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export { expect } from '@playwright/test';
|
||||
```
|
||||
|
||||
**Usage:**
|
||||
|
||||
```typescript
|
||||
import { test, expect } from '../fixtures/multi-client';
|
||||
|
||||
test('voice call connects between two users', async ({ createClient }) => {
|
||||
const alice = await createClient();
|
||||
const bob = await createClient();
|
||||
|
||||
// Login both users
|
||||
await alice.page.goto('/login');
|
||||
await bob.page.goto('/login');
|
||||
// ... login flows ...
|
||||
});
|
||||
```
|
||||
|
||||
## Fake Media Devices
|
||||
|
||||
Chromium's fake device flags are essential for headless WebRTC testing:
|
||||
|
||||
| Flag | Purpose |
|
||||
|------|---------|
|
||||
| `--use-fake-device-for-media-stream` | Provides fake mic/camera devices (no real hardware needed) |
|
||||
| `--use-fake-ui-for-media-stream` | Auto-grants device permission prompts |
|
||||
| `--use-file-for-fake-audio-capture=<path>` | Feeds a WAV/WebM file as fake mic input |
|
||||
| `--use-file-for-fake-video-capture=<path>` | Feeds a Y4M/MJPEG file as fake video input |
|
||||
|
||||
### Test Audio File
|
||||
|
||||
Create a 440Hz sine wave test tone for audio verification:
|
||||
|
||||
```bash
|
||||
# Generate a 5-second 440Hz mono WAV test tone
|
||||
ffmpeg -f lavfi -i "sine=frequency=440:duration=5" -ar 48000 -ac 1 e2e/fixtures/test-tone-440hz.wav
|
||||
```
|
||||
|
||||
Or use Playwright's built-in fake device which generates a test pattern (beep) automatically when `--use-fake-device-for-media-stream` is set without specifying a file.
|
||||
|
||||
## WebRTC Connection Introspection
|
||||
|
||||
### Checking RTCPeerConnection State
|
||||
|
||||
Inject JavaScript to inspect WebRTC internals via `page.evaluate()`:
|
||||
|
||||
```typescript
|
||||
// e2e/helpers/webrtc-helpers.ts
|
||||
|
||||
/**
|
||||
* Get all RTCPeerConnection instances and their states.
|
||||
* Requires the app to expose connections (or use a monkey-patch approach).
|
||||
*/
|
||||
export async function getPeerConnectionStates(page: Page): Promise<Array<{
|
||||
connectionState: string;
|
||||
iceConnectionState: string;
|
||||
signalingState: string;
|
||||
}>> {
|
||||
return page.evaluate(() => {
|
||||
// Approach 1: Use chrome://webrtc-internals equivalent
|
||||
// Approach 2: Monkey-patch RTCPeerConnection (install before app loads)
|
||||
// Approach 3: Expose from app (preferred for this project)
|
||||
|
||||
// MetoYou exposes via Angular — access the injector
|
||||
const appRef = (window as any).ng?.getComponent(document.querySelector('app-root'));
|
||||
// This needs adaptation based on actual exposure method
|
||||
|
||||
// Fallback: Use performance.getEntriesByType or WebRTC stats
|
||||
return [];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for at least one peer connection to reach 'connected' state.
|
||||
*/
|
||||
export async function waitForPeerConnected(page: Page, timeout = 30_000): Promise<void> {
|
||||
await page.waitForFunction(() => {
|
||||
// Check if any RTCPeerConnection reached 'connected'
|
||||
return (window as any).__rtcConnections?.some(
|
||||
(pc: RTCPeerConnection) => pc.connectionState === 'connected'
|
||||
) ?? false;
|
||||
}, { timeout });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get WebRTC stats for audio tracks (inbound/outbound).
|
||||
*/
|
||||
export async function getAudioStats(page: Page): Promise<{
|
||||
outbound: { bytesSent: number; packetsSent: number } | null;
|
||||
inbound: { bytesReceived: number; packetsReceived: number } | null;
|
||||
}> {
|
||||
return page.evaluate(async () => {
|
||||
const connections = (window as any).__rtcConnections as RTCPeerConnection[] | undefined;
|
||||
if (!connections?.length) return { outbound: null, inbound: null };
|
||||
|
||||
const pc = connections[0];
|
||||
const stats = await pc.getStats();
|
||||
|
||||
let outbound: any = null;
|
||||
let inbound: any = null;
|
||||
|
||||
stats.forEach((report) => {
|
||||
if (report.type === 'outbound-rtp' && report.kind === 'audio') {
|
||||
outbound = { bytesSent: report.bytesSent, packetsSent: report.packetsSent };
|
||||
}
|
||||
if (report.type === 'inbound-rtp' && report.kind === 'audio') {
|
||||
inbound = { bytesReceived: report.bytesReceived, packetsReceived: report.packetsReceived };
|
||||
}
|
||||
});
|
||||
|
||||
return { outbound, inbound };
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
### RTCPeerConnection Monkey-Patch
|
||||
|
||||
To track all peer connections created by the app, inject a monkey-patch **before** navigation:
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* Install RTCPeerConnection tracking on a page BEFORE navigating.
|
||||
* Call this immediately after page creation, before any goto().
|
||||
*/
|
||||
export async function installWebRTCTracking(page: Page): Promise<void> {
|
||||
await page.addInitScript(() => {
|
||||
const connections: RTCPeerConnection[] = [];
|
||||
(window as any).__rtcConnections = connections;
|
||||
|
||||
const OriginalRTCPeerConnection = window.RTCPeerConnection;
|
||||
(window as any).RTCPeerConnection = function (...args: any[]) {
|
||||
const pc = new OriginalRTCPeerConnection(...args);
|
||||
connections.push(pc);
|
||||
|
||||
pc.addEventListener('connectionstatechange', () => {
|
||||
(window as any).__lastRtcState = pc.connectionState;
|
||||
});
|
||||
|
||||
// Track remote streams
|
||||
pc.addEventListener('track', (event) => {
|
||||
if (!((window as any).__rtcRemoteTracks)) {
|
||||
(window as any).__rtcRemoteTracks = [];
|
||||
}
|
||||
(window as any).__rtcRemoteTracks.push({
|
||||
kind: event.track.kind,
|
||||
id: event.track.id,
|
||||
readyState: event.track.readyState,
|
||||
});
|
||||
});
|
||||
|
||||
return pc;
|
||||
} as any;
|
||||
|
||||
// Preserve prototype chain
|
||||
(window as any).RTCPeerConnection.prototype = OriginalRTCPeerConnection.prototype;
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Voice Call Test Pattern — Full Example
|
||||
|
||||
This is the canonical pattern for testing that voice actually connects between two clients:
|
||||
|
||||
```typescript
|
||||
import { test, expect } from '../fixtures/multi-client';
|
||||
import { installWebRTCTracking, getAudioStats } from '../helpers/webrtc-helpers';
|
||||
|
||||
test.describe('Voice Call', () => {
|
||||
test('two users connect voice and exchange audio', async ({ createClient }) => {
|
||||
const alice = await createClient();
|
||||
const bob = await createClient();
|
||||
|
||||
// Install WebRTC tracking BEFORE navigation
|
||||
await installWebRTCTracking(alice.page);
|
||||
await installWebRTCTracking(bob.page);
|
||||
|
||||
await test.step('Both users log in', async () => {
|
||||
// Login Alice
|
||||
await alice.page.goto('/login');
|
||||
await alice.page.getByLabel('Email').fill('alice@test.com');
|
||||
await alice.page.getByLabel('Password').fill('password123');
|
||||
await alice.page.getByRole('button', { name: /sign in/i }).click();
|
||||
await expect(alice.page).toHaveURL(/\/search/);
|
||||
|
||||
// Login Bob
|
||||
await bob.page.goto('/login');
|
||||
await bob.page.getByLabel('Email').fill('bob@test.com');
|
||||
await bob.page.getByLabel('Password').fill('password123');
|
||||
await bob.page.getByRole('button', { name: /sign in/i }).click();
|
||||
await expect(bob.page).toHaveURL(/\/search/);
|
||||
});
|
||||
|
||||
await test.step('Both users join the same room', async () => {
|
||||
// Navigate to a shared room (adapt URL to actual room ID)
|
||||
const roomUrl = '/room/test-room-id';
|
||||
await alice.page.goto(roomUrl);
|
||||
await bob.page.goto(roomUrl);
|
||||
|
||||
// Verify both are in the room
|
||||
await expect(alice.page.locator('app-chat-room')).toBeVisible();
|
||||
await expect(bob.page.locator('app-chat-room')).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('Alice starts voice', async () => {
|
||||
// Click the voice/call join button (adapt selector to actual UI)
|
||||
await alice.page.getByRole('button', { name: /join voice|connect/i }).click();
|
||||
|
||||
// Voice workspace should appear
|
||||
await expect(alice.page.locator('app-voice-workspace')).toBeVisible();
|
||||
|
||||
// Voice controls should be visible
|
||||
await expect(alice.page.locator('app-voice-controls')).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('Bob joins voice', async () => {
|
||||
await bob.page.getByRole('button', { name: /join voice|connect/i }).click();
|
||||
await expect(bob.page.locator('app-voice-workspace')).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('WebRTC connection establishes', async () => {
|
||||
// Wait for peer connection to reach 'connected' on both sides
|
||||
await alice.page.waitForFunction(
|
||||
() => (window as any).__rtcConnections?.some(
|
||||
(pc: any) => pc.connectionState === 'connected'
|
||||
),
|
||||
{ timeout: 30_000 }
|
||||
);
|
||||
await bob.page.waitForFunction(
|
||||
() => (window as any).__rtcConnections?.some(
|
||||
(pc: any) => pc.connectionState === 'connected'
|
||||
),
|
||||
{ timeout: 30_000 }
|
||||
);
|
||||
});
|
||||
|
||||
await test.step('Audio is flowing in both directions', async () => {
|
||||
// Wait a moment for audio stats to accumulate
|
||||
await alice.page.waitForTimeout(3_000); // Acceptable here: waiting for stats accumulation
|
||||
|
||||
// Check Alice is sending audio
|
||||
const aliceStats = await getAudioStats(alice.page);
|
||||
expect(aliceStats.outbound).not.toBeNull();
|
||||
expect(aliceStats.outbound!.bytesSent).toBeGreaterThan(0);
|
||||
expect(aliceStats.outbound!.packetsSent).toBeGreaterThan(0);
|
||||
|
||||
// Check Bob is sending audio
|
||||
const bobStats = await getAudioStats(bob.page);
|
||||
expect(bobStats.outbound).not.toBeNull();
|
||||
expect(bobStats.outbound!.bytesSent).toBeGreaterThan(0);
|
||||
|
||||
// Check Alice receives Bob's audio
|
||||
expect(aliceStats.inbound).not.toBeNull();
|
||||
expect(aliceStats.inbound!.bytesReceived).toBeGreaterThan(0);
|
||||
|
||||
// Check Bob receives Alice's audio
|
||||
expect(bobStats.inbound).not.toBeNull();
|
||||
expect(bobStats.inbound!.bytesReceived).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
await test.step('Voice UI states are correct', async () => {
|
||||
// Both should see stream tiles for each other
|
||||
await expect(alice.page.locator('app-voice-workspace-stream-tile')).toHaveCount(2);
|
||||
await expect(bob.page.locator('app-voice-workspace-stream-tile')).toHaveCount(2);
|
||||
|
||||
// Mute button should be visible and in unmuted state
|
||||
// (lucideMic icon visible, lucideMicOff NOT visible)
|
||||
await expect(alice.page.locator('app-voice-controls')).toBeVisible();
|
||||
});
|
||||
|
||||
await test.step('Mute toggles correctly', async () => {
|
||||
// Alice mutes
|
||||
await alice.page.getByRole('button', { name: /mute/i }).click();
|
||||
|
||||
// Alice's local UI shows muted state
|
||||
// Bob should see Alice as muted (mute indicator on her tile)
|
||||
|
||||
// Verify no audio being sent from Alice after mute
|
||||
const preStats = await getAudioStats(alice.page);
|
||||
await alice.page.waitForTimeout(2_000);
|
||||
const postStats = await getAudioStats(alice.page);
|
||||
|
||||
// Bytes sent should not increase (or increase minimally — comfort noise)
|
||||
// The exact assertion depends on whether mute stops the track or sends silence
|
||||
});
|
||||
|
||||
await test.step('Alice hangs up', async () => {
|
||||
await alice.page.getByRole('button', { name: /hang up|disconnect|leave/i }).click();
|
||||
|
||||
// Voice workspace should disappear for Alice
|
||||
await expect(alice.page.locator('app-voice-workspace')).not.toBeVisible();
|
||||
|
||||
// Bob should see Alice's tile disappear
|
||||
await expect(bob.page.locator('app-voice-workspace-stream-tile')).toHaveCount(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## Verifying Audio Is Actually Received
|
||||
|
||||
Beyond checking `bytesReceived > 0`, you can verify actual audio energy:
|
||||
|
||||
```typescript
|
||||
/**
|
||||
* Check if audio energy is present on a received stream.
|
||||
* Uses Web Audio AnalyserNode — same approach as MetoYou's VoiceActivityService.
|
||||
*/
|
||||
export async function hasAudioEnergy(page: Page): Promise<boolean> {
|
||||
return page.evaluate(async () => {
|
||||
const connections = (window as any).__rtcConnections as RTCPeerConnection[];
|
||||
if (!connections?.length) return false;
|
||||
|
||||
for (const pc of connections) {
|
||||
const receivers = pc.getReceivers();
|
||||
for (const receiver of receivers) {
|
||||
if (receiver.track.kind !== 'audio' || receiver.track.readyState !== 'live') continue;
|
||||
|
||||
const audioCtx = new AudioContext();
|
||||
const source = audioCtx.createMediaStreamSource(new MediaStream([receiver.track]));
|
||||
const analyser = audioCtx.createAnalyser();
|
||||
analyser.fftSize = 256;
|
||||
source.connect(analyser);
|
||||
|
||||
// Sample over 500ms
|
||||
const dataArray = new Float32Array(analyser.frequencyBinCount);
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
analyser.getFloatTimeDomainData(dataArray);
|
||||
|
||||
// Calculate RMS (same as VoiceActivityService)
|
||||
let sum = 0;
|
||||
for (const sample of dataArray) {
|
||||
sum += sample * sample;
|
||||
}
|
||||
const rms = Math.sqrt(sum / dataArray.length);
|
||||
|
||||
audioCtx.close();
|
||||
|
||||
// MetoYou uses threshold 0.015 — use lower threshold for test
|
||||
if (rms > 0.005) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## Testing Speaker/Playback Volume
|
||||
|
||||
MetoYou uses per-peer GainNode chains (0–200%). To verify:
|
||||
|
||||
```typescript
|
||||
await test.step('Bob adjusts Alice volume to 50%', async () => {
|
||||
// Interact with volume slider in stream tile
|
||||
// (adapt selector to actual volume control UI)
|
||||
const volumeSlider = bob.page.locator('app-voice-workspace-stream-tile')
|
||||
.filter({ hasText: 'Alice' })
|
||||
.getByRole('slider');
|
||||
|
||||
await volumeSlider.fill('50');
|
||||
|
||||
// Verify the gain was set (check via WebRTC or app state)
|
||||
const gain = await bob.page.evaluate(() => {
|
||||
// Access VoicePlaybackService through Angular DI if exposed
|
||||
// Or check audio element volume
|
||||
const audioElements = document.querySelectorAll('audio');
|
||||
return audioElements[0]?.volume;
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## Testing Screen Share
|
||||
|
||||
Screen share requires `getDisplayMedia()` which cannot be auto-granted. Options:
|
||||
|
||||
1. **Mock at the browser level** — use `page.addInitScript()` to replace `getDisplayMedia` with a fake stream
|
||||
2. **Use Chromium flags** — `--auto-select-desktop-capture-source=Entire screen`
|
||||
|
||||
```typescript
|
||||
// Mock getDisplayMedia before navigation
|
||||
await page.addInitScript(() => {
|
||||
navigator.mediaDevices.getDisplayMedia = async () => {
|
||||
// Create a simple canvas stream as fake screen share
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = 1280;
|
||||
canvas.height = 720;
|
||||
const ctx = canvas.getContext('2d')!;
|
||||
ctx.fillStyle = '#4a90d9';
|
||||
ctx.fillRect(0, 0, 1280, 720);
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.font = '48px sans-serif';
|
||||
ctx.fillText('Fake Screen Share', 400, 380);
|
||||
return canvas.captureStream(30);
|
||||
};
|
||||
});
|
||||
```
|
||||
|
||||
## Debugging Tips
|
||||
|
||||
### Trace Viewer
|
||||
When a WebRTC test fails, the trace captures network requests, console logs, and screenshots:
|
||||
```bash
|
||||
npx playwright show-trace test-results/trace.zip
|
||||
```
|
||||
|
||||
### Console Log Forwarding
|
||||
Forward browser console to Node for real-time debugging:
|
||||
```typescript
|
||||
page.on('console', msg => console.log(`[${name}]`, msg.text()));
|
||||
page.on('pageerror', err => console.error(`[${name}] PAGE ERROR:`, err.message));
|
||||
```
|
||||
|
||||
### WebRTC Internals
|
||||
Chromium exposes WebRTC stats at `chrome://webrtc-internals/`. In Playwright, access the same data via:
|
||||
```typescript
|
||||
const stats = await page.evaluate(async () => {
|
||||
const pcs = (window as any).__rtcConnections;
|
||||
return Promise.all(pcs.map(async (pc: any) => {
|
||||
const stats = await pc.getStats();
|
||||
const result: any[] = [];
|
||||
stats.forEach((report: any) => result.push(report));
|
||||
return result;
|
||||
}));
|
||||
});
|
||||
```
|
||||
|
||||
## Timeout Guidelines
|
||||
|
||||
| Operation | Recommended Timeout |
|
||||
|-----------|-------------------|
|
||||
| Page navigation | 10s (default) |
|
||||
| Login flow | 15s |
|
||||
| WebRTC connection establishment | 30s |
|
||||
| ICE negotiation (TURN fallback) | 45s |
|
||||
| Audio stats accumulation | 3–5s after connection |
|
||||
| Full voice test (end-to-end) | 90s |
|
||||
| Screen share setup | 15s |
|
||||
|
||||
## Parallelism Warning
|
||||
|
||||
WebRTC multi-client tests **must** run with `workers: 1` (sequential) because:
|
||||
- All clients share the same signaling server instance
|
||||
- Server state (rooms, users) is mutable
|
||||
- ICE candidates reference `localhost` — port conflicts possible with parallel launches
|
||||
|
||||
If you need parallelism, use separate server instances with different ports per worker.
|
||||
175
.agents/skills/playwright-e2e/reference/project-setup.md
Normal file
175
.agents/skills/playwright-e2e/reference/project-setup.md
Normal file
@@ -0,0 +1,175 @@
|
||||
# Project Setup — Playwright E2E for MetoYou
|
||||
|
||||
Before creating any tests or changing them read AGENTS.md for a understanding how the application works.
|
||||
|
||||
## First-Time Scaffold
|
||||
|
||||
### 1. Install Dependencies
|
||||
|
||||
From the **repository root**:
|
||||
|
||||
```bash
|
||||
npm install -D @playwright/test
|
||||
npx playwright install --with-deps chromium
|
||||
```
|
||||
|
||||
Only Chromium is needed — WebRTC fake media flags are Chromium-only. Add Firefox/WebKit later if needed for non-WebRTC tests.
|
||||
|
||||
### 2. Create Directory Structure
|
||||
|
||||
```bash
|
||||
mkdir -p e2e/{tests/{auth,chat,voice,settings},fixtures,pages,helpers}
|
||||
```
|
||||
|
||||
### 3. Create Config
|
||||
|
||||
Create `e2e/playwright.config.ts`:
|
||||
|
||||
```typescript
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './tests',
|
||||
timeout: 60_000,
|
||||
expect: { timeout: 10_000 },
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
workers: 1,
|
||||
reporter: [['html', { outputFolder: '../test-results/html-report' }], ['list']],
|
||||
outputDir: '../test-results/artifacts',
|
||||
use: {
|
||||
baseURL: 'http://localhost:4200',
|
||||
trace: 'on-first-retry',
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'on-first-retry',
|
||||
permissions: ['microphone', 'camera'],
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
launchOptions: {
|
||||
args: [
|
||||
'--use-fake-device-for-media-stream',
|
||||
'--use-fake-ui-for-media-stream',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
webServer: [
|
||||
{
|
||||
command: 'cd ../server && npm run dev',
|
||||
port: 3001,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 30_000,
|
||||
},
|
||||
{
|
||||
command: 'cd ../toju-app && npx ng serve',
|
||||
port: 4200,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 60_000,
|
||||
},
|
||||
],
|
||||
});
|
||||
```
|
||||
|
||||
### 4. Create Base Fixture
|
||||
|
||||
Create `e2e/fixtures/base.ts`:
|
||||
|
||||
```typescript
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
export const test = base.extend({
|
||||
// Add common fixtures here as the test suite grows
|
||||
// Examples: authenticated page, test data seeding, etc.
|
||||
});
|
||||
|
||||
export { expect } from '@playwright/test';
|
||||
```
|
||||
|
||||
### 5. Create Multi-Client Fixture
|
||||
|
||||
Create `e2e/fixtures/multi-client.ts` — see [multi-client-webrtc.md](./multi-client-webrtc.md) for the full fixture code.
|
||||
|
||||
### 6. Create WebRTC Helpers
|
||||
|
||||
Create `e2e/helpers/webrtc-helpers.ts` — see [multi-client-webrtc.md](./multi-client-webrtc.md) for helper functions.
|
||||
|
||||
### 7. Create Isolated Test Server Launcher
|
||||
|
||||
The app requires a signal server. Tests use an isolated instance with its own temporary database so test data never pollutes the dev environment.
|
||||
|
||||
Create `e2e/helpers/start-test-server.js` — a Node.js script that:
|
||||
1. Creates a temp directory under the OS tmpdir
|
||||
2. Writes a `data/variables.json` with `serverPort: 3099`, `serverProtocol: "http"`
|
||||
3. Spawns `ts-node server/src/index.ts` with `cwd` set to the temp dir
|
||||
4. Cleans up the temp dir on exit
|
||||
|
||||
The server's `getRuntimeBaseDir()` returns `process.cwd()`, so setting cwd to the temp dir makes the database go to `<tmpdir>/data/metoyou.sqlite`. Module resolution (`require`/`import`) uses `__dirname`, so server source and `node_modules` resolve correctly from the real `server/` directory.
|
||||
|
||||
Playwright's `webServer` config calls this script and waits for port 3099 to be ready.
|
||||
|
||||
### 8. Create Test Endpoint Seeder
|
||||
|
||||
The Angular app reads signal endpoints from `localStorage['metoyou_server_endpoints']`. By default it falls back to production URLs in `environment.ts`. For tests, seed localStorage with a single endpoint pointing at `http://localhost:3099`.
|
||||
|
||||
Create `e2e/helpers/seed-test-endpoint.ts` — called automatically by the multi-client fixture after creating each browser context. The flow is:
|
||||
1. Navigate to `/` (establishes the origin for localStorage)
|
||||
2. Set `metoyou_server_endpoints` to `[{ id: 'e2e-test-server', url: 'http://localhost:3099', ... }]`
|
||||
3. Set `metoyou_removed_default_server_keys` to suppress production endpoints
|
||||
4. Reload the page so the app picks up the test endpoint
|
||||
|
||||
### 9. Add npm Scripts
|
||||
|
||||
Add to root `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"test:e2e": "cd e2e && npx playwright test",
|
||||
"test:e2e:ui": "cd e2e && npx playwright test --ui",
|
||||
"test:e2e:debug": "cd e2e && npx playwright test --debug",
|
||||
"test:e2e:report": "cd e2e && npx playwright show-report ../test-results/html-report"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 8. Update .gitignore
|
||||
|
||||
Add to `.gitignore`:
|
||||
|
||||
```
|
||||
# Playwright
|
||||
test-results/
|
||||
e2e/playwright-report/
|
||||
```
|
||||
|
||||
### 9. Generate Test Audio Fixture (Optional)
|
||||
|
||||
For voice tests with controlled audio input:
|
||||
|
||||
```bash
|
||||
# Requires ffmpeg
|
||||
ffmpeg -f lavfi -i "sine=frequency=440:duration=5" -ar 48000 -ac 1 e2e/fixtures/test-tone-440hz.wav
|
||||
```
|
||||
|
||||
## Existing Dev Stack Integration
|
||||
|
||||
The tests assume the standard MetoYou dev stack:
|
||||
|
||||
- **Signaling server** at `http://localhost:3001` (via `server/npm run dev`)
|
||||
- **Angular dev server** at `http://localhost:4200` (via `toju-app/npx ng serve`)
|
||||
|
||||
The `webServer` config in `playwright.config.ts` starts these automatically if not already running. When running `npm run dev` (full Electron stack) separately, tests will reuse the existing servers.
|
||||
|
||||
## Test Data Requirements
|
||||
|
||||
E2E tests need user accounts to log in with. Options:
|
||||
|
||||
1. **Seed via API** — create users in `test.beforeAll` via the server REST API
|
||||
2. **Pre-seeded database** — maintain a test SQLite database with known accounts
|
||||
3. **Register in test** — use the `/register` flow as a setup step (slower but self-contained)
|
||||
|
||||
Recommended: Option 3 for initial setup, migrate to Option 1 as the test suite grows.
|
||||
@@ -17,6 +17,13 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Restore npm cache
|
||||
uses: https://github.com/actions/cache@v4
|
||||
with:
|
||||
path: ~/AppData/Local/npm-cache
|
||||
key: npm-windows-${{ hashFiles('package-lock.json', 'website/package-lock.json') }}
|
||||
restore-keys: npm-windows-
|
||||
|
||||
- name: Install root dependencies
|
||||
env:
|
||||
NODE_ENV: development
|
||||
|
||||
@@ -48,18 +48,30 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Restore npm cache
|
||||
uses: https://github.com/actions/cache@v4
|
||||
with:
|
||||
path: /root/.npm
|
||||
key: npm-linux-${{ hashFiles('package-lock.json', 'server/package-lock.json') }}
|
||||
restore-keys: npm-linux-
|
||||
|
||||
- name: Restore Electron cache
|
||||
uses: https://github.com/actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
/root/.cache/electron
|
||||
/root/.cache/electron-builder
|
||||
key: electron-linux-${{ hashFiles('package.json') }}
|
||||
restore-keys: electron-linux-
|
||||
|
||||
- name: Install dependencies
|
||||
env:
|
||||
NODE_ENV: development
|
||||
run: |
|
||||
apt-get update && apt-get install -y --no-install-recommends zip
|
||||
npm ci
|
||||
cd server && npm ci
|
||||
|
||||
- name: Install zip utility
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install -y zip
|
||||
|
||||
- name: Set CI release version
|
||||
run: >
|
||||
node tools/set-release-version.js
|
||||
@@ -108,6 +120,22 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Restore npm cache
|
||||
uses: https://github.com/actions/cache@v4
|
||||
with:
|
||||
path: ~/AppData/Local/npm-cache
|
||||
key: npm-windows-${{ hashFiles('package-lock.json', 'server/package-lock.json') }}
|
||||
restore-keys: npm-windows-
|
||||
|
||||
- name: Restore Electron cache
|
||||
uses: https://github.com/actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/AppData/Local/electron/Cache
|
||||
~/AppData/Local/electron-builder/Cache
|
||||
key: electron-windows-${{ hashFiles('package.json') }}
|
||||
restore-keys: electron-windows-
|
||||
|
||||
- name: Install dependencies
|
||||
env:
|
||||
NODE_ENV: development
|
||||
@@ -217,9 +245,6 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci --omit=dev
|
||||
|
||||
- name: Download previous manifest
|
||||
env:
|
||||
GITEA_RELEASE_TOKEN: ${{ secrets.RELEASE_TOKEN }}
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -44,6 +44,10 @@ testem.log
|
||||
/typings
|
||||
__screenshots__/
|
||||
|
||||
# Playwright
|
||||
test-results/
|
||||
e2e/playwright-report/
|
||||
|
||||
# System files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
4
e2e/fixtures/base.ts
Normal file
4
e2e/fixtures/base.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
export const test = base;
|
||||
export { expect } from '@playwright/test';
|
||||
202
e2e/fixtures/multi-client.ts
Normal file
202
e2e/fixtures/multi-client.ts
Normal file
@@ -0,0 +1,202 @@
|
||||
import {
|
||||
test as base,
|
||||
chromium,
|
||||
type Page,
|
||||
type BrowserContext,
|
||||
type Browser
|
||||
} from '@playwright/test';
|
||||
import { spawn, type ChildProcess } from 'node:child_process';
|
||||
import { once } from 'node:events';
|
||||
import { createServer } from 'node:net';
|
||||
import { join } from 'node:path';
|
||||
import { installTestServerEndpoint } from '../helpers/seed-test-endpoint';
|
||||
|
||||
export interface Client {
|
||||
page: Page;
|
||||
context: BrowserContext;
|
||||
}
|
||||
|
||||
interface TestServerHandle {
|
||||
port: number;
|
||||
url: string;
|
||||
stop: () => Promise<void>;
|
||||
}
|
||||
|
||||
interface MultiClientFixture {
|
||||
createClient: () => Promise<Client>;
|
||||
testServer: TestServerHandle;
|
||||
}
|
||||
|
||||
const FAKE_AUDIO_FILE = join(__dirname, 'test-tone.wav');
|
||||
const CHROMIUM_FAKE_MEDIA_ARGS = [
|
||||
'--use-fake-device-for-media-stream',
|
||||
'--use-fake-ui-for-media-stream',
|
||||
`--use-file-for-fake-audio-capture=${FAKE_AUDIO_FILE}`
|
||||
];
|
||||
const E2E_DIR = join(__dirname, '..');
|
||||
const START_SERVER_SCRIPT = join(E2E_DIR, 'helpers', 'start-test-server.js');
|
||||
|
||||
export const test = base.extend<MultiClientFixture>({
|
||||
testServer: async ({ playwright: _playwright }, use: (testServer: TestServerHandle) => Promise<void>) => {
|
||||
const testServer = await startTestServer();
|
||||
|
||||
await use(testServer);
|
||||
await testServer.stop();
|
||||
},
|
||||
|
||||
createClient: async ({ testServer }, use) => {
|
||||
const browsers: Browser[] = [];
|
||||
const clients: Client[] = [];
|
||||
const factory = async (): Promise<Client> => {
|
||||
// Launch a dedicated browser per client so each gets its own fake
|
||||
// audio device - shared browsers can starve the first context's
|
||||
// audio capture under load.
|
||||
const browser = await chromium.launch({ args: CHROMIUM_FAKE_MEDIA_ARGS });
|
||||
|
||||
browsers.push(browser);
|
||||
|
||||
const context = await browser.newContext({
|
||||
permissions: ['microphone', 'camera'],
|
||||
baseURL: 'http://localhost:4200'
|
||||
});
|
||||
|
||||
await installTestServerEndpoint(context, testServer.port);
|
||||
|
||||
const page = await context.newPage();
|
||||
|
||||
clients.push({ page, context });
|
||||
return { page, context };
|
||||
};
|
||||
|
||||
await use(factory);
|
||||
|
||||
for (const client of clients) {
|
||||
await client.context.close();
|
||||
}
|
||||
|
||||
for (const browser of browsers) {
|
||||
await browser.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export { expect } from '@playwright/test';
|
||||
|
||||
async function startTestServer(retries = 3): Promise<TestServerHandle> {
|
||||
for (let attempt = 1; attempt <= retries; attempt++) {
|
||||
const port = await allocatePort();
|
||||
const child = spawn(process.execPath, [START_SERVER_SCRIPT], {
|
||||
cwd: E2E_DIR,
|
||||
env: {
|
||||
...process.env,
|
||||
TEST_SERVER_PORT: String(port)
|
||||
},
|
||||
stdio: 'pipe'
|
||||
});
|
||||
|
||||
child.stdout?.on('data', (chunk: Buffer | string) => {
|
||||
process.stdout.write(chunk.toString());
|
||||
});
|
||||
|
||||
child.stderr?.on('data', (chunk: Buffer | string) => {
|
||||
process.stderr.write(chunk.toString());
|
||||
});
|
||||
|
||||
try {
|
||||
await waitForServerReady(port, child);
|
||||
} catch (error) {
|
||||
await stopServer(child);
|
||||
|
||||
if (attempt < retries) {
|
||||
console.log(`[E2E Server] Attempt ${attempt} failed, retrying...`);
|
||||
continue;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
return {
|
||||
port,
|
||||
url: `http://localhost:${port}`,
|
||||
stop: async () => {
|
||||
await stopServer(child);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error('startTestServer: unreachable');
|
||||
}
|
||||
|
||||
async function allocatePort(): Promise<number> {
|
||||
return new Promise<number>((resolve, reject) => {
|
||||
const probe = createServer();
|
||||
|
||||
probe.once('error', reject);
|
||||
probe.listen(0, '127.0.0.1', () => {
|
||||
const address = probe.address();
|
||||
|
||||
if (!address || typeof address === 'string') {
|
||||
probe.close();
|
||||
reject(new Error('Failed to resolve an ephemeral test server port'));
|
||||
return;
|
||||
}
|
||||
|
||||
const { port } = address;
|
||||
|
||||
probe.close((error) => {
|
||||
if (error) {
|
||||
reject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(port);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function waitForServerReady(port: number, child: ChildProcess, timeoutMs = 30_000): Promise<void> {
|
||||
const readyUrl = `http://127.0.0.1:${port}/api/servers?limit=1`;
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
if (child.exitCode !== null) {
|
||||
throw new Error(`Test server exited before becoming ready (exit code ${child.exitCode})`);
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(readyUrl);
|
||||
|
||||
if (response.ok) {
|
||||
return;
|
||||
}
|
||||
} catch {
|
||||
// Server still starting.
|
||||
}
|
||||
|
||||
await wait(250);
|
||||
}
|
||||
|
||||
throw new Error(`Timed out waiting for test server on port ${port}`);
|
||||
}
|
||||
|
||||
async function stopServer(child: ChildProcess): Promise<void> {
|
||||
if (child.exitCode !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
child.kill('SIGTERM');
|
||||
|
||||
const exited = await Promise.race([once(child, 'exit').then(() => true), wait(3_000).then(() => false)]);
|
||||
|
||||
if (!exited && child.exitCode === null) {
|
||||
child.kill('SIGKILL');
|
||||
await once(child, 'exit');
|
||||
}
|
||||
}
|
||||
|
||||
function wait(durationMs: number): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, durationMs);
|
||||
});
|
||||
}
|
||||
BIN
e2e/fixtures/test-tone.wav
Normal file
BIN
e2e/fixtures/test-tone.wav
Normal file
Binary file not shown.
77
e2e/helpers/seed-test-endpoint.ts
Normal file
77
e2e/helpers/seed-test-endpoint.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { type BrowserContext, type Page } from '@playwright/test';
|
||||
|
||||
const SERVER_ENDPOINTS_STORAGE_KEY = 'metoyou_server_endpoints';
|
||||
const REMOVED_DEFAULT_KEYS_STORAGE_KEY = 'metoyou_removed_default_server_keys';
|
||||
|
||||
type SeededEndpointStorageState = {
|
||||
key: string;
|
||||
removedKey: string;
|
||||
endpoints: {
|
||||
id: string;
|
||||
name: string;
|
||||
url: string;
|
||||
isActive: boolean;
|
||||
isDefault: boolean;
|
||||
status: string;
|
||||
}[];
|
||||
};
|
||||
|
||||
function buildSeededEndpointStorageState(
|
||||
port: number = Number(process.env.TEST_SERVER_PORT) || 3099
|
||||
): SeededEndpointStorageState {
|
||||
const endpoint = {
|
||||
id: 'e2e-test-server',
|
||||
name: 'E2E Test Server',
|
||||
url: `http://localhost:${port}`,
|
||||
isActive: true,
|
||||
isDefault: false,
|
||||
status: 'unknown'
|
||||
};
|
||||
|
||||
return {
|
||||
key: SERVER_ENDPOINTS_STORAGE_KEY,
|
||||
removedKey: REMOVED_DEFAULT_KEYS_STORAGE_KEY,
|
||||
endpoints: [endpoint]
|
||||
};
|
||||
}
|
||||
|
||||
function applySeededEndpointStorageState(storageState: SeededEndpointStorageState): void {
|
||||
try {
|
||||
const storage = window.localStorage;
|
||||
|
||||
storage.setItem(storageState.key, JSON.stringify(storageState.endpoints));
|
||||
storage.setItem(storageState.removedKey, JSON.stringify(['default', 'toju-primary', 'toju-sweden']));
|
||||
} catch {
|
||||
// about:blank and some Playwright UI pages deny localStorage access.
|
||||
}
|
||||
}
|
||||
|
||||
export async function installTestServerEndpoint(
|
||||
context: BrowserContext,
|
||||
port: number = Number(process.env.TEST_SERVER_PORT) || 3099
|
||||
): Promise<void> {
|
||||
const storageState = buildSeededEndpointStorageState(port);
|
||||
|
||||
await context.addInitScript(applySeededEndpointStorageState, storageState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Seed localStorage with a single signal endpoint pointing at the test server.
|
||||
* Must be called AFTER navigating to the app origin (localStorage is per-origin)
|
||||
* but BEFORE the app reads from storage (i.e. before the Angular bootstrap is
|
||||
* relied upon — calling it in the first goto() landing page is fine since the
|
||||
* page will re-read on next navigation/reload).
|
||||
*
|
||||
* Typical usage:
|
||||
* await page.goto('/');
|
||||
* await seedTestServerEndpoint(page);
|
||||
* await page.reload(); // App now picks up the test endpoint
|
||||
*/
|
||||
export async function seedTestServerEndpoint(
|
||||
page: Page,
|
||||
port: number = Number(process.env.TEST_SERVER_PORT) || 3099
|
||||
): Promise<void> {
|
||||
const storageState = buildSeededEndpointStorageState(port);
|
||||
|
||||
await page.evaluate(applySeededEndpointStorageState, storageState);
|
||||
}
|
||||
107
e2e/helpers/start-test-server.js
Normal file
107
e2e/helpers/start-test-server.js
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Launches an isolated MetoYou signaling server for E2E tests.
|
||||
*
|
||||
* Creates a temporary data directory so the test server gets its own
|
||||
* fresh SQLite database. The server process inherits stdio so Playwright
|
||||
* can watch stdout for readiness and the developer can see logs.
|
||||
*
|
||||
* Cleanup: the temp directory is removed when the process exits.
|
||||
*/
|
||||
const { mkdtempSync, writeFileSync, mkdirSync, rmSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
const { tmpdir } = require('os');
|
||||
const { spawn } = require('child_process');
|
||||
|
||||
const TEST_PORT = process.env.TEST_SERVER_PORT || '3099';
|
||||
const SERVER_DIR = join(__dirname, '..', '..', 'server');
|
||||
const SERVER_ENTRY = join(SERVER_DIR, 'src', 'index.ts');
|
||||
const SERVER_TSCONFIG = join(SERVER_DIR, 'tsconfig.json');
|
||||
|
||||
// ── Create isolated temp data directory ──────────────────────────────
|
||||
const tmpDir = mkdtempSync(join(tmpdir(), 'metoyou-e2e-'));
|
||||
const dataDir = join(tmpDir, 'data');
|
||||
mkdirSync(dataDir, { recursive: true });
|
||||
|
||||
writeFileSync(
|
||||
join(dataDir, 'variables.json'),
|
||||
JSON.stringify({
|
||||
serverPort: parseInt(TEST_PORT, 10),
|
||||
serverProtocol: 'http',
|
||||
serverHost: '',
|
||||
klipyApiKey: '',
|
||||
releaseManifestUrl: '',
|
||||
linkPreview: { enabled: false, cacheTtlMinutes: 60, maxCacheSizeMb: 10 },
|
||||
})
|
||||
);
|
||||
|
||||
console.log(`[E2E Server] Temp data dir: ${tmpDir}`);
|
||||
console.log(`[E2E Server] Starting on port ${TEST_PORT}...`);
|
||||
|
||||
// ── Spawn the server with cwd = temp dir ─────────────────────────────
|
||||
// process.cwd() is used by getRuntimeBaseDir() in the server, so data/
|
||||
// (database, variables.json) will resolve to our temp directory.
|
||||
// Module resolution (require/import) uses __dirname, so server source
|
||||
// and node_modules are found from the real server/ directory.
|
||||
const child = spawn(
|
||||
'npx',
|
||||
['ts-node', '--project', SERVER_TSCONFIG, SERVER_ENTRY],
|
||||
{
|
||||
cwd: tmpDir,
|
||||
env: {
|
||||
...process.env,
|
||||
PORT: TEST_PORT,
|
||||
SSL: 'false',
|
||||
NODE_ENV: 'test',
|
||||
DB_SYNCHRONIZE: 'true',
|
||||
},
|
||||
stdio: 'inherit',
|
||||
shell: true,
|
||||
}
|
||||
);
|
||||
|
||||
let shuttingDown = false;
|
||||
|
||||
child.on('error', (err) => {
|
||||
console.error('[E2E Server] Failed to start:', err.message);
|
||||
cleanup();
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
child.on('exit', (code) => {
|
||||
console.log(`[E2E Server] Exited with code ${code}`);
|
||||
cleanup();
|
||||
|
||||
if (shuttingDown) {
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
// ── Cleanup on signals ───────────────────────────────────────────────
|
||||
function cleanup() {
|
||||
try {
|
||||
rmSync(tmpDir, { recursive: true, force: true });
|
||||
console.log(`[E2E Server] Cleaned up temp dir: ${tmpDir}`);
|
||||
} catch {
|
||||
// already gone
|
||||
}
|
||||
}
|
||||
|
||||
function shutdown() {
|
||||
if (shuttingDown) {
|
||||
return;
|
||||
}
|
||||
|
||||
shuttingDown = true;
|
||||
child.kill('SIGTERM');
|
||||
|
||||
// Give child 3s to exit, then force kill
|
||||
setTimeout(() => {
|
||||
if (child.exitCode === null) {
|
||||
child.kill('SIGKILL');
|
||||
}
|
||||
}, 3_000);
|
||||
}
|
||||
|
||||
process.on('SIGTERM', shutdown);
|
||||
process.on('SIGINT', shutdown);
|
||||
process.on('exit', cleanup);
|
||||
717
e2e/helpers/webrtc-helpers.ts
Normal file
717
e2e/helpers/webrtc-helpers.ts
Normal file
@@ -0,0 +1,717 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { type Page } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* Install RTCPeerConnection monkey-patch on a page BEFORE navigating.
|
||||
* Tracks all created peer connections and their remote tracks so tests
|
||||
* can inspect WebRTC state via `page.evaluate()`.
|
||||
*
|
||||
* Call immediately after page creation, before any `goto()`.
|
||||
*/
|
||||
export async function installWebRTCTracking(page: Page): Promise<void> {
|
||||
await page.addInitScript(() => {
|
||||
const connections: RTCPeerConnection[] = [];
|
||||
|
||||
(window as any).__rtcConnections = connections;
|
||||
(window as any).__rtcRemoteTracks = [] as { kind: string; id: string; readyState: string }[];
|
||||
|
||||
const OriginalRTCPeerConnection = window.RTCPeerConnection;
|
||||
|
||||
(window as any).RTCPeerConnection = function(this: RTCPeerConnection, ...args: any[]) {
|
||||
const pc: RTCPeerConnection = new OriginalRTCPeerConnection(...args);
|
||||
|
||||
connections.push(pc);
|
||||
|
||||
pc.addEventListener('connectionstatechange', () => {
|
||||
(window as any).__lastRtcState = pc.connectionState;
|
||||
});
|
||||
|
||||
pc.addEventListener('track', (event: RTCTrackEvent) => {
|
||||
(window as any).__rtcRemoteTracks.push({
|
||||
kind: event.track.kind,
|
||||
id: event.track.id,
|
||||
readyState: event.track.readyState
|
||||
});
|
||||
});
|
||||
|
||||
return pc;
|
||||
} as any;
|
||||
|
||||
(window as any).RTCPeerConnection.prototype = OriginalRTCPeerConnection.prototype;
|
||||
Object.setPrototypeOf((window as any).RTCPeerConnection, OriginalRTCPeerConnection);
|
||||
|
||||
// Patch getUserMedia to use an AudioContext oscillator for audio
|
||||
// instead of the hardware capture device. Chromium's fake audio
|
||||
// device intermittently fails to produce frames after renegotiation.
|
||||
const origGetUserMedia = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
|
||||
|
||||
navigator.mediaDevices.getUserMedia = async (constraints?: MediaStreamConstraints) => {
|
||||
const wantsAudio = !!constraints?.audio;
|
||||
|
||||
if (!wantsAudio) {
|
||||
return origGetUserMedia(constraints);
|
||||
}
|
||||
|
||||
// Get the original stream (may include video)
|
||||
const originalStream = await origGetUserMedia(constraints);
|
||||
const audioCtx = new AudioContext();
|
||||
const oscillator = audioCtx.createOscillator();
|
||||
|
||||
oscillator.frequency.value = 440;
|
||||
|
||||
const dest = audioCtx.createMediaStreamDestination();
|
||||
|
||||
oscillator.connect(dest);
|
||||
oscillator.start();
|
||||
|
||||
const synthAudioTrack = dest.stream.getAudioTracks()[0];
|
||||
const resultStream = new MediaStream();
|
||||
|
||||
resultStream.addTrack(synthAudioTrack);
|
||||
|
||||
// Keep any video tracks from the original stream
|
||||
for (const videoTrack of originalStream.getVideoTracks()) {
|
||||
resultStream.addTrack(videoTrack);
|
||||
}
|
||||
|
||||
// Stop original audio tracks since we're not using them
|
||||
for (const track of originalStream.getAudioTracks()) {
|
||||
track.stop();
|
||||
}
|
||||
|
||||
return resultStream;
|
||||
};
|
||||
|
||||
// Patch getDisplayMedia to return a synthetic screen share stream
|
||||
// (canvas-based video + 880Hz oscillator audio) so the browser
|
||||
// picker dialog is never shown.
|
||||
navigator.mediaDevices.getDisplayMedia = async (_constraints?: DisplayMediaStreamOptions) => {
|
||||
const canvas = document.createElement('canvas');
|
||||
|
||||
canvas.width = 640;
|
||||
canvas.height = 480;
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
if (!ctx) {
|
||||
throw new Error('Canvas 2D context unavailable');
|
||||
}
|
||||
|
||||
let frameCount = 0;
|
||||
|
||||
// Draw animated frames so video stats show increasing bytes
|
||||
const drawFrame = () => {
|
||||
frameCount++;
|
||||
ctx.fillStyle = `hsl(${frameCount % 360}, 70%, 50%)`;
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.fillStyle = '#fff';
|
||||
ctx.font = '24px monospace';
|
||||
ctx.fillText(`Screen Share Frame ${frameCount}`, 40, 60);
|
||||
};
|
||||
|
||||
drawFrame();
|
||||
const drawInterval = setInterval(drawFrame, 100);
|
||||
const videoStream = canvas.captureStream(10); // 10 fps
|
||||
const videoTrack = videoStream.getVideoTracks()[0];
|
||||
|
||||
// Stop drawing when the track ends
|
||||
videoTrack.addEventListener('ended', () => clearInterval(drawInterval));
|
||||
|
||||
// Create 880Hz oscillator for screen share audio (distinct from 440Hz voice)
|
||||
const audioCtx = new AudioContext();
|
||||
const osc = audioCtx.createOscillator();
|
||||
|
||||
osc.frequency.value = 880;
|
||||
|
||||
const dest = audioCtx.createMediaStreamDestination();
|
||||
|
||||
osc.connect(dest);
|
||||
osc.start();
|
||||
|
||||
const audioTrack = dest.stream.getAudioTracks()[0];
|
||||
// Combine video + audio into one stream
|
||||
const resultStream = new MediaStream([videoTrack, audioTrack]);
|
||||
|
||||
// Tag the stream so tests can identify it
|
||||
(resultStream as any).__isScreenShare = true;
|
||||
|
||||
return resultStream;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until at least one RTCPeerConnection reaches the 'connected' state.
|
||||
*/
|
||||
export async function waitForPeerConnected(page: Page, timeout = 30_000): Promise<void> {
|
||||
await page.waitForFunction(
|
||||
() => (window as any).__rtcConnections?.some(
|
||||
(pc: RTCPeerConnection) => pc.connectionState === 'connected'
|
||||
) ?? false,
|
||||
{ timeout }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that a peer connection is still in 'connected' state (not failed/disconnected).
|
||||
*/
|
||||
export async function isPeerStillConnected(page: Page): Promise<boolean> {
|
||||
return page.evaluate(
|
||||
() => (window as any).__rtcConnections?.some(
|
||||
(pc: RTCPeerConnection) => pc.connectionState === 'connected'
|
||||
) ?? false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get outbound and inbound audio RTP stats aggregated across all peer
|
||||
* connections. Uses a per-connection high water mark stored on `window` so
|
||||
* that connections that close mid-measurement still contribute their last
|
||||
* known counters, preventing the aggregate from going backwards.
|
||||
*/
|
||||
export async function getAudioStats(page: Page): Promise<{
|
||||
outbound: { bytesSent: number; packetsSent: number } | null;
|
||||
inbound: { bytesReceived: number; packetsReceived: number } | null;
|
||||
}> {
|
||||
return page.evaluate(async () => {
|
||||
const connections = (window as any).__rtcConnections as RTCPeerConnection[] | undefined;
|
||||
|
||||
if (!connections?.length)
|
||||
return { outbound: null, inbound: null };
|
||||
|
||||
interface HWMEntry {
|
||||
outBytesSent: number;
|
||||
outPacketsSent: number;
|
||||
inBytesReceived: number;
|
||||
inPacketsReceived: number;
|
||||
hasOutbound: boolean;
|
||||
hasInbound: boolean;
|
||||
};
|
||||
|
||||
const hwm: Record<number, HWMEntry> = (window as any).__rtcStatsHWM =
|
||||
((window as any).__rtcStatsHWM as Record<number, HWMEntry> | undefined) ?? {};
|
||||
|
||||
for (let idx = 0; idx < connections.length; idx++) {
|
||||
let stats: RTCStatsReport;
|
||||
|
||||
try {
|
||||
stats = await connections[idx].getStats();
|
||||
} catch {
|
||||
continue; // closed connection - keep its last HWM
|
||||
}
|
||||
|
||||
let obytes = 0;
|
||||
let opackets = 0;
|
||||
let ibytes = 0;
|
||||
let ipackets = 0;
|
||||
let hasOut = false;
|
||||
let hasIn = false;
|
||||
|
||||
stats.forEach((report: any) => {
|
||||
const kind = report.kind ?? report.mediaType;
|
||||
|
||||
if (report.type === 'outbound-rtp' && kind === 'audio') {
|
||||
hasOut = true;
|
||||
obytes += report.bytesSent ?? 0;
|
||||
opackets += report.packetsSent ?? 0;
|
||||
}
|
||||
|
||||
if (report.type === 'inbound-rtp' && kind === 'audio') {
|
||||
hasIn = true;
|
||||
ibytes += report.bytesReceived ?? 0;
|
||||
ipackets += report.packetsReceived ?? 0;
|
||||
}
|
||||
});
|
||||
|
||||
if (hasOut || hasIn) {
|
||||
hwm[idx] = {
|
||||
outBytesSent: obytes,
|
||||
outPacketsSent: opackets,
|
||||
inBytesReceived: ibytes,
|
||||
inPacketsReceived: ipackets,
|
||||
hasOutbound: hasOut,
|
||||
hasInbound: hasIn
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let totalOutBytes = 0;
|
||||
let totalOutPackets = 0;
|
||||
let totalInBytes = 0;
|
||||
let totalInPackets = 0;
|
||||
let anyOutbound = false;
|
||||
let anyInbound = false;
|
||||
|
||||
for (const entry of Object.values(hwm)) {
|
||||
totalOutBytes += entry.outBytesSent;
|
||||
totalOutPackets += entry.outPacketsSent;
|
||||
totalInBytes += entry.inBytesReceived;
|
||||
totalInPackets += entry.inPacketsReceived;
|
||||
|
||||
if (entry.hasOutbound)
|
||||
anyOutbound = true;
|
||||
|
||||
if (entry.hasInbound)
|
||||
anyInbound = true;
|
||||
}
|
||||
|
||||
return {
|
||||
outbound: anyOutbound
|
||||
? { bytesSent: totalOutBytes, packetsSent: totalOutPackets }
|
||||
: null,
|
||||
inbound: anyInbound
|
||||
? { bytesReceived: totalInBytes, packetsReceived: totalInPackets }
|
||||
: null
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Snapshot audio stats, wait `durationMs`, snapshot again, and return the delta.
|
||||
* Useful for verifying audio is actively flowing (bytes increasing).
|
||||
*/
|
||||
export async function getAudioStatsDelta(page: Page, durationMs = 3_000): Promise<{
|
||||
outboundBytesDelta: number;
|
||||
inboundBytesDelta: number;
|
||||
outboundPacketsDelta: number;
|
||||
inboundPacketsDelta: number;
|
||||
}> {
|
||||
const before = await getAudioStats(page);
|
||||
|
||||
await page.waitForTimeout(durationMs);
|
||||
|
||||
const after = await getAudioStats(page);
|
||||
|
||||
return {
|
||||
outboundBytesDelta: (after.outbound?.bytesSent ?? 0) - (before.outbound?.bytesSent ?? 0),
|
||||
inboundBytesDelta: (after.inbound?.bytesReceived ?? 0) - (before.inbound?.bytesReceived ?? 0),
|
||||
outboundPacketsDelta: (after.outbound?.packetsSent ?? 0) - (before.outbound?.packetsSent ?? 0),
|
||||
inboundPacketsDelta: (after.inbound?.packetsReceived ?? 0) - (before.inbound?.packetsReceived ?? 0)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until at least one connection has both outbound-rtp and inbound-rtp
|
||||
* audio reports. Call after `waitForPeerConnected` to ensure the audio
|
||||
* pipeline is ready before measuring deltas.
|
||||
*/
|
||||
export async function waitForAudioStatsPresent(page: Page, timeout = 15_000): Promise<void> {
|
||||
await page.waitForFunction(
|
||||
async () => {
|
||||
const connections = (window as any).__rtcConnections as RTCPeerConnection[] | undefined;
|
||||
|
||||
if (!connections?.length)
|
||||
return false;
|
||||
|
||||
for (const pc of connections) {
|
||||
let stats: RTCStatsReport;
|
||||
|
||||
try {
|
||||
stats = await pc.getStats();
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
let hasOut = false;
|
||||
let hasIn = false;
|
||||
|
||||
stats.forEach((report: any) => {
|
||||
const kind = report.kind ?? report.mediaType;
|
||||
|
||||
if (report.type === 'outbound-rtp' && kind === 'audio')
|
||||
hasOut = true;
|
||||
|
||||
if (report.type === 'inbound-rtp' && kind === 'audio')
|
||||
hasIn = true;
|
||||
});
|
||||
|
||||
if (hasOut && hasIn)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
{ timeout }
|
||||
);
|
||||
}
|
||||
|
||||
interface AudioFlowDelta {
|
||||
outboundBytesDelta: number;
|
||||
inboundBytesDelta: number;
|
||||
outboundPacketsDelta: number;
|
||||
inboundPacketsDelta: number;
|
||||
}
|
||||
|
||||
function snapshotToDelta(
|
||||
curr: Awaited<ReturnType<typeof getAudioStats>>,
|
||||
prev: Awaited<ReturnType<typeof getAudioStats>>
|
||||
): AudioFlowDelta {
|
||||
return {
|
||||
outboundBytesDelta: (curr.outbound?.bytesSent ?? 0) - (prev.outbound?.bytesSent ?? 0),
|
||||
inboundBytesDelta: (curr.inbound?.bytesReceived ?? 0) - (prev.inbound?.bytesReceived ?? 0),
|
||||
outboundPacketsDelta: (curr.outbound?.packetsSent ?? 0) - (prev.outbound?.packetsSent ?? 0),
|
||||
inboundPacketsDelta: (curr.inbound?.packetsReceived ?? 0) - (prev.inbound?.packetsReceived ?? 0)
|
||||
};
|
||||
}
|
||||
|
||||
function isDeltaFlowing(delta: AudioFlowDelta): boolean {
|
||||
const outFlowing = delta.outboundBytesDelta > 0 || delta.outboundPacketsDelta > 0;
|
||||
const inFlowing = delta.inboundBytesDelta > 0 || delta.inboundPacketsDelta > 0;
|
||||
|
||||
return outFlowing && inFlowing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Poll until two consecutive HWM-based reads show both outbound and inbound
|
||||
* audio byte counts increasing. Combines per-connection high-water marks
|
||||
* (which prevent totals from going backwards after connection churn) with
|
||||
* consecutive comparison (which avoids a stale single baseline).
|
||||
*/
|
||||
export async function waitForAudioFlow(
|
||||
page: Page,
|
||||
timeoutMs = 30_000,
|
||||
pollIntervalMs = 1_000
|
||||
): Promise<AudioFlowDelta> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
let prev = await getAudioStats(page);
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
await page.waitForTimeout(pollIntervalMs);
|
||||
const curr = await getAudioStats(page);
|
||||
const delta = snapshotToDelta(curr, prev);
|
||||
|
||||
if (isDeltaFlowing(delta)) {
|
||||
return delta;
|
||||
}
|
||||
|
||||
prev = curr;
|
||||
}
|
||||
|
||||
// Timeout - return zero deltas so the caller's assertion reports the failure.
|
||||
return {
|
||||
outboundBytesDelta: 0,
|
||||
inboundBytesDelta: 0,
|
||||
outboundPacketsDelta: 0,
|
||||
inboundPacketsDelta: 0
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get outbound and inbound video RTP stats aggregated across all peer
|
||||
* connections. Uses the same HWM pattern as {@link getAudioStats}.
|
||||
*/
|
||||
export async function getVideoStats(page: Page): Promise<{
|
||||
outbound: { bytesSent: number; packetsSent: number } | null;
|
||||
inbound: { bytesReceived: number; packetsReceived: number } | null;
|
||||
}> {
|
||||
return page.evaluate(async () => {
|
||||
const connections = (window as any).__rtcConnections as RTCPeerConnection[] | undefined;
|
||||
|
||||
if (!connections?.length)
|
||||
return { outbound: null, inbound: null };
|
||||
|
||||
interface VHWM {
|
||||
outBytesSent: number;
|
||||
outPacketsSent: number;
|
||||
inBytesReceived: number;
|
||||
inPacketsReceived: number;
|
||||
hasOutbound: boolean;
|
||||
hasInbound: boolean;
|
||||
}
|
||||
|
||||
const hwm: Record<number, VHWM> = (window as any).__rtcVideoStatsHWM =
|
||||
((window as any).__rtcVideoStatsHWM as Record<number, VHWM> | undefined) ?? {};
|
||||
|
||||
for (let idx = 0; idx < connections.length; idx++) {
|
||||
let stats: RTCStatsReport;
|
||||
|
||||
try {
|
||||
stats = await connections[idx].getStats();
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
let obytes = 0;
|
||||
let opackets = 0;
|
||||
let ibytes = 0;
|
||||
let ipackets = 0;
|
||||
let hasOut = false;
|
||||
let hasIn = false;
|
||||
|
||||
stats.forEach((report: any) => {
|
||||
const kind = report.kind ?? report.mediaType;
|
||||
|
||||
if (report.type === 'outbound-rtp' && kind === 'video') {
|
||||
hasOut = true;
|
||||
obytes += report.bytesSent ?? 0;
|
||||
opackets += report.packetsSent ?? 0;
|
||||
}
|
||||
|
||||
if (report.type === 'inbound-rtp' && kind === 'video') {
|
||||
hasIn = true;
|
||||
ibytes += report.bytesReceived ?? 0;
|
||||
ipackets += report.packetsReceived ?? 0;
|
||||
}
|
||||
});
|
||||
|
||||
if (hasOut || hasIn) {
|
||||
hwm[idx] = {
|
||||
outBytesSent: obytes,
|
||||
outPacketsSent: opackets,
|
||||
inBytesReceived: ibytes,
|
||||
inPacketsReceived: ipackets,
|
||||
hasOutbound: hasOut,
|
||||
hasInbound: hasIn
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let totalOutBytes = 0;
|
||||
let totalOutPackets = 0;
|
||||
let totalInBytes = 0;
|
||||
let totalInPackets = 0;
|
||||
let anyOutbound = false;
|
||||
let anyInbound = false;
|
||||
|
||||
for (const entry of Object.values(hwm)) {
|
||||
totalOutBytes += entry.outBytesSent;
|
||||
totalOutPackets += entry.outPacketsSent;
|
||||
totalInBytes += entry.inBytesReceived;
|
||||
totalInPackets += entry.inPacketsReceived;
|
||||
|
||||
if (entry.hasOutbound)
|
||||
anyOutbound = true;
|
||||
|
||||
if (entry.hasInbound)
|
||||
anyInbound = true;
|
||||
}
|
||||
|
||||
return {
|
||||
outbound: anyOutbound
|
||||
? { bytesSent: totalOutBytes, packetsSent: totalOutPackets }
|
||||
: null,
|
||||
inbound: anyInbound
|
||||
? { bytesReceived: totalInBytes, packetsReceived: totalInPackets }
|
||||
: null
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until at least one connection has both outbound-rtp and inbound-rtp
|
||||
* video reports.
|
||||
*/
|
||||
export async function waitForVideoStatsPresent(page: Page, timeout = 15_000): Promise<void> {
|
||||
await page.waitForFunction(
|
||||
async () => {
|
||||
const connections = (window as any).__rtcConnections as RTCPeerConnection[] | undefined;
|
||||
|
||||
if (!connections?.length)
|
||||
return false;
|
||||
|
||||
for (const pc of connections) {
|
||||
let stats: RTCStatsReport;
|
||||
|
||||
try {
|
||||
stats = await pc.getStats();
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
|
||||
let hasOut = false;
|
||||
let hasIn = false;
|
||||
|
||||
stats.forEach((report: any) => {
|
||||
const kind = report.kind ?? report.mediaType;
|
||||
|
||||
if (report.type === 'outbound-rtp' && kind === 'video')
|
||||
hasOut = true;
|
||||
|
||||
if (report.type === 'inbound-rtp' && kind === 'video')
|
||||
hasIn = true;
|
||||
});
|
||||
|
||||
if (hasOut && hasIn)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
{ timeout }
|
||||
);
|
||||
}
|
||||
|
||||
interface VideoFlowDelta {
|
||||
outboundBytesDelta: number;
|
||||
inboundBytesDelta: number;
|
||||
outboundPacketsDelta: number;
|
||||
inboundPacketsDelta: number;
|
||||
}
|
||||
|
||||
function videoSnapshotToDelta(
|
||||
curr: Awaited<ReturnType<typeof getVideoStats>>,
|
||||
prev: Awaited<ReturnType<typeof getVideoStats>>
|
||||
): VideoFlowDelta {
|
||||
return {
|
||||
outboundBytesDelta: (curr.outbound?.bytesSent ?? 0) - (prev.outbound?.bytesSent ?? 0),
|
||||
inboundBytesDelta: (curr.inbound?.bytesReceived ?? 0) - (prev.inbound?.bytesReceived ?? 0),
|
||||
outboundPacketsDelta: (curr.outbound?.packetsSent ?? 0) - (prev.outbound?.packetsSent ?? 0),
|
||||
inboundPacketsDelta: (curr.inbound?.packetsReceived ?? 0) - (prev.inbound?.packetsReceived ?? 0)
|
||||
};
|
||||
}
|
||||
|
||||
function isVideoDeltaFlowing(delta: VideoFlowDelta): boolean {
|
||||
const outFlowing = delta.outboundBytesDelta > 0 || delta.outboundPacketsDelta > 0;
|
||||
const inFlowing = delta.inboundBytesDelta > 0 || delta.inboundPacketsDelta > 0;
|
||||
|
||||
return outFlowing && inFlowing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Poll until two consecutive HWM-based reads show both outbound and inbound
|
||||
* video byte counts increasing - proving screen share video is flowing.
|
||||
*/
|
||||
export async function waitForVideoFlow(
|
||||
page: Page,
|
||||
timeoutMs = 30_000,
|
||||
pollIntervalMs = 1_000
|
||||
): Promise<VideoFlowDelta> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
let prev = await getVideoStats(page);
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
await page.waitForTimeout(pollIntervalMs);
|
||||
const curr = await getVideoStats(page);
|
||||
const delta = videoSnapshotToDelta(curr, prev);
|
||||
|
||||
if (isVideoDeltaFlowing(delta)) {
|
||||
return delta;
|
||||
}
|
||||
|
||||
prev = curr;
|
||||
}
|
||||
|
||||
return {
|
||||
outboundBytesDelta: 0,
|
||||
inboundBytesDelta: 0,
|
||||
outboundPacketsDelta: 0,
|
||||
inboundPacketsDelta: 0
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until outbound video bytes are increasing (sender side).
|
||||
* Use on the page that is sharing its screen.
|
||||
*/
|
||||
export async function waitForOutboundVideoFlow(
|
||||
page: Page,
|
||||
timeoutMs = 30_000,
|
||||
pollIntervalMs = 1_000
|
||||
): Promise<VideoFlowDelta> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
let prev = await getVideoStats(page);
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
await page.waitForTimeout(pollIntervalMs);
|
||||
const curr = await getVideoStats(page);
|
||||
const delta = videoSnapshotToDelta(curr, prev);
|
||||
|
||||
if (delta.outboundBytesDelta > 0 || delta.outboundPacketsDelta > 0) {
|
||||
return delta;
|
||||
}
|
||||
|
||||
prev = curr;
|
||||
}
|
||||
|
||||
return {
|
||||
outboundBytesDelta: 0,
|
||||
inboundBytesDelta: 0,
|
||||
outboundPacketsDelta: 0,
|
||||
inboundPacketsDelta: 0
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until inbound video bytes are increasing (receiver side).
|
||||
* Use on the page that is viewing someone else's screen share.
|
||||
*/
|
||||
export async function waitForInboundVideoFlow(
|
||||
page: Page,
|
||||
timeoutMs = 30_000,
|
||||
pollIntervalMs = 1_000
|
||||
): Promise<VideoFlowDelta> {
|
||||
const deadline = Date.now() + timeoutMs;
|
||||
|
||||
let prev = await getVideoStats(page);
|
||||
|
||||
while (Date.now() < deadline) {
|
||||
await page.waitForTimeout(pollIntervalMs);
|
||||
const curr = await getVideoStats(page);
|
||||
const delta = videoSnapshotToDelta(curr, prev);
|
||||
|
||||
if (delta.inboundBytesDelta > 0 || delta.inboundPacketsDelta > 0) {
|
||||
return delta;
|
||||
}
|
||||
|
||||
prev = curr;
|
||||
}
|
||||
|
||||
return {
|
||||
outboundBytesDelta: 0,
|
||||
inboundBytesDelta: 0,
|
||||
outboundPacketsDelta: 0,
|
||||
inboundPacketsDelta: 0
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump full RTC connection diagnostics for debugging audio flow failures.
|
||||
*/
|
||||
export async function dumpRtcDiagnostics(page: Page): Promise<string> {
|
||||
return page.evaluate(async () => {
|
||||
const conns = (window as any).__rtcConnections as RTCPeerConnection[] | undefined;
|
||||
|
||||
if (!conns?.length)
|
||||
return 'No connections tracked';
|
||||
|
||||
const lines: string[] = [`Total connections: ${conns.length}`];
|
||||
|
||||
for (let idx = 0; idx < conns.length; idx++) {
|
||||
const pc = conns[idx];
|
||||
|
||||
lines.push(`PC[${idx}]: connection=${pc.connectionState}, signaling=${pc.signalingState}`);
|
||||
|
||||
const senders = pc.getSenders().map(
|
||||
(sender) => `${sender.track?.kind ?? 'none'}:enabled=${sender.track?.enabled}:${sender.track?.readyState ?? 'null'}`
|
||||
);
|
||||
const receivers = pc.getReceivers().map(
|
||||
(recv) => `${recv.track?.kind ?? 'none'}:enabled=${recv.track?.enabled}:${recv.track?.readyState ?? 'null'}`
|
||||
);
|
||||
|
||||
lines.push(` senders=[${senders.join(', ')}]`);
|
||||
lines.push(` receivers=[${receivers.join(', ')}]`);
|
||||
|
||||
try {
|
||||
const stats = await pc.getStats();
|
||||
|
||||
stats.forEach((report: any) => {
|
||||
if (report.type !== 'outbound-rtp' && report.type !== 'inbound-rtp')
|
||||
return;
|
||||
|
||||
const kind = report.kind ?? report.mediaType;
|
||||
const bytes = report.type === 'outbound-rtp' ? report.bytesSent : report.bytesReceived;
|
||||
const packets = report.type === 'outbound-rtp' ? report.packetsSent : report.packetsReceived;
|
||||
|
||||
lines.push(` ${report.type}: kind=${kind}, bytes=${bytes}, packets=${packets}`);
|
||||
});
|
||||
} catch (err: any) {
|
||||
lines.push(` getStats() failed: ${err?.message ?? err}`);
|
||||
}
|
||||
}
|
||||
|
||||
return lines.join('\n');
|
||||
});
|
||||
}
|
||||
143
e2e/pages/chat-messages.page.ts
Normal file
143
e2e/pages/chat-messages.page.ts
Normal file
@@ -0,0 +1,143 @@
|
||||
import {
|
||||
expect,
|
||||
type Locator,
|
||||
type Page
|
||||
} from '@playwright/test';
|
||||
|
||||
export type ChatDropFilePayload = {
|
||||
name: string;
|
||||
mimeType: string;
|
||||
base64: string;
|
||||
};
|
||||
|
||||
export class ChatMessagesPage {
|
||||
readonly composer: Locator;
|
||||
readonly composerInput: Locator;
|
||||
readonly sendButton: Locator;
|
||||
readonly typingIndicator: Locator;
|
||||
readonly gifButton: Locator;
|
||||
readonly gifPicker: Locator;
|
||||
readonly messageItems: Locator;
|
||||
|
||||
constructor(private page: Page) {
|
||||
this.composer = page.locator('app-chat-message-composer');
|
||||
this.composerInput = page.getByPlaceholder('Type a message...');
|
||||
this.sendButton = page.getByRole('button', { name: 'Send message' });
|
||||
this.typingIndicator = page.locator('app-typing-indicator');
|
||||
this.gifButton = page.getByRole('button', { name: 'Search KLIPY GIFs' });
|
||||
this.gifPicker = page.getByRole('dialog', { name: 'KLIPY GIF picker' });
|
||||
this.messageItems = page.locator('[data-message-id]');
|
||||
}
|
||||
|
||||
async waitForReady(): Promise<void> {
|
||||
await expect(this.composerInput).toBeVisible({ timeout: 30_000 });
|
||||
}
|
||||
|
||||
async sendMessage(content: string): Promise<void> {
|
||||
await this.waitForReady();
|
||||
await this.composerInput.fill(content);
|
||||
await this.sendButton.click();
|
||||
}
|
||||
|
||||
async typeDraft(content: string): Promise<void> {
|
||||
await this.waitForReady();
|
||||
await this.composerInput.fill(content);
|
||||
}
|
||||
|
||||
async clearDraft(): Promise<void> {
|
||||
await this.waitForReady();
|
||||
await this.composerInput.fill('');
|
||||
}
|
||||
|
||||
async attachFiles(files: ChatDropFilePayload[]): Promise<void> {
|
||||
await this.waitForReady();
|
||||
|
||||
await this.composerInput.evaluate((element, payloads: ChatDropFilePayload[]) => {
|
||||
const dataTransfer = new DataTransfer();
|
||||
|
||||
for (const payload of payloads) {
|
||||
const binary = atob(payload.base64);
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
|
||||
for (let index = 0; index < binary.length; index++) {
|
||||
bytes[index] = binary.charCodeAt(index);
|
||||
}
|
||||
|
||||
dataTransfer.items.add(new File([bytes], payload.name, { type: payload.mimeType }));
|
||||
}
|
||||
|
||||
element.dispatchEvent(new DragEvent('drop', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
dataTransfer
|
||||
}));
|
||||
}, files);
|
||||
}
|
||||
|
||||
async openGifPicker(): Promise<void> {
|
||||
await this.waitForReady();
|
||||
await this.gifButton.click();
|
||||
await expect(this.gifPicker).toBeVisible({ timeout: 10_000 });
|
||||
}
|
||||
|
||||
async selectFirstGif(): Promise<void> {
|
||||
const gifCard = this.gifPicker.getByRole('button', { name: /click to select/i }).first();
|
||||
|
||||
await expect(gifCard).toBeVisible({ timeout: 10_000 });
|
||||
await gifCard.click();
|
||||
}
|
||||
|
||||
getMessageItemByText(text: string): Locator {
|
||||
return this.messageItems.filter({
|
||||
has: this.page.getByText(text, { exact: false })
|
||||
}).last();
|
||||
}
|
||||
|
||||
getMessageImageByAlt(altText: string): Locator {
|
||||
return this.page.locator(`[data-message-id] img[alt="${altText}"]`).last();
|
||||
}
|
||||
|
||||
async expectMessageImageLoaded(altText: string): Promise<void> {
|
||||
const image = this.getMessageImageByAlt(altText);
|
||||
|
||||
await expect(image).toBeVisible({ timeout: 20_000 });
|
||||
await expect.poll(async () =>
|
||||
image.evaluate((element) => {
|
||||
const img = element as HTMLImageElement;
|
||||
|
||||
return img.complete && img.naturalWidth > 0 && img.naturalHeight > 0;
|
||||
}), {
|
||||
timeout: 20_000,
|
||||
message: `Image ${altText} should fully load in chat`
|
||||
}).toBe(true);
|
||||
}
|
||||
|
||||
getEmbedCardByTitle(title: string): Locator {
|
||||
return this.page.locator('app-chat-link-embed').filter({
|
||||
has: this.page.getByText(title, { exact: true })
|
||||
}).last();
|
||||
}
|
||||
|
||||
async editOwnMessage(originalText: string, updatedText: string): Promise<void> {
|
||||
const messageItem = this.getMessageItemByText(originalText);
|
||||
const editButton = messageItem.locator('button:has(ng-icon[name="lucideEdit"])').first();
|
||||
const editTextarea = this.page.locator('textarea.edit-textarea').first();
|
||||
const saveButton = this.page.locator('button:has(ng-icon[name="lucideCheck"])').first();
|
||||
|
||||
await expect(messageItem).toBeVisible({ timeout: 15_000 });
|
||||
await messageItem.hover();
|
||||
await editButton.click();
|
||||
await expect(editTextarea).toBeVisible({ timeout: 10_000 });
|
||||
await editTextarea.fill(updatedText);
|
||||
await saveButton.click();
|
||||
}
|
||||
|
||||
async deleteOwnMessage(text: string): Promise<void> {
|
||||
const messageItem = this.getMessageItemByText(text);
|
||||
const deleteButton = messageItem.locator('button:has(ng-icon[name="lucideTrash2"])').first();
|
||||
|
||||
await expect(messageItem).toBeVisible({ timeout: 15_000 });
|
||||
await messageItem.hover();
|
||||
await deleteButton.click();
|
||||
}
|
||||
}
|
||||
390
e2e/pages/chat-room.page.ts
Normal file
390
e2e/pages/chat-room.page.ts
Normal file
@@ -0,0 +1,390 @@
|
||||
import {
|
||||
expect,
|
||||
type Page,
|
||||
type Locator
|
||||
} from '@playwright/test';
|
||||
|
||||
export class ChatRoomPage {
|
||||
readonly chatMessages: Locator;
|
||||
readonly voiceWorkspace: Locator;
|
||||
readonly channelsSidePanel: Locator;
|
||||
readonly usersSidePanel: Locator;
|
||||
|
||||
constructor(private page: Page) {
|
||||
this.chatMessages = page.locator('app-chat-messages');
|
||||
this.voiceWorkspace = page.locator('app-voice-workspace');
|
||||
this.channelsSidePanel = page.locator('app-rooms-side-panel').first();
|
||||
this.usersSidePanel = page.locator('app-rooms-side-panel').last();
|
||||
}
|
||||
|
||||
/** Click a voice channel by name in the channels sidebar to join voice. */
|
||||
async joinVoiceChannel(channelName: string) {
|
||||
const channelButton = this.page.locator('app-rooms-side-panel')
|
||||
.getByRole('button', { name: channelName, exact: true });
|
||||
|
||||
await expect(channelButton).toBeVisible({ timeout: 15_000 });
|
||||
await channelButton.click();
|
||||
}
|
||||
|
||||
/** Click a text channel by name in the channels sidebar to switch chat rooms. */
|
||||
async joinTextChannel(channelName: string) {
|
||||
const channelButton = this.getTextChannelButton(channelName);
|
||||
|
||||
if (await channelButton.count() === 0) {
|
||||
await this.refreshRoomMetadata();
|
||||
}
|
||||
|
||||
await expect(channelButton).toBeVisible({ timeout: 15_000 });
|
||||
await channelButton.click();
|
||||
}
|
||||
|
||||
/** Creates a text channel and waits until it appears locally. */
|
||||
async ensureTextChannelExists(channelName: string) {
|
||||
const channelButton = this.getTextChannelButton(channelName);
|
||||
|
||||
if (await channelButton.count() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.openCreateTextChannelDialog();
|
||||
await this.createChannel(channelName);
|
||||
|
||||
try {
|
||||
await expect(channelButton).toBeVisible({ timeout: 5_000 });
|
||||
} catch {
|
||||
await this.createTextChannelThroughComponent(channelName);
|
||||
}
|
||||
|
||||
await this.persistCurrentChannelsToServer(channelName);
|
||||
await expect(channelButton).toBeVisible({ timeout: 15_000 });
|
||||
}
|
||||
|
||||
/** Click "Create Voice Channel" button in the channels sidebar. */
|
||||
async openCreateVoiceChannelDialog() {
|
||||
await this.page.locator('button[title="Create Voice Channel"]').click();
|
||||
}
|
||||
|
||||
/** Click "Create Text Channel" button in the channels sidebar. */
|
||||
async openCreateTextChannelDialog() {
|
||||
await this.page.locator('button[title="Create Text Channel"]').click();
|
||||
}
|
||||
|
||||
/** Fill the channel name in the create channel dialog and confirm. */
|
||||
async createChannel(name: string) {
|
||||
const dialog = this.page.locator('app-confirm-dialog');
|
||||
const channelNameInput = dialog.getByPlaceholder('Channel name');
|
||||
const createButton = dialog.getByRole('button', { name: 'Create', exact: true });
|
||||
|
||||
await expect(channelNameInput).toBeVisible({ timeout: 10_000 });
|
||||
await channelNameInput.fill(name);
|
||||
await channelNameInput.press('Enter');
|
||||
|
||||
if (await dialog.isVisible()) {
|
||||
try {
|
||||
await createButton.click();
|
||||
} catch {
|
||||
// Enter may already have confirmed and removed the dialog.
|
||||
}
|
||||
}
|
||||
|
||||
await expect(dialog).not.toBeVisible({ timeout: 10_000 });
|
||||
}
|
||||
|
||||
/** Get the voice controls component. */
|
||||
get voiceControls() {
|
||||
return this.page.locator('app-voice-controls');
|
||||
}
|
||||
|
||||
/** Get the mute toggle button inside voice controls. */
|
||||
get muteButton() {
|
||||
return this.voiceControls.locator('button:has(ng-icon[name="lucideMic"]), button:has(ng-icon[name="lucideMicOff"])').first();
|
||||
}
|
||||
|
||||
/** Get the disconnect/hang-up button (destructive styled). */
|
||||
get disconnectButton() {
|
||||
return this.voiceControls.locator('button:has(ng-icon[name="lucidePhoneOff"])').first();
|
||||
}
|
||||
|
||||
/** Get all voice stream tiles. */
|
||||
get streamTiles() {
|
||||
return this.page.locator('app-voice-workspace-stream-tile');
|
||||
}
|
||||
|
||||
/** Get the count of voice users listed under a voice channel. */
|
||||
async getVoiceUserCountInChannel(channelName: string): Promise<number> {
|
||||
const channelSection = this.page.locator('app-rooms-side-panel')
|
||||
.getByRole('button', { name: channelName })
|
||||
.locator('..');
|
||||
const userAvatars = channelSection.locator('app-user-avatar');
|
||||
|
||||
return userAvatars.count();
|
||||
}
|
||||
|
||||
/** Get the screen share toggle button inside voice controls. */
|
||||
get screenShareButton() {
|
||||
return this.voiceControls.locator(
|
||||
'button:has(ng-icon[name="lucideMonitor"]), button:has(ng-icon[name="lucideMonitorOff"])'
|
||||
).first();
|
||||
}
|
||||
|
||||
/** Start screen sharing. Bypasses the quality dialog via localStorage preset. */
|
||||
async startScreenShare() {
|
||||
// Disable quality dialog so clicking the button starts sharing immediately
|
||||
await this.page.evaluate(() => {
|
||||
const key = 'metoyou_voice_settings';
|
||||
const raw = localStorage.getItem(key);
|
||||
const settings = raw ? JSON.parse(raw) : {};
|
||||
|
||||
settings.askScreenShareQuality = false;
|
||||
settings.screenShareQuality = 'balanced';
|
||||
localStorage.setItem(key, JSON.stringify(settings));
|
||||
});
|
||||
|
||||
await this.screenShareButton.click();
|
||||
}
|
||||
|
||||
/** Stop screen sharing by clicking the active screen share button. */
|
||||
async stopScreenShare() {
|
||||
await this.screenShareButton.click();
|
||||
}
|
||||
|
||||
/** Check whether the screen share button shows the active (MonitorOff) icon. */
|
||||
get isScreenShareActive() {
|
||||
return this.voiceControls.locator('button:has(ng-icon[name="lucideMonitorOff"])').first();
|
||||
}
|
||||
|
||||
private getTextChannelButton(channelName: string): Locator {
|
||||
const channelPattern = new RegExp(`#\\s*${escapeRegExp(channelName)}$`, 'i');
|
||||
|
||||
return this.channelsSidePanel.getByRole('button', { name: channelPattern }).first();
|
||||
}
|
||||
|
||||
private async createTextChannelThroughComponent(channelName: string): Promise<void> {
|
||||
await this.page.evaluate((name) => {
|
||||
interface ChannelSidebarComponent {
|
||||
createChannel: (type: 'text' | 'voice') => void;
|
||||
newChannelName: string;
|
||||
confirmCreateChannel: () => void;
|
||||
}
|
||||
interface AngularDebugApi {
|
||||
getComponent: (element: Element) => ChannelSidebarComponent;
|
||||
}
|
||||
interface WindowWithAngularDebug extends Window {
|
||||
ng?: AngularDebugApi;
|
||||
}
|
||||
|
||||
const host = document.querySelector('app-rooms-side-panel');
|
||||
const debugApi = (window as WindowWithAngularDebug).ng;
|
||||
|
||||
if (!host || !debugApi?.getComponent) {
|
||||
throw new Error('Angular debug API unavailable for text channel fallback');
|
||||
}
|
||||
|
||||
const component = debugApi.getComponent(host);
|
||||
|
||||
component.createChannel('text');
|
||||
component.newChannelName = name;
|
||||
component.confirmCreateChannel();
|
||||
}, channelName);
|
||||
}
|
||||
|
||||
private async persistCurrentChannelsToServer(channelName: string): Promise<void> {
|
||||
const result = await this.page.evaluate(async (requestedChannelName) => {
|
||||
interface ServerEndpoint {
|
||||
isActive?: boolean;
|
||||
url: string;
|
||||
}
|
||||
|
||||
interface ChannelShape {
|
||||
id: string;
|
||||
name: string;
|
||||
type: 'text' | 'voice';
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface RoomShape {
|
||||
id: string;
|
||||
sourceUrl?: string;
|
||||
channels?: ChannelShape[];
|
||||
}
|
||||
|
||||
interface UserShape {
|
||||
id: string;
|
||||
}
|
||||
|
||||
interface ChannelSidebarComponent {
|
||||
currentRoom: () => RoomShape | null;
|
||||
currentUser: () => UserShape | null;
|
||||
}
|
||||
|
||||
interface AngularDebugApi {
|
||||
getComponent: (element: Element) => ChannelSidebarComponent;
|
||||
}
|
||||
|
||||
interface WindowWithAngularDebug extends Window {
|
||||
ng?: AngularDebugApi;
|
||||
}
|
||||
|
||||
const host = document.querySelector('app-rooms-side-panel');
|
||||
const debugApi = (window as WindowWithAngularDebug).ng;
|
||||
|
||||
if (!host || !debugApi?.getComponent) {
|
||||
throw new Error('Angular debug API unavailable for channel persistence');
|
||||
}
|
||||
|
||||
const component = debugApi.getComponent(host);
|
||||
const room = component.currentRoom();
|
||||
const currentUser = component.currentUser();
|
||||
const endpoints = JSON.parse(localStorage.getItem('metoyou_server_endpoints') || '[]') as ServerEndpoint[];
|
||||
const activeEndpoint = endpoints.find((endpoint) => endpoint.isActive) || endpoints[0] || null;
|
||||
const apiBaseUrl = room?.sourceUrl || activeEndpoint?.url;
|
||||
const normalizedChannelName = requestedChannelName.trim().replace(/\s+/g, ' ');
|
||||
const existingChannels = Array.isArray(room?.channels) ? room.channels : [];
|
||||
const hasTextChannel = existingChannels.some((channel) =>
|
||||
channel.type === 'text' && channel.name.trim().toLowerCase() === normalizedChannelName.toLowerCase()
|
||||
);
|
||||
const nextChannels = hasTextChannel
|
||||
? existingChannels
|
||||
: [
|
||||
...existingChannels,
|
||||
{
|
||||
id: globalThis.crypto.randomUUID(),
|
||||
name: normalizedChannelName,
|
||||
type: 'text' as const,
|
||||
position: existingChannels.length
|
||||
}
|
||||
];
|
||||
|
||||
if (!room?.id || !currentUser?.id || !apiBaseUrl) {
|
||||
throw new Error('Missing room, user, or endpoint when persisting channels');
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiBaseUrl}/api/servers/${room.id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
currentOwnerId: currentUser.id,
|
||||
channels: nextChannels
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to persist channels: ${response.status}`);
|
||||
}
|
||||
|
||||
return { roomId: room.id, channels: nextChannels };
|
||||
}, channelName);
|
||||
|
||||
// Update NGRX store directly so the UI reflects the new channel
|
||||
// immediately, without waiting for an async effect round-trip.
|
||||
await this.dispatchRoomChannelsUpdate(result.roomId, result.channels);
|
||||
}
|
||||
|
||||
private async dispatchRoomChannelsUpdate(
|
||||
roomId: string,
|
||||
channels: { id: string; name: string; type: string; position: number }[]
|
||||
): Promise<void> {
|
||||
await this.page.evaluate(({ rid, chs }) => {
|
||||
interface AngularDebugApi {
|
||||
getComponent: (element: Element) => Record<string, unknown>;
|
||||
}
|
||||
|
||||
const host = document.querySelector('app-rooms-side-panel');
|
||||
const debugApi = (window as { ng?: AngularDebugApi }).ng;
|
||||
|
||||
if (!host || !debugApi?.getComponent) {
|
||||
return;
|
||||
}
|
||||
|
||||
const component = debugApi.getComponent(host);
|
||||
const store = component['store'] as { dispatch: (a: Record<string, unknown>) => void } | undefined;
|
||||
|
||||
if (store?.dispatch) {
|
||||
store.dispatch({
|
||||
type: '[Rooms] Update Room',
|
||||
roomId: rid,
|
||||
changes: { channels: chs }
|
||||
});
|
||||
}
|
||||
}, { rid: roomId, chs: channels });
|
||||
}
|
||||
|
||||
private async refreshRoomMetadata(): Promise<void> {
|
||||
await this.page.evaluate(async () => {
|
||||
interface ServerEndpoint {
|
||||
isActive?: boolean;
|
||||
url: string;
|
||||
}
|
||||
|
||||
interface ChannelShape {
|
||||
id: string;
|
||||
name: string;
|
||||
type: 'text' | 'voice';
|
||||
position: number;
|
||||
}
|
||||
|
||||
interface AngularDebugApi {
|
||||
getComponent: (element: Element) => Record<string, unknown>;
|
||||
}
|
||||
|
||||
interface WindowWithAngularDebug extends Window {
|
||||
ng?: AngularDebugApi;
|
||||
}
|
||||
|
||||
const host = document.querySelector('app-rooms-side-panel');
|
||||
const debugApi = (window as WindowWithAngularDebug).ng;
|
||||
|
||||
if (!host || !debugApi?.getComponent) {
|
||||
throw new Error('Angular debug API unavailable for room refresh');
|
||||
}
|
||||
|
||||
const component = debugApi.getComponent(host);
|
||||
const currentRoom = typeof component['currentRoom'] === 'function'
|
||||
? (component['currentRoom'] as () => { id: string; sourceUrl?: string; channels?: ChannelShape[] } | null)()
|
||||
: null;
|
||||
|
||||
if (!currentRoom) {
|
||||
throw new Error('No current room to refresh');
|
||||
}
|
||||
|
||||
const store = component['store'] as { dispatch: (action: Record<string, unknown>) => void } | undefined;
|
||||
|
||||
if (!store?.dispatch) {
|
||||
throw new Error('NGRX store not available on component');
|
||||
}
|
||||
|
||||
// Fetch server data directly via REST API instead of triggering
|
||||
// an async NGRX effect that can race with pending writes.
|
||||
const endpoints = JSON.parse(localStorage.getItem('metoyou_server_endpoints') || '[]') as ServerEndpoint[];
|
||||
const activeEndpoint = endpoints.find((ep) => ep.isActive) || endpoints[0] || null;
|
||||
const apiBaseUrl = currentRoom.sourceUrl || activeEndpoint?.url;
|
||||
|
||||
if (!apiBaseUrl) {
|
||||
throw new Error('No API base URL available for room refresh');
|
||||
}
|
||||
|
||||
const response = await fetch(`${apiBaseUrl}/api/servers/${currentRoom.id}`);
|
||||
|
||||
if (response.ok) {
|
||||
const serverData = await response.json() as { channels?: ChannelShape[] };
|
||||
|
||||
if (serverData.channels?.length) {
|
||||
store.dispatch({
|
||||
type: '[Rooms] Update Room',
|
||||
roomId: currentRoom.id,
|
||||
changes: { channels: serverData.channels }
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Brief wait for Angular change detection to propagate
|
||||
await this.page.waitForTimeout(500);
|
||||
}
|
||||
}
|
||||
|
||||
function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
29
e2e/pages/login.page.ts
Normal file
29
e2e/pages/login.page.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { type Page, type Locator } from '@playwright/test';
|
||||
|
||||
export class LoginPage {
|
||||
readonly usernameInput: Locator;
|
||||
readonly passwordInput: Locator;
|
||||
readonly serverSelect: Locator;
|
||||
readonly submitButton: Locator;
|
||||
readonly errorText: Locator;
|
||||
readonly registerLink: Locator;
|
||||
|
||||
constructor(private page: Page) {
|
||||
this.usernameInput = page.locator('#login-username');
|
||||
this.passwordInput = page.locator('#login-password');
|
||||
this.serverSelect = page.locator('#login-server');
|
||||
this.submitButton = page.getByRole('button', { name: 'Login' });
|
||||
this.errorText = page.locator('.text-destructive');
|
||||
this.registerLink = page.getByRole('button', { name: 'Register' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/login');
|
||||
}
|
||||
|
||||
async login(username: string, password: string) {
|
||||
await this.usernameInput.fill(username);
|
||||
await this.passwordInput.fill(password);
|
||||
await this.submitButton.click();
|
||||
}
|
||||
}
|
||||
45
e2e/pages/register.page.ts
Normal file
45
e2e/pages/register.page.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { expect, type Page, type Locator } from '@playwright/test';
|
||||
|
||||
export class RegisterPage {
|
||||
readonly usernameInput: Locator;
|
||||
readonly displayNameInput: Locator;
|
||||
readonly passwordInput: Locator;
|
||||
readonly serverSelect: Locator;
|
||||
readonly submitButton: Locator;
|
||||
readonly errorText: Locator;
|
||||
readonly loginLink: Locator;
|
||||
|
||||
constructor(private page: Page) {
|
||||
this.usernameInput = page.locator('#register-username');
|
||||
this.displayNameInput = page.locator('#register-display-name');
|
||||
this.passwordInput = page.locator('#register-password');
|
||||
this.serverSelect = page.locator('#register-server');
|
||||
this.submitButton = page.getByRole('button', { name: 'Create Account' });
|
||||
this.errorText = page.locator('.text-destructive');
|
||||
this.loginLink = page.getByRole('button', { name: 'Login' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/register', { waitUntil: 'domcontentloaded' });
|
||||
|
||||
try {
|
||||
await expect(this.usernameInput).toBeVisible({ timeout: 10_000 });
|
||||
} catch {
|
||||
// Angular router may redirect to /login on first load; click through.
|
||||
const registerLink = this.page.getByRole('link', { name: 'Register' })
|
||||
.or(this.page.getByText('Register'));
|
||||
|
||||
await registerLink.first().click();
|
||||
await expect(this.usernameInput).toBeVisible({ timeout: 30_000 });
|
||||
}
|
||||
|
||||
await expect(this.submitButton).toBeVisible({ timeout: 30_000 });
|
||||
}
|
||||
|
||||
async register(username: string, displayName: string, password: string) {
|
||||
await this.usernameInput.fill(username);
|
||||
await this.displayNameInput.fill(displayName);
|
||||
await this.passwordInput.fill(password);
|
||||
await this.submitButton.click();
|
||||
}
|
||||
}
|
||||
65
e2e/pages/server-search.page.ts
Normal file
65
e2e/pages/server-search.page.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
type Page,
|
||||
type Locator,
|
||||
expect
|
||||
} from '@playwright/test';
|
||||
|
||||
export class ServerSearchPage {
|
||||
readonly searchInput: Locator;
|
||||
readonly createServerButton: Locator;
|
||||
readonly settingsButton: Locator;
|
||||
|
||||
// Create server dialog
|
||||
readonly serverNameInput: Locator;
|
||||
readonly serverDescriptionInput: Locator;
|
||||
readonly serverTopicInput: Locator;
|
||||
readonly signalEndpointSelect: Locator;
|
||||
readonly privateCheckbox: Locator;
|
||||
readonly serverPasswordInput: Locator;
|
||||
readonly dialogCreateButton: Locator;
|
||||
readonly dialogCancelButton: Locator;
|
||||
|
||||
constructor(private page: Page) {
|
||||
this.searchInput = page.getByPlaceholder('Search servers...');
|
||||
this.createServerButton = page.getByRole('button', { name: 'Create New Server' });
|
||||
this.settingsButton = page.locator('button[title="Settings"]');
|
||||
|
||||
// Create dialog elements
|
||||
this.serverNameInput = page.locator('#create-server-name');
|
||||
this.serverDescriptionInput = page.locator('#create-server-description');
|
||||
this.serverTopicInput = page.locator('#create-server-topic');
|
||||
this.signalEndpointSelect = page.locator('#create-server-signal-endpoint');
|
||||
this.privateCheckbox = page.locator('#private');
|
||||
this.serverPasswordInput = page.locator('#create-server-password');
|
||||
this.dialogCreateButton = page.locator('div[role="dialog"]').getByRole('button', { name: 'Create' });
|
||||
this.dialogCancelButton = page.locator('div[role="dialog"]').getByRole('button', { name: 'Cancel' });
|
||||
}
|
||||
|
||||
async goto() {
|
||||
await this.page.goto('/search');
|
||||
}
|
||||
|
||||
async createServer(name: string, options?: { description?: string; topic?: string }) {
|
||||
await this.createServerButton.click();
|
||||
await expect(this.serverNameInput).toBeVisible();
|
||||
await this.serverNameInput.fill(name);
|
||||
|
||||
if (options?.description) {
|
||||
await this.serverDescriptionInput.fill(options.description);
|
||||
}
|
||||
|
||||
if (options?.topic) {
|
||||
await this.serverTopicInput.fill(options.topic);
|
||||
}
|
||||
|
||||
await this.dialogCreateButton.click();
|
||||
}
|
||||
|
||||
async joinSavedRoom(name: string) {
|
||||
await this.page.getByRole('button', { name }).click();
|
||||
}
|
||||
|
||||
async joinServerFromSearch(name: string) {
|
||||
await this.page.locator('button', { hasText: name }).click();
|
||||
}
|
||||
}
|
||||
39
e2e/playwright.config.ts
Normal file
39
e2e/playwright.config.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { defineConfig, devices } from '@playwright/test';
|
||||
|
||||
export default defineConfig({
|
||||
testDir: './tests',
|
||||
timeout: 90_000,
|
||||
expect: { timeout: 10_000 },
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
workers: 1,
|
||||
reporter: [['html', { outputFolder: '../test-results/html-report' }], ['list']],
|
||||
outputDir: '../test-results/artifacts',
|
||||
use: {
|
||||
baseURL: 'http://localhost:4200',
|
||||
trace: 'on-first-retry',
|
||||
screenshot: 'only-on-failure',
|
||||
video: 'on-first-retry',
|
||||
actionTimeout: 15_000,
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
use: {
|
||||
...devices['Desktop Chrome'],
|
||||
permissions: ['microphone', 'camera'],
|
||||
launchOptions: {
|
||||
args: [
|
||||
'--use-fake-device-for-media-stream',
|
||||
'--use-fake-ui-for-media-stream',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
webServer: {
|
||||
command: 'cd ../toju-app && npx ng serve',
|
||||
port: 4200,
|
||||
reuseExistingServer: !process.env.CI,
|
||||
timeout: 120_000,
|
||||
},
|
||||
});
|
||||
295
e2e/tests/chat/chat-message-features.spec.ts
Normal file
295
e2e/tests/chat/chat-message-features.spec.ts
Normal file
@@ -0,0 +1,295 @@
|
||||
import { type Page } from '@playwright/test';
|
||||
import { test, expect, type Client } from '../../fixtures/multi-client';
|
||||
import { RegisterPage } from '../../pages/register.page';
|
||||
import { ServerSearchPage } from '../../pages/server-search.page';
|
||||
import { ChatRoomPage } from '../../pages/chat-room.page';
|
||||
import {
|
||||
ChatMessagesPage,
|
||||
type ChatDropFilePayload
|
||||
} from '../../pages/chat-messages.page';
|
||||
|
||||
const MOCK_EMBED_URL = 'https://example.test/mock-embed';
|
||||
const MOCK_EMBED_TITLE = 'Mock Embed Title';
|
||||
const MOCK_EMBED_DESCRIPTION = 'Mock embed description for chat E2E coverage.';
|
||||
const MOCK_GIF_IMAGE_URL = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==';
|
||||
const DELETED_MESSAGE_CONTENT = '[Message deleted]';
|
||||
|
||||
test.describe('Chat messaging features', () => {
|
||||
test.describe.configure({ timeout: 180_000 });
|
||||
|
||||
test('syncs messages in a newly created text channel', async ({ createClient }) => {
|
||||
const scenario = await createChatScenario(createClient);
|
||||
const channelName = uniqueName('updates');
|
||||
const aliceMessage = `Alice text channel message ${uniqueName('msg')}`;
|
||||
const bobMessage = `Bob text channel reply ${uniqueName('msg')}`;
|
||||
|
||||
await test.step('Alice creates a new text channel and both users join it', async () => {
|
||||
await scenario.aliceRoom.ensureTextChannelExists(channelName);
|
||||
await scenario.aliceRoom.joinTextChannel(channelName);
|
||||
await scenario.bobRoom.joinTextChannel(channelName);
|
||||
});
|
||||
|
||||
await test.step('Alice and Bob see synced messages in the new text channel', async () => {
|
||||
await scenario.aliceMessages.sendMessage(aliceMessage);
|
||||
await expect(scenario.bobMessages.getMessageItemByText(aliceMessage)).toBeVisible({ timeout: 20_000 });
|
||||
|
||||
await scenario.bobMessages.sendMessage(bobMessage);
|
||||
await expect(scenario.aliceMessages.getMessageItemByText(bobMessage)).toBeVisible({ timeout: 20_000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('shows typing indicators to other users', async ({ createClient }) => {
|
||||
const scenario = await createChatScenario(createClient);
|
||||
const draftMessage = `Typing indicator draft ${uniqueName('draft')}`;
|
||||
|
||||
await test.step('Alice starts typing in general channel', async () => {
|
||||
await scenario.aliceMessages.typeDraft(draftMessage);
|
||||
});
|
||||
|
||||
await test.step('Bob sees Alice typing', async () => {
|
||||
await expect(scenario.bob.page.getByText('Alice is typing...')).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('edits and removes messages for both users', async ({ createClient }) => {
|
||||
const scenario = await createChatScenario(createClient);
|
||||
const originalMessage = `Editable message ${uniqueName('edit')}`;
|
||||
const updatedMessage = `Edited message ${uniqueName('edit')}`;
|
||||
|
||||
await test.step('Alice sends a message and Bob receives it', async () => {
|
||||
await scenario.aliceMessages.sendMessage(originalMessage);
|
||||
await expect(scenario.bobMessages.getMessageItemByText(originalMessage)).toBeVisible({ timeout: 20_000 });
|
||||
});
|
||||
|
||||
await test.step('Alice edits the message and both users see updated content', async () => {
|
||||
await scenario.aliceMessages.editOwnMessage(originalMessage, updatedMessage);
|
||||
await expect(scenario.aliceMessages.getMessageItemByText(updatedMessage)).toBeVisible({ timeout: 20_000 });
|
||||
await expect(scenario.alice.page.getByText('(edited)')).toBeVisible({ timeout: 10_000 });
|
||||
await expect(scenario.bobMessages.getMessageItemByText(updatedMessage)).toBeVisible({ timeout: 20_000 });
|
||||
});
|
||||
|
||||
await test.step('Alice deletes the message and both users see deletion state', async () => {
|
||||
await scenario.aliceMessages.deleteOwnMessage(updatedMessage);
|
||||
await expect(scenario.aliceMessages.getMessageItemByText(DELETED_MESSAGE_CONTENT)).toBeVisible({ timeout: 20_000 });
|
||||
await expect(scenario.bobMessages.getMessageItemByText(DELETED_MESSAGE_CONTENT)).toBeVisible({ timeout: 20_000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('syncs image and file attachments between users', async ({ createClient }) => {
|
||||
const scenario = await createChatScenario(createClient);
|
||||
const imageName = `${uniqueName('diagram')}.svg`;
|
||||
const fileName = `${uniqueName('notes')}.txt`;
|
||||
const imageCaption = `Image upload ${uniqueName('caption')}`;
|
||||
const fileCaption = `File upload ${uniqueName('caption')}`;
|
||||
const imageAttachment = createTextFilePayload(imageName, 'image/svg+xml', buildMockSvgMarkup(imageName));
|
||||
const fileAttachment = createTextFilePayload(fileName, 'text/plain', `Attachment body for ${fileName}`);
|
||||
|
||||
await test.step('Alice sends image attachment and Bob receives it', async () => {
|
||||
await scenario.aliceMessages.attachFiles([imageAttachment]);
|
||||
await scenario.aliceMessages.sendMessage(imageCaption);
|
||||
|
||||
await scenario.aliceMessages.expectMessageImageLoaded(imageName);
|
||||
await expect(scenario.bobMessages.getMessageItemByText(imageCaption)).toBeVisible({ timeout: 20_000 });
|
||||
await scenario.bobMessages.expectMessageImageLoaded(imageName);
|
||||
});
|
||||
|
||||
await test.step('Alice sends generic file attachment and Bob receives it', async () => {
|
||||
await scenario.aliceMessages.attachFiles([fileAttachment]);
|
||||
await scenario.aliceMessages.sendMessage(fileCaption);
|
||||
|
||||
await expect(scenario.bobMessages.getMessageItemByText(fileCaption)).toBeVisible({ timeout: 20_000 });
|
||||
await expect(scenario.bob.page.getByText(fileName, { exact: false })).toBeVisible({ timeout: 20_000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('renders link embeds for shared links', async ({ createClient }) => {
|
||||
const scenario = await createChatScenario(createClient);
|
||||
const messageText = `Useful docs ${MOCK_EMBED_URL}`;
|
||||
|
||||
await test.step('Alice shares a link in chat', async () => {
|
||||
await scenario.aliceMessages.sendMessage(messageText);
|
||||
await expect(scenario.bobMessages.getMessageItemByText(messageText)).toBeVisible({ timeout: 20_000 });
|
||||
});
|
||||
|
||||
await test.step('Both users see mocked link embed metadata', async () => {
|
||||
await expect(scenario.aliceMessages.getEmbedCardByTitle(MOCK_EMBED_TITLE)).toBeVisible({ timeout: 20_000 });
|
||||
await expect(scenario.bobMessages.getEmbedCardByTitle(MOCK_EMBED_TITLE)).toBeVisible({ timeout: 20_000 });
|
||||
await expect(scenario.bob.page.getByText(MOCK_EMBED_DESCRIPTION)).toBeVisible({ timeout: 20_000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('sends KLIPY GIF messages with mocked API responses', async ({ createClient }) => {
|
||||
const scenario = await createChatScenario(createClient);
|
||||
|
||||
await test.step('Alice opens GIF picker and sends mocked GIF', async () => {
|
||||
await scenario.aliceMessages.openGifPicker();
|
||||
await scenario.aliceMessages.selectFirstGif();
|
||||
});
|
||||
|
||||
await test.step('Bob sees GIF message sync', async () => {
|
||||
await scenario.aliceMessages.expectMessageImageLoaded('KLIPY GIF');
|
||||
await scenario.bobMessages.expectMessageImageLoaded('KLIPY GIF');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
type ChatScenario = {
|
||||
alice: Client;
|
||||
bob: Client;
|
||||
aliceRoom: ChatRoomPage;
|
||||
bobRoom: ChatRoomPage;
|
||||
aliceMessages: ChatMessagesPage;
|
||||
bobMessages: ChatMessagesPage;
|
||||
};
|
||||
|
||||
async function createChatScenario(createClient: () => Promise<Client>): Promise<ChatScenario> {
|
||||
const suffix = uniqueName('chat');
|
||||
const serverName = `Chat Server ${suffix}`;
|
||||
const aliceCredentials = {
|
||||
username: `alice_${suffix}`,
|
||||
displayName: 'Alice',
|
||||
password: 'TestPass123!'
|
||||
};
|
||||
const bobCredentials = {
|
||||
username: `bob_${suffix}`,
|
||||
displayName: 'Bob',
|
||||
password: 'TestPass123!'
|
||||
};
|
||||
const alice = await createClient();
|
||||
const bob = await createClient();
|
||||
|
||||
await installChatFeatureMocks(alice.page);
|
||||
await installChatFeatureMocks(bob.page);
|
||||
|
||||
const aliceRegisterPage = new RegisterPage(alice.page);
|
||||
const bobRegisterPage = new RegisterPage(bob.page);
|
||||
|
||||
await aliceRegisterPage.goto();
|
||||
await aliceRegisterPage.register(
|
||||
aliceCredentials.username,
|
||||
aliceCredentials.displayName,
|
||||
aliceCredentials.password
|
||||
);
|
||||
await expect(alice.page).toHaveURL(/\/search/, { timeout: 15_000 });
|
||||
|
||||
await bobRegisterPage.goto();
|
||||
await bobRegisterPage.register(
|
||||
bobCredentials.username,
|
||||
bobCredentials.displayName,
|
||||
bobCredentials.password
|
||||
);
|
||||
await expect(bob.page).toHaveURL(/\/search/, { timeout: 15_000 });
|
||||
|
||||
const aliceSearchPage = new ServerSearchPage(alice.page);
|
||||
|
||||
await aliceSearchPage.createServer(serverName, {
|
||||
description: 'E2E chat server for messaging feature coverage'
|
||||
});
|
||||
await expect(alice.page).toHaveURL(/\/room\//, { timeout: 15_000 });
|
||||
|
||||
const bobSearchPage = new ServerSearchPage(bob.page);
|
||||
const serverCard = bob.page.locator('button', { hasText: serverName }).first();
|
||||
|
||||
await bobSearchPage.searchInput.fill(serverName);
|
||||
await expect(serverCard).toBeVisible({ timeout: 15_000 });
|
||||
await serverCard.click();
|
||||
await expect(bob.page).toHaveURL(/\/room\//, { timeout: 15_000 });
|
||||
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
const bobRoom = new ChatRoomPage(bob.page);
|
||||
const aliceMessages = new ChatMessagesPage(alice.page);
|
||||
const bobMessages = new ChatMessagesPage(bob.page);
|
||||
|
||||
await aliceMessages.waitForReady();
|
||||
await bobMessages.waitForReady();
|
||||
|
||||
return {
|
||||
alice,
|
||||
bob,
|
||||
aliceRoom,
|
||||
bobRoom,
|
||||
aliceMessages,
|
||||
bobMessages
|
||||
};
|
||||
}
|
||||
|
||||
async function installChatFeatureMocks(page: Page): Promise<void> {
|
||||
await page.route('**/api/klipy/config', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ enabled: true })
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/klipy/gifs**', async (route) => {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
enabled: true,
|
||||
hasNext: false,
|
||||
results: [
|
||||
{
|
||||
id: 'mock-gif-1',
|
||||
slug: 'mock-gif-1',
|
||||
title: 'Mock Celebration GIF',
|
||||
url: MOCK_GIF_IMAGE_URL,
|
||||
previewUrl: MOCK_GIF_IMAGE_URL,
|
||||
width: 64,
|
||||
height: 64
|
||||
}
|
||||
]
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
await page.route('**/api/link-metadata**', async (route) => {
|
||||
const requestUrl = new URL(route.request().url());
|
||||
const requestedTargetUrl = requestUrl.searchParams.get('url') ?? '';
|
||||
|
||||
if (requestedTargetUrl === MOCK_EMBED_URL) {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
title: MOCK_EMBED_TITLE,
|
||||
description: MOCK_EMBED_DESCRIPTION,
|
||||
imageUrl: MOCK_GIF_IMAGE_URL,
|
||||
siteName: 'Mock Docs'
|
||||
})
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({ failed: true })
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function createTextFilePayload(name: string, mimeType: string, content: string): ChatDropFilePayload {
|
||||
return {
|
||||
name,
|
||||
mimeType,
|
||||
base64: Buffer.from(content, 'utf8').toString('base64')
|
||||
};
|
||||
}
|
||||
|
||||
function buildMockSvgMarkup(label: string): string {
|
||||
return [
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" width="160" height="120" viewBox="0 0 160 120">',
|
||||
'<rect width="160" height="120" rx="18" fill="#0f172a" />',
|
||||
'<circle cx="38" cy="36" r="18" fill="#38bdf8" />',
|
||||
'<rect x="66" y="28" width="64" height="16" rx="8" fill="#f8fafc" />',
|
||||
'<rect x="24" y="74" width="112" height="12" rx="6" fill="#22c55e" />',
|
||||
`<text x="24" y="104" fill="#e2e8f0" font-size="12" font-family="Arial, sans-serif">${label}</text>`,
|
||||
'</svg>'
|
||||
].join('');
|
||||
}
|
||||
|
||||
function uniqueName(prefix: string): string {
|
||||
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
396
e2e/tests/screen-share/screen-share.spec.ts
Normal file
396
e2e/tests/screen-share/screen-share.spec.ts
Normal file
@@ -0,0 +1,396 @@
|
||||
import { test, expect } from '../../fixtures/multi-client';
|
||||
import {
|
||||
installWebRTCTracking,
|
||||
waitForPeerConnected,
|
||||
isPeerStillConnected,
|
||||
waitForAudioFlow,
|
||||
waitForAudioStatsPresent,
|
||||
waitForVideoFlow,
|
||||
waitForOutboundVideoFlow,
|
||||
waitForInboundVideoFlow,
|
||||
dumpRtcDiagnostics
|
||||
} from '../../helpers/webrtc-helpers';
|
||||
import { RegisterPage } from '../../pages/register.page';
|
||||
import { ServerSearchPage } from '../../pages/server-search.page';
|
||||
import { ChatRoomPage } from '../../pages/chat-room.page';
|
||||
|
||||
/**
|
||||
* Screen sharing E2E tests: verify video, screen-share audio, and voice audio
|
||||
* flow correctly between users during screen sharing.
|
||||
*
|
||||
* Uses the same dedicated-browser-per-client infrastructure as voice tests.
|
||||
* getDisplayMedia is monkey-patched to return a synthetic canvas video stream
|
||||
* + 880 Hz oscillator audio, bypassing the browser picker dialog.
|
||||
*/
|
||||
|
||||
const ALICE = { username: `alice_ss_${Date.now()}`, displayName: 'Alice', password: 'TestPass123!' };
|
||||
const BOB = { username: `bob_ss_${Date.now()}`, displayName: 'Bob', password: 'TestPass123!' };
|
||||
const SERVER_NAME = `SS Test ${Date.now()}`;
|
||||
const VOICE_CHANNEL = 'General';
|
||||
|
||||
/** Register a user and navigate to /search. */
|
||||
async function registerUser(page: import('@playwright/test').Page, user: typeof ALICE) {
|
||||
const registerPage = new RegisterPage(page);
|
||||
|
||||
await registerPage.goto();
|
||||
await expect(registerPage.submitButton).toBeVisible();
|
||||
await registerPage.register(user.username, user.displayName, user.password);
|
||||
await expect(page).toHaveURL(/\/search/, { timeout: 15_000 });
|
||||
}
|
||||
|
||||
/** Both users register → Alice creates server → Bob joins. */
|
||||
async function setupServerWithBothUsers(
|
||||
alice: { page: import('@playwright/test').Page },
|
||||
bob: { page: import('@playwright/test').Page }
|
||||
) {
|
||||
await registerUser(alice.page, ALICE);
|
||||
await registerUser(bob.page, BOB);
|
||||
|
||||
// Alice creates server
|
||||
const aliceSearch = new ServerSearchPage(alice.page);
|
||||
|
||||
await aliceSearch.createServer(SERVER_NAME, { description: 'Screen share E2E' });
|
||||
await expect(alice.page).toHaveURL(/\/room\//, { timeout: 15_000 });
|
||||
|
||||
// Bob joins server
|
||||
const bobSearch = new ServerSearchPage(bob.page);
|
||||
|
||||
await bobSearch.searchInput.fill(SERVER_NAME);
|
||||
|
||||
const serverCard = bob.page.locator('button', { hasText: SERVER_NAME }).first();
|
||||
|
||||
await expect(serverCard).toBeVisible({ timeout: 10_000 });
|
||||
await serverCard.click();
|
||||
await expect(bob.page).toHaveURL(/\/room\//, { timeout: 15_000 });
|
||||
}
|
||||
|
||||
/** Ensure voice channel exists and both users join it. */
|
||||
async function joinVoiceTogether(
|
||||
alice: { page: import('@playwright/test').Page },
|
||||
bob: { page: import('@playwright/test').Page }
|
||||
) {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
const existingChannel = alice.page
|
||||
.locator('app-rooms-side-panel')
|
||||
.getByRole('button', { name: VOICE_CHANNEL, exact: true });
|
||||
|
||||
if (await existingChannel.count() === 0) {
|
||||
await aliceRoom.openCreateVoiceChannelDialog();
|
||||
await aliceRoom.createChannel(VOICE_CHANNEL);
|
||||
await expect(existingChannel).toBeVisible({ timeout: 10_000 });
|
||||
}
|
||||
|
||||
await aliceRoom.joinVoiceChannel(VOICE_CHANNEL);
|
||||
await expect(alice.page.locator('app-voice-controls')).toBeVisible({ timeout: 15_000 });
|
||||
|
||||
const bobRoom = new ChatRoomPage(bob.page);
|
||||
|
||||
await bobRoom.joinVoiceChannel(VOICE_CHANNEL);
|
||||
await expect(bob.page.locator('app-voice-controls')).toBeVisible({ timeout: 15_000 });
|
||||
|
||||
// Wait for WebRTC + audio pipeline
|
||||
await waitForPeerConnected(alice.page, 30_000);
|
||||
await waitForPeerConnected(bob.page, 30_000);
|
||||
await waitForAudioStatsPresent(alice.page, 20_000);
|
||||
await waitForAudioStatsPresent(bob.page, 20_000);
|
||||
|
||||
// Expand voice workspace on both clients so the demand-driven screen
|
||||
// share request flow can fire (requires connectRemoteShares = true).
|
||||
// Click the "VIEW" badge that appears next to the active voice channel.
|
||||
const aliceView = alice.page.locator('app-rooms-side-panel')
|
||||
.getByRole('button', { name: /view/i })
|
||||
.first();
|
||||
const bobView = bob.page.locator('app-rooms-side-panel')
|
||||
.getByRole('button', { name: /view/i })
|
||||
.first();
|
||||
|
||||
await expect(aliceView).toBeVisible({ timeout: 10_000 });
|
||||
await aliceView.click();
|
||||
await expect(alice.page.locator('app-voice-workspace')).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
await expect(bobView).toBeVisible({ timeout: 10_000 });
|
||||
await bobView.click();
|
||||
await expect(bob.page.locator('app-voice-workspace')).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
// Re-verify audio stats are present after workspace expansion (the VIEW
|
||||
// click can trigger renegotiation which briefly disrupts audio).
|
||||
await waitForAudioStatsPresent(alice.page, 20_000);
|
||||
await waitForAudioStatsPresent(bob.page, 20_000);
|
||||
}
|
||||
|
||||
function expectFlowing(
|
||||
delta: { outboundBytesDelta: number; inboundBytesDelta: number; outboundPacketsDelta: number; inboundPacketsDelta: number },
|
||||
label: string
|
||||
) {
|
||||
expect(
|
||||
delta.outboundBytesDelta > 0 || delta.outboundPacketsDelta > 0,
|
||||
`${label} should be sending`
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
delta.inboundBytesDelta > 0 || delta.inboundPacketsDelta > 0,
|
||||
`${label} should be receiving`
|
||||
).toBe(true);
|
||||
}
|
||||
|
||||
test.describe('Screen sharing', () => {
|
||||
test('single user screen share: video and audio flow to receiver, voice audio continues', async ({ createClient }) => {
|
||||
test.setTimeout(180_000);
|
||||
|
||||
const alice = await createClient();
|
||||
const bob = await createClient();
|
||||
|
||||
await installWebRTCTracking(alice.page);
|
||||
await installWebRTCTracking(bob.page);
|
||||
|
||||
alice.page.on('console', msg => console.log('[Alice]', msg.text()));
|
||||
bob.page.on('console', msg => console.log('[Bob]', msg.text()));
|
||||
|
||||
// ── Setup: register, server, voice ────────────────────────────
|
||||
|
||||
await test.step('Setup server and voice channel', async () => {
|
||||
await setupServerWithBothUsers(alice, bob);
|
||||
await joinVoiceTogether(alice, bob);
|
||||
});
|
||||
|
||||
// ── Verify voice audio before screen share ────────────────────
|
||||
|
||||
await test.step('Voice audio flows before screen share', async () => {
|
||||
const aliceDelta = await waitForAudioFlow(alice.page, 30_000);
|
||||
const bobDelta = await waitForAudioFlow(bob.page, 30_000);
|
||||
|
||||
expectFlowing(aliceDelta, 'Alice voice');
|
||||
expectFlowing(bobDelta, 'Bob voice');
|
||||
});
|
||||
|
||||
// ── Alice starts screen sharing ───────────────────────────────
|
||||
|
||||
await test.step('Alice starts screen sharing', async () => {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
|
||||
await aliceRoom.startScreenShare();
|
||||
|
||||
// Screen share button should show active state (MonitorOff icon)
|
||||
await expect(aliceRoom.isScreenShareActive).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
// ── Verify screen share video flows ───────────────────────────
|
||||
|
||||
await test.step('Screen share video flows from Alice to Bob', async () => {
|
||||
// Screen share is unidirectional: Alice sends video, Bob receives it.
|
||||
const aliceVideo = await waitForOutboundVideoFlow(alice.page, 30_000);
|
||||
const bobVideo = await waitForInboundVideoFlow(bob.page, 30_000);
|
||||
|
||||
if (aliceVideo.outboundBytesDelta === 0 || bobVideo.inboundBytesDelta === 0) {
|
||||
console.log('[Alice RTC]\n' + await dumpRtcDiagnostics(alice.page));
|
||||
console.log('[Bob RTC]\n' + await dumpRtcDiagnostics(bob.page));
|
||||
}
|
||||
|
||||
expect(
|
||||
aliceVideo.outboundBytesDelta > 0 || aliceVideo.outboundPacketsDelta > 0,
|
||||
'Alice should be sending screen share video'
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
bobVideo.inboundBytesDelta > 0 || bobVideo.inboundPacketsDelta > 0,
|
||||
'Bob should be receiving screen share video'
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
// ── Verify voice audio continues during screen share ──────────
|
||||
|
||||
await test.step('Voice audio continues during screen share', async () => {
|
||||
const aliceAudio = await waitForAudioFlow(alice.page, 20_000);
|
||||
const bobAudio = await waitForAudioFlow(bob.page, 20_000);
|
||||
|
||||
expectFlowing(aliceAudio, 'Alice voice during screen share');
|
||||
expectFlowing(bobAudio, 'Bob voice during screen share');
|
||||
});
|
||||
|
||||
// ── Bob can hear Alice talk while she screen shares ───────────
|
||||
|
||||
await test.step('Bob receives audio from Alice during screen share', async () => {
|
||||
// Specifically check Bob is receiving audio (from Alice's voice)
|
||||
const bobAudio = await waitForAudioFlow(bob.page, 15_000);
|
||||
|
||||
expect(
|
||||
bobAudio.inboundBytesDelta > 0,
|
||||
'Bob should receive voice audio while Alice screen shares'
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
// ── Alice stops screen sharing ────────────────────────────────
|
||||
|
||||
await test.step('Alice stops screen sharing', async () => {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
|
||||
await aliceRoom.stopScreenShare();
|
||||
|
||||
// Active icon should disappear - regular Monitor icon shown instead
|
||||
await expect(
|
||||
aliceRoom.voiceControls.locator('button:has(ng-icon[name="lucideMonitor"])').first()
|
||||
).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
// ── Voice audio still works after screen share ends ───────────
|
||||
|
||||
await test.step('Voice audio resumes normally after screen share stops', async () => {
|
||||
const aliceAudio = await waitForAudioFlow(alice.page, 20_000);
|
||||
const bobAudio = await waitForAudioFlow(bob.page, 20_000);
|
||||
|
||||
expectFlowing(aliceAudio, 'Alice voice after screen share');
|
||||
expectFlowing(bobAudio, 'Bob voice after screen share');
|
||||
});
|
||||
});
|
||||
|
||||
test('multiple users screen share simultaneously', async ({ createClient }) => {
|
||||
test.setTimeout(180_000);
|
||||
|
||||
const alice = await createClient();
|
||||
const bob = await createClient();
|
||||
|
||||
await installWebRTCTracking(alice.page);
|
||||
await installWebRTCTracking(bob.page);
|
||||
|
||||
alice.page.on('console', msg => console.log('[Alice]', msg.text()));
|
||||
bob.page.on('console', msg => console.log('[Bob]', msg.text()));
|
||||
|
||||
await test.step('Setup server and voice channel', async () => {
|
||||
await setupServerWithBothUsers(alice, bob);
|
||||
await joinVoiceTogether(alice, bob);
|
||||
});
|
||||
|
||||
// ── Both users start screen sharing ───────────────────────────
|
||||
|
||||
await test.step('Alice starts screen sharing', async () => {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
|
||||
await aliceRoom.startScreenShare();
|
||||
await expect(aliceRoom.isScreenShareActive).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
await test.step('Bob starts screen sharing', async () => {
|
||||
const bobRoom = new ChatRoomPage(bob.page);
|
||||
|
||||
await bobRoom.startScreenShare();
|
||||
await expect(bobRoom.isScreenShareActive).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
// ── Verify video flows in both directions ─────────────────────
|
||||
|
||||
await test.step('Video flows bidirectionally with both screen shares active', async () => {
|
||||
// Both sharing: each page sends and receives video
|
||||
const aliceVideo = await waitForVideoFlow(alice.page, 30_000);
|
||||
const bobVideo = await waitForVideoFlow(bob.page, 30_000);
|
||||
|
||||
expectFlowing(aliceVideo, 'Alice screen share video');
|
||||
expectFlowing(bobVideo, 'Bob screen share video');
|
||||
});
|
||||
|
||||
// ── Voice audio continues with dual screen shares ─────────────
|
||||
|
||||
await test.step('Voice audio continues with both users screen sharing', async () => {
|
||||
const aliceAudio = await waitForAudioFlow(alice.page, 20_000);
|
||||
const bobAudio = await waitForAudioFlow(bob.page, 20_000);
|
||||
|
||||
expectFlowing(aliceAudio, 'Alice voice during dual screen share');
|
||||
expectFlowing(bobAudio, 'Bob voice during dual screen share');
|
||||
});
|
||||
|
||||
// ── Both stop screen sharing ──────────────────────────────────
|
||||
|
||||
await test.step('Both users stop screen sharing', async () => {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
const bobRoom = new ChatRoomPage(bob.page);
|
||||
|
||||
await aliceRoom.stopScreenShare();
|
||||
await expect(
|
||||
aliceRoom.voiceControls.locator('button:has(ng-icon[name="lucideMonitor"])').first()
|
||||
).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
await bobRoom.stopScreenShare();
|
||||
await expect(
|
||||
bobRoom.voiceControls.locator('button:has(ng-icon[name="lucideMonitor"])').first()
|
||||
).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('screen share connection stays stable for 10+ seconds', async ({ createClient }) => {
|
||||
test.setTimeout(180_000);
|
||||
|
||||
const alice = await createClient();
|
||||
const bob = await createClient();
|
||||
|
||||
await installWebRTCTracking(alice.page);
|
||||
await installWebRTCTracking(bob.page);
|
||||
|
||||
alice.page.on('console', msg => console.log('[Alice]', msg.text()));
|
||||
bob.page.on('console', msg => console.log('[Bob]', msg.text()));
|
||||
|
||||
await test.step('Setup server and voice channel', async () => {
|
||||
await setupServerWithBothUsers(alice, bob);
|
||||
await joinVoiceTogether(alice, bob);
|
||||
});
|
||||
|
||||
await test.step('Alice starts screen sharing', async () => {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
|
||||
await aliceRoom.startScreenShare();
|
||||
await expect(aliceRoom.isScreenShareActive).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
// Wait for video pipeline to fully establish
|
||||
await waitForOutboundVideoFlow(alice.page, 30_000);
|
||||
await waitForInboundVideoFlow(bob.page, 30_000);
|
||||
});
|
||||
|
||||
// ── Stability checkpoints at 0s, 5s, 10s ─────────────────────
|
||||
|
||||
await test.step('Connection stays stable for 10+ seconds during screen share', async () => {
|
||||
for (const checkpoint of [
|
||||
0,
|
||||
5_000,
|
||||
5_000
|
||||
]) {
|
||||
if (checkpoint > 0) {
|
||||
await alice.page.waitForTimeout(checkpoint);
|
||||
}
|
||||
|
||||
const aliceConnected = await isPeerStillConnected(alice.page);
|
||||
const bobConnected = await isPeerStillConnected(bob.page);
|
||||
|
||||
expect(aliceConnected, 'Alice should still be connected').toBe(true);
|
||||
expect(bobConnected, 'Bob should still be connected').toBe(true);
|
||||
}
|
||||
|
||||
// After 10s - verify both video and audio still flowing
|
||||
const aliceVideo = await waitForOutboundVideoFlow(alice.page, 15_000);
|
||||
const bobVideo = await waitForInboundVideoFlow(bob.page, 15_000);
|
||||
|
||||
expect(
|
||||
aliceVideo.outboundBytesDelta > 0,
|
||||
'Alice still sending screen share video after 10s'
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
bobVideo.inboundBytesDelta > 0,
|
||||
'Bob still receiving screen share video after 10s'
|
||||
).toBe(true);
|
||||
|
||||
const aliceAudio = await waitForAudioFlow(alice.page, 15_000);
|
||||
const bobAudio = await waitForAudioFlow(bob.page, 15_000);
|
||||
|
||||
expectFlowing(aliceAudio, 'Alice voice after 10s screen share');
|
||||
expectFlowing(bobAudio, 'Bob voice after 10s screen share');
|
||||
});
|
||||
|
||||
// ── Clean disconnect ──────────────────────────────────────────
|
||||
|
||||
await test.step('Alice stops screen share and disconnects', async () => {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
|
||||
await aliceRoom.stopScreenShare();
|
||||
await aliceRoom.disconnectButton.click();
|
||||
await expect(aliceRoom.disconnectButton).not.toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
});
|
||||
});
|
||||
260
e2e/tests/voice/voice-full-journey.spec.ts
Normal file
260
e2e/tests/voice/voice-full-journey.spec.ts
Normal file
@@ -0,0 +1,260 @@
|
||||
import { test, expect } from '../../fixtures/multi-client';
|
||||
import {
|
||||
installWebRTCTracking,
|
||||
waitForPeerConnected,
|
||||
isPeerStillConnected,
|
||||
getAudioStatsDelta,
|
||||
waitForAudioFlow,
|
||||
waitForAudioStatsPresent,
|
||||
dumpRtcDiagnostics
|
||||
} from '../../helpers/webrtc-helpers';
|
||||
import { RegisterPage } from '../../pages/register.page';
|
||||
import { ServerSearchPage } from '../../pages/server-search.page';
|
||||
import { ChatRoomPage } from '../../pages/chat-room.page';
|
||||
|
||||
/**
|
||||
* Full user journey: register → create server → join → voice → verify audio
|
||||
* for 10+ seconds of stable connectivity.
|
||||
*
|
||||
* Uses two independent browser contexts (Alice & Bob) to simulate real
|
||||
* multi-user WebRTC voice chat.
|
||||
*/
|
||||
|
||||
const ALICE = { username: `alice_${Date.now()}`, displayName: 'Alice', password: 'TestPass123!' };
|
||||
const BOB = { username: `bob_${Date.now()}`, displayName: 'Bob', password: 'TestPass123!' };
|
||||
const SERVER_NAME = `E2E Test Server ${Date.now()}`;
|
||||
const VOICE_CHANNEL = 'General';
|
||||
|
||||
test.describe('Full user journey: register → server → voice chat', () => {
|
||||
test('two users register, create server, join voice, and stay connected 10+ seconds with audio', async ({ createClient }) => {
|
||||
test.setTimeout(180_000); // 3 min - covers registration, server creation, voice establishment, and 10s stability check
|
||||
|
||||
const alice = await createClient();
|
||||
const bob = await createClient();
|
||||
|
||||
// Install WebRTC tracking before any navigation
|
||||
await installWebRTCTracking(alice.page);
|
||||
await installWebRTCTracking(bob.page);
|
||||
|
||||
// Forward browser console for debugging
|
||||
alice.page.on('console', msg => console.log('[Alice]', msg.text()));
|
||||
bob.page.on('console', msg => console.log('[Bob]', msg.text()));
|
||||
|
||||
// ── Step 1: Register both users ──────────────────────────────────
|
||||
|
||||
await test.step('Alice registers an account', async () => {
|
||||
const registerPage = new RegisterPage(alice.page);
|
||||
|
||||
await registerPage.goto();
|
||||
await expect(registerPage.submitButton).toBeVisible();
|
||||
await registerPage.register(ALICE.username, ALICE.displayName, ALICE.password);
|
||||
|
||||
// After registration, app should navigate to /search
|
||||
await expect(alice.page).toHaveURL(/\/search/, { timeout: 15_000 });
|
||||
});
|
||||
|
||||
await test.step('Bob registers an account', async () => {
|
||||
const registerPage = new RegisterPage(bob.page);
|
||||
|
||||
await registerPage.goto();
|
||||
await expect(registerPage.submitButton).toBeVisible();
|
||||
await registerPage.register(BOB.username, BOB.displayName, BOB.password);
|
||||
|
||||
await expect(bob.page).toHaveURL(/\/search/, { timeout: 15_000 });
|
||||
});
|
||||
|
||||
// ── Step 2: Alice creates a server ───────────────────────────────
|
||||
|
||||
await test.step('Alice creates a new server', async () => {
|
||||
const searchPage = new ServerSearchPage(alice.page);
|
||||
|
||||
await searchPage.createServer(SERVER_NAME, {
|
||||
description: 'E2E test server for voice testing'
|
||||
});
|
||||
|
||||
// After server creation, app navigates to the room
|
||||
await expect(alice.page).toHaveURL(/\/room\//, { timeout: 15_000 });
|
||||
});
|
||||
|
||||
// ── Step 3: Bob joins the server ─────────────────────────────────
|
||||
|
||||
await test.step('Bob finds and joins the server', async () => {
|
||||
const searchPage = new ServerSearchPage(bob.page);
|
||||
|
||||
// Search for the server
|
||||
await searchPage.searchInput.fill(SERVER_NAME);
|
||||
|
||||
// Wait for search results and click the server
|
||||
const serverCard = bob.page.locator('button', { hasText: SERVER_NAME }).first();
|
||||
|
||||
await expect(serverCard).toBeVisible({ timeout: 10_000 });
|
||||
await serverCard.click();
|
||||
|
||||
// Bob should be in the room now
|
||||
await expect(bob.page).toHaveURL(/\/room\//, { timeout: 15_000 });
|
||||
});
|
||||
|
||||
// ── Step 4: Create a voice channel (if one doesn't exist) ────────
|
||||
|
||||
await test.step('Alice ensures a voice channel is available', async () => {
|
||||
const chatRoom = new ChatRoomPage(alice.page);
|
||||
const existingVoiceChannel = alice.page.locator('app-rooms-side-panel')
|
||||
.getByRole('button', { name: VOICE_CHANNEL, exact: true });
|
||||
const voiceChannelExists = await existingVoiceChannel.count() > 0;
|
||||
|
||||
if (!voiceChannelExists) {
|
||||
// Click "Create Voice Channel" plus button
|
||||
await chatRoom.openCreateVoiceChannelDialog();
|
||||
await chatRoom.createChannel(VOICE_CHANNEL);
|
||||
|
||||
// Wait for the channel to appear
|
||||
await expect(existingVoiceChannel).toBeVisible({ timeout: 10_000 });
|
||||
}
|
||||
});
|
||||
|
||||
// ── Step 5: Both users join the voice channel ────────────────────
|
||||
|
||||
await test.step('Alice joins the voice channel', async () => {
|
||||
const chatRoom = new ChatRoomPage(alice.page);
|
||||
|
||||
await chatRoom.joinVoiceChannel(VOICE_CHANNEL);
|
||||
|
||||
// Voice controls should appear (indicates voice is connected)
|
||||
await expect(alice.page.locator('app-voice-controls')).toBeVisible({ timeout: 15_000 });
|
||||
});
|
||||
|
||||
await test.step('Bob joins the voice channel', async () => {
|
||||
const chatRoom = new ChatRoomPage(bob.page);
|
||||
|
||||
await chatRoom.joinVoiceChannel(VOICE_CHANNEL);
|
||||
|
||||
await expect(bob.page.locator('app-voice-controls')).toBeVisible({ timeout: 15_000 });
|
||||
});
|
||||
|
||||
// ── Step 6: Verify WebRTC connection establishes ─────────────────
|
||||
|
||||
await test.step('WebRTC peer connection reaches "connected" state', async () => {
|
||||
await waitForPeerConnected(alice.page, 30_000);
|
||||
await waitForPeerConnected(bob.page, 30_000);
|
||||
|
||||
// Wait for audio RTP pipeline to appear before measuring deltas -
|
||||
// renegotiation after initial connect can temporarily remove stats.
|
||||
await waitForAudioStatsPresent(alice.page, 20_000);
|
||||
await waitForAudioStatsPresent(bob.page, 20_000);
|
||||
});
|
||||
|
||||
// ── Step 7: Verify audio is flowing in both directions ───────────
|
||||
|
||||
await test.step('Audio packets are flowing between Alice and Bob', async () => {
|
||||
const aliceDelta = await waitForAudioFlow(alice.page, 30_000);
|
||||
const bobDelta = await waitForAudioFlow(bob.page, 30_000);
|
||||
|
||||
if (aliceDelta.outboundBytesDelta === 0 || aliceDelta.inboundBytesDelta === 0
|
||||
|| bobDelta.outboundBytesDelta === 0 || bobDelta.inboundBytesDelta === 0) {
|
||||
console.log('[Alice RTC Diagnostics]\n' + await dumpRtcDiagnostics(alice.page));
|
||||
console.log('[Bob RTC Diagnostics]\n' + await dumpRtcDiagnostics(bob.page));
|
||||
}
|
||||
|
||||
expectAudioFlow(aliceDelta, 'Alice');
|
||||
expectAudioFlow(bobDelta, 'Bob');
|
||||
});
|
||||
|
||||
// ── Step 8: Verify UI states are correct ─────────────────────────
|
||||
|
||||
await test.step('Voice UI shows correct state for both users', async () => {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
const bobRoom = new ChatRoomPage(bob.page);
|
||||
|
||||
// Both should see voice controls with "Connected" status
|
||||
await expect(alice.page.locator('app-voice-controls')).toBeVisible();
|
||||
await expect(bob.page.locator('app-voice-controls')).toBeVisible();
|
||||
|
||||
// Both should see the voice workspace or at least voice users listed
|
||||
// Check that both users appear in the voice channel user list
|
||||
const aliceSeesBob = aliceRoom.channelsSidePanel.getByText(BOB.displayName).first();
|
||||
const bobSeesAlice = bobRoom.channelsSidePanel.getByText(ALICE.displayName).first();
|
||||
|
||||
await expect(aliceSeesBob).toBeVisible({ timeout: 10_000 });
|
||||
await expect(bobSeesAlice).toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
|
||||
// ── Step 9: Stay connected for 10+ seconds, verify stability ─────
|
||||
|
||||
await test.step('Connection remains stable for 10+ seconds', async () => {
|
||||
// Check connectivity at 0s, 5s, and 10s intervals
|
||||
for (const checkpoint of [
|
||||
0,
|
||||
5_000,
|
||||
5_000
|
||||
]) {
|
||||
if (checkpoint > 0) {
|
||||
await alice.page.waitForTimeout(checkpoint);
|
||||
}
|
||||
|
||||
const aliceConnected = await isPeerStillConnected(alice.page);
|
||||
const bobConnected = await isPeerStillConnected(bob.page);
|
||||
|
||||
expect(aliceConnected, 'Alice should still be connected').toBe(true);
|
||||
expect(bobConnected, 'Bob should still be connected').toBe(true);
|
||||
}
|
||||
|
||||
// After 10s total, verify audio is still flowing
|
||||
const aliceDelta = await waitForAudioFlow(alice.page, 15_000);
|
||||
const bobDelta = await waitForAudioFlow(bob.page, 15_000);
|
||||
|
||||
expectAudioFlow(aliceDelta, 'Alice after 10s');
|
||||
expectAudioFlow(bobDelta, 'Bob after 10s');
|
||||
});
|
||||
|
||||
// ── Step 10: Verify mute/unmute works correctly ──────────────────
|
||||
|
||||
await test.step('Mute toggle works correctly', async () => {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
|
||||
// Alice mutes - click the first button in voice controls (mute button)
|
||||
await aliceRoom.muteButton.click();
|
||||
|
||||
// After muting, Alice's outbound audio should stop increasing
|
||||
// When muted, bytesSent may still show small comfort noise or zero growth
|
||||
// The key assertion is that Bob's inbound for Alice's stream stops or reduces
|
||||
await getAudioStatsDelta(alice.page, 2_000);
|
||||
|
||||
// Alice unmutes
|
||||
await aliceRoom.muteButton.click();
|
||||
|
||||
// After unmuting, outbound should resume
|
||||
const unmutedDelta = await waitForAudioFlow(alice.page, 15_000);
|
||||
|
||||
expectAudioFlow(unmutedDelta, 'Alice after unmuting');
|
||||
});
|
||||
|
||||
// ── Step 11: Clean disconnect ────────────────────────────────────
|
||||
|
||||
await test.step('Alice disconnects from voice', async () => {
|
||||
const aliceRoom = new ChatRoomPage(alice.page);
|
||||
|
||||
// Click the disconnect/hang-up button
|
||||
await aliceRoom.disconnectButton.click();
|
||||
|
||||
// Connected controls should collapse for Alice after disconnect
|
||||
await expect(aliceRoom.disconnectButton).not.toBeVisible({ timeout: 10_000 });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function expectAudioFlow(delta: {
|
||||
outboundBytesDelta: number;
|
||||
inboundBytesDelta: number;
|
||||
outboundPacketsDelta: number;
|
||||
inboundPacketsDelta: number;
|
||||
}, label: string): void {
|
||||
expect(
|
||||
delta.outboundBytesDelta > 0 || delta.outboundPacketsDelta > 0,
|
||||
`${label} should be sending audio`
|
||||
).toBe(true);
|
||||
|
||||
expect(
|
||||
delta.inboundBytesDelta > 0 || delta.inboundPacketsDelta > 0,
|
||||
`${label} should be receiving audio`
|
||||
).toBe(true);
|
||||
}
|
||||
@@ -18,7 +18,8 @@ export async function handleSaveMessage(command: SaveMessageCommand, dataSource:
|
||||
timestamp: message.timestamp,
|
||||
editedAt: message.editedAt ?? null,
|
||||
isDeleted: message.isDeleted ? 1 : 0,
|
||||
replyToId: message.replyToId ?? null
|
||||
replyToId: message.replyToId ?? null,
|
||||
linkMetadata: message.linkMetadata ? JSON.stringify(message.linkMetadata) : null
|
||||
});
|
||||
|
||||
await repo.save(entity);
|
||||
|
||||
@@ -13,29 +13,35 @@ export async function handleUpdateMessage(command: UpdateMessageCommand, dataSou
|
||||
if (!existing)
|
||||
return;
|
||||
|
||||
if (updates.channelId !== undefined)
|
||||
existing.channelId = updates.channelId ?? null;
|
||||
const directFields = [
|
||||
'senderId',
|
||||
'senderName',
|
||||
'content',
|
||||
'timestamp'
|
||||
] as const;
|
||||
const entity = existing as unknown as Record<string, unknown>;
|
||||
|
||||
if (updates.senderId !== undefined)
|
||||
existing.senderId = updates.senderId;
|
||||
for (const field of directFields) {
|
||||
if (updates[field] !== undefined)
|
||||
entity[field] = updates[field];
|
||||
}
|
||||
|
||||
if (updates.senderName !== undefined)
|
||||
existing.senderName = updates.senderName;
|
||||
const nullableFields = [
|
||||
'channelId',
|
||||
'editedAt',
|
||||
'replyToId'
|
||||
] as const;
|
||||
|
||||
if (updates.content !== undefined)
|
||||
existing.content = updates.content;
|
||||
|
||||
if (updates.timestamp !== undefined)
|
||||
existing.timestamp = updates.timestamp;
|
||||
|
||||
if (updates.editedAt !== undefined)
|
||||
existing.editedAt = updates.editedAt ?? null;
|
||||
for (const field of nullableFields) {
|
||||
if (updates[field] !== undefined)
|
||||
entity[field] = updates[field] ?? null;
|
||||
}
|
||||
|
||||
if (updates.isDeleted !== undefined)
|
||||
existing.isDeleted = updates.isDeleted ? 1 : 0;
|
||||
|
||||
if (updates.replyToId !== undefined)
|
||||
existing.replyToId = updates.replyToId ?? null;
|
||||
if (updates.linkMetadata !== undefined)
|
||||
existing.linkMetadata = updates.linkMetadata ? JSON.stringify(updates.linkMetadata) : null;
|
||||
|
||||
await repo.save(existing);
|
||||
|
||||
|
||||
@@ -35,7 +35,8 @@ export function rowToMessage(row: MessageEntity, reactions: ReactionPayload[] =
|
||||
editedAt: row.editedAt ?? undefined,
|
||||
reactions: isDeleted ? [] : reactions,
|
||||
isDeleted,
|
||||
replyToId: row.replyToId ?? undefined
|
||||
replyToId: row.replyToId ?? undefined,
|
||||
linkMetadata: row.linkMetadata ? JSON.parse(row.linkMetadata) : undefined
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ export interface MessagePayload {
|
||||
reactions?: ReactionPayload[];
|
||||
isDeleted?: boolean;
|
||||
replyToId?: string;
|
||||
linkMetadata?: { url: string; title?: string; description?: string; imageUrl?: string; siteName?: string; failed?: boolean }[];
|
||||
}
|
||||
|
||||
export interface ReactionPayload {
|
||||
|
||||
@@ -35,4 +35,7 @@ export class MessageEntity {
|
||||
|
||||
@Column('text', { nullable: true })
|
||||
replyToId!: string | null;
|
||||
|
||||
@Column('text', { nullable: true })
|
||||
linkMetadata!: string | null;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import {
|
||||
desktopCapturer,
|
||||
dialog,
|
||||
ipcMain,
|
||||
nativeImage,
|
||||
net,
|
||||
Notification,
|
||||
shell
|
||||
} from 'electron';
|
||||
@@ -503,4 +505,56 @@ export function setupSystemHandlers(): void {
|
||||
await fsp.mkdir(dirPath, { recursive: true });
|
||||
return true;
|
||||
});
|
||||
|
||||
ipcMain.handle('copy-image-to-clipboard', (_event, srcURL: string) => {
|
||||
if (typeof srcURL !== 'string' || !srcURL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return new Promise<boolean>((resolve) => {
|
||||
const request = net.request(srcURL);
|
||||
|
||||
request.on('response', (response) => {
|
||||
const chunks: Buffer[] = [];
|
||||
|
||||
response.on('data', (chunk) => chunks.push(chunk));
|
||||
response.on('end', () => {
|
||||
const image = nativeImage.createFromBuffer(Buffer.concat(chunks));
|
||||
|
||||
if (!image.isEmpty()) {
|
||||
clipboard.writeImage(image);
|
||||
resolve(true);
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
response.on('error', () => resolve(false));
|
||||
});
|
||||
|
||||
request.on('error', () => resolve(false));
|
||||
request.end();
|
||||
});
|
||||
});
|
||||
|
||||
ipcMain.handle('context-menu-command', (_event, command: string) => {
|
||||
const allowedCommands = ['cut', 'copy', 'paste', 'selectAll'] as const;
|
||||
|
||||
if (!allowedCommands.includes(command as typeof allowedCommands[number])) {
|
||||
return;
|
||||
}
|
||||
|
||||
const mainWindow = getMainWindow();
|
||||
const webContents = mainWindow?.webContents;
|
||||
|
||||
if (!webContents) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (command) {
|
||||
case 'cut': webContents.cut(); break;
|
||||
case 'copy': webContents.copy(); break;
|
||||
case 'paste': webContents.paste(); break;
|
||||
case 'selectAll': webContents.selectAll(); break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
11
electron/migrations/1000000000005-AddLinkMetadata.ts
Normal file
11
electron/migrations/1000000000005-AddLinkMetadata.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddLinkMetadata1000000000005 implements MigrationInterface {
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "messages" ADD COLUMN "linkMetadata" text`);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
// SQLite does not support DROP COLUMN; column is nullable and harmless.
|
||||
}
|
||||
}
|
||||
@@ -124,6 +124,22 @@ function readLinuxDisplayServer(): string {
|
||||
}
|
||||
}
|
||||
|
||||
export interface ContextMenuParams {
|
||||
posX: number;
|
||||
posY: number;
|
||||
isEditable: boolean;
|
||||
selectionText: string;
|
||||
linkURL: string;
|
||||
mediaType: string;
|
||||
srcURL: string;
|
||||
editFlags: {
|
||||
canCut: boolean;
|
||||
canCopy: boolean;
|
||||
canPaste: boolean;
|
||||
canSelectAll: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ElectronAPI {
|
||||
linuxDisplayServer: string;
|
||||
minimizeWindow: () => void;
|
||||
@@ -194,6 +210,10 @@ export interface ElectronAPI {
|
||||
deleteFile: (filePath: string) => Promise<boolean>;
|
||||
ensureDir: (dirPath: string) => Promise<boolean>;
|
||||
|
||||
onContextMenu: (listener: (params: ContextMenuParams) => void) => () => void;
|
||||
contextMenuCommand: (command: string) => Promise<void>;
|
||||
copyImageToClipboard: (srcURL: string) => Promise<boolean>;
|
||||
|
||||
command: <T = unknown>(command: Command) => Promise<T>;
|
||||
query: <T = unknown>(query: Query) => Promise<T>;
|
||||
}
|
||||
@@ -299,6 +319,20 @@ const electronAPI: ElectronAPI = {
|
||||
deleteFile: (filePath) => ipcRenderer.invoke('delete-file', filePath),
|
||||
ensureDir: (dirPath) => ipcRenderer.invoke('ensure-dir', dirPath),
|
||||
|
||||
onContextMenu: (listener) => {
|
||||
const wrappedListener = (_event: Electron.IpcRendererEvent, params: ContextMenuParams) => {
|
||||
listener(params);
|
||||
};
|
||||
|
||||
ipcRenderer.on('show-context-menu', wrappedListener);
|
||||
|
||||
return () => {
|
||||
ipcRenderer.removeListener('show-context-menu', wrappedListener);
|
||||
};
|
||||
},
|
||||
contextMenuCommand: (command) => ipcRenderer.invoke('context-menu-command', command),
|
||||
copyImageToClipboard: (srcURL) => ipcRenderer.invoke('copy-image-to-clipboard', srcURL),
|
||||
|
||||
command: (command) => ipcRenderer.invoke('cqrs:command', command),
|
||||
query: (query) => ipcRenderer.invoke('cqrs:query', query)
|
||||
};
|
||||
|
||||
@@ -264,6 +264,24 @@ export async function createWindow(): Promise<void> {
|
||||
|
||||
emitWindowState();
|
||||
|
||||
mainWindow.webContents.on('context-menu', (_event, params) => {
|
||||
mainWindow?.webContents.send('show-context-menu', {
|
||||
posX: params.x,
|
||||
posY: params.y,
|
||||
isEditable: params.isEditable,
|
||||
selectionText: params.selectionText,
|
||||
linkURL: params.linkURL,
|
||||
mediaType: params.mediaType,
|
||||
srcURL: params.srcURL,
|
||||
editFlags: {
|
||||
canCut: params.editFlags.canCut,
|
||||
canCopy: params.editFlags.canCopy,
|
||||
canPaste: params.editFlags.canPaste,
|
||||
canSelectAll: params.editFlags.canSelectAll
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||
shell.openExternal(url);
|
||||
return { action: 'deny' };
|
||||
|
||||
64
package-lock.json
generated
64
package-lock.json
generated
@@ -56,6 +56,7 @@
|
||||
"@angular/cli": "^21.0.4",
|
||||
"@angular/compiler-cli": "^21.0.0",
|
||||
"@eslint/js": "^9.39.3",
|
||||
"@playwright/test": "^1.59.1",
|
||||
"@stylistic/eslint-plugin-js": "^4.4.1",
|
||||
"@stylistic/eslint-plugin-ts": "^4.4.1",
|
||||
"@types/auto-launch": "^5.0.5",
|
||||
@@ -9337,6 +9338,22 @@
|
||||
"url": "https://opencollective.com/pkgr"
|
||||
}
|
||||
},
|
||||
"node_modules/@playwright/test": {
|
||||
"version": "1.59.1",
|
||||
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.59.1.tgz",
|
||||
"integrity": "sha512-PG6q63nQg5c9rIi4/Z5lR5IVF7yU5MqmKaPOe0HSc0O2cX1fPi96sUQu5j7eo4gKCkB2AnNGoWt7y4/Xx3Kcqg==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright": "1.59.1"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@rolldown/binding-android-arm64": {
|
||||
"version": "1.0.0-beta.47",
|
||||
"resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm64/-/binding-android-arm64-1.0.0-beta.47.tgz",
|
||||
@@ -24652,6 +24669,53 @@
|
||||
"node": ">= 10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright": {
|
||||
"version": "1.59.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.59.1.tgz",
|
||||
"integrity": "sha512-C8oWjPR3F81yljW9o5OxcWzfh6avkVwDD2VYdwIGqTkl+OGFISgypqzfu7dOe4QNLL2aqcWBmI3PMtLIK233lw==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"playwright-core": "1.59.1"
|
||||
},
|
||||
"bin": {
|
||||
"playwright": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"fsevents": "2.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright-core": {
|
||||
"version": "1.59.1",
|
||||
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.59.1.tgz",
|
||||
"integrity": "sha512-HBV/RJg81z5BiiZ9yPzIiClYV/QMsDCKUyogwH9p3MCP6IYjUFu/MActgYAvK0oWyV9NlwM3GLBjADyWgydVyg==",
|
||||
"dev": true,
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"playwright-core": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright/node_modules/fsevents": {
|
||||
"version": "2.3.2",
|
||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/plist": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/plist/-/plist-3.1.0.tgz",
|
||||
|
||||
13
package.json
13
package.json
@@ -49,7 +49,11 @@
|
||||
"release:version": "node tools/resolve-release-version.js",
|
||||
"server:bundle:linux": "node tools/package-server-executable.js --target node18-linux-x64 --output metoyou-server-linux-x64",
|
||||
"server:bundle:win": "node tools/package-server-executable.js --target node18-win-x64 --output metoyou-server-win-x64.exe",
|
||||
"sort:props": "node tools/sort-template-properties.js"
|
||||
"sort:props": "node tools/sort-template-properties.js",
|
||||
"test:e2e": "cd e2e && npx playwright test",
|
||||
"test:e2e:ui": "cd e2e && npx playwright test --ui",
|
||||
"test:e2e:debug": "cd e2e && npx playwright test --debug",
|
||||
"test:e2e:report": "cd e2e && npx playwright show-report ../test-results/html-report"
|
||||
},
|
||||
"private": true,
|
||||
"packageManager": "npm@10.9.2",
|
||||
@@ -102,6 +106,7 @@
|
||||
"@angular/cli": "^21.0.4",
|
||||
"@angular/compiler-cli": "^21.0.0",
|
||||
"@eslint/js": "^9.39.3",
|
||||
"@playwright/test": "^1.59.1",
|
||||
"@stylistic/eslint-plugin-js": "^4.4.1",
|
||||
"@stylistic/eslint-plugin-ts": "^4.4.1",
|
||||
"@types/auto-launch": "^5.0.5",
|
||||
@@ -141,9 +146,13 @@
|
||||
"output": "dist-electron"
|
||||
},
|
||||
"files": [
|
||||
"!node_modules",
|
||||
"dist/client/**/*",
|
||||
"dist/electron/**/*",
|
||||
"node_modules/**/*",
|
||||
"node_modules/{ansi-regex,ansi-styles,ansis,app-root-path,applescript,argparse,auto-launch,available-typed-arrays,balanced-match,base64-js,brace-expansion,buffer,builder-util-runtime,call-bind,call-bind-apply-helpers,call-bound,cliui,concat-map,cross-spawn,dayjs,debug,dedent,define-data-property,dotenv,dunder-proto,electron-updater,emoji-regex,es-define-property,es-errors,es-object-atoms,escalade,for-each,foreground-child,fs-extra,function-bind,get-caller-file,get-east-asian-width,get-intrinsic,get-proto,glob,gopd,graceful-fs,has-property-descriptors,has-symbols,has-tostringtag,hasown,ieee754,inherits,is-callable,is-fullwidth-code-point,is-typed-array,isarray,isexe,jackspeak,js-yaml,jsonfile,lazy-val,lodash.escaperegexp,lodash.isequal,lru-cache,math-intrinsics,minimatch,minimist,minipass,mkdirp,ms,package-json-from-dist,path-is-absolute,path-key,path-scurry,possible-typed-array-names,reflect-metadata,safe-buffer,sax,semver,set-function-length,sha.js,shebang-command,shebang-regex,signal-exit,sql-highlight,sql.js,string-width,string-width-cjs,strip-ansi,strip-ansi-cjs,tiny-typed-emitter,to-buffer,tslib,typed-array-buffer,typeorm,universalify,untildify,uuid,which,which-typed-array,winreg,wrap-ansi,wrap-ansi-cjs,y18n,yallist,yargs,yargs-parser}/**/*",
|
||||
"node_modules/@isaacs/cliui/**/*",
|
||||
"node_modules/@pkgjs/parseargs/**/*",
|
||||
"node_modules/@sqltools/formatter/**/*",
|
||||
"!node_modules/**/test/**/*",
|
||||
"!node_modules/**/tests/**/*",
|
||||
"!node_modules/**/*.d.ts",
|
||||
|
||||
@@ -4,18 +4,28 @@ import { resolveRuntimePath } from '../runtime-paths';
|
||||
|
||||
export type ServerHttpProtocol = 'http' | 'https';
|
||||
|
||||
export interface LinkPreviewConfig {
|
||||
enabled: boolean;
|
||||
cacheTtlMinutes: number;
|
||||
maxCacheSizeMb: number;
|
||||
}
|
||||
|
||||
export interface ServerVariablesConfig {
|
||||
klipyApiKey: string;
|
||||
releaseManifestUrl: string;
|
||||
serverPort: number;
|
||||
serverProtocol: ServerHttpProtocol;
|
||||
serverHost: string;
|
||||
linkPreview: LinkPreviewConfig;
|
||||
}
|
||||
|
||||
const DATA_DIR = resolveRuntimePath('data');
|
||||
const VARIABLES_FILE = path.join(DATA_DIR, 'variables.json');
|
||||
const DEFAULT_SERVER_PORT = 3001;
|
||||
const DEFAULT_SERVER_PROTOCOL: ServerHttpProtocol = 'http';
|
||||
const DEFAULT_LINK_PREVIEW_CACHE_TTL_MINUTES = 7200;
|
||||
const DEFAULT_LINK_PREVIEW_MAX_CACHE_SIZE_MB = 50;
|
||||
const HARD_MAX_CACHE_SIZE_MB = 50;
|
||||
|
||||
function normalizeKlipyApiKey(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : '';
|
||||
@@ -66,6 +76,27 @@ function normalizeServerPort(value: unknown, fallback = DEFAULT_SERVER_PORT): nu
|
||||
: fallback;
|
||||
}
|
||||
|
||||
function normalizeLinkPreviewConfig(value: unknown): LinkPreviewConfig {
|
||||
const raw = (value && typeof value === 'object' && !Array.isArray(value))
|
||||
? value as Record<string, unknown>
|
||||
: {};
|
||||
const enabled = typeof raw.enabled === 'boolean'
|
||||
? raw.enabled
|
||||
: true;
|
||||
const cacheTtl = typeof raw.cacheTtlMinutes === 'number'
|
||||
&& Number.isFinite(raw.cacheTtlMinutes)
|
||||
&& raw.cacheTtlMinutes >= 0
|
||||
? raw.cacheTtlMinutes
|
||||
: DEFAULT_LINK_PREVIEW_CACHE_TTL_MINUTES;
|
||||
const maxSize = typeof raw.maxCacheSizeMb === 'number'
|
||||
&& Number.isFinite(raw.maxCacheSizeMb)
|
||||
&& raw.maxCacheSizeMb >= 0
|
||||
? Math.min(raw.maxCacheSizeMb, HARD_MAX_CACHE_SIZE_MB)
|
||||
: DEFAULT_LINK_PREVIEW_MAX_CACHE_SIZE_MB;
|
||||
|
||||
return { enabled, cacheTtlMinutes: cacheTtl, maxCacheSizeMb: maxSize };
|
||||
}
|
||||
|
||||
function hasEnvironmentOverride(value: string | undefined): value is string {
|
||||
return typeof value === 'string' && value.trim().length > 0;
|
||||
}
|
||||
@@ -111,7 +142,8 @@ export function ensureVariablesConfig(): ServerVariablesConfig {
|
||||
releaseManifestUrl: normalizeReleaseManifestUrl(remainingParsed.releaseManifestUrl),
|
||||
serverPort: normalizeServerPort(remainingParsed.serverPort),
|
||||
serverProtocol: normalizeServerProtocol(remainingParsed.serverProtocol),
|
||||
serverHost: normalizeServerHost(remainingParsed.serverHost ?? legacyServerIpAddress)
|
||||
serverHost: normalizeServerHost(remainingParsed.serverHost ?? legacyServerIpAddress),
|
||||
linkPreview: normalizeLinkPreviewConfig(remainingParsed.linkPreview)
|
||||
};
|
||||
const nextContents = JSON.stringify(normalized, null, 2) + '\n';
|
||||
|
||||
@@ -124,7 +156,8 @@ export function ensureVariablesConfig(): ServerVariablesConfig {
|
||||
releaseManifestUrl: normalized.releaseManifestUrl,
|
||||
serverPort: normalized.serverPort,
|
||||
serverProtocol: normalized.serverProtocol,
|
||||
serverHost: normalized.serverHost
|
||||
serverHost: normalized.serverHost,
|
||||
linkPreview: normalized.linkPreview
|
||||
};
|
||||
}
|
||||
|
||||
@@ -169,3 +202,7 @@ export function getServerHost(): string | undefined {
|
||||
export function isHttpsServerEnabled(): boolean {
|
||||
return getServerProtocol() === 'https';
|
||||
}
|
||||
|
||||
export function getLinkPreviewConfig(): LinkPreviewConfig {
|
||||
return getVariablesConfig().linkPreview;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ export async function initDatabase(): Promise<void> {
|
||||
ServerBanEntity
|
||||
],
|
||||
migrations: serverMigrations,
|
||||
synchronize: false,
|
||||
synchronize: process.env.DB_SYNCHRONIZE === 'true',
|
||||
logging: false,
|
||||
autoSave: true,
|
||||
location: DB_FILE,
|
||||
@@ -90,8 +90,12 @@ export async function initDatabase(): Promise<void> {
|
||||
|
||||
console.log('[DB] Connection initialised at:', DB_FILE);
|
||||
|
||||
if (process.env.DB_SYNCHRONIZE !== 'true') {
|
||||
await applicationDataSource.runMigrations();
|
||||
console.log('[DB] Migrations executed');
|
||||
} else {
|
||||
console.log('[DB] Synchronize mode — migrations skipped');
|
||||
}
|
||||
}
|
||||
|
||||
export async function destroyDatabase(): Promise<void> {
|
||||
|
||||
@@ -4,8 +4,12 @@ export class ServerChannels1000000000002 implements MigrationInterface {
|
||||
name = 'ServerChannels1000000000002';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
const columns: { name: string }[] = await queryRunner.query(`PRAGMA table_info("servers")`);
|
||||
const hasChannels = columns.some(c => c.name === 'channels');
|
||||
if (!hasChannels) {
|
||||
await queryRunner.query(`ALTER TABLE "servers" ADD COLUMN "channels" TEXT NOT NULL DEFAULT '[]'`);
|
||||
}
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "servers" DROP COLUMN "channels"`);
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { Router } from 'express';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { getAllPublicServers } from '../cqrs';
|
||||
import { getReleaseManifestUrl } from '../config/variables';
|
||||
import { SERVER_BUILD_VERSION } from '../generated/build-version';
|
||||
import { connectedUsers } from '../websocket/state';
|
||||
|
||||
const router = Router();
|
||||
const SERVER_INSTANCE_ID = typeof process.env.METOYOU_SERVER_INSTANCE_ID === 'string'
|
||||
&& process.env.METOYOU_SERVER_INSTANCE_ID.trim().length > 0
|
||||
? process.env.METOYOU_SERVER_INSTANCE_ID.trim()
|
||||
: randomUUID();
|
||||
|
||||
function getServerProjectVersion(): string {
|
||||
return typeof process.env.METOYOU_SERVER_VERSION === 'string' && process.env.METOYOU_SERVER_VERSION.trim().length > 0
|
||||
@@ -20,6 +25,7 @@ router.get('/health', async (_req, res) => {
|
||||
timestamp: Date.now(),
|
||||
serverCount: servers.length,
|
||||
connectedUsers: connectedUsers.size,
|
||||
serverInstanceId: SERVER_INSTANCE_ID,
|
||||
serverVersion: getServerProjectVersion(),
|
||||
releaseManifestUrl: getReleaseManifestUrl()
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Express } from 'express';
|
||||
import healthRouter from './health';
|
||||
import klipyRouter from './klipy';
|
||||
import linkMetadataRouter from './link-metadata';
|
||||
import proxyRouter from './proxy';
|
||||
import usersRouter from './users';
|
||||
import serversRouter from './servers';
|
||||
@@ -10,6 +11,7 @@ import { invitesApiRouter, invitePageRouter } from './invites';
|
||||
export function registerRoutes(app: Express): void {
|
||||
app.use('/api', healthRouter);
|
||||
app.use('/api', klipyRouter);
|
||||
app.use('/api', linkMetadataRouter);
|
||||
app.use('/api', proxyRouter);
|
||||
app.use('/api/users', usersRouter);
|
||||
app.use('/api/servers', serversRouter);
|
||||
|
||||
292
server/src/routes/link-metadata.ts
Normal file
292
server/src/routes/link-metadata.ts
Normal file
@@ -0,0 +1,292 @@
|
||||
import { Router } from 'express';
|
||||
import { getLinkPreviewConfig } from '../config/variables';
|
||||
import { resolveAndValidateHost, safeFetch } from './ssrf-guard';
|
||||
|
||||
const router = Router();
|
||||
const REQUEST_TIMEOUT_MS = 8000;
|
||||
const MAX_HTML_BYTES = 512 * 1024;
|
||||
const BYTES_PER_MB = 1024 * 1024;
|
||||
const MAX_FIELD_LENGTH = 512;
|
||||
|
||||
interface CachedMetadata {
|
||||
title?: string;
|
||||
description?: string;
|
||||
imageUrl?: string;
|
||||
siteName?: string;
|
||||
failed?: boolean;
|
||||
cachedAt: number;
|
||||
}
|
||||
|
||||
const metadataCache = new Map<string, CachedMetadata>();
|
||||
|
||||
let cacheByteEstimate = 0;
|
||||
|
||||
function estimateEntryBytes(key: string, entry: CachedMetadata): number {
|
||||
let bytes = key.length * 2;
|
||||
|
||||
if (entry.title)
|
||||
bytes += entry.title.length * 2;
|
||||
|
||||
if (entry.description)
|
||||
bytes += entry.description.length * 2;
|
||||
|
||||
if (entry.imageUrl)
|
||||
bytes += entry.imageUrl.length * 2;
|
||||
|
||||
if (entry.siteName)
|
||||
bytes += entry.siteName.length * 2;
|
||||
|
||||
return bytes + 64;
|
||||
}
|
||||
|
||||
function cacheSet(key: string, entry: CachedMetadata): void {
|
||||
const config = getLinkPreviewConfig();
|
||||
const maxBytes = config.maxCacheSizeMb * BYTES_PER_MB;
|
||||
|
||||
if (metadataCache.has(key)) {
|
||||
const existing = metadataCache.get(key) as CachedMetadata;
|
||||
|
||||
cacheByteEstimate -= estimateEntryBytes(key, existing);
|
||||
}
|
||||
|
||||
const entryBytes = estimateEntryBytes(key, entry);
|
||||
|
||||
while (cacheByteEstimate + entryBytes > maxBytes && metadataCache.size > 0) {
|
||||
const oldest = metadataCache.keys().next().value as string;
|
||||
const oldestEntry = metadataCache.get(oldest) as CachedMetadata;
|
||||
|
||||
cacheByteEstimate -= estimateEntryBytes(oldest, oldestEntry);
|
||||
metadataCache.delete(oldest);
|
||||
}
|
||||
|
||||
metadataCache.set(key, entry);
|
||||
cacheByteEstimate += entryBytes;
|
||||
}
|
||||
|
||||
function truncateField(value: string | undefined): string | undefined {
|
||||
if (!value)
|
||||
return value;
|
||||
|
||||
if (value.length <= MAX_FIELD_LENGTH)
|
||||
return value;
|
||||
|
||||
return value.slice(0, MAX_FIELD_LENGTH);
|
||||
}
|
||||
|
||||
function sanitizeImageUrl(rawUrl: string | undefined, baseUrl: string): string | undefined {
|
||||
if (!rawUrl)
|
||||
return undefined;
|
||||
|
||||
try {
|
||||
const resolved = new URL(rawUrl, baseUrl);
|
||||
|
||||
if (resolved.protocol !== 'http:' && resolved.protocol !== 'https:')
|
||||
return undefined;
|
||||
|
||||
return resolved.href;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function getMetaContent(html: string, patterns: RegExp[]): string | undefined {
|
||||
for (const pattern of patterns) {
|
||||
const match = pattern.exec(html);
|
||||
|
||||
if (match?.[1])
|
||||
return decodeHtmlEntities(match[1].trim());
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function decodeHtmlEntities(text: string): string {
|
||||
return text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, "'")
|
||||
.replace(/'/g, "'")
|
||||
.replace(///g, '/');
|
||||
}
|
||||
|
||||
function parseMetadata(html: string, url: string): CachedMetadata {
|
||||
const title = getMetaContent(html, [
|
||||
/<meta[^>]+property=["']og:title["'][^>]+content=["']([^"']+)["']/i,
|
||||
/<meta[^>]+content=["']([^"']+)["'][^>]+property=["']og:title["']/i,
|
||||
/<meta[^>]+name=["']twitter:title["'][^>]+content=["']([^"']+)["']/i,
|
||||
/<meta[^>]+content=["']([^"']+)["'][^>]+name=["']twitter:title["']/i,
|
||||
/<title[^>]*>([^<]+)<\/title>/i
|
||||
]);
|
||||
const description = getMetaContent(html, [
|
||||
/<meta[^>]+property=["']og:description["'][^>]+content=["']([^"']+)["']/i,
|
||||
/<meta[^>]+content=["']([^"']+)["'][^>]+property=["']og:description["']/i,
|
||||
/<meta[^>]+name=["']twitter:description["'][^>]+content=["']([^"']+)["']/i,
|
||||
/<meta[^>]+content=["']([^"']+)["'][^>]+name=["']twitter:description["']/i,
|
||||
/<meta[^>]+name=["']description["'][^>]+content=["']([^"']+)["']/i,
|
||||
/<meta[^>]+content=["']([^"']+)["'][^>]+name=["']description["']/i
|
||||
]);
|
||||
const rawImageUrl = getMetaContent(html, [
|
||||
/<meta[^>]+property=["']og:image["'][^>]+content=["']([^"']+)["']/i,
|
||||
/<meta[^>]+content=["']([^"']+)["'][^>]+property=["']og:image["']/i,
|
||||
/<meta[^>]+name=["']twitter:image["'][^>]+content=["']([^"']+)["']/i,
|
||||
/<meta[^>]+content=["']([^"']+)["'][^>]+name=["']twitter:image["']/i
|
||||
]);
|
||||
const siteNamePatterns = [
|
||||
// eslint-disable-next-line @stylistic/js/array-element-newline
|
||||
/<meta[^>]+property=["']og:site_name["'][^>]+content=["']([^"']+)["']/i,
|
||||
/<meta[^>]+content=["']([^"']+)["'][^>]+property=["']og:site_name["']/i
|
||||
];
|
||||
const siteName = getMetaContent(html, siteNamePatterns);
|
||||
const imageUrl = sanitizeImageUrl(rawImageUrl, url);
|
||||
|
||||
return {
|
||||
title: truncateField(title),
|
||||
description: truncateField(description),
|
||||
imageUrl,
|
||||
siteName: truncateField(siteName),
|
||||
cachedAt: Date.now()
|
||||
};
|
||||
}
|
||||
|
||||
function evictExpired(): void {
|
||||
const config = getLinkPreviewConfig();
|
||||
|
||||
if (config.cacheTtlMinutes === 0) {
|
||||
cacheByteEstimate = 0;
|
||||
metadataCache.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const ttlMs = config.cacheTtlMinutes * 60 * 1000;
|
||||
const now = Date.now();
|
||||
|
||||
for (const [key, entry] of metadataCache) {
|
||||
if (now - entry.cachedAt > ttlMs) {
|
||||
cacheByteEstimate -= estimateEntryBytes(key, entry);
|
||||
metadataCache.delete(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
router.get('/link-metadata', async (req, res) => {
|
||||
try {
|
||||
const config = getLinkPreviewConfig();
|
||||
|
||||
if (!config.enabled) {
|
||||
return res.status(403).json({ error: 'Link previews are disabled' });
|
||||
}
|
||||
|
||||
const url = String(req.query.url || '');
|
||||
|
||||
if (!/^https?:\/\//i.test(url)) {
|
||||
return res.status(400).json({ error: 'Invalid URL' });
|
||||
}
|
||||
|
||||
const hostAllowed = await resolveAndValidateHost(url);
|
||||
|
||||
if (!hostAllowed) {
|
||||
return res.status(400).json({ error: 'URL resolves to a blocked address' });
|
||||
}
|
||||
|
||||
evictExpired();
|
||||
|
||||
const cached = metadataCache.get(url);
|
||||
|
||||
if (cached) {
|
||||
const { cachedAt, ...metadata } = cached;
|
||||
|
||||
console.log(`[Link Metadata] Cache hit for ${url} (cached at ${new Date(cachedAt).toISOString()})`);
|
||||
return res.json(metadata);
|
||||
}
|
||||
|
||||
console.log(`[Link Metadata] Cache miss for ${url}. Fetching...`);
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
||||
const response = await safeFetch(url, {
|
||||
signal: controller.signal,
|
||||
headers: {
|
||||
'Accept': 'text/html',
|
||||
'User-Agent': 'MetoYou-LinkPreview/1.0'
|
||||
}
|
||||
});
|
||||
|
||||
clearTimeout(timeout);
|
||||
|
||||
if (!response || !response.ok) {
|
||||
const failed: CachedMetadata = { failed: true, cachedAt: Date.now() };
|
||||
|
||||
cacheSet(url, failed);
|
||||
|
||||
return res.json({ failed: true });
|
||||
}
|
||||
|
||||
const contentType = response.headers.get('content-type') || '';
|
||||
|
||||
if (!contentType.includes('text/html')) {
|
||||
const failed: CachedMetadata = { failed: true, cachedAt: Date.now() };
|
||||
|
||||
cacheSet(url, failed);
|
||||
|
||||
return res.json({ failed: true });
|
||||
}
|
||||
|
||||
const reader = response.body?.getReader();
|
||||
|
||||
if (!reader) {
|
||||
const failed: CachedMetadata = { failed: true, cachedAt: Date.now() };
|
||||
|
||||
cacheSet(url, failed);
|
||||
|
||||
return res.json({ failed: true });
|
||||
}
|
||||
|
||||
const chunks: Uint8Array[] = [];
|
||||
|
||||
let totalBytes = 0;
|
||||
let done = false;
|
||||
|
||||
while (!done) {
|
||||
const result = await reader.read();
|
||||
|
||||
done = result.done;
|
||||
|
||||
if (result.value) {
|
||||
chunks.push(result.value);
|
||||
totalBytes += result.value.length;
|
||||
|
||||
if (totalBytes > MAX_HTML_BYTES) {
|
||||
reader.cancel();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const html = Buffer.concat(chunks).toString('utf-8');
|
||||
const metadata = parseMetadata(html, url);
|
||||
|
||||
cacheSet(url, metadata);
|
||||
|
||||
const { cachedAt, ...result } = metadata;
|
||||
|
||||
res.json(result);
|
||||
} catch (err) {
|
||||
const url = String(req.query.url || '');
|
||||
|
||||
if (url) {
|
||||
cacheSet(url, { failed: true, cachedAt: Date.now() });
|
||||
}
|
||||
|
||||
if ((err as { name?: string })?.name === 'AbortError') {
|
||||
return res.json({ failed: true });
|
||||
}
|
||||
|
||||
console.error('Link metadata error:', err);
|
||||
res.json({ failed: true });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Router } from 'express';
|
||||
import { resolveAndValidateHost, safeFetch } from './ssrf-guard';
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -10,14 +11,20 @@ router.get('/image-proxy', async (req, res) => {
|
||||
return res.status(400).json({ error: 'Invalid URL' });
|
||||
}
|
||||
|
||||
const hostAllowed = await resolveAndValidateHost(url);
|
||||
|
||||
if (!hostAllowed) {
|
||||
return res.status(400).json({ error: 'URL resolves to a blocked address' });
|
||||
}
|
||||
|
||||
const controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller.abort(), 8000);
|
||||
const response = await fetch(url, { redirect: 'follow', signal: controller.signal });
|
||||
const response = await safeFetch(url, { signal: controller.signal });
|
||||
|
||||
clearTimeout(timeout);
|
||||
|
||||
if (!response.ok) {
|
||||
return res.status(response.status).end();
|
||||
if (!response || !response.ok) {
|
||||
return res.status(response?.status ?? 502).end();
|
||||
}
|
||||
|
||||
const contentType = response.headers.get('content-type') || '';
|
||||
|
||||
119
server/src/routes/ssrf-guard.ts
Normal file
119
server/src/routes/ssrf-guard.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
import { lookup } from 'dns/promises';
|
||||
|
||||
const MAX_REDIRECTS = 5;
|
||||
|
||||
function isPrivateIp(ip: string): boolean {
|
||||
if (
|
||||
ip === '127.0.0.1' ||
|
||||
ip === '::1' ||
|
||||
ip === '0.0.0.0' ||
|
||||
ip === '::'
|
||||
)
|
||||
return true;
|
||||
|
||||
// 10.x.x.x
|
||||
if (ip.startsWith('10.'))
|
||||
return true;
|
||||
|
||||
// 172.16.0.0 - 172.31.255.255
|
||||
if (ip.startsWith('172.')) {
|
||||
const second = parseInt(ip.split('.')[1], 10);
|
||||
|
||||
if (second >= 16 && second <= 31)
|
||||
return true;
|
||||
}
|
||||
|
||||
// 192.168.x.x
|
||||
if (ip.startsWith('192.168.'))
|
||||
return true;
|
||||
|
||||
// 169.254.x.x (link-local, AWS metadata)
|
||||
if (ip.startsWith('169.254.'))
|
||||
return true;
|
||||
|
||||
// IPv6 private ranges (fc00::/7, fe80::/10)
|
||||
const lower = ip.toLowerCase();
|
||||
|
||||
if (lower.startsWith('fc') || lower.startsWith('fd') || lower.startsWith('fe80'))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function resolveAndValidateHost(url: string): Promise<boolean> {
|
||||
let hostname: string;
|
||||
|
||||
try {
|
||||
hostname = new URL(url).hostname;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Block obvious private hostnames
|
||||
if (hostname === 'localhost' || hostname === 'metadata.google.internal')
|
||||
return false;
|
||||
|
||||
// If hostname is already an IP literal, check it directly
|
||||
if (/^[\d.]+$/.test(hostname) || hostname.startsWith('['))
|
||||
return !isPrivateIp(hostname.replace(/[[\]]/g, ''));
|
||||
|
||||
try {
|
||||
const { address } = await lookup(hostname);
|
||||
|
||||
return !isPrivateIp(address);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SafeFetchOptions {
|
||||
signal?: AbortSignal;
|
||||
headers?: Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a URL while following redirects safely, validating each
|
||||
* hop against SSRF (private/reserved IPs, blocked hostnames).
|
||||
*
|
||||
* The caller must validate the initial URL with `resolveAndValidateHost`
|
||||
* before calling this function.
|
||||
*/
|
||||
export async function safeFetch(url: string, options: SafeFetchOptions = {}): Promise<Response | undefined> {
|
||||
let currentUrl = url;
|
||||
let response: Response | undefined;
|
||||
|
||||
for (let redirects = 0; redirects <= MAX_REDIRECTS; redirects++) {
|
||||
response = await fetch(currentUrl, {
|
||||
redirect: 'manual',
|
||||
signal: options.signal,
|
||||
headers: options.headers
|
||||
});
|
||||
|
||||
const location = response.headers.get('location');
|
||||
|
||||
if (response.status >= 300 && response.status < 400 && location) {
|
||||
let nextUrl: string;
|
||||
|
||||
try {
|
||||
nextUrl = new URL(location, currentUrl).href;
|
||||
} catch {
|
||||
break;
|
||||
}
|
||||
|
||||
if (!/^https?:\/\//i.test(nextUrl))
|
||||
break;
|
||||
|
||||
const redirectAllowed = await resolveAndValidateHost(nextUrl);
|
||||
|
||||
if (!redirectAllowed)
|
||||
break;
|
||||
|
||||
currentUrl = nextUrl;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { WebSocket } from 'ws';
|
||||
import { connectedUsers } from './state';
|
||||
import { ConnectedUser } from './types';
|
||||
|
||||
interface WsMessage {
|
||||
[key: string]: unknown;
|
||||
@@ -8,8 +10,14 @@ interface WsMessage {
|
||||
export function broadcastToServer(serverId: string, message: WsMessage, excludeOderId?: string): void {
|
||||
console.log(`Broadcasting to server ${serverId}, excluding ${excludeOderId}:`, message.type);
|
||||
|
||||
// Deduplicate by oderId so users with multiple connections (e.g. from
|
||||
// different signal URLs routing to the same server) receive the
|
||||
// broadcast only once.
|
||||
const sentToOderIds = new Set<string>();
|
||||
|
||||
connectedUsers.forEach((user) => {
|
||||
if (user.serverIds.has(serverId) && user.oderId !== excludeOderId) {
|
||||
if (user.serverIds.has(serverId) && user.oderId !== excludeOderId && !sentToOderIds.has(user.oderId)) {
|
||||
sentToOderIds.add(user.oderId);
|
||||
console.log(` -> Sending to ${user.displayName} (${user.oderId})`);
|
||||
user.ws.send(JSON.stringify(message));
|
||||
}
|
||||
@@ -24,6 +32,43 @@ export function notifyServerOwner(ownerId: string, message: WsMessage): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function getUniqueUsersInServer(serverId: string, excludeOderId?: string): ConnectedUser[] {
|
||||
const usersByOderId = new Map<string, ConnectedUser>();
|
||||
|
||||
connectedUsers.forEach((user) => {
|
||||
if (user.oderId === excludeOderId || !user.serverIds.has(serverId) || user.ws.readyState !== WebSocket.OPEN) {
|
||||
return;
|
||||
}
|
||||
|
||||
usersByOderId.set(user.oderId, user);
|
||||
});
|
||||
|
||||
return Array.from(usersByOderId.values());
|
||||
}
|
||||
|
||||
export function isOderIdConnectedToServer(oderId: string, serverId: string, excludeConnectionId?: string): boolean {
|
||||
return Array.from(connectedUsers.entries()).some(([connectionId, user]) =>
|
||||
connectionId !== excludeConnectionId
|
||||
&& user.oderId === oderId
|
||||
&& user.serverIds.has(serverId)
|
||||
&& user.ws.readyState === WebSocket.OPEN
|
||||
);
|
||||
}
|
||||
|
||||
export function getServerIdsForOderId(oderId: string, excludeConnectionId?: string): string[] {
|
||||
const serverIds = new Set<string>();
|
||||
|
||||
connectedUsers.forEach((user, connectionId) => {
|
||||
if (connectionId === excludeConnectionId || user.oderId !== oderId || user.ws.readyState !== WebSocket.OPEN) {
|
||||
return;
|
||||
}
|
||||
|
||||
user.serverIds.forEach((serverId) => serverIds.add(serverId));
|
||||
});
|
||||
|
||||
return Array.from(serverIds);
|
||||
}
|
||||
|
||||
export function notifyUser(oderId: string, message: WsMessage): void {
|
||||
const user = findUserByOderId(oderId);
|
||||
|
||||
@@ -33,5 +78,13 @@ export function notifyUser(oderId: string, message: WsMessage): void {
|
||||
}
|
||||
|
||||
export function findUserByOderId(oderId: string) {
|
||||
return Array.from(connectedUsers.values()).find(user => user.oderId === oderId);
|
||||
let match: ConnectedUser | undefined;
|
||||
|
||||
connectedUsers.forEach((user) => {
|
||||
if (user.oderId === oderId && user.ws.readyState === WebSocket.OPEN) {
|
||||
match = user;
|
||||
}
|
||||
});
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { connectedUsers } from './state';
|
||||
import { ConnectedUser } from './types';
|
||||
import { broadcastToServer, findUserByOderId } from './broadcast';
|
||||
import {
|
||||
broadcastToServer,
|
||||
findUserByOderId,
|
||||
getServerIdsForOderId,
|
||||
getUniqueUsersInServer,
|
||||
isOderIdConnectedToServer
|
||||
} from './broadcast';
|
||||
import { authorizeWebSocketJoin } from '../services/server-access.service';
|
||||
|
||||
interface WsMessage {
|
||||
@@ -14,24 +20,60 @@ function normalizeDisplayName(value: unknown, fallback = 'User'): string {
|
||||
return normalized || fallback;
|
||||
}
|
||||
|
||||
function readMessageId(value: unknown): string | undefined {
|
||||
if (typeof value !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const normalized = value.trim();
|
||||
|
||||
if (!normalized || normalized === 'undefined' || normalized === 'null') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
/** Sends the current user list for a given server to a single connected user. */
|
||||
function sendServerUsers(user: ConnectedUser, serverId: string): void {
|
||||
const users = Array.from(connectedUsers.values())
|
||||
.filter(cu => cu.serverIds.has(serverId) && cu.oderId !== user.oderId)
|
||||
const users = getUniqueUsersInServer(serverId, user.oderId)
|
||||
.map(cu => ({ oderId: cu.oderId, displayName: normalizeDisplayName(cu.displayName) }));
|
||||
|
||||
user.ws.send(JSON.stringify({ type: 'server_users', serverId, users }));
|
||||
}
|
||||
|
||||
function handleIdentify(user: ConnectedUser, message: WsMessage, connectionId: string): void {
|
||||
user.oderId = String(message['oderId'] || connectionId);
|
||||
const newOderId = readMessageId(message['oderId']) ?? connectionId;
|
||||
const newScope = typeof message['connectionScope'] === 'string' ? message['connectionScope'] : undefined;
|
||||
|
||||
// Close stale connections from the same identity AND the same connection
|
||||
// scope so offer routing always targets the freshest socket (e.g. after
|
||||
// page refresh). Connections with a *different* scope (= a different
|
||||
// signal URL that happens to route to this server) are left untouched so
|
||||
// multi-signal-URL setups don't trigger an eviction loop.
|
||||
connectedUsers.forEach((existing, existingId) => {
|
||||
if (existingId !== connectionId
|
||||
&& existing.oderId === newOderId
|
||||
&& existing.connectionScope === newScope) {
|
||||
console.log(`Closing stale connection for ${newOderId} (old=${existingId}, new=${connectionId}, scope=${newScope ?? 'none'})`);
|
||||
|
||||
try {
|
||||
existing.ws.close();
|
||||
} catch { /* already closing */ }
|
||||
|
||||
connectedUsers.delete(existingId);
|
||||
}
|
||||
});
|
||||
|
||||
user.oderId = newOderId;
|
||||
user.displayName = normalizeDisplayName(message['displayName'], normalizeDisplayName(user.displayName));
|
||||
user.connectionScope = newScope;
|
||||
connectedUsers.set(connectionId, user);
|
||||
console.log(`User identified: ${user.displayName} (${user.oderId})`);
|
||||
}
|
||||
|
||||
async function handleJoinServer(user: ConnectedUser, message: WsMessage, connectionId: string): Promise<void> {
|
||||
const sid = String(message['serverId']);
|
||||
const sid = readMessageId(message['serverId']);
|
||||
|
||||
if (!sid)
|
||||
return;
|
||||
@@ -48,16 +90,20 @@ async function handleJoinServer(user: ConnectedUser, message: WsMessage, connect
|
||||
return;
|
||||
}
|
||||
|
||||
const isNew = !user.serverIds.has(sid);
|
||||
const isNewConnectionMembership = !user.serverIds.has(sid);
|
||||
const isNewIdentityMembership = isNewConnectionMembership && !isOderIdConnectedToServer(user.oderId, sid, connectionId);
|
||||
|
||||
user.serverIds.add(sid);
|
||||
user.viewedServerId = sid;
|
||||
connectedUsers.set(connectionId, user);
|
||||
console.log(`User ${normalizeDisplayName(user.displayName)} (${user.oderId}) joined server ${sid} (new=${isNew})`);
|
||||
console.log(
|
||||
`User ${normalizeDisplayName(user.displayName)} (${user.oderId}) joined server ${sid} `
|
||||
+ `(newConnection=${isNewConnectionMembership}, newIdentity=${isNewIdentityMembership})`
|
||||
);
|
||||
|
||||
sendServerUsers(user, sid);
|
||||
|
||||
if (isNew) {
|
||||
if (isNewIdentityMembership) {
|
||||
broadcastToServer(sid, {
|
||||
type: 'user_joined',
|
||||
oderId: user.oderId,
|
||||
@@ -68,7 +114,10 @@ async function handleJoinServer(user: ConnectedUser, message: WsMessage, connect
|
||||
}
|
||||
|
||||
function handleViewServer(user: ConnectedUser, message: WsMessage, connectionId: string): void {
|
||||
const viewSid = String(message['serverId']);
|
||||
const viewSid = readMessageId(message['serverId']);
|
||||
|
||||
if (!viewSid)
|
||||
return;
|
||||
|
||||
user.viewedServerId = viewSid;
|
||||
connectedUsers.set(connectionId, user);
|
||||
@@ -78,7 +127,7 @@ function handleViewServer(user: ConnectedUser, message: WsMessage, connectionId:
|
||||
}
|
||||
|
||||
function handleLeaveServer(user: ConnectedUser, message: WsMessage, connectionId: string): void {
|
||||
const leaveSid = (message['serverId'] as string | undefined) ?? user.viewedServerId;
|
||||
const leaveSid = readMessageId(message['serverId']) ?? user.viewedServerId;
|
||||
|
||||
if (!leaveSid)
|
||||
return;
|
||||
@@ -90,17 +139,23 @@ function handleLeaveServer(user: ConnectedUser, message: WsMessage, connectionId
|
||||
|
||||
connectedUsers.set(connectionId, user);
|
||||
|
||||
const remainingServerIds = getServerIdsForOderId(user.oderId, connectionId);
|
||||
|
||||
if (remainingServerIds.includes(leaveSid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
broadcastToServer(leaveSid, {
|
||||
type: 'user_left',
|
||||
oderId: user.oderId,
|
||||
displayName: normalizeDisplayName(user.displayName),
|
||||
serverId: leaveSid,
|
||||
serverIds: Array.from(user.serverIds)
|
||||
serverIds: remainingServerIds
|
||||
}, user.oderId);
|
||||
}
|
||||
|
||||
function forwardRtcMessage(user: ConnectedUser, message: WsMessage): void {
|
||||
const targetUserId = String(message['targetUserId'] || '');
|
||||
const targetUserId = readMessageId(message['targetUserId']) ?? '';
|
||||
|
||||
console.log(`Forwarding ${message.type} from ${user.oderId} to ${targetUserId}`);
|
||||
|
||||
|
||||
@@ -6,7 +6,11 @@ import {
|
||||
import { WebSocketServer, WebSocket } from 'ws';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { connectedUsers } from './state';
|
||||
import { broadcastToServer } from './broadcast';
|
||||
import {
|
||||
broadcastToServer,
|
||||
getServerIdsForOderId,
|
||||
isOderIdConnectedToServer
|
||||
} from './broadcast';
|
||||
import { handleWebSocketMessage } from './handler';
|
||||
|
||||
/** How often to ping all connected clients (ms). */
|
||||
@@ -20,13 +24,19 @@ function removeDeadConnection(connectionId: string): void {
|
||||
if (user) {
|
||||
console.log(`Removing dead connection: ${user.displayName ?? 'Unknown'} (${user.oderId})`);
|
||||
|
||||
const remainingServerIds = getServerIdsForOderId(user.oderId, connectionId);
|
||||
|
||||
user.serverIds.forEach((sid) => {
|
||||
if (isOderIdConnectedToServer(user.oderId, sid, connectionId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
broadcastToServer(sid, {
|
||||
type: 'user_left',
|
||||
oderId: user.oderId,
|
||||
displayName: user.displayName,
|
||||
serverId: sid,
|
||||
serverIds: []
|
||||
serverIds: remainingServerIds
|
||||
}, user.oderId);
|
||||
});
|
||||
|
||||
|
||||
@@ -6,6 +6,13 @@ export interface ConnectedUser {
|
||||
serverIds: Set<string>;
|
||||
viewedServerId?: string;
|
||||
displayName?: string;
|
||||
/**
|
||||
* Opaque scope string sent by the client (typically the signal URL it
|
||||
* connected through). Stale-connection eviction only targets connections
|
||||
* that share the same (oderId, connectionScope) pair, so multiple signal
|
||||
* URLs routing to the same server coexist without an eviction loop.
|
||||
*/
|
||||
connectionScope?: string;
|
||||
/** Timestamp of the last pong received (used to detect dead connections). */
|
||||
lastPong: number;
|
||||
}
|
||||
|
||||
10
skills-lock.json
Normal file
10
skills-lock.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 1,
|
||||
"skills": {
|
||||
"caveman": {
|
||||
"source": "JuliusBrussee/caveman",
|
||||
"sourceType": "github",
|
||||
"computedHash": "4d486dd6f9fbb27ce1c51c972c9a5eb25a53236ae05eabf4d076ac1e293f4b7a"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ import { MessagesSyncEffects } from './store/messages/messages-sync.effects';
|
||||
import { UsersEffects } from './store/users/users.effects';
|
||||
import { RoomsEffects } from './store/rooms/rooms.effects';
|
||||
import { RoomMembersSyncEffects } from './store/rooms/room-members-sync.effects';
|
||||
import { RoomStateSyncEffects } from './store/rooms/room-state-sync.effects';
|
||||
import { RoomSettingsEffects } from './store/rooms/room-settings.effects';
|
||||
import { STORE_DEVTOOLS_MAX_AGE } from './core/constants';
|
||||
|
||||
/** Root application configuration providing routing, HTTP, NgRx store, and devtools. */
|
||||
@@ -38,7 +40,9 @@ export const appConfig: ApplicationConfig = {
|
||||
MessagesSyncEffects,
|
||||
UsersEffects,
|
||||
RoomsEffects,
|
||||
RoomMembersSyncEffects
|
||||
RoomMembersSyncEffects,
|
||||
RoomStateSyncEffects,
|
||||
RoomSettingsEffects
|
||||
]),
|
||||
provideStoreDevtools({
|
||||
maxAge: STORE_DEVTOOLS_MAX_AGE,
|
||||
|
||||
@@ -150,6 +150,7 @@
|
||||
}
|
||||
<app-settings-modal />
|
||||
<app-screen-share-source-picker />
|
||||
<app-native-context-menu />
|
||||
<app-debug-console [showLauncher]="false" />
|
||||
<app-theme-picker-overlay />
|
||||
</div>
|
||||
|
||||
@@ -10,12 +10,12 @@ export const routes: Routes = [
|
||||
{
|
||||
path: 'login',
|
||||
loadComponent: () =>
|
||||
import('./domains/auth/feature/login/login.component').then((module) => module.LoginComponent)
|
||||
import('./domains/authentication/feature/login/login.component').then((module) => module.LoginComponent)
|
||||
},
|
||||
{
|
||||
path: 'register',
|
||||
loadComponent: () =>
|
||||
import('./domains/auth/feature/register/register.component').then((module) => module.RegisterComponent)
|
||||
import('./domains/authentication/feature/register/register.component').then((module) => module.RegisterComponent)
|
||||
},
|
||||
{
|
||||
path: 'invite/:inviteId',
|
||||
|
||||
@@ -39,6 +39,7 @@ import { FloatingVoiceControlsComponent } from './domains/voice-session/feature/
|
||||
import { SettingsModalComponent } from './features/settings/settings-modal/settings-modal.component';
|
||||
import { DebugConsoleComponent } from './shared/components/debug-console/debug-console.component';
|
||||
import { ScreenShareSourcePickerComponent } from './shared/components/screen-share-source-picker/screen-share-source-picker.component';
|
||||
import { NativeContextMenuComponent } from './features/shell/native-context-menu.component';
|
||||
import { UsersActions } from './store/users/users.actions';
|
||||
import { RoomsActions } from './store/rooms/rooms.actions';
|
||||
import { selectCurrentRoom } from './store/rooms/rooms.selectors';
|
||||
@@ -61,6 +62,7 @@ import {
|
||||
SettingsModalComponent,
|
||||
DebugConsoleComponent,
|
||||
ScreenShareSourcePickerComponent,
|
||||
NativeContextMenuComponent,
|
||||
ThemeNodeDirective,
|
||||
ThemePickerOverlayComponent
|
||||
],
|
||||
|
||||
@@ -10,8 +10,9 @@ export const STORAGE_KEY_THEME_DRAFT = 'metoyou_theme_draft';
|
||||
export const STORAGE_KEY_USER_VOLUMES = 'metoyou_user_volumes';
|
||||
export const ROOM_URL_PATTERN = /\/room\/([^/]+)/;
|
||||
export const STORE_DEVTOOLS_MAX_AGE = 25;
|
||||
export const DEBUG_LOG_MAX_ENTRIES = 500;
|
||||
export const DEBUG_LOG_MAX_ENTRIES = 5000;
|
||||
export const DEFAULT_MAX_USERS = 50;
|
||||
export const DEFAULT_AUDIO_BITRATE_KBPS = 96;
|
||||
export const DEFAULT_VOLUME = 100;
|
||||
export const SEARCH_DEBOUNCE_MS = 300;
|
||||
export const RECONNECT_SOUND_GRACE_MS = 15_000;
|
||||
|
||||
@@ -134,6 +134,22 @@ export interface ElectronQuery {
|
||||
payload: unknown;
|
||||
}
|
||||
|
||||
export interface ContextMenuParams {
|
||||
posX: number;
|
||||
posY: number;
|
||||
isEditable: boolean;
|
||||
selectionText: string;
|
||||
linkURL: string;
|
||||
mediaType: string;
|
||||
srcURL: string;
|
||||
editFlags: {
|
||||
canCut: boolean;
|
||||
canCopy: boolean;
|
||||
canPaste: boolean;
|
||||
canSelectAll: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ElectronApi {
|
||||
linuxDisplayServer: string;
|
||||
minimizeWindow: () => void;
|
||||
@@ -176,6 +192,9 @@ export interface ElectronApi {
|
||||
fileExists: (filePath: string) => Promise<boolean>;
|
||||
deleteFile: (filePath: string) => Promise<boolean>;
|
||||
ensureDir: (dirPath: string) => Promise<boolean>;
|
||||
onContextMenu: (listener: (params: ContextMenuParams) => void) => () => void;
|
||||
contextMenuCommand: (command: string) => Promise<void>;
|
||||
copyImageToClipboard: (srcURL: string) => Promise<boolean>;
|
||||
command: <T = unknown>(command: ElectronCommand) => Promise<T>;
|
||||
query: <T = unknown>(query: ElectronQuery) => Promise<T>;
|
||||
}
|
||||
|
||||
@@ -302,7 +302,9 @@ class DebugNetworkSnapshotBuilder {
|
||||
case 'offer':
|
||||
case 'answer':
|
||||
case 'ice_candidate': {
|
||||
const peerId = this.getPayloadString(payload, 'targetPeerId') ?? this.getPayloadString(payload, 'fromUserId');
|
||||
const peerId = direction === 'outbound'
|
||||
? (this.getPayloadString(payload, 'targetPeerId') ?? this.getPayloadString(payload, 'fromUserId'))
|
||||
: (this.getPayloadString(payload, 'fromUserId') ?? this.getPayloadString(payload, 'targetPeerId'));
|
||||
const displayName = this.getPayloadString(payload, 'displayName');
|
||||
|
||||
if (!peerId)
|
||||
@@ -1295,7 +1297,7 @@ class DebugNetworkSnapshotBuilder {
|
||||
private getPayloadString(payload: Record<string, unknown> | null, key: string): string | null {
|
||||
const value = this.getPayloadField(payload, key);
|
||||
|
||||
return typeof value === 'string' ? value : null;
|
||||
return this.normalizeStringValue(value);
|
||||
}
|
||||
|
||||
private getPayloadNumber(payload: Record<string, unknown> | null, key: string): number | null {
|
||||
@@ -1323,7 +1325,7 @@ class DebugNetworkSnapshotBuilder {
|
||||
private getStringProperty(record: Record<string, unknown> | null, key: string): string | null {
|
||||
const value = record?.[key];
|
||||
|
||||
return typeof value === 'string' ? value : null;
|
||||
return this.normalizeStringValue(value);
|
||||
}
|
||||
|
||||
private getBooleanProperty(record: Record<string, unknown> | null, key: string): boolean | null {
|
||||
@@ -1344,4 +1346,16 @@ class DebugNetworkSnapshotBuilder {
|
||||
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
private normalizeStringValue(value: unknown): string | null {
|
||||
if (typeof value !== 'string')
|
||||
return null;
|
||||
|
||||
const normalized = value.trim();
|
||||
|
||||
if (!normalized || normalized === 'undefined' || normalized === 'null')
|
||||
return null;
|
||||
|
||||
return normalized;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ infrastructure adapters and UI.
|
||||
| Domain | Purpose | Public entry point |
|
||||
| -------------------- | ------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------- |
|
||||
| **attachment** | File upload/download, chunk transfer, persistence | `AttachmentFacade` |
|
||||
| **access-control** | Role, permission, moderation, and room access rules | `normalizeRoomAccessControl()`, `resolveRoomPermission()` |
|
||||
| **auth** | Login / register HTTP orchestration, user-bar UI | `AuthService` |
|
||||
| **access-control** | Role, permission, ban matching, moderation, and room access rules | `normalizeRoomAccessControl()`, `resolveRoomPermission()`, `hasRoomBanForUser()` |
|
||||
| **authentication** | Login / register HTTP orchestration, user-bar UI | `AuthenticationService` |
|
||||
| **chat** | Messaging rules, sync logic, GIF/Klipy integration, chat UI | `KlipyService`, `canEditMessage()`, `ChatMessagesComponent` |
|
||||
| **notifications** | Notification preferences, unread tracking, desktop alert orchestration | `NotificationsFacade` |
|
||||
| **screen-share** | Source picker, quality presets | `ScreenShareFacade` |
|
||||
@@ -25,7 +25,7 @@ The larger domains also keep longer design notes in their own folders:
|
||||
|
||||
- [attachment/README.md](attachment/README.md)
|
||||
- [access-control/README.md](access-control/README.md)
|
||||
- [auth/README.md](auth/README.md)
|
||||
- [authentication/README.md](authentication/README.md)
|
||||
- [chat/README.md](chat/README.md)
|
||||
- [notifications/README.md](notifications/README.md)
|
||||
- [screen-share/README.md](screen-share/README.md)
|
||||
|
||||
@@ -7,13 +7,18 @@ Role and permission rules for servers, including default system roles, role assi
|
||||
```
|
||||
access-control/
|
||||
├── domain/
|
||||
│ ├── access-control.models.ts MemberIdentity and RoomPermissionDefinition domain types
|
||||
│ ├── access-control.constants.ts SYSTEM_ROLE_IDS and permission metadata
|
||||
│ ├── models/
|
||||
│ │ └── access-control.model.ts MemberIdentity and RoomPermissionDefinition domain types
|
||||
│ ├── constants/
|
||||
│ │ └── access-control.constants.ts SYSTEM_ROLE_IDS and permission metadata
|
||||
│ ├── util/
|
||||
│ │ └── access-control.util.ts Internal helpers (normalization, identity matching, sorting)
|
||||
│ └── rules/
|
||||
│ ├── role.rules.ts Role defaults, normalization, ordering, create/update helpers
|
||||
│ ├── role-assignment.rules.ts Assignment normalization and member-role lookups
|
||||
│ ├── permission.rules.ts Permission resolution and moderation hierarchy checks
|
||||
│ ├── room.rules.ts Legacy compatibility, room hydration, room-level normalization
|
||||
│ └── access-control.logic.ts Public barrel for domain rules
|
||||
│ └── ban.rules.ts Ban matching and user-ban resolution
|
||||
│
|
||||
└── index.ts Domain barrel used by other layers
|
||||
```
|
||||
@@ -29,6 +34,8 @@ access-control/
|
||||
| `canManageMember(...)` | Applies both permission checks and role hierarchy checks |
|
||||
| `canManageRole(...)` | Prevents editing roles at or above the actor's highest role |
|
||||
| `normalizeRoomAccessControl(room)` | Produces a fully hydrated room with normalized roles, assignments, overrides, and legacy compatibility fields |
|
||||
| `hasRoomBanForUser(bans, user, persistedUserId?)` | Returns true when any active ban entry targets the provided user |
|
||||
| `isRoomBanMatch(ban, user, persistedUserId?)` | Returns true when a single ban entry targets the provided user |
|
||||
|
||||
## Layering
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
export * from './access-control.models';
|
||||
export * from './access-control.constants';
|
||||
export * from './role.rules';
|
||||
export * from './role-assignment.rules';
|
||||
export * from './permission.rules';
|
||||
export * from './room.rules';
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { RoomPermissionDefinition } from './access-control.models';
|
||||
import type { RoomPermissionDefinition } from '../models/access-control.model';
|
||||
|
||||
export const SYSTEM_ROLE_IDS = {
|
||||
everyone: 'system-everyone',
|
||||
@@ -2,7 +2,7 @@ import type {
|
||||
RoomMember,
|
||||
RoomPermissionKey,
|
||||
User
|
||||
} from '../../../shared-kernel';
|
||||
} from '../../../../shared-kernel';
|
||||
|
||||
export interface RoomPermissionDefinition {
|
||||
key: RoomPermissionKey;
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BanEntry, User } from '../models/index';
|
||||
import { BanEntry, User } from '../../../../shared-kernel';
|
||||
|
||||
type BanAwareUser = Pick<User, 'id' | 'oderId'> | null | undefined;
|
||||
|
||||
@@ -4,9 +4,9 @@ import {
|
||||
Room,
|
||||
RoomPermissionKey,
|
||||
RoomRole
|
||||
} from '../../../shared-kernel';
|
||||
import { SYSTEM_ROLE_IDS } from './access-control.constants';
|
||||
import type { MemberIdentity } from './access-control.models';
|
||||
} from '../../../../shared-kernel';
|
||||
import { SYSTEM_ROLE_IDS } from '../constants/access-control.constants';
|
||||
import type { MemberIdentity } from '../models/access-control.model';
|
||||
import {
|
||||
buildRoleLookup,
|
||||
getRolePermissionState,
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
normalizePermissionState,
|
||||
roleSortAscending,
|
||||
compareText
|
||||
} from './access-control.internal';
|
||||
} from '../util/access-control.util';
|
||||
import { getAssignedRoleIds, getHighestAssignedRole } from './role-assignment.rules';
|
||||
import { getRoomRoleById, normalizeRoomRoles } from './role.rules';
|
||||
|
||||
@@ -3,9 +3,9 @@ import {
|
||||
RoomMember,
|
||||
RoomRole,
|
||||
RoomRoleAssignment
|
||||
} from '../../../shared-kernel';
|
||||
import { SYSTEM_ROLE_IDS } from './access-control.constants';
|
||||
import type { MemberIdentity } from './access-control.models';
|
||||
} from '../../../../shared-kernel';
|
||||
import { SYSTEM_ROLE_IDS } from '../constants/access-control.constants';
|
||||
import type { MemberIdentity } from '../models/access-control.model';
|
||||
import {
|
||||
buildRoleLookup,
|
||||
compareText,
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
matchesIdentity,
|
||||
roleSortDescending,
|
||||
uniqueStrings
|
||||
} from './access-control.internal';
|
||||
} from '../util/access-control.util';
|
||||
import { getRoomRoleById, normalizeRoomRoles } from './role.rules';
|
||||
|
||||
function sortAssignments(assignments: readonly RoomRoleAssignment[]): RoomRoleAssignment[] {
|
||||
@@ -2,8 +2,8 @@ import {
|
||||
RoomPermissionMatrix,
|
||||
RoomPermissions,
|
||||
RoomRole
|
||||
} from '../../../shared-kernel';
|
||||
import { SYSTEM_ROLE_IDS } from './access-control.constants';
|
||||
} from '../../../../shared-kernel';
|
||||
import { SYSTEM_ROLE_IDS } from '../constants/access-control.constants';
|
||||
import {
|
||||
buildRoleLookup,
|
||||
buildSystemRole,
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
normalizePermissionMatrix,
|
||||
roleSortAscending,
|
||||
roleSortDescending
|
||||
} from './access-control.internal';
|
||||
} from '../util/access-control.util';
|
||||
|
||||
const ROLE_COLORS = {
|
||||
everyone: '#6b7280',
|
||||
@@ -7,14 +7,14 @@ import {
|
||||
RoomRole,
|
||||
RoomRoleAssignment,
|
||||
UserRole
|
||||
} from '../../../shared-kernel';
|
||||
import { SYSTEM_ROLE_IDS } from './access-control.constants';
|
||||
} from '../../../../shared-kernel';
|
||||
import { SYSTEM_ROLE_IDS } from '../constants/access-control.constants';
|
||||
import {
|
||||
getRolePermissionState,
|
||||
permissionStateToBoolean,
|
||||
resolveLegacyAllowState
|
||||
} from './access-control.internal';
|
||||
import type { MemberIdentity } from './access-control.models';
|
||||
} from '../util/access-control.util';
|
||||
import type { MemberIdentity } from '../models/access-control.model';
|
||||
import {
|
||||
getAssignedRoleIds,
|
||||
normalizeRoomRoleAssignments,
|
||||
@@ -5,8 +5,8 @@ import {
|
||||
RoomRole,
|
||||
RoomRoleAssignment,
|
||||
ROOM_PERMISSION_KEYS
|
||||
} from '../../../shared-kernel';
|
||||
import type { MemberIdentity } from './access-control.models';
|
||||
} from '../../../../shared-kernel';
|
||||
import type { MemberIdentity } from '../models/access-control.model';
|
||||
|
||||
export function normalizeName(name: string): string {
|
||||
return name.trim().replace(/\s+/g, ' ');
|
||||
@@ -1,6 +1,7 @@
|
||||
export * from './domain/access-control.models';
|
||||
export * from './domain/access-control.constants';
|
||||
export * from './domain/role.rules';
|
||||
export * from './domain/role-assignment.rules';
|
||||
export * from './domain/permission.rules';
|
||||
export * from './domain/room.rules';
|
||||
export * from './domain/models/access-control.model';
|
||||
export * from './domain/constants/access-control.constants';
|
||||
export * from './domain/rules/role.rules';
|
||||
export * from './domain/rules/role-assignment.rules';
|
||||
export * from './domain/rules/permission.rules';
|
||||
export * from './domain/rules/room.rules';
|
||||
export * from './domain/rules/ban.rules';
|
||||
|
||||
@@ -7,7 +7,9 @@ Handles file sharing between peers over WebRTC data channels. Files are announce
|
||||
```
|
||||
attachment/
|
||||
├── application/
|
||||
│ ├── attachment.facade.ts Thin entry point, delegates to manager
|
||||
│ ├── facades/
|
||||
│ │ └── attachment.facade.ts Thin entry point, delegates to manager
|
||||
│ └── services/
|
||||
│ ├── attachment-manager.service.ts Orchestrates lifecycle, auto-download, peer listeners
|
||||
│ ├── attachment-transfer.service.ts P2P file transfer protocol (announce/request/chunk/cancel)
|
||||
│ ├── attachment-transfer-transport.service.ts Base64 encode/decode, chunked streaming
|
||||
@@ -15,15 +17,20 @@ attachment/
|
||||
│ └── attachment-runtime.store.ts In-memory signal-based state (Maps for attachments, chunks, pending)
|
||||
│
|
||||
├── domain/
|
||||
│ ├── attachment.models.ts Attachment type extending AttachmentMeta with runtime state
|
||||
│ ├── attachment.logic.ts isAttachmentMedia, shouldAutoRequestWhenWatched, shouldPersistDownloadedAttachment
|
||||
│ ├── logic/
|
||||
│ │ └── attachment.logic.ts isAttachmentMedia, shouldAutoRequestWhenWatched, shouldPersistDownloadedAttachment
|
||||
│ ├── models/
|
||||
│ │ ├── attachment.model.ts Attachment type extending AttachmentMeta with runtime state
|
||||
│ │ └── attachment-transfer.model.ts Protocol event types (file-announce, file-chunk, file-request, ...)
|
||||
│ └── constants/
|
||||
│ ├── attachment.constants.ts MAX_AUTO_SAVE_SIZE_BYTES = 10 MB
|
||||
│ ├── attachment-transfer.models.ts Protocol event types (file-announce, file-chunk, file-request, ...)
|
||||
│ └── attachment-transfer.constants.ts FILE_CHUNK_SIZE_BYTES = 64 KB, EWMA weights, error messages
|
||||
│
|
||||
├── infrastructure/
|
||||
│ ├── attachment-storage.service.ts Electron filesystem access (save / read / delete)
|
||||
│ └── attachment-storage.helpers.ts sanitizeAttachmentRoomName, resolveAttachmentStorageBucket
|
||||
│ ├── services/
|
||||
│ │ └── attachment-storage.service.ts Electron filesystem access (save / read / delete)
|
||||
│ └── util/
|
||||
│ └── attachment-storage.util.ts sanitizeAttachmentRoomName, resolveAttachmentStorageBucket
|
||||
│
|
||||
└── index.ts Barrel exports
|
||||
```
|
||||
@@ -52,17 +59,17 @@ graph TD
|
||||
Transfer --> Store
|
||||
Persistence --> Storage
|
||||
Persistence --> Store
|
||||
Storage --> Helpers[attachment-storage.helpers]
|
||||
Storage --> Helpers[attachment-storage.util]
|
||||
|
||||
click Facade "application/attachment.facade.ts" "Thin entry point" _blank
|
||||
click Manager "application/attachment-manager.service.ts" "Orchestrates lifecycle" _blank
|
||||
click Transfer "application/attachment-transfer.service.ts" "P2P file transfer protocol" _blank
|
||||
click Transport "application/attachment-transfer-transport.service.ts" "Base64 encode/decode, chunked streaming" _blank
|
||||
click Persistence "application/attachment-persistence.service.ts" "DB + filesystem persistence" _blank
|
||||
click Store "application/attachment-runtime.store.ts" "In-memory signal-based state" _blank
|
||||
click Storage "infrastructure/attachment-storage.service.ts" "Electron filesystem access" _blank
|
||||
click Helpers "infrastructure/attachment-storage.helpers.ts" "Path helpers" _blank
|
||||
click Logic "domain/attachment.logic.ts" "Pure decision functions" _blank
|
||||
click Facade "application/facades/attachment.facade.ts" "Thin entry point" _blank
|
||||
click Manager "application/services/attachment-manager.service.ts" "Orchestrates lifecycle" _blank
|
||||
click Transfer "application/services/attachment-transfer.service.ts" "P2P file transfer protocol" _blank
|
||||
click Transport "application/services/attachment-transfer-transport.service.ts" "Base64 encode/decode, chunked streaming" _blank
|
||||
click Persistence "application/services/attachment-persistence.service.ts" "DB + filesystem persistence" _blank
|
||||
click Store "application/services/attachment-runtime.store.ts" "In-memory signal-based state" _blank
|
||||
click Storage "infrastructure/services/attachment-storage.service.ts" "Electron filesystem access" _blank
|
||||
click Helpers "infrastructure/util/attachment-storage.util.ts" "Path helpers" _blank
|
||||
click Logic "domain/logic/attachment.logic.ts" "Pure decision functions" _blank
|
||||
```
|
||||
|
||||
## File transfer protocol
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { AttachmentManagerService } from './attachment-manager.service';
|
||||
import { AttachmentManagerService } from '../services/attachment-manager.service';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AttachmentFacade {
|
||||
@@ -4,18 +4,18 @@ import {
|
||||
inject
|
||||
} from '@angular/core';
|
||||
import { NavigationEnd, Router } from '@angular/router';
|
||||
import { RealtimeSessionFacade } from '../../../core/realtime';
|
||||
import { DatabaseService } from '../../../infrastructure/persistence';
|
||||
import { ROOM_URL_PATTERN } from '../../../core/constants';
|
||||
import { shouldAutoRequestWhenWatched } from '../domain/attachment.logic';
|
||||
import type { Attachment, AttachmentMeta } from '../domain/attachment.models';
|
||||
import { RealtimeSessionFacade } from '../../../../core/realtime';
|
||||
import { DatabaseService } from '../../../../infrastructure/persistence';
|
||||
import { ROOM_URL_PATTERN } from '../../../../core/constants';
|
||||
import { shouldAutoRequestWhenWatched } from '../../domain/logic/attachment.logic';
|
||||
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.model';
|
||||
import type {
|
||||
FileAnnouncePayload,
|
||||
FileCancelPayload,
|
||||
FileChunkPayload,
|
||||
FileNotFoundPayload,
|
||||
FileRequestPayload
|
||||
} from '../domain/attachment-transfer.models';
|
||||
} from '../../domain/models/attachment-transfer.model';
|
||||
import { AttachmentPersistenceService } from './attachment-persistence.service';
|
||||
import { AttachmentRuntimeStore } from './attachment-runtime.store';
|
||||
import { AttachmentTransferService } from './attachment-transfer.service';
|
||||
@@ -1,12 +1,12 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { take } from 'rxjs';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { selectCurrentRoomName } from '../../../store/rooms/rooms.selectors';
|
||||
import { DatabaseService } from '../../../infrastructure/persistence';
|
||||
import { AttachmentStorageService } from '../infrastructure/attachment-storage.service';
|
||||
import type { Attachment, AttachmentMeta } from '../domain/attachment.models';
|
||||
import { MAX_AUTO_SAVE_SIZE_BYTES } from '../domain/attachment.constants';
|
||||
import { LEGACY_ATTACHMENTS_STORAGE_KEY } from '../domain/attachment-transfer.constants';
|
||||
import { selectCurrentRoomName } from '../../../../store/rooms/rooms.selectors';
|
||||
import { DatabaseService } from '../../../../infrastructure/persistence';
|
||||
import { AttachmentStorageService } from '../../infrastructure/services/attachment-storage.service';
|
||||
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.model';
|
||||
import { MAX_AUTO_SAVE_SIZE_BYTES } from '../../domain/constants/attachment.constants';
|
||||
import { LEGACY_ATTACHMENTS_STORAGE_KEY } from '../../domain/constants/attachment-transfer.constants';
|
||||
import { AttachmentRuntimeStore } from './attachment-runtime.store';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Injectable, signal } from '@angular/core';
|
||||
import type { Attachment } from '../domain/attachment.models';
|
||||
import type { Attachment } from '../../domain/models/attachment.model';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AttachmentRuntimeStore {
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { RealtimeSessionFacade } from '../../../core/realtime';
|
||||
import { AttachmentStorageService } from '../infrastructure/attachment-storage.service';
|
||||
import { FILE_CHUNK_SIZE_BYTES } from '../domain/attachment-transfer.constants';
|
||||
import { FileChunkEvent } from '../domain/attachment-transfer.models';
|
||||
import { RealtimeSessionFacade } from '../../../../core/realtime';
|
||||
import { AttachmentStorageService } from '../../infrastructure/services/attachment-storage.service';
|
||||
import { FILE_CHUNK_SIZE_BYTES } from '../../domain/constants/attachment-transfer.constants';
|
||||
import { FileChunkEvent } from '../../domain/models/attachment-transfer.model';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AttachmentTransferTransportService {
|
||||
@@ -1,17 +1,17 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { recordDebugNetworkFileChunk } from '../../../infrastructure/realtime/logging/debug-network-metrics';
|
||||
import { RealtimeSessionFacade } from '../../../core/realtime';
|
||||
import { AttachmentStorageService } from '../infrastructure/attachment-storage.service';
|
||||
import { MAX_AUTO_SAVE_SIZE_BYTES } from '../domain/attachment.constants';
|
||||
import { shouldPersistDownloadedAttachment } from '../domain/attachment.logic';
|
||||
import type { Attachment, AttachmentMeta } from '../domain/attachment.models';
|
||||
import { recordDebugNetworkFileChunk } from '../../../../infrastructure/realtime/logging/debug-network-metrics';
|
||||
import { RealtimeSessionFacade } from '../../../../core/realtime';
|
||||
import { AttachmentStorageService } from '../../infrastructure/services/attachment-storage.service';
|
||||
import { MAX_AUTO_SAVE_SIZE_BYTES } from '../../domain/constants/attachment.constants';
|
||||
import { shouldPersistDownloadedAttachment } from '../../domain/logic/attachment.logic';
|
||||
import type { Attachment, AttachmentMeta } from '../../domain/models/attachment.model';
|
||||
import {
|
||||
ATTACHMENT_TRANSFER_EWMA_CURRENT_WEIGHT,
|
||||
ATTACHMENT_TRANSFER_EWMA_PREVIOUS_WEIGHT,
|
||||
DEFAULT_ATTACHMENT_MIME_TYPE,
|
||||
FILE_NOT_FOUND_REQUEST_ERROR,
|
||||
NO_CONNECTED_PEERS_REQUEST_ERROR
|
||||
} from '../domain/attachment-transfer.constants';
|
||||
} from '../../domain/constants/attachment-transfer.constants';
|
||||
import {
|
||||
type FileAnnounceEvent,
|
||||
type FileAnnouncePayload,
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
type FileRequestEvent,
|
||||
type FileRequestPayload,
|
||||
type LocalFileWithPath
|
||||
} from '../domain/attachment-transfer.models';
|
||||
} from '../../domain/models/attachment-transfer.model';
|
||||
import { AttachmentPersistenceService } from './attachment-persistence.service';
|
||||
import { AttachmentRuntimeStore } from './attachment-runtime.store';
|
||||
import { AttachmentTransferTransportService } from './attachment-transfer-transport.service';
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MAX_AUTO_SAVE_SIZE_BYTES } from './attachment.constants';
|
||||
import type { Attachment } from './attachment.models';
|
||||
import { MAX_AUTO_SAVE_SIZE_BYTES } from '../constants/attachment.constants';
|
||||
import type { Attachment } from '../models/attachment.model';
|
||||
|
||||
export function isAttachmentMedia(attachment: Pick<Attachment, 'mime'>): boolean {
|
||||
return attachment.mime.startsWith('image/') ||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { ChatEvent } from '../../../shared-kernel';
|
||||
import type { ChatAttachmentAnnouncement } from '../../../shared-kernel';
|
||||
import type { ChatEvent } from '../../../../shared-kernel';
|
||||
import type { ChatAttachmentAnnouncement } from '../../../../shared-kernel';
|
||||
|
||||
export type FileAnnounceEvent = ChatEvent & {
|
||||
type: 'file-announce';
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ChatAttachmentMeta } from '../../../shared-kernel';
|
||||
import type { ChatAttachmentMeta } from '../../../../shared-kernel';
|
||||
|
||||
export type AttachmentMeta = ChatAttachmentMeta;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from './application/attachment.facade';
|
||||
export * from './domain/attachment.constants';
|
||||
export * from './domain/attachment.models';
|
||||
export * from './application/facades/attachment.facade';
|
||||
export * from './domain/constants/attachment.constants';
|
||||
export * from './domain/models/attachment.model';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { ElectronBridgeService } from '../../../core/platform/electron/electron-bridge.service';
|
||||
import type { Attachment } from '../domain/attachment.models';
|
||||
import { ElectronBridgeService } from '../../../../core/platform/electron/electron-bridge.service';
|
||||
import type { Attachment } from '../../domain/models/attachment.model';
|
||||
import {
|
||||
resolveAttachmentStorageBucket,
|
||||
resolveAttachmentStoredFilename,
|
||||
sanitizeAttachmentRoomName
|
||||
} from './attachment-storage.helpers';
|
||||
} from '../util/attachment-storage.util';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AttachmentStorageService {
|
||||
@@ -1 +0,0 @@
|
||||
export * from './application/auth.service';
|
||||
@@ -1,13 +1,18 @@
|
||||
# Auth Domain
|
||||
# Authentication Domain
|
||||
|
||||
Handles user authentication (login and registration) against the configured server endpoint. Provides the login, register, and user-bar UI components.
|
||||
|
||||
## Module map
|
||||
|
||||
```
|
||||
auth/
|
||||
authentication/
|
||||
├── application/
|
||||
│ └── auth.service.ts HTTP login/register against the active server endpoint
|
||||
│ └── services/
|
||||
│ └── authentication.service.ts HTTP login/register against the active server endpoint
|
||||
│
|
||||
├── domain/
|
||||
│ └── models/
|
||||
│ └── authentication.model.ts LoginResponse interface
|
||||
│
|
||||
├── feature/
|
||||
│ ├── login/ Login form component
|
||||
@@ -19,14 +24,14 @@ auth/
|
||||
|
||||
## Service overview
|
||||
|
||||
`AuthService` resolves the API base URL from `ServerDirectoryFacade`, then makes POST requests for login and registration. It does not hold session state itself; after a successful login the calling component stores `currentUserId` in localStorage and dispatches `UsersActions.setCurrentUser` into the NgRx store.
|
||||
`AuthenticationService` resolves the API base URL from `ServerDirectoryFacade`, then makes POST requests for login and registration. It does not hold session state itself; after a successful login the calling component stores `currentUserId` in localStorage and dispatches `UsersActions.setCurrentUser` into the NgRx store.
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
Login[LoginComponent]
|
||||
Register[RegisterComponent]
|
||||
UserBar[UserBarComponent]
|
||||
Auth[AuthService]
|
||||
Auth[AuthenticationService]
|
||||
SD[ServerDirectoryFacade]
|
||||
Store[NgRx Store]
|
||||
|
||||
@@ -36,7 +41,7 @@ graph TD
|
||||
Auth --> SD
|
||||
Login --> Store
|
||||
|
||||
click Auth "application/auth.service.ts" "HTTP login/register" _blank
|
||||
click Auth "application/services/authentication.service.ts" "HTTP login/register" _blank
|
||||
click Login "feature/login/" "Login form" _blank
|
||||
click Register "feature/register/" "Registration form" _blank
|
||||
click UserBar "feature/user-bar/" "Current user display" _blank
|
||||
@@ -49,7 +54,7 @@ graph TD
|
||||
sequenceDiagram
|
||||
participant User
|
||||
participant Login as LoginComponent
|
||||
participant Auth as AuthService
|
||||
participant Auth as AuthenticationService
|
||||
participant SD as ServerDirectoryFacade
|
||||
participant API as Server API
|
||||
participant Store as NgRx Store
|
||||
@@ -2,19 +2,8 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { type ServerEndpoint, ServerDirectoryFacade } from '../../server-directory';
|
||||
|
||||
/**
|
||||
* Response returned by the authentication endpoints (login / register).
|
||||
*/
|
||||
export interface LoginResponse {
|
||||
/** Unique user identifier assigned by the server. */
|
||||
id: string;
|
||||
/** Login username. */
|
||||
username: string;
|
||||
/** Human-readable display name. */
|
||||
displayName: string;
|
||||
}
|
||||
import { type ServerEndpoint, ServerDirectoryFacade } from '../../../server-directory';
|
||||
import type { LoginResponse } from '../../domain/models/authentication.model';
|
||||
|
||||
/**
|
||||
* Handles user authentication (login and registration) against a
|
||||
@@ -25,7 +14,7 @@ export interface LoginResponse {
|
||||
* server endpoint is used.
|
||||
*/
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AuthService {
|
||||
export class AuthenticationService {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly serverDirectory = inject(ServerDirectoryFacade);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Response returned by the authentication endpoints (login / register).
|
||||
*/
|
||||
export interface LoginResponse {
|
||||
/** Unique user identifier assigned by the server. */
|
||||
id: string;
|
||||
/** Login username. */
|
||||
username: string;
|
||||
/** Human-readable display name. */
|
||||
displayName: string;
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import { Store } from '@ngrx/store';
|
||||
import { NgIcon, provideIcons } from '@ng-icons/core';
|
||||
import { lucideLogIn } from '@ng-icons/lucide';
|
||||
|
||||
import { AuthService } from '../../application/auth.service';
|
||||
import { AuthenticationService } from '../../application/services/authentication.service';
|
||||
import { ServerDirectoryFacade } from '../../../server-directory';
|
||||
import { UsersActions } from '../../../../store/users/users.actions';
|
||||
import { User } from '../../../../shared-kernel';
|
||||
@@ -40,7 +40,7 @@ export class LoginComponent {
|
||||
serverId: string | undefined = this.serversSvc.activeServer()?.id;
|
||||
error = signal<string | null>(null);
|
||||
|
||||
private auth = inject(AuthService);
|
||||
private auth = inject(AuthenticationService);
|
||||
private store = inject(Store);
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
@@ -11,7 +11,7 @@ import { Store } from '@ngrx/store';
|
||||
import { NgIcon, provideIcons } from '@ng-icons/core';
|
||||
import { lucideUserPlus } from '@ng-icons/lucide';
|
||||
|
||||
import { AuthService } from '../../application/auth.service';
|
||||
import { AuthenticationService } from '../../application/services/authentication.service';
|
||||
import { ServerDirectoryFacade } from '../../../server-directory';
|
||||
import { UsersActions } from '../../../../store/users/users.actions';
|
||||
import { User } from '../../../../shared-kernel';
|
||||
@@ -41,7 +41,7 @@ export class RegisterComponent {
|
||||
serverId: string | undefined = this.serversSvc.activeServer()?.id;
|
||||
error = signal<string | null>(null);
|
||||
|
||||
private auth = inject(AuthService);
|
||||
private auth = inject(AuthenticationService);
|
||||
private store = inject(Store);
|
||||
private route = inject(ActivatedRoute);
|
||||
private router = inject(Router);
|
||||
2
toju-app/src/app/domains/authentication/index.ts
Normal file
2
toju-app/src/app/domains/authentication/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './application/services/authentication.service';
|
||||
export * from './domain/models/authentication.model';
|
||||
@@ -7,9 +7,12 @@ Text messaging, reactions, GIF search, typing indicators, and the user list. All
|
||||
```
|
||||
chat/
|
||||
├── application/
|
||||
│ └── klipy.service.ts GIF search via the KLIPY API (proxied through the server)
|
||||
│ └── services/
|
||||
│ ├── klipy.service.ts GIF search via the KLIPY API (proxied through the server)
|
||||
│ └── link-metadata.service.ts Link preview metadata fetching
|
||||
│
|
||||
├── domain/
|
||||
│ └── rules/
|
||||
│ ├── message.rules.ts canEditMessage, normaliseDeletedMessage, getMessageTimestamp
|
||||
│ └── message-sync.rules.ts Inventory-based sync: chunkArray, findMissingIds, limits
|
||||
│
|
||||
@@ -25,6 +28,7 @@ chat/
|
||||
│ │ └── services/
|
||||
│ │ └── chat-markdown.service.ts Markdown-to-HTML rendering
|
||||
│ │
|
||||
│ ├── chat-image-proxy-fallback.directive.ts Image proxy fallback for broken URLs
|
||||
│ ├── klipy-gif-picker/ GIF search/browse picker panel
|
||||
│ ├── typing-indicator/ "X is typing..." display (3 s TTL, max 4 names)
|
||||
│ └── user-list/ Online user sidebar
|
||||
@@ -129,7 +133,7 @@ graph LR
|
||||
Klipy --> API
|
||||
|
||||
click Picker "feature/klipy-gif-picker/" "GIF search panel" _blank
|
||||
click Klipy "application/klipy.service.ts" "GIF search via KLIPY API" _blank
|
||||
click Klipy "application/services/klipy.service.ts" "GIF search via KLIPY API" _blank
|
||||
click SD "../server-directory/application/server-directory.facade.ts" "Resolves API base URL" _blank
|
||||
```
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
throwError
|
||||
} from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { ServerDirectoryFacade } from '../../server-directory';
|
||||
import { ServerDirectoryFacade } from '../../../server-directory';
|
||||
|
||||
export interface KlipyGif {
|
||||
id: string;
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import { ServerDirectoryFacade } from '../../../server-directory';
|
||||
import { LinkMetadata } from '../../../../shared-kernel';
|
||||
|
||||
const URL_PATTERN = /https?:\/\/[^\s<>)"']+/g;
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class LinkMetadataService {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly serverDirectory = inject(ServerDirectoryFacade);
|
||||
|
||||
extractUrls(content: string): string[] {
|
||||
return [...content.matchAll(URL_PATTERN)].map((m) => m[0]);
|
||||
}
|
||||
|
||||
async fetchMetadata(url: string): Promise<LinkMetadata> {
|
||||
try {
|
||||
const apiBase = this.serverDirectory.getApiBaseUrl();
|
||||
const result = await firstValueFrom(
|
||||
this.http.get<Omit<LinkMetadata, 'url'>>(
|
||||
`${apiBase}/link-metadata`,
|
||||
{ params: { url } }
|
||||
)
|
||||
);
|
||||
|
||||
return { url, ...result };
|
||||
} catch {
|
||||
return { url, failed: true };
|
||||
}
|
||||
}
|
||||
|
||||
async fetchAllMetadata(urls: string[]): Promise<LinkMetadata[]> {
|
||||
const unique = [...new Set(urls)];
|
||||
|
||||
return Promise.all(unique.map((url) => this.fetchMetadata(url)));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { DELETED_MESSAGE_CONTENT, type Message } from '../../../shared-kernel';
|
||||
import { DELETED_MESSAGE_CONTENT, type Message } from '../../../../shared-kernel';
|
||||
|
||||
/** Extracts the effective timestamp from a message (editedAt takes priority). */
|
||||
export function getMessageTimestamp(msg: Message): number {
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
input,
|
||||
signal
|
||||
} from '@angular/core';
|
||||
import { KlipyService } from '../application/klipy.service';
|
||||
import { KlipyService } from '../application/services/klipy.service';
|
||||
|
||||
@Directive({
|
||||
selector: 'img[appChatImageProxyFallback]',
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
(downloadRequested)="downloadAttachment($event)"
|
||||
(imageOpened)="openLightbox($event)"
|
||||
(imageContextMenuRequested)="openImageContextMenu($event)"
|
||||
(embedRemoved)="handleEmbedRemoved($event)"
|
||||
/>
|
||||
|
||||
<div class="chat-bottom-bar absolute bottom-0 left-0 right-0 z-10">
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Store } from '@ngrx/store';
|
||||
import { ElectronBridgeService } from '../../../../core/platform/electron/electron-bridge.service';
|
||||
import { RealtimeSessionFacade } from '../../../../core/realtime';
|
||||
import { Attachment, AttachmentFacade } from '../../../attachment';
|
||||
import { KlipyGif } from '../../application/klipy.service';
|
||||
import { KlipyGif } from '../../application/services/klipy.service';
|
||||
import { MessagesActions } from '../../../../store/messages/messages.actions';
|
||||
import {
|
||||
selectAllMessages,
|
||||
@@ -29,10 +29,11 @@ import {
|
||||
ChatMessageComposerSubmitEvent,
|
||||
ChatMessageDeleteEvent,
|
||||
ChatMessageEditEvent,
|
||||
ChatMessageEmbedRemoveEvent,
|
||||
ChatMessageImageContextMenuEvent,
|
||||
ChatMessageReactionEvent,
|
||||
ChatMessageReplyEvent
|
||||
} from './models/chat-messages.models';
|
||||
} from './models/chat-messages.model';
|
||||
|
||||
@Component({
|
||||
selector: 'app-chat-messages',
|
||||
@@ -191,6 +192,15 @@ export class ChatMessagesComponent {
|
||||
this.composerBottomPadding.set(height + 20);
|
||||
}
|
||||
|
||||
handleEmbedRemoved(event: ChatMessageEmbedRemoveEvent): void {
|
||||
this.store.dispatch(
|
||||
MessagesActions.removeLinkEmbed({
|
||||
messageId: event.messageId,
|
||||
url: event.url
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
toggleKlipyGifPicker(): void {
|
||||
const nextState = !this.showKlipyGifPicker();
|
||||
|
||||
|
||||
@@ -21,12 +21,12 @@ import {
|
||||
} from '@ng-icons/lucide';
|
||||
import type { ClipboardFilePayload } from '../../../../../../core/platform/electron/electron-api.models';
|
||||
import { ElectronBridgeService } from '../../../../../../core/platform/electron/electron-bridge.service';
|
||||
import { KlipyGif, KlipyService } from '../../../../application/klipy.service';
|
||||
import { KlipyGif, KlipyService } from '../../../../application/services/klipy.service';
|
||||
import { Message } from '../../../../../../shared-kernel';
|
||||
import { ChatImageProxyFallbackDirective } from '../../../chat-image-proxy-fallback.directive';
|
||||
import { TypingIndicatorComponent } from '../../../typing-indicator/typing-indicator.component';
|
||||
import { ChatMarkdownService } from '../../services/chat-markdown.service';
|
||||
import { ChatMessageComposerSubmitEvent } from '../../models/chat-messages.models';
|
||||
import { ChatMessageComposerSubmitEvent } from '../../models/chat-messages.model';
|
||||
|
||||
type LocalFileWithPath = File & {
|
||||
path?: string;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user