Skip to content

Commit

Permalink
Add streams to sip dial
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Oct 16, 2023
1 parent 5d255be commit cf456a4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/OpenTok/OpenTok.php
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,8 @@ public function dial($sessionId, $token, $sipUri, $options = [])
'secure' => true,
'from' => null,
'video' => false,
'observeForceMute' => false
'observeForceMute' => false,
'streams' => null
);

$options = array_merge($defaults, array_intersect_key($options, $defaults));
Expand Down
6 changes: 5 additions & 1 deletion src/OpenTok/Util/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ public function setStreamClassLists($sessionId, $payload)
* @param string $sessionId
* @param string $token
* @param string $sipUri
* @param array{secure: bool, headers?: array<string, string>, auth?: array{username: string, password: string}, from?: string, video?: boolean} $options
* @param array{secure: bool, headers?: array<string, string>, auth?: array{username: string, password: string}, from?: string, video?: boolean, streams?: array} $options
* @return array{id: string, streamId: string, connectId: string}
* @throws AuthenticationException
* @throws DomainException
Expand Down Expand Up @@ -726,6 +726,10 @@ public function dial($sessionId, $token, $sipUri, $options)
$body['sip']['video'] = (bool) $options['video'];
}

if (array_key_exists('streams', $options)) {
$body['sip']['streams'] = $options['streams'];
}

// set up the request
$request = new Request('POST', '/v2/project/' . $this->apiKey . '/call');

Expand Down
34 changes: 34 additions & 0 deletions tests/OpenTokTest/OpenTokTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2402,6 +2402,40 @@ public function testSipCallVideo(): void
$this->assertEquals(true, $body->sip->video);
}

public function testSipCallStreams(): void
{
$this->setupOTWithMocks([[
'code' => 200,
'headers' => [
'Content-Type' => 'application/json'
],
'path' => 'v2/project/APIKEY/dial'
]]);

$sessionId = '1_MX4xMjM0NTY3OH4-VGh1IEZlYiAyNyAwNDozODozMSBQU1QgMjAxNH4wLjI0NDgyMjI';
$bogusToken = 'T1==TEST';
$bogusSipUri = 'sip:john@doe.com';

$options = [
'video' => true,
'streams' => ['stream1', 'stream2']
];

$sipCall = $this->opentok->dial($sessionId, $bogusToken, $bogusSipUri, $options);

$this->assertInstanceOf('OpenTok\SipCall', $sipCall);
$this->assertNotNull($sipCall->id);
$this->assertNotNull($sipCall->connectionId);
$this->assertNotNull($sipCall->streamId);

$this->assertCount(1, $this->historyContainer);
$request = $this->historyContainer[0]['request'];

$body = json_decode($request->getBody());
$this->assertEquals(true, $body->sip->video);
$this->assertEquals('stream1', $body->sip->streams[0]);
}

public function testSipCallVideoWithObserveForceMute(): void
{
$this->setupOTWithMocks([[
Expand Down

0 comments on commit cf456a4

Please sign in to comment.