From cf456a4fd3d81820fb9dd70e0a43c2671c566957 Mon Sep 17 00:00:00 2001 From: James Seconde Date: Mon, 16 Oct 2023 12:41:51 +0100 Subject: [PATCH] Add streams to sip dial --- src/OpenTok/OpenTok.php | 3 ++- src/OpenTok/Util/Client.php | 6 +++++- tests/OpenTokTest/OpenTokTest.php | 34 +++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/OpenTok/OpenTok.php b/src/OpenTok/OpenTok.php index a33e394..c061249 100644 --- a/src/OpenTok/OpenTok.php +++ b/src/OpenTok/OpenTok.php @@ -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)); diff --git a/src/OpenTok/Util/Client.php b/src/OpenTok/Util/Client.php index 76606ec..9771b33 100755 --- a/src/OpenTok/Util/Client.php +++ b/src/OpenTok/Util/Client.php @@ -690,7 +690,7 @@ public function setStreamClassLists($sessionId, $payload) * @param string $sessionId * @param string $token * @param string $sipUri - * @param array{secure: bool, headers?: array, auth?: array{username: string, password: string}, from?: string, video?: boolean} $options + * @param array{secure: bool, headers?: array, 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 @@ -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'); diff --git a/tests/OpenTokTest/OpenTokTest.php b/tests/OpenTokTest/OpenTokTest.php index 4dbacfe..00bb622 100644 --- a/tests/OpenTokTest/OpenTokTest.php +++ b/tests/OpenTokTest/OpenTokTest.php @@ -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([[