Events MediaFlowInChange and MediaFlowOutChange are now sent to clients

pull/20/head
Štěpán Škorpil 2017-12-18 19:28:12 +01:00
parent c5db83951d
commit 6fe6b52dcf
5 changed files with 88 additions and 17 deletions

View File

@ -112,5 +112,15 @@ public class ProtocolElements {
public static final String ICECANDIDATE_SDPMID_PARAM = "sdpMid"; public static final String ICECANDIDATE_SDPMID_PARAM = "sdpMid";
public static final String ICECANDIDATE_SDPMLINEINDEX_PARAM = "sdpMLineIndex"; public static final String ICECANDIDATE_SDPMLINEINDEX_PARAM = "sdpMLineIndex";
public static final String MEDIAFLOWINCHANGE_METHOD = "onMediaFlowInChange";
public static final String MEDIAFLOWINCHANGE_MEDIATYPE_PARAM = "mediaType";
public static final String MEDIAFLOWINCHANGE_NEWSTATE_PARAM = "newState";
public static final String MEDIAFLOWINCHANGE_USER_PARAM = "id";
public static final String MEDIAFLOWOUTCHANGE_METHOD = "onMediaFlowOutChange";
public static final String MEDIAFLOWOUTCHANGE_MEDIATYPE_PARAM = "mediaType";
public static final String MEDIAFLOWOUTCHANGE_NEWSTATE_PARAM = "newState";
public static final String MEDIAFLOWOUTCHANGE_USER_PARAM = "id";
public static final String CUSTOM_NOTIFICATION = "custonNotification"; public static final String CUSTOM_NOTIFICATION = "custonNotification";
} }

View File

@ -16,12 +16,17 @@
package io.openvidu.server.core.api; package io.openvidu.server.core.api;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set; import java.util.Set;
import io.openvidu.server.core.api.pojo.UserParticipant;
import org.kurento.client.IceCandidate; import org.kurento.client.IceCandidate;
import io.openvidu.server.InfoHandler; import io.openvidu.server.InfoHandler;
import io.openvidu.server.core.internal.Participant; import io.openvidu.server.core.internal.Participant;
import org.kurento.client.MediaFlowState;
import org.kurento.client.MediaType;
/** /**
* Handler for events triggered from media objects. * Handler for events triggered from media objects.
@ -73,6 +78,26 @@ public interface RoomHandler {
*/ */
void updateFilter(String roomName, Participant participant, String filterId, String state); void updateFilter(String roomName, Participant participant, String filterId, String state);
/**
* Called as a result of started or interrupted media flow. All participants should be notified.
* @param participantId
* @param mediaType
* @param newState
* @param participants
*/
void onMediaFlowInChange(String roomName, String participantId, MediaType mediaType,
MediaFlowState newState, Collection<Participant> participants);
/**
* Called as a result of started or interrupted media flow. All participants should be notified.
* @param participantId
* @param mediaType
* @param newState
* @param participants
*/
void onMediaFlowOutChange(String roomName, String participantId, MediaType mediaType,
MediaFlowState newState, Collection<Participant> participants);
/** /**
* Called to get the next state of a filter when requested by a call to updateFilter * Called to get the next state of a filter when requested by a call to updateFilter
* *

View File

@ -16,12 +16,12 @@
package io.openvidu.server.core.internal; package io.openvidu.server.core.internal;
import java.util.HashSet; import java.util.*;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.kurento.client.IceCandidate; import org.kurento.client.IceCandidate;
import org.kurento.client.MediaFlowState;
import org.kurento.client.MediaType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
@ -306,6 +306,32 @@ public class DefaultNotificationRoomHandler implements NotificationRoomHandler {
ProtocolElements.PARTICIPANTEVICTED_METHOD, new JsonObject()); ProtocolElements.PARTICIPANTEVICTED_METHOD, new JsonObject());
} }
@Override
public void onMediaFlowInChange(String roomName, String participantId, MediaType mediaType,
MediaFlowState newState, Collection<Participant> participants) {
JsonObject notifParams = new JsonObject();
notifParams.addProperty(ProtocolElements.MEDIAFLOWINCHANGE_USER_PARAM, participantId);
notifParams.addProperty(ProtocolElements.MEDIAFLOWINCHANGE_MEDIATYPE_PARAM, mediaType.toString());
notifParams.addProperty(ProtocolElements.MEDIAFLOWINCHANGE_NEWSTATE_PARAM, newState.toString());
for (Participant participant : participants) {
notifService.sendNotification(participant.getId(),
ProtocolElements.MEDIAFLOWINCHANGE_METHOD, notifParams);
}
}
@Override
public void onMediaFlowOutChange(String roomName, String participantId, MediaType mediaType,
MediaFlowState newState, Collection<Participant> participants) {
JsonObject notifParams = new JsonObject();
notifParams.addProperty(ProtocolElements.MEDIAFLOWOUTCHANGE_USER_PARAM, participantId);
notifParams.addProperty(ProtocolElements.MEDIAFLOWOUTCHANGE_MEDIATYPE_PARAM, mediaType.toString());
notifParams.addProperty(ProtocolElements.MEDIAFLOWOUTCHANGE_NEWSTATE_PARAM, newState.toString());
for (Participant participant : participants) {
notifService.sendNotification(participant.getId(),
ProtocolElements.MEDIAFLOWOUTCHANGE_METHOD, notifParams);
}
}
// ------------ EVENTS FROM ROOM HANDLER ----- // ------------ EVENTS FROM ROOM HANDLER -----
@Override @Override

View File

@ -23,14 +23,7 @@ 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.kurento.client.Continuation; import org.kurento.client.*;
import org.kurento.client.ErrorEvent;
import org.kurento.client.Filter;
import org.kurento.client.IceCandidate;
import org.kurento.client.MediaElement;
import org.kurento.client.MediaPipeline;
import org.kurento.client.MediaType;
import org.kurento.client.SdpEndpoint;
import org.kurento.client.internal.server.KurentoServerException; import org.kurento.client.internal.server.KurentoServerException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -498,6 +491,16 @@ public class Participant {
room.sendMediaError(id, desc); room.sendMediaError(id, desc);
} }
public void sendMediaFlowInChange(MediaFlowInStateChangeEvent event) {
log.warn("PARTICIPANT {}: Media flow in: {}", name, event.getState());
room.sendMediaFlowInChange(name, event.getMediaType(),event.getState());
}
public void sendMediaFlowOutChange(MediaFlowOutStateChangeEvent event) {
log.warn("PARTICIPANT {}: Media flow out: {}", name, event.getState());
room.sendMediaFlowOutChange(name, event.getMediaType(),event.getState());
}
private void releasePublisherEndpoint() { private void releasePublisherEndpoint() {
if (publisher != null && publisher.getEndpoint() != null) { if (publisher != null && publisher.getEndpoint() != null) {
this.streaming = false; this.streaming = false;
@ -638,6 +641,7 @@ public class Participant {
System.out.println(msg2); System.out.println(msg2);
this.infoHandler.sendInfo(msg1); this.infoHandler.sendInfo(msg1);
this.infoHandler.sendInfo(msg2); this.infoHandler.sendInfo(msg2);
this.sendMediaFlowInChange(event);
}); });
endpoint.getWebEndpoint().addMediaFlowOutStateChangeListener((event) -> { endpoint.getWebEndpoint().addMediaFlowOutStateChangeListener((event) -> {
@ -662,6 +666,7 @@ public class Participant {
System.out.println(msg2); System.out.println(msg2);
this.infoHandler.sendInfo(msg1); this.infoHandler.sendInfo(msg1);
this.infoHandler.sendInfo(msg2); this.infoHandler.sendInfo(msg2);
this.sendMediaFlowOutChange(event);
}); });
endpoint.getWebEndpoint().addMediaSessionStartedListener((event) -> { endpoint.getWebEndpoint().addMediaSessionStartedListener((event) -> {

View File

@ -24,12 +24,7 @@ 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.kurento.client.Continuation; import org.kurento.client.*;
import org.kurento.client.ErrorEvent;
import org.kurento.client.EventListener;
import org.kurento.client.IceCandidate;
import org.kurento.client.KurentoClient;
import org.kurento.client.MediaPipeline;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -236,6 +231,16 @@ public class Room {
this.roomHandler.onIceCandidate(name, participantId, endpointName, candidate); this.roomHandler.onIceCandidate(name, participantId, endpointName, candidate);
} }
public void sendMediaFlowInChange(String participantId, MediaType mediaType,
MediaFlowState newState){
this.roomHandler.onMediaFlowInChange(name,participantId, mediaType, newState, participants.values());
}
public void sendMediaFlowOutChange(String participantId, MediaType mediaType,
MediaFlowState newState){
this.roomHandler.onMediaFlowOutChange(name,participantId, mediaType, newState, participants.values());
}
public void sendMediaError(String participantId, String description) { public void sendMediaError(String participantId, String description) {
this.roomHandler.onMediaElementError(name, participantId, description); this.roomHandler.onMediaElementError(name, participantId, description);
} }