openvidu-android: update to use sample application server
This commit is contained in:
parent
90add968a9
commit
23b79a61f8
7
openvidu-android/.idea/misc.xml
generated
7
openvidu-android/.idea/misc.xml
generated
@ -1,5 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.3333333333333333" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
|
||||
@ -63,8 +63,8 @@ public class SessionActivity extends AppCompatActivity {
|
||||
EditText participant_name;
|
||||
@BindView(R.id.openvidu_url)
|
||||
EditText openvidu_url;
|
||||
@BindView(R.id.openvidu_secret)
|
||||
EditText openvidu_secret;
|
||||
@BindView(R.id.application_server_url)
|
||||
EditText application_server_url;
|
||||
@BindView(R.id.local_gl_surface_view)
|
||||
SurfaceViewRenderer localVideoView;
|
||||
@BindView(R.id.main_participant)
|
||||
@ -73,7 +73,7 @@ public class SessionActivity extends AppCompatActivity {
|
||||
FrameLayout peer_container;
|
||||
|
||||
private String OPENVIDU_URL;
|
||||
private String OPENVIDU_SECRET;
|
||||
private String APPLICATION_SERVER_URL;
|
||||
private Session session;
|
||||
private CustomHttpClient httpClient;
|
||||
|
||||
@ -122,8 +122,8 @@ public class SessionActivity extends AppCompatActivity {
|
||||
viewToConnectingState();
|
||||
|
||||
OPENVIDU_URL = openvidu_url.getText().toString();
|
||||
OPENVIDU_SECRET = openvidu_secret.getText().toString();
|
||||
httpClient = new CustomHttpClient(OPENVIDU_URL, "Basic " + android.util.Base64.encodeToString(("OPENVIDUAPP:" + OPENVIDU_SECRET).getBytes(), android.util.Base64.DEFAULT).trim());
|
||||
APPLICATION_SERVER_URL = application_server_url.getText().toString();
|
||||
httpClient = new CustomHttpClient(APPLICATION_SERVER_URL);
|
||||
|
||||
String sessionId = session_name.getText().toString();
|
||||
getToken(sessionId);
|
||||
@ -137,7 +137,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("/openvidu/api/sessions", "POST", "application/json", sessionBody, new Callback() {
|
||||
this.httpClient.httpCall("/sessions", "POST", "application/json", sessionBody, new Callback() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
|
||||
@ -145,7 +145,7 @@ public class SessionActivity extends AppCompatActivity {
|
||||
|
||||
// Token Request
|
||||
RequestBody tokenBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), "{}");
|
||||
httpClient.httpCall("/openvidu/api/sessions/" + sessionId + "/connection", "POST", "application/json", tokenBody, new Callback() {
|
||||
httpClient.httpCall("/sessions/" + sessionId + "/connections", "POST", "application/json", tokenBody, new Callback() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call call, @NotNull Response response) {
|
||||
@ -155,22 +155,13 @@ public class SessionActivity extends AppCompatActivity {
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error getting body", e);
|
||||
}
|
||||
Log.d(TAG, "responseString2: " + responseString);
|
||||
JSONObject tokenJsonObject = null;
|
||||
String token = null;
|
||||
try {
|
||||
tokenJsonObject = new JSONObject(responseString);
|
||||
token = tokenJsonObject.getString("token");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
getTokenSuccess(token, sessionId);
|
||||
getTokenSuccess(responseString, sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
Log.e(TAG, "Error POST /api/tokens", e);
|
||||
connectionError();
|
||||
connectionError(APPLICATION_SERVER_URL);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -178,13 +169,13 @@ public class SessionActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
Log.e(TAG, "Error POST /api/sessions", e);
|
||||
connectionError();
|
||||
connectionError(APPLICATION_SERVER_URL);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, "Error getting token", e);
|
||||
e.printStackTrace();
|
||||
connectionError();
|
||||
connectionError(APPLICATION_SERVER_URL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -212,9 +203,9 @@ public class SessionActivity extends AppCompatActivity {
|
||||
session.setWebSocket(webSocket);
|
||||
}
|
||||
|
||||
private void connectionError() {
|
||||
private void connectionError(String url) {
|
||||
Runnable myRunnable = () -> {
|
||||
Toast toast = Toast.makeText(this, "Error connecting to " + OPENVIDU_URL, Toast.LENGTH_LONG);
|
||||
Toast toast = Toast.makeText(this, "Error connecting to " + url, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
viewToDisconnectedState();
|
||||
};
|
||||
@ -235,10 +226,8 @@ public class SessionActivity extends AppCompatActivity {
|
||||
localVideoView.release();
|
||||
start_finish_call.setText(getResources().getString(R.string.start_button));
|
||||
start_finish_call.setEnabled(true);
|
||||
openvidu_url.setEnabled(true);
|
||||
openvidu_url.setFocusableInTouchMode(true);
|
||||
openvidu_secret.setEnabled(true);
|
||||
openvidu_secret.setFocusableInTouchMode(true);
|
||||
application_server_url.setEnabled(true);
|
||||
application_server_url.setFocusableInTouchMode(true);
|
||||
session_name.setEnabled(true);
|
||||
session_name.setFocusableInTouchMode(true);
|
||||
participant_name.setEnabled(true);
|
||||
@ -251,10 +240,8 @@ public class SessionActivity extends AppCompatActivity {
|
||||
public void viewToConnectingState() {
|
||||
runOnUiThread(() -> {
|
||||
start_finish_call.setEnabled(false);
|
||||
openvidu_url.setEnabled(false);
|
||||
openvidu_url.setFocusable(false);
|
||||
openvidu_secret.setEnabled(false);
|
||||
openvidu_secret.setFocusable(false);
|
||||
application_server_url.setEnabled(false);
|
||||
application_server_url.setFocusable(false);
|
||||
session_name.setEnabled(false);
|
||||
session_name.setFocusable(false);
|
||||
participant_name.setEnabled(false);
|
||||
|
||||
@ -22,11 +22,9 @@ public class CustomHttpClient {
|
||||
|
||||
private OkHttpClient client;
|
||||
private String baseUrl;
|
||||
private String basicAuth;
|
||||
|
||||
public CustomHttpClient(String baseUrl, String basicAuth) {
|
||||
public CustomHttpClient(String baseUrl) {
|
||||
this.baseUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
|
||||
this.basicAuth = basicAuth;
|
||||
|
||||
try {
|
||||
// Create a trust manager that does not validate certificate chains
|
||||
@ -82,7 +80,7 @@ public class CustomHttpClient {
|
||||
url = url.startsWith("/") ? url.substring(1) : url;
|
||||
Request request = new Request.Builder()
|
||||
.url(this.baseUrl + url)
|
||||
.header("Authorization", this.basicAuth).header("Content-Type", contentType)
|
||||
.header("Content-Type", contentType)
|
||||
.method(method, body)
|
||||
.build();
|
||||
Call call = client.newCall(request);
|
||||
|
||||
@ -98,17 +98,17 @@
|
||||
android:layout_weight="1"
|
||||
android:hint="@string/openvidu_url"
|
||||
android:inputType="text"
|
||||
android:text="@string/default_openvidu_url" />
|
||||
android:text="@string/openvidu_url" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/openvidu_secret"
|
||||
android:id="@+id/application_server_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_secret"
|
||||
android:hint="@string/application_server_url"
|
||||
android:inputType="text"
|
||||
android:text="@string/default_openvidu_secret" />
|
||||
android:text="@string/application_server_url" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/session_name"
|
||||
|
||||
@ -5,10 +5,8 @@
|
||||
<string name="default_session_name">SessionA</string>
|
||||
<string name="participant_name">Participant Name</string>
|
||||
<string name="default_participant_name">Participant</string>
|
||||
<string name="openvidu_url">OPENVIDU URL</string>
|
||||
<string name="openvidu_secret">OPENVIDU SECRET</string>
|
||||
<string name="default_openvidu_url">https://demos.openvidu.io</string>
|
||||
<string name="default_openvidu_secret">MY_SECRET</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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user