working poc

This commit is contained in:
2025-11-28 14:33:24 -05:00
parent 0494115007
commit f9396cb6a3
3 changed files with 26 additions and 5 deletions

View File

@@ -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<MediaStream | null> = new Subject(null);
private readonly _readOnlyMediaStream: ReadOnlySubject<MediaStream | null> = 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;
}

View File

@@ -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<T>(event: string, callback: (event: IEvent<T>) => void | Promise<void>): IDisposable;
}