Skip to content

Commit

Permalink
Clean up dead staging code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Pedrick committed Aug 28, 2012
1 parent 8ee1147 commit 89c56c7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 74 deletions.
11 changes: 2 additions & 9 deletions README.md
Expand Up @@ -20,26 +20,19 @@ To install as a regular npm package just type `npm install opentok`

### API key and API secret

Request your API key and API secret at <http://www.tokbox.com/opentok/api/tools/js/apikey>. You can use the staging environment for development. This package uses this staging environment by default.
Request your API key and API secret at <http://www.tokbox.com/opentok/api/tools/js/apikey>.

### 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 *API key* and *API secret*. If your app is in production, you must also pass in a object containing the `API_URL` property.
For more information about production apps, check out <http://www.tokbox.com/opentok/api/tools/documentation/overview/production.html#launching>.
You must pass in your *API key* and *API secret*.

Example: ( Staging )
<pre>
var key = ''; // Replace with your API key
var secret = ''; // Replace with your API secret
var opentok = new OpenTok.OpenTokSDK(key, secret);
</pre>

Example: ( Production )
<pre>
var opentok = new OpenTok.OpenTokSDK(key, secret, {API_URL:'https://api.opentok.com/hl'});
</pre>

### Creating Sessions
Use your `OpenTokSDK` object to create a `session_id`. See <http://www.tokbox.com/opentok/api/tools/documentation/api/server_side_libraries.html#create_session> for more details.
`createSession` takes 2-3 parameters:
Expand Down
7 changes: 1 addition & 6 deletions examples/app.js
Expand Up @@ -12,11 +12,6 @@ var http = require('http')
// create a single instance of opentok sdk.
var ot = new opentok.OpenTokSDK(OPENTOK_API_KEY,OPENTOK_API_SECRET)

// set the tokbox host, for dev: staging.tokbox.com, for prod: api.opentok.com
// it defaults to staging.tokbox.com, so you only need to set it in prod:
//
// ot.setEnvironment("staging.tokbox.com")

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

Expand Down Expand Up @@ -60,7 +55,7 @@ renderExampleHTML = function(apikey, sessionId, token){
'<html>\n',
'<head>\n',
'<title>OpenTok Hello World</title>\n',
'<script src="http://staging.tokbox.com/v0.91/js/TB.min.js"></script>\n',
'<script src="http://static.opentok.com/v0.91/js/TB.min.js"></script>\n',
'<script>\n',
'var apikey = "',apikey,'"\n',
' , sessionId = "',sessionId,'"\n',
Expand Down
24 changes: 3 additions & 21 deletions lib/opentok.js
Expand Up @@ -4,8 +4,7 @@ var https = require('https')

// tokbox constants:
, TOKEN_SENTINEL = "T1=="
, STAGING_HOST = "staging.tokbox.com"
, PROD_HOST = "api.opentok.com"
, API_HOST = "api.opentok.com"
, SESSION_API_ENDPOINT = "/hl/session/create"
, GET_MANIFEST = "/archive/getmanifest/"
, GET_URL = "/hl/archive/url/";
Expand All @@ -22,27 +21,10 @@ var OpenTokSession = function(sessionId){
}

// OpenTokSDK constructor
var OpenTokSDK = exports.OpenTokSDK = function(partnerId, partnerSecret, properties){
var OpenTokSDK = exports.OpenTokSDK = function(partnerId, partnerSecret){
this.partnerId = partnerId
this.partnerSecret = partnerSecret
this.api_url = STAGING_HOST;

if(properties && properties['API_URL']){
if(properties['API_URL'].split('staging').length > 1){
// This is meant to guart against http://staging.tokbox.com vs staging.tokbox.com vs https...
this.api_url = STAGING_HOST;
}else{
this.api_url = PROD_HOST;
}
}
}

OpenTokSDK.prototype.setEnvironment = function(host){
if(host.split('staging').length >1 ){
this.api_url = STAGING_HOST
}else{
this.api_url = PROD_HOST
}
this.api_url = API_HOST;
}

OpenTokSDK.OpenTokArchive = function(sdkObject){
Expand Down
46 changes: 8 additions & 38 deletions spec/opentok_spec.coffee
@@ -1,20 +1,15 @@
OpenTok = require('../lib/opentok')

describe "Staging Environment", ->
stagingKey = '14971292'
stagingSecret = 'ecbe2b25afec7887bd72fe4763b87add8ce02658'
opentok = new OpenTok.OpenTokSDK(stagingKey, stagingSecret, {API_URL:'staging.tokbox.com'})

it "should pass in apikey, secret, and api_url", ->
expect(opentok.partnerId).toEqual(stagingKey)
expect(opentok.partnerSecret).toEqual(stagingSecret)
expect(opentok.api_url).toEqual('staging.tokbox.com')
describe "Production Environment", ->
apiKey = '14971292'
apiSecret = 'ecbe2b25afec7887bd72fe4763b87add8ce02658'
opentok = new OpenTok.OpenTokSDK(apiKey, apiSecret)

it "should auto set api_url defaults", ->
opentok = new OpenTok.OpenTokSDK(stagingKey, stagingSecret)
expect(opentok.partnerId).toEqual(stagingKey)
expect(opentok.partnerSecret).toEqual(stagingSecret)
expect(opentok.api_url).toEqual('staging.tokbox.com')
opentok = new OpenTok.OpenTokSDK(apiKey, apiSecret)
expect(opentok.partnerId).toEqual(apiKey)
expect(opentok.partnerSecret).toEqual(apiSecret)
expect(opentok.api_url).toEqual('api.opentok.com')

it "should create session", ->
sessionId = null
Expand Down Expand Up @@ -62,31 +57,6 @@ describe "Staging Environment", ->
expect(tokenBuffer.split('hello').length).toBeGreaterThan(1)
expect(tokenBuffer.split(sessionId).length).toBeGreaterThan(1)


describe "Production Environment", ->
stagingKey = '11421872'
stagingSecret = '296cebc2fc4104cd348016667ffa2a3909ec636f'
opentok = new OpenTok.OpenTokSDK(stagingKey, stagingSecret, {API_URL:'https://api.opentok.com/hl'})

it "should pass in apikey, secret, and api_url", ->
expect(opentok.partnerId).toEqual(stagingKey)
expect(opentok.partnerSecret).toEqual(stagingSecret)
expect(opentok.api_url).toEqual('api.opentok.com')

it "should create session", ->
sessionId = null
queryFinished = false

waitsFor ->
return queryFinished
runs ->
expect(sessionId).not.toBeNull()
expect(sessionId.length).toBeGreaterThan(5)

opentok.createSession 'localhost', (result) ->
sessionId = result
queryFinished = true

describe 'Archiving', ->
sessionId = '1_MX4xNDk3MTI5Mn5-MjAxMi0wNS0yMCAwMTowMzozMS41MDEzMDArMDA6MDB-MC40NjI0MjI4MjU1MDF-'
token = opentok.generateToken({session_id:sessionId, role:OpenTok.RoleConstants.MODERATOR})
Expand Down

0 comments on commit 89c56c7

Please sign in to comment.