ClientController.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Http;
  5. use App\HttpModels\ClientLobbyModel;
  6. use App\HttpModels\MeetingModel;
  7. use App\Models\AppSession;
  8. use Cookie;
  9. use App\Models\Lobby;
  10. class ClientController extends Controller
  11. {
  12. // GET /care_months
  13. public function entranceLobby(Request $request, Lobby $lobby) {
  14. if (!$lobby->id) {
  15. \abort(404);
  16. return;
  17. }
  18. $sessionKey = Cookie::get('sessionKey');
  19. $lobbyModel = new ClientLobbyModel($lobby);
  20. // $response = response()->view('client/index',compact('lobbyModel'),200);
  21. if(!$sessionKey){
  22. $loginUrl = env('BACKEND_URL', 'http://localhost:8080') . '/api/session/createStrangerSession';
  23. $httpResponse = Http::asForm()->post($loginUrl)->json();
  24. if(!$httpResponse['success']){
  25. return back()->with("message", $httpResponse['message']);
  26. }
  27. $sessionKey = $httpResponse['data'];
  28. // $cookie = cookie()->forever('sessionKey', $sessionKey, '/');
  29. cookie()->queue('sessionKey', $sessionKey, 1440, '/');
  30. // $response = new \Illuminate\Http\Response(view('client/index'));
  31. // $response->withCookie($cookie);
  32. // return $response;
  33. }
  34. // else {
  35. // return view('client/index');
  36. // }
  37. $session = AppSession::where("session_key",$sessionKey)->first();
  38. $meeting = null;
  39. if ($session->meetingParticipant && $session->meetingParticipant->meeting->lobby_id === $lobby->id) {
  40. $meeting = new MeetingModel($session->meetingParticipant->meeting);
  41. }
  42. return view('client/index',compact('lobbyModel','meeting','sessionKey'));
  43. }
  44. }