openvidu-server: allow setting custom ConnectionId for debug purposes

Allows applications to set a custom string for the the connection ID,
which is a great help for debugging purposes, as it will appear in
all server logs and also will be used to set media server object names
(with obj.setName() API)
pull/690/head
pabloFuente 2022-01-24 12:04:54 +01:00 committed by Juan Navarro
parent 202e782c9d
commit 425fe0983c
2 changed files with 20 additions and 1 deletions

View File

@ -336,6 +336,21 @@ public abstract class SessionManager {
} }
Token tokenObj = tokenGenerator.generateToken(session.getSessionId(), serverMetadata, record, role, Token tokenObj = tokenGenerator.generateToken(session.getSessionId(), serverMetadata, record, role,
kurentoOptions); kurentoOptions);
// Internal dev feature: allows customizing connectionId
if (serverMetadata.contains("openviduCustomConnectionId")) {
try {
JsonObject serverMetadataJson = JsonParser.parseString(serverMetadata).getAsJsonObject();
String customConnectionId = serverMetadataJson.get("openviduCustomConnectionId").getAsString();
customConnectionId = customConnectionId.replaceAll(IdentifierPrefixes.PARTICIPANT_PUBLIC_ID, "");
tokenObj.setConnectionId(IdentifierPrefixes.PARTICIPANT_PUBLIC_ID + customConnectionId);
} catch (Exception e) {
log.debug(
"Tried to parse server metadata as JSON after encountering \"openviduCustomConnectionId\" string but failed with {}: {}",
e.getClass().getCanonicalName(), e.getMessage());
}
}
session.storeToken(tokenObj); session.storeToken(tokenObj);
return tokenObj; return tokenObj;
} }

View File

@ -37,7 +37,7 @@ public class Token {
private ConnectionProperties connectionProperties; private ConnectionProperties connectionProperties;
private TurnCredentials turnCredentials; private TurnCredentials turnCredentials;
private final String connectionId = IdentifierPrefixes.PARTICIPANT_PUBLIC_ID private String connectionId = IdentifierPrefixes.PARTICIPANT_PUBLIC_ID
+ RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(9); + RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(9);
public Token(String token, String sessionId, ConnectionProperties connectionProperties, public Token(String token, String sessionId, ConnectionProperties connectionProperties,
@ -118,6 +118,10 @@ public class Token {
public String getConnectionId() { public String getConnectionId() {
return connectionId; return connectionId;
} }
public void setConnectionId(String connectionId) {
this.connectionId = connectionId;
}
public JsonObject toJson() { public JsonObject toJson() {
JsonObject json = new JsonObject(); JsonObject json = new JsonObject();