|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is `@jitsi/js-utils`, a collection of utility libraries for Jitsi JavaScript projects. The package is published to npm and provides shared functionality across the Jitsi ecosystem. This is a JavaScript/TypeScript hybrid project that exports ES6 modules. |
| 8 | + |
| 9 | +## Development Commands |
| 10 | + |
| 11 | +### Build and Type Generation |
| 12 | +- `npm run build` - Compile TypeScript files using tsc |
| 13 | +- `npm run gen-types` - Generate TypeScript declaration files in the `types/` directory |
| 14 | +- `npm run prepack` - Runs both build and gen-types (automatically runs before publishing) |
| 15 | + |
| 16 | +### Linting |
| 17 | +- `npm run lint` - Run ESLint using @jitsi/eslint-config |
| 18 | +- Always run linting before committing changes |
| 19 | + |
| 20 | +## Code Architecture |
| 21 | + |
| 22 | +### Module Structure |
| 23 | +The codebase is organized as a collection of independent utility modules, each in its own directory: |
| 24 | + |
| 25 | +- **avatar/** - Avatar generation utilities |
| 26 | +- **browser-detection/** - Browser and environment detection using ua-parser-js |
| 27 | + - Uses TypeScript with `BrowserDetection` class |
| 28 | + - Maps various browser names to Jitsi-specific naming conventions |
| 29 | + - Detects React Native, Electron, Chromium-based browsers, engines (Blink, Gecko, WebKit) |
| 30 | + |
| 31 | +- **jitsi-local-storage/** - LocalStorage wrapper with fallback |
| 32 | + - Provides `JitsiLocalStorage` class extending EventEmitter |
| 33 | + - Falls back to `DummyLocalStorage` (in-memory) when localStorage is unavailable |
| 34 | + - Emits 'changed' events on modifications |
| 35 | + - Supports serialization with optional key exclusion |
| 36 | + |
| 37 | +- **json.ts** - Safe JSON parsing using @hapi/bourne |
| 38 | + |
| 39 | +- **polyfills/** - Browser polyfills (currently querySelector-related) |
| 40 | + |
| 41 | +- **random/** - Random utility functions |
| 42 | + - `roomNameGenerator.js` - Generate random room names |
| 43 | + - `randomUtil.js` - General random utilities |
| 44 | + |
| 45 | +- **transport/** - Message transport abstraction with request/response pattern |
| 46 | + - `Transport.js` - Main transport class with event emitter pattern |
| 47 | + - Handles MESSAGE_TYPE_EVENT, MESSAGE_TYPE_REQUEST, MESSAGE_TYPE_RESPONSE |
| 48 | + - Implements pluggable backends via `setBackend()` |
| 49 | + - `PostMessageTransportBackend.js` - postMessage-based backend |
| 50 | + - `postis.js` - Third-party postMessage utility (used by PostMessageTransportBackend) |
| 51 | + |
| 52 | +- **uri/** - URI manipulation utilities |
| 53 | + |
| 54 | +### Entry Point |
| 55 | +The main `index.js` re-exports all module functionality: |
| 56 | + |
| 57 | +### TypeScript Configuration |
| 58 | +- Target: ES6 modules |
| 59 | +- Strict mode enabled |
| 60 | +- Declaration files generated in `types/` directory |
| 61 | +- Only compiles specific TypeScript files (browser-detection, json.ts, polyfills) |
| 62 | +- Most of the codebase remains in JavaScript |
| 63 | + |
| 64 | +### Package Publishing |
| 65 | +- Published as `@jitsi/js-utils` to npm with public access |
| 66 | +- Main entry: `index.js` |
| 67 | +- Type: ES module |
| 68 | +- The `files` field in package.json controls what gets published |
| 69 | +- AutoPublish workflow triggers on master branch pushes |
| 70 | +- Version bumping handled automatically by gh-action-bump-version |
| 71 | + |
| 72 | +## Key Dependencies |
| 73 | +- `@hapi/bourne` - Safe JSON parsing (prevents prototype pollution) |
| 74 | +- `js-md5` - MD5 hashing |
| 75 | +- `ua-parser-js` - User agent parsing for browser detection |
| 76 | + |
| 77 | +## Coding Conventions |
| 78 | +- Uses @jitsi/eslint-config with @babel/eslint-parser |
| 79 | +- JSDoc comments for all public APIs |
| 80 | +- Private members prefixed with underscore (_) |
| 81 | +- Event emitter pattern used for reactive components (JitsiLocalStorage, Transport) |
| 82 | + |
| 83 | +## TypeScript Migration |
| 84 | +The project is gradually migrating from JavaScript to TypeScript. When adding features: |
| 85 | +- New utilities should be written in TypeScript when possible |
| 86 | +- When modifying existing JavaScript files, consider converting to TypeScript if it makes sense |
| 87 | +- Update tsconfig.json `include` array when adding new TypeScript files |
| 88 | +- Run `npm run build` and `npm run gen-types` to ensure type generation works |
| 89 | + |
| 90 | +## Testing and CI |
| 91 | +- CI runs on pull requests via GitHub Actions |
| 92 | +- Linting is enforced in CI (no test suite currently defined) |
0 commit comments