I'm using the opentok SDK for video chatting, and I need to create sessions. It's pretty straightforward, and that part's working fine. This is all being done in node.js, server side.
The issues is - and it's mostly cause I still don't quite get var scopes (especially with anonymous functions and closures) - I have a value inside of my anonymous function that I want to access (preferably by assigning it to another var, one that's in its parent scope), but can't!
Something like this:
function generateSession(session){
var session='';
opentok.createSession(function(error, sessionId){
if (error) {
throw new Error("Session creation failed.");
}
session = sessionId;
});
return session;
}
session
retains it's initial value of '' (empty string), not the sessionId
it was assigned to. Help?