Giter VIP home page Giter VIP logo

opentok-laravel's Introduction

OpenTok for Laravel


This is a laravel4 wrapper library forthe OpenTok SDK. OpenTok is a product by TokBox which utilizes WebRTC to enable peer to peer video, audio and messaging.

Please note: this repository is in NO WAY associated with TokBox.

Composer Require

Currently only dev-master but is only a wrapper really...

"tomcorbett/opentok-laravel": "dev-master"

Publishing The Configuration

Publish the configurations for this package in order to change them to your liking:

php artisan config:publish tomcorbett/opentok-laravel

Setting up your Configuration

Get your api_key and api_secret from your OpenTok account and replace the placeholders in your config file:

  return array( 
    /**
    * put your API key in here
    */
    'api_key' => 'API_KEY',

    /**
    * put your API secret in here
    */	
    'api_secret' => 'API_SECRET',
  );

Before you dive in...

Although it's very tempting yo dive straight in, to avoid frustration, I would highly reccomend that you take a look at the Intro to OpenTok and also click around the site and read their docs. My documentation is terrible and only intended to make it easier to use for laravel developers and in no way is it a replacement for the OpenTok documentation (which is really good).

It's definitely a good idea to get to grips with the general flow, the technologies used and also their definitions e.g. session, publisher, subscriber, token etc.

General Usage

First you need to create a session so your subscribers and/or publishers have something to assiciate with

// new session
$session    = OpentokApi::createSession();            
$sessionId  = $session->getSessionId();

// check if it's been created or not (could have failed)
if (empty($sessionId)) {
    throw new \Exception("An open tok session could not be created");
}

Now we need to create a token for your publisher to use so they can actually publish Please note that you will need to API key on the client side to use in the JS so something like this would be fine: (saves you hardcoding in your JS file or template)

// use the necessary files
use Tomcorbett\OpentokLaravel\Facades\OpentokApi;
use OpenTokException;

// get your API key from config
$api_key = Config::get('opentok-laravel::api_key');
        
// then create a token (session created in previous step)
try {
    // note we're create a publisher token here, for subscriber tokens we would specify.. yep 'subscriber' instead
    $token = OpentokApi::generateToken($sessionId,
        array(
            'role' => Role::PUBLISHER
        )
    );
} catch(OpenTokException $e) {
    // do something here for failure
}

// pass these to your view where you're broadcasting from as you'll need them...
return View::make('your/view')
    ->with('session_id', $sessionId)
    ->with('api_key', $api_key)
    ->with('token', $token)

For the JS/HTML etc. for publishing video/audio/messages please see the OpenTok Quick Start Guide and Documentation and take a browse around their How To examples etc. they're pretty good!

Hopefully you will find this library useful, if so please feel free to let me know, and feel free to drop any comments, questions or suggestions to improve!

opentok-laravel's People

Contributors

dldean avatar intonarumori avatar tomcorbett avatar

Watchers

 avatar

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.