Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resolves #89] OpenVidu로 WebRTC 구조 변경 #92

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ dependencies {

//jsoup
implementation 'org.jsoup:jsoup:1.14.2'

//OpenVidu
implementation 'io.openvidu:openvidu-java-client:2.26.0'
}

tasks.named('test') {
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
depends_on:
- mysql
- redis
- openvidu
deploy:
resources:
limits:
Expand Down Expand Up @@ -43,5 +44,14 @@ services:
limits:
memory: 200M

openvidu:
restart: always
container_name: concoder-openvidu
image: openvidu/openvidu-dev:2.27.0
ports:
- 4443:4443
environment:
OPENVIDU_SECRET: ${OPENVIDU_SECRET}

volumes:
concoder-volume:
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
package oncoding.concoder.controller;

import java.util.List;
import java.util.Map;

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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oncoding.concoder.dto.ChatDTO.UserAndRoomResponse;
import oncoding.concoder.dto.ChatDTO.ExitResponse;
import oncoding.concoder.dto.ChatDTO.UserResponse;
import oncoding.concoder.service.ChattingService;
import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.EventListener;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.messaging.handler.annotation.DestinationVariable;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpAttributesContextHolder;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RestController;
import org.springframework.web.socket.messaging.SessionConnectEvent;
import org.springframework.web.socket.messaging.SessionDisconnectEvent;

import javax.annotation.PostConstruct;

@Slf4j
@RestController
@RequiredArgsConstructor
Expand All @@ -30,6 +44,16 @@ public class VideoRoomController {
private final ChattingService chattingService;
private final SimpMessagingTemplate template;

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

private OpenVidu openvidu;

@PostConstruct
public void init() {
this.openvidu = new OpenVidu("http://localhost:4443/", OPENVIDU_SECRET);
}

@MessageMapping("/video/chat/{roomId}")
public void chat(@DestinationVariable final String roomId, JSONObject ob) {
log.debug("/rooms/chat/{}, userId: {}", roomId, ob.get("userId").toString());
Expand Down Expand Up @@ -94,6 +118,35 @@ private ExitResponse unJoinRoom(@DestinationVariable final String roomId, JSONOb
}


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

/**
* @param sessionId The Session in which to create the Connection
* @param params The Connection properties
* @return The Token associated to the Connection
*/
@PostMapping("/sessions/{sessionId}/connections")
public ResponseEntity<String> 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 new ResponseEntity<>(connection.getToken(), HttpStatus.OK);
}


// caller의 정보를 다른 callee들에게 쏴준다.
Expand Down