Skip to content

Commit

Permalink
Replace usages of SessionManager with usages of Utils, SessionStorage…
Browse files Browse the repository at this point in the history
… and SessionManagerProvider
  • Loading branch information
thojou committed Jul 9, 2018
1 parent 32329e1 commit 798a7b7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,7 @@ public boolean isPublisherInSession(String sessionId, Participant participant) {
}

public boolean isModeratorInSession(String sessionId, Participant participant) {
if (!this.isInsecureParticipant(participant.getParticipantPrivateId())) {
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
return ParticipantRole.MODERATOR.equals(participant.getToken().getRole());
} else {
return false;
}
} else {
return true;
}
return this.sessionStorage.isModeratorInSession(sessionId, participant);
}

public boolean isInsecureParticipant(String participantPrivateId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,16 @@ public void showInsecureParticipants() {
public void showAllParticipants() {
log.info("<SESSIONID, PARTICIPANTS>: {}", this.sessionidParticipantpublicidParticipant.toString());
}

public boolean isModeratorInSession(String sessionId, Participant participant) {
if (!this.isInsecureParticipant(participant.getParticipantPrivateId())) {
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
return ParticipantRole.MODERATOR.equals(participant.getToken().getRole());
} else {
return false;
}
} else {
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@
public class SessionRestController {

@Autowired
private SessionManager sessionManager;
private SessionManagerProvider sessionManagerProvider;

@Autowired
private SessionStorage sessionStorage;

@Autowired
private Utils utils;

@Autowired
private ComposedRecordingService recordingService;

Expand Down Expand Up @@ -125,11 +128,11 @@ public ResponseEntity<JSONObject> getSessionId(@RequestBody(required = false) Ma
}
sessionId = customSessionId;
} else {
sessionId = sessionManager.generateRandomChain();
sessionId = utils.generateRandomChain();
this.sessionStorage.putTokenObject(sessionId, new ConcurrentHashMap<>());
}

sessionManager.storeSessionId(sessionId, sessionProperties);
sessionStorage.storeSessionId(sessionId, sessionProperties);
JSONObject responseJson = new JSONObject();
responseJson.put("id", sessionId);

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

@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.DELETE)
public ResponseEntity<JSONObject> closeSession(@PathVariable("sessionId") String sessionId) {
Session session = this.sessionManager.getSession(sessionId);
Session session = this.sessionStorage.getSession(sessionId);
if (session != null) {
this.sessionManager.closeSession(sessionId, "sessionClosedByServer");
this.sessionManagerProvider.get(sessionId).closeSession(sessionId, "sessionClosedByServer");
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand All @@ -181,11 +184,11 @@ public ResponseEntity<JSONObject> closeSession(@PathVariable("sessionId") String
@RequestMapping(value = "/sessions/{sessionId}/connection/{connectionId}", method = RequestMethod.DELETE)
public ResponseEntity<JSONObject> disconnectParticipant(@PathVariable("sessionId") String sessionId,
@PathVariable("connectionId") String participantPublicId) {
Session session = this.sessionManager.getSession(sessionId);
Session session = this.sessionStorage.getSession(sessionId);
if (session != null) {
Participant participant = session.getParticipantByPublicId(participantPublicId);
if (participant != null) {
this.sessionManager.evictParticipant(participant, null, null, "forceDisconnectByServer");
this.sessionManagerProvider.get(sessionId).evictParticipant(participant, null, null, "forceDisconnectByServer");
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand All @@ -198,9 +201,9 @@ public ResponseEntity<JSONObject> disconnectParticipant(@PathVariable("sessionId
@RequestMapping(value = "/sessions/{sessionId}/stream/{streamId}", method = RequestMethod.DELETE)
public ResponseEntity<JSONObject> unpublishStream(@PathVariable("sessionId") String sessionId,
@PathVariable("streamId") String streamId) {
Session session = this.sessionManager.getSession(sessionId);
Session session = this.sessionStorage.getSession(sessionId);
if (session != null) {
if (this.sessionManager.unpublishStream(session, streamId, null, null, "forceUnpublishByServer")) {
if (this.sessionManagerProvider.get(sessionId).unpublishStream(session, streamId, null, null, "forceUnpublishByServer")) {
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
Expand Down Expand Up @@ -236,7 +239,7 @@ public ResponseEntity<JSONObject> newToken(@RequestBody Map<?, ?> params) {

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

String token = sessionManager.newToken(sessionId, role, metadata);
String token = sessionStorage.newToken(sessionId, role, metadata);
JSONObject responseJson = new JSONObject();
responseJson.put("id", token);
responseJson.put("session", sessionId);
Expand Down Expand Up @@ -271,7 +274,7 @@ public ResponseEntity<JSONObject> startRecordingSession(@RequestBody Map<?, ?> p
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}

Session session = sessionManager.getSession(sessionId);
Session session = sessionStorage.getSession(sessionId);

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

Session session = sessionManager.getSession(recording.getSessionId());
Session session = sessionStorage.getSession(recording.getSessionId());

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

sessionManager.evictParticipant(
sessionManagerProvider.get(session.getSessionId()).evictParticipant(
session.getParticipantByPublicId(ProtocolElements.RECORDER_PARTICIPANT_PUBLICID), null, null,
"EVICT_RECORDER");

Expand Down
Loading

0 comments on commit 798a7b7

Please sign in to comment.