mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-10 10:53:24 +00:00
Split the monolithic peer.ts file into a modular state-based architecture: - Created separate files for each state class (idle, creating-offer, waiting-for-answer, answering, exchanging-ice, connected, failed, closed) - Extracted shared types into types.ts - Extracted base PeerState class into state.ts - Updated peer/index.ts to import state classes instead of defining them inline - Made close() method async to support dynamic imports and avoid circular dependencies - Used dynamic imports in state transitions to prevent circular dependency issues This improves code organization, maintainability, and makes each state's logic easier to understand and test. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
19 lines
707 B
TypeScript
19 lines
707 B
TypeScript
import { PeerState } from './state.js';
|
|
import type { PeerOptions } from './types.js';
|
|
|
|
export class IdleState extends PeerState {
|
|
get name() { return 'idle'; }
|
|
|
|
async createOffer(options: PeerOptions): Promise<string> {
|
|
const { CreatingOfferState } = await import('./creating-offer-state.js');
|
|
this.peer.setState(new CreatingOfferState(this.peer, options));
|
|
return this.peer.state.createOffer(options);
|
|
}
|
|
|
|
async answer(offerId: string, offerSdp: string, options: PeerOptions): Promise<void> {
|
|
const { AnsweringState } = await import('./answering-state.js');
|
|
this.peer.setState(new AnsweringState(this.peer));
|
|
return this.peer.state.answer(offerId, offerSdp, options);
|
|
}
|
|
}
|