1212namespace Webrtc \Webrtc ;
1313
1414use Webrtc \Exception \InvalidArgumentException ;
15- use Webrtc \ICE \Enum \TransportPolicyType ;
1615use Webrtc \ICE \RTCIceServer ;
1716use Webrtc \ICE \RTCIceServerInterface ;
17+ use Webrtc \ICE \RTCICESetting ;
1818
1919/**
2020 * The `RTCConfiguration` class provides configuration options for an
21- * `RTCPeerConnection` class .
21+ * `RTCPeerConnection` instance .
2222 *
23- * This class allows configuration of ICE servers (STUN/TURN), certificate paths,
24- * and private key paths for WebRTC connections. It implements the
25- * `RTCConfigurationInterface` and provides methods to manage ICE servers and
26- * security credentials.
23+ * It allows configuring ICE servers (STUN/TURN), certificate paths,
24+ * private key paths, and low-level ICE behavior through `RTCICESetting`.
25+ *
26+ * Example usage:
27+ * ```php
28+ * $config = new RTCConfiguration([
29+ * 'iceServers' => [
30+ * ['urls' => 'stun:stun.l.google.com:19302']
31+ * ]
32+ * ]);
33+ *
34+ * $config->iceSettings()->setIcePortRange(40000, 50000);
35+ * ```
2736 */
2837class RTCConfiguration implements RTCConfigurationInterface
2938{
3039 /**
31- * Default STUN server URL used when no configuration is provided
40+ * Default STUN server URL used when no configuration is provided.
3241 */
3342 private const string DEFAULT_STUN_SERVER = "stun:stun.l.google.com:19302 " ;
3443
3544 /**
36- * Array of RTCIceServer objects representing STUN/TURN servers
45+ * Array of RTCIceServer objects representing STUN/TURN servers.
3746 *
3847 * @var array<RTCIceServerInterface>
3948 */
4049 private array $ iceServers = [];
4150
4251 /**
43- * Path to the certificate file for secure connections
52+ * Path to the certificate file for secure connections.
4453 *
4554 * @var string|null
4655 */
4756 private ?string $ certificatePath = null ;
4857
4958 /**
50- * Path to the private key file for secure connections
59+ * Path to the private key file for secure connections.
5160 *
5261 * @var string|null
5362 */
5463 private ?string $ privateKeyPath = null ;
5564
56- private ?array $ icePortRange = null ;
57- private ?TransportPolicyType $ transportPolicy = null ;
65+ /**
66+ * ICE settings object defining port range, transport policy,
67+ * NAT mapping, and IP family usage.
68+ *
69+ * @var RTCICESetting
70+ */
71+ private RTCICESetting $ iceSettings ;
5872
5973 /**
6074 * Constructs a new RTCConfiguration instance
@@ -69,6 +83,7 @@ class RTCConfiguration implements RTCConfigurationInterface
6983 */
7084 public function __construct (?array $ configuration = null )
7185 {
86+ $ this ->iceSettings = new RTCICESetting ();
7287 $ configuration !== null ? $ this ->parseConfiguration ($ configuration ) : $ this ->getDefaultConfiguration ();
7388 }
7489
@@ -185,31 +200,21 @@ private function parseConfiguration(array $configuration): void
185200 */
186201 private function getDefaultConfiguration (): void
187202 {
188- $ iceServer = new RTCIceServer ();
203+ $ iceServer = new RTCIceServer ();
189204 $ iceServer ->setUrls ([self ::DEFAULT_STUN_SERVER ]);
190205 $ this ->addIceServer ($ iceServer );
191206 }
192207
193- public function getIcePortRange (): ?array
194- {
195- return $ this ->icePortRange ;
196- }
197-
198- public function setIcePortRange (int $ minPort , int $ maxPort ): void
199- {
200- if ($ maxPort - $ minPort < 100 ) {
201- throw new InvalidArgumentException ("maxPort - minPort must be greater than 100 " );
202- }
203- $ this ->icePortRange = [$ minPort , $ maxPort ];
204- }
205-
206- public function getTransportPolicy (): ?TransportPolicyType
207- {
208- return $ this ->transportPolicy ;
209- }
210-
211- public function setTransportPolicy (?TransportPolicyType $ transportPolicy ): void
208+ /**
209+ * Gets the ICE settings instance associated with this configuration.
210+ *
211+ * This object allows customization of advanced ICE parameters such as
212+ * port ranges, NAT mappings, ICE-Lite mode, and transport policies.
213+ *
214+ * @return RTCICESetting The ICE settings instance
215+ */
216+ public function iceSettings (): RTCICESetting
212217 {
213- $ this ->transportPolicy = $ transportPolicy ;
218+ return $ this ->iceSettings ;
214219 }
215220}
0 commit comments