-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from mju-KyungDongWonJeong/feature/room
컴포즈 파일 수정, 세션&커넥션 생성
- Loading branch information
Showing
4 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/com/togedong/room/controller/RoomController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters