Skip to content

Commit 798a7b7

Browse files
committed
Replace usages of SessionManager with usages of Utils, SessionStorage and SessionManagerProvider
1 parent 32329e1 commit 798a7b7

4 files changed

Lines changed: 75 additions & 61 deletions

File tree

openvidu-server/src/main/java/io/openvidu/server/core/SessionManager.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,7 @@ public boolean isPublisherInSession(String sessionId, Participant participant) {
189189
}
190190

191191
public boolean isModeratorInSession(String sessionId, Participant participant) {
192-
if (!this.isInsecureParticipant(participant.getParticipantPrivateId())) {
193-
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
194-
return ParticipantRole.MODERATOR.equals(participant.getToken().getRole());
195-
} else {
196-
return false;
197-
}
198-
} else {
199-
return true;
200-
}
192+
return this.sessionStorage.isModeratorInSession(sessionId, participant);
201193
}
202194

203195
public boolean isInsecureParticipant(String participantPrivateId) {

openvidu-server/src/main/java/io/openvidu/server/core/SessionStorage.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,16 @@ public void showInsecureParticipants() {
308308
public void showAllParticipants() {
309309
log.info("<SESSIONID, PARTICIPANTS>: {}", this.sessionidParticipantpublicidParticipant.toString());
310310
}
311+
312+
public boolean isModeratorInSession(String sessionId, Participant participant) {
313+
if (!this.isInsecureParticipant(participant.getParticipantPrivateId())) {
314+
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
315+
return ParticipantRole.MODERATOR.equals(participant.getToken().getRole());
316+
} else {
317+
return false;
318+
}
319+
} else {
320+
return true;
321+
}
322+
}
311323
}

openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@
5757
public class SessionRestController {
5858

5959
@Autowired
60-
private SessionManager sessionManager;
60+
private SessionManagerProvider sessionManagerProvider;
6161

6262
@Autowired
6363
private SessionStorage sessionStorage;
6464

65+
@Autowired
66+
private Utils utils;
67+
6568
@Autowired
6669
private ComposedRecordingService recordingService;
6770

@@ -125,11 +128,11 @@ public ResponseEntity<JSONObject> getSessionId(@RequestBody(required = false) Ma
125128
}
126129
sessionId = customSessionId;
127130
} else {
128-
sessionId = sessionManager.generateRandomChain();
131+
sessionId = utils.generateRandomChain();
129132
this.sessionStorage.putTokenObject(sessionId, new ConcurrentHashMap<>());
130133
}
131134

132-
sessionManager.storeSessionId(sessionId, sessionProperties);
135+
sessionStorage.storeSessionId(sessionId, sessionProperties);
133136
JSONObject responseJson = new JSONObject();
134137
responseJson.put("id", sessionId);
135138

@@ -140,7 +143,7 @@ public ResponseEntity<JSONObject> getSessionId(@RequestBody(required = false) Ma
140143
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)
141144
public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String sessionId,
142145
@RequestParam(value = "webRtcStats", defaultValue = "false", required = false) boolean webRtcStats) {
143-
Session session = this.sessionManager.getSession(sessionId);
146+
Session session = this.sessionStorage.getSession(sessionId);
144147
if (session != null) {
145148
JSONObject response = (webRtcStats == true) ? session.withStatsToJSON() : session.toJSON();
146149
response.put("recording", this.recordingService.sessionIsBeingRecorded(sessionId));
@@ -154,7 +157,7 @@ public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String s
154157
@RequestMapping(value = "/sessions", method = RequestMethod.GET)
155158
public ResponseEntity<JSONObject> listSessions(
156159
@RequestParam(value = "webRtcStats", defaultValue = "false", required = false) boolean webRtcStats) {
157-
Collection<Session> sessions = this.sessionManager.getSessionObjects();
160+
Collection<Session> sessions = this.sessionStorage.getSessionObjects();
158161
JSONObject json = new JSONObject();
159162
JSONArray jsonArray = new JSONArray();
160163
sessions.forEach(s -> {
@@ -169,9 +172,9 @@ public ResponseEntity<JSONObject> listSessions(
169172

170173
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.DELETE)
171174
public ResponseEntity<JSONObject> closeSession(@PathVariable("sessionId") String sessionId) {
172-
Session session = this.sessionManager.getSession(sessionId);
175+
Session session = this.sessionStorage.getSession(sessionId);
173176
if (session != null) {
174-
this.sessionManager.closeSession(sessionId, "sessionClosedByServer");
177+
this.sessionManagerProvider.get(sessionId).closeSession(sessionId, "sessionClosedByServer");
175178
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
176179
} else {
177180
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
@@ -181,11 +184,11 @@ public ResponseEntity<JSONObject> closeSession(@PathVariable("sessionId") String
181184
@RequestMapping(value = "/sessions/{sessionId}/connection/{connectionId}", method = RequestMethod.DELETE)
182185
public ResponseEntity<JSONObject> disconnectParticipant(@PathVariable("sessionId") String sessionId,
183186
@PathVariable("connectionId") String participantPublicId) {
184-
Session session = this.sessionManager.getSession(sessionId);
187+
Session session = this.sessionStorage.getSession(sessionId);
185188
if (session != null) {
186189
Participant participant = session.getParticipantByPublicId(participantPublicId);
187190
if (participant != null) {
188-
this.sessionManager.evictParticipant(participant, null, null, "forceDisconnectByServer");
191+
this.sessionManagerProvider.get(sessionId).evictParticipant(participant, null, null, "forceDisconnectByServer");
189192
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
190193
} else {
191194
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
@@ -198,9 +201,9 @@ public ResponseEntity<JSONObject> disconnectParticipant(@PathVariable("sessionId
198201
@RequestMapping(value = "/sessions/{sessionId}/stream/{streamId}", method = RequestMethod.DELETE)
199202
public ResponseEntity<JSONObject> unpublishStream(@PathVariable("sessionId") String sessionId,
200203
@PathVariable("streamId") String streamId) {
201-
Session session = this.sessionManager.getSession(sessionId);
204+
Session session = this.sessionStorage.getSession(sessionId);
202205
if (session != null) {
203-
if (this.sessionManager.unpublishStream(session, streamId, null, null, "forceUnpublishByServer")) {
206+
if (this.sessionManagerProvider.get(sessionId).unpublishStream(session, streamId, null, null, "forceUnpublishByServer")) {
204207
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
205208
} else {
206209
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
@@ -236,7 +239,7 @@ public ResponseEntity<JSONObject> newToken(@RequestBody Map<?, ?> params) {
236239

237240
metadata = (metadata != null) ? metadata : "";
238241

239-
String token = sessionManager.newToken(sessionId, role, metadata);
242+
String token = sessionStorage.newToken(sessionId, role, metadata);
240243
JSONObject responseJson = new JSONObject();
241244
responseJson.put("id", token);
242245
responseJson.put("session", sessionId);
@@ -271,7 +274,7 @@ public ResponseEntity<JSONObject> startRecordingSession(@RequestBody Map<?, ?> p
271274
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
272275
}
273276

274-
Session session = sessionManager.getSession(sessionId);
277+
Session session = sessionStorage.getSession(sessionId);
275278

276279
if (session == null) {
277280
// Session does not exist
@@ -327,11 +330,11 @@ public ResponseEntity<JSONObject> stopRecordingSession(@PathVariable("recordingI
327330
return new ResponseEntity<>(HttpStatus.CONFLICT);
328331
}
329332

330-
Session session = sessionManager.getSession(recording.getSessionId());
333+
Session session = sessionStorage.getSession(recording.getSessionId());
331334

332335
Recording stoppedRecording = this.recordingService.stopRecording(session);
333336

334-
sessionManager.evictParticipant(
337+
sessionManagerProvider.get(session.getSessionId()).evictParticipant(
335338
session.getParticipantByPublicId(ProtocolElements.RECORDER_PARTICIPANT_PUBLICID), null, null,
336339
"EVICT_RECORDER");
337340

0 commit comments

Comments
 (0)