1
1
package oncoding .concoder .controller ;
2
2
3
3
import java .util .List ;
4
+ import java .util .Map ;
5
+
6
+ import io .openvidu .java .client .Connection ;
7
+ import io .openvidu .java .client .ConnectionProperties ;
8
+ import io .openvidu .java .client .OpenVidu ;
9
+ import io .openvidu .java .client .OpenViduHttpException ;
10
+ import io .openvidu .java .client .OpenViduJavaClientException ;
11
+ import io .openvidu .java .client .Session ;
12
+ import io .openvidu .java .client .SessionProperties ;
4
13
import lombok .RequiredArgsConstructor ;
5
14
import lombok .extern .slf4j .Slf4j ;
6
15
import oncoding .concoder .dto .ChatDTO .UserAndRoomResponse ;
7
16
import oncoding .concoder .dto .ChatDTO .ExitResponse ;
8
17
import oncoding .concoder .dto .ChatDTO .UserResponse ;
9
18
import oncoding .concoder .service .ChattingService ;
10
19
import org .json .simple .JSONObject ;
20
+ import org .springframework .beans .factory .annotation .Value ;
11
21
import org .springframework .context .event .EventListener ;
22
+ import org .springframework .http .HttpStatus ;
12
23
import org .springframework .http .ResponseEntity ;
13
24
import org .springframework .messaging .handler .annotation .DestinationVariable ;
14
25
import org .springframework .messaging .handler .annotation .MessageMapping ;
15
26
import org .springframework .messaging .simp .SimpAttributesContextHolder ;
16
27
import org .springframework .messaging .simp .SimpMessagingTemplate ;
17
28
import org .springframework .messaging .simp .stomp .StompHeaderAccessor ;
18
29
import org .springframework .web .bind .annotation .DeleteMapping ;
30
+ import org .springframework .web .bind .annotation .PathVariable ;
19
31
import org .springframework .web .bind .annotation .PostMapping ;
20
32
import org .springframework .web .bind .annotation .RequestBody ;
21
33
import org .springframework .web .bind .annotation .RestController ;
22
34
import org .springframework .web .socket .messaging .SessionConnectEvent ;
23
35
import org .springframework .web .socket .messaging .SessionDisconnectEvent ;
24
36
37
+ import javax .annotation .PostConstruct ;
38
+
25
39
@ Slf4j
26
40
@ RestController
27
41
@ RequiredArgsConstructor
@@ -30,6 +44,16 @@ public class VideoRoomController {
30
44
private final ChattingService chattingService ;
31
45
private final SimpMessagingTemplate template ;
32
46
47
+ @ Value ("${OPENVIDU_SECRET}" )
48
+ private String OPENVIDU_SECRET ;
49
+
50
+ private OpenVidu openvidu ;
51
+
52
+ @ PostConstruct
53
+ public void init () {
54
+ this .openvidu = new OpenVidu ("http://localhost:4443/" , OPENVIDU_SECRET );
55
+ }
56
+
33
57
@ MessageMapping ("/video/chat/{roomId}" )
34
58
public void chat (@ DestinationVariable final String roomId , JSONObject ob ) {
35
59
log .debug ("/rooms/chat/{}, userId: {}" , roomId , ob .get ("userId" ).toString ());
@@ -94,6 +118,35 @@ private ExitResponse unJoinRoom(@DestinationVariable final String roomId, JSONOb
94
118
}
95
119
96
120
121
+ /**
122
+ * @param params The Session properties
123
+ * @return The Session ID
124
+ */
125
+ @ PostMapping ("/sessions" )
126
+ public ResponseEntity <String > initializeSession (@ RequestBody (required = false ) Map <String , Object > params )
127
+ throws OpenViduJavaClientException , OpenViduHttpException {
128
+ SessionProperties properties = SessionProperties .fromJson (params ).build ();
129
+ Session session = openvidu .createSession (properties );
130
+ return new ResponseEntity <>(session .getSessionId (), HttpStatus .OK );
131
+ }
132
+
133
+ /**
134
+ * @param sessionId The Session in which to create the Connection
135
+ * @param params The Connection properties
136
+ * @return The Token associated to the Connection
137
+ */
138
+ @ PostMapping ("/sessions/{sessionId}/connections" )
139
+ public ResponseEntity <String > createConnection (@ PathVariable ("sessionId" ) String sessionId ,
140
+ @ RequestBody (required = false ) Map <String , Object > params )
141
+ throws OpenViduJavaClientException , OpenViduHttpException {
142
+ Session session = openvidu .getActiveSession (sessionId );
143
+ if (session == null ) {
144
+ return new ResponseEntity <>(HttpStatus .NOT_FOUND );
145
+ }
146
+ ConnectionProperties properties = ConnectionProperties .fromJson (params ).build ();
147
+ Connection connection = session .createConnection (properties );
148
+ return new ResponseEntity <>(connection .getToken (), HttpStatus .OK );
149
+ }
97
150
98
151
99
152
// caller의 정보를 다른 callee들에게 쏴준다.
0 commit comments