Ulises Vargas De Sousa Ulises Vargas De Sousa - 2 months ago 12
Node.js Question

Using dynamic sessionId and token in OpenTok-Angular

I want try the aullman example OpenTok-Angular: https://github.com/aullman/OpenTok-Angular

But, in the second step (Replace your apiKey, sessionId and token in the demo.html file), I want replace with my sessionId and token generated dynamically by OpenTok SDK Node.js (that I've done already in app.js)

How I could do it?

PS: MY app.js FILE that render in view apiKey, sessionId and Token:

// Dependencies
var express = require('express');
var server_port = process.env.PORT || 3000;
var newSession = require('./credentialsPromise').newSession(); //obtains the promise with sessionId and token generated dynamically

var app = express();

app.use(express.static(__dirname + '/public'));

//Init the app

app.get('/', function(req, res){
var obj = req;
//Render in view
res.render('index.ejs', {
apiKey: obj.apiKey,
sessionId: obj.sessionId,
token: obj.tokenId
}, function(reject){ //rejected
console.log("Error, cannot use promise");

function init() {
app.listen(server_port, function() {
console.log('App is running in localhost:' + server_port);


I just had to change the demo.html to index.ejs and store it in views folder (modifying the paths, obviously).

Then, I've changed my apiKey, sessionId and token by values that returns app.js, as follow:

  angular.module('demo', ['opentok'])
            .controller('MyCtrl', ['$scope', 'OTSession', 'apiKey', 'sessionId', 'token', function($scope, OTSession, apiKey, sessionId, token) {
                OTSession.init(apiKey, sessionId, token);
                $scope.streams = OTSession.streams;
                apiKey: '<%= apiKey %>',
                sessionId: '<%= sessionId %>',
                token: '<%= token %>'