I’m running this code server-side:
var sessionId;
//Generate a basic session. Or you could use an existing session ID.
opentok.createSession({mediaMode:'routed', archiveMode:'always'}, function(error, session) {
if (error) {
throw new Meteor.Error(500, error.message);
} else {
sessionId = session.sessionId;
console.log('Created session',sessionId);
return session.sessionId;
}
});
console.log(sessionId);
And the createSession method is running successfully. I’m getting the ‘Created session’ and a session id, but I can’t figure out how to access sessionId outside that callback function. The following console.log(sessionId) returns undefined, and it seems to return it before createSession runs. So what’s the smart move here? This is a collection. It’s impossible to get the sessionId at this point.