Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
- ubuntu-latest
strategy:
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
steps:
- name: Configure Git
if: ${{ matrix.os == 'windows-latest' }}
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ docs/
.phpdoc/
phpDocumentor*
.phpunit.result.cache
.idea/*
.idea/*
var/
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"issues": "https://github.com/opentok/Opentok-PHP-SDK/issues"
},
"require": {
"php": "^7.2|^8.0",
"php": "^8.1|^8.2|^8.3|^8.4|^8.5",
"ext-xml": "*",
"johnstevenson/json-works": "~1.1",
"firebase/php-jwt": "^6.11",
Expand All @@ -37,14 +37,14 @@
"vonage/jwt": "^0.5.1"
},
"require-dev": {
"phpunit/phpunit": "^7.4|^8.0",
"phpunit/phpunit": "^8.0",
"php-http/mock-client": "^1.4",
"helmich/phpunit-json-assert": "^3.0.0",
"squizlabs/php_codesniffer": "^3.1",
"php-http/guzzle7-adapter": "^1.0",
"phpstan/phpstan": "^0.12",
"rector/rector": "^0.8",
"phing/phing": "~2.16.0"
"phpstan/phpstan": "^1.10",
"phing/phing": "~2.16.0",
"rector/rector": "^1.0"
},
"scripts": {
"phpstan": "./vendor/bin/phpstan",
Expand Down
46 changes: 46 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/examples',
__DIR__ . '/sample',
__DIR__ . '/tests',
]);

// Define a clear cache directory
$rectorConfig->cacheDirectory(__DIR__ . '/var/cache/rector');

// Here we can define what rule sets we want to apply
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
SetList::CODE_QUALITY,
SetList::DEAD_CODE,
SetList::PRIVATIZATION,
SetList::TYPE_DECLARATION,
SetList::EARLY_RETURN,
]);

// Skip certain files or directories if needed
$rectorConfig->skip([
__DIR__ . '/vendor',
__DIR__ . '/var',
__DIR__ . '/tools',
]);

// Import names (classes, functions) automatically
$rectorConfig->importNames();
$rectorConfig->importShortClasses();

// Register file extensions
$rectorConfig->fileExtensions(['php']);

// Parallel processing - adjust number based on your CPU cores
$rectorConfig->parallel();
};
5 changes: 0 additions & 5 deletions rector.yaml

This file was deleted.

78 changes: 24 additions & 54 deletions sample/Archiving/web/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Slim\Views\Twig;

$autoloader = __DIR__ . '/../vendor/autoload.php';
$sdkAutoloader = __DIR__ . '/../../../vendor/autoload.php';

Expand All @@ -23,7 +25,7 @@
use OpenTok\OutputMode;

// PHP CLI webserver compatibility, serving static files
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', (string) $_SERVER['REQUEST_URI']);
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
return false;
}
Expand All @@ -34,109 +36,77 @@
}

// Initialize Slim application
$app = new Slim(array(
'templates.path' => __DIR__ . '/../templates',
'view' => new \Slim\Views\Twig(),
));
$app = new Slim(['templates.path' => __DIR__ . '/../templates', 'view' => new Twig()]);

// Intialize a cache, store it in the app container
$app->container->singleton('cache', function () {
return new Cache();
});
$app->container->singleton('cache', fn(): Cache => new Cache());

// Initialize OpenTok instance, store it in the app contianer
$app->container->singleton('opentok', function () {
return new OpenTok(getenv('API_KEY'), getenv('API_SECRET'));
});
$app->container->singleton('opentok', fn(): OpenTok => new OpenTok(getenv('API_KEY'), getenv('API_SECRET')));
// Store the API Key in the app container
$app->apiKey = getenv('API_KEY');

// If a sessionId has already been created, retrieve it from the cache
$sessionId = $app->cache->getOrCreate('sessionId', array(), function () use ($app) {
$sessionId = $app->cache->getOrCreate('sessionId', [], function () use ($app) {
// If the sessionId hasn't been created, create it now and store it
$session = $app->opentok->createSession(array(
'mediaMode' => MediaMode::ROUTED
));
$session = $app->opentok->createSession(['mediaMode' => MediaMode::ROUTED]);
return $session->getSessionId();
});

// Configure routes
$app->get('/', function () use ($app) {
$app->get('/', function () use ($app): void {
$app->render('index.html');
});

$app->get('/host', function () use ($app, $sessionId) {
$app->get('/host', function () use ($app, $sessionId): void {

$token = $app->opentok->generateToken($sessionId, array(
'role' => Role::MODERATOR
));
$token = $app->opentok->generateToken($sessionId, ['role' => Role::MODERATOR]);

$app->render('host.html', array(
'apiKey' => $app->apiKey,
'sessionId' => $sessionId,
'token' => $token
));
$app->render('host.html', ['apiKey' => $app->apiKey, 'sessionId' => $sessionId, 'token' => $token]);
});

$app->get('/participant', function () use ($app, $sessionId) {
$app->get('/participant', function () use ($app, $sessionId): void {

$token = $app->opentok->generateToken($sessionId, array(
'role' => Role::MODERATOR
));
$token = $app->opentok->generateToken($sessionId, ['role' => Role::MODERATOR]);

$app->render('participant.html', array(
'apiKey' => $app->apiKey,
'sessionId' => $sessionId,
'token' => $token
));
$app->render('participant.html', ['apiKey' => $app->apiKey, 'sessionId' => $sessionId, 'token' => $token]);
});

$app->get('/history', function () use ($app) {
$app->get('/history', function () use ($app): void {
$page = intval($app->request->get('page'));
if (empty($page)) {
if ($page === 0) {
$page = 1;
}

$offset = ($page - 1) * 5;

$archives = $app->opentok->listArchives($offset, 5);

$toArray = function ($archive) {
return $archive->toArray();
};
$toArray = fn($archive) => $archive->toArray();

$app->render('history.html', array(
'archives' => array_map($toArray, $archives->getItems()),
'showPrevious' => $page > 1 ? '/history?page=' . ($page - 1) : null,
'showNext' => $archives->totalCount() > $offset + 5 ? '/history?page=' . ($page + 1) : null
));
$app->render('history.html', ['archives' => array_map($toArray, $archives->getItems()), 'showPrevious' => $page > 1 ? '/history?page=' . ($page - 1) : null, 'showNext' => $archives->totalCount() > $offset + 5 ? '/history?page=' . ($page + 1) : null]);
});

$app->get('/download/:archiveId', function ($archiveId) use ($app) {
$app->get('/download/:archiveId', function ($archiveId) use ($app): void {
$archive = $app->opentok->getArchive($archiveId);
$app->redirect($archive->url);
});

$app->post('/start', function () use ($app, $sessionId) {
$app->post('/start', function () use ($app, $sessionId): void {

$archive = $app->opentok->startArchive($sessionId, array(
'name' => "PHP Archiving Sample App",
'hasAudio' => ($app->request->post('hasAudio') == 'on'),
'hasVideo' => ($app->request->post('hasVideo') == 'on'),
'outputMode' => ($app->request->post('outputMode') == 'composed' ? OutputMode::COMPOSED : OutputMode::INDIVIDUAL)
));
$archive = $app->opentok->startArchive($sessionId, ['name' => "PHP Archiving Sample App", 'hasAudio' => ($app->request->post('hasAudio') == 'on'), 'hasVideo' => ($app->request->post('hasVideo') == 'on'), 'outputMode' => ($app->request->post('outputMode') == 'composed' ? OutputMode::COMPOSED : OutputMode::INDIVIDUAL)]);

$app->response->headers->set('Content-Type', 'application/json');
echo $archive->toJson();
});

$app->get('/stop/:archiveId', function ($archiveId) use ($app) {
$app->get('/stop/:archiveId', function ($archiveId) use ($app): void {
$archive = $app->opentok->stopArchive($archiveId);
$app->response->headers->set('Content-Type', 'application/json');
echo $archive->toJson();
});

$app->get('/delete/:archiveId', function ($archiveId) use ($app) {
$app->get('/delete/:archiveId', function ($archiveId) use ($app): void {
$app->opentok->deleteArchive($archiveId);
$app->redirect('/history');
});
Expand Down
24 changes: 7 additions & 17 deletions sample/HelloWorld/web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use OpenTok\OpenTok;

// PHP CLI webserver compatibility, serving static files
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', (string) $_SERVER['REQUEST_URI']);
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
return false;
}
Expand All @@ -31,27 +31,21 @@
}

// Initialize Slim application
$app = new Slim(array(
'templates.path' => __DIR__ . '/../templates'
));
$app = new Slim(['templates.path' => __DIR__ . '/../templates']);

// Intialize a cache, store it in the app container
$app->container->singleton('cache', function () {
return new Cache();
});
$app->container->singleton('cache', fn(): Cache => new Cache());

// Initialize OpenTok instance, store it in the app contianer
$app->container->singleton('opentok', function () {
return new OpenTok(getenv('API_KEY'), getenv('API_SECRET'));
});
$app->container->singleton('opentok', fn(): OpenTok => new OpenTok(getenv('API_KEY'), getenv('API_SECRET')));
// Store the API Key in the app container
$app->apiKey = getenv('API_KEY');

// Configure routes
$app->get('/', function () use ($app) {
$app->get('/', function () use ($app): void {

// If a sessionId has already been created, retrieve it from the cache
$sessionId = $app->cache->getOrCreate('sessionId', array(), function () use ($app) {
$sessionId = $app->cache->getOrCreate('sessionId', [], function () use ($app) {
// If the sessionId hasn't been created, create it now and store it
$session = $app->opentok->createSession();
return $session->getSessionId();
Expand All @@ -60,11 +54,7 @@
// Generate a fresh token for this client
$token = $app->opentok->generateToken($sessionId);

$app->render('helloworld.php', array(
'apiKey' => $app->apiKey,
'sessionId' => $sessionId,
'token' => $token
));
$app->render('helloworld.php', ['apiKey' => $app->apiKey, 'sessionId' => $sessionId, 'token' => $token]);
});

$app->run();
47 changes: 14 additions & 33 deletions sample/SipCall/web/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use OpenTok\MediaMode;

// PHP CLI webserver compatibility, serving static files
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', $_SERVER['REQUEST_URI']);
$filename = __DIR__ . preg_replace('#(\?.*)$#', '', (string) $_SERVER['REQUEST_URI']);
if (php_sapi_name() === 'cli-server' && is_file($filename)) {
return false;
}
Expand All @@ -32,62 +32,43 @@
}

// Initialize Slim application
$app = new Slim(array(
'templates.path' => __DIR__ . '/../templates'
));
$app = new Slim(['templates.path' => __DIR__ . '/../templates']);

// Intialize a cache, store it in the app container
$app->container->singleton('cache', function () {
return new Cache();
});
$app->container->singleton('cache', fn(): Cache => new Cache());

// Initialize OpenTok instance, store it in the app contianer
$app->container->singleton('opentok', function () {
return new OpenTok(getenv('API_KEY'), getenv('API_SECRET'));
});
$app->container->singleton('opentok', fn(): OpenTok => new OpenTok(getenv('API_KEY'), getenv('API_SECRET')));
// Store the API Key in the app container
$app->apiKey = getenv('API_KEY');

$app->sip = array(
'uri' => getenv('SIP_URI'),
'username' => getenv('SIP_USERNAME'),
'password' => getenv('SIP_PASSWORD'),
'secure' => (getenv('SIP_SECURE') === 'true'),
'from' => getenv('SIP_FROM'),
);
$app->sip = ['uri' => getenv('SIP_URI'), 'username' => getenv('SIP_USERNAME'), 'password' => getenv('SIP_PASSWORD'), 'secure' => (getenv('SIP_SECURE') === 'true'), 'from' => getenv('SIP_FROM')];

// Configure routes
$app->get('/', function () use ($app) {
$app->get('/', function () use ($app): void {
// If a sessionId has already been created, retrieve it from the cache
$sessionId = $app->cache->getOrCreate('sessionId', array(), function () use ($app) {
$sessionId = $app->cache->getOrCreate('sessionId', [], function () use ($app) {
// If the sessionId hasn't been created, create it now and store it
$session = $app->opentok->createSession(array('mediaMode' => MediaMode::ROUTED));
$session = $app->opentok->createSession(['mediaMode' => MediaMode::ROUTED]);
return $session->getSessionId();
});

// Generate a fresh token for this client
$token = $app->opentok->generateToken($sessionId, array('role' => 'moderator'));
$token = $app->opentok->generateToken($sessionId, ['role' => 'moderator']);

$app->render('index.php', array(
'apiKey' => $app->apiKey,
'sessionId' => $sessionId,
'token' => $token
));
$app->render('index.php', ['apiKey' => $app->apiKey, 'sessionId' => $sessionId, 'token' => $token]);
});

$app->post('/sip/start', function () use ($app) {
$app->post('/sip/start', function () use ($app): void {
$sessionId = $app->request->post('sessionId');

// generate a token
$token = $app->opentok->generateToken($sessionId, array('data' => 'sip=true'));
$token = $app->opentok->generateToken($sessionId, ['data' => 'sip=true']);

// create the options parameter
$options = array(
'secure' => $app->sip['secure'],
'from' => $app->sip['from'],
);
$options = ['secure' => $app->sip['secure'], 'from' => $app->sip['from']];
if ($app->sip['username'] !== false) {
$options['auth'] = array('username' => $app->sip['username'], 'password' => $app->sip['password']);
$options['auth'] = ['username' => $app->sip['username'], 'password' => $app->sip['password']];
}

// make the sip call
Expand Down
Loading
Loading