android: Get TURN settings from server and use them in client
This commit is contained in:
parent
b925a64358
commit
fcb783c3ad
@ -50,4 +50,8 @@ public final class JsonConstants {
|
||||
public static final String SDP_ANSWER = "sdpAnswer";
|
||||
public static final String METADATA = "metadata";
|
||||
|
||||
}
|
||||
public static final String TURN_HOST = "coturnIp";
|
||||
public static final String TURN_PORT = "coturnPort";
|
||||
public static final String TURN_USER = "turnUsername";
|
||||
public static final String TURN_PASS = "turnCredential";
|
||||
}
|
||||
|
||||
@ -36,6 +36,9 @@ public class Session {
|
||||
private Map<String, RemoteParticipant> remoteParticipants = new HashMap<>();
|
||||
private String id;
|
||||
private String token;
|
||||
private String iceServerUri;
|
||||
private String iceServerUser;
|
||||
private String iceServerPass;
|
||||
private LinearLayout views_container;
|
||||
private PeerConnectionFactory peerConnectionFactory;
|
||||
private CustomWebSocket websocket;
|
||||
@ -44,6 +47,9 @@ public class Session {
|
||||
public Session(String id, String token, LinearLayout views_container, SessionActivity activity) {
|
||||
this.id = id;
|
||||
this.token = token;
|
||||
this.iceServerUri = "stun:stun.l.google.com:19302"; // Default value, will be updated from OpenVidu Server.
|
||||
this.iceServerUser = "";
|
||||
this.iceServerPass = "";
|
||||
this.views_container = views_container;
|
||||
this.activity = activity;
|
||||
|
||||
@ -71,7 +77,12 @@ public class Session {
|
||||
|
||||
public PeerConnection createLocalPeerConnection() {
|
||||
final List<PeerConnection.IceServer> iceServers = new ArrayList<>();
|
||||
PeerConnection.IceServer iceServer = PeerConnection.IceServer.builder("stun:stun.l.google.com:19302").createIceServer();
|
||||
|
||||
PeerConnection.IceServer iceServer = PeerConnection.IceServer
|
||||
.builder(this.iceServerUri)
|
||||
.setUsername(this.iceServerUser)
|
||||
.setPassword(this.iceServerPass)
|
||||
.createIceServer();
|
||||
iceServers.add(iceServer);
|
||||
|
||||
PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
|
||||
@ -106,11 +117,11 @@ public class Session {
|
||||
|
||||
if (localParticipant.getAudioTrack() != null) {
|
||||
peerConnection.addTransceiver(localParticipant.getAudioTrack(),
|
||||
new RtpTransceiver.RtpTransceiverInit(RtpTransceiver.RtpTransceiverDirection.SEND_ONLY));
|
||||
new RtpTransceiver.RtpTransceiverInit(RtpTransceiver.RtpTransceiverDirection.SEND_ONLY));
|
||||
}
|
||||
if (localParticipant.getVideoTrack() != null) {
|
||||
peerConnection.addTransceiver(localParticipant.getVideoTrack(),
|
||||
new RtpTransceiver.RtpTransceiverInit(RtpTransceiver.RtpTransceiverDirection.SEND_ONLY));
|
||||
new RtpTransceiver.RtpTransceiverInit(RtpTransceiver.RtpTransceiverDirection.SEND_ONLY));
|
||||
}
|
||||
|
||||
return peerConnection;
|
||||
@ -118,7 +129,12 @@ public class Session {
|
||||
|
||||
public void createRemotePeerConnection(final String connectionId) {
|
||||
final List<PeerConnection.IceServer> iceServers = new ArrayList<>();
|
||||
PeerConnection.IceServer iceServer = PeerConnection.IceServer.builder("stun:stun.l.google.com:19302").createIceServer();
|
||||
|
||||
PeerConnection.IceServer iceServer = PeerConnection.IceServer
|
||||
.builder(this.iceServerUri)
|
||||
.setUsername(this.iceServerUser)
|
||||
.setPassword(this.iceServerPass)
|
||||
.createIceServer();
|
||||
iceServers.add(iceServer);
|
||||
|
||||
PeerConnection.RTCConfiguration rtcConfig = new PeerConnection.RTCConfiguration(iceServers);
|
||||
@ -232,6 +248,18 @@ public class Session {
|
||||
return this.token;
|
||||
}
|
||||
|
||||
public void setIceServerUri(String uri) {
|
||||
this.iceServerUri = uri;
|
||||
}
|
||||
|
||||
public void setIceServerUser(String user) {
|
||||
this.iceServerUser = user;
|
||||
}
|
||||
|
||||
public void setIceServerPass(String pass) {
|
||||
this.iceServerPass = pass;
|
||||
}
|
||||
|
||||
public LocalParticipant getLocalParticipant() {
|
||||
return this.localParticipant;
|
||||
}
|
||||
|
||||
@ -121,9 +121,26 @@ public class CustomWebSocket extends AsyncTask<SessionActivity, Void, Void> impl
|
||||
|
||||
final LocalParticipant localParticipant = this.session.getLocalParticipant();
|
||||
final String localConnectionId = result.getString(JsonConstants.ID);
|
||||
this.mediaServer = result.getString(JsonConstants.MEDIA_SERVER);
|
||||
localParticipant.setConnectionId(localConnectionId);
|
||||
|
||||
this.mediaServer = result.getString(JsonConstants.MEDIA_SERVER);
|
||||
|
||||
if (result.has(JsonConstants.TURN_HOST) && result.has(JsonConstants.TURN_PORT)) {
|
||||
final String turnHost = result.getString(JsonConstants.TURN_HOST);
|
||||
final String turnPort = result.getString(JsonConstants.TURN_PORT);
|
||||
session.setIceServerUri("turn:" + turnHost + ":" + turnPort);
|
||||
}
|
||||
|
||||
if (result.has(JsonConstants.TURN_USER)) {
|
||||
final String turnUser = result.getString(JsonConstants.TURN_USER);
|
||||
session.setIceServerUser(turnUser);
|
||||
}
|
||||
|
||||
if (result.has(JsonConstants.TURN_PASS)) {
|
||||
final String turnPass = result.getString(JsonConstants.TURN_PASS);
|
||||
session.setIceServerPass(turnPass);
|
||||
}
|
||||
|
||||
PeerConnection localPeerConnection = session.createLocalPeerConnection();
|
||||
|
||||
localParticipant.setPeerConnection(localPeerConnection);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user