You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 83a00ff
Browse filesBrowse the repository at this point in the historyBrowse files
feat: add the missing peer connection signaling and control calls
RTCPeerConnection gains:
- addIceCandidate(candidate, AddIceCandidateObserver), which is queued
behind pending offer/answer operations and reports whether the
candidate was accepted.
- removeIceCandidate(candidate), and PeerConnectionObserver gains
onIceCandidateRemoved for local candidates that go away.
- setLocalDescription(observer), which creates the offer or answer
itself, as perfect negotiation needs.
- setBitrate(min, current, max) for the connection's send bandwidth.
- setAudioPlayout and setAudioRecording.
PeerConnectionObserver also gains onSelectedCandidatePairChanged with an
RTCCandidatePairChangeEvent carrying both candidates of the pair, the
reason for the switch and the disconnection estimate. Its default passes
the remote address, port and type on to the existing callback, so
observers that override that one keep working.
The new callbacks report a Java exception to the thread's uncaught
exception handler instead of throwing it through WebRTC's frames;
ReportUncaughtException moves to WebRTCUtils to be shared with the data
channel send observer.
### Letting the Peer Connection Create the Description
219
+
220
+
`setLocalDescription` can also be called with only an observer. It then creates the offer or the answer, whichever the signaling state calls for, and applies it in one step, so nothing can change in between. That makes it the simpler way to implement "perfect negotiation". Read the result with `getLocalDescription()` once the observer reports success:
System.err.println("Failed to set local description: "+ error);
232
+
}
233
+
});
234
+
```
235
+
236
+
### Adding Candidates and Knowing the Outcome
237
+
238
+
`addIceCandidate(candidate)` reports nothing and fails silently when the remote description is not set yet. The form that takes an `AddIceCandidateObserver` is queued behind any pending offer/answer operation, as the standard requires, so a candidate can be added right after `setRemoteDescription()` without waiting for it, and the observer says whether it was accepted:
A local candidate can also go away, for example when its network interface does. The observer's `onIceCandidateRemoved(RTCIceCandidate)` reports it; send it to the remote peer, which passes it to `removeIceCandidate(candidate)`.
255
+
256
+
Once ICE has picked the candidate pair it uses, `onSelectedCandidatePairChanged(RTCCandidatePairChangeEvent)` reports both candidates of the pair and why it was chosen. It fires again whenever ICE switches pairs:
`cryptexPolicy` encrypts the RTP header extensions and CSRCs as a whole (RFC 9335) where the peer supports it (`NEGOTIATE`) or always (`REQUIRE`).
71
71
72
+
`certificates` takes the DTLS certificate a peer connection authenticates with, as an `RTCCertificatePEM`; without one, WebRTC generates a certificate per connection. A certificate that does not parse makes `createPeerConnection()` and `setConfiguration()` throw.
73
+
72
74
## Signaling
73
75
74
76
| Setting | Effect |
75
77
|---|---|
76
78
|`offerExtmapAllowMixed`| Allows one- and two-byte header extensions to be mixed in offers. Default true. |
77
-
|`enableImplicitRollback`| Rolls a pending local offer back when a remote offer arrives, as perfect negotiation needs. Default false. |
79
+
|`enableImplicitRollback`| Rolls a pending local offer back when a remote offer arrives, as perfect negotiation needs. Default false. Pair it with `setLocalDescription(observer)`, which creates the offer or answer itself. |
78
80
|`alwaysNegotiateDataChannels`| Includes data channels in offers before any is created. Default false. |
79
81
82
+
## Changing a Running Connection
83
+
84
+
A few controls are methods of `RTCPeerConnection` rather than configuration fields, and can be used at any time.
85
+
86
+
`setBitrate(min, current, max)` limits the bandwidth all streams sent by the connection may use together, in bits per second. A `null` value leaves that limit as it is, and `current` resets the bandwidth estimate to that value. Limits from the SDP and from each sender's encoding parameters still apply. Values that are negative or not ordered as min ≤ current ≤ max make it throw.
87
+
88
+
```java
89
+
// Start from 1 Mbps and never use more than 2.5 Mbps.
`setAudioPlayout(false)` stops the audio device from playing received audio; the audio is still decoded and its statistics still updated. `setAudioRecording(false)` stops the audio device from recording, so tracks fed by it send nothing, while tracks fed by a `CustomAudioSource` keep sending. Both are on by default and act on the audio device module, which all connections of a `PeerConnectionFactory` share.
94
+
80
95
## Related API
81
96
82
97
-`RTCConfiguration` — the configuration of a peer connection.
83
98
-`RTCPeerConnection.getConfiguration()`, `setConfiguration()` — read and change it.
99
+
-`RTCPeerConnection.setBitrate()`, `setAudioPlayout()`, `setAudioRecording()` — controls of a running connection.
84
100
-`RTCCryptoOptions` — the SRTP cipher suites.
85
101
-`PortAllocatorConfig` — ports and interfaces, see [Port Allocator Configuration](/guide/networking/port-allocator-config).
0 commit comments