mirror of https://github.com/OpenVidu/openvidu.git
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
parent
202e782c9d
commit
425fe0983c
|
@ -336,6 +336,21 @@ public abstract class SessionManager {
|
|||
}
|
||||
Token tokenObj = tokenGenerator.generateToken(session.getSessionId(), serverMetadata, record, role,
|
||||
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);
|
||||
return tokenObj;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class Token {
|
|||
private ConnectionProperties connectionProperties;
|
||||
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);
|
||||
|
||||
public Token(String token, String sessionId, ConnectionProperties connectionProperties,
|
||||
|
@ -118,6 +118,10 @@ public class Token {
|
|||
public String getConnectionId() {
|
||||
return connectionId;
|
||||
}
|
||||
|
||||
public void setConnectionId(String connectionId) {
|
||||
this.connectionId = connectionId;
|
||||
}
|
||||
|
||||
public JsonObject toJson() {
|
||||
JsonObject json = new JsonObject();
|
||||
|
|
Loading…
Reference in New Issue