PHP code example of agence104 / livekit-server-sdk
1. Go to this page and download the library: Download agence104/livekit-server-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
agence104 / livekit-server-sdk example snippets
use Agence104\LiveKit\AccessToken;
use Agence104\LiveKit\AccessTokenOptions;
use Agence104\LiveKit\VideoGrant;
// If this room doesn't exist, it'll be automatically created when the first
// client joins.
$roomName = 'name-of-room';
// The identifier to be used for participant.
$participantName = 'user-name';
// Define the token options.
$tokenOptions = (new AccessTokenOptions())
->setIdentity($participantName);
// Define the video grants.
$videoGrant = (new VideoGrant())
->setRoomJoin();
->setRoomName($roomName);
// Initialize and fetch the JWT Token.
$token = (new AccessToken('api-key', 'secret-key'))
->init($tokenOptions)
->setGrant($videoGrant)
->toJwt();
use Agence104\LiveKit\AccessToken;
// Initialize and parse the JWT Token.
$claimGrants = (new AccessToken('api-key', 'secret-key'))
->fromJwt($token);
use Agence104\LiveKit\VideoGrant;
$videoGrant = (new VideoGrant())
->setRoomJoin() // TRUE by default.
->setRoomName('name-of-room')
->setCanPublish(FALSE)
->setCanSubscribe() // TRUE by default.
->setGrant($videoGrant);
use Agence104\LiveKit\RoomServiceClient;
use Agence104\LiveKit\RoomCreateOptions;
$host = 'https://my.livekit.host';
$svc = new RoomServiceClient($host, 'api-key', 'secret-key');
// List rooms.
$rooms = $svc->listRooms();
// Create a new room.
$opts = (new RoomCreateOptions())
->setName('myroom')
->setEmptyTimeout(10)
->setMaxParticipants(20);
$room = $svc->createRoom($opts);
// Delete a room.
$svc->deleteRoom('myroom');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.