From a2a7828c9da2bfa2b4e9b354484a7746a0b22416 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Fri, 1 Mar 2019 16:57:49 +0100 Subject: [PATCH] openvidu-server: common KmsEvent toJson --- .../server/kurento/endpoint/KmsEvent.java | 19 ++++--------------- .../kurento/endpoint/MediaEndpoint.java | 16 +++++++--------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/KmsEvent.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/KmsEvent.java index ac1707cb..6ef24b78 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/KmsEvent.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/KmsEvent.java @@ -17,9 +17,8 @@ package io.openvidu.server.kurento.endpoint; -import org.kurento.client.ErrorEvent; -import org.kurento.client.MediaEvent; import org.kurento.client.RaiseBaseEvent; +import org.kurento.jsonrpc.JsonUtils; import com.google.gson.JsonObject; @@ -44,22 +43,12 @@ public class KmsEvent { } public JsonObject toJson() { - JsonObject json = new JsonObject(); - - if (event instanceof ErrorEvent) { - ErrorEvent errorEvent = (ErrorEvent) event; - json.addProperty("eventType", errorEvent.getType()); - json.addProperty("errorCode", errorEvent.getErrorCode()); - json.addProperty("description", errorEvent.getDescription()); - } else { - MediaEvent mediaEvent = (MediaEvent) event; - json.addProperty("eventType", mediaEvent.getType()); - } - + JsonObject json = JsonUtils.toJsonObject(event); + json.remove("tags"); + json.addProperty("timestamp", timestamp); json.addProperty("session", sessionId); json.addProperty("connection", connectionId); json.addProperty("endpoint", this.endpoint); - json.addProperty("timestamp", timestamp); json.addProperty("msSinceEndpointCreation", msSinceCreation); return json; } diff --git a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java index 76e8e251..22dfb9f6 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java +++ b/openvidu-server/src/main/java/io/openvidu/server/kurento/endpoint/MediaEndpoint.java @@ -34,7 +34,6 @@ import org.kurento.client.OnIceCandidateEvent; import org.kurento.client.RtpEndpoint; import org.kurento.client.SdpEndpoint; import org.kurento.client.WebRtcEndpoint; -import org.kurento.jsonrpc.JsonUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -501,14 +500,13 @@ public abstract class MediaEndpoint { } JsonArray jsonArray = new JsonArray(); - for (KmsEvent event : this.kmsEvents) { - JsonObject jsonKmsEvent = JsonUtils.toJsonObject(event.event); - // Set custom more precise timestamp - jsonKmsEvent.addProperty("timestamp", event.timestamp); - // Set milliseconds since the Publisher or Subscriber started transmitting media - jsonKmsEvent.addProperty("msSinceCreation", event.msSinceCreation); - jsonArray.add(jsonKmsEvent); - } + this.kmsEvents.forEach(ev -> { + JsonObject j = ev.toJson(); + j.remove("session"); + j.remove("connection"); + j.remove("endpoint"); + jsonArray.add(j); + }); json.add("events", jsonArray); return json;