1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! Events of one of the connection's transports, naming it.
//!
//! W3C webrtc-pc fires `statechange`, `gatheringstatechange`, `selectedcandidatepairchange`
//! (sections 5.5, 5.6) and `error` at the `RTCIceTransport` or `RTCDtlsTransport` object they
//! concern, and webrtc-extensions 7 the candidate pair events. A peer connection with several
//! transports (an m= section outside a BUNDLE group has one of its own, RFC 9429 section
//! 5.2.1) has several such objects; [`RTCTransportEvent`] is one of those events with the
//! transport it is fired at.
use crateRTCError;
use crateRTCIceGatheringState;
use crateRTCTransportId;
use crateRTCDtlsTransportState;
use crateRTCIceCandidatePair;
use crateRTCIceTransportState;
/// An event fired at one transport of the connection.
///
/// `ice_transport` and `dtls_transport` are the ids of the transport's
/// [`RTCIceTransport`](crate::peer_connection::transport::RTCIceTransport) and
/// [`RTCDtlsTransport`](crate::peer_connection::transport::RTCDtlsTransport), the ones a
/// sender's, receiver's or the SCTP transport's `transport()` returns for the sections on it;
/// [`RTCPeerConnection::dtls_transport_by_id`] gives the handle back.
///
/// [`RTCPeerConnection::dtls_transport_by_id`]: crate::peer_connection::RTCPeerConnection::dtls_transport_by_id
/// What happened to a transport; each kind is one of the events the single-transport
/// variants of `RTCPeerConnectionEvent` report for the default transport.
/// Why a transport needs a new set of local candidates
/// ([`RTCLocalCandidatesNeededEvent::reason`]).
/// `OnLocalCandidatesNeeded`: a transport holds none of the local candidates it had and needs
/// a new set, gathered by the application (the engine has no sockets).
///
/// For every reason but [`RTCLocalCandidatesNeededReason::DiscardedBySetting`], the UDP
/// transport addresses the transport used before ([`Self::refused_addresses`]) are refused:
/// [`RTCPeerConnection::add_local_candidate`] returns
/// `Error::ErrICECandidateAddressOfPreviousDtlsAssociation` for a UDP candidate on one of
/// them. The application binds new ports, adds a candidate for each with `sdp_mid` set to
/// [`Self::mids`]`[0]`, signals each to the peer (`OnIceCandidateEvent`) and ends the
/// generation with an empty candidate for the same mid. The previous sockets keep carrying
/// the transport's packets until a candidate pair on a new one is selected
/// (`SelectedCandidatePairChange`), or the transport closes: close them then (a few seconds
/// after a new selection: the peer selects on its own and may still send to them), not before.
///
/// A local offer that fired the event and is then rolled back takes it back (RFC 9429 section
/// 5.7): the transport has its previous candidates again, their addresses are no longer
/// refused, and the candidates added for the abandoned generation are dropped. The
/// application keeps the previous sockets as they were (not retired), closes or keeps aside
/// the ones it bound for the event, and gathers again on the next event (the answer to the
/// peer's colliding offer fires one when it sets up a new association). See the crate's
/// "Gathering" section.
///
/// [`RTCPeerConnection::add_local_candidate`]: crate::peer_connection::RTCPeerConnection::add_local_candidate