commit
a98e2c73eb
@ -28,4 +28,5 @@ public interface LectureService {
|
|||||||
Lecture findLectureByTitle(String title);
|
Lecture findLectureByTitle(String title);
|
||||||
|
|
||||||
void changeState(Long lectureId);
|
void changeState(Long lectureId);
|
||||||
|
boolean getState(Long lectureId);
|
||||||
}
|
}
|
||||||
|
@ -239,5 +239,13 @@ public class LectureServiceImpl implements LectureService {
|
|||||||
lectureRepository.save(l);
|
lectureRepository.save(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getState(Long lectureId) {
|
||||||
|
|
||||||
|
Lecture lecture= lectureRepository.findById(lectureId).orElse(null);
|
||||||
|
return lecture.isOnline();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,6 @@ public class GlobalExceptionHandler {
|
|||||||
|
|
||||||
@ExceptionHandler(ExpriedTokenException.class)
|
@ExceptionHandler(ExpriedTokenException.class)
|
||||||
public ResponseEntity<String> handleInvalidTokenException(ExpriedTokenException e) {
|
public ResponseEntity<String> handleInvalidTokenException(ExpriedTokenException e) {
|
||||||
// 로그 남기기 (선택 사항)
|
|
||||||
// log.error("Invalid token", e);
|
|
||||||
|
|
||||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.UNAUTHORIZED);
|
return new ResponseEntity<>(e.getMessage(), HttpStatus.UNAUTHORIZED);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import com.edufocus.edufocus.lecture.entity.Lecture;
|
import com.edufocus.edufocus.lecture.entity.Lecture;
|
||||||
import com.edufocus.edufocus.lecture.entity.LectureDetailResponse;
|
import com.edufocus.edufocus.lecture.entity.LectureDetailResponse;
|
||||||
|
import com.edufocus.edufocus.lecture.repository.LectureRepository;
|
||||||
import com.edufocus.edufocus.lecture.service.LectureService;
|
import com.edufocus.edufocus.lecture.service.LectureService;
|
||||||
import com.edufocus.edufocus.registration.entity.RegistrationStatus;
|
import com.edufocus.edufocus.registration.entity.RegistrationStatus;
|
||||||
import com.edufocus.edufocus.registration.service.RegistrationService;
|
import com.edufocus.edufocus.registration.service.RegistrationService;
|
||||||
@ -37,6 +38,7 @@ public class Controller {
|
|||||||
private final VideoSertvice videoSertvice;
|
private final VideoSertvice videoSertvice;
|
||||||
private final RegistrationService registrationService;
|
private final RegistrationService registrationService;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
private final LectureRepository lectureRepository;
|
||||||
@Value("${livekit.api.key}")
|
@Value("${livekit.api.key}")
|
||||||
private String LIVEKIT_API_KEY;
|
private String LIVEKIT_API_KEY;
|
||||||
|
|
||||||
@ -67,18 +69,37 @@ public class Controller {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
@PostMapping(value = "/makeroom/{lecture_id}")
|
@PostMapping(value = "/makeroom/{lecture_id}")
|
||||||
public ResponseEntity<Map<String, String>> startLecture(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception {
|
public ResponseEntity<String> startLecture(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception {
|
||||||
|
|
||||||
|
|
||||||
|
String userToken = request.getHeader("Authorization");
|
||||||
|
Long userId = Long.parseLong(jwtUtil.getUserId(userToken));
|
||||||
|
|
||||||
|
|
||||||
|
videoSertvice.startOnline(userId, id);
|
||||||
|
|
||||||
|
return new ResponseEntity<>("방만들기 성공",HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(value = "/joinroom/{lecture_id}")
|
||||||
|
public ResponseEntity<Map<String, String>> joinRoom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
String userToken = request.getHeader("Authorization");
|
String userToken = request.getHeader("Authorization");
|
||||||
log.info("userToekn : ", userToken);
|
|
||||||
|
|
||||||
|
|
||||||
Long userId = Long.parseLong(jwtUtil.getUserId(userToken));
|
Long userId = Long.parseLong(jwtUtil.getUserId(userToken));
|
||||||
User findUser= userRepository.findById(userId).orElse(null);
|
User findUser= userRepository.findById(userId).orElse(null);
|
||||||
|
Lecture lecture= lectureRepository.findById(id).orElse(null);
|
||||||
|
|
||||||
|
|
||||||
if(findUser.getRole()==UserRole.ADMIN) {
|
|
||||||
LectureDetailResponse lecture = lectureService.findLectureById(userId, id);
|
|
||||||
|
|
||||||
|
if(findUser.getRole()==UserRole.ADMIN && lecture.isOnline() ) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String roomName = lecture.getTitle();
|
String roomName = lecture.getTitle();
|
||||||
@ -96,9 +117,8 @@ public class Controller {
|
|||||||
return ResponseEntity.ok(Map.of("token", token.toJwt()));
|
return ResponseEntity.ok(Map.of("token", token.toJwt()));
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(findUser.getRole()==UserRole.STUDENT)
|
else if(findUser.getRole()==UserRole.STUDENT && lecture.isOnline() )
|
||||||
{
|
{
|
||||||
LectureDetailResponse lecture = lectureService.findLectureById(userId, id);
|
|
||||||
|
|
||||||
|
|
||||||
String roomName = lecture.getTitle();
|
String roomName = lecture.getTitle();
|
||||||
@ -108,7 +128,8 @@ public class Controller {
|
|||||||
AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
||||||
token.setName(participantName);
|
token.setName(participantName);
|
||||||
token.setIdentity(participantName);
|
token.setIdentity(participantName);
|
||||||
token.addGrants(new RoomJoin(true), new RoomName(roomName), new RoomCreate(true));
|
token.addGrants(new RoomJoin(true), new RoomName(roomName));
|
||||||
|
|
||||||
|
|
||||||
videoSertvice.startOnline(userId, id);
|
videoSertvice.startOnline(userId, id);
|
||||||
|
|
||||||
@ -119,48 +140,40 @@ public class Controller {
|
|||||||
|
|
||||||
return ResponseEntity.ok(Map.of("token", null));
|
return ResponseEntity.ok(Map.of("token", null));
|
||||||
|
|
||||||
|
// String userToken = request.getHeader("Authorization");
|
||||||
|
//
|
||||||
|
// Long userId = Long.parseLong(jwtUtil.getUserId(userToken));
|
||||||
|
// LectureDetailResponse lecture= lectureService.findLectureById(userId,id);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// //RegistrationStatus registrationStatus = registrationService.isOnline(userId,id);
|
||||||
|
//
|
||||||
|
// if(registrationStatus==RegistrationStatus.ACCEPTED)
|
||||||
|
// {
|
||||||
|
// String roomName = lecture.getTitle();
|
||||||
|
// String participantName = userService.getUserName(userId);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
||||||
|
// token.setName(participantName);
|
||||||
|
// token.setIdentity(participantName);
|
||||||
|
// token.addGrants(new RoomJoin(true), new RoomName(roomName));
|
||||||
|
//
|
||||||
|
// //videoSertvice.startOnline(userId,id);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// return ResponseEntity.ok(Map.of("token", token.toJwt()));
|
||||||
|
// }
|
||||||
|
// else{
|
||||||
|
// return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Map.of("errorMessage", "Not accepted"));
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @PostMapping(value = "/joinroom/{lecture_id}")
|
|
||||||
// public ResponseEntity<Map<String, String>> joinRoom(@PathVariable("lecture_id") Long id, HttpServletRequest request) throws Exception {
|
|
||||||
//
|
|
||||||
//// String userToken = request.getHeader("Authorization");
|
|
||||||
////
|
|
||||||
//// Long userId = Long.parseLong(jwtUtil.getUserId(userToken));
|
|
||||||
//// LectureDetailResponse lecture= lectureService.findLectureById(userId,id);
|
|
||||||
////
|
|
||||||
////
|
|
||||||
//// //RegistrationStatus registrationStatus = registrationService.isOnline(userId,id);
|
|
||||||
////
|
|
||||||
////// if(registrationStatus==RegistrationStatus.ACCEPTED)
|
|
||||||
////// {
|
|
||||||
//// String roomName = lecture.getTitle();
|
|
||||||
//// String participantName = userService.getUserName(userId);
|
|
||||||
////
|
|
||||||
////
|
|
||||||
//// AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
|
||||||
//// token.setName(participantName);
|
|
||||||
//// token.setIdentity(participantName);
|
|
||||||
//// token.addGrants(new RoomJoin(true), new RoomName(roomName));
|
|
||||||
////
|
|
||||||
//// //videoSertvice.startOnline(userId,id);
|
|
||||||
////
|
|
||||||
////
|
|
||||||
////
|
|
||||||
//// return ResponseEntity.ok(Map.of("token", token.toJwt()));
|
|
||||||
////// }
|
|
||||||
////// else{
|
|
||||||
////// return ResponseEntity.status(HttpStatus.FORBIDDEN).body(Map.of("errorMessage", "Not accepted"));
|
|
||||||
//////
|
|
||||||
////// }
|
|
||||||
////
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
@PostMapping(value = "/livekit/webhook", consumes = "application/webhook+json")
|
@PostMapping(value = "/livekit/webhook", consumes = "application/webhook+json")
|
||||||
public ResponseEntity<String> receiveWebhook(@RequestHeader("Authorization") String authHeader, @RequestBody String body) {
|
public ResponseEntity<String> receiveWebhook(@RequestHeader("Authorization") String authHeader, @RequestBody String body) {
|
||||||
WebhookReceiver webhookReceiver = new WebhookReceiver(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
WebhookReceiver webhookReceiver = new WebhookReceiver(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
|
||||||
|
Loading…
Reference in New Issue
Block a user