From 9971e6394bb3edf14c1df4a2bd659fc0f3f4efd0 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Tue, 17 Apr 2018 16:02:27 +0200 Subject: [PATCH] CDR recording events extended (id, hasAudio, hasVideo, size) --- .../java/io/openvidu/server/cdr/CDREvent.java | 33 +++++++++++++++++++ .../openvidu/server/cdr/CallDetailRecord.java | 25 +++++++------- .../server/core/SessionEventsHandler.java | 4 +-- 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREvent.java b/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREvent.java index 2613469d..c3ec97be 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREvent.java +++ b/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREvent.java @@ -4,6 +4,7 @@ import org.json.simple.JSONObject; import io.openvidu.server.core.MediaOptions; import io.openvidu.server.core.Participant; +import io.openvidu.server.recording.Recording; public class CDREvent implements Comparable { @@ -25,6 +26,12 @@ public class CDREvent implements Comparable { private MediaOptions mediaOptions; private String receivingFrom; private String reason; + + // Recording events + private Long size; + private String id; + private Boolean hasAudio; + private Boolean hasVideo; public CDREvent(String eventName, CDREvent event) { this(eventName, event.participant, event.sessionId, event.mediaOptions, event.receivingFrom, event.startTime, event.reason); @@ -46,6 +53,20 @@ public class CDREvent implements Comparable { this.timeStamp = System.currentTimeMillis(); this.startTime = this.timeStamp; } + + public CDREvent(String eventName, String sessionId, Recording recording) { + this.eventName = eventName; + if ((sessionId.indexOf('/')) != -1) { + this.sessionId = sessionId.substring(sessionId.lastIndexOf('/') + 1, sessionId.length()); + } else { + this.sessionId = sessionId; + } + this.timeStamp = System.currentTimeMillis(); + this.id = recording.getId(); + this.size = recording.getSize(); + this.hasAudio = recording.hasAudio(); + this.hasVideo = recording.hasVideo(); + } public CDREvent(String eventName, Participant participant, String sessionId) { this(eventName, sessionId); @@ -106,6 +127,18 @@ public class CDREvent implements Comparable { if (this.reason != null) { json.put("reason", this.reason); } + if (this.id != null) { + json.put("id", this.id); + } + if (this.size != null) { + json.put("size", this.size); + } + if (this.hasAudio != null) { + json.put("hasAudio", this.hasAudio); + } + if (this.hasVideo != null) { + json.put("hasVideo", this.hasVideo); + } JSONObject root = new JSONObject(); root.put(this.eventName, json); diff --git a/openvidu-server/src/main/java/io/openvidu/server/cdr/CallDetailRecord.java b/openvidu-server/src/main/java/io/openvidu/server/cdr/CallDetailRecord.java index 46abf5de..4d6576ac 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/cdr/CallDetailRecord.java +++ b/openvidu-server/src/main/java/io/openvidu/server/cdr/CallDetailRecord.java @@ -11,19 +11,20 @@ import org.slf4j.LoggerFactory; import io.openvidu.server.core.MediaOptions; import io.openvidu.server.core.Participant; +import io.openvidu.server.recording.Recording; /** * CDR logger to register all information of a Session. * Enabled by property 'openvidu.cdr=true' * * - 'sessionCreated': {sessionId, timestamp} - * - 'sessionDestroyed': {sessionId, timestamp, startTime, endTime, duration } + * - 'sessionDestroyed': {sessionId, timestamp, startTime, endTime, duration, reason} * - 'participantJoined': {sessionId, timestamp, participantId} * - 'participantLeft': {sessionId, timestamp, participantId, startTime, endTime, duration, reason} - * - 'webrtcConnectionCreated' {sessionId, timestamp, participantId, connection, [receivingFrom], audioEnabled, videoEnabled, [videoSource], [videoFramerate] } - * - 'webrtcConnectionDestroyed' {sessionId, timestamp, participantId, connection, [receivingFrom], audioEnabled, videoEnabled, [videoSource], [videoFramerate], reason } - * - 'recordingStarted' {sessionId, timestamp} - * - 'recordingStopped' {sessionId, timestamp} + * - 'webrtcConnectionCreated' {sessionId, timestamp, participantId, connection, [receivingFrom], audioEnabled, videoEnabled, [videoSource], [videoFramerate]} + * - 'webrtcConnectionDestroyed' {sessionId, timestamp, participantId, startTime, endTime, duration, connection, [receivingFrom], audioEnabled, videoEnabled, [videoSource], [videoFramerate], reason} + * - 'recordingStarted' {sessionId, timestamp, id, hasAudio, hasVideo, size} + * - 'recordingStopped' {sessionId, timestamp, id, hasAudio, hasVideo, size} * * PROPERTIES VALUES: * @@ -39,6 +40,10 @@ import io.openvidu.server.core.Participant; * - videoEnabled: boolean * - videoSource: "CAMERA", "SCREEN" * - videoFramerate: number + * - id: string + * - hasAudio: boolean + * - hasVideo: boolean + * - size: number * - webrtcConnectionDestroyed.reason: "unsubscribe", "unpublish", "disconnect", "networkDisconnect", "openviduServerDestroyed" * - participantLeft.reason: "unsubscribe", "unpublish", "disconnect", "networkDisconnect", "openviduServerDestroyed" * - sessionDestroyed.reason: "lastParticipantLeft", "openviduServerDestroyed" @@ -124,14 +129,12 @@ public class CallDetailRecord { return false; } - public void recordRecordingStarted(String sessionId) { - CDREvent recording = new CDREvent(CDREvent.RECORDING_STARTED, sessionId); - log.info("{}", recording); + public void recordRecordingStarted(String sessionId, Recording recording) { + log.info("{}", new CDREvent(CDREvent.RECORDING_STARTED, sessionId, recording)); } - public void recordRecordingStopped(String sessionId) { - CDREvent recording = new CDREvent(CDREvent.RECORDING_STOPPED, sessionId); - log.info("{}", recording); + public void recordRecordingStopped(String sessionId, Recording recording) { + log.info("{}", new CDREvent(CDREvent.RECORDING_STOPPED, sessionId, recording)); } } diff --git a/openvidu-server/src/main/java/io/openvidu/server/core/SessionEventsHandler.java b/openvidu-server/src/main/java/io/openvidu/server/core/SessionEventsHandler.java index 02bfc99a..d15cf16f 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/core/SessionEventsHandler.java +++ b/openvidu-server/src/main/java/io/openvidu/server/core/SessionEventsHandler.java @@ -326,7 +326,7 @@ public class SessionEventsHandler { public void sendRecordingStartedNotification(Session session, Recording recording) { if (openviduConfig.isCdrEnabled()) { - CDR.recordRecordingStarted(session.getSessionId()); + CDR.recordRecordingStarted(session.getSessionId(), recording); } // Filter participants by roles according to "openvidu.recording.notification" @@ -345,7 +345,7 @@ public class SessionEventsHandler { public void sendRecordingStoppedNotification(Session session, Recording recording) { if (openviduConfig.isCdrEnabled()) { - CDR.recordRecordingStopped(session.getSessionId()); + CDR.recordRecordingStopped(session.getSessionId(), recording); } // Be sure to clean this map (this should return null)