working poc
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import {Subject, ReadOnlySubject, Disposable, DisposableList, EventPublisher, type IEvent, type IDisposable} from '@techniker-me/tools';
|
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 {
|
export default class PeerConnection implements IPeerConnectionOperations {
|
||||||
private readonly _disposables: DisposableList = new DisposableList();
|
private readonly _disposables: DisposableList = new DisposableList();
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
import type {ILogger} from '@techniker-me/logger';
|
import type {ILogger} from '@techniker-me/logger';
|
||||||
import {LoggerFactory} from '@techniker-me/logger';
|
import {LoggerFactory} from '@techniker-me/logger';
|
||||||
import {ReadOnlySubject, Subject, type IEvent} from '@techniker-me/tools';
|
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';
|
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 {
|
export default class User {
|
||||||
private readonly _logger: ILogger = LoggerFactory.getLogger('User');
|
private readonly _logger: ILogger = LoggerFactory.getLogger('User');
|
||||||
private readonly _localVideoElement: HTMLVideoElement;
|
private readonly _localVideoElement: HTMLVideoElement;
|
||||||
private readonly _remoteVideoElement: HTMLVideoElement;
|
private readonly _remoteVideoElement: HTMLVideoElement;
|
||||||
private readonly _peerConnection: PeerConnection;
|
private readonly _peerConnection: IPeerConnectionOperations;
|
||||||
private readonly _signalingClient: ISignalingClient;
|
private readonly _signalingClient: ISignalingClient;
|
||||||
private readonly _mediaStream: Subject<MediaStream | null> = new Subject(null);
|
private readonly _mediaStream: Subject<MediaStream | null> = new Subject(null);
|
||||||
private readonly _readOnlyMediaStream: ReadOnlySubject<MediaStream | null> = new ReadOnlySubject(this._mediaStream);
|
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._localVideoElement = localVideoElement;
|
||||||
this._remoteVideoElement = remoteVideoElement;
|
this._remoteVideoElement = remoteVideoElement;
|
||||||
this._peerConnection = peerConnection;
|
this._peerConnection = peerConnection;
|
||||||
@@ -25,7 +30,7 @@ export default class User {
|
|||||||
return this._localVideoElement;
|
return this._localVideoElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
get peerConnection(): PeerConnection {
|
get peerConnection(): IPeerConnectionOperations {
|
||||||
return this._peerConnection;
|
return this._peerConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
import type { IEvent, IDisposable } from '@techniker-me/tools';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for peer connection operations
|
* Interface for peer connection operations
|
||||||
* Follows Interface Segregation Principle - focused interface for WebRTC operations
|
* Follows Interface Segregation Principle - focused interface for WebRTC operations
|
||||||
|
* Follows Dependency Inversion Principle - abstracts peer connection capabilities
|
||||||
*/
|
*/
|
||||||
export interface IPeerConnectionOperations {
|
export interface IPeerConnectionOperations {
|
||||||
/**
|
/**
|
||||||
@@ -27,5 +30,18 @@ export interface IPeerConnectionOperations {
|
|||||||
* Get the current signaling state
|
* Get the current signaling state
|
||||||
*/
|
*/
|
||||||
getSignalingState(): RTCSignalingState;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user