Skip to content

Commit 911f986

Browse files
author
QuasarStream Team
committed
add ICE port range
1 parent 481ccb6 commit 911f986

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/RTCIceConnection.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ class RTCIceConnection extends EventEmitter implements RTCIceConnectionInterface
179179
/** @var int Count of failed binding attempts */
180180
private int $tryFailedCount = 0;
181181

182+
private ?array $icePortRange = null;
183+
182184
/**
183185
* Constructor - Creates a new ICE connection
184186
*
@@ -584,7 +586,7 @@ private function getTurnCandidate(TurnInterface $turn, int $componentId): RTCIce
584586
private function getStun(string $address): StunInterface|false
585587
{
586588
try {
587-
return Stun::create($this, $address, $this->logger);
589+
return Stun::create($this, $address, $this->logger, $this->icePortRange);
588590
} catch (Throwable) {
589591
return false;
590592
}
@@ -2058,4 +2060,9 @@ public function setIceRole(IceRole $iceRole): void
20582060
{
20592061
$this->iceRole = $iceRole;
20602062
}
2063+
2064+
public function setIcePortRange(?array $icePortRange): void
2065+
{
2066+
$this->icePortRange = $icePortRange;
2067+
}
20612068
}

src/RTCIceGatherer.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Throwable;
1818
use Webrtc\ICE\Enum\IceGatheringState;
1919
use Webrtc\ICE\Enum\IceRole;
20+
use Webrtc\ICE\Enum\TransportPolicyType;
2021

2122
/**
2223
* The RTCIceGatherer is responsible for gathering ICE candidates on the local machine.
@@ -44,14 +45,25 @@ class RTCIceGatherer extends EventEmitter implements RTCIceGathererInterface
4445
*
4546
* @throws RandomException
4647
*/
47-
public function __construct(private readonly array $iceServes, IceRole $role = IceRole::Controlling, ?LoggerInterface $logger = null)
48+
public function __construct(
49+
private readonly array $iceServes,
50+
?array $icePortRange = null,
51+
?TransportPolicyType $transportPolicy = null,
52+
IceRole $role = IceRole::Controlling,
53+
?LoggerInterface $logger = null
54+
)
4855
{
4956
$protocolParser = new IceProtocolParser($iceServes);
5057
$this->iceConnection = new RTCIceConnection($protocolParser->getIceConnectionConfiguration(), $role);
58+
$this->iceConnection->setIcePortRange($icePortRange);
5159

5260
if ($logger) {
5361
$this->iceConnection->setLogger($logger);
5462
}
63+
64+
if ($transportPolicy) {
65+
$this->iceConnection->setTransportPolicy($transportPolicy);
66+
}
5567
}
5668

5769
/**
@@ -70,10 +82,10 @@ public function getIceServes(): array
7082
* Changes state from 'new' to 'gathering', then to 'complete' after gathering is finished.
7183
* Emits a 'statechange' event on state transitions.
7284
*
73-
* @throws RandomException
85+
* @return void
7486
* @throws Throwable
7587
*
76-
* @return void
88+
* @throws RandomException
7789
*/
7890
public function gather(): void
7991
{

tests/RTCIceTransportTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ public function testConstruct()
107107

108108
public function testConnect()
109109
{
110-
$gatherer1 = new RTCIceGatherer([],IceRole::Controlling);
110+
$gatherer1 = new RTCIceGatherer([], role: IceRole::Controlling);
111111
$transport1 = new RTCIceTransport($gatherer1);
112112

113-
$gatherer2 = new RTCIceGatherer([], IceRole::Controlled);
113+
$gatherer2 = new RTCIceGatherer([], role: IceRole::Controlled);
114114
$transport2 = new RTCIceTransport($gatherer2);
115115

116116
$gatherer1->gather();
@@ -140,10 +140,10 @@ public function testConnect()
140140

141141
public function testConnectFail()
142142
{
143-
$gatherer1 = new RTCIceGatherer([],IceRole::Controlling);
143+
$gatherer1 = new RTCIceGatherer([], role: IceRole::Controlling);
144144
$transport1 = new RTCIceTransport($gatherer1);
145145

146-
$gatherer2 = new RTCIceGatherer([], IceRole::Controlled);
146+
$gatherer2 = new RTCIceGatherer([], role: IceRole::Controlled);
147147
$transport2 = new RTCIceTransport($gatherer2);
148148

149149
$gatherer1->gather();
@@ -173,10 +173,10 @@ public function testConnectFail()
173173

174174
public function testConnectThenConsentExpires()
175175
{
176-
$gatherer1 = new RTCIceGatherer([],IceRole::Controlling);
176+
$gatherer1 = new RTCIceGatherer([], role: IceRole::Controlling);
177177
$transport1 = new RTCIceTransport($gatherer1);
178178

179-
$gatherer2 = new RTCIceGatherer([], IceRole::Controlled);
179+
$gatherer2 = new RTCIceGatherer([], role: IceRole::Controlled);
180180
$transport2 = new RTCIceTransport($gatherer2);
181181

182182
$gatherer1->gather();

0 commit comments

Comments
 (0)