2016-03-05 138 views
0

在我的iOS应用程序中,我使用TokBox实现私人视频聊天功能。 我需要为每个私人聊天创建一个随机的会话ID,使用Server SDK API,我很难理解如何去做。生成随机会话ID OpenTok

我成功地完成了文档“学习opentok-PHP”中列出的所有步骤的opentok GitHub的页面上可用。 我将我的OpenTok应用程序与Heroku连接起来,并配置了“web/index.php”以在浏览器中显示静态的“SESSION_ID”和“TOKEN_ID”。

如文档中所述,“示例应用程序”使用单个会话ID,并且不会为每个调用生成新的会话ID。请有人提供一些例子或建议如何配置我的应用程序生成每次不同的会话ID?

+0

阅读此:https://github.com/opentok/learning-opentok-php#1-generate-a-session-and-token – user818455

+0

感谢您的建议。您在文章中提到的代码行存储在名为index.js的文件中 – user4950087

回答

0
$app->get('/', function() use ($app) { 
// If a sessionId has already been created, retrieve it from the cache 
$sessionId = $app->cache->getOrCreate('sessionId', array(), function() use ($app) { 
    // If the sessionId hasn't been created, create it now and store it 
    $session = $app->opentok->createSession(); 
    return $session->getSessionId(); 
}); 
// Generate a fresh token for this client 
$token = $app->opentok->generateToken($sessionId); 
$app->render('helloworld.php', array(
    'apiKey' => $app->apiKey, 
    'sessionId' => $sessionId, 
    'token' => $token 
)); 

}); 试试这个代码

在服务器上发送请求获取每次新的sessionId。