feat: 초기설정

This commit is contained in:
jungmin 2024-07-15 13:14:21 +09:00
parent 2d268af334
commit 80513c0146
3 changed files with 94 additions and 21 deletions

View File

@ -1,38 +1,31 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'org.springframework.boot' version '3.2.7'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.edufocus'
group = 'io.openvidu'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
description = 'Basic server application built for Java with Spring Boot'
sourceCompatibility = '17'
targetCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.openpnp:opencv:4.9.0-0'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'io.livekit:livekit-server:0.5.11'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'mysql:mysql-connector-java:8.0.33'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation group: 'io.livekit', name: 'livekit-server', version: '0.6.1'
}
tasks.named('test') {
test {
useJUnitPlatform()
}

View File

@ -0,0 +1,64 @@
package com.edufocus.edufocus.video.controller;
import io.livekit.server.AccessToken;
import io.livekit.server.RoomJoin;
import io.livekit.server.RoomName;
import io.livekit.server.WebhookReceiver;
import livekit.LivekitWebhook.WebhookEvent;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@CrossOrigin(origins = "*")
@RestController
public class Controller {
@Value("${livekit.api.key}")
private String LIVEKIT_API_KEY;
@Value("${livekit.api.secret}")
private String LIVEKIT_API_SECRET;
/**
* @param params JSON object with roomName and participantName
* @return JSON object with the JWT token
*/
@PostMapping(value = "/token")
public ResponseEntity<Map<String, String>> createToken(@RequestBody Map<String, String> params) {
String roomName = params.get("roomName");
String participantName = params.get("participantName");
if (roomName == null || participantName == null) {
return ResponseEntity.badRequest().body(Map.of("errorMessage", "roomName and participantName are required"));
}
AccessToken token = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
token.setName(participantName);
token.setIdentity(participantName);
token.addGrants(new RoomJoin(true), new RoomName(roomName));
// 방이름으로 입장하는건데
// 만약 수강생에 DB에 신청한 강의명이 없다면 들어갈수 없음
// 검증 로직만 추가하면 될듯?
return ResponseEntity.ok(Map.of("token", token.toJwt()));
}
@PostMapping(value = "/webhook", consumes = "application/webhook+json")
public ResponseEntity<String> receiveWebhook(@RequestHeader("Authorization") String authHeader, @RequestBody String body) {
WebhookReceiver webhookReceiver = new WebhookReceiver(LIVEKIT_API_KEY, LIVEKIT_API_SECRET);
try {
WebhookEvent event = webhookReceiver.receive(body, authHeader);
System.out.println("LiveKit Webhook: " + event.toString());
} catch (Exception e) {
System.err.println("Error validating webhook event: " + e.getMessage());
}
return ResponseEntity.ok("ok");
}
}

View File

@ -1 +1,17 @@
spring.application.name=edufocus
server.port=${SERVER_PORT:6080}
server.ssl.enabled=false
# LiveKit configuration
livekit.api.key=${LIVEKIT_API_KEY:devkey}
livekit.api.secret=${LIVEKIT_API_SECRET:secret}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/edufocus?serverTimezone=Asia/Seoul
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.database=mysql
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true