Skip to content

Commit 1493c01

Browse files
authored
Merge pull request #296 from opentok/dev
Release merge for 4.10.0
2 parents cf930fc + 6d414a0 commit 1493c01

29 files changed

+1351
-177
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ vendor/
66
phpunit.xml
77
sample/*/vendor/
88
sample/*/cache/
9+
docs/
10+
.phpdoc/
11+
phpDocumentor*
12+
.phpunit.result.cache
913
.idea/*

DEVELOPING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ This project's tests are written as PHPUnit test cases. Common tasks:
2020

2121
* `./vendor/bin/phing test` - run the test suite.
2222

23+
### Building docs
24+
25+
Install [PhpDocumentor](https://docs.phpdoc.org/). Add it to the project root directory.
26+
Then run `php phpDocumentor.phar --config phpdoc.dist.xml`.
27+
28+
The current reference docs were built with PhpDocumentor 3.3.0.
29+
2330
### Releasing
2431

2532
In order to create a release, the following should be completed in order.

README.md

Lines changed: 24 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44

55
<img src="https://assets.tokbox.com/img/vonage/Vonage_VideoAPI_black.svg" height="48px" alt="Tokbox is now known as Vonage" />
66

7-
The OpenTok PHP SDK lets you generate [sessions](http://tokbox.com/developer/guides/create-session/) and
8-
[tokens](http://tokbox.com/developer/guides/create-token/) for [OpenTok](http://www.tokbox.com/)
9-
applications, and [archive](http://tokbox.com/developer/guides/archiving/) sessions.
10-
It also includes methods for working with OpenTok
11-
[archives](http://tokbox.com/developer/guides/archiving), working with OpenTok
12-
[SIP interconnect](http://tokbox.com/developer/guides/sip), and
13-
[disconnecting clients from sessions](http://tokbox.com/developer/guides/moderation/rest/).
7+
The OpenTok PHP SDK provides methods for:
8+
9+
* Generating
10+
[sessions](https://tokbox.com/developer/guides/create-session/) and
11+
[tokens](https://tokbox.com/developer/guides/create-token/) for
12+
[OpenTok](https://www.tokbox.com/) applications that run on the .NET platform
13+
* Working with [OpenTok archives](https://tokbox.com/opentok/tutorials/archiving)
14+
* Working with [OpenTok live streaming broadcasts](https://tokbox.com/developer/guides/broadcast/live-streaming/)
15+
* Working with [OpenTok SIP interconnect](https://tokbox.com/developer/guides/sip)
16+
* [Sending signals to clients connected to a session](https://www.tokbox.com/developer/guides/signaling/)
17+
* [Disconnecting clients from sessions](https://tokbox.com/developer/guides/moderation/rest/)
18+
* [Forcing clients in a session to disconnect or mute published audio](https://tokbox.com/developer/guides/moderation/)
1419

1520
## Installation
1621

@@ -370,6 +375,17 @@ use OpenTok\OpenTok;
370375
$opentok->forceDisconnect($sessionId, $connectionId);
371376
```
372377

378+
### Forcing clients in a session mute published audio
379+
380+
You can force the publisher of a specific stream to stop publishing audio using the
381+
`Opentok.forceMuteStream($sessionId, $stream)` method.
382+
383+
You can force the publisher of all streams in a session (except for an optional list of streams)
384+
to stop publishing audio using the `Opentok.forceMuteAll($sessionId, $excludedStreamIds)` method.
385+
You can then disable the mute state of the session by calling the
386+
`Opentok.DisableForceMute(sessionId)` or `Opentok.DisableForceMuteAsync(sessionId)`
387+
method.
388+
373389
### Sending Signals
374390

375391
Once a Session is created, you can send signals to everyone in the session or to a specific connection.
@@ -411,7 +427,7 @@ $opentok->signal($sessionId, $signalPayload);
411427
For more information, see the [OpenTok signaling developer
412428
guide](https://tokbox.com/developer/guides/signaling/).
413429

414-
## Working with SIP Interconnect
430+
### Working with SIP Interconnect
415431

416432
You can add an audio-only stream from an external third-party SIP gateway using the SIP
417433
Interconnect feature. This requires a SIP URI, the session ID you wish to add the audio-only
@@ -441,59 +457,6 @@ $opentok->dial($sessionId, $token, $sipUri, $options);
441457
For more information, see the [OpenTok SIP Interconnect developer
442458
guide](https://tokbox.com/developer/guides/sip/).
443459

444-
## Force Disconnect
445-
446-
Your application server can disconnect a client from an OpenTok session by calling the `forceDisconnect($sessionId, $connectionId)`
447-
method of the `OpenTok\OpenTok` class.
448-
449-
```php
450-
use OpenTok\OpenTok;
451-
452-
// Force disconnect a client connection
453-
$opentok->forceDisconnect($sessionId, $connectionId);
454-
```
455-
456-
## Sending Signals
457-
458-
Once a Session is created, you can send signals to everyone in the session or to a specific connection.
459-
You can send a signal by calling the `signal($sessionId, $payload, $connectionId)` method of the
460-
`OpenTok\OpenTok` class.
461-
462-
The `$sessionId` parameter is the session ID of the session.
463-
464-
The `$payload` parameter is an associative array used to set the
465-
following:
466-
467-
- `data` (string) -- The data string for the signal. You can send a maximum of 8kB.
468-
469-
- `type` (string) -- &mdash; (Optional) The type string for the signal. You can send a maximum of 128 characters, and only the following characters are allowed: A-Z, a-z, numbers (0-9), '-', '\_', and '~'.
470-
471-
The `$connectionId` parameter is an optional string used to specify the connection ID of
472-
a client connected to the session. If you specify this value, the signal is sent to
473-
the specified client. Otherwise, the signal is sent to all clients connected to the session.
474-
475-
```php
476-
use OpenTok\OpenTok;
477-
478-
// Send a signal to a specific client
479-
$signalPayload = array(
480-
'data' => 'some signal message',
481-
'type' => 'signal type'
482-
);
483-
$connectionId = 'da9cb410-e29b-4c2d-ab9e-fe65bf83fcaf';
484-
$opentok->signal($sessionId, $signalPayload, $connectionId);
485-
486-
// Send a signal to everyone in the session
487-
$signalPayload = array(
488-
'data' => 'some signal message',
489-
'type' => 'signal type'
490-
);
491-
$opentok->signal($sessionId, $signalPayload);
492-
```
493-
494-
For more information, see the [OpenTok signaling developer
495-
guide](https://tokbox.com/developer/guides/signaling/).
496-
497460
## Samples
498461

499462
There are three sample applications included in this repository. To get going as fast as possible, clone the whole

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"ext-xml": "*",
3333
"johnstevenson/json-works": "~1.1",
3434
"firebase/php-jwt": "^5.0",
35-
"guzzlehttp/guzzle": "~6.0|~7.0"
35+
"guzzlehttp/guzzle": "~6.0|~7.0",
36+
"ext-json": "*"
3637
},
3738
"require-dev": {
3839
"phpunit/phpunit": "^7.4|^8.0",

phpdoc.dist.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<phpdocumentor
3+
configVersion="3"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns="https://www.phpdoc.org"
6+
xsi:noNamespaceSchemaLocation="https://docs.phpdoc.org/latest/phpdoc.xsd"
7+
>
8+
<paths>
9+
<output>docs</output>
10+
</paths>
11+
<version number="latest">
12+
<api>
13+
<source dsn=".">
14+
<path>src</path>
15+
</source>
16+
<ignore hidden="true" symlinks="true">
17+
<path>src/OpenTok/Util</path>
18+
</ignore>
19+
</api>
20+
</version>
21+
</phpdocumentor>

src/OpenTok/Archive.php

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* The time at which the archive was created, in milliseconds since the UNIX epoch.
1515
*
1616
* @property string $duration
17-
* The duration of the archive, in milliseconds.
17+
* The duration of the archive, in seconds.
1818
*
1919
* @property bool $hasVideo
2020
* Whether the archive has a video track (<code>true</code>) or not (<code>false</code>).
@@ -49,6 +49,17 @@
4949
* @property string $size
5050
* The size of the MP4 file. For archives that have not been generated, this value is set to 0.
5151
*
52+
* @property string $streamMode
53+
* Whether streams included in the archive are selected automatically (<code>StreamMode.AUTO</code>) or
54+
* manually (<code>StreamMode.MANUAL</code>). When streams are selected automatically (<code>StreamMode.AUTO</code>),
55+
* all streams in the session can be included in the archive. When streams are selected manually
56+
* (<code>StreamMode.MANUAL</code>), you specify streams to be included based on calls to the
57+
* <code>Archive.addStreamToArchive()</code> and <code>Archive.removeStreamFromArchive()</code> methods.
58+
* With manual mode, you can specify whether a stream's audio, video, or both are included in the
59+
* archive. In both automatic and manual modes, the archive composer includes streams based on
60+
* <a href="https://tokbox.com/developer/guides/archive-broadcast-layout/#stream-prioritization-rules">stream
61+
* prioritization rules</a>.
62+
*
5263
* @property string $status
5364
* The status of the archive, which can be one of the following:
5465
*
@@ -95,14 +106,16 @@ public function __construct($archiveData, $options = array())
95106
'apiKey' => null,
96107
'apiSecret' => null,
97108
'apiUrl' => 'https://api.opentok.com',
98-
'client' => null
109+
'client' => null,
110+
'streamMode' => StreamMode::AUTO
99111
);
100112
$options = array_merge($defaults, array_intersect_key($options, $defaults));
101-
list($apiKey, $apiSecret, $apiUrl, $client) = array_values($options);
113+
list($apiKey, $apiSecret, $apiUrl, $client, $streamMode) = array_values($options);
102114

103115
// validate params
104116
Validators::validateArchiveData($archiveData);
105117
Validators::validateClient($client);
118+
Validators::validateHasStreamMode($streamMode);
106119

107120
$this->data = $archiveData;
108121

@@ -137,6 +150,7 @@ public function __get($name)
137150
case 'hasAudio':
138151
case 'outputMode':
139152
case 'resolution':
153+
case 'streamMode':
140154
return $this->data[$name];
141155
default:
142156
return null;
@@ -202,6 +216,65 @@ public function toJson()
202216
return json_encode($this->jsonSerialize());
203217
}
204218

219+
/**
220+
* Adds a stream to a currently running archive that was started with the
221+
* the streamMode set to StreamMode.Manual. You can call the method
222+
* repeatedly with the same stream ID, to toggle the stream's audio or video in the archive.
223+
*
224+
* @param String $streamId The stream ID.
225+
* @param Boolean $hasAudio Whether the archive should include the stream's audio (true, the default)
226+
* or not (false).
227+
* @param Boolean $hasVideo Whether the archive should include the stream's video (true, the default)
228+
* or not (false).
229+
*
230+
* @return Boolean Returns true on success.
231+
*/
232+
public function addStreamToArchive(string $streamId, bool $hasAudio, bool $hasVideo): bool
233+
{
234+
if ($this->streamMode === StreamMode::AUTO) {
235+
throw new InvalidArgumentException('Cannot add stream to an Archive in auto stream mode');
236+
}
237+
238+
if ($hasAudio === false && $hasVideo === false) {
239+
throw new InvalidArgumentException('Both hasAudio and hasVideo cannot be false');
240+
}
241+
242+
if ($this->client->addStreamToArchive(
243+
$this->data['id'],
244+
$streamId,
245+
$hasVideo,
246+
$hasVideo
247+
)) {
248+
return true;
249+
}
250+
251+
return false;
252+
}
253+
254+
/**
255+
* Removes a stream from a currently running archive that was started with the
256+
* the streamMode set to StreamMode.Manual.
257+
*
258+
* @param String $streamId The stream ID.
259+
*
260+
* @return Boolean Returns true on success.
261+
*/
262+
public function removeStreamFromArchive(string $streamId): bool
263+
{
264+
if ($this->streamMode === StreamMode::AUTO) {
265+
throw new InvalidArgumentException('Cannot remove stream to an Archive in auto stream mode');
266+
}
267+
268+
if ($this->client->removeStreamFromArchive(
269+
$this->data['id'],
270+
$streamId
271+
)) {
272+
return true;
273+
}
274+
275+
return false;
276+
}
277+
205278
/**
206279
* Returns an associative array representation of this Archive object.
207280
* @deprecated 3.0.0 A more standard name for this method is supplied by JsonSerializable

src/OpenTok/ArchiveList.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public function totalCount()
6767

6868
/**
6969
* Returns an array of Archive objects.
70+
*
71+
* @return Archive[]
7072
*/
7173
public function getItems()
7274
{

src/OpenTok/ArchiveMode.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ abstract class ArchiveMode extends BasicEnum
1717
* The session is not archived automatically. To archive the session, you can call the
1818
* \OpenTok\OpenTok->startArchive() method.
1919
*/
20-
const MANUAL = 'manual';
20+
public const MANUAL = 'manual';
2121
/**
22-
* The session is archived automatically (as soon as there are clients publishing streams
22+
* The session is archived automatically (as soon as there are clients connected
2323
* to the session).
2424
*/
25-
const ALWAYS = 'always';
25+
public const ALWAYS = 'always';
2626
}

0 commit comments

Comments
 (0)