stijnster / opentok

Ruby gem for opentok api

Home Page:https://rubygems.org/gems/opentok

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Opentok

OpenTok is a free set of APIs from TokBox that enables websites to weave live group video communication into their online experience. With OpenTok you have the freedom and flexibility to create the most engaging web experience for your users. OpenTok is currently available as a JavaScript and ActionScript 3.0 library. Check out http://www.tokbox.com/ and http://www.tokbox.com/opentok/tools/js/gettingstarted for more information.

This is the official Opentok rubygem.

Installation

To install using bundler, add Opentok to your gemfile and run bundle install:

gem 'opentok'

To install as a regular gem just type gem install opentok

How to use

API-key and secret

Request your api-key and secret at http://www.tokbox.com/opentok/tools/js/apikey. You can use the staging environment for testing. The gem uses this staging environment by default.

OpenTokSDK

In order to use any of the server side functions, you must first create an OpenTokSDK object with your developer credentials.
You must pass in your Key and Secret. If your app is in production, you must also pass in a hash containing api_url
For more information about production apps, check out http://www.tokbox.com/opentok/api/tools/js/launch

Example: ( Staging )

@api_key = ''                # should be a string
@api_secret = ''            # should be a string
@opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret

Example: ( Production )

@opentok = OpenTok::OpenTokSDK.new @api_key, @api_secret, :api_url => 'https://api.opentok.com/hl'

Creating Sessions

Use your OpenTokSDK object to create session_id
create_session takes 1-2 parameters:

location (string) - give Opentok a hint on where you are running your application
properties (object) - OPTIONAL. Set peer to peer as enabled or disabled

Example: P2P disabled by default

@location = 'localhost'
session_id = @opentok.create_session(@location)

Example: P2P enabled

session_properties = {OpenTok::SessionPropertyConstants::P2P_PREFERENCE => "enabled"}    # or disabled
session_id = @opentok.create_session( @location, session_properties )

Generating Token

With the generated session_id, you can start generating tokens for each user. generate_token takes in hash with 1-4 properties:

session_id (string) - required
role (string) - OPTIONAL. subscriber, publisher, or moderator
expire_time (int) - OPTIONAL. Time when token will expire in unix timestamp
connection_data (string) - OPTIONAL. Metadata to store data (names, user id, etc)

Example:

token = @opentok.generate_token :session_id => session, :role => OpenTok::RoleConstants::PUBLISHER, :connection_data => "username=Bob,level=4"

Downloading Archive Videos

To Download archives, first you must first create a token that has a moderator role

Get Archive Manifest

get_archive_manifest() takes in 2 parameters: archiveId and moderator token

returns an OpenTokArchive. The resources property of this object is array of OpenTokArchiveVideoResource, and each OpenTokArchiveVideoResource object represents a video in the archive.

Get video ID

With your OpenTokArchive object, call getId() getId() will return the video ID (a String)

Get Download Url

downloadArchiveURL takes 1 parameters: video ID and returns download URL for the video

About

Ruby gem for opentok api

https://rubygems.org/gems/opentok

License:MIT License


Languages

Language:Ruby 72.6%Language:JavaScript 27.4%