Update: 2026-06-11 18:22:57

This commit is contained in:
Hamza-Ayed
2026-06-11 18:22:59 +03:00
parent c5170a88d2
commit 727068b668
629 changed files with 46050 additions and 46109 deletions

Binary file not shown.

View File

@@ -0,0 +1,52 @@
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Replace with your actual credentials
$appId = '12994c6e707543e68d5638894d04f989';
$appCertificate = 'e21a388f83034a159f2783889a6d7bcf';
// Set server port
$port = 8080;
// Function to generate Agora token
function generateToken($channelName, $uid = 0, $role = RtcRole::SUBSCRIBER, $expireTime = 360) {
// Check mandatory parameter
if (!$channelName) {
throw new Exception('Channel name is required');
}
// Calculate privilege expiration time
$currentTime = time();
$privilegeExpireTime = $currentTime + $expireTime;
// Build and return token
return RtcTokenBuilder::buildTokenWithUid($appId, $appCertificate, $channelName, $uid, $role, $privilegeExpireTime);
}
// Create server using Slim Framework
$app = new Slim\App();
// Token generation endpoint
$app->get('/token', function ($request, $response) use ($app, $appId, $appCertificate) {
// Get parameters
$channelName = $request->getQueryParam('channelName');
$uid = $request->getQueryParam('uid', 0);
$role = $request->getQueryParam('role', RtcRole::SUBSCRIBER);
$expireTime = $request->getQueryParam('expireTime', 3600);
try {
// Generate token
$token = generateToken($channelName, $uid, $role, $expireTime);
// Respond with JSON
$response->withJson(['token' => $token]);
} catch (Exception $e) {
// Handle error
$response->withStatus(500)->withJson(['error' => $e->getMessage()]);
}
});
// Start server
$app->run($port);

View File

@@ -0,0 +1,9 @@
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var message = 'It works!\n',
version = 'NodeJS ' + process.versions.node + '\n',
response = [message, version].join('\n');
res.end(response);
});
server.listen();