Skip to content

Commit 2d0b030

Browse files
author
QuasarStream Team
committed
Update ICE Setting and minor improvements like add documents
1 parent a95c088 commit 2d0b030

3 files changed

Lines changed: 168 additions & 8 deletions

File tree

src/RTCICESetting.php

Lines changed: 154 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,89 @@
66
use Webrtc\ICE\Enum\IceRole;
77
use Webrtc\ICE\Enum\TransportPolicyType;
88

9+
/**
10+
* The `RTCICESetting` class defines advanced configuration options
11+
* for the ICE (Interactive Connectivity Establishment) layer.
12+
*
13+
* It controls aspects such as port ranges, transport policy,
14+
* NAT mapping, ICE roles, and IP version usage.
15+
*/
916
class RTCICESetting
1017
{
18+
/**
19+
* Port range used for ICE candidate gathering.
20+
* If null, the system assigns ports automatically.
21+
*
22+
* @var array<int,int>|null [minPort, maxPort] or null if unset
23+
*/
1124
private ?array $icePortRange = null;
25+
26+
/**
27+
* Defines the policy for allowed transport types (e.g., ALL, RELAY).
28+
*
29+
* @var TransportPolicyType
30+
*/
1231
private TransportPolicyType $transportPolicy = TransportPolicyType::ALL;
32+
33+
/**
34+
* A list of 1:1 NAT public-to-private IP address mappings.
35+
* Useful for servers behind NAT that need predictable candidate addresses.
36+
*
37+
* @var array<string,string>|null Array of mappings like ['privateIp' => 'publicIp']
38+
*/
1339
private ?array $nat1to1 = null;
40+
41+
/**
42+
* Whether the agent should operate in ICE-Lite mode.
43+
* ICE-Lite agents only respond to connectivity checks.
44+
*
45+
* @var bool
46+
*/
1447
private bool $iceLite = false;
15-
// it will be changed for only testing purpose
48+
49+
/**
50+
* Defines the current ICE role (Controlling or Controlled).
51+
* Primarily used for testing or forcing specific behavior.
52+
*
53+
* @var IceRole
54+
*/
1655
private IceRole $iceRole = IceRole::Controlling;
1756

57+
/**
58+
* Whether to gather and use IPv4 candidates.
59+
*
60+
* @var bool
61+
*/
62+
private bool $useIPv4 = true;
63+
64+
/**
65+
* Whether to gather and use IPv6 candidates.
66+
*
67+
* @var bool
68+
*/
69+
private bool $useIPv6 = true;
70+
71+
/**
72+
* Gets the configured ICE port range.
73+
*
74+
* @return array<int,int>|null The [minPort, maxPort] range or null if not set
75+
*/
1876
public function getIcePortRange(): ?array
1977
{
2078
return $this->icePortRange;
2179
}
2280

81+
/**
82+
* Sets the ICE port range used for candidate gathering.
83+
*
84+
* @param int $minPort Minimum port number (must be >= 1024)
85+
* @param int $maxPort Maximum port number (must be <= 65535)
86+
* @return void
87+
* @throws InvalidArgumentException If the range is invalid or too narrow
88+
*/
2389
public function setIcePortRange(int $minPort, int $maxPort): void
2490
{
25-
if ($maxPort- $minPort < 100) {
91+
if ($maxPort - $minPort < 100) {
2692
throw new InvalidArgumentException("maxPort - minPort must be greater than 100");
2793
}
2894

@@ -33,44 +99,129 @@ public function setIcePortRange(int $minPort, int $maxPort): void
3399
$this->icePortRange = [$minPort, $maxPort];
34100
}
35101

102+
/**
103+
* Gets the current transport policy.
104+
*
105+
* @return TransportPolicyType The transport policy (e.g., ALL, RELAY)
106+
*/
36107
public function getTransportPolicy(): TransportPolicyType
37108
{
38109
return $this->transportPolicy;
39110
}
40111

112+
/**
113+
* Sets the transport policy for ICE candidate gathering.
114+
*
115+
* @param TransportPolicyType $transportPolicy The desired transport policy
116+
* @return void
117+
*/
41118
public function setTransportPolicy(TransportPolicyType $transportPolicy): void
42119
{
43120
$this->transportPolicy = $transportPolicy;
44121
}
45122

123+
/**
124+
* Gets the 1:1 NAT mapping configuration.
125+
*
126+
* @return array<string,string>|null NAT mappings or null if not configured
127+
*/
46128
public function getNat1to1(): ?array
47129
{
48130
return $this->nat1to1;
49131
}
50132

133+
/**
134+
* Sets the 1:1 NAT mapping configuration.
135+
*
136+
* @param array<string,string>|null $nat1to1 Array of ['privateIp' => 'publicIp'] or null
137+
* @return void
138+
*/
51139
public function setNat1to1(?array $nat1to1): void
52140
{
53141
$this->nat1to1 = $nat1to1;
54142
}
55143

144+
/**
145+
* Checks if ICE-Lite mode is enabled.
146+
*
147+
* @return bool True if ICE-Lite mode is enabled, false otherwise
148+
*/
56149
public function isIceLite(): bool
57150
{
58151
return $this->iceLite;
59152
}
60153

154+
/**
155+
* Enables or disables ICE-Lite mode.
156+
*
157+
* @param bool $iceLite Whether to enable ICE-Lite mode
158+
* @return void
159+
*/
61160
public function setIceLite(bool $iceLite): void
62161
{
63162
$this->iceLite = $iceLite;
64163
}
65164

165+
/**
166+
* Gets the current ICE role.
167+
*
168+
* @return IceRole The ICE role (Controlling or Controlled)
169+
*/
66170
public function getIceRole(): IceRole
67171
{
68172
return $this->iceRole;
69173
}
70174

175+
/**
176+
* Sets the ICE role.
177+
*
178+
* @param IceRole $iceRole The ICE role to set
179+
* @return void
180+
*/
71181
public function setIceRole(IceRole $iceRole): void
72182
{
73183
$this->iceRole = $iceRole;
74184
}
75185

76-
}
186+
/**
187+
* Checks whether IPv4 candidates are used.
188+
*
189+
* @return bool True if IPv4 candidates are used, false otherwise
190+
*/
191+
public function isUseIPv4(): bool
192+
{
193+
return $this->useIPv4;
194+
}
195+
196+
/**
197+
* Enables or disables the use of IPv4 candidates.
198+
*
199+
* @param bool $useIPv4 Whether to use IPv4 candidates
200+
* @return void
201+
*/
202+
public function setUseIPv4(bool $useIPv4): void
203+
{
204+
$this->useIPv4 = $useIPv4;
205+
}
206+
207+
/**
208+
* Checks whether IPv6 candidates are used.
209+
*
210+
* @return bool True if IPv6 candidates are used, false otherwise
211+
*/
212+
public function isUseIPv6(): bool
213+
{
214+
return $this->useIPv6;
215+
}
216+
217+
/**
218+
* Enables or disables the use of IPv6 candidates.
219+
*
220+
* @param bool $useIPv6 Whether to use IPv6 candidates
221+
* @return void
222+
*/
223+
public function setUseIPv6(bool $useIPv6): void
224+
{
225+
$this->useIPv6 = $useIPv6;
226+
}
227+
}

src/RTCIceConnection.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,16 +2058,23 @@ public function setIceRole(IceRole $iceRole): void
20582058
$this->iceRole = $iceRole;
20592059
}
20602060

2061+
/**
2062+
* Sets the ICE port range used for candidate gathering.
2063+
*
2064+
* @param array|null $icePortRange
2065+
* @return void
2066+
*/
20612067
public function setIcePortRange(?array $icePortRange): void
20622068
{
20632069
$this->icePortRange = $icePortRange;
20642070
}
20652071

2066-
public function getNat1to1(): ?array
2067-
{
2068-
return $this->nat1to1;
2069-
}
2070-
2072+
/**
2073+
* Sets the 1:1 NAT mapping configuration.
2074+
*
2075+
* @param array<string,string>|null $nat1to1 Array of ['privateIp' => 'publicIp'] or null
2076+
* @return void
2077+
*/
20712078
public function setNat1to1(?array $nat1to1): void
20722079
{
20732080
$this->nat1to1 = $nat1to1;

src/RTCIceGatherer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ public function __construct(private array $iceServes, ?RTCICESetting $setting =
5656
$this->iceConnection->setTransportPolicy($setting->getTransportPolicy());
5757
$this->iceConnection->setRemoteIsLite($setting->isIceLite());
5858
$this->iceConnection->setNat1to1($setting->getNat1to1());
59+
$this->iceConnection->setUseIPv4($setting->isUseIPv4());
60+
$this->iceConnection->setUseIPv6($setting->isUseIPv6());
5961

6062
if ($logger) {
6163
$this->iceConnection->setLogger($logger);

0 commit comments

Comments
 (0)