0

Notice: Undefined variable: streamId in C:\xampp\htdocs\vonagephp\index.php on line 46

This is the problem. I hope someone can help me. I am creating a opentok video using the php sdk but I have come across this issue. I will be very happy if someone who has this issue can help me out. Thanks guys

 require 'vendor/autoload.php';
   
use OpenTok\OpenTok;
$apiKey = "key";
$apiSecret = "secret";
$opentok = new OpenTok($apiKey, $apiSecret);
  
use OpenTok\MediaMode;
use OpenTok\ArchiveMode;

// Create a session that attempts to use peer-to-peer streaming:
$session = $opentok->createSession();

// A session that uses the OpenTok Media Router, which is required for archiving:
$session = $opentok->createSession(array( 'mediaMode' => MediaMode::ROUTED ));

// A session with a location hint:
$session = $opentok->createSession(array( 'location' => '12.34.56.78' ));

// An automatically archived session:
$sessionOptions = array(
    'archiveMode' => ArchiveMode::ALWAYS,
    'mediaMode' => MediaMode::ROUTED
);
 $session = $opentok->createSession($sessionOptions);


// Store this sessionId in the database for later use
 $sessionId = $session->getSessionId();
   
   use OpenTok\Session;

// Get stream info from just a sessionId (fetched from a database)
$stream = $opentok->getStream($sessionId, $streamId);

// Stream properties
$stream->id; // string with the stream ID
$stream->videoType; // string with the video type
$stream->name; // string with the name
$stream->layoutClassList; // array with the layout class list


 

// Get list of streams from just a sessionId (fetched from a database)
$streamList = $opentok->listStreams($sessionId);

$streamList->totalCount(); // total count 
 
 // Create a simple archive of a session
$archive = $opentok->startArchive($sessionId);


// Create an archive using custom options
$archiveOptions = array(
    'name' => 'Important Presentation',     // default: null
    'hasAudio' => true,                     // default: true
    'hasVideo' => true,                     // default: true
    'outputMode' => OutputMode::COMPOSED,   // default: OutputMode::COMPOSED
    'resolution' => '1280x720'              // default: '640x480'
);
$archive = $opentok->startArchive($sessionId, $archiveOptions);

// Store this archiveId in the database for later use
$archiveId = $archive->id;

// Stop an Archive from an archiveId (fetched from database)
$opentok->stopArchive($archiveId);
// Stop an Archive from an Archive instance (returned from startArchive)
$archive->stop();

$archive = $opentok->getArchive($archiveId);

// Delete an Archive from an archiveId (fetched from database)
$opentok->deleteArchive($archiveId);
// Delete an Archive from an Archive instance (returned from startArchive, getArchive)
$archive->delete();

$archiveList = $opentok->listArchives();

I am creating a opentok video using the php sdk but I have come across this issue. I will be very happy if someone who has this issue can help me out. Thanks guys

1 Answers1

1

Well, it's just as the error suggests: you're trying to use the variable $streamId, but the interpreter doesn't know this variable, as you didn't create it yet.

I don't know OpenTok, so I'm not sure what it expects here, but you should do something like:

$streamId = 1234

BEFORE using it in $opentok->getStream()

user3478148
  • 433
  • 1
  • 8
  • 26
  • Bro, you're right. I think OpenTok should come and explain this. It's part of the PHP code. Clearly,the has not been defined anywhere as far as I know –  Sep 09 '20 at 01:45