diff --git a/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREventFilterEvent.java b/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREventFilterEvent.java new file mode 100644 index 00000000..51e210a5 --- /dev/null +++ b/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREventFilterEvent.java @@ -0,0 +1,43 @@ +package io.openvidu.server.cdr; + +import org.kurento.client.GenericMediaEvent; +import org.kurento.jsonrpc.Props; + +import com.google.gson.JsonObject; + +public class CDREventFilterEvent extends CDREvent { + + private GenericMediaEvent event; + private String participantId; + private String streamId; + private String filterType; + + public CDREventFilterEvent(String sessionId, String participantId, String streamId, String filterType, + GenericMediaEvent event) { + super(CDREventName.filterEventDispatched, sessionId, Long.parseLong(event.getTimestampMillis())); + this.event = event; + this.participantId = participantId; + this.streamId = streamId; + this.filterType = filterType; + } + + public String getEventType() { + return this.event.getType(); + } + + public Props getEventData() { + return this.event.getData(); + } + + @Override + public JsonObject toJson() { + JsonObject json = super.toJson(); + json.addProperty("participantId", this.participantId); + json.addProperty("streamId", this.streamId); + json.addProperty("filterType", this.filterType); + json.addProperty("eventType", this.event.getType()); + json.addProperty("data", this.event.getData().toString()); + return json; + } + +} diff --git a/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREventName.java b/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREventName.java index 4fa8813d..17ea6ec4 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREventName.java +++ b/openvidu-server/src/main/java/io/openvidu/server/cdr/CDREventName.java @@ -19,6 +19,6 @@ package io.openvidu.server.cdr; public enum CDREventName { - sessionCreated, sessionDestroyed, participantJoined, participantLeft, webrtcConnectionCreated, webrtcConnectionDestroyed, recordingStarted, recordingStopped, recordingStatusChanged + sessionCreated, sessionDestroyed, participantJoined, participantLeft, webrtcConnectionCreated, webrtcConnectionDestroyed, recordingStarted, recordingStopped, recordingStatusChanged, filterEventDispatched } 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 f0f6ebad..c1c6f9fd 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 @@ -24,6 +24,7 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListSet; +import org.kurento.client.GenericMediaEvent; import org.springframework.beans.factory.annotation.Autowired; import io.openvidu.java.client.Recording.Status; @@ -52,6 +53,7 @@ import io.openvidu.server.webhook.CDRLoggerWebhook; * - 'recordingStarted' {sessionId, timestamp, id, name, hasAudio, hasVideo, resolution, recordingLayout, size} * - 'recordingStopped' {sessionId, timestamp, id, name, hasAudio, hasVideo, resolution, recordingLayout, size} * - 'recordingStatusChanged' {sessionId, timestamp, id, name, hasAudio, hasVideo, resolution, recordingLayout, size, status} + * - 'filterEventDispatched' {sessionId, timestamp, participantId, streamId, filterType, eventType, data} * * PROPERTIES VALUES: * @@ -219,6 +221,11 @@ public class CallDetailRecord { this.log(new CDREventRecordingStatus(recording, recording.getCreatedAt(), finalReason, timestamp, status)); } + public void recordFilterEventDispatched(String sessionId, String participantId, String streamId, String filterType, + GenericMediaEvent event) { + this.log(new CDREventFilterEvent(sessionId, participantId, streamId, filterType, event)); + } + private void log(CDREvent event) { this.loggers.forEach(logger -> { 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 59163f06..7031d264 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 @@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; +import org.kurento.client.GenericMediaEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -540,14 +541,18 @@ public class SessionEventsHandler { } } - public void onFilterEventDispatched(String connectionId, String streamId, String filterType, String eventType, - Object data, Set participants, Set subscribedParticipants) { + public void onFilterEventDispatched(String sessionId, String connectionId, String streamId, String filterType, + GenericMediaEvent event, Set participants, Set subscribedParticipants) { + + CDR.recordFilterEventDispatched(sessionId, connectionId, streamId, filterType, event); + JsonObject params = new JsonObject(); params.addProperty(ProtocolElements.FILTEREVENTLISTENER_CONNECTIONID_PARAM, connectionId); params.addProperty(ProtocolElements.FILTEREVENTLISTENER_STREAMID_PARAM, streamId); params.addProperty(ProtocolElements.FILTEREVENTLISTENER_FILTERTYPE_PARAM, filterType); - params.addProperty(ProtocolElements.FILTEREVENTLISTENER_EVENTTYPE_PARAM, eventType); - params.addProperty(ProtocolElements.FILTEREVENTLISTENER_DATA_PARAM, data.toString()); + params.addProperty(ProtocolElements.FILTEREVENTLISTENER_EVENTTYPE_PARAM, event.getType()); + params.addProperty(ProtocolElements.FILTEREVENTLISTENER_DATA_PARAM, event.getData().toString()); + for (Participant p : participants) { if (subscribedParticipants.contains(p.getParticipantPublicId())) { rpcNotificationService.sendNotification(p.getParticipantPrivateId(), diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java index 4878e674..11066bc3 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/core/KurentoSessionManager.java @@ -34,8 +34,6 @@ import org.springframework.beans.factory.annotation.Autowired; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.JsonSyntaxException; import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException.Code; @@ -882,13 +880,14 @@ public class KurentoSessionManager extends SessionManager { throws OpenViduException { PublisherEndpoint pub = kParticipant.getPublisher(); if (!pub.isListenerAddedToFilterEvent(eventType)) { + final String sessionId = kParticipant.getSessionId(); final String connectionId = kParticipant.getParticipantPublicId(); final String streamId = kParticipant.getPublisherStreamId(); final String filterType = kParticipant.getPublisherMediaOptions().getFilter().getType(); try { ListenerSubscription listener = pub.getFilter().addEventListener(eventType, event -> { - sessionEventsHandler.onFilterEventDispatched(connectionId, streamId, filterType, event.getType(), - event.getData(), kParticipant.getSession().getParticipants(), + sessionEventsHandler.onFilterEventDispatched(sessionId, connectionId, streamId, filterType, event, + kParticipant.getSession().getParticipants(), kParticipant.getPublisher().getPartipantsListentingToFilterEvent(eventType)); }); pub.storeListener(eventType, listener); diff --git a/openvidu-server/src/main/resources/application.properties b/openvidu-server/src/main/resources/application.properties index 92e1c886..434a02d0 100644 --- a/openvidu-server/src/main/resources/application.properties +++ b/openvidu-server/src/main/resources/application.properties @@ -20,7 +20,7 @@ openvidu.cdr.path=log openvidu.webhook=false openvidu.webhook.endpoint= openvidu.webhook.headers=[] -openvidu.webhook.events=["sessionCreated","sessionDestroyed","participantJoined","participantLeft","webrtcConnectionCreated","webrtcConnectionDestroyed","recordingStatusChanged"] +openvidu.webhook.events=["sessionCreated","sessionDestroyed","participantJoined","participantLeft","webrtcConnectionCreated","webrtcConnectionDestroyed","recordingStatusChanged","filterEventDispatched"] openvidu.recording=false openvidu.recording.version=2.9.0