@@ -55,17 +55,18 @@ class RTCConfiguration implements RTCConfigurationInterface
55
55
/**
56
56
* Constructs a new RTCConfiguration instance
57
57
*
58
- * @param array|null $configuration Optional configuration array. If null,
59
- * default configuration with a Google STUN server will be used.
60
- * Expected keys:
61
- * - 'iceServers': Array of ICE server configurations
62
- * - 'certificatePath': Path to a certificate file (optional)
63
- * - 'privateKeyPath': Path to a private key file (optional)
64
- * @throws InvalidArgumentException If iceServer configuration is invalid
58
+ * @param array<RTCIceServerInterface> $iceServers
59
+ * @param string|null $certificatePath
60
+ * @param string|null $privateKeyPath
65
61
*/
66
- public function __construct (?array $ configuration = null )
67
- {
68
- $ configuration !== null ? $ this ->parseConfiguration ($ configuration ) : $ this ->getDefaultConfiguration ();
62
+ public function __construct (
63
+ array $ iceServers = [],
64
+ ?string $ certificatePath = null ,
65
+ ?string $ privateKeyPath = null
66
+ ) {
67
+ $ this ->iceServers = empty ($ iceServers ) ? $ this ->getDefaultIceServer () : $ iceServers ;
68
+ $ this ->certificatePath = $ certificatePath ;
69
+ $ this ->privateKeyPath = $ privateKeyPath ;
69
70
}
70
71
71
72
/**
@@ -149,11 +150,11 @@ public function setPrivateKeyPath(?string $privateKeyPath): void
149
150
* - 'iceServers': Array of ICE server configurations (required if present)
150
151
* - 'certificatePath': Path to a certificate file (optional)
151
152
* - 'privateKeyPath': Path to a private key file (optional)
152
- * @return void
153
- * @throws InvalidArgumentException If iceServer configuration is missing required 'urls' key
153
+ * @return RTCConfiguration
154
154
*/
155
- private function parseConfiguration (array $ configuration ): void
155
+ public static function parseConfiguration (array $ configuration ): self
156
156
{
157
+ $ iceServers = [];
157
158
if (isset ($ configuration ['iceServers ' ])) {
158
159
foreach ($ configuration ["iceServers " ] as $ iceServer ) {
159
160
if (!isset ($ iceServer ["urls " ])) {
@@ -166,23 +167,28 @@ private function parseConfiguration(array $configuration): void
166
167
$ iceServerObj ->setCredential ($ iceServer ["credential " ] ?? null );
167
168
$ iceServerObj ->setCredentialType ($ iceServer ["credentialType " ] ?? null );
168
169
169
- $ this -> addIceServer ( $ iceServerObj) ;
170
+ $ iceServers [] = $ iceServerObj ;
170
171
}
172
+ }else {
173
+ $ iceServers = (new RTCConfiguration )->getDefaultIceServer ();
171
174
}
172
175
173
- $ this ->certificatePath = $ configuration ["certificatePath " ] ?? null ;
174
- $ this ->privateKeyPath = $ configuration ["privateKeyPath " ] ?? null ;
176
+ $ certificatePath = $ configuration ["certificatePath " ] ?? null ;
177
+ $ privateKeyPath = $ configuration ["privateKeyPath " ] ?? null ;
178
+
179
+ return new static ($ iceServers , $ certificatePath , $ privateKeyPath );
175
180
}
176
181
177
182
/**
178
- * Sets up default configuration with Google's public STUN server
183
+ * return the default ice configuration with Google's public STUN server
179
184
*
180
- * @return void
185
+ * @return array<RTCIceServer>
181
186
*/
182
- private function getDefaultConfiguration (): void
187
+ private function getDefaultIceServer (): array
183
188
{
184
189
$ iceServer = new RTCIceServer ();
185
190
$ iceServer ->setUrls ([self ::DEFAULT_STUN_SERVER ]);
186
- $ this ->addIceServer ($ iceServer );
191
+
192
+ return [$ iceServer ];
187
193
}
188
194
}
0 commit comments