Skip to content

Commit f928145

Browse files
authored
Merge pull request #169 from digitaltsai/SIP
Makes the auth and headers for dial in the children of sip
2 parents c15e349 + e58229b commit f928145

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

sample/SipCall/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ Finally, start the PHP CLI development server (requires PHP >= 5.4) using the `r
2727
$ ./run-demo
2828
```
2929

30-
Visit <http://localhost:8080> in your browser. Open it again in a second window. Smile! You've just
31-
set up a group chat. You can
30+
Visit <http://localhost:8080> in your browser.
3231

3332
## Walkthrough
3433

src/OpenTok/Util/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ public function dial($sessionId, $token, $sipUri, $options)
233233
);
234234

235235
if (isset($options) && array_key_exists('headers', $options) && sizeof($options['headers']) > 0) {
236-
$body['headers'] = $options['headers'];
236+
$body['sip']['headers'] = $options['headers'];
237237
}
238238

239239
if (isset($options) && array_key_exists('auth', $options)) {
240-
$body['auth'] = $options['auth'];
240+
$body['sip']['auth'] = $options['auth'];
241241
}
242242

243243
// set up the request

tests/OpenTok/OpenTokTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,48 @@ public function testSipCall()
11181118
$this->assertNotNull($sipCall->streamId);
11191119
}
11201120

1121+
public function testSipCallWithAuth()
1122+
{
1123+
// Arrange
1124+
$mock = new MockPlugin();
1125+
$response = MockPlugin::getMockFile(
1126+
self::$mockBasePath . 'v2/partner/APIKEY/dial'
1127+
);
1128+
$mock->addResponse($response);
1129+
$this->client->addSubscriber($mock);
1130+
1131+
$sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI';
1132+
$bogusApiKey = '12345678';
1133+
$bogusApiSecret = '0123456789abcdef0123456789abcdef0123456789';
1134+
$bogusToken = 'T1==TEST';
1135+
$bogusSipUri = 'sip:[email protected]';
1136+
$opentok = new OpenTok($bogusApiKey, $bogusApiSecret);
1137+
1138+
$auth = array(
1139+
'username' => 'john',
1140+
'password' => 'doe'
1141+
);
1142+
1143+
// Act
1144+
$sipCall = $this->opentok->dial($sessionId, $bogusToken, $bogusSipUri, array(
1145+
'auth' => $auth
1146+
));
1147+
1148+
// Assert
1149+
$this->assertInstanceOf('OpenTok\SipCall', $sipCall);
1150+
$this->assertNotNull($sipCall->id);
1151+
$this->assertNotNull($sipCall->connectionId);
1152+
$this->assertNotNull($sipCall->streamId);
1153+
1154+
$requests = $mock->getReceivedRequests();
1155+
$this->assertCount(1, $requests);
1156+
$request = $requests[0];
1157+
1158+
$body = json_decode($request->getBody());
1159+
$this->assertEquals($auth['username'], $body->sip->auth->username);
1160+
$this->assertEquals($auth['password'], $body->sip->auth->password);
1161+
}
1162+
11211163
public function testFailedSipCall()
11221164
{
11231165
// Arrange

0 commit comments

Comments
 (0)