# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Infobip RTC is a JavaScript/TypeScript SDK for Infobip's WebRTC platform, enabling real-time communications in web applications. The SDK supports:
- WebRTC user-to-user calls (audio/video)
- Phone calls (WebRTC to PSTN)
- Viber calls
- Room calls (multi-participant)
- Application calls (server-side integration)

## Development Commands

### Building
- `npm run build` - Full build (generates version + transpiles TypeScript)
- `npm run transpile` - TypeScript compilation only
- `npm run gver` - Generate version info into src/Version.ts

### Testing
- `npm run test:unit` - Run unit tests with Mocha
- `npm run test:e2e` - Run end-to-end tests with Nightwatch (retries 3x)
- `npm test` - Run both unit and e2e tests

### Webpack Bundling
- `npm run webpack:dev` - Development bundle
- `npm run webpack:prod` - Production bundle

### Cleaning
- `npm run clean:dist` - Remove dist directory
- `npm run clean:modules` - Remove node_modules
- `npm run clean` - Clean both dist and node_modules

## Architecture

### Core Structure
- **src/InfobipRTC.ts** - Main SDK interface and factory
- **src/DefaultInfobipRTC.ts** - Default implementation
- **src/index.ts** - Public API exports

### Call Types
The SDK supports five main call types, each with its own class and options:
- **WebrtcCall** (`src/call/WebrtcCall.ts`) - Direct WebRTC user-to-user calls
- **PhoneCall** (`src/call/PhoneCall.ts`) - Calls to phone numbers via PSTN
- **ViberCall** (`src/call/ViberCall.ts`) - Calls via Viber messaging
- **RoomCall** (`src/call/RoomCall.ts`) - Multi-participant room calls
- **ApplicationCall** (`src/call/ApplicationCall.ts`) - Server-side application calls

### Key Directories
- **src/call/** - Call implementations, events, options, and utilities
  - `event/` - Call event definitions and handlers
  - `options/` - Call configuration options for each call type
  - `impl/` - Internal call implementation details
  - `stats/` - Call statistics and monitoring
  - `ws/` - WebSocket event handling
- **src/device/** - Media device management
- **src/log/** - Logging and monitoring infrastructure
- **src/util/** - Shared utilities and helpers

### Media and Filtering
- **Audio/Video Filters** - `src/call/options/filters/` contains audio and video filtering capabilities
- **Capturers** - `src/call/*Capturer.ts` files handle local and server-side media capture
- **Device Management** - `src/RTCMediaDevice.ts` and `src/device/` manage audio/video input/output devices

### Configuration
- **TypeScript**: Targets ES2021, outputs to `dist/` with declarations
- **Testing**:
  - Unit tests in `test/unit/` using Mocha with ts-node
  - E2E tests in `test/e2e/` using Nightwatch with Chrome
- **Build**: Uses TypeScript compiler + Webpack for bundling
- **Version**: Auto-generated via genversion into `src/Version.ts`

## Testing Patterns

### Unit Tests
- Located in `test/unit/**/*.test.ts`
- Run with `npm run test:unit`
- Use Mocha with TypeScript support via ts-node

### End-to-End Tests
- Located in `test/e2e/`
- Run with `npm run test:e2e`
- Use Nightwatch.js with headless Chrome
- Configured with 3 automatic retries

## Key Dependencies

### Runtime Dependencies
- **webrtc-adapter** - WebRTC browser compatibility
- **jwt-decode** - JWT token handling
- **bowser** - Browser detection
- **lodash** - Utility functions
- **loglevel** - Logging infrastructure

### Development Dependencies
- **TypeScript 4.9.5** - Language and compiler
- **Webpack 5.x** - Module bundling
- **Mocha 10.x** - Unit testing framework
- **Nightwatch 3.x** - E2E testing framework
- **genversion** - Automatic version generation

## Call Flow Architecture

The SDK follows a factory pattern:
1. Create InfobipRTC instance with `createInfobipRtc(token, options)`
2. Connect to platform with `connect()`
3. Make calls using appropriate method (`callWebrtc`, `callPhone`, etc.)
4. Handle call events via event handlers
5. Manage media devices through device management APIs

Each call type has specific options classes and event handlers, allowing for type-safe configuration and event handling throughout the call lifecycle.