diff --git a/frontend-web-vanilla/src/PeerConnection.ts b/frontend-web-vanilla/src/PeerConnection.ts index 011e6e3..02c5321 100644 --- a/frontend-web-vanilla/src/PeerConnection.ts +++ b/frontend-web-vanilla/src/PeerConnection.ts @@ -1,5 +1,5 @@ import {Subject, ReadOnlySubject, Disposable, DisposableList, EventPublisher, type IEvent, type IDisposable} from '@techniker-me/tools'; -import type { IPeerConnectionOperations } from './interfaces/IPeerConnectionOperations'; +import type {IPeerConnectionOperations} from './interfaces/IPeerConnectionOperations'; export default class PeerConnection implements IPeerConnectionOperations { private readonly _disposables: DisposableList = new DisposableList(); diff --git a/frontend-web-vanilla/src/User.ts b/frontend-web-vanilla/src/User.ts index 2a73012..d3e07b9 100644 --- a/frontend-web-vanilla/src/User.ts +++ b/frontend-web-vanilla/src/User.ts @@ -1,19 +1,24 @@ import type {ILogger} from '@techniker-me/logger'; import {LoggerFactory} from '@techniker-me/logger'; import {ReadOnlySubject, Subject, type IEvent} from '@techniker-me/tools'; -import PeerConnection from './PeerConnection'; +import type { IPeerConnectionOperations } from './interfaces/IPeerConnectionOperations'; import type { ISignalingClient } from './interfaces/ISignalingClient'; +/** + * User class - manages local and remote media streams + * Follows Single Responsibility Principle - only handles media stream management + * Follows Dependency Inversion Principle - depends on abstractions (interfaces) + */ export default class User { private readonly _logger: ILogger = LoggerFactory.getLogger('User'); private readonly _localVideoElement: HTMLVideoElement; private readonly _remoteVideoElement: HTMLVideoElement; - private readonly _peerConnection: PeerConnection; + private readonly _peerConnection: IPeerConnectionOperations; private readonly _signalingClient: ISignalingClient; private readonly _mediaStream: Subject = new Subject(null); private readonly _readOnlyMediaStream: ReadOnlySubject = new ReadOnlySubject(this._mediaStream); - constructor(localVideoElement: HTMLVideoElement, remoteVideoElement: HTMLVideoElement, peerConnection: PeerConnection, signalingClient: ISignalingClient) { + constructor(localVideoElement: HTMLVideoElement, remoteVideoElement: HTMLVideoElement, peerConnection: IPeerConnectionOperations, signalingClient: ISignalingClient) { this._localVideoElement = localVideoElement; this._remoteVideoElement = remoteVideoElement; this._peerConnection = peerConnection; @@ -25,7 +30,7 @@ export default class User { return this._localVideoElement; } - get peerConnection(): PeerConnection { + get peerConnection(): IPeerConnectionOperations { return this._peerConnection; } diff --git a/frontend-web-vanilla/src/interfaces/IPeerConnectionOperations.ts b/frontend-web-vanilla/src/interfaces/IPeerConnectionOperations.ts index f7091b8..9f28860 100644 --- a/frontend-web-vanilla/src/interfaces/IPeerConnectionOperations.ts +++ b/frontend-web-vanilla/src/interfaces/IPeerConnectionOperations.ts @@ -1,6 +1,9 @@ +import type { IEvent, IDisposable } from '@techniker-me/tools'; + /** * Interface for peer connection operations * Follows Interface Segregation Principle - focused interface for WebRTC operations + * Follows Dependency Inversion Principle - abstracts peer connection capabilities */ export interface IPeerConnectionOperations { /** @@ -27,5 +30,18 @@ export interface IPeerConnectionOperations { * Get the current signaling state */ getSignalingState(): RTCSignalingState; + + /** + * Add a media stream to the peer connection + */ + addMediaStream(mediaStream: MediaStream): void; + + /** + * Subscribe to peer connection events + * @param event Event name (e.g., 'icecandidate', 'track') + * @param callback Event handler function + * @returns Disposable to unsubscribe from the event + */ + on(event: string, callback: (event: IEvent) => void | Promise): IDisposable; }