【问题标题】:generate random session IDs OpenTok生成随机会话 ID OpenTok
【发布时间】:2016-05-24 20:11:00
【问题描述】:

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

我成功完成了 opentok github 页面上提供的文档“learning-opentok-php”中列出的所有步骤。 我将我的 OpenTok 应用程序与 Heroku 相关联,并配置“web/index.php”以在我的浏览器上显示静态“SESSION_ID”和“TOKEN_ID”。

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

【问题讨论】:

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

标签: php session heroku opentok


【解决方案1】:
$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 时在服务器上发送请求。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 2011-02-02
    • 2021-09-16
    • 2011-10-17
    • 1970-01-01
    • 2013-01-21
    • 2021-02-07
    相关资源
    最近更新 更多