PHP code example of rtippin / janus-client

1. Go to this page and download the library: Download rtippin/janus-client 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/ */

    

rtippin / janus-client example snippets


use RTippin\Janus\Facades\Janus;

$ping = Janus::ping(); 

---------------------------------------

['pong' => true]

---------------------------------------

$room = Janus::videoRoom()->create([
    'description' => 'My first room!',
    'publishers' => 4,
]);

---------------------------------------

[
  'videoroom' => 'created',
  'room' => 6663183870503329,
  'permanent' => false,
  'pin' => 'TFQuls',
  'secret' => 'y2WaVehf7cOM',
]

'server_endpoint' => env('JANUS_SERVER_ENDPOINT'),
'admin_server_endpoint' => env('JANUS_ADMIN_SERVER_ENDPOINT'),
'verify_ssl' => env('JANUS_VERIFY_SSL', true),
'debug' => env('JANUS_DEBUG', false),
'admin_secret' => env('JANUS_ADMIN_SECRET'),
'api_secret' => env('JANUS_API_SECRET'),
'video_room_secret' => env('JANUS_VIDEO_ROOM_SECRET'),

use RTippin\Janus\Facades\Janus;

$info = Janus::info() || Janus::getInstance()->info();



namespace App\Http\Controllers;

use RTippin\Janus\Janus;

class JanusController
{
    private Janus $janus;

    public function __construct(Janus $janus)
    {
       $this->janus = $janus;
    }
}

Janus::info();

Janus::ping();

use RTippin\Janus\Facades\Janus;

Route::get('test', function(){
    Janus::debug()->ping();
    dump('It dumps inline for each http call!');
});

//OUTPUT

"PAYLOAD"

array:3 [▼
  "transaction" => "q52xpYrZJ6e6"
  "apisecret" => "secret"
  "janus" => "ping"
]

"RESPONSE"

array:2 [▼
  "janus" => "pong"
  "transaction" => "q52xpYrZJ6e6"
]

"LATENCY"

16.0

"It dumps inline for each http call!"

Janus::connect();

Janus::attach('janus.plugin.name');

Janus::detach();

Janus::disconnect();

Janus::message(['request' => 'list']);

Janus::trickle('candidate information');

use RTippin\Janus\Facades\Janus;

$server = Janus::server()
    ->setServerEndpoint('http://test.com')
    ->setAdminServerEndpoint('http://test.com/admin')
    ->setApiSecret('secret');
    
Janus::connect();

$response = $server->getApiResponse();
$payload = $server->getApiPayload();
$latency = $server->getEndLatency();

use RTippin\Janus\Facades\Janus;

//Send our command for the results we want.    
Janus::connect()
    ->attach('janus.plugin.videoroom')
    ->message(['request' => 'list']);

//Set the results from the last command sent.
$rooms = Janus::getApiResponse();

//Disconnect and reset all janus values.
Janus::disconnect();

use RTippin\Janus\Facades\Janus;

//Disable disconnects for plugin calls.
Janus::videoRoom()->withoutDisconnect();

//Grab list of rooms.
$rooms = Janus::videoRoom()->list()['list'];

//Destroy each room.
foreach ($rooms as $room) {
    Janus::videoRoom()->destroy($room['room']);
}

//Now disconnect to remove our session/handle.
Janus::videoRoom()->disconnect(true); //Forced on current plugin instance.
---------------------------------------------------------------------------
Janus::disconnect(); //Main disconnect will always be run if called.

//Make plugin call. 
Janus::videoRoom()->list();

//Get response.
$list = Janus::videoRoom()->getPluginResponse('list');

//Make plugin call. 
Janus::videoRoom()->list();

//Get payload.
$payload = Janus::videoRoom()->getPluginPayload();

use RTippin\Janus\Facades\Janus;

$videoRoom = Janus::videoRoom();



namespace App\Http\Controllers;

use RTippin\Janus\Plugins\VideoRoom;

class VideoRoomController
{
    private VideoRoom $videoRoom;

    public function __construct(VideoRoom $videoRoom)
    {
       $this->videoRoom = $videoRoom;
    }
}

$list = Janus::videoRoom()->list();

$exists = Janus::videoRoom()->exists(12345678);

$room = Janus::videoRoom()->create([
    'description' => 'My first room!',
    'publishers' => 10,
    'bitrate' => 1024000,
    'is_private' => true,
]);

$newProperties = [
    'new_description' => 'First room!',
    'new_bitrate' => 600000,
];

$edit = Janus::videoRoom()->edit(12345678, $newProperties, 'SECRET');

$allowed = Janus::videoRoom()->allowed(12345678, 'remove', ['token'], 'SECRET');

$kick = Janus::videoRoom()->kick(12345678, 987654321, 'SECRET');

$participants = Janus::videoRoom()->listParticipants(12345678);

$forwarders = Janus::videoRoom()->listForwarders(12345678, 'SECRET');

$destroy = Janus::videoRoom()->destroy(12345678, 'SECRET');

$moderate = Janus::videoRoom()->moderate(12345678, 987654321, true, 'm-line' 'SECRET');

$record = Janus::videoRoom()->enableRecording(12345678, true, 'SECRET');

use RTippin\Janus\Facades\Janus;

//Disable disconnect between each method call.
Janus::videoRoom()->withoutDisconnect();

//Run methods as needed. Connect and attach will only be called once.
if (Janus::videoRoom()->exists(12345678)['exists']) {
    Janus::videoRoom()->destroy(12345678);
}

//Disconnect and reset all janus values.
Janus::disconnect();
 bash
php artisan vendor:publish --tag=janus