����JFIF��x�x����'
Server IP : 66.29.137.217 / Your IP : 3.149.230.209 Web Server : LiteSpeed System : Linux premium294.web-hosting.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : gltevjme ( 1095) PHP Version : 7.0.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/gltevjme/bofirmacademy.com/app/Http/Controllers/Frontend/ |
Upload File : |
<?php namespace App\Http\Controllers\Frontend; use App\Http\Services\Agora\RtcTokenBuilder; use App\Http\Services\Agora\RtmTokenBuilder; use App\Http\Controllers\Controller; use App\Models\BookingHistory; use App\Models\LiveClass; use Carbon\Carbon; class AgoraController extends Controller { public $appId; private $appCertificate; public function __construct() { $this->appId = get_option('agora_app_id'); $this->appCertificate = get_option('agora_app_certificate'); } public function getRTCToken(string $channelName, bool $isHost): string { $role = $isHost ? RtcTokenBuilder::RolePublisher : RtcTokenBuilder::RoleAttendee; $expireTimeInSeconds = 3600; $currentTimestamp = now()->getTimestamp(); $privilegeExpiredTs = $currentTimestamp + $expireTimeInSeconds; return RtcTokenBuilder::buildTokenWithUserAccount($this->appId, $this->appCertificate, $channelName, null, $role, $privilegeExpiredTs); } public function getRTMToken($channelName): string { $expireTimeInSeconds = 3600; $currentTimestamp = now()->getTimestamp(); $privilegeExpiredTs = $currentTimestamp + $expireTimeInSeconds; return RtmTokenBuilder::buildToken($this->appId, $this->appCertificate, $channelName, null, $privilegeExpiredTs); } public function openLiveClass($uuid, $type) { $streamRole = 'audience'; if($type == 'live_class'){ $session = LiveClass::where('uuid', $uuid)->first(); if($session->user_id == auth()->id()){ $streamRole = 'host'; } $channelName = $session->class_topic; $startTime = Carbon::parse($session->date.' '.$session->time); $hostUserId = $session->user_id; } else{ $session = BookingHistory::where('uuid', $uuid)->first(); if($session->instructor_user_id == auth()->id()){ $streamRole = 'host'; } $channelName = "Consultation with ".$session->user->name; $startTime = Carbon::parse($session->date.' '.explode('-', $session->time)[0]); $hostUserId = $session->instructor_user_id; } if(is_null($session)){ $this->showToastrMessage('success', __('This session was not found.')) ; return redirect()->back(); } $accountName = "user ".auth()->id(); $agoraController = new AgoraController(); $isHost = ($streamRole === 'host'); $rtcToken = $agoraController->getRTCToken($channelName, $isHost); $rtmToken = $agoraController->getRTMToken($accountName); $data = [ 'pageTitle' => $channelName, 'session' => $session, 'isHost' => $isHost, 'appId' => $this->appId, 'accountName' => $accountName, 'channelName' => $channelName, 'rtcToken' => $rtcToken, 'rtmToken' => $rtmToken, 'streamRole' => $streamRole, 'notStarted' => !$isHost, 'streamStartAt' => $startTime, 'authUserId' => auth()->id(), 'hostUserId' => $hostUserId, 'sessionStreamType' => ($type == 'live_class') ? 'multiple' : 'single' ]; return view('frontend.student.agora.index', $data); } }