NAME
OpenTok::API - Perl SDK for OpenTok http://www.tokbox.com/
VERSION
Version 0.03
SYNOPSIS
1. Generate Token
use OpenTok::API;
# Get your own API-keys from http://www.tokbox.com/opentok
my $ot = OpenTok::API->new(
'api_key' => $api_key,
'api_secret' => $api_secret,
'mode' => "development"|"production",
);
2. Create new session
my $session_id = $ot->create_session(
location => '',
'p2p.preference' => "enabled"|"disabled"
)->getSessionId();
3. Generate a new token for session
my $token = $ot->generate_token(
session_id => $session_id,
role => "publisher"|"subscriber"|"moderator"
);
4. Now insert your $api_key, $session_id, and $token into your template using your favourite templating engine
# TT example
# In server side code
my $tt = Template->new(...});
my $vars = { api_key => $api_key, session_id => $session_id, token => $token };
$tt->process($template, $vars) || die $tt->error(), "\n";
# In HTML (javascript part)
var apiKey = "[% api_key %]";
var sessionId = "[% session_id %]";
var token = "[% token %]";
...
var session = TB.initSession(sessionId);
session.addEventListener("sessionConnected", sessionConnectedHandler);
session.addEventListener("streamCreated", streamCreatedHandler);
session.connect(apiKey,token);
SUBROUTINES/METHODS
new
Creates and returns a new OpenTok::API object
my $ot = OpenTok::API->new(
'api_key' => $api_key,
'api_secret' => $api_secret,
'mode' => "development"|"production",
);
api_key => string
Sets your TokBox API Partner Key
api_secret => string
Sets your TokBox API Partner Secret
mode => "development|"production"
Set it to "production" when you launch your app in production. Default is "development".
generate_token
Generates a token for specific session.
my $token = $ot->generate_token(
session_id => $session_id,
role => "publisher"|"subscriber"|"moderator",
expire_time => (time()+24*3600),
);
session_id => string
If session_id is not blank, this token can only join the call with the specified session_id.
role => "subscriber"|"publisher"|"moderator"
One of the roles. Default is publisher, look in the documentation to learn more about roles. http://www.tokbox.com/opentok/api/tools/as3/documentation/overview/token_creation.html
expire_time => int
Optional. The time when the token will expire, defined as an integer value for a Unix timestamp (in seconds). If you do not specify this value, tokens expire in 24 hours after being created. The expiration_time value, if specified, must be within 30 days of the creation time.
create_session
Creates and returns OpenTok::API::Session object
my $session_id = $ot->create_session(
location => '',
'p2p.preference' => "enabled"|"disabled"
)->getSessionId();
location => string
An IP address that TokBox will use to situate the session in its global network. In general, you should not specify a location hint; if no location hint is specified, the session uses a media server based on the location of the first client connecting to the session. Specify a location hint only if you know the general geographic region (and a representative IP address) for the session and you think the first client connecting may not be in that region.
'p2p.preference' => 'enabled'
The properties option includes any following key value pairs. Currently only the following property exists:
p2p.preference (String) . Whether the session's streams will be transmitted directly between peers. You can set the following possible values:
"disabled" (the default) . The session's streams will all be relayed using the OpenTok servers. More than two clients can connect to the session.
"enabled" . The session will attempt to transmit streams directly between clients. If peer-to-peer streaming fails (either when streams are initially published or during the course of a session), the session falls back to using the OpenTok servers for relaying streams. (Peer-to-peer streaming uses UDP, which may be blocked by a firewall.) For a session created with peer-to-peer streaming enabled, only two clients can connect to the session at a time. If an additional client attempts to connect, the TB object on the client dispatches an exception event. By removing the server, peer-to-peer streaming decreases latency and improves quality.
Note that the properties object previously included settings for multiplexing and server-side echo suppression. However, these features were deleted in OpenTok v0.91.48. (Server-side echo suppression was replaced with the acoustic echo cancellation feature added in OpenTok v0.91.18.)
AUTHOR
This version: Dr James Freeman, <james at gp2u.com.au>
Original version: Maxim Nikolenko, <root at zbsd.ru>
BUGS
Please report any bugs or feature requests to bug-opentok-api at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=OpenTok::API. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc OpenTok::API
You can also look for information at:
http://www.tokbox.com/opentok
RT: CPAN's request tracker (report bugs here)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
LICENSE AND COPYRIGHT
Copyright 2011 Maxim Nikolenko.
This module is released under the following license: BSD