@Override public void onIceCandidate(final IceCandidate iceCandidate) { mExecutorService.execute(new Runnable() { @Override public void run() { JSONObject candidate = new JSONObject(); jsonPut(candidate, "monitor_id", curMonitorId); jsonPut(candidate, "type", "candidate"); jsonPut(candidate, "label", iceCandidate.sdpMLineIndex); jsonPut(candidate, "id", iceCandidate.sdpMid); jsonPut(candidate, "candidate", iceCandidate.sdp); // Sending IceCandidate to monitor. Log.d(TAG, "Sending IceCandidate to monitor:" + candidate.toString()); sendMessage(candidate); } }); }
@Override public void sendLocalIceCandidate(final IceCandidate candidate) { executor.execute(new Runnable() { @Override public void run() { JSONObject json = new JSONObject(); jsonPut(json, "type", "candidate"); jsonPut(json, "label", candidate.sdpMLineIndex); jsonPut(json, "id", candidate.sdpMid); jsonPut(json, "candidate", candidate.sdp); if (roomState != ConnectionState.CONNECTED) { reportError("Sending ICE candidate in non connected state."); return; } sendMessage(json.toString()); } }); }
/** Send removed Ice candidates to the other participant. */ @Override public void sendLocalIceCandidateRemovals(final IceCandidate[] candidates) { executor.execute(new Runnable() { @Override public void run() { JSONObject json = new JSONObject(); jsonPut(json, "type", "remove-candidates"); JSONArray jsonArray = new JSONArray(); for (final IceCandidate candidate : candidates) { jsonArray.put(toJsonCandidate(candidate)); } jsonPut(json, "candidates", jsonArray); if (roomState != ConnectionState.CONNECTED) { reportError("Sending ICE candidate removals in non connected state."); return; } sendMessage(json.toString()); } }); }
/** * Send removed Ice candidates to the other participant. */ @Override public void sendLocalIceCandidateRemovals(final IceCandidate[] candidates) { executor.execute(new Runnable() { @Override public void run() { JSONObject json = new JSONObject(); jsonPut(json, "type", "remove-candidates"); JSONArray jsonArray = new JSONArray(); for (final IceCandidate candidate : candidates) { jsonArray.put(toJsonCandidate(candidate)); } jsonPut(json, "candidates", jsonArray); if (roomState != ConnectionState.CONNECTED) { reportError("Sending ICE candidate removals in non connected state."); return; } sendMessage(json.toString()); } }); }
@Override public void onIceCandidate(final IceCandidate candidate) { synchronized (iceCandidateEvent) { Log.d(TAG, "IceCandidate #" + iceCandidates.size() + " : " + candidate.toString()); if (loopback) { // Loopback local ICE candidate in a separate thread to avoid adding // remote ICE candidate in a local ICE candidate callback. signalingExecutor.execute(new Runnable() { @Override public void run() { pcClient.addRemoteIceCandidate(candidate); } }); } iceCandidates.add(candidate); iceCandidateEvent.notifyAll(); } }
@Override public void onIceCandidate(final IceCandidate candidate) { try { JSONObject payload = new JSONObject(); payload.put("label", candidate.sdpMLineIndex); payload.put("id", candidate.sdpMid); payload.put("candidate", candidate.sdp); JSONObject message = new JSONObject(); message.put("to", friendName); message.put("type", "candidate"); message.put("payload", payload); MqttClientHelper.getInstance(getApplicationContext()).publishMessage(friendName, message.toString()); } catch (JSONException e) { e.printStackTrace(); } }
@Override public void onRoomNotification(RoomNotification notification) { Log.i(TAG, "OnRoomNotification (state=" + callState.toString() + "):" + notification); Map<String, Object> map = notification.getParams(); if(notification.getMethod().equals(RoomListener.METHOD_ICE_CANDIDATE)) { String sdpMid = map.get("sdpMid").toString(); int sdpMLineIndex = Integer.valueOf(map.get("sdpMLineIndex").toString()); String sdp = map.get("candidate").toString(); IceCandidate ic = new IceCandidate(sdpMid, sdpMLineIndex, sdp); if (callState == CallState.PUBLISHING || callState == CallState.PUBLISHED) { nbmWebRTCPeer.addRemoteIceCandidate(ic, "local"); } else { nbmWebRTCPeer.addRemoteIceCandidate(ic, notification.getParam("endpointName").toString()); } } // Somebody in the room published their video else if(notification.getMethod().equals(RoomListener.METHOD_PARTICIPANT_PUBLISHED)) { mHandler.postDelayed(offerWhenReady, 2000); } }
private void consumeIceCandidate(@Nonnull final Element iceCandidateElement, @Nonnull final String id, final boolean creating) { final Node sdpElement = Observable.fromIterable( DomUtils.convertToList(iceCandidateElement.getChildNodes()) ).filter(it -> "sdp".equals(it.getLocalName())).firstElement().blockingGet(); final String sdp = sdpElement == null ? "" : convertSdpElementsToString(sdpElement); this.eventStream.onNext(new IceCandidateReceivedEvent( new IceCandidate( iceCandidateElement.getAttribute("sdpMid"), Integer.getInteger(iceCandidateElement.getAttribute("sdpMLineIndex")), sdp ), id, creating )); }
@Override public void onTreeNotification(TreeNotification notification) { Log.i(TAG, "OnTreeNotification (state=" + treeState.toString() + "):" + notification); if(notification.getMethod().equals("iceCandidate")) { Map<String, Object> map = notification.getParams(); String sdpMid = map.get("sdpMid").toString(); int sdpMLineIndex = Integer.valueOf(map.get("sdpMLineIndex").toString()); String sdp = map.get("candidate").toString(); IceCandidate ic = new IceCandidate(sdpMid, sdpMLineIndex, sdp); nbmWebRTCPeer.addRemoteIceCandidate(ic, "derp"); } }
@Override public void onIceCandidate(IceCandidate iceCandidate, NBMPeerConnection nbmPeerConnection) { if (sinkId != null) { sendIceCandidateRequestId = ++Constants.id; MainActivity.getKurentoTreeAPIInstance().sendAddIceCandidate(treeId, sinkId, iceCandidate.sdpMid, iceCandidate.sdpMLineIndex, iceCandidate.sdp, sendIceCandidateRequestId); } else { queuedIceCandidates.add(iceCandidate); } // if (callState == CallState.PUBLISHING || callState == CallState.PUBLISHED){ // MainActivity.getKurentoRoomAPIInstance().sendOnIceCandidate(this.username, iceCandidate.sdp, // iceCandidate.sdpMid, Integer.toString(iceCandidate.sdpMLineIndex), sendIceCandidateRequestId); // } else { // MainActivity.getKurentoRoomAPIInstance().sendOnIceCandidate(this.calluser, iceCandidate.sdp, // iceCandidate.sdpMid, Integer.toString(iceCandidate.sdpMLineIndex), sendIceCandidateRequestId); // } }
@Override public void onTreeResponse(TreeResponse response) { Log.d(TAG, "OnTreeResponse:" + response); if (Integer.valueOf(response.getId()) == addSinkRequestId){ sinkId = response.getValue("sinkId"); while (!queuedIceCandidates.isEmpty()) { IceCandidate ic = queuedIceCandidates.remove(0); onIceCandidate(ic, null); } SessionDescription sd = new SessionDescription(SessionDescription.Type.ANSWER, response.getValue("answerSdp")); treeState = TreeState.JOINED; nbmWebRTCPeer.processAnswer(sd, "remote"); } else { //NOP } }
@Override public void onTreeNotification(TreeNotification notification) { Log.i(TAG, "OnTreeNotification (state=" + treeState.toString() + "):" + notification); if(notification.getMethod().equals("iceCandidate")) { Map<String, Object> map = notification.getParams(); String sdpMid = map.get("sdpMid").toString(); int sdpMLineIndex = Integer.valueOf(map.get("sdpMLineIndex").toString()); String sdp = map.get("candidate").toString(); IceCandidate ic = new IceCandidate(sdpMid, sdpMLineIndex, sdp); nbmWebRTCPeer.addRemoteIceCandidate(ic, "remote"); } }
@Override public void onIceCandidate(final MediaConnection conn, final IceCandidate candidate) { try { JSONObject candidateMsg = new JSONObject(); candidateMsg.put("candidate", candidate.sdp); candidateMsg.put("sdpMLineIndex", candidate.sdpMLineIndex); candidateMsg.put("sdpMid", candidate.sdpMid); JSONObject payload = new JSONObject(); payload.put("candidate", candidateMsg); payload.put("type", "media"); payload.put("connectionId", conn.getConnectionId()); JSONObject message = new JSONObject(); message.put("type", "CANDIDATE"); message.put("payload", payload); message.put("dst", conn.getPeerId()); mSignaling.queueMessage(message.toString()); } catch (Exception e) { if (BuildConfig.DEBUG) { Log.e(TAG, "Failed to create a message that send to a signaling server.", e); } } }
/** * Common constructor logic * * @param channel The signaling channel to use for the call */ private void commonConstructor(RespokeSignalingChannel channel) { signalingChannel = channel; iceServers = new ArrayList<PeerConnection.IceServer>(); queuedLocalCandidates = new ArrayList<IceCandidate>(); queuedRemoteCandidates = new ArrayList<IceCandidate>(); collectedLocalCandidates = new ArrayList<IceCandidate>(); sessionID = Respoke.makeGUID(); timestamp = new Date(); queuedRemoteCandidatesSemaphore = new Semaphore(1); // remote candidates queue mutex localCandidatesSemaphore = new Semaphore(1); // local candidates queue mutex if (null != signalingChannel) { RespokeSignalingChannel.Listener signalingChannelListener = signalingChannel.GetListener(); if (null != signalingChannelListener) { signalingChannelListener.callCreated(this); } } //TODO resign active handler? }
private void handleLocalCandidate(IceCandidate candidate) { try { // Start critical block localCandidatesSemaphore.acquire(); // Collect candidates that are generated in addition to sending them immediately. // This allows us to send a 'finalCandidates' signal when the iceGatheringState has // changed to COMPLETED. 'finalCandidates' are used by the backend to smooth inter-op // between clients that generate trickle ice, and clients that do not support trickle ice. collectedLocalCandidates.add(candidate); if (null != queuedLocalCandidates) { queuedLocalCandidates.add(candidate); } else { sendLocalCandidate(candidate); } // End critical block localCandidatesSemaphore.release(); } catch (InterruptedException e) { Log.d(TAG, "Error with local candidates semaphore"); } }
private void drainRemoteCandidates() { try { // Start critical block queuedRemoteCandidatesSemaphore.acquire(); for (IceCandidate candidate : queuedRemoteCandidates) { peerConnection.addIceCandidate(candidate); } queuedRemoteCandidates = null; // End critical block queuedRemoteCandidatesSemaphore.release(); } catch (InterruptedException e) { Log.d(TAG, "Error with remote candidates semaphore"); } }
private void drainLocalCandidates() { try { // Start critical block localCandidatesSemaphore.acquire(); for (IceCandidate candidate : queuedLocalCandidates) { sendLocalCandidate(candidate); } queuedLocalCandidates = null; // End critical block localCandidatesSemaphore.release(); } catch (InterruptedException e) { Log.d(TAG, "Error with local candidates semaphore"); } }
private JSONArray getLocalCandidateJSONArray() { JSONArray result = new JSONArray(); try { // Begin critical block localCandidatesSemaphore.acquire(); for (IceCandidate candidate: collectedLocalCandidates) { result.put(getCandidateDict(candidate)); } // End critical block localCandidatesSemaphore.release(); } catch (InterruptedException e) { e.printStackTrace(); } return result; }
public SignalingParameters( List<PeerConnection.IceServer> iceServers, boolean initiator, String clientId, String sipUrl, String wssPostUrl, SessionDescription offerSdp, List<IceCandidate> iceCandidates, HashMap<String, String> sipHeaders, boolean videoEnabled) { this.iceServers = iceServers; this.initiator = initiator; this.clientId = clientId; this.sipUrl = sipUrl; this.wssPostUrl = wssPostUrl; this.offerSdp = offerSdp; this.answerSdp = null; this.iceCandidates = iceCandidates; this.sipHeaders = sipHeaders; this.videoEnabled = videoEnabled; //this.answerIceCandidates = null; }
@Override public void onIceCandidate(final IceCandidate candidate) { Log.d(TAG, "onIceCandidate"); WritableMap params = Arguments.createMap(); params.putInt("id", id); WritableMap candidateParams = Arguments.createMap(); candidateParams.putInt("sdpMLineIndex", candidate.sdpMLineIndex); candidateParams.putString("sdpMid", candidate.sdpMid); candidateParams.putString("candidate", candidate.sdp); params.putMap("candidate", candidateParams); webRTCModule.sendEvent("peerConnectionGotICECandidate", params); }
private void handleRemoteIceCandidate(Intent intent) { Log.w(TAG, "handleRemoteIceCandidate..."); if (peerConnection != null && Util.isEquals(this.callId, getCallId(intent))) { peerConnection.addIceCandidate(new IceCandidate(intent.getStringExtra(EXTRA_ICE_SDP_MID), intent.getIntExtra(EXTRA_ICE_SDP_LINE_INDEX, 0), intent.getStringExtra(EXTRA_ICE_SDP))); } }
@Override public void onIceCandidate(IceCandidate candidate) { Log.w(TAG, "onIceCandidate:" + candidate); Intent intent = new Intent(this, WebRtcCallService.class); intent.setAction(ACTION_ICE_CANDIDATE); intent.putExtra(EXTRA_ICE_SDP_MID, candidate.sdpMid); intent.putExtra(EXTRA_ICE_SDP_LINE_INDEX, candidate.sdpMLineIndex); intent.putExtra(EXTRA_ICE_SDP, candidate.sdp); startService(intent); }
public void execute(String peerId, JSONObject payload) throws JSONException { Log.d("AICAction","AddIceCandidateAction"); PeerConnection pc = peers.get(peerId).pc; if (pc.getRemoteDescription() != null) { IceCandidate candidate = new IceCandidate( payload.getString("sdpMid"), payload.getInt("sdpMLineIndex"), payload.getString("candidate") ); pc.addIceCandidate(candidate); } }
@Override public void onIceCandidate(final IceCandidate candidate) { try { JSONObject payload = new JSONObject(); payload.put("sdpMLineIndex", candidate.sdpMLineIndex); payload.put("sdpMid", candidate.sdpMid); payload.put("candidate", candidate.sdp); pcClient.transmitMessage(id, payload); } catch (JSONException e) { e.printStackTrace(); } }
public void addRemoteIceCandidate(final IceCandidate candidate) { executor.execute(new Runnable() { @Override public void run() { if (peerConnection != null && !isError) { if (queuedRemoteCandidates != null) { queuedRemoteCandidates.add(candidate); } else { peerConnection.addIceCandidate(candidate); } } } }); }
public void removeRemoteIceCandidates(final IceCandidate[] candidates) { executor.execute(new Runnable() { @Override public void run() { if (peerConnection == null || isError) { return; } // Drain the queued remote candidates if there is any so that // they are processed in the proper order. drainCandidates(); peerConnection.removeIceCandidates(candidates); } }); }
private void drainCandidates() { if (queuedRemoteCandidates != null) { Log.d(TAG, "Add " + queuedRemoteCandidates.size() + " remote candidates"); for (IceCandidate candidate : queuedRemoteCandidates) { peerConnection.addIceCandidate(candidate); } queuedRemoteCandidates = null; } }
@Override public void onIceCandidate(final IceCandidate candidate) { executor.execute(new Runnable() { @Override public void run() { events.onIceCandidate(candidate); } }); }
@Override public void onIceCandidatesRemoved(final IceCandidate[] candidates) { executor.execute(new Runnable() { @Override public void run() { events.onIceCandidatesRemoved(candidates); } }); }
public SignalingParameters(List<PeerConnection.IceServer> iceServers, boolean initiator, String clientId, String wssUrl, String wssPostUrl, SessionDescription offerSdp, List<IceCandidate> iceCandidates) { this.iceServers = iceServers; this.initiator = initiator; this.clientId = clientId; this.wssUrl = wssUrl; this.wssPostUrl = wssPostUrl; this.offerSdp = offerSdp; this.iceCandidates = iceCandidates; }
@Override public void sendLocalIceCandidate(final IceCandidate candidate) { handler.post(new Runnable() { @Override public void run() { JSONObject json = new JSONObject(); jsonPut(json, "type", "candidate"); jsonPut(json, "label", candidate.sdpMLineIndex); jsonPut(json, "id", candidate.sdpMid); jsonPut(json, "candidate", candidate.sdp); if (initiator) { // Call initiator sends ice candidates to GAE server. if (roomState != ConnectionState.CONNECTED) { reportError("Sending ICE candidate in non connected state."); return; } sendPostMessage(MessageType.MESSAGE, messageUrl, json.toString()); if (connectionParameters.loopback) { events.onRemoteIceCandidate(candidate); } } else { // Call receiver sends ice candidates to websocket server. wsClient.send(json.toString()); } } }); }
@Override public void sendLocalIceCandidateRemovals(final IceCandidate[] candidates) { handler.post(new Runnable() { @Override public void run() { JSONObject json = new JSONObject(); jsonPut(json, "type", "remove-candidates"); JSONArray jsonArray = new JSONArray(); for (final IceCandidate candidate : candidates) { jsonArray.put(toJsonCandidate(candidate)); } jsonPut(json, "candidates", jsonArray); if (initiator) { // Call initiator sends ice candidates to GAE server. if (roomState != ConnectionState.CONNECTED) { reportError("Sending ICE candidate removals in non connected state."); return; } sendPostMessage(MessageType.MESSAGE, messageUrl, json.toString()); if (connectionParameters.loopback) { events.onRemoteIceCandidatesRemoved(candidates); } } else { // Call receiver sends ice candidates to websocket server. wsClient.send(json.toString()); } } }); }
private JSONObject toJsonCandidate(final IceCandidate candidate) { JSONObject json = new JSONObject(); jsonPut(json, "label", candidate.sdpMLineIndex); jsonPut(json, "id", candidate.sdpMid); jsonPut(json, "candidate", candidate.sdp); return json; }
private static JSONObject toJsonCandidate(final IceCandidate candidate) { JSONObject json = new JSONObject(); jsonPut(json, "label", candidate.sdpMLineIndex); jsonPut(json, "id", candidate.sdpMid); jsonPut(json, "candidate", candidate.sdp); return json; }