Skip to content

Commit 77765be

Browse files
author
QuasarStream Team
committed
Add ICESetting in RTCConfiguration class
1 parent c053061 commit 77765be

File tree

4 files changed

+48
-36
lines changed

4 files changed

+48
-36
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
github: [php-webrtc]
1+
github:
2+
- php-webrtc
3+
- quasarstream

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
1313
## [1.0.0] - 2025-05-13
1414

1515
### Added
16-
- First release
16+
- First release
17+
18+
## [1.0.3] - 2025-10-08
19+
20+
### Added
21+
- Add ICESetting in RTCConfiguration class that represent low level ice setting

src/RTCConfiguration.php

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,63 @@
1212
namespace Webrtc\Webrtc;
1313

1414
use Webrtc\Exception\InvalidArgumentException;
15-
use Webrtc\ICE\Enum\TransportPolicyType;
1615
use Webrtc\ICE\RTCIceServer;
1716
use 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
*/
2837
class 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
}

src/RTCPeerConnection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ private function createSctpTransport(): void
734734
private function createDtlsTransport(): RTCDtlsTransport
735735
{
736736
// create ICE transport
737-
$iceGatherer = new RTCIceGatherer($this->configuration->getIceServers(), $this->configuration->getIcePortRange(), $this->configuration->getTransportPolicy(), logger: $this->logger);
737+
$iceGatherer = new RTCIceGatherer($this->configuration->getIceServers(), $this->configuration->iceSettings(), $this->logger);
738738
$iceGatherer->on("statechange", fn() => $this->updateIceGatheringState());
739739
$iceTransport = new RTCIceTransport($iceGatherer, $this->logger);
740740
$iceTransport->on("statechange", fn() => $this->updateIceConnectionState());

0 commit comments

Comments
 (0)