PHP code example of raqmeyat / webrtc

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

    

raqmeyat / webrtc example snippets


'participant_types' => [
    'user'   => App\Models\User::class,
    'staff' => App\Models\Staff::class,
],

use Raqmeyat\WebRtc\Contracts\InvitationPolicy;
use Raqmeyat\WebRtc\DTOs\CreateSessionData;
use Raqmeyat\WebRtc\DTOs\ParticipantRef;

final class TripCallPolicy implements InvitationPolicy
{
    public function allows(ParticipantRef $initiator, ParticipantRef $invitee, CreateSessionData $data): bool
    {
        return $data->subject?->type === 'trip'
            && Trip::query()->whereKey($data->subject->id)->involving($initiator, $invitee)->exists();
    }
}

use Raqmeyat\WebRtc\IceProviders\IceServerManager;

app(IceServerManager::class)->extend('twilio', fn ($app) => new TwilioIceProvider(...));

'database' => [
    'connection' => env('WEBRTC_DB_CONNECTION'),
],
'models' => [
    'session' => App\Models\CustomWebRtcSession::class,
    'participant' => App\Models\CustomWebRtcParticipant::class,
],

use Raqmeyat\WebRtc\Actions\CreateSessionAction;
use Raqmeyat\WebRtc\DTOs\CreateSessionData;
use Raqmeyat\WebRtc\DTOs\ParticipantRef;
use Raqmeyat\WebRtc\Enums\SessionType;

$session = app(CreateSessionAction::class)->handle(new CreateSessionData(
    initiator: new ParticipantRef('user', (string) $authUserId),
    invitees: [new ParticipantRef('user', (string) $calleeId)],
    type: SessionType::Video,
));