Skip to content

Commit 9eee7c1

Browse files
committed
Merge branch 'master' into bklima-ss-patch-1
2 parents 406c1a0 + 2c7c370 commit 9eee7c1

34 files changed

+1024
-66
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Add this package (`opentok/opentok`) to your `composer.json` file, or just run t
1616
command line:
1717

1818
```
19-
$ ./composer.phar require opentok/opentok 2.3.x
19+
$ ./composer.phar require opentok/opentok 2.4.x
2020
```
2121

2222
## Manually:
@@ -52,7 +52,7 @@ $opentok = new OpenTok($apiKey, $apiSecret);
5252
To create an OpenTok Session, use the `createSession($options)` method of the
5353
`OpenTok\OpenTok` class. The `$options` parameter is an optional array used to specify the following:
5454

55-
* Setting whether the session will use the OpenTok Media Router or attempt send streams directly
55+
* Setting whether the session will use the OpenTok Media Router or attempt to send streams directly
5656
between clients.
5757

5858
* Setting whether the session will automatically create archives (implies use of routed session)
@@ -141,7 +141,7 @@ $archive = $opentok->startArchive($sessionId, $archiveOptions);
141141
$archiveId = $archive->id;
142142
```
143143

144-
Setting the output mode to `OutputMode::INDIVIDUAL` setting causes each stream in the archive to be recorded to its own individual file. The `OutputMode::COMPOSED` setting (the default) causes all streams in the archive are recorded to a single (composed) file.
144+
Setting the output mode to `OutputMode::INDIVIDUAL` setting causes each stream in the archive to be recorded to its own individual file. The `OutputMode::COMPOSED` setting (the default) causes all streams in the archive to be recorded to a single (composed) file.
145145

146146
You can stop the recording of a started Archive using the `stopArchive($archiveId)` method of the
147147
`OpenTok\OpenTok` object. You can also do this using the `stop()` method of the

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
},
3636
"require-dev": {
3737
"phpunit/phpunit": "~4.1",
38-
"phing/phing": "dev-master"
38+
"phing/phing": "~2.15.2"
3939
},
4040
"autoload": {
4141
"psr-4": {

sample/SipCall/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ Finally, start the PHP CLI development server (requires PHP >= 5.4) using the `r
2727
$ ./run-demo
2828
```
2929

30-
Visit <http://localhost:8080> in your browser. Open it again in a second window. Smile! You've just
31-
set up a group chat. You can
30+
Visit <http://localhost:8080> in your browser.
3231

3332
## Walkthrough
3433

src/OpenTok/Archive.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
* The API key associated with the archive.
3939
*
4040
* @property string $reason
41-
* For archives with the status "stopped", this can be set to "maximum duration
42-
* exceeded", "maximum idle time exceeded", "session ended", "user initiated". For archives with
43-
* the status "failed", this can be set to "failure".
41+
* For archives with the status "stopped" or "failed", this string describes the reason
42+
* the archive stopped (such as "maximum duration exceeded") or failed.
4443
*
4544
* @property string $sessionId
4645
* The session ID of the OpenTok session associated with this archive.
@@ -76,6 +75,7 @@
7675
* 10 minutes. To generate a new URL, call the Archive.listArchives() or OpenTok.getArchive() method.
7776
*/
7877
class Archive {
78+
// NOTE: after PHP 5.3.0 support is dropped, the class can implement JsonSerializable
7979

8080
/** @internal */
8181
private $data;
@@ -196,16 +196,23 @@ public function delete()
196196
*/
197197
public function toJson()
198198
{
199-
return json_encode($this->data);
199+
return json_encode($this->jsonSerialize());
200200
}
201201

202202
/**
203203
* Returns an associative array representation of this Archive object.
204+
* @deprecated 3.0.0 A more standard name for this method is supplied by JsonSerializable
205+
* @see Archive::jsonSerialize() for a method with the same behavior
204206
*/
205207
public function toArray()
206208
{
207209
return $this->data;
208210
}
211+
212+
public function jsonSerialize()
213+
{
214+
return $this->data;
215+
}
209216
}
210217

211218
/* vim: set ts=4 sw=4 tw=100 sts=4 et :*/

src/OpenTok/Broadcast.php

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
namespace OpenTok;
4+
5+
use OpenTok\Exception\BroadcastDomainException;
6+
use OpenTok\Exception\BroadcastUnexpectedValueException;
7+
use OpenTok\Util\Validators;
8+
9+
class Broadcast {
10+
// NOTE: after PHP 5.3.0 support is dropped, the class can implement JsonSerializable
11+
12+
private $data;
13+
private $isStopped = false;
14+
private $client;
15+
16+
public function __construct($broadcastData, $options = array()) {
17+
// unpack optional arguments (merging with default values) into named variables
18+
$defaults = array(
19+
'apiKey' => null,
20+
'apiSecret' => null,
21+
'apiUrl' => 'https://api.opentok.com',
22+
'client' => null,
23+
'isStopped' => false
24+
);
25+
$options = array_merge($defaults, array_intersect_key($options, $defaults));
26+
list($apiKey, $apiSecret, $apiUrl, $client, $isStopped) = array_values($options);
27+
28+
// validate params
29+
Validators::validateBroadcastData($broadcastData);
30+
Validators::validateClient($client);
31+
32+
$this->data = $broadcastData;
33+
34+
$this->isStopped = $isStopped;
35+
36+
$this->client = isset($client) ? $client : new Client();
37+
if (!$this->client->isConfigured()) {
38+
Validators::validateApiKey($apiKey);
39+
Validators::validateApiSecret($apiSecret);
40+
Validators::validateApiUrl($apiUrl);
41+
42+
$this->client->configure($apiKey, $apiSecret, $apiUrl);
43+
}
44+
}
45+
46+
public function __get($name)
47+
{
48+
switch ($name) {
49+
case 'createdAt':
50+
case 'updatedAt':
51+
case 'id':
52+
case 'partnerId':
53+
case 'sessionId':
54+
case 'broadcastUrls':
55+
return $this->data[$name];
56+
break;
57+
case 'hlsUrl':
58+
return $this->data['broadcastUrls']['hls'];
59+
break;
60+
case 'isStopped':
61+
return $this->isStopped;
62+
break;
63+
default:
64+
return null;
65+
}
66+
}
67+
68+
public function stop()
69+
{
70+
if ($this->isStopped) {
71+
throw new BroadcastDomainException(
72+
'You cannot stop a broadcast which is already stopped.'
73+
);
74+
}
75+
76+
$broadcastData = $this->client->stopBroadcast($this->data['id']);
77+
78+
try {
79+
Validators::validateBroadcastData($broadcastData);
80+
} catch (InvalidArgumentException $e) {
81+
throw new BroadcastUnexpectedValueException('The broadcast JSON returned after stopping was not valid', null, $e);
82+
}
83+
84+
$this->data = $broadcastData;
85+
return $this;
86+
}
87+
88+
// TODO: not yet implemented by the platform
89+
// public function getLayout()
90+
// {
91+
// $layoutData = $this->client->getLayout($this->id, 'broadcast');
92+
// return Layout::fromData($layoutData);
93+
// }
94+
95+
public function updateLayout($layout)
96+
{
97+
Validators::validateLayout($layout);
98+
99+
// TODO: platform implementation did not meet API review spec
100+
// $layoutData = $this->client->updateLayout($this->id, $layout, 'broadcast');
101+
// return Layout::fromData($layoutData);
102+
103+
$this->client->updateLayout($this->id, $layout, 'broadcast');
104+
}
105+
106+
public function jsonSerialize()
107+
{
108+
return $this->data;
109+
}
110+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* Defines the exception thrown when you use an invalid API or secret and call a broadcast method.
7+
*/
8+
class BroadcastAuthenticationException extends \OpenTok\Exception\AuthenticationException implements \OpenTok\Exception\BroadcastException
9+
{
10+
}
11+
/* vim: set ts=4 sw=4 tw=100 sts=4 et :*/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
// TODO: this kind of exception has a detailed message from the HTTP response, use it.
6+
/**
7+
* Defines an exception thrown when a call to a broadcast method results in an error response from
8+
* the server.
9+
*/
10+
class BroadcastDomainException extends \OpenTok\Exception\DomainException implements \OpenTok\Exception\BroadcastException
11+
{
12+
}
13+
/* vim: set ts=4 sw=4 tw=100 sts=4 et :*/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* The interface used by all exceptions resulting from calls to the broadcast API.
7+
*/
8+
interface BroadcastException
9+
{
10+
}
11+
/* vim: set ts=4 sw=4 tw=100 sts=4 et :*/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* Defines an exception thrown when a call to a broadcast method results in an error due to an
7+
* unexpected value.
8+
*/
9+
class BroadcastUnexpectedValueException extends \OpenTok\Exception\UnexpectedValueException implements \OpenTok\Exception\BroadcastException
10+
{
11+
}
12+
/* vim: set ts=4 sw=4 tw=100 sts=4 et :*/

src/OpenTok/Layout.php

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace OpenTok;
4+
5+
use OpenTok\Util\Validators;
6+
7+
class Layout {
8+
// NOTE: after PHP 5.3.0 support is dropped, the class can implement JsonSerializable
9+
10+
private static $bestFit = null;
11+
private static $pip = null;
12+
private static $verticalPresentation = null;
13+
private static $horizontalPresentaton = null;
14+
15+
public static function getBestFit()
16+
{
17+
if (is_null(self::$bestFit)) {
18+
self::$bestFit = new Layout('bestFit');
19+
}
20+
return self::$bestFit;
21+
}
22+
23+
public static function getPIP()
24+
{
25+
if (is_null(self::$pip)) {
26+
self::$pip = new Layout('pip');
27+
}
28+
return self::$pip;
29+
}
30+
31+
public static function getVerticalPresentation()
32+
{
33+
if (is_null(self::$verticalPresentation)) {
34+
self::$verticalPresentation = new Layout('verticalPresentation');
35+
}
36+
return self::$verticalPresentation;
37+
}
38+
39+
public static function getHorizontalPresentation()
40+
{
41+
if (is_null(self::$horizontalPresentaton)) {
42+
self::$horizontalPresentaton = new Layout('horizontalPresentaton');
43+
}
44+
return self::$horizontalPresentaton;
45+
}
46+
47+
public static function createCustom($options)
48+
{
49+
// unpack optional arguments (merging with default values) into named variables
50+
// NOTE: the default value of stylesheet=null will not pass validation, this essentially
51+
// means that stylesheet is not optional. its still purposely left as part of the
52+
// $options argument so that it can become truly optional in the future.
53+
$defaults = array('stylesheet' => null);
54+
$options = array_merge($defaults, array_intersect_key($options, $defaults));
55+
list($stylesheet) = array_values($options);
56+
57+
// validate arguments
58+
Validators::validateLayoutStylesheet($stylesheet);
59+
60+
return new Layout('custom', $stylesheet);
61+
}
62+
63+
64+
public static function fromData($layoutData)
65+
{
66+
if (array_key_exists('stylesheet', $layoutData)) {
67+
return new Layout($layoutData['type'], $layoutData['stylesheet']);
68+
} else {
69+
return new Layout($layoutData['type']);
70+
}
71+
}
72+
73+
private $type;
74+
private $stylesheet;
75+
76+
private function __construct($type, $stylesheet = null)
77+
{
78+
$this->type = $type;
79+
$this->stylesheet = $stylesheet;
80+
}
81+
82+
public function jsonSerialize() {
83+
$data = array(
84+
'type' => $this->type
85+
);
86+
87+
// omit 'stylesheet' property unless it is explicitly defined
88+
if (isset($this->stylesheet)) {
89+
$data['stylesheet'] = $this->stylesheet;
90+
}
91+
return $data;
92+
}
93+
94+
public function toJson()
95+
{
96+
return json_encode($this->jsonSerialize());
97+
}
98+
}

0 commit comments

Comments
 (0)