How to use opentok - 3 common examples

To help you get started, we’ve selected a few opentok examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jonmumm / OpenTok-Node-Session / server.js View on Github external
// When a client connects, figure out which session to join
	getSession(client);
	
	client.on('disconnect', function() {
		// When a client disconnects, drop that client from the session
		leaveSession(client);
	});
});

// OpenTok Variables
var OPENTOK_API_KEY = '413302',		// Replace with your API key
	OPENTOK_API_SECRET = 'fc512f1f3c13e3ec3f590386c986842f92efa7e7',		// Replace with your API secret

	// OpenTok SDK
	ot = new opentok.OpenTokSDK(OPENTOK_API_KEY, OPENTOK_API_SECRET),
	
	// NOTE: Uncomment for production, defaults to "staging.tokbox.com"
	// ot.setEnvironment("api.tokbox.com"),
	
	// Variables for managing OpenTok Sessions
	MAX_SESSION_CONNECTIONS = 3,	// Maximum number of client connections we want in a given session	
 	session_map = {},				// Hash for getting the session of a given client
	ot_sessions = new Array();		// Array for holding all sessions we have generated

// Finds an available session for the client to connect to
function getSession(client) {
	
	var session;
	// Look through all sessions to find a session that has less than the max number of sessions
	// NOTE: We start searching from the top of the array since it is more likely a non-full session is there
	for (var i = ot_sessions.length - 1; i >= 0; i--) {
github opentok / opentok-node / examples / app.js View on Github external
var http = require('http')
  , url = require('url')
  , fs = require('fs')
  , server

  // opentok:
  , opentok = require('opentok')
  , OPENTOK_API_KEY = 'XXXX' // add your API key here
  , OPENTOK_API_SECRET = 'XXXX'; // and your secret here


// create a single instance of opentok sdk.
var ot = new opentok.OpenTokSDK(OPENTOK_API_KEY,OPENTOK_API_SECRET)

server = http.createServer(function(req, res){
  var path = url.parse(req.url).pathname;

  switch (path){
    case '/':
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.write(
        renderExampleHTML(
          OPENTOK_API_KEY,
          ot.sessionId,
          ot.generateToken({
            'connection_data': "userid_" + new Date().getTime(),
            'role': "publisher"
          })
        )
github songz / OpenTokNodeJS / app.js View on Github external
// *** Required modules, Listed in the order of importance
// ***
var OpenTokLibrary = require('opentok');
var express = require('express');

// ***
// *** OpenTok Constants for creating Session and Token values
// ***
var OTKEY = process.env.TB_KEY;
var OTSECRET = process.env.TB_SECRET;

// ***
// *** Setup when server first starts
// ***
var urlSessions = {};
var OpenTokObject = new OpenTokLibrary.OpenTokSDK(OTKEY, OTSECRET);

// ***
// *** Setup Express to handle static files in public folder
// *** Express is also great for handling url routing
// ***
var app = express();
app.use(express.static(__dirname + '/public'));
app.set( 'views', __dirname + "/views");
app.set( 'view engine', 'ejs' );

// ***
// *** When user goes to root directory, redirect them to a room (timestamp)
// ***
app.get("/", function( req, res ){
  res.writeHead(302, { 'Location': Date.now() });
  res.end();

opentok

OpenTok server-side SDK

MIT
Latest version published 2 months ago

Package Health Score

87 / 100
Full package analysis

Popular opentok functions