org.kurento.client.ListenerSubscription Java Examples

The following examples show how to use org.kurento.client.ListenerSubscription. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KurentoSessionManager.java    From openvidu with Apache License 2.0 6 votes vote down vote up
private void addFilterEventListenerInPublisher(KurentoParticipant kParticipant, String eventType)
		throws OpenViduException {
	PublisherEndpoint pub = kParticipant.getPublisher();
	if (!pub.isListenerAddedToFilterEvent(eventType)) {
		final String sessionId = kParticipant.getSessionId();
		final String connectionId = kParticipant.getParticipantPublicId();
		final String streamId = kParticipant.getPublisherStreamId();
		final String filterType = kParticipant.getPublisherMediaOptions().getFilter().getType();
		try {
			ListenerSubscription listener = pub.getFilter().addEventListener(eventType, event -> {
				sessionEventsHandler.onFilterEventDispatched(sessionId, connectionId, streamId, filterType, event,
						kParticipant.getSession().getParticipants(),
						kParticipant.getPublisher().getPartipantsListentingToFilterEvent(eventType));
			});
			pub.storeListener(eventType, listener);
		} catch (Exception e) {
			log.error("Request to addFilterEventListener to stream {} gone wrong. Error: {}", streamId,
					e.getMessage());
			throw new OpenViduException(Code.FILTER_EVENT_LISTENER_NOT_FOUND,
					"Request to addFilterEventListener to stream " + streamId + " gone wrong: " + e.getMessage());
		}
	}
}
 
Example #2
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 6 votes vote down vote up
public void stop() {
  if (recorderEndpoint != null) {
    final CountDownLatch stoppedCountDown = new CountDownLatch(1);
    ListenerSubscription subscriptionId = recorderEndpoint
        .addStoppedListener(new EventListener<StoppedEvent>() {

          @Override
          public void onEvent(StoppedEvent event) {
            stoppedCountDown.countDown();
          }
        });
    recorderEndpoint.stop();
    try {
      if (!stoppedCountDown.await(5, TimeUnit.SECONDS)) {
        log.error("Error waiting for recorder to stop");
      }
    } catch (InterruptedException e) {
      log.error("Exception while waiting for state change", e);
    }
    recorderEndpoint.removeStoppedListener(subscriptionId);
  }
}
 
Example #3
Source File: MediaEndpoint.java    From openvidu with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a listener for when the {@link MediaElement} triggers an
 * {@link ErrorEvent}. Notifies the owner with the error.
 *
 * @param element the {@link MediaElement}
 * @return {@link ListenerSubscription} that can be used to deregister the
 *         listener
 */
protected ListenerSubscription registerElemErrListener(MediaElement element) {
	return element.addErrorListener(new EventListener<ErrorEvent>() {
		@Override
		public void onEvent(ErrorEvent event) {
			owner.sendMediaError(event);
		}
	});
}
 
Example #4
Source File: MediaEndpoint.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a listener for when the {@link MediaElement} triggers an {@link ErrorEvent}. Notifies
 * the owner with the error.
 *
 * @param element
 *          the {@link MediaElement}
 * @return {@link ListenerSubscription} that can be used to deregister the listener
 */
protected ListenerSubscription registerElemErrListener(MediaElement element) {
  return element.addErrorListener(new EventListener<ErrorEvent>() {
    @Override
    public void onEvent(ErrorEvent event) {
      owner.sendMediaError(event);
    }
  });
}
 
Example #5
Source File: PublisherEndpoint.java    From openvidu with Apache License 2.0 4 votes vote down vote up
public boolean storeListener(String eventType, ListenerSubscription listener) {
	return (this.filterListeners.putIfAbsent(eventType, listener) == null);
}
 
Example #6
Source File: PublisherEndpoint.java    From openvidu with Apache License 2.0 4 votes vote down vote up
public ListenerSubscription removeListener(String eventType) {
	// Clean all participant subscriptions to this event
	this.subscribersToFilterEvents.remove(eventType);
	// Clean ListenerSubscription object for this event
	return this.filterListeners.remove(eventType);
}
 
Example #7
Source File: SampleClass.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
void addSampleListener(EventListener<SampleEvent> listener,
Continuation<ListenerSubscription> cont);
 
Example #8
Source File: PlayerEndpointAsyncTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Test
public void testEventEndOfStream() throws InterruptedException {

  AsyncResultManager<ListenerSubscription> asyncListener =
      new AsyncResultManager<>("EndOfStream Listener registration");

  AsyncEventManager<EndOfStreamEvent> asyncEvent = new AsyncEventManager<>("EndOfStream event");

  player.addEndOfStreamListener(asyncEvent.getMediaEventListener(),
      asyncListener.getContinuation());

  asyncListener.waitForResult();

  player.play();

  asyncEvent.waitForResult();
}
 
Example #9
Source File: MediaEndpoint.java    From openvidu with Apache License 2.0 3 votes vote down vote up
/**
 * Unregisters the error listener from the media element using the provided
 * subscription.
 *
 * @param element      the {@link MediaElement}
 * @param subscription the associated {@link ListenerSubscription}
 */
protected void unregisterElementErrListener(MediaElement element, final ListenerSubscription subscription) {
	if (element == null || subscription == null) {
		return;
	}
	element.removeErrorListener(subscription);
}
 
Example #10
Source File: MediaEndpoint.java    From kurento-room with Apache License 2.0 3 votes vote down vote up
/**
 * Unregisters the error listener from the media element using the provided subscription.
 *
 * @param element
 *          the {@link MediaElement}
 * @param subscription
 *          the associated {@link ListenerSubscription}
 */
protected void unregisterElementErrListener(MediaElement element,
    final ListenerSubscription subscription) {
  if (element == null || subscription == null) {
    return;
  }
  element.removeErrorListener(subscription);
}
 
Example #11
Source File: SampleClass.java    From kurento-java with Apache License 2.0 votes vote down vote up
ListenerSubscription addSampleListener(EventListener<SampleEvent> listener);