Skip to content

Commit cb6b39a

Browse files
author
Manik Sachdeva
authored
release (#222)
* release 4.2.0 and update branch
1 parent 35f7e5e commit cb6b39a

20 files changed

+892
-9
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,36 @@ $token = $session->generateToken(array(
112112
));
113113
```
114114

115+
## Working with Streams
116+
117+
You can get information about a stream by calling the `getStream($sessionId, $streamId)` method of the
118+
`OpenTok\OpenTok` class.
119+
120+
```php
121+
use OpenTok\Session;
122+
123+
// Get stream info from just a sessionId (fetched from a database)
124+
$stream = $opentok->getStream($sessionId, $streamId);
125+
126+
// Stream properties
127+
$stream->id; // string with the stream ID
128+
$stream->videoType; // string with the video type
129+
$stream->name; // string with the name
130+
$stream->layoutClassList; // array with the layout class list
131+
```
132+
133+
You can get information about all the streams in a session by calling the `listStreams($sessionId)` method of the
134+
`OpenTok\OpenTok` class.
135+
136+
```php
137+
use OpenTok\Session;
138+
139+
// Get list of streams from just a sessionId (fetched from a database)
140+
$streamList = $opentok->listStreams($sessionId);
141+
142+
$streamList->totalCount(); // total count
143+
```
144+
115145
## Working with Archives
116146

117147
You can only archive sessions that use the OpenTok Media Router
@@ -193,6 +223,58 @@ method (see "Creating Sessions," above).
193223
For more information on archiving, see the
194224
[OpenTok archiving](https://tokbox.com/opentok/tutorials/archiving/) programming guide.
195225

226+
## Force Disconnect
227+
228+
Your application server can disconnect a client from an OpenTok session by calling the `forceDisconnect($sessionId, $connectionId)`
229+
method of the `OpenTok\OpenTok` class.
230+
231+
```php
232+
use OpenTok\OpenTok;
233+
234+
// Force disconnect a client connection
235+
$opentok->forceDisconnect($sessionId, $connectionId);
236+
```
237+
## Sending Signals
238+
239+
Once a Session is created, you can send signals to everyone in the session or to a specific connection.
240+
You can send a signal by calling the `signal($sessionId, $payload, $connectionId)` method of the
241+
`OpenTok\OpenTok` class.
242+
243+
The `$sessionId` parameter is the session ID of the session.
244+
245+
The `$payload` parameter is an associative array used to set the
246+
following:
247+
248+
* `data` (string) -- The data string for the signal. You can send a maximum of 8kB.
249+
250+
* `type` (string) -- — (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 '~'.
251+
252+
The `$connectionId` parameter is an optional string used to specify the connection ID of
253+
a client connected to the session. If you specify this value, the signal is sent to
254+
the specified client. Otherwise, the signal is sent to all clients connected to the session.
255+
256+
257+
```php
258+
use OpenTok\OpenTok;
259+
260+
// Send a signal to a specific client
261+
$signalPayload = array(
262+
'data' => 'some signal message',
263+
'type' => 'signal type'
264+
);
265+
$connectionId = 'da9cb410-e29b-4c2d-ab9e-fe65bf83fcaf';
266+
$opentok->signal($sessionId, $signalPayload, $connectionId);
267+
268+
// Send a signal to everyone in the session
269+
$signalPayload = array(
270+
'data' => 'some signal message',
271+
'type' => 'signal type'
272+
);
273+
$opentok->signal($sessionId, $signalPayload);
274+
```
275+
276+
For more information, see the [OpenTok signaling developer
277+
guide](https://tokbox.com/developer/guides/signaling/).
196278

197279
# Samples
198280

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* Defines the exception thrown when you use an invalid API or secret and call the force disconnect method.
7+
*/
8+
class ForceDisconnectAuthenticationException extends \OpenTok\Exception\AuthenticationException implements \OpenTok\Exception\ForceDisconnectException
9+
{
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* Defines an exception thrown when a call to a force disconnect method results in an error response from
7+
* the server.
8+
*/
9+
class ForceDisconnectConnectionException extends \OpenTok\Exception\DomainException implements \OpenTok\Exception\ForceDisconnectException
10+
{
11+
public function __construct($message, $code)
12+
{
13+
parent::__construct($message, $code);
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* The interface used by all exceptions resulting from calls to the signal API.
7+
*/
8+
interface ForceDisconnectException
9+
{
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* Defines an exception thrown when a call to the force disconnect method results in an error due to an
7+
* unexpected value.
8+
*/
9+
class ForceDisconnectUnexpectedValueException extends \OpenTok\Exception\UnexpectedValueException implements \OpenTok\Exception\ForceDisconnectException
10+
{
11+
public function __construct($message, $code)
12+
{
13+
parent::__construct($message, $code);
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 signal method.
7+
*/
8+
class SignalAuthenticationException extends \OpenTok\Exception\AuthenticationException implements \OpenTok\Exception\SignalException
9+
{
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* Defines an exception thrown when a call to a signal method results in an error response from
7+
* the server.
8+
*/
9+
class SignalConnectionException extends \OpenTok\Exception\DomainException implements \OpenTok\Exception\SignalException
10+
{
11+
public function __construct($message, $code)
12+
{
13+
parent::__construct($message, $code);
14+
}
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* The interface used by all exceptions resulting from calls to the signal API.
7+
*/
8+
interface SignalException
9+
{
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace OpenTok\Exception;
4+
5+
/**
6+
* Defines an exception thrown when a call to a signal method results in an error due to an
7+
* unexpected value.
8+
*/
9+
class SignalUnexpectedValueException extends \OpenTok\Exception\UnexpectedValueException implements \OpenTok\Exception\SignalException
10+
{
11+
public function __construct($message, $code)
12+
{
13+
parent::__construct($message, $code);
14+
}
15+
}

src/OpenTok/OpenTok.php

Lines changed: 105 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace OpenTok;
44

55
use OpenTok\Session;
6+
use OpenTok\Stream;
7+
use OpenTok\StreamList;
68
use OpenTok\Archive;
79
use OpenTok\Broadcast;
810
use OpenTok\Layout;
@@ -388,21 +390,35 @@ public function deleteArchive($archiveId)
388390
* recent archive. If you do not specify an offset, 0 is used.
389391
* @param integer $count Optional. The number of archives to be returned. The maximum number of
390392
* archives returned is 1000.
393+
* @param string $sessionId Optional. The OpenTok session Id for which you want to retrieve Archives for. If no session Id
394+
* is specified, the method will return archives from all sessions created with the API key.
395+
*
391396
* @return ArchiveList An ArchiveList object. Call the items() method of the ArchiveList object
392397
* to return an array of Archive objects.
393398
*/
394-
public function listArchives($offset=0, $count=null)
399+
public function listArchives($offset=0, $count=null, $sessionId=null)
395400
{
396401
// validate params
397402
Validators::validateOffsetAndCount($offset, $count);
403+
if (!is_null($sessionId)) {
404+
Validators::validateSessionIdBelongsToKey($sessionId, $this->apiKey);
405+
}
398406

399-
$archiveListData = $this->client->listArchives($offset, $count);
407+
$archiveListData = $this->client->listArchives($offset, $count, $sessionId);
400408
return new ArchiveList($archiveListData, array( 'client' => $this->client ));
401409
}
402410

411+
/**
412+
* Force disconnects a specific client connected to an OpenTok session.
413+
*
414+
* @param string $sessionId The OpenTok session ID where the signal will be sent.
415+
*
416+
* @param string $connectionId The connectionId of the connection in a session.
417+
*/
418+
403419
public function forceDisconnect($sessionId, $connectionId)
404420
{
405-
Validators::validateSessionId($sessionId);
421+
Validators::validateSessionIdBelongsToKey($sessionId, $this->apiKey);
406422
Validators::validateConnectionId($connectionId);
407423

408424
return $this->client->forceDisconnect($sessionId, $connectionId);
@@ -490,6 +506,46 @@ public function updateStream($sessionId, $streamId, $properties = array())
490506
$this->client->updateStream($sessionId, $streamId, $properties);
491507
}
492508

509+
/**
510+
* Gets an Stream object for the given stream ID.
511+
*
512+
* @param String $sessionId The session ID.
513+
*
514+
* @param String $streamId The stream ID.
515+
*
516+
* @return Stream The Stream object.
517+
*/
518+
519+
public function getStream($sessionId, $streamId)
520+
{
521+
Validators::validateSessionId($sessionId);
522+
Validators::validateStreamId($streamId);
523+
524+
// make API call
525+
$streamData = $this->client->getStream($sessionId, $streamId);
526+
return new Stream($streamData);
527+
528+
}
529+
530+
/**
531+
* Returns a StreamList Object for the given session ID.
532+
*
533+
* @param String $sessionId The session ID.
534+
*
535+
* @return StreamList A StreamList object. Call the items() method of the StreamList object
536+
* to return an array of Stream objects.
537+
*/
538+
539+
public function listStreams($sessionId)
540+
{
541+
Validators::validateSessionIdBelongsToKey($sessionId, $this->apiKey);
542+
543+
// make API call
544+
$streamListData = $this->client->listStreams($sessionId);
545+
return new StreamList($streamListData);
546+
547+
}
548+
493549
/**
494550
* Initiate an outgoing SIP call
495551
*
@@ -566,6 +622,52 @@ public function dial($sessionId, $token, $sipUri, $options=array())
566622
return new SipCall($sipJson);
567623
}
568624

625+
/**
626+
* Sends a signal to clients (or a specific client) connected to an OpenTok session.
627+
*
628+
* @param string $sessionId The OpenTok session ID where the signal will be sent.
629+
*
630+
*
631+
* @param array $payload This array defines the payload for the signal. This array includes the
632+
* following keys, of which type is optional:
633+
*
634+
* <ul>
635+
*
636+
* <li><code>'data'</code> (string) &mdash; The data string for the signal. You can send a maximum of 8kB.</li>
637+
* <li><code>'type'</code> (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 '~'. </li>
638+
*
639+
* </ul>
640+
*
641+
*
642+
* @param string $connectionId An optional parameter used to send the signal to a specific connection in a session.
643+
*/
644+
public function signal($sessionId, $payload, $connectionId=null)
645+
{
646+
647+
// unpack optional arguments (merging with default values) into named variables
648+
$defaults = array(
649+
'type' => '',
650+
'data' => '',
651+
);
652+
653+
$payload = array_merge($defaults, array_intersect_key($payload, $defaults));
654+
list($type, $data) = array_values($payload);
655+
656+
// validate arguments
657+
Validators::validateSessionIdBelongsToKey($sessionId, $this->apiKey);
658+
Validators::validateSignalPayload($payload);
659+
660+
if (is_null($connectionId) || empty($connectionId)) {
661+
// make API call without connectionId
662+
$this->client->signal($sessionId, $payload);
663+
} else {
664+
Validators::validateConnectionId($connectionId);
665+
// make API call with connectionId
666+
$this->client->signal($sessionId, $payload, $connectionId);
667+
}
668+
669+
}
670+
569671
/** @internal */
570672
private function _sign_string($string, $secret)
571673
{

0 commit comments

Comments
 (0)