Skip to content

Commit 458623c

Browse files
author
Guillermo López Leal
committed
OPENTOK-35108 Add from support on SIP calls
1 parent 1caa078 commit 458623c

File tree

7 files changed

+54
-3
lines changed

7 files changed

+54
-3
lines changed

sample/SipCall/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Next, input your own API Key, API Secret, and SIP configuration into the `run-de
1919
export SIP_USERNAME=
2020
export SIP_PASSWORD=
2121
export SIP_SECURE=false
22+
2223
```
2324

2425
Finally, start the PHP CLI development server (requires PHP >= 5.4) using the `run-demo` script

sample/SipCall/run-demo

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ then
1111
export SIP_USERNAME=
1212
export SIP_PASSWORD=
1313
export SIP_SECURE=false
14+
15+
# SIP from (optional)
16+
1417
fi
1518

1619
if [ -d "cache" ]

sample/SipCall/run-demo.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ SET SIP_USERNAME=
1515
SET SIP_PASSWORD=
1616
SET SIP_SECURE=false
1717

18+
:: SIP from (optional)
19+
SET SIP_FROM=
20+
1821
:skipdef
1922

2023
RD /q /s cache

sample/SipCall/web/index.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
'uri' => getenv('SIP_URI'),
5050
'username' => getenv('SIP_USERNAME'),
5151
'password' => getenv('SIP_PASSWORD'),
52-
'secure' => (getenv('SIP_SECURE') === 'true')
52+
'secure' => (getenv('SIP_SECURE') === 'true'),
53+
'from' => getenv('SIP_FROM'),
5354
);
5455

5556
// Configure routes
@@ -79,7 +80,8 @@
7980

8081
// create the options parameter
8182
$options = array(
82-
'secure' => $app->sip['secure']
83+
'secure' => $app->sip['secure'],
84+
'from' => $app->$sip['from'],
8385
);
8486
if ($app->sip['username'] !== false) {
8587
$options['auth'] = array('username' => $app->sip['username'], 'password' => $app->sip['password']);

src/OpenTok/OpenTok.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,10 @@ public function dial($sessionId, $token, $sipUri, $options=array())
531531
'auth' => null,
532532
'headers' => null,
533533
'secure' => true,
534+
'from' => null,
534535
);
535536
$options = array_merge($defaults, array_intersect_key($options, $defaults));
536-
list($headers, $secure) = array_values($options);
537+
list($headers, $secure, $from) = array_values($options);
537538

538539
// validate arguments
539540
Validators::validateSessionIdBelongsToKey($sessionId, $this->apiKey);

src/OpenTok/Util/Client.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ public function dial($sessionId, $token, $sipUri, $options)
262262
if (isset($options) && array_key_exists('auth', $options)) {
263263
$body['sip']['auth'] = $options['auth'];
264264
}
265+
if (isset($options) && array_key_exists('from', $options)) {
266+
$body['sip']['from'] = $options['from'];
267+
}
265268

266269
// set up the request
267270
$request = $this->post('/v2/project/'.$this->apiKey.'/call');

tests/OpenTok/OpenTokTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,5 +1232,43 @@ public function testFailedSipCall()
12321232
$this->assertNull($sipCall);
12331233
}
12341234
}
1235+
1236+
public function testSipCallFrom()
1237+
{
1238+
// Arrange
1239+
$mock = new MockPlugin();
1240+
$response = MockPlugin::getMockFile(
1241+
self::$mockBasePath . 'v2/project/APIKEY/dial'
1242+
);
1243+
$mock->addResponse($response);
1244+
$this->client->addSubscriber($mock);
1245+
1246+
$sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI';
1247+
$bogusApiKey = '12345678';
1248+
$bogusApiSecret = '0123456789abcdef0123456789abcdef0123456789';
1249+
$bogusToken = 'T1==TEST';
1250+
$bogusSipUri = 'sip:[email protected]';
1251+
$opentok = new OpenTok($bogusApiKey, $bogusApiSecret);
1252+
1253+
$from = "[email protected]";
1254+
1255+
// Act
1256+
$sipCall = $this->opentok->dial($sessionId, $bogusToken, $bogusSipUri, array(
1257+
'from' => $from
1258+
));
1259+
1260+
// Assert
1261+
$this->assertInstanceOf('OpenTok\SipCall', $sipCall);
1262+
$this->assertNotNull($sipCall->id);
1263+
$this->assertNotNull($sipCall->connectionId);
1264+
$this->assertNotNull($sipCall->streamId);
1265+
1266+
$requests = $mock->getReceivedRequests();
1267+
$this->assertCount(1, $requests);
1268+
$request = $requests[0];
1269+
1270+
$body = json_decode($request->getBody());
1271+
$this->assertEquals($from, $body->sip->from);
1272+
}
12351273
}
12361274
/* vim: set ts=4 sw=4 tw=100 sts=4 et :*/

0 commit comments

Comments
 (0)