import { AgoraRTCPlayer, VideoPlayer, LocalTrack, LocalDataChannel, RemoteDataChannel, LocalVideoTrackStats, AgoraRTCStats } from '@agora-js/media'; import { TurnServerConfigWithMode, CloudProxyServerMode, SDKStore, SDK_CODEC, SDK_AUDIO_CODEC, AgoraPCStats, UID, Candidate, Setup, EventEmitter, CandidateStats, FingerPrint, PromiseMutex } from '@agora-js/shared'; import { RTPCapabilitiesBeforeMerge, RTPCapabilitiesWithDirection } from '@agora-js/protocol'; interface PeerConnectionSpec { iceServers?: RTCIceServer[]; turnServer?: TurnServerConfigWithMode; enableEncodedTransform?: boolean; isPreallocation?: boolean; cloudProxyServer?: CloudProxyServerMode; } interface RemoteConfig { tcc?: boolean; remb?: boolean; twcc?: boolean; } type Transmission = WebSocket | RTCDataChannel; interface TransmissonInfo { transmitter: Transmission; close: () => void; } declare abstract class P2PConnectionBaseImpl extends EventEmitter { onICEConnectionStateChange?: (ICEConnectionState: RTCIceConnectionState) => void; onConnectionStateChange?: (connectionState: RTCPeerConnectionState) => void; onDTLSTransportStateChange?: (state: RTCDtlsTransportState) => void; onDTLSTransportError?: (error: any) => void; onICETransportStateChange?: (state: RTCIceTransportState) => void; onFirstAudioReceived?: (ssrcId: number) => void; onFirstVideoReceived?: (ssrcId: number) => void; onFirstAudioDecoded?: (ssrcId: number) => void; onFirstVideoDecoded?: (ssrcId: number, width: number, height: number) => void; onFirstVideoRender?: (ssrcId: number) => void; onFirstVideoBufferReady?: (ssrcId: number) => void; onFirstVideoDecodedTimeout?: (ssrcId: number) => void; onSelectedLocalCandidateChanged?: (cur: CandidateStats, prev: CandidateStats) => void; onSelectedRemoteCandidateChanged?: (cur: CandidateStats, prev: CandidateStats) => void; onICECandidateError?: (errMsg: string) => void; getLocalVideoStats?: () => LocalVideoTrackStats & AgoraRTCStats; constructor(spec: PeerConnectionSpec, store: SDKStore); abstract get currentLocalDescription(): RTCSessionDescription | null; abstract get currentRemoteDescription(): RTCSessionDescription | null; abstract get peerConnectionState(): RTCPeerConnectionState; abstract get iceConnectionState(): RTCIceConnectionState; abstract get localCodecs(): SDK_CODEC[]; } declare abstract class P2PConnectionImpl extends P2PConnectionBaseImpl { abstract establishPromise: Promise; constructor(spec: PeerConnectionSpec, store: SDKStore); abstract establish(): Promise; abstract connect(connectParams: ConnectionParams): Promise; abstract updateRemoteConnect(connectParams: ConnectionParams): Promise; abstract updateRemoteRTPCapabilities(mids: string[], codecs: SDK_CODEC[]): Promise; abstract getPreMedia(ssrcId: number): { mid: string; track: MediaStreamTrack; transceiver: RTCRtpTransceiver; player: AgoraRTCPlayer | VideoPlayer | undefined; firstVideoRender?: number; audioTrackId?: string; } | undefined; abstract send(tracks: LocalTrack[], codec: SDK_CODEC, audioCodec: SDK_AUDIO_CODEC): AsyncGenerator; abstract stopSending(mids: string[]): Promise; abstract receive(kind: Kind, ssrcMsg: SSRCMessage, mslabel: string, remoteConfig: RemoteConfig | undefined): Promise<{ track: MediaStreamTrack; id: string; transceiver?: RTCRtpTransceiver; }>; abstract batchReceive(list: { kind: Kind; ssrcMsg: SSRCMessage; mslabel: string; }[]): Promise<{ track: MediaStreamTrack; id: string; transceiver?: RTCRtpTransceiver; }[]>; abstract stopReceiving(mids: string[]): Promise; abstract muteRemote(mid: string): Promise; abstract unmuteRemote(mid: string): Promise; abstract muteLocal(mids: string[]): Promise; abstract unmuteLocal(ids: string[]): Promise; abstract restartICE(type?: ICERestartType): AsyncGenerator; abstract close(): void; abstract getStats(): AgoraPCStats; abstract getRemoteVideoIsReady(ssrcId: number): boolean; abstract updateEncoderConfig(mid: string, track: LocalTrack): Promise; abstract updateSendParameters(mid: string, track: LocalTrack): Promise; abstract setStatsRemoteVideoIsReady(ssrcId: number, isReady: boolean): void; abstract replaceTrack(track: LocalTrack, id: string): Promise; abstract getRemoteSSRC(mid: string): Promise; abstract createDataChannels(uid: UID, dataChannels: LocalDataChannel[] | RemoteDataChannel[]): Promise; abstract stopDataChannels(uid: UID): Promise; abstract setConfiguration(spec: PeerConnectionSpec): void; } interface ICEParameters { iceUfrag: string; icePwd: string; } interface DtlsParameters { fingerprints: FingerPrint[]; } declare enum Kind { VIDEO = "video", AUDIO = "audio" } declare enum ICERestartType { UDP_RELAY = "udp_relay", UDP_TCP_RELAY = "udp_tcp_relay", TCP_RELAY = "tcp_relay", RELAY = "relay" } type EstablishParams = { iceParameters: ICEParameters; dtlsParameters: DtlsParameters; rtpCapabilities: RTPCapabilitiesBeforeMerge; offerSDP?: string; }; type ConnectionParams = { iceParameters: ICEParameters; dtlsParameters: DtlsParameters; candidates: Candidate[]; rtpCapabilities: RTPCapabilitiesWithDirection; setup: Setup; cname: string; preallocation?: boolean; preSSRCs?: PreSSRCMessage[]; }; type SSRCMessage = { ssrcId: number; rtx?: number; }[]; type PreSSRCMessage = { kind: Kind; ssrcMsg: SSRCMessage; mslabel: string; }; type TRteServiceName = "ChannelMediaRelay" | "LiveStreaming" | "ImageModeration" | "ContentInspect" | "DataStream" | "P2PChannel" | "PlanBConnection" | "InterceptFrame" | "DataChannelConnection" | "DataChannelSignal"; interface IRteService { name: TRteServiceName; create: (...args: any[]) => T; createSubmodule?: (...args: any[]) => R; } declare class PlanBConnection extends P2PConnectionImpl { private readonly store; private readonly peerConnection; private remoteSDP?; private initialOffer?; private statsFilter; private useRTX; private localCapabilities?; private localCandidateCount; private allCandidatesReceived; readonly establishPromise: Promise; protected mutex: PromiseMutex; get peerConnectionState(): RTCPeerConnectionState; get iceConnectionState(): RTCIceConnectionState; get currentLocalDescription(): RTCSessionDescription | null; get currentRemoteDescription(): RTCSessionDescription | null; get localCodecs(): SDK_CODEC[]; constructor(spec: PeerConnectionSpec, store: SDKStore); establish(): Promise; updateRemoteConnect(): Promise; connect(connectParams: ConnectionParams): Promise; updateRemoteRTPCapabilities(mids: string[], codecs: SDK_CODEC[]): Promise; getPreMedia(ssrcId: number): undefined; send(tracks: LocalTrack[], codec: SDK_CODEC): AsyncGenerator; stopSending(ids: string[]): Promise; receive(kind: Kind, ssrcMsg: SSRCMessage, mslabel: string, remoteConfig?: RemoteConfig): Promise<{ track: MediaStreamTrack; id: string; transceiver?: undefined; }>; stopReceiving(ids: string[]): Promise; muteRemote(mid: string): Promise; unmuteRemote(mid: string): Promise; muteLocal(ids: string[]): Promise; unmuteLocal(ids: string[]): Promise; restartICE(type?: ICERestartType): AsyncGenerator; close(): void; getStats(): AgoraPCStats; getRemoteVideoIsReady(ssrcId: number): boolean; updateEncoderConfig(mid: string, track: LocalTrack): Promise; updateSendParameters(id: string, track: LocalTrack): Promise; setStatsRemoteVideoIsReady(ssrcId: number, isReady: boolean): void; replaceTrack(track: LocalTrack, id: string): Promise; createDataChannels(uid: UID, dataChannels: LocalDataChannel[] | RemoteDataChannel[]): Promise; stopDataChannels(uid: UID): Promise; private bindPCEvents; private unbindPCEvents; private static resolvePCConfiguration; private static turnServerConfigToIceServers; updateRtpSenderEncodings(track: LocalTrack, rtpSender?: RTCRtpSender): Promise; private applySendEncodings; private mungSendOfferSDP; private bindStatsEvents; private unbindStatsEvents; batchReceive(receiveList: { kind: Kind; ssrcMsg: SSRCMessage; mslabel: string; }[]): Promise<{ track: MediaStreamTrack; id: string; }[]>; getRemoteSSRC(id: string): Promise; setConfiguration(spec: PeerConnectionSpec): void; } interface IPlanBConnectionOptions { spec: PeerConnectionSpec; store: SDKStore; } declare const PlanBConnectionService: IRteService; export { type IPlanBConnectionOptions, PlanBConnection, PlanBConnectionService };