22
33namespace OpenTok ;
44
5- use OpenTok \Layout ;
65use OpenTok \Util \Client ;
76use OpenTok \Util \Validators ;
87use OpenTok \Exception \InvalidArgumentException ;
@@ -27,6 +26,8 @@ class OpenTok
2726 private $ apiSecret ;
2827 /** @internal */
2928 private $ client ;
29+ /** @internal */
30+ public $ options ;
3031
3132 /** @internal */
3233 public function __construct ($ apiKey , $ apiSecret , $ options = array ())
@@ -37,8 +38,10 @@ public function __construct($apiKey, $apiSecret, $options = array())
3738 'client ' => null ,
3839 'timeout ' => null // In the future we should set this to 2
3940 );
40- $ options = array_merge ($ defaults , array_intersect_key ($ options , $ defaults ));
41- list ($ apiUrl , $ client , $ timeout ) = array_values ($ options );
41+
42+ $ this ->options = array_merge ($ defaults , array_intersect_key ($ options , $ defaults ));
43+
44+ list ($ apiUrl , $ client , $ timeout ) = array_values ($ this ->options );
4245
4346 // validate arguments
4447 Validators::validateApiKey ($ apiKey );
@@ -53,7 +56,7 @@ public function __construct($apiKey, $apiSecret, $options = array())
5356 $ apiKey ,
5457 $ apiSecret ,
5558 $ apiUrl ,
56- ['timeout ' => $ timeout ]
59+ array_merge ( ['timeout ' => $ timeout ], $ this -> options )
5760 );
5861 }
5962 $ this ->apiKey = $ apiKey ;
@@ -166,6 +169,10 @@ public function generateToken($sessionId, $options = array())
166169 * (either automatically or not), you must set the <code>mediaMode</code> key to
167170 * <code>MediaMode::ROUTED</code>.</li>
168171 *
172+ * <li><code>'e2ee'</code> (Boolean) — Whether to enable
173+ * <a href="https://tokbox.com/developer/guides/end-to-end-encryption">end-to-end encryption</a>
174+ * for a routed session.</li>
175+ *
169176 * <li><code>'location'</code> (String) — An IP address that the OpenTok servers
170177 * will use to situate the session in its global network. If you do not set a location hint,
171178 * the OpenTok servers will be based on the first client connecting to the session.</li>
@@ -212,26 +219,41 @@ public function createSession($options = array())
212219 {
213220 if (
214221 array_key_exists ('archiveMode ' , $ options ) &&
215- $ options ['archiveMode ' ] != ArchiveMode::MANUAL
222+ $ options ['archiveMode ' ] !== ArchiveMode::MANUAL
216223 ) {
217224 if (
218225 array_key_exists ('mediaMode ' , $ options ) &&
219- $ options ['mediaMode ' ] != MediaMode::ROUTED
226+ $ options ['mediaMode ' ] !== MediaMode::ROUTED
220227 ) {
221228 throw new InvalidArgumentException ('A session must be routed to be archived. ' );
222229 } else {
223230 $ options ['mediaMode ' ] = MediaMode::ROUTED ;
224231 }
225232 }
226233
234+ if (array_key_exists ('e2ee ' , $ options ) && $ options ['e2ee ' ]) {
235+
236+ if (array_key_exists ('mediaMode ' , $ options ) && $ options ['mediaMode ' ] !== MediaMode::ROUTED ) {
237+ throw new InvalidArgumentException ('MediaMode must be routed in order to enable E2EE ' );
238+ }
239+
240+ if (array_key_exists ('archiveMode ' , $ options ) && $ options ['archiveMode ' ] === ArchiveMode::ALWAYS ) {
241+ throw new InvalidArgumentException ('ArchiveMode cannot be set to always when using E2EE ' );
242+ }
243+
244+ $ options ['e2ee ' ] = 'true ' ;
245+ }
246+
227247 // unpack optional arguments (merging with default values) into named variables
228248 $ defaults = array (
229249 'mediaMode ' => MediaMode::RELAYED ,
230250 'archiveMode ' => ArchiveMode::MANUAL ,
231- 'location ' => null
251+ 'location ' => null ,
252+ 'e2ee ' => 'false ' ,
232253 );
254+
233255 $ options = array_merge ($ defaults , array_intersect_key ($ options , $ defaults ));
234- list ($ mediaMode , $ archiveMode , $ location ) = array_values ($ options );
256+ list ($ mediaMode , $ archiveMode , $ location, $ e2ee ) = array_values ($ options );
235257
236258 // validate arguments
237259 Validators::validateMediaMode ($ mediaMode );
@@ -251,7 +273,8 @@ public function createSession($options = array())
251273 return new Session ($ this , (string )$ sessionId , array (
252274 'location ' => $ location ,
253275 'mediaMode ' => $ mediaMode ,
254- 'archiveMode ' => $ archiveMode
276+ 'archiveMode ' => $ archiveMode ,
277+ 'e2ee ' => $ e2ee
255278 ));
256279 }
257280
0 commit comments