openvidu-server: StreamPropertyChangedEvent

pull/88/merge
pabloFuente 2018-07-03 15:43:37 +02:00
parent 15d879992a
commit 4a99ea5fe8
9 changed files with 347 additions and 127 deletions

View File

@ -17,7 +17,8 @@
package io.openvidu.client.internal; package io.openvidu.client.internal;
/** /**
* This class defines constant values of client-server messages and their parameters. * This class defines constant values of client-server messages and their
* parameters.
* *
* @author <a href="mailto:rvlad@naevatec.com">Radu Tom Vlad</a> * @author <a href="mailto:rvlad@naevatec.com">Radu Tom Vlad</a>
*/ */
@ -41,20 +42,26 @@ public class ProtocolElements {
public static final String JOINROOM_PEERID_PARAM = "id"; public static final String JOINROOM_PEERID_PARAM = "id";
public static final String JOINROOM_PEERSTREAMS_PARAM = "streams"; public static final String JOINROOM_PEERSTREAMS_PARAM = "streams";
public static final String JOINROOM_PEERSTREAMID_PARAM = "id"; public static final String JOINROOM_PEERSTREAMID_PARAM = "id";
public static final String JOINROOM_PEERSTREAMHASAUDIO_PARAM = "hasAudio";
public static final String JOINROOM_PEERSTREAMHASVIDEO_PARAM = "hasVideo";
public static final String JOINROOM_PEERSTREAMAUDIOACTIVE_PARAM = "audioActive"; public static final String JOINROOM_PEERSTREAMAUDIOACTIVE_PARAM = "audioActive";
public static final String JOINROOM_PEERSTREAMVIDEOACTIVE_PARAM = "videoActive"; public static final String JOINROOM_PEERSTREAMVIDEOACTIVE_PARAM = "videoActive";
public static final String JOINROOM_PEERSTREAMTYPEOFVIDEO_PARAM = "typeOfVideo"; public static final String JOINROOM_PEERSTREAMTYPEOFVIDEO_PARAM = "typeOfVideo";
public static final String JOINROOM_PEERSTREAMFRAMERATE_PARAM = "frameRate"; public static final String JOINROOM_PEERSTREAMFRAMERATE_PARAM = "frameRate";
public static final String JOINROOM_PEERSTREAMVIDEODIMENSIONS_PARAM = "videoDimensions";
public static final String PUBLISHVIDEO_METHOD = "publishVideo"; public static final String PUBLISHVIDEO_METHOD = "publishVideo";
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_STREAMID_PARAM = "id";
public static final String PUBLISHVIDEO_HASAUDIO_PARAM = "hasAudio";
public static final String PUBLISHVIDEO_HASVIDEO_PARAM = "hasVideo";
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";
public static final String PUBLISHVIDEO_FRAMERATE_PARAM = "frameRate"; public static final String PUBLISHVIDEO_FRAMERATE_PARAM = "frameRate";
public static final String PUBLISHVIDEO_VIDEODIMENSIONS_PARAM = "videoDimensions";
public static final String UNPUBLISHVIDEO_METHOD = "unpublishVideo"; public static final String UNPUBLISHVIDEO_METHOD = "unpublishVideo";
@ -74,6 +81,13 @@ public class ProtocolElements {
public static final String CUSTOMREQUEST_METHOD = "customRequest"; public static final String CUSTOMREQUEST_METHOD = "customRequest";
public static final String STREAMPROPERTYCHANGED_METHOD = "streamPropertyChanged";
public static final String STREAMPROPERTYCHANGED_CONNECTIONID_PARAM = "connectionId";
public static final String STREAMPROPERTYCHANGED_STREAMID_PARAM = "streamId";
public static final String STREAMPROPERTYCHANGED_PROPERTY_PARAM = "property";
public static final String STREAMPROPERTYCHANGED_NEWVALUE_PARAM = "newValue";
public static final String STREAMPROPERTYCHANGED_REASON_PARAM = "reason";
// ---------------------------- SERVER RESPONSES & EVENTS ----------------- // ---------------------------- SERVER RESPONSES & EVENTS -----------------
public static final String PARTICIPANTJOINED_METHOD = "participantJoined"; public static final String PARTICIPANTJOINED_METHOD = "participantJoined";
@ -90,10 +104,13 @@ public class ProtocolElements {
public static final String PARTICIPANTPUBLISHED_USER_PARAM = "id"; public static final String PARTICIPANTPUBLISHED_USER_PARAM = "id";
public static final String PARTICIPANTPUBLISHED_STREAMS_PARAM = "streams"; public static final String PARTICIPANTPUBLISHED_STREAMS_PARAM = "streams";
public static final String PARTICIPANTPUBLISHED_STREAMID_PARAM = "id"; public static final String PARTICIPANTPUBLISHED_STREAMID_PARAM = "id";
public static final String PARTICIPANTPUBLISHED_HASAUDIO_PARAM = "hasAudio";
public static final String PARTICIPANTPUBLISHED_HASVIDEO_PARAM = "hasVideo";
public static final String PARTICIPANTPUBLISHED_AUDIOACTIVE_PARAM = "audioActive"; public static final String PARTICIPANTPUBLISHED_AUDIOACTIVE_PARAM = "audioActive";
public static final String PARTICIPANTPUBLISHED_VIDEOACTIVE_PARAM = "videoActive"; public static final String PARTICIPANTPUBLISHED_VIDEOACTIVE_PARAM = "videoActive";
public static final String PARTICIPANTPUBLISHED_TYPEOFVIDEO_PARAM = "typeOfVideo"; public static final String PARTICIPANTPUBLISHED_TYPEOFVIDEO_PARAM = "typeOfVideo";
public static final String PARTICIPANTPUBLISHED_FRAMERATE_PARAM = "frameRate"; public static final String PARTICIPANTPUBLISHED_FRAMERATE_PARAM = "frameRate";
public static final String PARTICIPANTPUBLISHED_VIDEODIMENSIONS_PARAM = "videoDimensions";
public static final String PARTICIPANTUNPUBLISHED_METHOD = "participantUnpublished"; public static final String PARTICIPANTUNPUBLISHED_METHOD = "participantUnpublished";
public static final String PARTICIPANTUNPUBLISHED_NAME_PARAM = "name"; public static final String PARTICIPANTUNPUBLISHED_NAME_PARAM = "name";

View File

@ -122,11 +122,11 @@ public class CDREvent implements Comparable<CDREvent> {
} }
if (this.mediaOptions != null) { if (this.mediaOptions != null) {
json.put("connection", this.receivingFrom != null ? "INBOUND" : "OUTBOUND"); json.put("connection", this.receivingFrom != null ? "INBOUND" : "OUTBOUND");
json.put("audioEnabled", this.mediaOptions.audioActive); json.put("audioEnabled", this.mediaOptions.hasAudio());
json.put("videoEnabled", this.mediaOptions.videoActive); json.put("videoEnabled", this.mediaOptions.hasVideo());
if (this.mediaOptions.videoActive) { if (this.mediaOptions.hasVideo()) {
json.put("videoSource", this.mediaOptions.typeOfVideo); json.put("videoSource", this.mediaOptions.getTypeOfVideo());
json.put("videoFramerate", this.mediaOptions.frameRate); json.put("videoFramerate", this.mediaOptions.getFrameRate());
} }
if (this.receivingFrom != null) { if (this.receivingFrom != null) {
json.put("receivingFrom", this.receivingFrom); json.put("receivingFrom", this.receivingFrom);

View File

@ -17,18 +17,72 @@
package io.openvidu.server.core; package io.openvidu.server.core;
import org.json.simple.JSONObject;
public class MediaOptions { public class MediaOptions {
public boolean audioActive; protected Boolean hasAudio;
public boolean videoActive; protected Boolean hasVideo;
public String typeOfVideo; protected Boolean audioActive;
public int frameRate; protected Boolean videoActive;
protected String typeOfVideo;
protected Integer frameRate;
protected String videoDimensions;
public MediaOptions(boolean audioActive, boolean videoActive, String typeOfVideo, int frameRate) { public MediaOptions(Boolean hasAudio, Boolean hasVideo, Boolean audioActive, Boolean videoActive,
String typeOfVideo, Integer frameRate, String videoDimensions) {
this.hasAudio = hasAudio;
this.hasVideo = hasVideo;
this.audioActive = audioActive; this.audioActive = audioActive;
this.videoActive = videoActive; this.videoActive = videoActive;
this.typeOfVideo = typeOfVideo; this.typeOfVideo = typeOfVideo;
this.frameRate = frameRate; this.frameRate = frameRate;
this.videoDimensions = videoDimensions;
}
@SuppressWarnings("unchecked")
public JSONObject toJson() {
JSONObject json = new JSONObject();
json.put("hasAudio", this.hasAudio);
if (hasAudio)
json.put("audioActive", this.audioActive);
json.put("hasVideo", this.hasVideo);
if (hasVideo)
json.put("videoActive", this.videoActive);
if (this.hasVideo && this.videoActive) {
json.put("typeOfVideo", this.typeOfVideo);
json.put("frameRate", this.frameRate);
json.put("videoDimensions", this.videoDimensions);
}
return json;
}
public boolean hasAudio() {
return this.hasAudio;
}
public boolean hasVideo() {
return this.hasVideo;
}
public boolean isAudioActive() {
return this.hasAudio && this.audioActive;
}
public boolean isVideoActive() {
return this.hasVideo && this.videoActive;
}
public String getTypeOfVideo() {
return this.typeOfVideo;
}
public Integer getFrameRate() {
return this.frameRate;
}
public String getVideoDimensions() {
return this.videoDimensions;
} }
} }

View File

@ -97,6 +97,12 @@ public class SessionEventsHandler {
JsonObject stream = new JsonObject(); JsonObject stream = new JsonObject();
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMID_PARAM, stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMID_PARAM,
existingParticipant.getPublisherStremId()); existingParticipant.getPublisherStremId());
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMHASAUDIO_PARAM,
kParticipant.getPublisherMediaOptions().hasAudio);
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMHASVIDEO_PARAM,
kParticipant.getPublisherMediaOptions().hasVideo);
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMVIDEOACTIVE_PARAM,
kParticipant.getPublisherMediaOptions().videoActive);
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMAUDIOACTIVE_PARAM, stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMAUDIOACTIVE_PARAM,
kParticipant.getPublisherMediaOptions().audioActive); kParticipant.getPublisherMediaOptions().audioActive);
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMVIDEOACTIVE_PARAM, stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMVIDEOACTIVE_PARAM,
@ -105,6 +111,8 @@ public class SessionEventsHandler {
kParticipant.getPublisherMediaOptions().typeOfVideo); kParticipant.getPublisherMediaOptions().typeOfVideo);
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMFRAMERATE_PARAM, stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMFRAMERATE_PARAM,
kParticipant.getPublisherMediaOptions().frameRate); kParticipant.getPublisherMediaOptions().frameRate);
stream.addProperty(ProtocolElements.JOINROOM_PEERSTREAMVIDEODIMENSIONS_PARAM,
kParticipant.getPublisherMediaOptions().videoDimensions);
JsonArray streamsArray = new JsonArray(); JsonArray streamsArray = new JsonArray();
streamsArray.add(stream); streamsArray.add(stream);
@ -168,8 +176,8 @@ public class SessionEventsHandler {
} }
} }
public void onPublishMedia(Participant participant, String streamId, String sessionId, MediaOptions mediaOptions, String sdpAnswer, public void onPublishMedia(Participant participant, String streamId, String sessionId, MediaOptions mediaOptions,
Set<Participant> participants, Integer transactionId, OpenViduException error) { String sdpAnswer, 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);
return; return;
@ -184,10 +192,13 @@ public class SessionEventsHandler {
JsonObject stream = new JsonObject(); JsonObject stream = new JsonObject();
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_STREAMID_PARAM, streamId); stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_STREAMID_PARAM, streamId);
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_HASAUDIO_PARAM, mediaOptions.hasAudio);
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_HASVIDEO_PARAM, mediaOptions.hasVideo);
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);
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_FRAMERATE_PARAM, mediaOptions.frameRate); stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_FRAMERATE_PARAM, mediaOptions.frameRate);
stream.addProperty(ProtocolElements.PARTICIPANTPUBLISHED_VIDEODIMENSIONS_PARAM, mediaOptions.videoDimensions);
JsonArray streamsArray = new JsonArray(); JsonArray streamsArray = new JsonArray();
streamsArray.add(stream); streamsArray.add(stream);
@ -308,6 +319,28 @@ public class SessionEventsHandler {
rpcNotificationService.sendResponse(participant.getParticipantPrivateId(), transactionId, new JsonObject()); rpcNotificationService.sendResponse(participant.getParticipantPrivateId(), transactionId, new JsonObject());
} }
public void onStreamPropertyChanged(Participant participant, Integer transactionId, Set<Participant> participants,
String streamId, String property, JsonElement newValue, String reason) {
JsonObject params = new JsonObject();
params.addProperty(ProtocolElements.STREAMPROPERTYCHANGED_CONNECTIONID_PARAM,
participant.getParticipantPublicId());
params.addProperty(ProtocolElements.STREAMPROPERTYCHANGED_STREAMID_PARAM, streamId);
params.addProperty(ProtocolElements.STREAMPROPERTYCHANGED_PROPERTY_PARAM, property);
params.addProperty(ProtocolElements.STREAMPROPERTYCHANGED_NEWVALUE_PARAM, newValue.toString());
params.addProperty(ProtocolElements.STREAMPROPERTYCHANGED_REASON_PARAM, reason);
for (Participant p : participants) {
if (p.getParticipantPrivateId().equals(participant.getParticipantPrivateId())) {
rpcNotificationService.sendResponse(participant.getParticipantPrivateId(), transactionId,
new JsonObject());
} else {
rpcNotificationService.sendNotification(p.getParticipantPrivateId(),
ProtocolElements.STREAMPROPERTYCHANGED_METHOD, params);
}
}
}
public void onRecvIceCandidate(Participant participant, Integer transactionId, OpenViduException error) { public void onRecvIceCandidate(Participant participant, Integer transactionId, OpenViduException error) {
if (error != null) { if (error != null) {
rpcNotificationService.sendErrorResponse(participant.getParticipantPrivateId(), transactionId, null, error); rpcNotificationService.sendErrorResponse(participant.getParticipantPrivateId(), transactionId, null, error);

View File

@ -32,6 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
@ -86,6 +87,9 @@ public abstract class SessionManager {
public abstract void sendMessage(Participant participant, String message, Integer transactionId); public abstract void sendMessage(Participant participant, String message, Integer transactionId);
public abstract void streamPropertyChanged(Participant participant, Integer transactionId, String streamId,
String property, JsonElement newValue, String reason);
public abstract void onIceCandidate(Participant participant, String endpointName, String candidate, public abstract void onIceCandidate(Participant participant, String endpointName, String candidate,
int sdpMLineIndex, String sdpMid, Integer transactionId); int sdpMLineIndex, String sdpMid, Integer transactionId);
@ -203,7 +207,8 @@ 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 {
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) {
if (!isMetadataFormatCorrect(serverMetadata)) { if (!isMetadataFormatCorrect(serverMetadata)) {
@ -250,7 +255,9 @@ public abstract class SessionManager {
this.sessionidTokenTokenobj.putIfAbsent(sessionId, new ConcurrentHashMap<>()); this.sessionidTokenTokenobj.putIfAbsent(sessionId, new ConcurrentHashMap<>());
this.sessionidTokenTokenobj.get(sessionId).putIfAbsent(token, this.sessionidTokenTokenobj.get(sessionId).putIfAbsent(token,
new Token(token, ParticipantRole.PUBLISHER, "", new Token(token, ParticipantRole.PUBLISHER, "",
this.coturnCredentialsService.isCoturnAvailable() ? this.coturnCredentialsService.createUser() : null)); this.coturnCredentialsService.isCoturnAvailable()
? this.coturnCredentialsService.createUser()
: null));
return true; return true;
} }
} }
@ -313,8 +320,10 @@ public abstract class SessionManager {
public Participant newRecorderParticipant(String sessionId, String participantPrivatetId, Token token, public Participant newRecorderParticipant(String sessionId, String participantPrivatetId, Token token,
String clientMetadata) { String clientMetadata) {
if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) { if (this.sessionidParticipantpublicidParticipant.get(sessionId) != null) {
Participant p = new Participant(participantPrivatetId, ProtocolElements.RECORDER_PARTICIPANT_PUBLICID, token, clientMetadata); Participant p = new Participant(participantPrivatetId, ProtocolElements.RECORDER_PARTICIPANT_PUBLICID,
this.sessionidParticipantpublicidParticipant.get(sessionId).put(ProtocolElements.RECORDER_PARTICIPANT_PUBLICID, p); token, clientMetadata);
this.sessionidParticipantpublicidParticipant.get(sessionId)
.put(ProtocolElements.RECORDER_PARTICIPANT_PUBLICID, 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);

View File

@ -32,9 +32,10 @@ public class KurentoMediaOptions extends MediaOptions {
public MediaElement[] mediaElements; public MediaElement[] mediaElements;
public KurentoMediaOptions(boolean isOffer, String sdpOffer, MediaElement loopbackAlternativeSrc, public KurentoMediaOptions(boolean isOffer, String sdpOffer, MediaElement loopbackAlternativeSrc,
MediaType loopbackConnectionType, boolean audioActive, boolean videoActive, String typeOfVideo, MediaType loopbackConnectionType, Boolean hasAudio, Boolean hasVideo, Boolean audioActive,
int frameRate, boolean doLoopback, MediaElement... mediaElements) { Boolean videoActive, String typeOfVideo, Integer frameRate, String videoDimensions, boolean doLoopback,
super(audioActive, videoActive, typeOfVideo, frameRate); MediaElement... mediaElements) {
super(hasAudio, hasVideo, audioActive, videoActive, typeOfVideo, frameRate, videoDimensions);
this.isOffer = isOffer; this.isOffer = isOffer;
this.sdpOffer = sdpOffer; this.sdpOffer = sdpOffer;
this.loopbackAlternativeSrc = loopbackAlternativeSrc; this.loopbackAlternativeSrc = loopbackAlternativeSrc;

View File

@ -102,7 +102,7 @@ public class KurentoParticipant extends Participant {
publisher.setMediaOptions(mediaOptions); publisher.setMediaOptions(mediaOptions);
String publisherStreamId = this.getParticipantPublicId() + "_" String publisherStreamId = this.getParticipantPublicId() + "_"
+ (mediaOptions.videoActive ? mediaOptions.typeOfVideo : "MICRO") + "_" + (mediaOptions.hasVideo() ? mediaOptions.getTypeOfVideo() : "MICRO") + "_"
+ RandomStringUtils.random(5, true, false).toUpperCase(); + RandomStringUtils.random(5, true, false).toUpperCase();
this.publisher.getEndpoint().addTag("name", publisherStreamId); this.publisher.getEndpoint().addTag("name", publisherStreamId);
addEndpointListeners(this.publisher); addEndpointListeners(this.publisher);
@ -185,6 +185,10 @@ public class KurentoParticipant extends Participant {
return this.publisher.getMediaOptions(); return this.publisher.getMediaOptions();
} }
public void setPublisherMediaOptions(MediaOptions mediaOptions) {
this.publisher.setMediaOptions(mediaOptions);
}
public KurentoSession getSession() { public KurentoSession getSession() {
return session; return session;
} }
@ -641,7 +645,7 @@ public class KurentoParticipant extends Participant {
+ " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis(); + " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis();
endpoint.flowInMedia.put(event.getSource().getName(), event.getMediaType()); endpoint.flowInMedia.put(event.getSource().getName(), event.getMediaType());
if (endpoint.getMediaOptions().audioActive && endpoint.getMediaOptions().videoActive if (endpoint.getMediaOptions().hasAudio() && endpoint.getMediaOptions().hasVideo()
&& endpoint.flowInMedia.values().size() == 2) { && endpoint.flowInMedia.values().size() == 2) {
endpoint.kmsEvents.add(new KmsEvent(event)); endpoint.kmsEvents.add(new KmsEvent(event));
} else if (endpoint.flowInMedia.values().size() == 1) { } else if (endpoint.flowInMedia.values().size() == 1) {
@ -658,7 +662,7 @@ public class KurentoParticipant extends Participant {
+ " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis(); + " | MEDIATYPE: " + event.getMediaType() + " | TIMESTAMP: " + System.currentTimeMillis();
endpoint.flowOutMedia.put(event.getSource().getName(), event.getMediaType()); endpoint.flowOutMedia.put(event.getSource().getName(), event.getMediaType());
if (endpoint.getMediaOptions().audioActive && endpoint.getMediaOptions().videoActive if (endpoint.getMediaOptions().hasAudio() && endpoint.getMediaOptions().hasVideo()
&& endpoint.flowOutMedia.values().size() == 2) { && endpoint.flowOutMedia.values().size() == 2) {
endpoint.kmsEvents.add(new KmsEvent(event)); endpoint.kmsEvents.add(new KmsEvent(event));
} else if (endpoint.flowOutMedia.values().size() == 1) { } else if (endpoint.flowOutMedia.values().size() == 1) {
@ -708,6 +712,24 @@ public class KurentoParticipant extends Participant {
return json; return json;
} }
@SuppressWarnings("unchecked")
public JSONObject withStatsToJSON() {
JSONObject json = super.toJSON();
JSONArray publisherEnpoints = new JSONArray();
if (this.streaming && this.publisher.getEndpoint() != null) {
publisherEnpoints.add(this.publisher.withStatsToJSON());
}
JSONArray subscriberEndpoints = new JSONArray();
for (MediaEndpoint sub : this.subscribers.values()) {
if (sub.getEndpoint() != null) {
subscriberEndpoints.add(sub.withStatsToJSON());
}
}
json.put("publishers", publisherEnpoints);
json.put("subscribers", subscriberEndpoints);
return json;
}
@Override @Override
public String getPublisherStremId() { public String getPublisherStremId() {
return this.publisher.getEndpoint().getTag("name"); return this.publisher.getEndpoint().getTag("name");

View File

@ -28,6 +28,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException; import com.google.gson.JsonSyntaxException;
@ -271,8 +272,8 @@ public class KurentoSessionManager extends SessionManager {
participants = kurentoParticipant.getSession().getParticipants(); participants = kurentoParticipant.getSession().getParticipants();
if (sdpAnswer != null) { if (sdpAnswer != null) {
sessionEventsHandler.onPublishMedia(participant, participant.getPublisherStremId(), session.getSessionId(), mediaOptions, sdpAnswer, sessionEventsHandler.onPublishMedia(participant, participant.getPublisherStremId(), session.getSessionId(),
participants, transactionId, null); mediaOptions, sdpAnswer, participants, transactionId, null);
} }
} }
@ -379,6 +380,40 @@ public class KurentoSessionManager extends SessionManager {
} }
} }
@Override
public void streamPropertyChanged(Participant participant, Integer transactionId, String streamId, String property,
JsonElement newValue, String reason) {
KurentoParticipant kParticipant = (KurentoParticipant) participant;
streamId = kParticipant.getPublisherStremId();
MediaOptions streamProperties = kParticipant.getPublisherMediaOptions();
Boolean hasAudio = streamProperties.hasAudio();
Boolean hasVideo = streamProperties.hasVideo();
Boolean audioActive = streamProperties.isAudioActive();
Boolean videoActive = streamProperties.isVideoActive();
String typeOfVideo = streamProperties.getTypeOfVideo();
Integer frameRate = streamProperties.getFrameRate();
String videoDimensions = streamProperties.getVideoDimensions();
switch (property) {
case "audioActive":
audioActive = newValue.getAsBoolean();
break;
case "videoActive":
videoActive = newValue.getAsBoolean();
break;
case "videoDimensions":
videoDimensions = newValue.getAsString();
break;
}
kParticipant.setPublisherMediaOptions(new MediaOptions(hasAudio, hasVideo, audioActive, videoActive,
typeOfVideo, frameRate, videoDimensions));
sessionEventsHandler.onStreamPropertyChanged(participant, transactionId,
kParticipant.getSession().getParticipants(), streamId, property, newValue, reason);
}
@Override @Override
public void onIceCandidate(Participant participant, String endpointName, String candidate, int sdpMLineIndex, public void onIceCandidate(Participant participant, String endpointName, String candidate, int sdpMLineIndex,
String sdpMid, Integer transactionId) { String sdpMid, Integer transactionId) {
@ -450,14 +485,38 @@ public class KurentoSessionManager extends SessionManager {
public MediaOptions generateMediaOptions(Request<JsonObject> request) { public MediaOptions generateMediaOptions(Request<JsonObject> request) {
String sdpOffer = RpcHandler.getStringParam(request, ProtocolElements.PUBLISHVIDEO_SDPOFFER_PARAM); String sdpOffer = RpcHandler.getStringParam(request, ProtocolElements.PUBLISHVIDEO_SDPOFFER_PARAM);
boolean audioActive = RpcHandler.getBooleanParam(request, ProtocolElements.PUBLISHVIDEO_AUDIOACTIVE_PARAM); boolean hasAudio = RpcHandler.getBooleanParam(request, ProtocolElements.PUBLISHVIDEO_HASAUDIO_PARAM);
boolean videoActive = RpcHandler.getBooleanParam(request, ProtocolElements.PUBLISHVIDEO_VIDEOACTIVE_PARAM); boolean hasVideo = RpcHandler.getBooleanParam(request, ProtocolElements.PUBLISHVIDEO_HASVIDEO_PARAM);
String typeOfVideo = RpcHandler.getStringParam(request, ProtocolElements.PUBLISHVIDEO_TYPEOFVIDEO_PARAM);
int frameRate = RpcHandler.getIntParam(request, ProtocolElements.PUBLISHVIDEO_FRAMERATE_PARAM); Boolean audioActive = null, videoActive = null;
String typeOfVideo = null, videoDimensions = null;
Integer frameRate = null;
try {
audioActive = RpcHandler.getBooleanParam(request, ProtocolElements.PUBLISHVIDEO_AUDIOACTIVE_PARAM);
} catch (RuntimeException noParameterFound) {
}
try {
videoActive = RpcHandler.getBooleanParam(request, ProtocolElements.PUBLISHVIDEO_VIDEOACTIVE_PARAM);
} catch (RuntimeException noParameterFound) {
}
try {
typeOfVideo = RpcHandler.getStringParam(request, ProtocolElements.PUBLISHVIDEO_TYPEOFVIDEO_PARAM);
} catch (RuntimeException noParameterFound) {
}
try {
videoDimensions = RpcHandler.getStringParam(request, ProtocolElements.PUBLISHVIDEO_VIDEODIMENSIONS_PARAM);
} catch (RuntimeException noParameterFound) {
}
try {
frameRate = RpcHandler.getIntParam(request, ProtocolElements.PUBLISHVIDEO_FRAMERATE_PARAM);
} catch (RuntimeException noParameterFound) {
}
boolean doLoopback = RpcHandler.getBooleanParam(request, ProtocolElements.PUBLISHVIDEO_DOLOOPBACK_PARAM); boolean doLoopback = RpcHandler.getBooleanParam(request, ProtocolElements.PUBLISHVIDEO_DOLOOPBACK_PARAM);
return new KurentoMediaOptions(true, sdpOffer, null, null, audioActive, videoActive, typeOfVideo, frameRate, return new KurentoMediaOptions(true, sdpOffer, null, null, hasAudio, hasVideo, audioActive, videoActive,
doLoopback); typeOfVideo, frameRate, videoDimensions, doLoopback);
} }
} }

View File

@ -30,6 +30,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
@ -122,6 +123,9 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
case ProtocolElements.UNPUBLISHVIDEO_METHOD: case ProtocolElements.UNPUBLISHVIDEO_METHOD:
unpublishVideo(rpcConnection, request); unpublishVideo(rpcConnection, request);
break; break;
case ProtocolElements.STREAMPROPERTYCHANGED_METHOD:
streamPropertyChanged(rpcConnection, request);
break;
default: default:
log.error("Unrecognized request {}", request); log.error("Unrecognized request {}", request);
break; break;
@ -283,6 +287,19 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
sessionManager.unpublishVideo(participant, request.getId(), "unpublish"); sessionManager.unpublishVideo(participant, request.getId(), "unpublish");
} }
public void streamPropertyChanged(RpcConnection rpcConnection, Request<JsonObject> request) {
String participantPrivateId = rpcConnection.getParticipantPrivateId();
String sessionId = rpcConnection.getSessionId();
Participant participant = sessionManager.getParticipant(sessionId, participantPrivateId);
String streamId = getStringParam(request, ProtocolElements.STREAMPROPERTYCHANGED_STREAMID_PARAM);
String property = getStringParam(request, ProtocolElements.STREAMPROPERTYCHANGED_PROPERTY_PARAM);
JsonElement newValue = getParam(request, ProtocolElements.STREAMPROPERTYCHANGED_NEWVALUE_PARAM);
String reason = getStringParam(request, ProtocolElements.STREAMPROPERTYCHANGED_REASON_PARAM);
sessionManager.streamPropertyChanged(participant, request.getId(), streamId, property, newValue, reason);
}
public void leaveRoomAfterConnClosed(String participantPrivateId, String reason) { public void leaveRoomAfterConnClosed(String participantPrivateId, String reason) {
try { try {
sessionManager.evictParticipant(participantPrivateId, reason); sessionManager.evictParticipant(participantPrivateId, reason);
@ -386,4 +403,12 @@ public class RpcHandler extends DefaultJsonRpcHandler<JsonObject> {
return request.getParams().get(key).getAsBoolean(); return request.getParams().get(key).getAsBoolean();
} }
public static JsonElement getParam(Request<JsonObject> request, String key) {
if (request.getParams() == null || request.getParams().get(key) == null) {
throw new RuntimeException("Request element '" + key + "' is missing in method '" + request.getMethod()
+ "'. CHECK THAT 'openvidu-server' AND 'openvidu-browser' SHARE THE SAME VERSION NUMBER");
}
return request.getParams().get(key);
}
} }