Skip to content

Commit 21df5e4

Browse files
author
Amin
committed
improvement
1 parent daab602 commit 21df5e4

File tree

8 files changed

+141
-21
lines changed

8 files changed

+141
-21
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"require": {
2626
"php": "^8.4",
2727
"quasarstream/exception": "^1.0",
28-
"quasarstream/dtls": "^1.0"
28+
"quasarstream/rtp-parameter": "^1.0",
29+
"quasarstream/ice": "^1.0"
2930
},
3031
"require-dev": {
3132
"phpunit/php-code-coverage": "11.0.x-dev",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the PHP WebRTC package.
5+
*
6+
* (c) Amin Yazdanpanah <https://www.aminyazdanpanah.com/#contact>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Webrtc\SDP\DtlsParameter;
13+
14+
use Webrtc\Mixin\DataClass;
15+
16+
/**
17+
* Represents a DTLS fingerprint.
18+
*/
19+
#[DataClass]
20+
class RTCDtlsFingerprint
21+
{
22+
/**
23+
* Initializes a new RTCDtlsFingerprint instance.
24+
*
25+
* @param string $algorithm The hash algorithm (e.g., "sha-256").
26+
* @param string $value The fingerprint value.
27+
*/
28+
public function __construct(
29+
public string $algorithm,
30+
public string $value
31+
)
32+
{
33+
}
34+
35+
public function isAlgorithm(string $algorithm): bool
36+
{
37+
return $this->algorithm === $algorithm;
38+
}
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the PHP WebRTC package.
5+
*
6+
* (c) Amin Yazdanpanah <https://www.aminyazdanpanah.com/#contact>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Webrtc\SDP\DtlsParameter;
13+
14+
use Webrtc\Mixin\DataClass;
15+
use Webrtc\SDP\Enum\DtlsRole;
16+
17+
/**
18+
* Represents DTLS (Datagram Transport Layer Security) parameters.
19+
*/
20+
#[DataClass]
21+
class RTCDtlsParameters
22+
{
23+
/**
24+
* Initializes a new RTCDtlsParameters instance.
25+
*
26+
* @param RTCDtlsFingerprint[] $fingerprints List of DTLS fingerprints, one for each certificate.
27+
* @param DtlsRole $role The DTLS role, with a default of "auto".
28+
*/
29+
public function __construct(
30+
public array $fingerprints = [],
31+
public DtlsRole $role = DtlsRole::Auto
32+
)
33+
{
34+
}
35+
}

src/Enum/DtlsRole.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the PHP WebRTC package.
5+
*
6+
* (c) Amin Yazdanpanah <https://www.aminyazdanpanah.com/#contact>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Webrtc\SDP\Enum;
13+
14+
enum DtlsRole: string
15+
{
16+
case Auto = "auto";
17+
case Client = "client";
18+
case Server = "server";
19+
}

src/MediaDescription.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

1212
namespace Webrtc\SDP;
1313

14-
use Webrtc\DTLS\Parameters\RTCDtlsParameters;
1514
use Webrtc\ICE\RTCIceCandidate;
1615
use Webrtc\ICE\RTCIceParameters;
17-
use Webrtc\RTP\Parameters\RTCRtpParameters;
18-
use Webrtc\SCTP\RTCSctpCapabilities;
16+
use Webrtc\RTPParameter\RTCRtpParameters;
17+
use Webrtc\SDP\DtlsParameter\RTCDtlsParameters;
1918
use Webrtc\SDP\Enum\SDPDirections;
19+
use Webrtc\SDP\SctpParameter\RTCSctpCapabilities;
2020

2121
/**
2222
* Represents a media description for SDP (Session Description Protocol).
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the PHP WebRTC package.
5+
*
6+
* (c) Amin Yazdanpanah <https://www.aminyazdanpanah.com/#contact>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Webrtc\SDP\SctpParameter;
13+
14+
/**
15+
* Provides information about the capabilities of the RTCSctpTransport.
16+
*/
17+
class RTCSctpCapabilities
18+
{
19+
/**
20+
* The maximum size of data that the implementation can send or
21+
* 0 if the implementation can handle messages of any size.
22+
*/
23+
public function __construct(public int $maxMessageSize = 0)
24+
{
25+
}
26+
}

src/SessionDescription.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111

1212
namespace Webrtc\SDP;
1313

14-
use Webrtc\DTLS\Enum\DtlsRole;
15-
use Webrtc\DTLS\Parameters\RTCDtlsFingerprint;
1614
use Webrtc\Exception\InvalidArgumentException;
1715
use Webrtc\ICE\RTCIceCandidate;
18-
use Webrtc\RTP\Parameters\RTCRtcpFeedback;
19-
use Webrtc\RTP\Parameters\RTCRtpCodecParameters;
20-
use Webrtc\RTP\Parameters\RTCRtpHeaderExtensionParameters;
21-
use Webrtc\RTP\RtpConstants;
22-
use Webrtc\SCTP\RTCSctpCapabilities;
16+
use Webrtc\RTPParameter\RTCRtcpFeedback;
17+
use Webrtc\RTPParameter\RTCRtpCodecParameters;
18+
use Webrtc\RTPParameter\RTCRtpHeaderExtensionParameters;
19+
use Webrtc\SDP\DtlsParameter\RTCDtlsFingerprint;
20+
use Webrtc\SDP\Enum\DtlsRole;
2321
use Webrtc\SDP\Enum\SDPDirections;
22+
use Webrtc\SDP\SctpParameter\RTCSctpCapabilities;
2423

2524
/**
2625
* Represents a session description for SDP (Session Description Protocol).
@@ -36,6 +35,7 @@ class SessionDescription
3635

3736
/** @var string[] Supported SSRC attributes. */
3837
private const array SSRC_INFO_ATTRS = ["cname", "msid", "mslabel", "label"];
38+
private const array FORBIDDEN_PAYLOAD_TYPES = [72, 73, 74, 75, 76];
3939
const array DIRECTIONS = ["inactive", "sendonly", "recvonly", "sendrecv"];
4040
/** @var int The SDP version. */
4141
private int $version = 0;
@@ -246,7 +246,7 @@ private function decodeMediaDescription(string $line): MediaDescription
246246
if (in_array($kind, ["audio", "video"])) {
247247
$fmtInt = array_map('intval', $fmt);
248248
foreach ($fmtInt as $pt) {
249-
if ($pt < 0 || $pt >= 256 || in_array($pt, RtpConstants::FORBIDDEN_PAYLOAD_TYPES)) {
249+
if ($pt < 0 || $pt >= 256 || in_array($pt, self::FORBIDDEN_PAYLOAD_TYPES)) {
250250
throw new InvalidArgumentException("Invalid payload type: $pt");
251251
}
252252
}

tests/SessionDescriptionTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
use PHPUnit\Framework\Attributes\CoversClass;
66
use PHPUnit\Framework\Attributes\UsesClass;
77
use PHPUnit\Framework\TestCase;
8-
use Webrtc\DTLS\Enum\DtlsRole;
9-
use Webrtc\DTLS\Parameters\RTCDtlsFingerprint;
10-
use Webrtc\DTLS\Parameters\RTCDtlsParameters;
118
use Webrtc\ICE\RTCIceCandidate;
129
use Webrtc\ICE\RTCIceParameters;
13-
use Webrtc\RTP\Parameters\RTCRtcpFeedback;
14-
use Webrtc\RTP\Parameters\RTCRtcpParameters;
15-
use Webrtc\RTP\Parameters\RTCRtpCodecParameters;
16-
use Webrtc\RTP\Parameters\RTCRtpHeaderExtensionParameters;
17-
use Webrtc\RTP\Parameters\RTCRtpParameters;
18-
use Webrtc\SCTP\RTCSctpCapabilities;
10+
use Webrtc\RTPParameter\RTCRtcpFeedback;
11+
use Webrtc\RTPParameter\RTCRtcpParameters;
12+
use Webrtc\RTPParameter\RTCRtpCodecParameters;
13+
use Webrtc\RTPParameter\RTCRtpHeaderExtensionParameters;
14+
use Webrtc\RTPParameter\RTCRtpParameters;
15+
use Webrtc\SDP\DtlsParameter\RTCDtlsFingerprint;
16+
use Webrtc\SDP\DtlsParameter\RTCDtlsParameters;
17+
use Webrtc\SDP\Enum\DtlsRole;
1918
use Webrtc\SDP\Enum\SDPDirections;
2019
use Webrtc\SDP\GroupDescription;
2120
use Webrtc\SDP\MediaDescription;
21+
use Webrtc\SDP\SctpParameter\RTCSctpCapabilities;
2222
use Webrtc\SDP\SDPUtility;
2323
use Webrtc\SDP\SessionDescription;
2424
use Webrtc\SDP\SsrcDescription;

0 commit comments

Comments
 (0)