@@ -35,26 +35,47 @@ class OpenTok
3535 private $ apiSecret ;
3636 /** @internal */
3737 private $ client ;
38- /** @internal */
38+
39+ /**
40+ * @var array
41+ * @internal
42+ * Options that can override the defaults. Additionally, you can set the keys
43+ * application_id & private_key_path to strings that will then override the default
44+ * OpenTok Client behaviour when making requests to the Vonage Video API.
45+ */
3946 public $ options ;
4047
4148 /** @internal */
4249 public function __construct ($ apiKey , $ apiSecret , $ options = array ())
4350 {
51+ $ validateKeys = true ;
52+ Validators::validateVonageJwtArguments ($ options );
53+ $ apiUrl = 'https://api.opentok.com ' ;
54+
55+ if (array_key_exists ('application_id ' , $ options ) && array_key_exists ('private_key_path ' , $ options )) {
56+ $ validateKeys = false ;
57+ $ apiUrl = 'https://video.api.vonage.com ' ;
58+ }
59+
4460 // unpack optional arguments (merging with default values) into named variables
4561 $ defaults = array (
46- 'apiUrl ' => ' https://api.opentok.com ' ,
62+ 'apiUrl ' => $ apiUrl ,
4763 'client ' => null ,
48- 'timeout ' => null // In the future we should set this to 2
64+ 'timeout ' => null , // In the future we should set this to 2
65+ 'application_id ' => null ,
66+ 'private_key_path ' => null ,
4967 );
5068
5169 $ this ->options = array_merge ($ defaults , array_intersect_key ($ options , $ defaults ));
5270
5371 list ($ apiUrl , $ client , $ timeout ) = array_values ($ this ->options );
5472
5573 // validate arguments
56- Validators::validateApiKey ($ apiKey );
57- Validators::validateApiSecret ($ apiSecret );
74+ if ($ validateKeys ) {
75+ Validators::validateApiKey ($ apiKey );
76+ Validators::validateApiSecret ($ apiSecret );
77+ }
78+
5879 Validators::validateApiUrl ($ apiUrl );
5980 Validators::validateClient ($ client );
6081 Validators::validateDefaultTimeout ($ timeout );
@@ -116,9 +137,16 @@ public function __construct($apiKey, $apiSecret, $options = array())
116137 * @param bool $legacy By default, OpenTok uses SHA256 JWTs for authentication. Switching
117138 * legacy to true will create a deprecated T1 token for backwards compatibility.
118139 *
140+ * Optionally, you can set $vonage to true and it will generate a Vonage Video token if you are using
141+ * the shim behaviour.
142+ *
119143 * @return string The token string.
120144 */
121- public function generateToken (string $ sessionId , array $ options = array (), bool $ legacy = false ): string
145+ public function generateToken (
146+ string $ sessionId ,
147+ array $ options = array (),
148+ bool $ legacy = false
149+ ): string
122150 {
123151 // Note, JWT generation disabled due to a backend bug regarding `exp` claims being mandatory - CRT
124152 // if ($legacy) {
0 commit comments