UNPKG

@phenixrts/sdk

Version:
116 lines (115 loc) 5.48 kB
import ReadOnlySubject from '../../rx/ReadOnlySubject'; import Dimension from '../../video/Dimension'; import EndPoint, { IStream } from '../discovery/EndPoint'; import { IOnRealTimeSubscribeRequestCallback } from './IOnRealTimeSubscribeRequestCallback'; import { IOnRealTimeSubscribeResponseCallback } from './IOnRealTimeSubscribeResponseCallback'; import IPeerConnection from '../../rtc/IPeerConnection'; import { IChannel } from './IChannel'; import ChannelState from './ChannelState'; import { IRtcMonitorStatistic } from '../../rtc/RtcConnectionMonitor'; import { EncodedEdgeToken } from '../../edgeAuth/EncodedEdgeToken'; import { BitsPerSecond, Millisecond } from '../../units/Units'; import { IEncodedStreamSink } from '../transformation/EncodedStreamSink'; import { IStreamTrackTransform } from '../transformation/StreamTrackTransform'; import { DecodedFrameTimingInformation, RenderedFrameTimingInformation } from '../frameTiming/FrameTimingInformation'; export type ChannelOptions = { targetLag?: Millisecond; videoStreamTransformCallback?: IStreamTrackTransform<VideoFrame>; audioStreamTransformCallback?: IStreamTrackTransform<AudioData>; encodedVideoStreamSink?: IEncodedStreamSink<RTCEncodedVideoFrame>; encodedAudioStreamSink?: IEncodedStreamSink<RTCEncodedAudioFrame>; onRealTimeSubscribeRequestCallback?: IOnRealTimeSubscribeRequestCallback; onRealTimeSubscribeResponseCallback?: IOnRealTimeSubscribeResponseCallback; }; export default class Channel implements IChannel { private readonly _logger; private readonly _tokenContext; private readonly _channelContext; private readonly _peerConnectionContext; private readonly _streamTransformContext; private readonly _stateContext; private readonly _frameTimingInformationContext; private readonly _exponentialBackoff; private readonly _channelStartTime; private readonly _readOnlyPeerConnection; private readonly _readOnlyState; private readonly _readOnlyExists; private readonly _readOnlyAutoMuted; private readonly _readOnlyAutoPaused; private readonly _readOnlyTokenExpiring; private readonly _readOnlyAuthorized; private readonly _readOnlyOnline; private readonly _readOnlyLoading; private readonly _readOnlyPlaying; private readonly _readOnlyStandby; private readonly _readOnlyStopped; private readonly _readOnlyTargetLag; private readonly _readOnlyLag; private readonly _readOnlyBitrateLimit; private readonly _readOnlyResolution; private readonly _readOnlyFailureCount; private readonly _readOnlyEndPoint; private readonly _readOnlyStream; private readonly _readOnlyRtcStatistics; private readonly _readOnlyMediaStream; private readonly _readOnlyIsFrameTimingInformationEnabled; private readonly _readOnlyDecodedFrameTimingInformation; private readonly _readOnlyRenderedFrameTimingInformation; private _metricsService; private _streamSubscriber; private readonly _sessionTelemetry; private readonly _videoMetaDataChangedHandler; constructor(videoElement: HTMLVideoElement, token: EncodedEdgeToken, options?: ChannelOptions); get videoElement(): HTMLVideoElement | null; set videoElement(videoElement: HTMLVideoElement); private handleVideoMetaDataChanged; get token(): EncodedEdgeToken; set token(token: EncodedEdgeToken); get peerConnection(): ReadOnlySubject<IPeerConnection | null>; get state(): ReadOnlySubject<ChannelState>; get exists(): ReadOnlySubject<boolean | null>; get autoMuted(): ReadOnlySubject<boolean>; get autoPaused(): ReadOnlySubject<boolean>; get tokenExpiring(): ReadOnlySubject<boolean>; get authorized(): ReadOnlySubject<boolean>; get online(): ReadOnlySubject<boolean>; get loading(): ReadOnlySubject<boolean>; get playing(): ReadOnlySubject<boolean>; get standby(): ReadOnlySubject<boolean>; get stopped(): ReadOnlySubject<boolean>; get targetLag(): ReadOnlySubject<Millisecond>; get lag(): ReadOnlySubject<Millisecond | undefined>; get bitrateLimit(): BitsPerSecond; get resolution(): ReadOnlySubject<Dimension>; get failureCount(): ReadOnlySubject<number>; get endPoint(): ReadOnlySubject<EndPoint | null>; get stream(): ReadOnlySubject<IStream | null>; get streamId(): string; get rtcStatistics(): ReadOnlySubject<IRtcMonitorStatistic | null>; get mediaStream(): ReadOnlySubject<MediaStream | null>; get isFrameTimingInformationEnabled(): ReadOnlySubject<boolean>; get decodedFrameTimingInformation(): ReadOnlySubject<DecodedFrameTimingInformation | null>; get renderedFrameTimingInformation(): ReadOnlySubject<RenderedFrameTimingInformation | null>; setBitrateLimit(bitrateLimit: BitsPerSecond): void; clearBitrateLimit(): void; updateTargetLag(lag: Millisecond): void; stop(reason: string): Promise<void>; private processStop; resume(): Promise<void>; mute(): void; unmute(): void; dispose(): Promise<void>; getUri(token: EncodedEdgeToken): URL; start(): Promise<void>; private isRetryableState; private isSubscriberHealthy; private restartOnForeground; private processStart; private restartAfterStop; play(): Promise<void>; private getRetryInterval; private handleStreamFailure; private cleanUpResources; private configureFrameTimingInformation; private playMediaStreamInVideoElement; }