import type { MediaAttributes } from 'sdp-transform'; import type TypedEmitter from 'typed-emitter'; import type { LoggerOptions } from './types'; interface TrackBitrateInfo { cid?: string; transceiver?: RTCRtpTransceiver; codec: string; maxbr: number; isScreenShare?: boolean; } export declare const PCEvents: { readonly NegotiationStarted: "negotiationStarted"; readonly NegotiationComplete: "negotiationComplete"; readonly OfferAnswered: "offerAnswered"; readonly RTPVideoPayloadTypes: "rtpVideoPayloadTypes"; }; export interface PCTransportOptions { singlePeerConnection?: boolean; } declare const PCTransport_base: new () => TypedEmitter; export default class PCTransport extends PCTransport_base { private _pc; private get pc(); private config?; private log; private iceLog; private loggerOptions; private ddExtID; latestOfferId: number; private answeredOfferId; /** offerId (0 if unnumbered) of the answer being applied right now */ private answerInFlight; latestAcknowledgedOfferId: number; private offerLock; private pendingInitialOffer?; private readonly offeredAudioNackMids; pendingCandidates: RTCIceCandidateInit[]; restartingIce: boolean; renegotiate: boolean; trackBitrates: TrackBitrateInfo[]; /** * Whether an offer carrying the connection-level `x-google-start-bitrate` has been * accepted locally. The hint is written once per peer connection: libwebrtc retains * `start_bitrate_bps` in `RtpBitrateConfigurator` and re-applies it on network route * changes, so a later rewrite is at best a no-op and at worst restarts a converged * bandwidth estimator. A new peer connection (full reconnect) seeds a new estimator. */ private hasAppliedVideoStartBitrate; /** * How long this peer connection took to set up, in ms, recorded once the initial connect * succeeds. Lowers the start bitrate hint for a slow connection; see `computeStartBitrateCap`. */ private connectionSetupTimeMs?; /** * When the connection attempt that built this peer connection began (`performance.now()`). * Until `connectionSetupTimeMs` is known, the time elapsed since then is used as a lower bound * on the setup time, so a video published during connect is still seeded from it rather than * waiting for the connection, which would delay the offer. */ private connectionStartedAt?; remoteStereoMids: string[]; remoteNackMids: string[]; onOffer?: (offer: RTCSessionDescriptionInit, offerId: number) => void; onIceCandidate?: (candidate: RTCIceCandidate) => void; onIceCandidateError?: (ev: Event) => void; onConnectionStateChange?: (state: RTCPeerConnectionState) => void; onIceConnectionStateChange?: (state: RTCIceConnectionState) => void; onSignalingStatechange?: (state: RTCSignalingState) => void; onDataChannel?: (ev: RTCDataChannelEvent) => void; onTrack?: (ev: RTCTrackEvent) => void; constructor(config?: RTCConfiguration, loggerOptions?: LoggerOptions, options?: PCTransportOptions); private createPC; private get logContext(); get isICEConnected(): boolean; addIceCandidate(candidate: RTCIceCandidateInit): Promise; /** Whether an answer for `offerId` answers an offer older than the latest one sent. */ isStaleAnswer(offerId: number): boolean; setRemoteDescription(sd: RTCSessionDescriptionInit, offerId: number): Promise; private applyRemoteDescription; negotiate: import("./debounce").DebouncedFunction void) => Promise>; createInitialOffer(): Promise<{ offer: RTCSessionDescriptionInit; offerId: number; } | undefined>; createAndSendOffer(options?: RTCOfferOptions): Promise; createAndSetAnswer(): Promise; /** * Returns the mids of transceivers that carry no outgoing track on this * (publisher) connection: the pre-populated placeholders added by * `RTCEngine.applyInitialPublisherLayout`, plus any transceiver that was used * for a track and reverted on unpublish (below server protocol 19; from protocol * 19 unpublish stops it). Their codec fmtp is conformed to the published tracks * so a shared payload type stays consistent across the bundle. */ private getPlaceholderMids; createDataChannel(label: string, dataChannelDict: RTCDataChannelInit): RTCDataChannel; addTransceiver(mediaStreamTrack: MediaStreamTrack, transceiverInit: RTCRtpTransceiverInit): RTCRtpTransceiver; addTransceiverOfKind(kind: 'audio' | 'video', transceiverInit: RTCRtpTransceiverInit): RTCRtpTransceiver; addTrack(track: MediaStreamTrack): RTCRtpSender; setTrackCodecBitrate(info: TrackBitrateInfo): void; /** * Record how long this peer connection took to set up. Called once, when the initial connect * succeeds; resumes and ICE restarts keep the estimator they have and never call this. */ setConnectionSetupTime(ms: number): void; /** Record when the connection attempt that built this peer connection began. */ setConnectionStartedAt(startedAt: number): void; /** The measured setup time, or while still connecting, the time elapsed so far. */ private connectionSetupTimeEstimateMs; setConfiguration(rtcConfig: RTCConfiguration): void; canRemoveTrack(): boolean; /** * Removes `sender` from the connection. With `stop`, it then stops the transceiver of `sender`. */ removeTrack(sender: RTCRtpSender, stop?: boolean): void; /** * Stops the transceivers of `senders`. `removeTrack` keeps the transceiver and its encoder, * and each publish adds a new transceiver. A transceiver that is not stopped stays until the * connection closes. Call this after `removeTrack`, as `removeTrack(sender, true)` does. * Returns true if a transceiver stopped. * * The last live transceiver of each kind stays. The server cannot follow two changes that some * browsers make after all transceivers of a kind stop. The browser drops the ICE and DTLS * transport when all m-sections are rejected. Some browsers also give the next transceiver new * header extension ids. */ stopTransceivers(senders: RTCRtpSender[]): boolean; getConnectionState(): RTCPeerConnectionState; getICEConnectionState(): RTCIceConnectionState; getSignallingState(): RTCSignalingState; getTransceivers(): RTCRtpTransceiver[]; getSenders(): RTCRtpSender[]; getLocalDescription(): RTCSessionDescription | null | undefined; getRemoteDescription(): RTCSessionDescription | null; /** stats of the underlying connection, `undefined` when there is none */ getStats(): Promise | undefined; getMaxMessageSize(): number | undefined; getConnectedAddress(): Promise; close: () => void; private setMungedSDP; } export declare function extractStereoAndNackAudioFromOffer(offer: RTCSessionDescriptionInit): { stereoMids: string[]; nackMids: string[]; }; type PCTransportEventCallbacks = { negotiationStarted: () => void; negotiationComplete: () => void; offerAnswered: (offerId: number) => void; rtpVideoPayloadTypes: (attributes: MediaAttributes['rtp']) => void; }; export {};