Interface RTCPeerConnection
canTrickleIceCandidates: boolean;
connectionState: RTCPeerConnectionState;
currentLocalDescription: RTCSessionDescription;
currentRemoteDescription: RTCSessionDescription;
iceConnectionState: RTCIceConnectionState;
iceGatheringState: RTCIceGatheringState;
localDescription: RTCSessionDescription;
onconnectionstatechange: (this: RTCPeerConnection, ev: Event) => any;
ondatachannel: (this: RTCPeerConnection, ev: RTCDataChannelEvent) => any;
onicecandidate: (
this: RTCPeerConnection,
ev: RTCPeerConnectionIceEvent,
) => any;
onicecandidateerror: (
this: RTCPeerConnection,
ev: RTCPeerConnectionIceErrorEvent,
) => any;
oniceconnectionstatechange: (this: RTCPeerConnection, ev: Event) => any;
onicegatheringstatechange: (this: RTCPeerConnection, ev: Event) => any;
onnegotiationneeded: (this: RTCPeerConnection, ev: Event) => any;
onsignalingstatechange: (this: RTCPeerConnection, ev: Event) => any;
ontrack: (this: RTCPeerConnection, ev: RTCTrackEvent) => any;
pendingLocalDescription: RTCSessionDescription;
pendingRemoteDescription: RTCSessionDescription;
remoteDescription: RTCSessionDescription;
sctp: RTCSctpTransport;
signalingState: RTCSignalingState;
addEventListener<K extends keyof RTCPeerConnectionEventMap>(
type: K,
listener: (
this: RTCPeerConnection,
ev: RTCPeerConnectionEventMap[K],
) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
addIceCandidate(candidate?: RTCIceCandidateInit): Promise<void>;
addIceCandidate(
candidate: RTCIceCandidateInit,
successCallback: VoidFunction,
failureCallback: RTCPeerConnectionErrorCallback,
): Promise<void>;
addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender;
addTransceiver(
trackOrKind: string | MediaStreamTrack,
init?: RTCRtpTransceiverInit,
): RTCRtpTransceiver;
close(): void;
createAnswer(
options?: RTCAnswerOptions,
): Promise<RTCSessionDescriptionInit>;
createAnswer(
successCallback: RTCSessionDescriptionCallback,
failureCallback: RTCPeerConnectionErrorCallback,
): Promise<void>;
createDataChannel(
label: string,
dataChannelDict?: RTCDataChannelInit,
): RTCDataChannel;
createOffer(options?: RTCOfferOptions): Promise<RTCSessionDescriptionInit>;
createOffer(
successCallback: RTCSessionDescriptionCallback,
failureCallback: RTCPeerConnectionErrorCallback,
options?: RTCOfferOptions,
): Promise<void>;
dispatchEvent(event: Event): boolean;
getConfiguration(): RTCConfiguration;
getReceivers(): RTCRtpReceiver[];
getSenders(): RTCRtpSender[];
getStats(selector?: MediaStreamTrack): Promise<RTCStatsReport>;
getTransceivers(): RTCRtpTransceiver[];
removeEventListener<K extends keyof RTCPeerConnectionEventMap>(
type: K,
listener: (
this: RTCPeerConnection,
ev: RTCPeerConnectionEventMap[K],
) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
removeTrack(sender: RTCRtpSender): void;
restartIce(): void;
setConfiguration(configuration?: RTCConfiguration): void;
setLocalDescription(
description?: RTCLocalSessionDescriptionInit,
): Promise<void>;
setLocalDescription(
description: RTCLocalSessionDescriptionInit,
successCallback: VoidFunction,
failureCallback: RTCPeerConnectionErrorCallback,
): Promise<void>;
setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void>;
setRemoteDescription(
description: RTCSessionDescriptionInit,
successCallback: VoidFunction,
failureCallback: RTCPeerConnectionErrorCallback,
): Promise<void>;
}
Hierarchy
- EventTarget
- RTCPeerConnection (View Summary)
Index
Properties
Methods
Properties
ReadonlycanTrickleIceCandidates
ReadonlyconnectionState
ReadonlycurrentLocalDescription
ReadonlycurrentRemoteDescription
ReadonlyiceConnectionState
ReadonlyiceGatheringState
ReadonlylocalDescription
onconnectionstatechange
ondatachannel
onicecandidate
onicecandidateerror
oniceconnectionstatechange
onicegatheringstatechange
onnegotiationneeded
onsignalingstatechange
ontrack
ReadonlypendingLocalDescription
ReadonlypendingRemoteDescription
ReadonlyremoteDescription
Readonlysctp
ReadonlysignalingState
Methods
addEventListener
- addEventListener<K extends keyof RTCPeerConnectionEventMap>(
type: K,
listener: (
this: RTCPeerConnection,
ev: RTCPeerConnectionEventMap[K],
) => any,
options?: boolean | AddEventListenerOptions,
): void Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
Type Parameters
- K extends keyof RTCPeerConnectionEventMap
Parameters
- type: K
- listener: (this: RTCPeerConnection, ev: RTCPeerConnectionEventMap[K]) => any
Optionaloptions: boolean | AddEventListenerOptions
Returns void
- addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.
The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.
When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.
When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.
When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.
If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.
The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.
Parameters
- type: string
- listener: EventListenerOrEventListenerObject
Optionaloptions: boolean | AddEventListenerOptions
Returns void
addIceCandidate
- addIceCandidate(candidate?: RTCIceCandidateInit): Promise<void>
Parameters
Optionalcandidate: RTCIceCandidateInit
Returns Promise<void>
- addIceCandidate(
candidate: RTCIceCandidateInit,
successCallback: VoidFunction,
failureCallback: RTCPeerConnectionErrorCallback,
): Promise<void> Parameters
- candidate: RTCIceCandidateInit
- successCallback: VoidFunction
- failureCallback: RTCPeerConnectionErrorCallback
Returns Promise<void>
addTrack
- addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender
Parameters
- track: MediaStreamTrack
- ...streams: MediaStream[]
Returns RTCRtpSender
addTransceiver
- addTransceiver(
trackOrKind: string | MediaStreamTrack,
init?: RTCRtpTransceiverInit,
): RTCRtpTransceiver Parameters
- trackOrKind: string | MediaStreamTrack
Optionalinit: RTCRtpTransceiverInit
Returns RTCRtpTransceiver
close
createAnswer
- createAnswer(options?: RTCAnswerOptions): Promise<RTCSessionDescriptionInit>
Parameters
Optionaloptions: RTCAnswerOptions
Returns Promise<RTCSessionDescriptionInit>
- createAnswer(
successCallback: RTCSessionDescriptionCallback,
failureCallback: RTCPeerConnectionErrorCallback,
): Promise<void> Parameters
- successCallback: RTCSessionDescriptionCallback
- failureCallback: RTCPeerConnectionErrorCallback
Returns Promise<void>
createDataChannel
- createDataChannel(
label: string,
dataChannelDict?: RTCDataChannelInit,
): RTCDataChannel Parameters
- label: string
OptionaldataChannelDict: RTCDataChannelInit
Returns RTCDataChannel
createOffer
- createOffer(options?: RTCOfferOptions): Promise<RTCSessionDescriptionInit>
Parameters
Optionaloptions: RTCOfferOptions
Returns Promise<RTCSessionDescriptionInit>
- createOffer(
successCallback: RTCSessionDescriptionCallback,
failureCallback: RTCPeerConnectionErrorCallback,
options?: RTCOfferOptions,
): Promise<void> Parameters
- successCallback: RTCSessionDescriptionCallback
- failureCallback: RTCPeerConnectionErrorCallback
Optionaloptions: RTCOfferOptions
Returns Promise<void>
dispatchEvent
getConfiguration
- getConfiguration(): RTCConfiguration
Returns RTCConfiguration
getReceivers
- getReceivers(): RTCRtpReceiver[]
Returns RTCRtpReceiver[]
getSenders
- getSenders(): RTCRtpSender[]
Returns RTCRtpSender[]
getStats
- getStats(selector?: MediaStreamTrack): Promise<RTCStatsReport>
Parameters
Optionalselector: MediaStreamTrack
Returns Promise<RTCStatsReport>
getTransceivers
- getTransceivers(): RTCRtpTransceiver[]
Returns RTCRtpTransceiver[]
removeEventListener
- removeEventListener<K extends keyof RTCPeerConnectionEventMap>(
type: K,
listener: (
this: RTCPeerConnection,
ev: RTCPeerConnectionEventMap[K],
) => any,
options?: boolean | EventListenerOptions,
): void Removes the event listener in target's event listener list with the same type, callback, and options.
Type Parameters
- K extends keyof RTCPeerConnectionEventMap
Parameters
- type: K
- listener: (this: RTCPeerConnection, ev: RTCPeerConnectionEventMap[K]) => any
Optionaloptions: boolean | EventListenerOptions
Returns void
- removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void Removes the event listener in target's event listener list with the same type, callback, and options.
Parameters
- type: string
- listener: EventListenerOrEventListenerObject
Optionaloptions: boolean | EventListenerOptions
Returns void
removeTrack
- removeTrack(sender: RTCRtpSender): void
Parameters
- sender: RTCRtpSender
Returns void
restartIce
setConfiguration
- setConfiguration(configuration?: RTCConfiguration): void
Parameters
Optionalconfiguration: RTCConfiguration
Returns void
setLocalDescription
- setLocalDescription(description?: RTCLocalSessionDescriptionInit): Promise<void>
Parameters
Optionaldescription: RTCLocalSessionDescriptionInit
Returns Promise<void>
- setLocalDescription(
description: RTCLocalSessionDescriptionInit,
successCallback: VoidFunction,
failureCallback: RTCPeerConnectionErrorCallback,
): Promise<void> Parameters
- description: RTCLocalSessionDescriptionInit
- successCallback: VoidFunction
- failureCallback: RTCPeerConnectionErrorCallback
Returns Promise<void>
setRemoteDescription
- setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void>
Parameters
- description: RTCSessionDescriptionInit
Returns Promise<void>
- setRemoteDescription(
description: RTCSessionDescriptionInit,
successCallback: VoidFunction,
failureCallback: RTCPeerConnectionErrorCallback,
): Promise<void> Parameters
- description: RTCSessionDescriptionInit
- successCallback: VoidFunction
- failureCallback: RTCPeerConnectionErrorCallback
Returns Promise<void>
A WebRTC connection between the local computer and a remote peer. It provides methods to connect to a remote peer, maintain and monitor the connection, and close the connection once it's no longer needed.
MDN Reference