import Event from "rx.mini" ; import * as uuid from "uuid" ; import { SenderDirections } from "../const" ; import { RTCDtlsTransport } from "../transport/dtls" ; import { Kind } from "../types/domain" ; import { RTCRtpCodecParameters , RTCRtpHeaderExtensionParameters , } from "./parameters" ; import { RTCRtpReceiver } from "./rtpReceiver" ; import { RTCRtpSender } from "./rtpSender" ; import { MediaStreamTrack } from "./track" ; export class RTCRtpTransceiver { readonly uuid = uuid . v4 ( ) ; readonly onTrack = new Event < [ MediaStreamTrack ] > ( ) ; mid ? : string ; mLineIndex ? : number ; usedForSender = false ; private _currentDirection ? : Direction | "stopped" ; set currentDirection ( direction ) { this . _currentDirection = direction ; if ( SenderDirections . includes ( this . _currentDirection || "" ) ) { this . usedForSender = true ; } } /**RFC 8829 4.2.5. last negotiated direction */ get currentDirection ( ) : Direction | "stopped" | undefined { return this . _currentDirection ; } offerDirection ! : Direction ; codecs : RTCRtpCodecParameters [ ] = [ ] ; headerExtensions : RTCRtpHeaderExtensionParameters [ ] = [ ] ; options : Partial < TransceiverOptions > = { } ; stopping = false ; stopped = false ; constructor ( public readonly kind , public readonly receiver , public readonly sender , /**RFC 8829 4.2.4.  direction the transceiver was initialized with */ public direction , public dtlsTransport ) { } get msid ( ) { return `${ this . sender . streamId } ${ this . sender . trackId }` ; } addTrack ( track ) { const res = this . receiver . addTrack ( track ) ; if ( res ) this . onTrack . execute ( track ) ; } stop ( ) { if ( this . stopping ) return ; this . stopping = true ; } getPayloadType ( mimeType ) { return this . codecs . find ( ( codec ) => codec . mimeType . toLowerCase ( ) . includes ( mimeType . toLowerCase ( ) ) ) ?. payloadType ; } } export const Directions = [ "inactive" , "sendonly" , "recvonly" , "sendrecv" , ] as const ; export type Direction = typeof Directions [ number ] ; type SimulcastDirection = "send" | "recv" ; export interface TransceiverOptions { direction : Direction ; simulcast : { direction : SimulcastDirection ; rid : string ; } [ ] ; }