22
33[ ![ Build Status] ( https://travis-ci.org/opentok/OpenTok-PHP-SDK.svg )] ( https://travis-ci.org/opentok/OpenTok-PHP-SDK )
44
5- The OpenTok PHP SDK lets you generate [ sessions] ( http://tokbox.com/opentok/tutorials/create-session/ ) and
6- [ tokens] ( http://tokbox.com/opentok/tutorials/create-token/ ) for [ OpenTok] ( http://www.tokbox.com/ )
7- applications, and [ archive] ( http://tokbox.com/opentok/tutorials/archiving/ ) sessions.
5+ The OpenTok PHP SDK lets you generate [ sessions] ( http://tokbox.com/developer/guides/create-session/ ) and
6+ [ tokens] ( http://tokbox.com/developer/guides/create-token/ ) for [ OpenTok] ( http://www.tokbox.com/ )
7+ applications, and [ archive] ( http://tokbox.com/developer/guides/archiving/ ) sessions.
8+ It also includes methods for working with OpenTok
9+ [ archives] ( http://tokbox.com/developer/guides/archiving ) , working with OpenTok
10+ [ SIP interconnect] ( http://tokbox.com/developer/guides/sip ) , and
11+ [ disconnecting clients from sessions] ( http://tokbox.com/developer/guides/moderation/rest/ ) .
812
9- # Installation
13+ ## Installation
1014
11- ## Composer (recommended):
15+ ### Composer (recommended):
1216
1317Composer helps manage dependencies for PHP projects. Find more info here: < http://getcomposer.org >
1418
1519Add this package (` opentok/opentok ` ) to your ` composer.json ` file, or just run the following at the
1620command line:
1721
1822```
19- $ ./composer.phar require opentok/opentok 4.2 .x
23+ $ ./composer.phar require opentok/opentok 4.3 .x
2024```
2125
22- ## Manually:
26+ ### Manually:
2327
2428Download the ` opentok.phar ` file for the latest release from the [ Releases] ( https://github.com/opentok/opentok-php-sdk/releases )
2529page.
2630
2731Place ` opentok.phar ` in the [ include_path] ( http://www.php.net/manual/en/ini.core.php#ini.include-path ) OR
2832require it in any script which uses the ` OpenTok\* ` classes.
2933
30- # Usage
34+ ## Usage
3135
32- ## Initializing
36+ ### Initializing
3337
3438This package follows the [ PSR-4] ( http://www.php-fig.org/psr/psr-4/ ) autoloading standard. If you are
3539using composer to install, you just require the generated autoloader:
@@ -47,7 +51,7 @@ use OpenTok\OpenTok;
4751$opentok = new OpenTok($apiKey, $apiSecret);
4852```
4953
50- ## Creating Sessions
54+ ### Creating Sessions
5155
5256To create an OpenTok Session, use the ` createSession($options) ` method of the
5357` OpenTok\OpenTok ` class. The ` $options ` parameter is an optional array used to specify the following:
@@ -87,13 +91,14 @@ $session = $opentok->createSession($sessionOptions);
8791$sessionId = $session->getSessionId();
8892```
8993
90- ## Generating Tokens
94+ ### Generating Tokens
9195
9296Once a Session is created, you can start generating Tokens for clients to use when connecting to it.
9397You can generate a token either by calling the ` generateToken($sessionId, $options) ` method of the
9498` OpenTok\OpenTok ` class, or by calling the ` generateToken($options) ` method on the ` OpenTok\Session `
9599instance after creating it. The ` $options ` parameter is an optional array used to set the role,
96- expire time, and connection data of the Token.
100+ expire time, and connection data of the Token. For layout control in archives and broadcasts,
101+ the initial layout class list of streams published from connections using this token can be set as well.
97102
98103``` php
99104use OpenTok\Session;
@@ -108,11 +113,12 @@ $token = $session->generateToken();
108113$token = $session->generateToken(array(
109114 'role' => Role::MODERATOR,
110115 'expireTime' => time()+(7 * 24 * 60 * 60), // in one week
111- 'data' => 'name=Johnny'
116+ 'data' => 'name=Johnny',
117+ 'initialLayoutClassList' => array('focus')
112118));
113119```
114120
115- ## Working with Streams
121+ ### Working with Streams
116122
117123You can get information about a stream by calling the ` getStream($sessionId, $streamId) ` method of the
118124` OpenTok\OpenTok ` class.
@@ -142,7 +148,7 @@ $streamList = $opentok->listStreams($sessionId);
142148$streamList->totalCount(); // total count
143149```
144150
145- ## Working with Archives
151+ ### Working with Archives
146152
147153You can only archive sessions that use the OpenTok Media Router
148154(sessions with the media mode set to routed).
@@ -160,11 +166,11 @@ $archive = $opentok->startArchive($sessionId);
160166
161167// Create an archive using custom options
162168$archiveOptions = array(
163- 'name' => 'Important Presentation', // default: null
164- 'hasAudio' => true, // default: true
165- 'hasVideo' => true, // default: true
166- 'outputMode' => OutputMode::COMPOSED, // default: OutputMode::COMPOSED
167- 'resolution' => '1280x720' // default: '640x480'
169+ 'name' => 'Important Presentation', // default: null
170+ 'hasAudio' => true, // default: true
171+ 'hasVideo' => true, // default: true
172+ 'outputMode' => OutputMode::COMPOSED, // default: OutputMode::COMPOSED
173+ 'resolution' => '1280x720' // default: '640x480'
168174);
169175$archive = $opentok->startArchive($sessionId, $archiveOptions);
170176
@@ -174,7 +180,11 @@ $archiveId = $archive->id;
174180
175181If you set the ` outputMode ` option to ` OutputMode::INDIVIDUAL ` , it causes each stream in the archive to be recorded to its own individual file. Please note that you cannot specify the resolution when you set the ` outputMode ` option to ` OutputMode::INDIVIDUAL ` . The ` OutputMode::COMPOSED ` setting (the default) causes all streams in the archive to be recorded to a single (composed) file.
176182
177- You can stop the recording of a started Archive using the ` stopArchive($archiveId) ` method of the
183+ Note that you can also create an automatically archived session, by passing in ` ArchiveMode::ALWAYS `
184+ as the ` archiveMode ` key of the ` options ` parameter passed into the ` OpenTok->createSession() `
185+ method (see "Creating Sessions," above).
186+
187+ You can stop the recording of a started archive using the ` stopArchive($archiveId) ` method of the
178188` OpenTok\OpenTok ` object. You can also do this using the ` stop() ` method of the
179189` OpenTok\Archive ` instance.
180190
@@ -186,7 +196,7 @@ $archive->stop();
186196```
187197
188198To get an ` OpenTok\Archive ` instance (and all the information about it) from an archive ID, use the
189- ` getArchvie ($archiveId)` method of the ` OpenTok\OpenTok ` class.
199+ ` getArchive ($archiveId)` method of the ` OpenTok\OpenTok ` class.
190200
191201``` php
192202$archive = $opentok->getArchive($archiveId);
@@ -216,12 +226,192 @@ $archives = $archiveList->getItems();
216226$totalCount = $archiveList->totalCount();
217227```
218228
219- Note that you can also create an automatically archived session, by passing in ` ArchiveMode::ALWAYS `
220- as the ` archiveMode ` key of the ` options ` parameter passed into the ` OpenTok->createSession() `
221- method (see "Creating Sessions," above).
229+ For composed archives, you can change the layout dynamically, using the ` updateArchiveLayout($archiveId, $layoutType) ` method:
230+
231+ ``` php
232+ use OpenTok\OpenTok;
233+
234+ $layout Layout::getPIP(); // Or use another get method of the Layout class.
235+ $opentok->updateArchiveLayout($archiveId, $layout);
236+ ```
237+
238+ You can set the initial layout class for a client's streams by setting the ` layout ` option when
239+ you create the token for the client, using the ` OpenTok->generateToken() ` method or the
240+ ` Session->generateToken() ` method. And you can change the layout classes for a stream
241+ by calling the ` OpenTok->updateStream() ` method.
242+
243+ Setting the layout of composed archives is optional. By default, composed archives use the
244+ "best fit" layout (see [ Customizing the video layout for composed
245+ archives] ( https://tokbox.com/developer/guides/archiving/layout-control.html ) ).
222246
223247For more information on archiving, see the
224- [ OpenTok archiving] ( https://tokbox.com/opentok/tutorials/archiving/ ) programming guide.
248+ [ OpenTok archiving] ( https://tokbox.com/developer/guides/archiving/ ) developer guide.
249+
250+ ### Working with Broadcasts
251+
252+ You can only start live streaming broadcasts for sessions that use the OpenTok Media Router
253+ (sessions with the media mode set to routed).
254+
255+ Start the live streaming broadcast of an OpenTok Session using the
256+ ` startBroadcast($sessionId, $options) ` method of the ` OpenTok\OpenTok ` class.
257+ This will return an ` OpenTok\Broadcast ` instance. The ` $options ` parameter is
258+ an optional array used to assign a layout type for the broadcast.
259+
260+ ``` php
261+ // Start a live streaming broadcast of a session
262+ $broadcast = $opentok->startBroadcast($sessionId);
263+
264+
265+ // Start a live streaming broadcast of a session, setting a layout type
266+ $options = array(
267+ 'layout' => Layout::getBestFit()
268+ );
269+ $broadcast = $opentok->startBroadcast($sessionId, $options);
270+
271+ // Store the broadcast ID in the database for later use
272+ $broadcastId = $broadcast->id;
273+ ```
274+
275+ You can stop the live streaming broadcast using the ` stopBroadcast($broadcastId) ` method of the
276+ ` OpenTok\OpenTok ` object. You can also do this using the ` stop() ` method of the
277+ ` OpenTok\Broadcast ` instance.
278+
279+ ``` php
280+ // Stop a broadcast from an broadcast ID (fetched from database)
281+ $opentok->stopBroadcast($broadcastId);
282+
283+ // Stop a broadcast from an Broadcast instance (returned from startBroadcast)
284+ $broadcast->stop();
285+ ```
286+
287+ To get an ` OpenTok\Broadcast ` instance (and all the information about it) from a broadcast ID,
288+ use the ` getBroadcast($broadcastId) ` method of the ` OpenTok\OpenTok ` class.
289+
290+ ``` php
291+ $broadcast = $opentok->getBroadcast($broadcastId);
292+ ```
293+
294+ You can set change the layout dynamically, using the
295+ ` OpenTok->updateBroadcastLayout($broadcastId, $layout) ` method:
296+
297+ ``` php
298+ use OpenTok\OpenTok;
299+
300+ $layout Layout::getPIP(); // Or use another get method of the Layout class.
301+ $opentok->updateBroadcastLayout($broadcastId, $layout);
302+ ```
303+ You can use the ` Layout ` class to set the layout types:
304+ ` Layout::getHorizontalPresentation() ` , ` Layout::getVerticalPresentation() ` , ` Layout::getPIP() ` ,
305+ ` Layout::getBestFit() ` , ` Layout::createCustom() ` .
306+
307+ ``` php
308+ $layoutType = Layout::getHorizontalPresentation();
309+ $opentok->setArchiveLayout($archiveId, $layoutType);
310+
311+ // For custom Layouts, you can do the following
312+ $options = array(
313+ 'stylesheet' => 'stream.instructor {position: absolute; width: 100%; height:50%;}'
314+ );
315+
316+ $layoutType = Layout::createCustom($options);
317+ $opentok->setArchiveLayout($archiveId, $layoutType);
318+ ```
319+
320+ You can set the initial layout class for a client's streams by setting the ` layout ` option when
321+ you create the token for the client, using the ` OpenTok->generateToken() ` method or the
322+ ` Session->generateToken() ` method. And you can change the layout classes for a stream
323+ by calling the ` OpenTok->updateStream() ` method.
324+
325+ Setting the layout of live streaming broadcasts is optional. By default, broadcasts use the
326+ "best fit" layout (see [ Configuring video layout for OpenTok live streaming
327+ broadcasts] ( https://tokbox.com/developer/guides/broadcast/live-streaming/#configuring-video-layout-for-opentok-live-streaming-broadcasts ) ).
328+
329+ For more information on live streaming broadcasts, see the
330+ [ OpenTok live streaming broadcasts] ( https://tokbox.com/developer/guides/broadcast/live-streaming/ )
331+ developer guide.
332+
333+ ### Force a Client to Disconnect
334+
335+ Your application server can disconnect a client from an OpenTok session by calling the ` forceDisconnect($sessionId, $connectionId) `
336+ method of the ` OpenTok\OpenTok ` class.
337+
338+ ``` php
339+ use OpenTok\OpenTok;
340+
341+ // Force disconnect a client connection
342+ $opentok->forceDisconnect($sessionId, $connectionId);
343+ ```
344+ ### Sending Signals
345+
346+ Once a Session is created, you can send signals to everyone in the session or to a specific connection.
347+ You can send a signal by calling the ` signal($sessionId, $payload, $connectionId) ` method of the
348+ ` OpenTok\OpenTok ` class.
349+
350+ The ` $sessionId ` parameter is the session ID of the session.
351+
352+ The ` $payload ` parameter is an associative array used to set the
353+ following:
354+
355+ * ` data ` (string) -- The data string for the signal. You can send a maximum of 8kB.
356+
357+ * ` 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 '~ '.
358+
359+ The ` $connectionId ` parameter is an optional string used to specify the connection ID of
360+ a client connected to the session. If you specify this value, the signal is sent to
361+ the specified client. Otherwise, the signal is sent to all clients connected to the session.
362+
363+
364+ ``` php
365+ use OpenTok\OpenTok;
366+
367+ // Send a signal to a specific client
368+ $signalPayload = array(
369+ 'data' => 'some signal message',
370+ 'type' => 'signal type'
371+ );
372+ $connectionId = 'da9cb410-e29b-4c2d-ab9e-fe65bf83fcaf';
373+ $opentok->signal($sessionId, $signalPayload, $connectionId);
374+
375+ // Send a signal to everyone in the session
376+ $signalPayload = array(
377+ 'data' => 'some signal message',
378+ 'type' => 'signal type'
379+ );
380+ $opentok->signal($sessionId, $signalPayload);
381+ ```
382+
383+ For more information, see the [ OpenTok signaling developer
384+ guide] ( https://tokbox.com/developer/guides/signaling/ ) .
385+
386+ ## Working with SIP Interconnect
387+
388+ You can add an audio-only stream from an external third-party SIP gateway using the SIP
389+ Interconnect feature. This requires a SIP URI, the session ID you wish to add the audio-only
390+ stream to, and a token to connect to that session ID.
391+
392+ To initiate a SIP call, call the ` dial($sessionId, $token, $sipUri, $options) ` method of the
393+ ` OpenTok\OpenTok ` class:
394+
395+ ``` php
396+ $sipUri = 'sip:
[email protected] ;transport=tls';
397+
398+ $options = array(
399+ 'headers' => array(
400+ 'X-CUSTOM-HEADER' => 'headerValue'
401+ ),
402+ 'auth' => array(
403+ 'username' => 'username',
404+ 'password' => 'password'
405+ ),
406+ 'secure' => true,
407+ 408+ );
409+
410+ $opentok->dial($sessionId, $token, $sipUri, $options);
411+ ```
412+
413+ For more information, see the [ OpenTok SIP Interconnect developer
414+ guide] ( https://tokbox.com/developer/guides/sip/ ) .
225415
226416## Force Disconnect
227417
@@ -276,20 +466,21 @@ $opentok->signal($sessionId, $signalPayload);
276466For more information, see the [ OpenTok signaling developer
277467guide] ( https://tokbox.com/developer/guides/signaling/ ) .
278468
279- # Samples
469+ ## Samples
280470
281- There are two sample applications included in this repository. To get going as fast as possible, clone the whole
471+ There are three sample applications included in this repository. To get going as fast as possible, clone the whole
282472repository and follow the Walkthroughs:
283473
284474* [ HelloWorld] ( sample/HelloWorld/README.md )
285475* [ Archiving] ( sample/Archiving/README.md )
476+ * [ SipCall] ( sample/SipCall/README.md )
286477
287- # Documentation
478+ ## Documentation
288479
289480Reference documentation is available at
290481< https://tokbox.com/developer/sdks/php/reference/index.html > .
291482
292- # Requirements
483+ ## Requirements
293484
294485You need an OpenTok API key and API secret, which you can obtain by logging into your
295486[ TokBox account] ( https://tokbox.com/account ) .
@@ -298,12 +489,12 @@ The OpenTok PHP SDK requires PHP 5.6+ or PHP 7+
298489
299490For PHP 5.5 and lower please use PHP SDK v2.5
300491
301- # Release Notes
492+ ## Release Notes
302493
303494See the [ Releases] ( https://github.com/opentok/opentok-php-sdk/releases ) page for details
304495about each release.
305496
306- # Important changes since v2.2.0
497+ ## Important changes since v2.2.0
307498
308499** Changes in v2.2.1:**
309500
@@ -332,12 +523,12 @@ See the reference documentation
332523< http://www.tokbox.com/opentok/libraries/server/php/reference/index.html > and in the
333524docs directory of the SDK.
334525
335- # Development and Contributing
526+ ## Development and Contributing
336527
337528Interested in contributing? We :heart : pull requests! See the [ Development] ( DEVELOPING.md ) and
338529[ Contribution] ( CONTRIBUTING.md ) guidelines.
339530
340- # Support
531+ ## Support
341532
342533See < https://support.tokbox.com > for all our support options.
343534
0 commit comments