Java Code Examples for org.webrtc.PeerConnection#IceServer
The following examples show how to use
org.webrtc.PeerConnection#IceServer .
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: RCConnection.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 6 votes |
private PeerConnection.IceServer external2InternalIceServer(Map<String, String> iceServer) { String url = ""; if (iceServer.containsKey(IceServersKeys.ICE_SERVER_URL)) { url = iceServer.get(IceServersKeys.ICE_SERVER_URL); } String username = ""; if (iceServer.containsKey(IceServersKeys.ICE_SERVER_USERNAME)) { username = iceServer.get(IceServersKeys.ICE_SERVER_USERNAME); } String password = ""; if (iceServer.containsKey(IceServersKeys.ICE_SERVER_PASSWORD)) { password = iceServer.get(IceServersKeys.ICE_SERVER_PASSWORD); } return new PeerConnection.IceServer(url, username, password); }
Example 2
Source File: PeersManager.java From WebRTCapp with Apache License 2.0 | 6 votes |
private void createLocalPeerConnection(MediaConstraints sdpConstraints) { final List<PeerConnection.IceServer> iceServers = new ArrayList<>(); PeerConnection.IceServer iceServer = new PeerConnection.IceServer("stun:stun.l.google.com:19302"); iceServers.add(iceServer); localPeer = peerConnectionFactory.createPeerConnection(iceServers, sdpConstraints, new CustomPeerConnectionObserver("localPeerCreation") { @Override public void onIceCandidate(IceCandidate iceCandidate) { super.onIceCandidate(iceCandidate); Map<String, String> iceCandidateParams = new HashMap<>(); iceCandidateParams.put("sdpMid", iceCandidate.sdpMid); iceCandidateParams.put("sdpMLineIndex", Integer.toString(iceCandidate.sdpMLineIndex)); iceCandidateParams.put("candidate", iceCandidate.sdp); if (webSocketAdapter.getUserId() != null) { iceCandidateParams.put("endpointName", webSocketAdapter.getUserId()); webSocketAdapter.sendJson(webSocket, "onIceCandidate", iceCandidateParams); } else { webSocketAdapter.addIceCandidate(iceCandidateParams); } } }); }
Example 3
Source File: SignalingParameters.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 6 votes |
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; }
Example 4
Source File: Peer.java From webrtc_android with MIT License | 5 votes |
public Peer(PeerConnectionFactory factory, List<PeerConnection.IceServer> list, String userId, IPeerEvent event) { mFactory = factory; mIceLis = list; mEvent = event; mUserId = userId; queuedRemoteCandidates = new ArrayList<>(); this.pc = createPeerConnection(); Log.d("dds_test", "create Peer:" + mUserId); }
Example 5
Source File: JingleRtpConnection.java From Conversations with GNU General Public License v3.0 | 5 votes |
private void setupWebRTC(final Set<Media> media, final List<PeerConnection.IceServer> iceServers) throws WebRTCWrapper.InitializationException { this.jingleConnectionManager.ensureConnectionIsRegistered(this); final AppRTCAudioManager.SpeakerPhonePreference speakerPhonePreference; if (media.contains(Media.VIDEO)) { speakerPhonePreference = AppRTCAudioManager.SpeakerPhonePreference.SPEAKER; } else { speakerPhonePreference = AppRTCAudioManager.SpeakerPhonePreference.EARPIECE; } this.webRTCWrapper.setup(this.xmppConnectionService, speakerPhonePreference); this.webRTCWrapper.initializePeerConnection(media, iceServers); }
Example 6
Source File: RCConnection.java From restcomm-android-sdk with GNU Affero General Public License v3.0 | 5 votes |
private LinkedList<PeerConnection.IceServer> external2InternalIceServers(List<Map<String, String>> iceServers) { RCLogger.e(TAG, "Using manual ICE server discovery"); LinkedList<PeerConnection.IceServer> iceServersInternal = new LinkedList<PeerConnection.IceServer>(); for (Map<String, String> iceServer : iceServers) { PeerConnection.IceServer iceServerInternal = external2InternalIceServer(iceServer); iceServersInternal.add(iceServerInternal); RCLogger.i(TAG, "ICE server: " + iceServerInternal.uri + ", " + iceServerInternal.username); } return iceServersInternal; }
Example 7
Source File: PnSignalingParams.java From android-webrtc-api with MIT License | 5 votes |
public PnSignalingParams( List<PeerConnection.IceServer> iceServers, MediaConstraints pcConstraints, MediaConstraints videoConstraints, MediaConstraints audioConstraints) { this.iceServers = (iceServers==null) ? defaultIceServers() : iceServers; this.pcConstraints = (pcConstraints==null) ? defaultPcConstraints() : pcConstraints; this.videoConstraints = (videoConstraints==null) ? defaultVideoConstraints() : videoConstraints; this.audioConstraints = (audioConstraints==null) ? defaultAudioConstraints() : audioConstraints; }
Example 8
Source File: AppRTCClient.java From WebRTCDemo with BSD 3-Clause "New" or "Revised" License | 5 votes |
public AppRTCSignalingParameters( List<PeerConnection.IceServer> iceServers, String gaeBaseHref, String channelToken, String postMessageUrl, boolean initiator, MediaConstraints pcConstraints, MediaConstraints videoConstraints, MediaConstraints audioConstraints) { this.iceServers = iceServers; this.gaeBaseHref = gaeBaseHref; this.channelToken = channelToken; this.postMessageUrl = postMessageUrl; this.initiator = initiator; this.pcConstraints = pcConstraints; this.videoConstraints = videoConstraints; this.audioConstraints = audioConstraints; }
Example 9
Source File: RoomParametersFetcher.java From sample-videoRTC with Apache License 2.0 | 5 votes |
private List<PeerConnection.IceServer> requestTurnServers(String url) throws IOException, JSONException { List<PeerConnection.IceServer> turnServers = new ArrayList<>(); Log.d(TAG, "Request TURN from: " + url); HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setDoOutput(true); connection.setRequestProperty("REFERER", "https://appr.tc"); connection.setConnectTimeout(TURN_HTTP_TIMEOUT_MS); connection.setReadTimeout(TURN_HTTP_TIMEOUT_MS); int responseCode = connection.getResponseCode(); if (responseCode != 200) { throw new IOException("Non-200 response when requesting TURN server from " + url + " : " + connection.getHeaderField(null)); } InputStream responseStream = connection.getInputStream(); String response = drainStream(responseStream); connection.disconnect(); Log.d(TAG, "TURN response: " + response); JSONObject responseJSON = new JSONObject(response); JSONArray iceServers = responseJSON.getJSONArray("iceServers"); for (int i = 0; i < iceServers.length(); ++i) { JSONObject server = iceServers.getJSONObject(i); JSONArray turnUrls = server.getJSONArray("urls"); String username = server.has("username") ? server.getString("username") : ""; String credential = server.has("credential") ? server.getString("credential") : ""; for (int j = 0; j < turnUrls.length(); j++) { String turnUrl = turnUrls.getString(j); PeerConnection.IceServer turnServer = PeerConnection.IceServer.builder(turnUrl) .setUsername(username) .setPassword(credential) .createIceServer(); turnServers.add(turnServer); } } return turnServers; }
Example 10
Source File: JingleRtpConnection.java From Pix-Art-Messenger with GNU General Public License v3.0 | 5 votes |
private void setupWebRTC(final Set<Media> media, final List<PeerConnection.IceServer> iceServers) throws WebRTCWrapper.InitializationException { this.jingleConnectionManager.ensureConnectionIsRegistered(this); final AppRTCAudioManager.SpeakerPhonePreference speakerPhonePreference; if (media.contains(Media.VIDEO)) { speakerPhonePreference = AppRTCAudioManager.SpeakerPhonePreference.SPEAKER; } else { speakerPhonePreference = AppRTCAudioManager.SpeakerPhonePreference.EARPIECE; } this.webRTCWrapper.setup(this.xmppConnectionService, speakerPhonePreference); this.webRTCWrapper.initializePeerConnection(media, iceServers); }
Example 11
Source File: AppRTCClient.java From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License | 5 votes |
public AppRTCSignalingParameters( List<PeerConnection.IceServer> iceServers, String gaeBaseHref, String channelToken, String postMessageUrl, boolean initiator, MediaConstraints pcConstraints, MediaConstraints videoConstraints, MediaConstraints audioConstraints) { this.iceServers = iceServers; this.gaeBaseHref = gaeBaseHref; this.channelToken = channelToken; this.postMessageUrl = postMessageUrl; this.initiator = initiator; this.pcConstraints = pcConstraints; this.videoConstraints = videoConstraints; this.audioConstraints = audioConstraints; }
Example 12
Source File: PnSignalingParams.java From android-webrtc-api with MIT License | 5 votes |
/** * Append default servers to the end of given list and set as iceServers instance variable * @param iceServers List of iceServers */ public void addIceServers(List<PeerConnection.IceServer> iceServers){ if(this.iceServers!=null) { iceServers.addAll(this.iceServers); } this.iceServers = iceServers; }
Example 13
Source File: WebRTC.java From iGap-Android with GNU Affero General Public License v3.0 | 5 votes |
PeerConnection peerConnectionInstance() { if (peerConnection == null) { List<PeerConnection.IceServer> iceServers = new ArrayList<>(); Realm realm = Realm.getDefaultInstance(); RealmCallConfig realmCallConfig = realm.where(RealmCallConfig.class).findFirst(); for (RealmIceServer ice : realmCallConfig.getIceServer()) { iceServers.add(new PeerConnection.IceServer(ice.getUrl(), ice.getUsername(), ice.getCredential())); } realm.close(); PeerConnection.RTCConfiguration configuration = new PeerConnection.RTCConfiguration(iceServers); configuration.bundlePolicy = PeerConnection.BundlePolicy.MAXBUNDLE; configuration.rtcpMuxPolicy = PeerConnection.RtcpMuxPolicy.REQUIRE; configuration.iceTransportsType = PeerConnection.IceTransportsType.RELAY; PeerConnection.Observer observer = new PeerConnectionObserver(); MediaConstraints mediaConstraints = mediaConstraintsGetInstance(); peerConnection = peerConnectionFactoryInstance().createPeerConnection(iceServers, mediaConstraints, observer); mediaStream = peerConnectionFactoryInstance().createLocalMediaStream("ARDAMS"); addAudioTrack(mediaStream); addVideoTrack(mediaStream); peerConnection.addStream(mediaStream); } return peerConnection; }
Example 14
Source File: AppRTCDemoActivity.java From WebRTCDemo with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onIceServers(List<PeerConnection.IceServer> iceServers) { factory = new PeerConnectionFactory(); MediaConstraints pcConstraints = appRtcClient.pcConstraints(); pcConstraints.optional.add( new MediaConstraints.KeyValuePair("RtpDataChannels", "true")); pc = factory.createPeerConnection(iceServers, pcConstraints, pcObserver); createDataChannelToRegressionTestBug2302(pc); // See method comment. // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging. // NOTE: this _must_ happen while |factory| is alive! // Logging.enableTracing( // "logcat:", // EnumSet.of(Logging.TraceLevel.TRACE_ALL), // Logging.Severity.LS_SENSITIVE); { final PeerConnection finalPC = pc; final Runnable repeatedStatsLogger = new Runnable() { public void run() { synchronized (quit[0]) { if (quit[0]) { return; } final Runnable runnableThis = this; if (hudView.getVisibility() == View.INVISIBLE) { vsv.postDelayed(runnableThis, 1000); return; } boolean success = finalPC.getStats(new StatsObserver() { public void onComplete(final StatsReport[] reports) { runOnUiThread(new Runnable() { public void run() { updateHUD(reports); } }); for (StatsReport report : reports) { Log.d(TAG, "Stats: " + report.toString()); } vsv.postDelayed(runnableThis, 1000); } }, null); if (!success) { throw new RuntimeException("getStats() return false!"); } } } }; vsv.postDelayed(repeatedStatsLogger, 1000); } { logAndToast("Creating local video source..."); MediaStream lMS = factory.createLocalMediaStream("ARDAMS"); if (appRtcClient.videoConstraints() != null) { VideoCapturer capturer = getVideoCapturer(); videoSource = factory.createVideoSource( capturer, appRtcClient.videoConstraints()); VideoTrack videoTrack = factory.createVideoTrack("ARDAMSv0", videoSource); videoTrack.addRenderer(new VideoRenderer(localRender)); lMS.addTrack(videoTrack); } if (appRtcClient.audioConstraints() != null) { lMS.addTrack(factory.createAudioTrack( "ARDAMSa0", factory.createAudioSource(appRtcClient.audioConstraints()))); } pc.addStream(lMS, new MediaConstraints()); } logAndToast("Waiting for ICE candidates..."); }
Example 15
Source File: VideoChatActivity.java From AndroidRTC with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_video_chat); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Bundle extras = getIntent().getExtras(); if (extras == null || !extras.containsKey(Constants.USER_NAME)) { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); Toast.makeText(this, "Need to pass username to VideoChatActivity in intent extras (Constants.USER_NAME).", Toast.LENGTH_SHORT).show(); finish(); return; } this.username = extras.getString(Constants.USER_NAME, ""); this.mChatList = getListView(); this.mChatEditText = (EditText) findViewById(R.id.chat_input); this.mCallStatus = (TextView) findViewById(R.id.call_status); // Set up the List View for chatting List<ChatMessage> ll = new LinkedList<ChatMessage>(); mChatAdapter = new ChatAdapter(this, ll); mChatList.setAdapter(mChatAdapter); // First, we initiate the PeerConnectionFactory with our application context and some options. PeerConnectionFactory.initializeAndroidGlobals( this, // Context true, // Audio Enabled true, // Video Enabled true, // Hardware Acceleration Enabled null); // Render EGL Context PeerConnectionFactory pcFactory = new PeerConnectionFactory(); this.pnRTCClient = new PnRTCClient(Constants.PUB_KEY, Constants.SUB_KEY, this.username); List<PeerConnection.IceServer> servers = getXirSysIceServers(); if (!servers.isEmpty()){ this.pnRTCClient.setSignalParams(new PnSignalingParams()); } // Returns the number of cams & front/back face device name int camNumber = VideoCapturerAndroid.getDeviceCount(); String frontFacingCam = VideoCapturerAndroid.getNameOfFrontFacingDevice(); String backFacingCam = VideoCapturerAndroid.getNameOfBackFacingDevice(); // Creates a VideoCapturerAndroid instance for the device name VideoCapturer capturer = VideoCapturerAndroid.create(frontFacingCam); // First create a Video Source, then we can make a Video Track localVideoSource = pcFactory.createVideoSource(capturer, this.pnRTCClient.videoConstraints()); VideoTrack localVideoTrack = pcFactory.createVideoTrack(VIDEO_TRACK_ID, localVideoSource); // First we create an AudioSource then we can create our AudioTrack AudioSource audioSource = pcFactory.createAudioSource(this.pnRTCClient.audioConstraints()); AudioTrack localAudioTrack = pcFactory.createAudioTrack(AUDIO_TRACK_ID, audioSource); // To create our VideoRenderer, we can use the included VideoRendererGui for simplicity // First we need to set the GLSurfaceView that it should render to this.videoView = (GLSurfaceView) findViewById(R.id.gl_surface); // Then we set that view, and pass a Runnable to run once the surface is ready VideoRendererGui.setView(videoView, null); // Now that VideoRendererGui is ready, we can get our VideoRenderer. // IN THIS ORDER. Effects which is on top or bottom remoteRender = VideoRendererGui.create(0, 0, 100, 100, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, false); localRender = VideoRendererGui.create(0, 0, 100, 100, VideoRendererGui.ScalingType.SCALE_ASPECT_FILL, true); // We start out with an empty MediaStream object, created with help from our PeerConnectionFactory // Note that LOCAL_MEDIA_STREAM_ID can be any string MediaStream mediaStream = pcFactory.createLocalMediaStream(LOCAL_MEDIA_STREAM_ID); // Now we can add our tracks. mediaStream.addTrack(localVideoTrack); mediaStream.addTrack(localAudioTrack); // First attach the RTC Listener so that callback events will be triggered this.pnRTCClient.attachRTCListener(new DemoRTCListener()); // Then attach your local media stream to the PnRTCClient. // This will trigger the onLocalStream callback. this.pnRTCClient.attachLocalMediaStream(mediaStream); // Listen on a channel. This is your "phone number," also set the max chat users. this.pnRTCClient.listenOn("Kevin"); this.pnRTCClient.setMaxConnections(1); // If the intent contains a number to dial, call it now that you are connected. // Else, remain listening for a call. if (extras.containsKey(Constants.CALL_USER)) { String callUser = extras.getString(Constants.CALL_USER, ""); connectToUser(callUser); } }
Example 16
Source File: AppRTCClient.java From WebRTCDemo with BSD 3-Clause "New" or "Revised" License | 4 votes |
private AppRTCSignalingParameters getParametersForRoomUrl(String url) throws IOException, JSONException { url = url + "&t=json"; JSONObject roomJson = new JSONObject( drainStream((new URL(url)).openConnection().getInputStream())); if (roomJson.has("error")) { JSONArray errors = roomJson.getJSONArray("error_messages"); throw new IOException(errors.toString()); } String gaeBaseHref = url.substring(0, url.indexOf('?')); String token = roomJson.getString("token"); String postMessageUrl = "/message?r=" + roomJson.getString("room_key") + "&u=" + roomJson.getString("me"); boolean initiator = roomJson.getInt("initiator") == 1; LinkedList<PeerConnection.IceServer> iceServers = iceServersFromPCConfigJSON(roomJson.getString("pc_config")); boolean isTurnPresent = false; for (PeerConnection.IceServer server : iceServers) { if (server.uri.startsWith("turn:")) { isTurnPresent = true; break; } } if (!isTurnPresent) { iceServers.add(requestTurnServer(roomJson.getString("turn_url"))); } MediaConstraints pcConstraints = constraintsFromJSON( roomJson.getString("pc_constraints")); addDTLSConstraintIfMissing(pcConstraints); Log.d(TAG, "pcConstraints: " + pcConstraints); MediaConstraints videoConstraints = constraintsFromJSON( getAVConstraints("video", roomJson.getString("media_constraints"))); Log.d(TAG, "videoConstraints: " + videoConstraints); MediaConstraints audioConstraints = constraintsFromJSON( getAVConstraints("audio", roomJson.getString("media_constraints"))); Log.d(TAG, "audioConstraints: " + audioConstraints); return new AppRTCSignalingParameters( iceServers, gaeBaseHref, token, postMessageUrl, initiator, pcConstraints, videoConstraints, audioConstraints); }
Example 17
Source File: VideoRoomTest.java From janus-gateway-android with MIT License | 4 votes |
@Override public List<PeerConnection.IceServer> getIceServers() { return new ArrayList<PeerConnection.IceServer>(); }
Example 18
Source File: AppRTCClient.java From droidkit-webrtc with BSD 3-Clause "New" or "Revised" License | votes |
public void onIceServers(List<PeerConnection.IceServer> iceServers);
Example 19
Source File: AppRTCClient.java From WebRTCDemo with BSD 3-Clause "New" or "Revised" License | votes |
public void onIceServers(List<PeerConnection.IceServer> iceServers);
Example 20
Source File: IJanusGatewayCallbacks.java From janus-gateway-android with MIT License | votes |
public List<PeerConnection.IceServer> getIceServers();