openvidu-android: remove direct communication with openvidu-server

This commit is contained in:
pabloFuente 2022-08-01 22:55:39 +02:00
parent def43a626e
commit 2e1440578d
5 changed files with 20 additions and 31 deletions

View File

@ -10,6 +10,7 @@
<uses-feature android:name="android.hardware.camera" />
<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"

View File

@ -61,8 +61,6 @@ public class SessionActivity extends AppCompatActivity {
EditText session_name;
@BindView(R.id.participant_name)
EditText participant_name;
@BindView(R.id.openvidu_url)
EditText openvidu_url;
@BindView(R.id.application_server_url)
EditText application_server_url;
@BindView(R.id.local_gl_surface_view)
@ -72,7 +70,6 @@ public class SessionActivity extends AppCompatActivity {
@BindView(R.id.peer_container)
FrameLayout peer_container;
private String OPENVIDU_URL;
private String APPLICATION_SERVER_URL;
private Session session;
private CustomHttpClient httpClient;
@ -121,7 +118,6 @@ public class SessionActivity extends AppCompatActivity {
initViews();
viewToConnectingState();
OPENVIDU_URL = openvidu_url.getText().toString();
APPLICATION_SERVER_URL = application_server_url.getText().toString();
httpClient = new CustomHttpClient(APPLICATION_SERVER_URL);
@ -137,7 +133,7 @@ public class SessionActivity extends AppCompatActivity {
try {
// Session Request
RequestBody sessionBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{\"customSessionId\": \"" + sessionId + "\"}");
this.httpClient.httpCall("/sessions", "POST", "application/json", sessionBody, new Callback() {
this.httpClient.httpCall("/api/sessions", "POST", "application/json", sessionBody, new Callback() {
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
@ -145,7 +141,7 @@ public class SessionActivity extends AppCompatActivity {
// Token Request
RequestBody tokenBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{}");
httpClient.httpCall("/sessions/" + sessionId + "/connections", "POST", "application/json", tokenBody, new Callback() {
httpClient.httpCall("/api/sessions/" + sessionId + "/connections", "POST", "application/json", tokenBody, new Callback() {
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) {
@ -160,7 +156,7 @@ public class SessionActivity extends AppCompatActivity {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
Log.e(TAG, "Error POST /api/tokens", e);
Log.e(TAG, "Error POST /api/sessions/SESSION_ID/connections", e);
connectionError(APPLICATION_SERVER_URL);
}
});
@ -198,7 +194,7 @@ public class SessionActivity extends AppCompatActivity {
}
private void startWebSocket() {
CustomWebSocket webSocket = new CustomWebSocket(session, OPENVIDU_URL, this);
CustomWebSocket webSocket = new CustomWebSocket(session, this);
webSocket.execute();
session.setWebSocket(webSocket);
}

View File

@ -27,6 +27,8 @@ import org.webrtc.SessionDescription;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@ -85,15 +87,13 @@ public class CustomWebSocket extends AsyncTask<SessionActivity, Void, Void> impl
private Map<Integer, String> IDS_RECEIVEVIDEO = new ConcurrentHashMap<>();
private Set<Integer> IDS_ONICECANDIDATE = Collections.newSetFromMap(new ConcurrentHashMap<>());
private Session session;
private String openviduUrl;
private String mediaServer;
private SessionActivity activity;
private WebSocket websocket;
private boolean websocketCancelled = false;
public CustomWebSocket(Session session, String openviduUrl, SessionActivity activity) {
public CustomWebSocket(Session session, SessionActivity activity) {
this.session = session;
this.openviduUrl = openviduUrl;
this.activity = activity;
}
@ -652,13 +652,17 @@ public class CustomWebSocket extends AsyncTask<SessionActivity, Void, Void> impl
}, initialDelay, PING_MESSAGE_INTERVAL, TimeUnit.SECONDS);
}
private String getWebSocketAddress(String openviduUrl) {
private String getWebSocketAddress() {
String wsUri;
try {
URL url = new URL(openviduUrl);
if (url.getPort() > -1)
return "wss://" + url.getHost() + ":" + url.getPort() + "/openvidu";
return "wss://" + url.getHost() + "/openvidu";
} catch (MalformedURLException e) {
URI url = new URI(this.session.getToken());
if (url.getPort() > -1) {
wsUri = url.getScheme() + "://" + url.getHost() + ":" + url.getPort() + "/openvidu";
} else {
wsUri = url.getScheme() + "://" + url.getHost() + "/openvidu";
}
return wsUri;
} catch (URISyntaxException e) {
Log.e(TAG, "Wrong URL", e);
e.printStackTrace();
return "";
@ -673,7 +677,7 @@ public class CustomWebSocket extends AsyncTask<SessionActivity, Void, Void> impl
sslContext.init(null, trustManagers, new java.security.SecureRandom());
factory.setSSLContext(sslContext);
factory.setVerifyHostname(false);
websocket = factory.createSocket(getWebSocketAddress(openviduUrl));
websocket = factory.createSocket(getWebSocketAddress());
websocket.addListener(this);
websocket.connect();
} catch (KeyManagementException | NoSuchAlgorithmException | IOException | WebSocketException e) {

View File

@ -90,16 +90,6 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<EditText
android:id="@+id/openvidu_url"
style="@android:style/Widget.Material.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/openvidu_url"
android:inputType="text"
android:text="@string/openvidu_url" />
<EditText
android:id="@+id/application_server_url"
style="@android:style/Widget.Material.Button.Borderless.Colored"
@ -134,4 +124,3 @@
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,12 +1,11 @@
<resources>
<string name="application_server_url">http://192.168.1.19:5000/</string>
<string name="app_name">OpenVidu Android Sample</string>
<string name="start_button">Join</string>
<string name="session_name">Session Name</string>
<string name="default_session_name">SessionA</string>
<string name="participant_name">Participant Name</string>
<string name="default_participant_name">Participant</string>
<string name="application_server_url">https://X.Y.W.Z:5000/</string>
<string name="openvidu_url">https://X.Y.W.Z:4443/</string>
<string name="hang_up">Leave session</string>
<string name="no_connection">COULD NOT ESTABLISH THE CONNECTION, TRY AGAIN </string>
<string name="no_permissions_granted">We can not give you service without your permission</string>