Skip to content

Commit 5806f19

Browse files
committed
Added SIP Video support
1 parent 1bf0c0f commit 5806f19

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

src/OpenTok/OpenTok.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ public function dial($sessionId, $token, $sipUri, $options = [])
743743
'headers' => [],
744744
'secure' => true,
745745
'from' => null,
746+
'video' => false,
746747
);
747748
$options = array_merge($defaults, array_intersect_key($options, $defaults));
748749
list($headers, $secure, $from) = array_values($options);

src/OpenTok/Util/Client.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenTok\Util;
44

5+
use Exception as GlobalException;
56
use OpenTok\Layout;
67
use Firebase\JWT\JWT;
78
use OpenTok\MediaMode;
@@ -13,6 +14,7 @@
1314
use Psr\Http\Message\RequestInterface;
1415
use OpenTok\Exception\ArchiveException;
1516
use GuzzleHttp\Exception\ClientException;
17+
use GuzzleHttp\Exception\GuzzleException;
1618
use GuzzleHttp\Exception\ServerException;
1719
use OpenTok\Exception\BroadcastException;
1820
use GuzzleHttp\Exception\RequestException;
@@ -475,7 +477,18 @@ public function setStreamClassLists($sessionId, $payload)
475477
}
476478
}
477479

478-
480+
/**
481+
* @param string $sessionId
482+
* @param string $token
483+
* @param string $sipUri
484+
* @param array{secure: bool, headers?: array<string, string>, auth?: array{username: string, password: string}, from?: string, video?: boolean} $options
485+
* @return array{id: string, streamId: string, connectId: string}
486+
* @throws AuthenticationException
487+
* @throws DomainException
488+
* @throws UnexpectedValueException
489+
* @throws GlobalException
490+
* @throws GuzzleException
491+
*/
479492
public function dial($sessionId, $token, $sipUri, $options)
480493
{
481494
$body = array(
@@ -487,17 +500,22 @@ public function dial($sessionId, $token, $sipUri, $options)
487500
)
488501
);
489502

490-
if (isset($options) && array_key_exists('headers', $options) && count($options['headers']) > 0) {
503+
if (array_key_exists('headers', $options) && count($options['headers']) > 0) {
491504
$body['sip']['headers'] = $options['headers'];
492505
}
493506

494-
if (isset($options) && array_key_exists('auth', $options)) {
507+
if (array_key_exists('auth', $options)) {
495508
$body['sip']['auth'] = $options['auth'];
496509
}
497-
if (isset($options) && array_key_exists('from', $options)) {
510+
511+
if (array_key_exists('from', $options)) {
498512
$body['sip']['from'] = $options['from'];
499513
}
500514

515+
if (array_key_exists('video', $options)) {
516+
$body['sip']['video'] = (bool) $options['video'];
517+
}
518+
501519
// set up the request
502520
$request = new Request('POST', '/v2/project/' . $this->apiKey . '/call');
503521

@@ -510,6 +528,7 @@ public function dial($sessionId, $token, $sipUri, $options)
510528
} catch (\Exception $e) {
511529
$this->handleException($e);
512530
}
531+
513532
return $sipJson;
514533
}
515534

tests/OpenTokTest/OpenTokTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,37 @@ public function testSipCallFrom()
16331633
$this->assertEquals($from, $body->sip->from);
16341634
}
16351635

1636+
public function testSipCallVideo()
1637+
{
1638+
// Arrange
1639+
$this->setupOTWithMocks([[
1640+
'code' => 200,
1641+
'headers' => [
1642+
'Content-Type' => 'application/json'
1643+
],
1644+
'path' => 'v2/project/APIKEY/dial'
1645+
]]);
1646+
1647+
$sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI';
1648+
$bogusToken = 'T1==TEST';
1649+
$bogusSipUri = 'sip:[email protected]';
1650+
1651+
// Act
1652+
$sipCall = $this->opentok->dial($sessionId, $bogusToken, $bogusSipUri, ['video' => true]);
1653+
1654+
// Assert
1655+
$this->assertInstanceOf('OpenTok\SipCall', $sipCall);
1656+
$this->assertNotNull($sipCall->id);
1657+
$this->assertNotNull($sipCall->connectionId);
1658+
$this->assertNotNull($sipCall->streamId);
1659+
1660+
$this->assertCount(1, $this->historyContainer);
1661+
$request = $this->historyContainer[0]['request'];
1662+
1663+
$body = json_decode($request->getBody());
1664+
$this->assertEquals(true, $body->sip->video);
1665+
}
1666+
16361667
public function testSignalData()
16371668
{
16381669
// Arrange

0 commit comments

Comments
 (0)