mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: return connectionId on POST /api/tokens
parent
6b6d6c2ba4
commit
04c012a327
|
@ -18,6 +18,8 @@
|
||||||
package io.openvidu.server.core;
|
package io.openvidu.server.core;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
@ -157,13 +159,25 @@ public class Session implements SessionInterface {
|
||||||
this.tokens.put(token.getToken(), token);
|
this.tokens.put(token.getToken(), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean deleteTokenFromConnectionId(String connectionId) {
|
||||||
|
boolean deleted = false;
|
||||||
|
Iterator<Entry<String, Token>> iterator = this.tokens.entrySet().iterator();
|
||||||
|
while (iterator.hasNext() && !deleted) {
|
||||||
|
Entry<String, Token> entry = iterator.next();
|
||||||
|
if (connectionId.equals(entry.getValue().getConnetionId())) {
|
||||||
|
iterator.remove();
|
||||||
|
deleted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deleted;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isTokenValid(String token) {
|
public boolean isTokenValid(String token) {
|
||||||
return this.tokens.containsKey(token);
|
return this.tokens.containsKey(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Token consumeToken(String token) {
|
public Token consumeToken(String token) {
|
||||||
Token tokenObj = this.tokens.remove(token);
|
Token tokenObj = this.tokens.remove(token);
|
||||||
showTokens("Token consumed");
|
|
||||||
return tokenObj;
|
return tokenObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.util.stream.Collectors;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
|
||||||
import org.kurento.jsonrpc.message.Request;
|
import org.kurento.jsonrpc.message.Request;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -295,7 +294,7 @@ public abstract class SessionManager {
|
||||||
return sessionNotActive;
|
return sessionNotActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String newToken(Session session, OpenViduRole role, String serverMetadata,
|
public Token newToken(Session session, OpenViduRole role, String serverMetadata,
|
||||||
KurentoTokenOptions kurentoTokenOptions) throws Exception {
|
KurentoTokenOptions kurentoTokenOptions) throws Exception {
|
||||||
if (!formatChecker.isServerMetadataFormatCorrect(serverMetadata)) {
|
if (!formatChecker.isServerMetadataFormatCorrect(serverMetadata)) {
|
||||||
log.error("Data invalid format");
|
log.error("Data invalid format");
|
||||||
|
@ -305,7 +304,7 @@ public abstract class SessionManager {
|
||||||
kurentoTokenOptions);
|
kurentoTokenOptions);
|
||||||
session.storeToken(tokenObj);
|
session.storeToken(tokenObj);
|
||||||
session.showTokens("Token created");
|
session.showTokens("Token created");
|
||||||
return tokenObj.getToken();
|
return tokenObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Token newTokenForInsecureUser(Session session, String token, String serverMetadata) throws Exception {
|
public Token newTokenForInsecureUser(Session session, String token, String serverMetadata) throws Exception {
|
||||||
|
@ -355,17 +354,13 @@ public abstract class SessionManager {
|
||||||
|
|
||||||
public Participant newParticipant(String sessionId, String participantPrivatetId, Token token,
|
public Participant newParticipant(String sessionId, String participantPrivatetId, Token token,
|
||||||
String clientMetadata, GeoLocation location, String platform, String finalUserId) {
|
String clientMetadata, GeoLocation location, String platform, String finalUserId) {
|
||||||
|
|
||||||
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
|
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
|
||||||
String participantPublicId = IdentifierPrefixes.PARTICIPANT_PUBLIC_ID
|
|
||||||
+ RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(9);
|
Participant p = new Participant(finalUserId, participantPrivatetId, token.getConnetionId(), sessionId,
|
||||||
Participant p = new Participant(finalUserId, participantPrivatetId, participantPublicId, sessionId, token,
|
token, clientMetadata, location, platform, EndpointType.WEBRTC_ENDPOINT, null);
|
||||||
clientMetadata, location, platform, EndpointType.WEBRTC_ENDPOINT, null);
|
|
||||||
while (this.sessionidParticipantpublicidParticipant.get(sessionId).putIfAbsent(participantPublicId,
|
this.sessionidParticipantpublicidParticipant.get(sessionId).put(p.getParticipantPublicId(), p);
|
||||||
p) != null) {
|
|
||||||
participantPublicId = IdentifierPrefixes.PARTICIPANT_PUBLIC_ID
|
|
||||||
+ RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(9);
|
|
||||||
p.setParticipantPublicId(participantPublicId);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sessionidFinalUsers.get(sessionId).computeIfAbsent(finalUserId, k -> {
|
this.sessionidFinalUsers.get(sessionId).computeIfAbsent(finalUserId, k -> {
|
||||||
log.info("Participant {} of session {} is a final user connecting to this session for the first time",
|
log.info("Participant {} of session {} is a final user connecting to this session for the first time",
|
||||||
|
@ -374,6 +369,7 @@ public abstract class SessionManager {
|
||||||
}).addConnectionIfAbsent(p);
|
}).addConnectionIfAbsent(p);
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, sessionId);
|
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, sessionId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package io.openvidu.server.core;
|
package io.openvidu.server.core;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
|
||||||
import io.openvidu.java.client.OpenViduRole;
|
import io.openvidu.java.client.OpenViduRole;
|
||||||
import io.openvidu.server.coturn.TurnCredentials;
|
import io.openvidu.server.coturn.TurnCredentials;
|
||||||
import io.openvidu.server.kurento.core.KurentoTokenOptions;
|
import io.openvidu.server.kurento.core.KurentoTokenOptions;
|
||||||
|
@ -27,12 +29,10 @@ public class Token {
|
||||||
private OpenViduRole role;
|
private OpenViduRole role;
|
||||||
private String serverMetadata = "";
|
private String serverMetadata = "";
|
||||||
private TurnCredentials turnCredentials;
|
private TurnCredentials turnCredentials;
|
||||||
|
|
||||||
private KurentoTokenOptions kurentoTokenOptions;
|
private KurentoTokenOptions kurentoTokenOptions;
|
||||||
|
|
||||||
public Token(String token) {
|
private final String connectionId = IdentifierPrefixes.PARTICIPANT_PUBLIC_ID
|
||||||
this.token = token;
|
+ RandomStringUtils.randomAlphabetic(1).toUpperCase() + RandomStringUtils.randomAlphanumeric(9);
|
||||||
}
|
|
||||||
|
|
||||||
public Token(String token, OpenViduRole role, String serverMetadata, TurnCredentials turnCredentials,
|
public Token(String token, OpenViduRole role, String serverMetadata, TurnCredentials turnCredentials,
|
||||||
KurentoTokenOptions kurentoTokenOptions) {
|
KurentoTokenOptions kurentoTokenOptions) {
|
||||||
|
@ -50,7 +50,7 @@ public class Token {
|
||||||
public void setToken(String token) {
|
public void setToken(String token) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenViduRole getRole() {
|
public OpenViduRole getRole() {
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,10 @@ public class Token {
|
||||||
return kurentoTokenOptions;
|
return kurentoTokenOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getConnetionId() {
|
||||||
|
return connectionId;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
if (this.role != null)
|
if (this.role != null)
|
||||||
|
|
|
@ -30,7 +30,6 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import io.openvidu.java.client.*;
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.kurento.client.GenericMediaElement;
|
import org.kurento.client.GenericMediaElement;
|
||||||
import org.kurento.client.IceCandidate;
|
import org.kurento.client.IceCandidate;
|
||||||
|
@ -48,6 +47,12 @@ import com.google.gson.JsonObject;
|
||||||
import io.openvidu.client.OpenViduException;
|
import io.openvidu.client.OpenViduException;
|
||||||
import io.openvidu.client.OpenViduException.Code;
|
import io.openvidu.client.OpenViduException.Code;
|
||||||
import io.openvidu.client.internal.ProtocolElements;
|
import io.openvidu.client.internal.ProtocolElements;
|
||||||
|
import io.openvidu.java.client.MediaMode;
|
||||||
|
import io.openvidu.java.client.Recording;
|
||||||
|
import io.openvidu.java.client.RecordingLayout;
|
||||||
|
import io.openvidu.java.client.RecordingMode;
|
||||||
|
import io.openvidu.java.client.RecordingProperties;
|
||||||
|
import io.openvidu.java.client.SessionProperties;
|
||||||
import io.openvidu.server.core.EndReason;
|
import io.openvidu.server.core.EndReason;
|
||||||
import io.openvidu.server.core.FinalUser;
|
import io.openvidu.server.core.FinalUser;
|
||||||
import io.openvidu.server.core.IdentifierPrefixes;
|
import io.openvidu.server.core.IdentifierPrefixes;
|
||||||
|
@ -142,7 +147,8 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
|
|
||||||
// If Recording default layout is COMPOSED_QUICK_START
|
// If Recording default layout is COMPOSED_QUICK_START
|
||||||
Recording.OutputMode defaultOutputMode = kSession.getSessionProperties().defaultOutputMode();
|
Recording.OutputMode defaultOutputMode = kSession.getSessionProperties().defaultOutputMode();
|
||||||
if (openviduConfig.isRecordingModuleEnabled() && defaultOutputMode.equals(Recording.OutputMode.COMPOSED_QUICK_START)) {
|
if (openviduConfig.isRecordingModuleEnabled()
|
||||||
|
&& defaultOutputMode.equals(Recording.OutputMode.COMPOSED_QUICK_START)) {
|
||||||
recordingManager.startComposedQuickStartContainer(kSession);
|
recordingManager.startComposedQuickStartContainer(kSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,10 +306,12 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
|
|
||||||
} else if (remainingParticipants.size() == 1 && openviduConfig.isRecordingModuleEnabled()
|
} else if (remainingParticipants.size() == 1 && openviduConfig.isRecordingModuleEnabled()
|
||||||
&& MediaMode.ROUTED.equals(session.getSessionProperties().mediaMode())
|
&& MediaMode.ROUTED.equals(session.getSessionProperties().mediaMode())
|
||||||
&& session.getSessionProperties().defaultOutputMode().equals(Recording.OutputMode.COMPOSED_QUICK_START)
|
&& session.getSessionProperties().defaultOutputMode()
|
||||||
|
.equals(Recording.OutputMode.COMPOSED_QUICK_START)
|
||||||
&& ProtocolElements.RECORDER_PARTICIPANT_PUBLICID
|
&& ProtocolElements.RECORDER_PARTICIPANT_PUBLICID
|
||||||
.equals(remainingParticipants.iterator().next().getParticipantPublicId())) {
|
.equals(remainingParticipants.iterator().next().getParticipantPublicId())) {
|
||||||
// If no recordings are active in COMPOSED_QUICK_START output mode, stop container
|
// If no recordings are active in COMPOSED_QUICK_START output mode, stop
|
||||||
|
// container
|
||||||
recordingManager.stopComposedQuickStartContainer(session, reason);
|
recordingManager.stopComposedQuickStartContainer(session, reason);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,7 @@ import io.openvidu.server.core.IdentifierPrefixes;
|
||||||
import io.openvidu.server.core.Participant;
|
import io.openvidu.server.core.Participant;
|
||||||
import io.openvidu.server.core.Session;
|
import io.openvidu.server.core.Session;
|
||||||
import io.openvidu.server.core.SessionManager;
|
import io.openvidu.server.core.SessionManager;
|
||||||
|
import io.openvidu.server.core.Token;
|
||||||
import io.openvidu.server.kurento.core.KurentoMediaOptions;
|
import io.openvidu.server.kurento.core.KurentoMediaOptions;
|
||||||
import io.openvidu.server.kurento.core.KurentoTokenOptions;
|
import io.openvidu.server.kurento.core.KurentoTokenOptions;
|
||||||
import io.openvidu.server.recording.Recording;
|
import io.openvidu.server.recording.Recording;
|
||||||
|
@ -280,7 +281,12 @@ public class SessionRestController {
|
||||||
this.sessionManager.evictParticipant(participant, null, null, EndReason.forceDisconnectByServer);
|
this.sessionManager.evictParticipant(participant, null, null, EndReason.forceDisconnectByServer);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
} else {
|
} else {
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
// Try to delete unused token
|
||||||
|
if (session.deleteTokenFromConnectionId(participantPublicId)) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
|
} else {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -387,14 +393,15 @@ public class SessionRestController {
|
||||||
// While closing a session tokens can't be generated
|
// While closing a session tokens can't be generated
|
||||||
if (session.closingLock.readLock().tryLock()) {
|
if (session.closingLock.readLock().tryLock()) {
|
||||||
try {
|
try {
|
||||||
String token = sessionManager.newToken(session, role, metadata, kurentoTokenOptions);
|
Token token = sessionManager.newToken(session, role, metadata, kurentoTokenOptions);
|
||||||
|
|
||||||
JsonObject responseJson = new JsonObject();
|
JsonObject responseJson = new JsonObject();
|
||||||
responseJson.addProperty("id", token);
|
responseJson.addProperty("id", token.getToken());
|
||||||
|
responseJson.addProperty("connectionId", token.getConnetionId());
|
||||||
responseJson.addProperty("session", sessionId);
|
responseJson.addProperty("session", sessionId);
|
||||||
responseJson.addProperty("role", role.toString());
|
responseJson.addProperty("role", role.toString());
|
||||||
responseJson.addProperty("data", metadata);
|
responseJson.addProperty("data", metadata);
|
||||||
responseJson.addProperty("token", token);
|
responseJson.addProperty("token", token.getToken());
|
||||||
|
|
||||||
if (kurentoOptions != null) {
|
if (kurentoOptions != null) {
|
||||||
JsonObject kurentoOptsResponse = new JsonObject();
|
JsonObject kurentoOptsResponse = new JsonObject();
|
||||||
|
|
|
@ -257,6 +257,9 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
|
||||||
|
|
||||||
Token tokenObj = session.consumeToken(token);
|
Token tokenObj = session.consumeToken(token);
|
||||||
if (tokenObj != null) {
|
if (tokenObj != null) {
|
||||||
|
|
||||||
|
session.showTokens("Token consumed");
|
||||||
|
|
||||||
String clientMetadata = getStringParam(request, ProtocolElements.JOINROOM_METADATA_PARAM);
|
String clientMetadata = getStringParam(request, ProtocolElements.JOINROOM_METADATA_PARAM);
|
||||||
if (sessionManager.formatChecker.isServerMetadataFormatCorrect(clientMetadata)) {
|
if (sessionManager.formatChecker.isServerMetadataFormatCorrect(clientMetadata)) {
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ OPENVIDU_CDR_PATH=/opt/openvidu/cdr
|
||||||
OPENVIDU_WEBHOOK=false
|
OPENVIDU_WEBHOOK=false
|
||||||
OPENVIDU_WEBHOOK_ENDPOINT=
|
OPENVIDU_WEBHOOK_ENDPOINT=
|
||||||
OPENVIDU_WEBHOOK_HEADERS=[]
|
OPENVIDU_WEBHOOK_HEADERS=[]
|
||||||
OPENVIDU_WEBHOOK_EVENTS=["sessionCreated","sessionDestroyed","participantJoined","participantLeft","webrtcConnectionCreated","webrtcConnectionDestroyed","recordingStatusChanged","filterEventDispatched","mediaNodeStatusChanged"]
|
OPENVIDU_WEBHOOK_EVENTS=["sessionCreated","sessionDestroyed","participantJoined","participantLeft","webrtcConnectionCreated","webrtcConnectionDestroyed","recordingStatusChanged","filterEventDispatched","mediaNodeStatusChanged","autoscaling"]
|
||||||
|
|
||||||
OPENVIDU_RECORDING=false
|
OPENVIDU_RECORDING=false
|
||||||
OPENVIDU_RECORDING_DEBUG=false
|
OPENVIDU_RECORDING_DEBUG=false
|
||||||
|
|
Loading…
Reference in New Issue