Git Product home page Git Product logo

opentok's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.