Last active
September 7, 2015 20:29
-
-
Save jeanlescure/25985d37a092f80aec83 to your computer and use it in GitHub Desktop.
First half of OpenTok NodeJS server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var server = express(); | |
var OpenTok = require('opentok'); | |
//Replace this with your OpenTok API key and OpenTok Secret | |
var opentok = new OpenTok('API_KEY', 'SECRET'); | |
var SESSION_ID; | |
var QUALITY_SESSION_ID; | |
// Before starting server we need two OpenTok session id's | |
// one for quality testing and one for our call | |
console.log('Creating OpenTok quality session...'); | |
opentok.createSession({mediaMode:"routed"}, function(error, result) { | |
if (error) { | |
console.log("Error creating quality session:", error); | |
process.exit(1); | |
} else { | |
QUALITY_SESSION_ID = result.sessionId; | |
console.log('Quality session created...'); | |
} | |
}); | |
console.log('Creating OpenTok session...'); | |
opentok.createSession({mediaMode:"relayed"}, function(error, result) { | |
if (error) { | |
console.log("Error creating session:", error); | |
process.exit(1); | |
} else { | |
SESSION_ID = result.sessionId; | |
fs.writeFile('last_session.id', SESSION_ID, function (err) { | |
if (err){ | |
console.log("Error creating session:", err); | |
process.exit(1); | |
} | |
// Session creation was successful, | |
// now we start the server | |
console.log('Session created...'); | |
start_server(); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment