2016-03-05 72 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。