openvidu-server: remove duplicated serialization of SessionProperties

Let SessionProperties serialize itself, instead of doing it externally
on the Session classes.
pull/667/head
Juan Navarro 2021-11-26 12:27:24 +01:00
parent 32fd093cf3
commit 0262c85ac0
3 changed files with 21 additions and 23 deletions

View File

@ -38,6 +38,7 @@ import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSyntaxException;
@ -756,19 +757,15 @@ public class Session {
JsonObject json = new JsonObject();
json.addProperty("sessionId", this.sessionId);
json.addProperty("createdAt", this.createdAt);
json.addProperty("customSessionId", this.properties.customSessionId());
json.addProperty("recording", this.recording);
json.addProperty("mediaMode", this.properties.mediaMode().name());
json.addProperty("recordingMode", this.properties.recordingMode().name());
if (this.properties.defaultRecordingProperties() != null) {
json.add("defaultRecordingProperties", this.properties.defaultRecordingProperties().toJson());
}
if (this.properties.forcedVideoCodec() != null) {
json.addProperty("forcedVideoCodec", this.properties.forcedVideoCodec().name());
}
if (this.properties.isTranscodingAllowed() != null) {
json.addProperty("allowTranscoding", this.properties.isTranscodingAllowed());
// Add keys from SessionProperties
JsonObject sessionPropertiesJson = this.properties.toJson();
for (Map.Entry<String, JsonElement> entry : sessionPropertiesJson.entrySet()) {
json.add(entry.getKey(), entry.getValue().deepCopy());
}
// Add "connections" object
JsonObject connections = new JsonObject();
connections.addProperty("numberOfElements", this.getConnections().size());
JsonArray jsonArrayConnections = new JsonArray();

View File

@ -236,13 +236,13 @@ public class SessionProperties {
return this.allowTranscoding;
}
protected JsonObject toJson() {
public JsonObject toJson() {
JsonObject json = new JsonObject();
json.addProperty("mediaMode", mediaMode().name());
json.addProperty("recordingMode", recordingMode().name());
json.addProperty("customSessionId", customSessionId());
json.add("defaultRecordingProperties", defaultRecordingProperties.toJson());
if (mediaNode() != null) {
if (mediaNode() != null && !mediaNode().isEmpty()) {
JsonObject mediaNodeJson = new JsonObject();
mediaNodeJson.addProperty("id", mediaNode());
json.add("mediaNode", mediaNodeJson);

View File

@ -19,6 +19,7 @@ package io.openvidu.server.core;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -32,6 +33,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.openvidu.client.OpenViduException;
@ -234,22 +236,21 @@ public class Session implements SessionInterface {
json.addProperty("object", "session");
json.addProperty("sessionId", this.sessionId); // TODO: deprecated. Better use only "id"
json.addProperty("createdAt", this.startTime);
json.addProperty("mediaMode", this.sessionProperties.mediaMode().name());
json.addProperty("recordingMode", this.sessionProperties.recordingMode().name());
json.add("defaultRecordingProperties", this.sessionProperties.defaultRecordingProperties().toJson());
if (this.sessionProperties.customSessionId() != null) {
json.addProperty("customSessionId", this.sessionProperties.customSessionId());
json.addProperty("recording", this.recordingManager.sessionIsBeingRecorded(this.sessionId));
// Add keys from SessionProperties
JsonObject sessionPropertiesJson = sessionProperties.toJson();
for (Map.Entry<String, JsonElement> entry : sessionPropertiesJson.entrySet()) {
json.add(entry.getKey(), entry.getValue().deepCopy());
}
// Add "connections" object
JsonObject connections = new JsonObject();
JsonArray participants = this.getSnapshotOfConnectionsAsJsonArray(withPendingConnections, withWebrtcStats);
connections.addProperty("numberOfElements", participants.size());
connections.add("content", participants);
json.add("connections", connections);
json.addProperty("recording", this.recordingManager.sessionIsBeingRecorded(this.sessionId));
if (this.sessionProperties.forcedVideoCodec() != null) {
json.addProperty("forcedVideoCodec", this.sessionProperties.forcedVideoCodec().name());
}
json.addProperty("allowTranscoding", this.sessionProperties.isTranscodingAllowed());
return json;
}