ProController.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Meeting;
  4. use App\Models\MeetingParticipant;
  5. use Illuminate\Http\Request;
  6. use App\Models\Pro;
  7. use Illuminate\Support\Facades\DB;
  8. class ProController extends Controller
  9. {
  10. public function dashboard(Request $request){
  11. return view('pro.dashboard', ['sessionKey' => $request->cookie('sessionKey')]);
  12. }
  13. public function index(){
  14. $pros = Pro::all();
  15. return view('pro.index', compact('pros'));
  16. }
  17. public function create(){
  18. return view('pro.create');
  19. }
  20. public function show($uid, Request $request){
  21. $pro = Pro::where('uid', $uid)->first();
  22. return view('pro.show', compact('pro'));
  23. }
  24. public function meeting(Request $request, $meetingID) {
  25. $meeting = Meeting::where('uid', $meetingID)->first();
  26. if(!$meeting) {
  27. return abort(404, "Meeting no longer active");
  28. }
  29. $participants = MeetingParticipant::where('meeting_id', $meeting->id)->get();
  30. foreach ($participants as $participant) {
  31. $participant->proName = $participant->proName(); // eager-fill proName
  32. }
  33. return view('meeting', [
  34. 'meetingID' => $meetingID,
  35. 'participants' => $participants,
  36. 'guest' => false
  37. ]);
  38. }
  39. public function meet(Request $request, $uid = false) {
  40. $session = DB::table('app_session')->where('session_key', $request->cookie('sessionKey'))->first();
  41. $pro = false;
  42. if($session && $session->pro_id) {
  43. $pro = DB::table('pro')->where('id', $session->pro_id)->first();
  44. }
  45. $client = null;
  46. if(!empty($uid)) {
  47. $client = DB::table('client')->where('uid', $uid)->first();
  48. }
  49. else if($pro->in_meeting_with_client_id) {
  50. $client = DB::table('client')->where('id', $pro->in_meeting_with_client_id)->first();
  51. }
  52. return view('pro-call', [
  53. 'guest' => false,
  54. 'session' => $session,
  55. 'pro' => $pro,
  56. 'client' => $client
  57. ]);
  58. }
  59. public function getOpentokSessionKey(Request $request, $uid) {
  60. $client = DB::table('client')->where('uid', $uid)->first();
  61. return json_encode([
  62. "data" => $client->opentok_session_id
  63. ]);
  64. }
  65. }