openvidu-server: allow posting an IPCAM as first participant of session

pull/370/head
pabloFuente 2019-10-30 11:01:07 +01:00
parent 6ac4082613
commit 407b710d10
8 changed files with 35 additions and 31 deletions

View File

@ -19,6 +19,7 @@ package io.openvidu.server.core;
import com.google.gson.JsonObject;
import io.openvidu.server.kurento.endpoint.EndpointType;
import io.openvidu.server.utils.GeoLocation;
public class Participant {
@ -33,6 +34,7 @@ public class Participant {
protected Token token; // Token associated to this participant
protected GeoLocation location; // Location of the participant
protected String platform; // Platform used by the participant to connect to the session
protected EndpointType endpointType; // Type of participant (web participant, IP cam participant...)
protected boolean streaming = false;
protected volatile boolean closed;
@ -40,7 +42,8 @@ public class Participant {
private final String METADATA_SEPARATOR = "%/%";
public Participant(String finalUserId, String participantPrivatetId, String participantPublicId, String sessionId,
Token token, String clientMetadata, GeoLocation location, String platform, Long createdAt) {
Token token, String clientMetadata, GeoLocation location, String platform, EndpointType endpointType,
Long createdAt) {
this.finalUserId = finalUserId;
this.participantPrivatetId = participantPrivatetId;
this.participantPublicId = participantPublicId;
@ -59,6 +62,7 @@ public class Participant {
}
this.location = location;
this.platform = platform;
this.endpointType = endpointType;
}
public String getFinalUserId() {
@ -129,6 +133,10 @@ public class Participant {
this.platform = platform;
}
public EndpointType getEndpointType() {
return this.endpointType;
}
public boolean isStreaming() {
return streaming;
}

View File

@ -36,7 +36,6 @@ import io.openvidu.java.client.RecordingLayout;
import io.openvidu.java.client.SessionProperties;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.kurento.core.KurentoParticipant;
import io.openvidu.server.kurento.endpoint.EndpointType;
import io.openvidu.server.recording.service.RecordingManager;
public class Session implements SessionInterface {
@ -168,7 +167,7 @@ public class Session implements SessionInterface {
}
@Override
public void join(Participant participant, EndpointType endpointType) {
public void join(Participant participant) {
}
@Override

View File

@ -22,7 +22,6 @@ import java.util.Set;
import com.google.gson.JsonObject;
import io.openvidu.java.client.SessionProperties;
import io.openvidu.server.kurento.endpoint.EndpointType;
public interface SessionInterface {
@ -30,7 +29,7 @@ public interface SessionInterface {
SessionProperties getSessionProperties();
void join(Participant participant, EndpointType endpointType);
void join(Participant participant);
void leave(String participantPrivateId, EndReason reason);

View File

@ -48,6 +48,7 @@ import io.openvidu.server.cdr.CDREventRecording;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.coturn.CoturnCredentialsService;
import io.openvidu.server.kurento.core.KurentoTokenOptions;
import io.openvidu.server.kurento.endpoint.EndpointType;
import io.openvidu.server.recording.service.RecordingManager;
import io.openvidu.server.utils.FormatChecker;
import io.openvidu.server.utils.GeoLocation;
@ -367,7 +368,7 @@ public abstract class SessionManager {
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
String participantPublicId = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
Participant p = new Participant(finalUserId, participantPrivatetId, participantPublicId, sessionId, token,
clientMetadata, location, platform, null);
clientMetadata, location, platform, EndpointType.WEBRTC_ENDPOINT, null);
while (this.sessionidParticipantpublicidParticipant.get(sessionId).putIfAbsent(participantPublicId,
p) != null) {
participantPublicId = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
@ -390,7 +391,7 @@ public abstract class SessionManager {
String clientMetadata) {
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
Participant p = new Participant(null, participantPrivatetId, ProtocolElements.RECORDER_PARTICIPANT_PUBLICID,
sessionId, token, clientMetadata, null, null, null);
sessionId, token, clientMetadata, null, null, EndpointType.WEBRTC_ENDPOINT, null);
this.sessionidParticipantpublicidParticipant.get(sessionId)
.put(ProtocolElements.RECORDER_PARTICIPANT_PUBLICID, p);
return p;
@ -399,9 +400,11 @@ public abstract class SessionManager {
}
}
public Participant newIpcamParticipant(String sessionId, String ipcamId, Token token, GeoLocation location, String platform) {
public Participant newIpcamParticipant(String sessionId, String ipcamId, Token token, GeoLocation location,
String platform) {
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
Participant p = new Participant(ipcamId, ipcamId, ipcamId, sessionId, token, null, location, platform, null);
Participant p = new Participant(ipcamId, ipcamId, ipcamId, sessionId, token, null, location, platform,
EndpointType.PLAYER_ENDPOINT, null);
this.sessionidParticipantpublicidParticipant.get(sessionId).put(ipcamId, p);
return p;
} else {

View File

@ -47,7 +47,6 @@ import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.EndReason;
import io.openvidu.server.core.MediaOptions;
import io.openvidu.server.core.Participant;
import io.openvidu.server.kurento.endpoint.EndpointType;
import io.openvidu.server.kurento.endpoint.MediaEndpoint;
import io.openvidu.server.kurento.endpoint.PublisherEndpoint;
import io.openvidu.server.kurento.endpoint.SdpType;
@ -61,8 +60,6 @@ public class KurentoParticipant extends Participant {
private OpenviduConfig openviduConfig;
private RecordingManager recordingManager;
private EndpointType endpointType;
private final KurentoSession session;
private KurentoParticipantEndpointConfig endpointConfig;
@ -72,13 +69,13 @@ public class KurentoParticipant extends Participant {
private final ConcurrentMap<String, Filter> filters = new ConcurrentHashMap<>();
private final ConcurrentMap<String, SubscriberEndpoint> subscribers = new ConcurrentHashMap<String, SubscriberEndpoint>();
public KurentoParticipant(Participant participant, KurentoSession kurentoSession, EndpointType endpointType,
public KurentoParticipant(Participant participant, KurentoSession kurentoSession,
KurentoParticipantEndpointConfig endpointConfig, OpenviduConfig openviduConfig,
RecordingManager recordingManager) {
super(participant.getFinalUserId(), participant.getParticipantPrivateId(), participant.getParticipantPublicId(),
kurentoSession.getSessionId(), participant.getToken(), participant.getClientMetadata(),
participant.getLocation(), participant.getPlatform(), participant.getCreatedAt());
this.endpointType = endpointType;
participant.getLocation(), participant.getPlatform(), participant.getEndpointType(),
participant.getCreatedAt());
this.endpointConfig = endpointConfig;
this.openviduConfig = openviduConfig;
this.recordingManager = recordingManager;

View File

@ -36,7 +36,6 @@ import io.openvidu.java.client.OpenViduRole;
import io.openvidu.server.core.EndReason;
import io.openvidu.server.core.Participant;
import io.openvidu.server.core.Session;
import io.openvidu.server.kurento.endpoint.EndpointType;
import io.openvidu.server.kurento.kms.Kms;
/**
@ -70,12 +69,12 @@ public class KurentoSession extends Session {
}
@Override
public void join(Participant participant, EndpointType endpointType) {
public void join(Participant participant) {
checkClosed();
createPipeline();
KurentoParticipant kurentoParticipant = new KurentoParticipant(participant, this, endpointType,
this.kurentoEndpointConfig, this.openviduConfig, this.recordingManager);
KurentoParticipant kurentoParticipant = new KurentoParticipant(participant, this, this.kurentoEndpointConfig,
this.openviduConfig, this.recordingManager);
participants.put(participant.getParticipantPrivateId(), kurentoParticipant);
log.info("SESSION {}: Added participant {}", sessionId, participant);

View File

@ -57,7 +57,6 @@ import io.openvidu.server.core.Participant;
import io.openvidu.server.core.Session;
import io.openvidu.server.core.SessionManager;
import io.openvidu.server.core.Token;
import io.openvidu.server.kurento.endpoint.EndpointType;
import io.openvidu.server.kurento.endpoint.KurentoFilter;
import io.openvidu.server.kurento.endpoint.PublisherEndpoint;
import io.openvidu.server.kurento.endpoint.SdpType;
@ -122,7 +121,7 @@ public class KurentoSessionManager extends SessionManager {
}
existingParticipants = getParticipants(sessionId);
kSession.join(participant, EndpointType.WEBRTC_ENDPOINT);
kSession.join(participant);
} catch (OpenViduException e) {
log.warn("PARTICIPANT {}: Error joining/creating session {}", participant.getParticipantPublicId(),
sessionId, e);
@ -849,8 +848,8 @@ public class KurentoSessionManager extends SessionManager {
@Override
public Participant publishIpcam(Session session, MediaOptions mediaOptions) throws Exception {
KurentoSession kSession = (KurentoSession) session;
KurentoMediaOptions kMediaOptions = (KurentoMediaOptions) mediaOptions;
final String sessionId = session.getSessionId();
final KurentoMediaOptions kMediaOptions = (KurentoMediaOptions) mediaOptions;
// Generate the location for the IpCam
GeoLocation location = null;
@ -888,20 +887,20 @@ public class KurentoSessionManager extends SessionManager {
this.newInsecureParticipant(rtspConnectionId);
String token = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
Token tokenObj = null;
if (this.isTokenValidInSession(token, session.getSessionId(), rtspConnectionId)) {
tokenObj = this.consumeToken(session.getSessionId(), rtspConnectionId, token);
if (this.isTokenValidInSession(token, sessionId, rtspConnectionId)) {
tokenObj = this.consumeToken(sessionId, rtspConnectionId, token);
}
Participant ipcamParticipant = this.newIpcamParticipant(session.getSessionId(), rtspConnectionId, tokenObj,
location, mediaOptions.getTypeOfVideo());
Participant ipcamParticipant = this.newIpcamParticipant(sessionId, rtspConnectionId, tokenObj, location,
mediaOptions.getTypeOfVideo());
// Store a "fake" final user for the IpCam connection
final String finalUserId = rtspConnectionId;
this.sessionidFinalUsers.get(session.getSessionId()).computeIfAbsent(finalUserId, k -> {
return new FinalUser(finalUserId, session.getSessionId(), ipcamParticipant);
this.sessionidFinalUsers.get(sessionId).computeIfAbsent(finalUserId, k -> {
return new FinalUser(finalUserId, sessionId, ipcamParticipant);
}).addConnectionIfAbsent(ipcamParticipant);
// Join the participant to the session
kSession.join(ipcamParticipant, EndpointType.PLAYER_ENDPOINT);
this.joinRoom(ipcamParticipant, sessionId, null);
// Publish the IpCam stream into the session
KurentoParticipant kParticipant = (KurentoParticipant) this.getParticipant(rtspConnectionId);

View File

@ -674,7 +674,7 @@ public class SessionRestController {
log.info("REST API: POST /api/sessions/{}/connection {}", sessionId, params.toString());
Session session = this.sessionManager.getSession(sessionId);
Session session = this.sessionManager.getSessionWithNotActive(sessionId);
if (session == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}