我想试试aullman示例OpenTok-Angular:https://github.com/aullman/OpenTok-Angular
但是,在第二步(替换demo.html文件中的apiKey,sessionId和token),我想要替换我的sessionId和由OpenTok SDK Node.js动态生成的令牌(我已经完成了在app.js)
我怎么能这样做?
PS:我在视图apiKey,sessionId和令牌中呈现的app.js文件:
// 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
init();
app.get('/', function(req, res){
//Promise
newSession.then(function(req){
//fullfilled
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);
});
}

答案 0 :(得分:0)
使用节点js创建一个Rest API,并从您的angular js页面调用该api。从节点js获得成功响应后,在变量中获取该会话ID和令牌并传入您的角度js方法。
如何创建Rest API。 http://www.tutorialspoint.com/nodejs/nodejs_restful_api.htm
答案 1 :(得分:0)
我只需将demo.html更改为index.ejs并将其存储在views文件夹中(显然修改路径)。
然后,我通过返回app.js的值更改了我的apiKey,sessionId和token,如下所示:
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;
}]).value({
apiKey: '<%= apiKey %>',
sessionId: '<%= sessionId %>',
token: '<%= token %>'
});
&#13;