Skip to content
This repository
branch: master
README.md

OpenTok Server SDK for Ruby

The OpenTok server SDK for Ruby lets you generate sessions and tokens for OpenTok applications.

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

Requirements

The OpenTok server SDK for Ruby requires Ruby 1.9 or greater.

You need an OpenTok API key and API secret, which you can obtain at https://dashboard.tokbox.com.

OpenTokSDK

In order to use any of the server side functions, you must first create an OpenTokSDK object with your developer credentials.
OpenTokSDK takes two parameters:

  • key (string) - Given to you when you register
  • secret (string) - Given to you when you register
# Creating an OpenTok Object
API_KEY = ''     # replace with your OpenTok API key
API_SECRET = ''  # replace with your OpenTok API secret
OTSDK = OpenTok::OpenTokSDK.new API_KEY, API_SECRET

Creating Sessions

Call the createSession() method of the OpenTokSDK object to create a session. The method returns a Session object. The sessionId property of the Session object is the OpenTok session ID:

# creating an OpenTok server-enabled session
sessionId = OTSDK.createSession().to_s

# Creating peer-to-peer session
sessionProperties = {OpenTok::SessionPropertyConstants::P2P_PREFERENCE => "enabled"}
sessionId = OTSDK.createSession( nil, sessionProperties ).to_s

Generating Tokens

With the generated session ID, you can generate tokens for each user:

# Generating a publisher token
token = OTSDK.generateToken :session_id => sessionId
 
# Generating a token with moderator role and connection data
role = OpenTok::RoleConstants::MODERATOR
connection_data = "username=Bob,level=4"
token = OTSDK.generateToken :session_id => sessionId, :role => role, :connection_data => connection_data

Possible Errors:

  • "Null or empty session ID are not valid"
  • "An invalid session ID was passed"

Contributing

To contribute, simple fork this repository and send a pull request when you are done.
Before you send pull requests, make sure all test cases are passing.

To install necessary gems, type bundle install in the root directory.

To run test cases, type rspec spec/ in the root directory.

More information

See the reference documentation.

For more information on OpenTok, go to http://www.tokbox.com/.

Something went wrong with that request. Please try again.