mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: allow posting an IPCAM as first participant of session
parent
6ac4082613
commit
407b710d10
|
@ -19,6 +19,7 @@ package io.openvidu.server.core;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
|
import io.openvidu.server.kurento.endpoint.EndpointType;
|
||||||
import io.openvidu.server.utils.GeoLocation;
|
import io.openvidu.server.utils.GeoLocation;
|
||||||
|
|
||||||
public class Participant {
|
public class Participant {
|
||||||
|
@ -33,6 +34,7 @@ public class Participant {
|
||||||
protected Token token; // Token associated to this participant
|
protected Token token; // Token associated to this participant
|
||||||
protected GeoLocation location; // Location of the participant
|
protected GeoLocation location; // Location of the participant
|
||||||
protected String platform; // Platform used by the participant to connect to the session
|
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 boolean streaming = false;
|
||||||
protected volatile boolean closed;
|
protected volatile boolean closed;
|
||||||
|
@ -40,7 +42,8 @@ public class Participant {
|
||||||
private final String METADATA_SEPARATOR = "%/%";
|
private final String METADATA_SEPARATOR = "%/%";
|
||||||
|
|
||||||
public Participant(String finalUserId, String participantPrivatetId, String participantPublicId, String sessionId,
|
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.finalUserId = finalUserId;
|
||||||
this.participantPrivatetId = participantPrivatetId;
|
this.participantPrivatetId = participantPrivatetId;
|
||||||
this.participantPublicId = participantPublicId;
|
this.participantPublicId = participantPublicId;
|
||||||
|
@ -59,6 +62,7 @@ public class Participant {
|
||||||
}
|
}
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
|
this.endpointType = endpointType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFinalUserId() {
|
public String getFinalUserId() {
|
||||||
|
@ -129,6 +133,10 @@ public class Participant {
|
||||||
this.platform = platform;
|
this.platform = platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EndpointType getEndpointType() {
|
||||||
|
return this.endpointType;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isStreaming() {
|
public boolean isStreaming() {
|
||||||
return streaming;
|
return streaming;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,6 @@ import io.openvidu.java.client.RecordingLayout;
|
||||||
import io.openvidu.java.client.SessionProperties;
|
import io.openvidu.java.client.SessionProperties;
|
||||||
import io.openvidu.server.config.OpenviduConfig;
|
import io.openvidu.server.config.OpenviduConfig;
|
||||||
import io.openvidu.server.kurento.core.KurentoParticipant;
|
import io.openvidu.server.kurento.core.KurentoParticipant;
|
||||||
import io.openvidu.server.kurento.endpoint.EndpointType;
|
|
||||||
import io.openvidu.server.recording.service.RecordingManager;
|
import io.openvidu.server.recording.service.RecordingManager;
|
||||||
|
|
||||||
public class Session implements SessionInterface {
|
public class Session implements SessionInterface {
|
||||||
|
@ -168,7 +167,7 @@ public class Session implements SessionInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void join(Participant participant, EndpointType endpointType) {
|
public void join(Participant participant) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.Set;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
|
||||||
import io.openvidu.java.client.SessionProperties;
|
import io.openvidu.java.client.SessionProperties;
|
||||||
import io.openvidu.server.kurento.endpoint.EndpointType;
|
|
||||||
|
|
||||||
public interface SessionInterface {
|
public interface SessionInterface {
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ public interface SessionInterface {
|
||||||
|
|
||||||
SessionProperties getSessionProperties();
|
SessionProperties getSessionProperties();
|
||||||
|
|
||||||
void join(Participant participant, EndpointType endpointType);
|
void join(Participant participant);
|
||||||
|
|
||||||
void leave(String participantPrivateId, EndReason reason);
|
void leave(String participantPrivateId, EndReason reason);
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ import io.openvidu.server.cdr.CDREventRecording;
|
||||||
import io.openvidu.server.config.OpenviduConfig;
|
import io.openvidu.server.config.OpenviduConfig;
|
||||||
import io.openvidu.server.coturn.CoturnCredentialsService;
|
import io.openvidu.server.coturn.CoturnCredentialsService;
|
||||||
import io.openvidu.server.kurento.core.KurentoTokenOptions;
|
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.recording.service.RecordingManager;
|
||||||
import io.openvidu.server.utils.FormatChecker;
|
import io.openvidu.server.utils.FormatChecker;
|
||||||
import io.openvidu.server.utils.GeoLocation;
|
import io.openvidu.server.utils.GeoLocation;
|
||||||
|
@ -367,7 +368,7 @@ public abstract class SessionManager {
|
||||||
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
|
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
|
||||||
String participantPublicId = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
|
String participantPublicId = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
|
||||||
Participant p = new Participant(finalUserId, participantPrivatetId, participantPublicId, sessionId, token,
|
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,
|
while (this.sessionidParticipantpublicidParticipant.get(sessionId).putIfAbsent(participantPublicId,
|
||||||
p) != null) {
|
p) != null) {
|
||||||
participantPublicId = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
|
participantPublicId = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
|
||||||
|
@ -390,7 +391,7 @@ public abstract class SessionManager {
|
||||||
String clientMetadata) {
|
String clientMetadata) {
|
||||||
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
|
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
|
||||||
Participant p = new Participant(null, participantPrivatetId, ProtocolElements.RECORDER_PARTICIPANT_PUBLICID,
|
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)
|
this.sessionidParticipantpublicidParticipant.get(sessionId)
|
||||||
.put(ProtocolElements.RECORDER_PARTICIPANT_PUBLICID, p);
|
.put(ProtocolElements.RECORDER_PARTICIPANT_PUBLICID, p);
|
||||||
return 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) {
|
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);
|
this.sessionidParticipantpublicidParticipant.get(sessionId).put(ipcamId, p);
|
||||||
return p;
|
return p;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -47,7 +47,6 @@ import io.openvidu.server.config.OpenviduConfig;
|
||||||
import io.openvidu.server.core.EndReason;
|
import io.openvidu.server.core.EndReason;
|
||||||
import io.openvidu.server.core.MediaOptions;
|
import io.openvidu.server.core.MediaOptions;
|
||||||
import io.openvidu.server.core.Participant;
|
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.MediaEndpoint;
|
||||||
import io.openvidu.server.kurento.endpoint.PublisherEndpoint;
|
import io.openvidu.server.kurento.endpoint.PublisherEndpoint;
|
||||||
import io.openvidu.server.kurento.endpoint.SdpType;
|
import io.openvidu.server.kurento.endpoint.SdpType;
|
||||||
|
@ -61,8 +60,6 @@ public class KurentoParticipant extends Participant {
|
||||||
private OpenviduConfig openviduConfig;
|
private OpenviduConfig openviduConfig;
|
||||||
private RecordingManager recordingManager;
|
private RecordingManager recordingManager;
|
||||||
|
|
||||||
private EndpointType endpointType;
|
|
||||||
|
|
||||||
private final KurentoSession session;
|
private final KurentoSession session;
|
||||||
private KurentoParticipantEndpointConfig endpointConfig;
|
private KurentoParticipantEndpointConfig endpointConfig;
|
||||||
|
|
||||||
|
@ -72,13 +69,13 @@ public class KurentoParticipant extends Participant {
|
||||||
private final ConcurrentMap<String, Filter> filters = new ConcurrentHashMap<>();
|
private final ConcurrentMap<String, Filter> filters = new ConcurrentHashMap<>();
|
||||||
private final ConcurrentMap<String, SubscriberEndpoint> subscribers = new ConcurrentHashMap<String, SubscriberEndpoint>();
|
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,
|
KurentoParticipantEndpointConfig endpointConfig, OpenviduConfig openviduConfig,
|
||||||
RecordingManager recordingManager) {
|
RecordingManager recordingManager) {
|
||||||
super(participant.getFinalUserId(), participant.getParticipantPrivateId(), participant.getParticipantPublicId(),
|
super(participant.getFinalUserId(), participant.getParticipantPrivateId(), participant.getParticipantPublicId(),
|
||||||
kurentoSession.getSessionId(), participant.getToken(), participant.getClientMetadata(),
|
kurentoSession.getSessionId(), participant.getToken(), participant.getClientMetadata(),
|
||||||
participant.getLocation(), participant.getPlatform(), participant.getCreatedAt());
|
participant.getLocation(), participant.getPlatform(), participant.getEndpointType(),
|
||||||
this.endpointType = endpointType;
|
participant.getCreatedAt());
|
||||||
this.endpointConfig = endpointConfig;
|
this.endpointConfig = endpointConfig;
|
||||||
this.openviduConfig = openviduConfig;
|
this.openviduConfig = openviduConfig;
|
||||||
this.recordingManager = recordingManager;
|
this.recordingManager = recordingManager;
|
||||||
|
|
|
@ -36,7 +36,6 @@ import io.openvidu.java.client.OpenViduRole;
|
||||||
import io.openvidu.server.core.EndReason;
|
import io.openvidu.server.core.EndReason;
|
||||||
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.kurento.endpoint.EndpointType;
|
|
||||||
import io.openvidu.server.kurento.kms.Kms;
|
import io.openvidu.server.kurento.kms.Kms;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,12 +69,12 @@ public class KurentoSession extends Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void join(Participant participant, EndpointType endpointType) {
|
public void join(Participant participant) {
|
||||||
checkClosed();
|
checkClosed();
|
||||||
createPipeline();
|
createPipeline();
|
||||||
|
|
||||||
KurentoParticipant kurentoParticipant = new KurentoParticipant(participant, this, endpointType,
|
KurentoParticipant kurentoParticipant = new KurentoParticipant(participant, this, this.kurentoEndpointConfig,
|
||||||
this.kurentoEndpointConfig, this.openviduConfig, this.recordingManager);
|
this.openviduConfig, this.recordingManager);
|
||||||
participants.put(participant.getParticipantPrivateId(), kurentoParticipant);
|
participants.put(participant.getParticipantPrivateId(), kurentoParticipant);
|
||||||
|
|
||||||
log.info("SESSION {}: Added participant {}", sessionId, participant);
|
log.info("SESSION {}: Added participant {}", sessionId, participant);
|
||||||
|
|
|
@ -57,7 +57,6 @@ 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.core.Token;
|
||||||
import io.openvidu.server.kurento.endpoint.EndpointType;
|
|
||||||
import io.openvidu.server.kurento.endpoint.KurentoFilter;
|
import io.openvidu.server.kurento.endpoint.KurentoFilter;
|
||||||
import io.openvidu.server.kurento.endpoint.PublisherEndpoint;
|
import io.openvidu.server.kurento.endpoint.PublisherEndpoint;
|
||||||
import io.openvidu.server.kurento.endpoint.SdpType;
|
import io.openvidu.server.kurento.endpoint.SdpType;
|
||||||
|
@ -122,7 +121,7 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
existingParticipants = getParticipants(sessionId);
|
existingParticipants = getParticipants(sessionId);
|
||||||
kSession.join(participant, EndpointType.WEBRTC_ENDPOINT);
|
kSession.join(participant);
|
||||||
} catch (OpenViduException e) {
|
} catch (OpenViduException e) {
|
||||||
log.warn("PARTICIPANT {}: Error joining/creating session {}", participant.getParticipantPublicId(),
|
log.warn("PARTICIPANT {}: Error joining/creating session {}", participant.getParticipantPublicId(),
|
||||||
sessionId, e);
|
sessionId, e);
|
||||||
|
@ -849,8 +848,8 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Participant publishIpcam(Session session, MediaOptions mediaOptions) throws Exception {
|
public Participant publishIpcam(Session session, MediaOptions mediaOptions) throws Exception {
|
||||||
KurentoSession kSession = (KurentoSession) session;
|
final String sessionId = session.getSessionId();
|
||||||
KurentoMediaOptions kMediaOptions = (KurentoMediaOptions) mediaOptions;
|
final KurentoMediaOptions kMediaOptions = (KurentoMediaOptions) mediaOptions;
|
||||||
|
|
||||||
// Generate the location for the IpCam
|
// Generate the location for the IpCam
|
||||||
GeoLocation location = null;
|
GeoLocation location = null;
|
||||||
|
@ -888,20 +887,20 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
this.newInsecureParticipant(rtspConnectionId);
|
this.newInsecureParticipant(rtspConnectionId);
|
||||||
String token = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
|
String token = RandomStringUtils.randomAlphanumeric(16).toLowerCase();
|
||||||
Token tokenObj = null;
|
Token tokenObj = null;
|
||||||
if (this.isTokenValidInSession(token, session.getSessionId(), rtspConnectionId)) {
|
if (this.isTokenValidInSession(token, sessionId, rtspConnectionId)) {
|
||||||
tokenObj = this.consumeToken(session.getSessionId(), rtspConnectionId, token);
|
tokenObj = this.consumeToken(sessionId, rtspConnectionId, token);
|
||||||
}
|
}
|
||||||
Participant ipcamParticipant = this.newIpcamParticipant(session.getSessionId(), rtspConnectionId, tokenObj,
|
Participant ipcamParticipant = this.newIpcamParticipant(sessionId, rtspConnectionId, tokenObj, location,
|
||||||
location, mediaOptions.getTypeOfVideo());
|
mediaOptions.getTypeOfVideo());
|
||||||
|
|
||||||
// Store a "fake" final user for the IpCam connection
|
// Store a "fake" final user for the IpCam connection
|
||||||
final String finalUserId = rtspConnectionId;
|
final String finalUserId = rtspConnectionId;
|
||||||
this.sessionidFinalUsers.get(session.getSessionId()).computeIfAbsent(finalUserId, k -> {
|
this.sessionidFinalUsers.get(sessionId).computeIfAbsent(finalUserId, k -> {
|
||||||
return new FinalUser(finalUserId, session.getSessionId(), ipcamParticipant);
|
return new FinalUser(finalUserId, sessionId, ipcamParticipant);
|
||||||
}).addConnectionIfAbsent(ipcamParticipant);
|
}).addConnectionIfAbsent(ipcamParticipant);
|
||||||
|
|
||||||
// Join the participant to the session
|
// Join the participant to the session
|
||||||
kSession.join(ipcamParticipant, EndpointType.PLAYER_ENDPOINT);
|
this.joinRoom(ipcamParticipant, sessionId, null);
|
||||||
|
|
||||||
// Publish the IpCam stream into the session
|
// Publish the IpCam stream into the session
|
||||||
KurentoParticipant kParticipant = (KurentoParticipant) this.getParticipant(rtspConnectionId);
|
KurentoParticipant kParticipant = (KurentoParticipant) this.getParticipant(rtspConnectionId);
|
||||||
|
|
|
@ -674,7 +674,7 @@ public class SessionRestController {
|
||||||
|
|
||||||
log.info("REST API: POST /api/sessions/{}/connection {}", sessionId, params.toString());
|
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) {
|
if (session == null) {
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue