ClientController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 entrance(Request $request, Lobby $lobby) {
  14. $sessionKey = Cookie::get('sessionKey');
  15. $lobbyModel = new ClientLobbyModel($lobby);
  16. // $response = response()->view('client/index',compact('lobbyModel'),200);
  17. if(!$sessionKey){
  18. $loginUrl = env('BACKEND_URL', 'http://localhost:8080') . '/api/session/createStrangerSession';
  19. $httpResponse = Http::asForm()->post($loginUrl)->json();
  20. if(!$httpResponse['success']){
  21. return back()->with("message", $httpResponse['message']);
  22. }
  23. $sessionKey = $httpResponse['data'];
  24. // $cookie = cookie()->forever('sessionKey', $sessionKey, '/');
  25. cookie()->queue('sessionKey', $sessionKey, 1440, '/');
  26. // $response = new \Illuminate\Http\Response(view('client/index'));
  27. // $response->withCookie($cookie);
  28. // return $response;
  29. }
  30. // else {
  31. // return view('client/index');
  32. // }
  33. $session = AppSession::where("session_key",$sessionKey)->first();
  34. $meeting = null;
  35. if ($session->meetingParticipant && $session->meetingParticipant->meeting->lobby_id === $lobby->id) {
  36. $meeting = new MeetingModel($session->meetingParticipant->meeting);
  37. }
  38. return view('client/index',compact('lobbyModel','meeting'));
  39. }
  40. }