mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: GET /sessions, streamId refactoring
parent
c7dd18c21c
commit
a9fb7b0739
|
@ -50,6 +50,7 @@ public class ProtocolElements {
|
||||||
public static final String PUBLISHVIDEO_SDPOFFER_PARAM = "sdpOffer";
|
public static final String PUBLISHVIDEO_SDPOFFER_PARAM = "sdpOffer";
|
||||||
public static final String PUBLISHVIDEO_DOLOOPBACK_PARAM = "doLoopback";
|
public static final String PUBLISHVIDEO_DOLOOPBACK_PARAM = "doLoopback";
|
||||||
public static final String PUBLISHVIDEO_SDPANSWER_PARAM = "sdpAnswer";
|
public static final String PUBLISHVIDEO_SDPANSWER_PARAM = "sdpAnswer";
|
||||||
|
public static final String PUBLISHVIDEO_STREAMID_PARAM = "id";
|
||||||
public static final String PUBLISHVIDEO_AUDIOACTIVE_PARAM = "audioActive";
|
public static final String PUBLISHVIDEO_AUDIOACTIVE_PARAM = "audioActive";
|
||||||
public static final String PUBLISHVIDEO_VIDEOACTIVE_PARAM = "videoActive";
|
public static final String PUBLISHVIDEO_VIDEOACTIVE_PARAM = "videoActive";
|
||||||
public static final String PUBLISHVIDEO_TYPEOFVIDEO_PARAM = "typeOfVideo";
|
public static final String PUBLISHVIDEO_TYPEOFVIDEO_PARAM = "typeOfVideo";
|
||||||
|
|
|
@ -36,15 +36,17 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
|
||||||
// Security for API REST
|
// Security for API REST
|
||||||
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry conf = http.csrf().disable()
|
ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry conf = http.cors().and()
|
||||||
.authorizeRequests().antMatchers(HttpMethod.POST, "/api/sessions").authenticated()
|
.csrf().disable().authorizeRequests().antMatchers(HttpMethod.POST, "/api/sessions").authenticated()
|
||||||
|
.antMatchers(HttpMethod.POST, "/api/sessions/**").authenticated()
|
||||||
.antMatchers(HttpMethod.POST, "/api/tokens").authenticated()
|
.antMatchers(HttpMethod.POST, "/api/tokens").authenticated()
|
||||||
.antMatchers(HttpMethod.POST, "/api/recordings/start").authenticated()
|
.antMatchers(HttpMethod.POST, "/api/recordings/start").authenticated()
|
||||||
.antMatchers(HttpMethod.POST, "/api/recordings/stop").authenticated()
|
.antMatchers(HttpMethod.POST, "/api/recordings/stop").authenticated()
|
||||||
.antMatchers(HttpMethod.GET, "/api/recordings").authenticated()
|
.antMatchers(HttpMethod.GET, "/api/recordings").authenticated()
|
||||||
.antMatchers(HttpMethod.GET, "/api/recordings/**").authenticated()
|
.antMatchers(HttpMethod.GET, "/api/recordings/**").authenticated()
|
||||||
.antMatchers(HttpMethod.DELETE, "/api/recordings/**").authenticated()
|
.antMatchers(HttpMethod.DELETE, "/api/recordings/**").authenticated()
|
||||||
.antMatchers(HttpMethod.GET, "/config/**").authenticated().antMatchers("/").authenticated();
|
.antMatchers(HttpMethod.GET, "/config/openvidu-publicurl").anonymous()
|
||||||
|
.antMatchers(HttpMethod.GET, "/config/**").authenticated();
|
||||||
|
|
||||||
// Security for layouts
|
// Security for layouts
|
||||||
conf.antMatchers("/layouts/*").authenticated();
|
conf.antMatchers("/layouts/*").authenticated();
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
package io.openvidu.server.core;
|
package io.openvidu.server.core;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
public class Participant {
|
public class Participant {
|
||||||
|
|
||||||
private String participantPrivatetId; // ID to identify the user on server (org.kurento.jsonrpc.Session.id)
|
private String participantPrivatetId; // ID to identify the user on server (org.kurento.jsonrpc.Session.id)
|
||||||
|
@ -128,6 +130,10 @@ public class Participant {
|
||||||
this.frameRate = frameRate;
|
this.frameRate = frameRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPublisherStremId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public String getFullMetadata() {
|
public String getFullMetadata() {
|
||||||
String fullMetadata;
|
String fullMetadata;
|
||||||
if ((!this.clientMetadata.isEmpty()) && (!this.serverMetadata.isEmpty())) {
|
if ((!this.clientMetadata.isEmpty()) && (!this.serverMetadata.isEmpty())) {
|
||||||
|
@ -194,4 +200,12 @@ public class Participant {
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public JSONObject toJSON() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("connectionId", this.participantPublicId);
|
||||||
|
json.put("token", this.token.toJSON());
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,8 @@ package io.openvidu.server.core;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import io.openvidu.java.client.SessionProperties;
|
import io.openvidu.java.client.SessionProperties;
|
||||||
|
|
||||||
public interface Session {
|
public interface Session {
|
||||||
|
@ -43,4 +45,6 @@ public interface Session {
|
||||||
|
|
||||||
int getActivePublishers();
|
int getActivePublishers();
|
||||||
|
|
||||||
|
JSONObject toJSON();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,19 +94,9 @@ public class SessionEventsHandler {
|
||||||
existingParticipant.getFullMetadata());
|
existingParticipant.getFullMetadata());
|
||||||
|
|
||||||
if (existingParticipant.isStreaming()) {
|
if (existingParticipant.isStreaming()) {
|
||||||
|
|
||||||
String streamId = "";
|
|
||||||
if ("SCREEN".equals(existingParticipant.getTypeOfVideo())) {
|
|
||||||
streamId = "SCREEN";
|
|
||||||
} else if (existingParticipant.isVideoActive()) {
|
|
||||||
streamId = "CAMERA";
|
|
||||||
} else if (existingParticipant.isAudioActive()) {
|
|
||||||
streamId = "MICRO";
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject stream = new JsonObject();
|
JsonObject stream = new JsonObject();
|
||||||
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMID_PARAM,
|
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMID_PARAM,
|
||||||
existingParticipant.getParticipantPublicId() + "_" + streamId);
|
existingParticipant.getPublisherStremId());
|
||||||
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMAUDIOACTIVE_PARAM,
|
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMAUDIOACTIVE_PARAM,
|
||||||
existingParticipant.isAudioActive());
|
existingParticipant.isAudioActive());
|
||||||
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMVIDEOACTIVE_PARAM,
|
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMVIDEOACTIVE_PARAM,
|
||||||
|
@ -178,7 +168,7 @@ public class SessionEventsHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPublishMedia(Participant participant, String sessionId, MediaOptions mediaOptions, String sdpAnswer,
|
public void onPublishMedia(Participant participant, String streamId, String sessionId, MediaOptions mediaOptions, String sdpAnswer,
|
||||||
Set<Participant> participants, Integer transactionId, OpenViduException error) {
|
Set<Participant> participants, Integer transactionId, OpenViduException error) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
rpcNotificationService.sendErrorResponse(participant.getParticipantPrivateId(), transactionId, null, error);
|
rpcNotificationService.sendErrorResponse(participant.getParticipantPrivateId(), transactionId, null, error);
|
||||||
|
@ -186,23 +176,14 @@ public class SessionEventsHandler {
|
||||||
}
|
}
|
||||||
JsonObject result = new JsonObject();
|
JsonObject result = new JsonObject();
|
||||||
result.addProperty(ProtocolElements.PUBLISHVIDEO_SDPANSWER_PARAM, sdpAnswer);
|
result.addProperty(ProtocolElements.PUBLISHVIDEO_SDPANSWER_PARAM, sdpAnswer);
|
||||||
|
result.addProperty(ProtocolElements.PUBLISHVIDEO_STREAMID_PARAM, streamId);
|
||||||
rpcNotificationService.sendResponse(participant.getParticipantPrivateId(), transactionId, result);
|
rpcNotificationService.sendResponse(participant.getParticipantPrivateId(), transactionId, result);
|
||||||
|
|
||||||
JsonObject params = new JsonObject();
|
JsonObject params = new JsonObject();
|
||||||
params.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_USER_PARAM, participant.getParticipantPublicId());
|
params.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_USER_PARAM, participant.getParticipantPublicId());
|
||||||
JsonObject stream = new JsonObject();
|
JsonObject stream = new JsonObject();
|
||||||
|
|
||||||
String streamId = "";
|
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_STREAMID_PARAM, streamId);
|
||||||
if ("SCREEN".equals(mediaOptions.typeOfVideo)) {
|
|
||||||
streamId = "SCREEN";
|
|
||||||
} else if (mediaOptions.videoActive) {
|
|
||||||
streamId = "CAMERA";
|
|
||||||
} else if (mediaOptions.audioActive) {
|
|
||||||
streamId = "MICRO";
|
|
||||||
}
|
|
||||||
|
|
||||||
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_STREAMID_PARAM,
|
|
||||||
participant.getParticipantPublicId() + "_" + streamId);
|
|
||||||
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_AUDIOACTIVE_PARAM, mediaOptions.audioActive);
|
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_AUDIOACTIVE_PARAM, mediaOptions.audioActive);
|
||||||
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_VIDEOACTIVE_PARAM, mediaOptions.videoActive);
|
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_VIDEOACTIVE_PARAM, mediaOptions.videoActive);
|
||||||
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_TYPEOFVIDEO_PARAM, mediaOptions.typeOfVideo);
|
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_TYPEOFVIDEO_PARAM, mediaOptions.typeOfVideo);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package io.openvidu.server.core;
|
package io.openvidu.server.core;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
@ -116,6 +117,15 @@ public abstract class SessionManager {
|
||||||
return new HashSet<String>(sessions.keySet());
|
return new HashSet<String>(sessions.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all currently active (opened) sessions.
|
||||||
|
*
|
||||||
|
* @return set of the session's identifiers
|
||||||
|
*/
|
||||||
|
public Collection<Session> getSessionObjects() {
|
||||||
|
return sessions.values();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all the participants inside a session.
|
* Returns all the participants inside a session.
|
||||||
*
|
*
|
||||||
|
@ -193,81 +203,6 @@ public abstract class SessionManager {
|
||||||
|
|
||||||
public String newToken(String sessionId, ParticipantRole role, String serverMetadata) throws OpenViduException {
|
public String newToken(String sessionId, ParticipantRole role, String serverMetadata) throws OpenViduException {
|
||||||
|
|
||||||
/*if (!isMetadataFormatCorrect(serverMetadata)) {
|
|
||||||
log.error("Data invalid format. Max length allowed is 10000 chars");
|
|
||||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
|
||||||
"Data invalid format. Max length allowed is 10000 chars");
|
|
||||||
}
|
|
||||||
|
|
||||||
String token = OpenViduServer.publicUrl;
|
|
||||||
token += "?sessionId=" + sessionId;
|
|
||||||
token += "&token=" + this.generateRandomChain();
|
|
||||||
token += "&role=" + role.name();
|
|
||||||
TurnCredentials turnCredentials = null;
|
|
||||||
if (this.coturnCredentialsService.isCoturnAvailable()) {
|
|
||||||
turnCredentials = coturnCredentialsService.createUser();
|
|
||||||
if (turnCredentials != null) {
|
|
||||||
if (turnCredentials != null) {
|
|
||||||
token += "&turnUsername=" + turnCredentials.getUsername();
|
|
||||||
token += "&turnCredential=" + turnCredentials.getCredential();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Token t = new Token(token, role, serverMetadata, turnCredentials);
|
|
||||||
|
|
||||||
final String finalToken = token;
|
|
||||||
|
|
||||||
ConcurrentHashMap<String, Token> tok = this.sessionidTokenTokenobj.computeIfPresent(sessionId, (key, value) -> {
|
|
||||||
value.putIfAbsent(finalToken, t);
|
|
||||||
return value;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (tok == null) {
|
|
||||||
log.error("sessionId [" + sessionId + "] is not valid");
|
|
||||||
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, "sessionId [" + sessionId + "] not found");
|
|
||||||
} else {
|
|
||||||
return tok.get(token).getToken();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
/*if (!isMetadataFormatCorrect(serverMetadata)) {
|
|
||||||
log.error("Data invalid format. Max length allowed is 10000 chars");
|
|
||||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
|
||||||
"Data invalid format. Max length allowed is 10000 chars");
|
|
||||||
}
|
|
||||||
|
|
||||||
final String[] tokenArray = {""};
|
|
||||||
|
|
||||||
try {
|
|
||||||
sessionidTokenTokenobj.computeIfPresent(sessionId, (key, value) -> {
|
|
||||||
String token = OpenViduServer.publicUrl;
|
|
||||||
token += "?sessionId=" + sessionId;
|
|
||||||
token += "&token=" + this.generateRandomChain();
|
|
||||||
token += "&role=" + role.name();
|
|
||||||
TurnCredentials turnCredentials = null;
|
|
||||||
if (this.coturnCredentialsService.isCoturnAvailable()) {
|
|
||||||
turnCredentials = coturnCredentialsService.createUser();
|
|
||||||
if (turnCredentials != null) {
|
|
||||||
token += "&turnUsername=" + turnCredentials.getUsername();
|
|
||||||
token += "&turnCredential=" + turnCredentials.getCredential();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Token t = new Token(token, role, serverMetadata, turnCredentials);
|
|
||||||
value.putIfAbsent(token, t);
|
|
||||||
tokenArray[0] = token;
|
|
||||||
throw new RuntimeException();
|
|
||||||
});
|
|
||||||
} catch(RuntimeException e) {
|
|
||||||
log.info("Token succesfully created");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tokenArray[0].isEmpty()) {
|
|
||||||
log.error("sessionId [" + sessionId + "] is not valid");
|
|
||||||
throw new OpenViduException(Code.ROOM_NOT_FOUND_ERROR_CODE, "sessionId [" + sessionId + "] not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
return tokenArray[0];*/
|
|
||||||
|
|
||||||
ConcurrentHashMap<String, Token> map = this.sessionidTokenTokenobj.putIfAbsent(sessionId, new ConcurrentHashMap<>());
|
ConcurrentHashMap<String, Token> map = this.sessionidTokenTokenobj.putIfAbsent(sessionId, new ConcurrentHashMap<>());
|
||||||
if (map != null) {
|
if (map != null) {
|
||||||
|
|
||||||
|
|
|
@ -17,14 +17,16 @@
|
||||||
|
|
||||||
package io.openvidu.server.core;
|
package io.openvidu.server.core;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import io.openvidu.server.coturn.TurnCredentials;
|
import io.openvidu.server.coturn.TurnCredentials;
|
||||||
|
|
||||||
public class Token {
|
public class Token {
|
||||||
|
|
||||||
String token;
|
private String token;
|
||||||
ParticipantRole role;
|
private ParticipantRole role;
|
||||||
String serverMetadata = "";
|
private String serverMetadata = "";
|
||||||
TurnCredentials turnCredentials;
|
private TurnCredentials turnCredentials;
|
||||||
|
|
||||||
public Token(String token) {
|
public Token(String token) {
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
@ -61,4 +63,13 @@ public class Token {
|
||||||
return this.token;
|
return this.token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public JSONObject toJSON() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("token", this.token);
|
||||||
|
json.put("role", this.role.name());
|
||||||
|
json.put("data", this.serverMetadata);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -24,6 +24,9 @@ import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
import org.kurento.client.Continuation;
|
import org.kurento.client.Continuation;
|
||||||
import org.kurento.client.ErrorEvent;
|
import org.kurento.client.ErrorEvent;
|
||||||
import org.kurento.client.Filter;
|
import org.kurento.client.Filter;
|
||||||
|
@ -85,15 +88,18 @@ public class KurentoParticipant extends Participant {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createPublishingEndpoint(MediaOptions mediaOptions) {
|
public void createPublishingEndpoint(MediaOptions mediaOptions) {
|
||||||
|
|
||||||
publisher.createEndpoint(endPointLatch);
|
publisher.createEndpoint(endPointLatch);
|
||||||
if (getPublisher().getEndpoint() == null) {
|
if (getPublisher().getEndpoint() == null) {
|
||||||
throw new OpenViduException(Code.MEDIA_ENDPOINT_ERROR_CODE, "Unable to create publisher endpoint");
|
throw new OpenViduException(Code.MEDIA_ENDPOINT_ERROR_CODE, "Unable to create publisher endpoint");
|
||||||
}
|
}
|
||||||
this.publisher.getEndpoint().addTag("name", "PUBLISHER " + this.getParticipantPublicId());
|
|
||||||
|
|
||||||
|
String publisherStreamId = this.getParticipantPublicId() + "_" +
|
||||||
|
(mediaOptions.videoActive ? mediaOptions.typeOfVideo : "MICRO") + "_" +
|
||||||
|
RandomStringUtils.random(5, true, false).toUpperCase();
|
||||||
|
this.publisher.getEndpoint().addTag("name", publisherStreamId);
|
||||||
addEndpointListeners(this.publisher);
|
addEndpointListeners(this.publisher);
|
||||||
|
|
||||||
|
|
||||||
CDR.recordNewPublisher(this, this.session.getSessionId(), mediaOptions);
|
CDR.recordNewPublisher(this, this.session.getSessionId(), mediaOptions);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -279,8 +285,9 @@ public class KurentoParticipant extends Participant {
|
||||||
throw new OpenViduException(Code.MEDIA_ENDPOINT_ERROR_CODE, "Unable to create subscriber endpoint");
|
throw new OpenViduException(Code.MEDIA_ENDPOINT_ERROR_CODE, "Unable to create subscriber endpoint");
|
||||||
}
|
}
|
||||||
|
|
||||||
subscriber.getEndpoint().addTag("name",
|
String subscriberStreamId = this.getParticipantPublicId() + "_" + kSender.getPublisherStremId();
|
||||||
"SUBSCRIBER " + senderName + " for user " + this.getParticipantPublicId());
|
|
||||||
|
subscriber.getEndpoint().addTag("name", subscriberStreamId);
|
||||||
|
|
||||||
addEndpointListeners(subscriber);
|
addEndpointListeners(subscriber);
|
||||||
|
|
||||||
|
@ -515,7 +522,7 @@ public class KurentoParticipant extends Participant {
|
||||||
* System.out.println(msg); this.infoHandler.sendInfo(msg); });
|
* System.out.println(msg); this.infoHandler.sendInfo(msg); });
|
||||||
*/
|
*/
|
||||||
|
|
||||||
endpoint.getWebEndpoint().addErrorListener((event) -> {
|
/*endpoint.getWebEndpoint().addErrorListener((event) -> {
|
||||||
String msg = " Error (PUBLISHER) -> " + "ERRORCODE: " + event.getErrorCode()
|
String msg = " Error (PUBLISHER) -> " + "ERRORCODE: " + event.getErrorCode()
|
||||||
+ " | DESCRIPTION: " + event.getDescription() + " | TIMESTAMP: " + System.currentTimeMillis();
|
+ " | DESCRIPTION: " + event.getDescription() + " | TIMESTAMP: " + System.currentTimeMillis();
|
||||||
log.debug(msg);
|
log.debug(msg);
|
||||||
|
@ -620,8 +627,42 @@ public class KurentoParticipant extends Participant {
|
||||||
+ " | TIMESTAMP: " + System.currentTimeMillis();
|
+ " | TIMESTAMP: " + System.currentTimeMillis();
|
||||||
log.debug(msg);
|
log.debug(msg);
|
||||||
this.infoHandler.sendInfo(msg);
|
this.infoHandler.sendInfo(msg);
|
||||||
|
});*/
|
||||||
|
|
||||||
|
endpoint.getWebEndpoint().addNewCandidatePairSelectedListener((event) -> {
|
||||||
|
endpoint.selectedLocalIceCandidate = event.getCandidatePair().getLocalCandidate();
|
||||||
|
endpoint.selectedRemoteIceCandidate = event.getCandidatePair().getRemoteCandidate();
|
||||||
|
String msg = "ICE CANDIDATE SELECTED (" + endpoint.getEndpoint().getTag("name")
|
||||||
|
+ "): LOCAL CANDIDATE: " + endpoint.selectedLocalIceCandidate +
|
||||||
|
" | REMOTE CANDIDATE: " + endpoint.selectedRemoteIceCandidate +
|
||||||
|
" | TIMESTAMP: " + System.currentTimeMillis();
|
||||||
|
log.warn(msg);
|
||||||
|
this.infoHandler.sendInfo(msg);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public JSONObject toJSON() {
|
||||||
|
JSONObject json = super.toJSON();
|
||||||
|
JSONArray publisherEnpoints = new JSONArray();
|
||||||
|
if (this.streaming && this.publisher.getEndpoint() != null) {
|
||||||
|
publisherEnpoints.add(this.publisher.toJSON());
|
||||||
|
}
|
||||||
|
JSONArray subscriberEndpoints = new JSONArray();
|
||||||
|
for (MediaEndpoint sub : this.subscribers.values()) {
|
||||||
|
if (sub.getEndpoint() != null) {
|
||||||
|
subscriberEndpoints.add(sub.toJSON());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
json.put("publishers", publisherEnpoints);
|
||||||
|
json.put("subscribers", subscriberEndpoints);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPublisherStremId() {
|
||||||
|
return this.publisher.getEndpoint().getTag("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
import org.kurento.client.Continuation;
|
import org.kurento.client.Continuation;
|
||||||
import org.kurento.client.ErrorEvent;
|
import org.kurento.client.ErrorEvent;
|
||||||
import org.kurento.client.EventListener;
|
import org.kurento.client.EventListener;
|
||||||
|
@ -347,4 +349,23 @@ public class KurentoSession implements Session {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public JSONObject toJSON() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("sessionId", this.sessionId);
|
||||||
|
json.put("mediaMode", this.sessionProperties.mediaMode().name());
|
||||||
|
json.put("recordingMode", this.sessionProperties.recordingMode().name());
|
||||||
|
json.put("defaultRecordingLayout", this.sessionProperties.defaultRecordingLayout().name());
|
||||||
|
if (this.sessionProperties.defaultCustomLayout() != null && !this.sessionProperties.defaultCustomLayout().isEmpty()) {
|
||||||
|
json.put("defaultCustomLayout", this.sessionProperties.defaultCustomLayout());
|
||||||
|
}
|
||||||
|
JSONArray participants = new JSONArray();
|
||||||
|
this.participants.values().forEach(p -> {
|
||||||
|
participants.add(p.toJSON());
|
||||||
|
});
|
||||||
|
json.put("connections", participants);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -248,7 +248,7 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
OpenViduException e = new OpenViduException(Code.MEDIA_SDP_ERROR_CODE,
|
OpenViduException e = new OpenViduException(Code.MEDIA_SDP_ERROR_CODE,
|
||||||
"Error generating SDP response for publishing user " + participant.getParticipantPublicId());
|
"Error generating SDP response for publishing user " + participant.getParticipantPublicId());
|
||||||
log.error("PARTICIPANT {}: Error publishing media", participant.getParticipantPublicId(), e);
|
log.error("PARTICIPANT {}: Error publishing media", participant.getParticipantPublicId(), e);
|
||||||
sessionEventsHandler.onPublishMedia(participant, session.getSessionId(), mediaOptions, sdpAnswer,
|
sessionEventsHandler.onPublishMedia(participant, null, session.getSessionId(), mediaOptions, sdpAnswer,
|
||||||
participants, transactionId, e);
|
participants, transactionId, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
participants = kurentoParticipant.getSession().getParticipants();
|
participants = kurentoParticipant.getSession().getParticipants();
|
||||||
|
|
||||||
if (sdpAnswer != null) {
|
if (sdpAnswer != null) {
|
||||||
sessionEventsHandler.onPublishMedia(participant, session.getSessionId(), mediaOptions, sdpAnswer,
|
sessionEventsHandler.onPublishMedia(participant, participant.getPublisherStremId(), session.getSessionId(), mediaOptions, sdpAnswer,
|
||||||
participants, transactionId, null);
|
participants, transactionId, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
import org.kurento.client.Continuation;
|
import org.kurento.client.Continuation;
|
||||||
import org.kurento.client.ErrorEvent;
|
import org.kurento.client.ErrorEvent;
|
||||||
import org.kurento.client.EventListener;
|
import org.kurento.client.EventListener;
|
||||||
|
@ -44,9 +45,10 @@ import io.openvidu.server.kurento.MutedMediaType;
|
||||||
import io.openvidu.server.kurento.core.KurentoParticipant;
|
import io.openvidu.server.kurento.core.KurentoParticipant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link WebRtcEndpoint} wrapper that supports buffering of {@link IceCandidate}s until the
|
* {@link WebRtcEndpoint} wrapper that supports buffering of
|
||||||
* {@link WebRtcEndpoint} is created. Connections to other peers are opened using the corresponding
|
* {@link IceCandidate}s until the {@link WebRtcEndpoint} is created.
|
||||||
* method of the internal endpoint.
|
* Connections to other peers are opened using the corresponding method of the
|
||||||
|
* internal endpoint.
|
||||||
*
|
*
|
||||||
* @author Pablo Fuente (pablofuenteperez@gmail.com)
|
* @author Pablo Fuente (pablofuenteperez@gmail.com)
|
||||||
*/
|
*/
|
||||||
|
@ -71,6 +73,9 @@ public abstract class MediaEndpoint {
|
||||||
public Map<String, MediaObject> flowInMedia = new ConcurrentHashMap<>();
|
public Map<String, MediaObject> flowInMedia = new ConcurrentHashMap<>();
|
||||||
public Map<String, MediaObject> flowOutMedia = new ConcurrentHashMap<>();
|
public Map<String, MediaObject> flowOutMedia = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public String selectedLocalIceCandidate;
|
||||||
|
public String selectedRemoteIceCandidate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to set the owner, the endpoint's name and the media pipeline.
|
* Constructor to set the owner, the endpoint's name and the media pipeline.
|
||||||
*
|
*
|
||||||
|
@ -80,8 +85,8 @@ public abstract class MediaEndpoint {
|
||||||
* @param pipeline
|
* @param pipeline
|
||||||
* @param log
|
* @param log
|
||||||
*/
|
*/
|
||||||
public MediaEndpoint(boolean web, KurentoParticipant owner, String endpointName,
|
public MediaEndpoint(boolean web, KurentoParticipant owner, String endpointName, MediaPipeline pipeline,
|
||||||
MediaPipeline pipeline, Logger log) {
|
Logger log) {
|
||||||
if (log == null) {
|
if (log == null) {
|
||||||
MediaEndpoint.log = LoggerFactory.getLogger(MediaEndpoint.class);
|
MediaEndpoint.log = LoggerFactory.getLogger(MediaEndpoint.class);
|
||||||
} else {
|
} else {
|
||||||
|
@ -124,13 +129,14 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this object doesn't have a {@link WebRtcEndpoint}, it is created in a thread-safe way using
|
* If this object doesn't have a {@link WebRtcEndpoint}, it is created in a
|
||||||
* the internal {@link MediaPipeline}. Otherwise no actions are taken. It also registers an error
|
* thread-safe way using the internal {@link MediaPipeline}. Otherwise no
|
||||||
* listener for the endpoint and for any additional media elements.
|
* actions are taken. It also registers an error listener for the endpoint and
|
||||||
|
* for any additional media elements.
|
||||||
*
|
*
|
||||||
* @param endpointLatch
|
* @param endpointLatch
|
||||||
* latch whose countdown is performed when the asynchronous call to build the
|
* latch whose countdown is performed when the asynchronous call to
|
||||||
* {@link WebRtcEndpoint} returns
|
* build the {@link WebRtcEndpoint} returns
|
||||||
*
|
*
|
||||||
* @return the existing endpoint, if any
|
* @return the existing endpoint, if any
|
||||||
*/
|
*/
|
||||||
|
@ -157,7 +163,8 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the {@link MediaPipeline} used to create the internal {@link WebRtcEndpoint}.
|
* Sets the {@link MediaPipeline} used to create the internal
|
||||||
|
* {@link WebRtcEndpoint}.
|
||||||
*
|
*
|
||||||
* @param pipeline
|
* @param pipeline
|
||||||
* the {@link MediaPipeline}
|
* the {@link MediaPipeline}
|
||||||
|
@ -184,7 +191,8 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters all error listeners created for media elements owned by this instance.
|
* Unregisters all error listeners created for media elements owned by this
|
||||||
|
* instance.
|
||||||
*/
|
*/
|
||||||
public synchronized void unregisterErrorListeners() {
|
public synchronized void unregisterErrorListeners() {
|
||||||
unregisterElementErrListener(endpoint, endpointSubscription);
|
unregisterElementErrListener(endpoint, endpointSubscription);
|
||||||
|
@ -235,16 +243,17 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the endpoint (RTP or WebRTC) and any other additional elements (if needed).
|
* Creates the endpoint (RTP or WebRTC) and any other additional elements (if
|
||||||
|
* needed).
|
||||||
*
|
*
|
||||||
* @param endpointLatch
|
* @param endpointLatch
|
||||||
*/
|
*/
|
||||||
protected void internalEndpointInitialization(final CountDownLatch endpointLatch) {
|
protected void internalEndpointInitialization(final CountDownLatch endpointLatch) {
|
||||||
if (this.isWeb()) {
|
if (this.isWeb()) {
|
||||||
WebRtcEndpoint.Builder builder = new WebRtcEndpoint.Builder(pipeline);
|
WebRtcEndpoint.Builder builder = new WebRtcEndpoint.Builder(pipeline);
|
||||||
/*if (this.dataChannels) {
|
/*
|
||||||
builder.useDataChannels();
|
* if (this.dataChannels) { builder.useDataChannels(); }
|
||||||
}*/
|
*/
|
||||||
builder.buildAsync(new Continuation<WebRtcEndpoint>() {
|
builder.buildAsync(new Continuation<WebRtcEndpoint>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(WebRtcEndpoint result) throws Exception {
|
public void onSuccess(WebRtcEndpoint result) throws Exception {
|
||||||
|
@ -304,12 +313,13 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a listener for when the {@link MediaElement} triggers an {@link ErrorEvent}. Notifies
|
* Registers a listener for when the {@link MediaElement} triggers an
|
||||||
* the owner with the error.
|
* {@link ErrorEvent}. Notifies the owner with the error.
|
||||||
*
|
*
|
||||||
* @param element
|
* @param element
|
||||||
* the {@link MediaElement}
|
* the {@link MediaElement}
|
||||||
* @return {@link ListenerSubscription} that can be used to deregister the listener
|
* @return {@link ListenerSubscription} that can be used to deregister the
|
||||||
|
* listener
|
||||||
*/
|
*/
|
||||||
protected ListenerSubscription registerElemErrListener(MediaElement element) {
|
protected ListenerSubscription registerElemErrListener(MediaElement element) {
|
||||||
return element.addErrorListener(new EventListener<ErrorEvent>() {
|
return element.addErrorListener(new EventListener<ErrorEvent>() {
|
||||||
|
@ -321,15 +331,15 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters the error listener from the media element using the provided subscription.
|
* Unregisters the error listener from the media element using the provided
|
||||||
|
* subscription.
|
||||||
*
|
*
|
||||||
* @param element
|
* @param element
|
||||||
* the {@link MediaElement}
|
* the {@link MediaElement}
|
||||||
* @param subscription
|
* @param subscription
|
||||||
* the associated {@link ListenerSubscription}
|
* the associated {@link ListenerSubscription}
|
||||||
*/
|
*/
|
||||||
protected void unregisterElementErrListener(MediaElement element,
|
protected void unregisterElementErrListener(MediaElement element, final ListenerSubscription subscription) {
|
||||||
final ListenerSubscription subscription) {
|
|
||||||
if (element == null || subscription == null) {
|
if (element == null || subscription == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -337,8 +347,8 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Orders the internal endpoint ({@link RtpEndpoint} or {@link WebRtcEndpoint}) to process the
|
* Orders the internal endpoint ({@link RtpEndpoint} or {@link WebRtcEndpoint})
|
||||||
* offer String.
|
* to process the offer String.
|
||||||
*
|
*
|
||||||
* @see SdpEndpoint#processOffer(String)
|
* @see SdpEndpoint#processOffer(String)
|
||||||
* @param offer
|
* @param offer
|
||||||
|
@ -362,8 +372,8 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Orders the internal endpoint ({@link RtpEndpoint} or {@link WebRtcEndpoint}) to generate the
|
* Orders the internal endpoint ({@link RtpEndpoint} or {@link WebRtcEndpoint})
|
||||||
* offer String that can be used to initiate a connection.
|
* to generate the offer String that can be used to initiate a connection.
|
||||||
*
|
*
|
||||||
* @see SdpEndpoint#generateOffer()
|
* @see SdpEndpoint#generateOffer()
|
||||||
* @return the Sdp offer
|
* @return the Sdp offer
|
||||||
|
@ -385,8 +395,8 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Orders the internal endpoint ({@link RtpEndpoint} or {@link WebRtcEndpoint}) to process the
|
* Orders the internal endpoint ({@link RtpEndpoint} or {@link WebRtcEndpoint})
|
||||||
* answer String.
|
* to process the answer String.
|
||||||
*
|
*
|
||||||
* @see SdpEndpoint#processAnswer(String)
|
* @see SdpEndpoint#processAnswer(String)
|
||||||
* @param answer
|
* @param answer
|
||||||
|
@ -410,9 +420,10 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If supported, it registers a listener for when a new {@link IceCandidate} is gathered by the
|
* If supported, it registers a listener for when a new {@link IceCandidate} is
|
||||||
* internal endpoint ({@link WebRtcEndpoint}) and sends it to the remote User Agent as a
|
* gathered by the internal endpoint ({@link WebRtcEndpoint}) and sends it to
|
||||||
* notification using the messaging capabilities of the {@link Participant}.
|
* the remote User Agent as a notification using the messaging capabilities of
|
||||||
|
* the {@link Participant}.
|
||||||
*
|
*
|
||||||
* @see WebRtcEndpoint#addOnIceCandidateListener(org.kurento.client.EventListener)
|
* @see WebRtcEndpoint#addOnIceCandidateListener(org.kurento.client.EventListener)
|
||||||
* @see Participant#sendIceCandidate(String, IceCandidate)
|
* @see Participant#sendIceCandidate(String, IceCandidate)
|
||||||
|
@ -436,7 +447,8 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If supported, it instructs the internal endpoint to start gathering {@link IceCandidate}s.
|
* If supported, it instructs the internal endpoint to start gathering
|
||||||
|
* {@link IceCandidate}s.
|
||||||
*/
|
*/
|
||||||
protected void gatherCandidates() throws OpenViduException {
|
protected void gatherCandidates() throws OpenViduException {
|
||||||
if (!this.isWeb()) {
|
if (!this.isWeb()) {
|
||||||
|
@ -454,8 +466,7 @@ public abstract class MediaEndpoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Throwable cause) throws Exception {
|
public void onError(Throwable cause) throws Exception {
|
||||||
log.warn("EP {}: Internal endpoint failed to start gathering candidates", endpointName,
|
log.warn("EP {}: Internal endpoint failed to start gathering candidates", endpointName, cause);
|
||||||
cause);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -477,4 +488,13 @@ public abstract class MediaEndpoint {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public JSONObject toJSON() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("webrtcTagName", this.getEndpoint().getTag("name"));
|
||||||
|
json.put("localCandidate", this.selectedLocalIceCandidate);
|
||||||
|
json.put("remoteCandidate", this.selectedRemoteIceCandidate);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ public class ComposedRecordingService {
|
||||||
envs.add("RECORDING_JSON=" + recording.toJson().toJSONString());
|
envs.add("RECORDING_JSON=" + recording.toJson().toJSONString());
|
||||||
|
|
||||||
log.info(recording.toJson().toJSONString());
|
log.info(recording.toJson().toJSONString());
|
||||||
log.debug("Recorder connecting to url {}", layoutUrl);
|
log.info("Recorder connecting to url {}", layoutUrl);
|
||||||
|
|
||||||
String containerId = this.runRecordingContainer(envs, "recording_" + recordingId);
|
String containerId = this.runRecordingContainer(envs, "recording_" + recordingId);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import io.openvidu.server.config.OpenviduConfig;
|
||||||
* @author Pablo Fuente Pérez
|
* @author Pablo Fuente Pérez
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*")
|
@CrossOrigin
|
||||||
@RequestMapping("/config")
|
@RequestMapping("/config")
|
||||||
public class ConfigRestController {
|
public class ConfigRestController {
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ package io.openvidu.server.rest;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
|
@ -54,7 +53,7 @@ import io.openvidu.server.recording.ComposedRecordingService;
|
||||||
* @author Pablo Fuente Pérez
|
* @author Pablo Fuente Pérez
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin(origins = "*")
|
@CrossOrigin
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
public class SessionRestController {
|
public class SessionRestController {
|
||||||
|
|
||||||
|
@ -67,11 +66,6 @@ public class SessionRestController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private OpenviduConfig openviduConfig;
|
private OpenviduConfig openviduConfig;
|
||||||
|
|
||||||
@RequestMapping(value = "/sessions", method = RequestMethod.GET)
|
|
||||||
public Set<String> getAllSessions() {
|
|
||||||
return sessionManager.getSessions();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@RequestMapping(value = "/sessions", method = RequestMethod.POST)
|
@RequestMapping(value = "/sessions", method = RequestMethod.POST)
|
||||||
public ResponseEntity<JSONObject> getSessionId(@RequestBody(required = false) Map<?, ?> params) {
|
public ResponseEntity<JSONObject> getSessionId(@RequestBody(required = false) Map<?, ?> params) {
|
||||||
|
@ -136,9 +130,34 @@ public class SessionRestController {
|
||||||
sessionManager.storeSessionId(sessionId, sessionProperties);
|
sessionManager.storeSessionId(sessionId, sessionProperties);
|
||||||
JSONObject responseJson = new JSONObject();
|
JSONObject responseJson = new JSONObject();
|
||||||
responseJson.put("id", sessionId);
|
responseJson.put("id", sessionId);
|
||||||
|
|
||||||
return new ResponseEntity<>(responseJson, HttpStatus.OK);
|
return new ResponseEntity<>(responseJson, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)
|
||||||
|
public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String sessionId) {
|
||||||
|
Session session = this.sessionManager.getSession(sessionId);
|
||||||
|
if (session != null) {
|
||||||
|
return new ResponseEntity<>(session.toJSON(), HttpStatus.OK);
|
||||||
|
} else {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
@RequestMapping(value = "/sessions", method = RequestMethod.GET)
|
||||||
|
public ResponseEntity<JSONObject> listSessions() {
|
||||||
|
Collection<Session> sessions = this.sessionManager.getSessionObjects();
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
|
sessions.forEach(s -> {
|
||||||
|
jsonArray.add(s.toJSON());
|
||||||
|
});
|
||||||
|
json.put("count", sessions.size());
|
||||||
|
json.put("items", jsonArray);
|
||||||
|
return new ResponseEntity<>(json, HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@RequestMapping(value = "/tokens", method = RequestMethod.POST)
|
@RequestMapping(value = "/tokens", method = RequestMethod.POST)
|
||||||
public ResponseEntity<JSONObject> newToken(@RequestBody Map<?, ?> params) {
|
public ResponseEntity<JSONObject> newToken(@RequestBody Map<?, ?> params) {
|
||||||
|
|
|
@ -54,7 +54,8 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
|
||||||
@Autowired
|
@Autowired
|
||||||
RpcNotificationService notificationService;
|
RpcNotificationService notificationService;
|
||||||
|
|
||||||
private ConcurrentMap<String, Boolean> webSocketTransportError = new ConcurrentHashMap<>();
|
private ConcurrentMap<String, Boolean> webSocketEOFTransportError = new ConcurrentHashMap<>();
|
||||||
|
// private ConcurrentMap<String, Boolean> webSocketBrokenPipeTransportError = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(Transaction transaction, Request<JsonObject> request) throws Exception {
|
public void handleRequest(Transaction transaction, Request<JsonObject> request) throws Exception {
|
||||||
|
@ -301,23 +302,37 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
|
||||||
public void afterConnectionClosed(Session rpcSession, String status) throws Exception {
|
public void afterConnectionClosed(Session rpcSession, String status) throws Exception {
|
||||||
log.info("After connection closed for WebSocket session: {} - Status: {}", rpcSession.getSessionId(), status);
|
log.info("After connection closed for WebSocket session: {} - Status: {}", rpcSession.getSessionId(), status);
|
||||||
|
|
||||||
|
String rpcSessionId = rpcSession.getSessionId();
|
||||||
|
String message = "";
|
||||||
|
|
||||||
if ("Close for not receive ping from client".equals(status)) {
|
if ("Close for not receive ping from client".equals(status)) {
|
||||||
RpcConnection rpc = this.notificationService.closeRpcSession(rpcSession.getSessionId());
|
message = "Evicting participant with private id {} because of a network disconnection";
|
||||||
|
} else if (status == null) { // && this.webSocketBrokenPipeTransportError.remove(rpcSessionId) != null)) {
|
||||||
|
try {
|
||||||
|
Participant p = sessionManager.getParticipant(rpcSession.getSessionId());
|
||||||
|
if (p != null) {
|
||||||
|
message = "Evicting participant with private id {} because its websocket unexpectedly closed in the client side";
|
||||||
|
}
|
||||||
|
} catch (OpenViduException exception) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!message.isEmpty()) {
|
||||||
|
RpcConnection rpc = this.notificationService.closeRpcSession(rpcSessionId);
|
||||||
if (rpc != null && rpc.getSessionId() != null) {
|
if (rpc != null && rpc.getSessionId() != null) {
|
||||||
io.openvidu.server.core.Session session = this.sessionManager.getSession(rpc.getSessionId());
|
io.openvidu.server.core.Session session = this.sessionManager.getSession(rpc.getSessionId());
|
||||||
if (session != null && session.getParticipantByPrivateId(rpc.getParticipantPrivateId()) != null) {
|
if (session != null && session.getParticipantByPrivateId(rpc.getParticipantPrivateId()) != null) {
|
||||||
|
log.info(message, rpc.getParticipantPrivateId());
|
||||||
leaveRoomAfterConnClosed(rpc.getParticipantPrivateId(), "networkDisconnect");
|
leaveRoomAfterConnClosed(rpc.getParticipantPrivateId(), "networkDisconnect");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String rpcSessionId = rpcSession.getSessionId();
|
if (this.webSocketEOFTransportError.remove(rpcSessionId) != null) {
|
||||||
if (this.webSocketTransportError.get(rpcSessionId) != null) {
|
|
||||||
log.warn(
|
log.warn(
|
||||||
"Evicting participant with private id {} because a transport error took place and its web socket connection is now closed",
|
"Evicting participant with private id {} because a transport error took place and its web socket connection is now closed",
|
||||||
rpcSession.getSessionId());
|
rpcSession.getSessionId());
|
||||||
this.leaveRoomAfterConnClosed(rpcSessionId, "networkDisconnect");
|
this.leaveRoomAfterConnClosed(rpcSessionId, "networkDisconnect");
|
||||||
this.webSocketTransportError.remove(rpcSessionId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -325,10 +340,15 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
|
||||||
public void handleTransportError(Session rpcSession, Throwable exception) throws Exception {
|
public void handleTransportError(Session rpcSession, Throwable exception) throws Exception {
|
||||||
log.error("Transport exception for WebSocket session: {} - Exception: {}", rpcSession.getSessionId(),
|
log.error("Transport exception for WebSocket session: {} - Exception: {}", rpcSession.getSessionId(),
|
||||||
exception);
|
exception);
|
||||||
|
if ("IOException".equals(exception.getClass().getSimpleName())
|
||||||
|
&& "Broken pipe".equals(exception.getCause().getMessage())) {
|
||||||
|
log.warn("Parcipant with private id {} unexpectedly closed the websocket", rpcSession.getSessionId());
|
||||||
|
// this.webSocketBrokenPipeTransportError.put(rpcSession.getSessionId(), true);
|
||||||
|
}
|
||||||
if ("EOFException".equals(exception.getClass().getSimpleName())) {
|
if ("EOFException".equals(exception.getClass().getSimpleName())) {
|
||||||
// Store WebSocket connection interrupted exception for this web socket to
|
// Store WebSocket connection interrupted exception for this web socket to
|
||||||
// automatically evict the participant on "afterConnectionClosed" event
|
// automatically evict the participant on "afterConnectionClosed" event
|
||||||
this.webSocketTransportError.put(rpcSession.getSessionId(), true);
|
this.webSocketEOFTransportError.put(rpcSession.getSessionId(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue