openvidus-server: stop recording even when not recorded participant joined

pull/173/head
pabloFuente 2018-11-20 11:55:53 +01:00
parent 422a4a7cd0
commit 12579d5c0f
4 changed files with 34 additions and 14 deletions

View File

@ -451,7 +451,7 @@ public abstract class SessionManager {
this.closeSessionAndEmptyCollections(session, reason);
if (recordingService.sessionIsBeingRecorded(session.getSessionId())) {
recordingService.stopRecording(session, reason);
recordingService.stopRecording(session, null, reason);
}
return participants;

View File

@ -180,7 +180,7 @@ public class KurentoSessionManager extends SessionManager {
.equals(remainingParticipants.iterator().next().getParticipantPublicId())) {
log.info("Last participant left. Stopping recording for session {}", sessionId);
recordingService.stopRecording(session, reason);
recordingService.stopRecording(session, null, reason);
evictParticipant(session.getParticipantByPublicId(ProtocolElements.RECORDER_PARTICIPANT_PUBLICID), null,
null, "EVICT_RECORDER");
}

View File

@ -155,10 +155,24 @@ public class ComposedRecordingService {
return recording;
}
public Recording stopRecording(Session session, String reason) {
Recording recording = this.sessionsRecordings.remove(session.getSessionId());
String containerId = this.sessionsContainers.remove(session.getSessionId());
public Recording stopRecording(Session session, String recordingId, String reason) {
Recording recording;
String containerId;
if (session == null) {
log.warn(
"Existing recording {} does not have an active session associated. This usually means the recording"
+ " layout did not join a recorded participant and therefore the session closed before"
+ " stopping the recording container",
recordingId);
recording = this.startedRecordings.remove(recordingId);
containerId = this.sessionsContainers.remove(recording.getSessionId());
this.sessionsRecordings.remove(recording.getSessionId());
} else {
recording = this.sessionsRecordings.remove(session.getSessionId());
containerId = this.sessionsContainers.remove(session.getSessionId());
this.startedRecordings.remove(recording.getId());
}
if (containerId == null) {
@ -250,8 +264,10 @@ public class ComposedRecordingService {
throw new OpenViduException(Code.RECORDING_REPORT_ERROR_CODE,
"There was an error generating the metadata report file for the recording");
}
if (session != null) {
this.sessionHandler.sendRecordingStoppedNotification(session, recording, reason);
}
}
return recording;
}
@ -465,8 +481,7 @@ public class ComposedRecordingService {
private boolean isFileFromRecording(File file, String recordingId, String recordingName) {
return (((recordingId + ".info").equals(file.getName()))
|| ((RECORDING_ENTITY_FILE + recordingId).equals(file.getName()))
|| (recordingName + ".mp4").equals(file.getName())
|| (recordingId + ".jpg").equals(file.getName()));
|| (recordingName + ".mp4").equals(file.getName()) || (recordingId + ".jpg").equals(file.getName()));
}
private String getFreeRecordingId(String sessionId, String shortSessionId) {

View File

@ -336,7 +336,9 @@ public class SessionRestController {
recordingLayout = RecordingLayout.valueOf(recordingLayoutString);
}
customLayout = (customLayout == null) ? session.getSessionProperties().defaultCustomLayout() : customLayout;
customLayout = (customLayout == null || customLayout.isEmpty())
? session.getSessionProperties().defaultCustomLayout()
: customLayout;
Recording startedRecording = this.recordingService.startRecording(session, new RecordingProperties.Builder()
.name(name).recordingLayout(recordingLayout).customLayout(customLayout).build());
@ -368,11 +370,14 @@ public class SessionRestController {
Session session = sessionManager.getSession(recording.getSessionId());
Recording stoppedRecording = this.recordingService.stopRecording(session, "recordingStoppedByServer");
Recording stoppedRecording = this.recordingService.stopRecording(session, recording.getId(),
"recordingStoppedByServer");
if (session != null) {
sessionManager.evictParticipant(
session.getParticipantByPublicId(ProtocolElements.RECORDER_PARTICIPANT_PUBLICID), null, null,
"EVICT_RECORDER");
}
return new ResponseEntity<>(stoppedRecording.toJson().toString(), getResponseHeaders(), HttpStatus.OK);
}