Search code examples
phpsessionopentok

Opentok php server sdk, session and token not working


I need help for my Php server in opentok this is my online website that i created

mrsvideocall.bugs3.com/Engine.php

the url above gives you session and token

it has output session id and token but.. when i tried that output. the token and the session is not connecting

if you want to try you can use my apikey and api secret this was just my trial account

api key : 45007972

api secret: xxxxxxxxxxxxxxxxxxxxxxx

try it. .it wont work

I dont know why.

this the code inside my php file. .is there anything wrong?

<?php
require "vendor/autoload.php";

use OpenTok\OpenTok;
use OpenTok\Session;
use OpenTok\Role; 
use OpenTok\MediaMode;

$API_KEY = "45007972";
$API_SECRET = "xxxxxxxxxxxxxxxxxxxxxxx";
$opentok = new OpenTok($API_KEY, $API_SECRET);

// Create a session that attempts to use peer-to-peer streaming:
$session = $opentok->createSession();
$session = $opentok->createSession(array('mediaMode' => MediaMode::ROUTED ));
// Store this sessionId in the database for later use
echo $sessionId = $session->getSessionId();

// Generate a Token from just a sessionId (fetched from a database)
$token = $opentok->generateToken($sessionId);
// Generate a Token by calling the method on the Session (returned from createSession)
$token = $session->generateToken();

// Set some options in a token
echo $token = $session->generateToken(array(
'role' => Role::PUBLISHER,
'expireTime' => time()+(7 * 24 * 60 * 60), // in one week
'data' => 'name=Eleo'
));

if i just make session and token at dashboard it was working but when i tried the result of my token and session generator it does not work it has result but not working


Solution

  • I just tried the sessionId and token generated at your URL and they worked fine to connect. One caveat was that you also echo-ed a literal \n between the two values so I had to separate them. If you are having trouble connecting to the session, could you please share what error you are seeing and what client side code you have used?

    Also, please read through the comments in the code you copy/pasted. You are actually generating 2 sessions and 3 tokens, but only outputting one of each, so you are unnecessarily doing extra work.