openvidu-server: webhook and CDR filterEventDispatched event

pull/375/head
pabloFuente 2019-09-16 16:50:40 +02:00
parent 9336773cbc
commit c8feebaf57
6 changed files with 64 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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
}

View File

@ -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 -> {

View File

@ -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<Participant> participants, Set<String> subscribedParticipants) {
public void onFilterEventDispatched(String sessionId, String connectionId, String streamId, String filterType,
GenericMediaEvent event, Set<Participant> participants, Set<String> 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(),

View File

@ -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);

View File

@ -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