Skip to content

Commit

Permalink
Merge pull request #4 from mju-KyungDongWonJeong/feature/room
Browse files Browse the repository at this point in the history
컴포즈 파일 수정, 세션&커넥션 생성
  • Loading branch information
ChoiWonYu authored Nov 22, 2023
2 parents 8ea9025 + 5f4bb2f commit 33ef175
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ jobs:
- name: compose up spring application
run: |
sudo docker compose --env-file ~/.env -f ~/docker-compose.yml up -d --build
sudo su
sudo docker compose --env-file /opt/openvidu/.env -f /opt/openvidu/docker-compose.yml up -d --build
sudo docker system prune -f
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ repositories {
}

dependencies {
implementation 'io.openvidu:openvidu-java-client:2.29.0'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/com/togedong/room/controller/RoomController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.togedong.room.controller;

import com.togedong.global.response.ResponseHandler;
import io.openvidu.java.client.Connection;
import io.openvidu.java.client.ConnectionProperties;
import io.openvidu.java.client.OpenVidu;
import io.openvidu.java.client.OpenViduHttpException;
import io.openvidu.java.client.OpenViduJavaClientException;
import io.openvidu.java.client.Session;
import io.openvidu.java.client.SessionProperties;
import jakarta.annotation.PostConstruct;
import java.util.Map;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/room")
public class RoomController {

@Value("${OPENVIDU_URL}")
private String OPENVIDU_URL;

@Value("${OPENVIDU_SECRET}")
private String OPENVIDU_SECRET;

private OpenVidu openvidu;


@PostConstruct
public void init() {
this.openvidu = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
}

@PostMapping("/sessions")
public ResponseEntity<Object> initializeSession(
@RequestBody(required = false) Map<String, Object> params)
throws OpenViduJavaClientException, OpenViduHttpException {
SessionProperties properties = SessionProperties.fromJson(params).build();
Session session = openvidu.createSession(properties);
return ResponseHandler.generateResponseWithoutMessage(HttpStatus.OK,
session.getSessionId());
}

@PostMapping("/sessions/{sessionId}/connections")
public ResponseEntity<Object> createConnection(@PathVariable("sessionId") String sessionId,
@RequestBody(required = false) Map<String, Object> params)
throws OpenViduJavaClientException, OpenViduHttpException {
Session session = openvidu.getActiveSession(sessionId);
if (session == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
ConnectionProperties properties = ConnectionProperties.fromJson(params).build();
Connection connection = session.createConnection(properties);
return ResponseHandler.generateResponseWithoutMessage(HttpStatus.OK, connection.getToken());
}
}
8 changes: 6 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ spring:
ddl-auto: create
properties:
format_sql: true
defer-datasource-initialization : true
sql.init.mode : always
defer-datasource-initialization: true
sql.init.mode: always

server:
servlet:
Expand All @@ -21,3 +21,7 @@ server:
jwt:
secret: eyJhbGciOiJIUzI1NiJ9eyJSb2xlIjoiQWRtaW4iLCJJc3N1ZXIiOiJJc3N1ZXIiLCJVc2VybmFtZSI6IkphdmFJblVzZSIsImV4cCI6MTY5ODUxMjMwMSwiaWF0IjoxNjk4NTEyMzAxfQkMdVrwZRf8VyrDh0RH56LUQWZWM7eRKrzWm6MBqzvrk
expired: 604800000

OPENVIDU_URL: { DOMAIN_OR_PUBLIC_IP0 }
OPENVIDU_SECRET: { OPENVIDU_SECRET }

0 comments on commit 33ef175

Please sign in to comment.