org.kurento.client.IceCandidate Java Examples

The following examples show how to use org.kurento.client.IceCandidate. 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: Handler.java    From kurento-tutorial-java with Apache License 2.0 6 votes vote down vote up
private void handleAddIceCandidate(final WebSocketSession session,
    JsonObject jsonMessage)
{
  String sessionId = session.getId();
  UserSession user = users.get(sessionId);

  if (user != null) {
    JsonObject jsonCandidate = jsonMessage.get("candidate").getAsJsonObject();
    IceCandidate candidate =
        new IceCandidate(jsonCandidate.get("candidate").getAsString(),
        jsonCandidate.get("sdpMid").getAsString(),
        jsonCandidate.get("sdpMLineIndex").getAsInt());

    WebRtcEndpoint webRtcEp = user.getWebRtcEndpoint();
    webRtcEp.addIceCandidate(candidate);
  }
}
 
Example #2
Source File: MediaEndpoint.java    From openvidu with Apache License 2.0 6 votes vote down vote up
private void internalAddIceCandidate(IceCandidate candidate) throws OpenViduException {
	if (webEndpoint == null) {
		throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
				"Can't add existing ICE candidates to null WebRtcEndpoint (ep: " + endpointName + ")");
	}
	this.receivedCandidateList.add(candidate);
	this.webEndpoint.addIceCandidate(candidate, new Continuation<Void>() {
		@Override
		public void onSuccess(Void result) throws Exception {
			log.trace("Ice candidate \"{}\" added to the internal endpoint", candidate.getCandidate());
		}

		@Override
		public void onError(Throwable cause) throws Exception {
			log.warn("EP {}: Failed to add ice candidate \"{}\" to the internal endpoint: {}", endpointName,
					candidate.getCandidate(), cause.getMessage());
		}
	});
}
 
Example #3
Source File: Handler.java    From kurento-tutorial-java with Apache License 2.0 6 votes vote down vote up
private void handleAddIceCandidate(final WebSocketSession session,
    JsonObject jsonMessage)
{
  final String sessionId = session.getId();
  if (!users.containsKey(sessionId)) {
    log.warn("[Handler::handleAddIceCandidate] Skip, unknown user, id: {}",
        sessionId);
    return;
  }

  final UserSession user = users.get(sessionId);
  final JsonObject jsonCandidate =
      jsonMessage.get("candidate").getAsJsonObject();
  final IceCandidate candidate =
      new IceCandidate(jsonCandidate.get("candidate").getAsString(),
      jsonCandidate.get("sdpMid").getAsString(),
      jsonCandidate.get("sdpMLineIndex").getAsInt());

  WebRtcEndpoint webRtcEp = user.getWebRtcEndpoint();
  webRtcEp.addIceCandidate(candidate);
}
 
Example #4
Source File: MediaEndpoint.java    From kurento-room with Apache License 2.0 6 votes vote down vote up
private void internalAddIceCandidate(IceCandidate candidate) throws RoomException {
  if (webEndpoint == null) {
    throw new RoomException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
        "Can't add existing ICE candidates to null WebRtcEndpoint (ep: " + endpointName + ")");
  }
  this.webEndpoint.addIceCandidate(candidate, new Continuation<Void>() {
    @Override
    public void onSuccess(Void result) throws Exception {
      log.trace("Ice candidate added to the internal endpoint");
    }

    @Override
    public void onError(Throwable cause) throws Exception {
      log.warn("EP {}: Failed to add ice candidate to the internal endpoint", endpointName, cause);
    }
  });
}
 
Example #5
Source File: KurentoSessionManager.java    From openvidu with Apache License 2.0 5 votes vote down vote up
@Override
public void onIceCandidate(Participant participant, String endpointName, String candidate, int sdpMLineIndex,
		String sdpMid, Integer transactionId) {
	try {
		KurentoParticipant kParticipant = (KurentoParticipant) participant;
		log.debug("Request [ICE_CANDIDATE] endpoint={} candidate={} " + "sdpMLineIdx={} sdpMid={} ({})",
				endpointName, candidate, sdpMLineIndex, sdpMid, participant.getParticipantPublicId());
		kParticipant.addIceCandidate(endpointName, new IceCandidate(candidate, sdpMid, sdpMLineIndex));
		sessionEventsHandler.onRecvIceCandidate(participant, transactionId, null);
	} catch (OpenViduException e) {
		log.error("PARTICIPANT {}: Error receiving ICE " + "candidate (epName={}, candidate={})",
				participant.getParticipantPublicId(), endpointName, candidate, e);
		sessionEventsHandler.onRecvIceCandidate(participant, transactionId, e);
	}
}
 
Example #6
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public void addCandidate(IceCandidate candidate) {
  if (this.webRtcEndpoint != null) {
    this.webRtcEndpoint.addIceCandidate(candidate);
  } else {
    candidateList.add(candidate);
  }

  if (this.playingWebRtcEndpoint != null) {
    this.playingWebRtcEndpoint.addIceCandidate(candidate);
  }
}
 
Example #7
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public void setWebRtcEndpoint(WebRtcEndpoint webRtcEndpoint) {
  this.webRtcEndpoint = webRtcEndpoint;

  if (this.webRtcEndpoint != null) {
    for (IceCandidate e : candidateList) {
      this.webRtcEndpoint.addIceCandidate(e);
    }
    this.candidateList.clear();
  }
}
 
Example #8
Source File: CallHandler.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
  final JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class);

  final UserSession user = registry.getBySession(session);

  if (user != null) {
    log.debug("Incoming message from user '{}': {}", user.getName(), jsonMessage);
  } else {
    log.debug("Incoming message from new user: {}", jsonMessage);
  }

  switch (jsonMessage.get("id").getAsString()) {
    case "joinRoom":
      joinRoom(jsonMessage, session);
      break;
    case "receiveVideoFrom":
      final String senderName = jsonMessage.get("sender").getAsString();
      final UserSession sender = registry.getByName(senderName);
      final String sdpOffer = jsonMessage.get("sdpOffer").getAsString();
      user.receiveVideoFrom(sender, sdpOffer);
      break;
    case "leaveRoom":
      leaveRoom(user);
      break;
    case "onIceCandidate":
      JsonObject candidate = jsonMessage.get("candidate").getAsJsonObject();

      if (user != null) {
        IceCandidate cand = new IceCandidate(candidate.get("candidate").getAsString(),
            candidate.get("sdpMid").getAsString(), candidate.get("sdpMLineIndex").getAsInt());
        user.addCandidate(cand, jsonMessage.get("name").getAsString());
      }
      break;
    default:
      break;
  }
}
 
Example #9
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public void addCandidate(IceCandidate candidate, String name) {
  if (this.name.compareTo(name) == 0) {
    outgoingMedia.addIceCandidate(candidate);
  } else {
    WebRtcEndpoint webRtc = incomingMedia.get(name);
    if (webRtc != null) {
      webRtc.addIceCandidate(candidate);
    }
  }
}
 
Example #10
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public void setWebRtcEndpoint(WebRtcEndpoint webRtcEndpoint) {
  this.webRtcEndpoint = webRtcEndpoint;

  for (IceCandidate e : candidateList) {
    this.webRtcEndpoint.addIceCandidate(e);
  }
  this.candidateList.clear();
}
 
Example #11
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public void addCandidate(IceCandidate candidate) {
  if (this.webRtcEndpoint != null) {
    this.webRtcEndpoint.addIceCandidate(candidate);
  } else {
    candidateList.add(candidate);
  }
}
 
Example #12
Source File: MediaEndpoint.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new {@link IceCandidate} received gathered by the remote peer of this
 * {@link WebRtcEndpoint}.
 *
 * @param candidate
 *          the remote candidate
 */
public synchronized void addIceCandidate(IceCandidate candidate) throws RoomException {
  if (!this.isWeb()) {
    throw new RoomException(Code.MEDIA_NOT_A_WEB_ENDPOINT_ERROR_CODE, "Operation not supported");
  }
  if (webEndpoint == null) {
    candidates.addLast(candidate);
  } else {
    internalAddIceCandidate(candidate);
  }
}
 
Example #13
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public void setWebRtcEndpoint(WebRtcEndpoint webRtcEndpoint) {
  this.webRtcEndpoint = webRtcEndpoint;

  if (this.webRtcEndpoint != null) {
    for (IceCandidate e : candidateList) {
      this.webRtcEndpoint.addIceCandidate(e);
    }
    this.candidateList.clear();
  }
}
 
Example #14
Source File: Participant.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
public void addIceCandidate(String endpointName, IceCandidate iceCandidate) {
  if (this.name.equals(endpointName)) {
    this.publisher.addIceCandidate(iceCandidate);
  } else {
    this.getNewOrExistingSubscriber(endpointName).addIceCandidate(iceCandidate);
  }
}
 
Example #15
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
public void addCandidate(IceCandidate candidate) {
  if (this.webRtcEndpoint != null) {
    this.webRtcEndpoint.addIceCandidate(candidate);
  } else {
    candidateList.add(candidate);
  }

  if (this.playingWebRtcEndpoint != null) {
    this.playingWebRtcEndpoint.addIceCandidate(candidate);
  }
}
 
Example #16
Source File: KStream.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
public void addCandidate(IceCandidate candidate, String uid) {
	if (this.uid.equals(uid)) {
		outgoingMedia.addIceCandidate(candidate);
	} else {
		WebRtcEndpoint endpoint = listeners.get(uid);
		log.debug("Add candidate for {}, listener found ? {}", uid, endpoint != null);
		if (endpoint != null) {
			endpoint.addIceCandidate(candidate);
		}
	}
}
 
Example #17
Source File: DefaultNotificationRoomHandler.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
@Override
public void onIceCandidate(String roomName, String participantId, String endpointName,
    IceCandidate candidate) {
  JsonObject params = new JsonObject();
  params.addProperty(ProtocolElements.ICECANDIDATE_EPNAME_PARAM, endpointName);
  params.addProperty(ProtocolElements.ICECANDIDATE_SDPMLINEINDEX_PARAM,
      candidate.getSdpMLineIndex());
  params.addProperty(ProtocolElements.ICECANDIDATE_SDPMID_PARAM, candidate.getSdpMid());
  params.addProperty(ProtocolElements.ICECANDIDATE_CANDIDATE_PARAM, candidate.getCandidate());
  notifService.sendNotification(participantId, ProtocolElements.ICECANDIDATE_METHOD, params);
}
 
Example #18
Source File: KurentoSessionEventsHandler.java    From openvidu with Apache License 2.0 5 votes vote down vote up
public void onIceCandidate(String roomName, String participantPrivateId, String senderPublicId, String endpointName,
		IceCandidate candidate) {
	JsonObject params = new JsonObject();

	params.addProperty(ProtocolElements.ICECANDIDATE_SENDERCONNECTIONID_PARAM, senderPublicId);
	params.addProperty(ProtocolElements.ICECANDIDATE_EPNAME_PARAM, endpointName);
	params.addProperty(ProtocolElements.ICECANDIDATE_SDPMLINEINDEX_PARAM, candidate.getSdpMLineIndex());
	params.addProperty(ProtocolElements.ICECANDIDATE_SDPMID_PARAM, candidate.getSdpMid());
	params.addProperty(ProtocolElements.ICECANDIDATE_CANDIDATE_PARAM, candidate.getCandidate());
	rpcNotificationService.sendNotification(participantPrivateId, ProtocolElements.ICECANDIDATE_METHOD, params);
}
 
Example #19
Source File: KTestStream.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
private void addIceListener(IWsClient inClient) {
	webRtcEndpoint.addIceCandidateFoundListener(evt -> {
			IceCandidate cand = evt.getCandidate();
			WebSocketHelper.sendClient(inClient, newTestKurentoMsg()
					.put("id", "iceCandidate")
					.put(PARAM_CANDIDATE, new JSONObject()
							.put(PARAM_CANDIDATE, cand.getCandidate())
							.put("sdpMid", cand.getSdpMid())
							.put("sdpMLineIndex", cand.getSdpMLineIndex())));
		});
}
 
Example #20
Source File: TestStreamProcessor.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
void onMessage(IWsClient c, final String cmdId, JSONObject msg) {
	KTestStream user = getByUid(c.getUid());
	switch (cmdId) {
		case "wannaRecord":
			WebSocketHelper.sendClient(c, newTestKurentoMsg()
					.put("id", "canRecord")
					.put(PARAM_ICE, kHandler.getTurnServers(null, true))
					);
			break;
		case "record":
			if (user != null) {
				user.release(this);
			}
			user = new KTestStream(c, msg, createTestPipeline());
			streamByUid.put(c.getUid(), user);
			break;
		case "iceCandidate":
			JSONObject candidate = msg.getJSONObject(PARAM_CANDIDATE);
			if (user != null) {
				IceCandidate cand = new IceCandidate(candidate.getString(PARAM_CANDIDATE),
						candidate.getString("sdpMid"), candidate.getInt("sdpMLineIndex"));
				user.addCandidate(cand);
			}
			break;
		case "wannaPlay":
			WebSocketHelper.sendClient(c, newTestKurentoMsg()
					.put("id", "canPlay")
					.put(PARAM_ICE, kHandler.getTurnServers(null, true))
					);
			break;
		case "play":
			if (user != null) {
				user.play(c, msg, createTestPipeline());
			}
			break;
		default:
			//no-op
			break;
	}
}
 
Example #21
Source File: MediaEndpoint.java    From openvidu with Apache License 2.0 5 votes vote down vote up
/**
 * If supported, it registers a listener for when a new {@link IceCandidate} is
 * gathered by the internal endpoint ({@link WebRtcEndpoint}) and sends it to
 * the remote User Agent as a notification using the messaging capabilities of
 * the {@link Participant}.
 *
 * @see WebRtcEndpoint#addOnIceCandidateListener(org.kurento.client.EventListener)
 * @see Participant#sendIceCandidate(String, IceCandidate)
 * @throws OpenViduException if thrown, unable to register the listener
 */
protected void registerOnIceCandidateEventListener(String senderPublicId) throws OpenViduException {
	if (!this.isWeb()) {
		return;
	}
	if (webEndpoint == null) {
		throw new OpenViduException(Code.MEDIA_WEBRTC_ENDPOINT_ERROR_CODE,
				"Can't register event listener for null WebRtcEndpoint (ep: " + endpointName + ")");
	}
	webEndpoint.addIceCandidateFoundListener(event -> {
		final IceCandidate candidate = event.getCandidate();
		gatheredCandidateList.add(candidate);
		owner.sendIceCandidate(senderPublicId, endpointName, candidate);
	});
}
 
Example #22
Source File: KurentoParticipant.java    From openvidu with Apache License 2.0 5 votes vote down vote up
public void addIceCandidate(String endpointName, IceCandidate iceCandidate) {
	if (this.getParticipantPublicId().equals(endpointName)) {
		this.publisher.addIceCandidate(iceCandidate);
	} else {
		this.getNewOrExistingSubscriber(endpointName).addIceCandidate(iceCandidate);
	}
}
 
Example #23
Source File: MediaEndpoint.java    From openvidu with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new {@link IceCandidate} received gathered by the remote peer of this
 * {@link WebRtcEndpoint}.
 *
 * @param candidate the remote candidate
 */
public synchronized void addIceCandidate(IceCandidate candidate) throws OpenViduException {
	if (!this.isWeb()) {
		throw new OpenViduException(Code.MEDIA_NOT_A_WEB_ENDPOINT_ERROR_CODE, "Operation not supported");
	}
	if (webEndpoint == null) {
		candidates.addLast(candidate);
	} else {
		internalAddIceCandidate(candidate);
	}
}
 
Example #24
Source File: PlayerHandler.java    From kurento-tutorial-java with Apache License 2.0 5 votes vote down vote up
private void onIceCandidate(String sessionId, JsonObject jsonMessage) {
  UserSession user = users.get(sessionId);

  if (user != null) {
    JsonObject jsonCandidate = jsonMessage.get("candidate").getAsJsonObject();
    IceCandidate candidate =
        new IceCandidate(jsonCandidate.get("candidate").getAsString(), jsonCandidate
            .get("sdpMid").getAsString(), jsonCandidate.get("sdpMLineIndex").getAsInt());
    user.getWebRtcEndpoint().addIceCandidate(candidate);
  }
}
 
Example #25
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
public void addCandidate(IceCandidate candidate) {
  webRtcEndpoint.addIceCandidate(candidate);
}
 
Example #26
Source File: CallHandler.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
  JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class);
  UserSession user = registry.getBySession(session);

  if (user != null) {
    log.debug("Incoming message from user '{}': {}", user.getName(), jsonMessage);
  } else {
    log.debug("Incoming message from new user: {}", jsonMessage);
  }

  switch (jsonMessage.get("id").getAsString()) {
    case "register":
      register(session, jsonMessage);
      break;
    case "call":
      call(user, jsonMessage);
      break;
    case "incomingCallResponse":
      incomingCallResponse(user, jsonMessage);
      break;
    case "play":
      play(user, jsonMessage);
      break;
    case "onIceCandidate": {
      JsonObject candidate = jsonMessage.get("candidate").getAsJsonObject();

      if (user != null) {
        IceCandidate cand =
            new IceCandidate(candidate.get("candidate").getAsString(), candidate.get("sdpMid")
                .getAsString(), candidate.get("sdpMLineIndex").getAsInt());
        user.addCandidate(cand);
      }
      break;
    }
    case "stop":
      stop(session);
      releasePipeline(user);
      break;
    case "stopPlay":
      releasePipeline(user);
      break;
    default:
      break;
  }
}
 
Example #27
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
public void addCandidate(IceCandidate candidate) {
  webRtcEndpoint.addIceCandidate(candidate);
}
 
Example #28
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
public void addCandidate(IceCandidate candidate) {
  webRtcEndpoint.addIceCandidate(candidate);
}
 
Example #29
Source File: HelloWorldRecHandler.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
  JsonObject jsonMessage = gson.fromJson(message.getPayload(), JsonObject.class);

  log.debug("Incoming message: {}", jsonMessage);

  UserSession user = registry.getBySession(session);
  if (user != null) {
    log.debug("Incoming message from user '{}': {}", user.getId(), jsonMessage);
  } else {
    log.debug("Incoming message from new user: {}", jsonMessage);
  }

  switch (jsonMessage.get("id").getAsString()) {
    case "start":
      start(session, jsonMessage);
      break;
    case "stop":
    case "stopPlay":
      if (user != null) {
        user.release();
      }
      break;
    case "play":
      play(user, session, jsonMessage);
      break;
    case "onIceCandidate": {
      JsonObject jsonCandidate = jsonMessage.get("candidate").getAsJsonObject();

      if (user != null) {
        IceCandidate candidate = new IceCandidate(jsonCandidate.get("candidate").getAsString(),
            jsonCandidate.get("sdpMid").getAsString(),
            jsonCandidate.get("sdpMLineIndex").getAsInt());
        user.addCandidate(candidate);
      }
      break;
    }
    default:
      sendError(session, "Invalid message with id " + jsonMessage.get("id").getAsString());
      break;
  }
}
 
Example #30
Source File: UserSession.java    From kurento-tutorial-java with Apache License 2.0 4 votes vote down vote up
public void addCandidate(IceCandidate candidate) {
  webRtcEndpoint.addIceCandidate(candidate);
}