Skip to content

Commit e1df9e5

Browse files
committed
changes default createSession to relayed session, fixes #52
1 parent ea2d9ea commit e1df9e5

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/OpenTok/OpenTok.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function generateToken($sessionId, $options = array())
181181
public function createSession($options=array())
182182
{
183183
// unpack optional arguments (merging with default values) into named variables
184-
$defaults = array('mediaMode' => MediaMode::ROUTED, 'location' => null);
184+
$defaults = array('mediaMode' => MediaMode::RELAYED, 'location' => null);
185185
$options = array_merge($defaults, array_intersect_key($options, $defaults));
186186
list($mediaMode, $location) = array_values($options);
187187

tests/OpenTok/OpenTokTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,50 @@ public function testFailsOnInvalidInitialization()
5454
// Assert
5555
}
5656

57+
public function testCreatesDefaultSession()
58+
{
59+
// Arrange
60+
$mock = new MockPlugin();
61+
$response = MockPlugin::getMockFile(
62+
self::$mockBasePath . 'session/create/relayed'
63+
);
64+
$mock->addResponse($response);
65+
$this->client->addSubscriber($mock);
66+
67+
// Act
68+
$session = $this->opentok->createSession();
69+
70+
// Assert
71+
$requests = $mock->getReceivedRequests();
72+
$this->assertCount(1, $requests);
73+
74+
$request = $requests[0];
75+
$this->assertEquals('POST', strtoupper($request->getMethod()));
76+
$this->assertEquals('/session/create', $request->getPath());
77+
$this->assertEquals('api.opentok.com', $request->getHost());
78+
$this->assertEquals('https', $request->getScheme());
79+
80+
$authString = $request->getHeader('X-TB-PARTNER-AUTH');
81+
$this->assertNotEmpty($authString);
82+
$this->assertEquals($this->API_KEY.':'.$this->API_SECRET, $authString);
83+
84+
// TODO: test the dynamically built User Agent string
85+
$userAgent = $request->getHeader('User-Agent');
86+
$this->assertNotEmpty($userAgent);
87+
$this->assertStringStartsWith('OpenTok-PHP-SDK/2.2.1-alpha.1', $userAgent->__toString());
88+
89+
$p2p_preference = $request->getPostField('p2p.preference');
90+
$this->assertEquals('enabled', $p2p_preference);
91+
92+
$this->assertInstanceOf('OpenTok\Session', $session);
93+
// NOTE: this is an actual sessionId from the recorded response, this doesn't correspond to
94+
// the API Key and API Secret used to create the session.
95+
$this->assertEquals(
96+
'2_MX4xNzAxMjYzMX4xMjcuMC4wLjF-V2VkIEZlYiAyNiAxODo1NzoyNCBQU1QgMjAxNH4wLjU0MDU4ODc0fg',
97+
$session->getSessionId()
98+
);
99+
}
100+
57101
public function testCreatesMediaRoutedAndLocationSession()
58102
{
59103
// Arrange

0 commit comments

Comments
 (0)