Show toast on connection error
This commit is contained in:
parent
4b9deba5f0
commit
230ebf7d03
@ -17,6 +17,11 @@ android {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
debug {
|
||||
debuggable true
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt')
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
|
||||
@ -14,6 +14,7 @@ import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
@ -88,10 +89,6 @@ public class SessionActivity extends AppCompatActivity {
|
||||
Random random = new Random();
|
||||
int randomIndex = random.nextInt(100);
|
||||
participant_name.setText(participant_name.getText().append(String.valueOf(randomIndex)));
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
public void askForPermissions() {
|
||||
@ -115,24 +112,19 @@ public class SessionActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
public void joinSession(View view) {
|
||||
public void buttonPressed(View view) {
|
||||
if (start_finish_call.getText().equals(getResources().getString(R.string.hang_up))) {
|
||||
// Already connected to a session
|
||||
leaveSession();
|
||||
return;
|
||||
}
|
||||
if (arePermissionGranted()) {
|
||||
if (start_finish_call.getText().equals(getResources().getString(R.string.hang_up))) {
|
||||
// Already in a call
|
||||
leaveSession();
|
||||
return;
|
||||
}
|
||||
initViews();
|
||||
start_finish_call.setText(getResources().getString(R.string.hang_up));
|
||||
start_finish_call.setEnabled(false);
|
||||
openvidu_url.setEnabled(false);
|
||||
openvidu_url.setFocusable(false);
|
||||
openvidu_secret.setEnabled(false);
|
||||
openvidu_secret.setFocusable(false);
|
||||
session_name.setEnabled(false);
|
||||
session_name.setFocusable(false);
|
||||
participant_name.setEnabled(false);
|
||||
participant_name.setFocusable(false);
|
||||
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());
|
||||
|
||||
String sessionId = session_name.getText().toString();
|
||||
getToken(sessionId);
|
||||
@ -187,6 +179,7 @@ public class SessionActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
Log.e(TAG, "Error POST /api/tokens", e);
|
||||
connectionError();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -194,14 +187,25 @@ public class SessionActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onFailure(@NotNull Call call, @NotNull IOException e) {
|
||||
Log.e(TAG, "Error POST /api/sessions", e);
|
||||
connectionError();
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
Log.e("Error getting token", e.getMessage());
|
||||
e.printStackTrace();
|
||||
connectionError();
|
||||
}
|
||||
}
|
||||
|
||||
private void connectionError() {
|
||||
Runnable myRunnable = () -> {
|
||||
Toast toast = Toast.makeText(this, "Error connecting to " + OPENVIDU_URL, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
viewToDisconnectedState();
|
||||
};
|
||||
new Handler(this.getMainLooper()).post(myRunnable);
|
||||
}
|
||||
|
||||
private void initViews() {
|
||||
EglBase rootEglBase = EglBase.create();
|
||||
localVideoView.init(rootEglBase.getEglBaseContext(), null);
|
||||
@ -210,6 +214,46 @@ public class SessionActivity extends AppCompatActivity {
|
||||
localVideoView.setZOrderMediaOverlay(true);
|
||||
}
|
||||
|
||||
public void viewToDisconnectedState() {
|
||||
runOnUiThread(() -> {
|
||||
localVideoView.clearImage();
|
||||
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);
|
||||
session_name.setEnabled(true);
|
||||
session_name.setFocusableInTouchMode(true);
|
||||
participant_name.setEnabled(true);
|
||||
participant_name.setFocusableInTouchMode(true);
|
||||
main_participant.setText(null);
|
||||
main_participant.setPadding(0, 0, 0, 0);
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
session_name.setEnabled(false);
|
||||
session_name.setFocusable(false);
|
||||
participant_name.setEnabled(false);
|
||||
participant_name.setFocusable(false);
|
||||
});
|
||||
}
|
||||
|
||||
public void viewToConnectedState() {
|
||||
runOnUiThread(() -> {
|
||||
start_finish_call.setText(getResources().getString(R.string.hang_up));
|
||||
start_finish_call.setEnabled(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void createRemoteParticipantVideo(final RemoteParticipant remoteParticipant) {
|
||||
Handler mainHandler = new Handler(this.getMainLooper());
|
||||
Runnable myRunnable = () -> {
|
||||
@ -250,27 +294,10 @@ public class SessionActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
public void enableLeaveButton() {
|
||||
runOnUiThread(() -> {
|
||||
start_finish_call.setEnabled(true);
|
||||
});
|
||||
}
|
||||
|
||||
public void leaveSession() {
|
||||
this.session.leaveSession();
|
||||
localVideoView.clearImage();
|
||||
localVideoView.release();
|
||||
start_finish_call.setText(getResources().getString(R.string.start_button));
|
||||
openvidu_url.setEnabled(true);
|
||||
openvidu_url.setFocusableInTouchMode(true);
|
||||
openvidu_secret.setEnabled(true);
|
||||
openvidu_secret.setFocusableInTouchMode(true);
|
||||
session_name.setEnabled(true);
|
||||
session_name.setFocusableInTouchMode(true);
|
||||
participant_name.setEnabled(true);
|
||||
participant_name.setFocusableInTouchMode(true);
|
||||
main_participant.setText(null);
|
||||
main_participant.setPadding(0, 0, 0, 0);
|
||||
this.httpClient.dispose();
|
||||
viewToDisconnectedState();
|
||||
}
|
||||
|
||||
private boolean arePermissionGranted() {
|
||||
|
||||
@ -8,8 +8,8 @@ import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.example.openviduandroid.activities.SessionActivity;
|
||||
import com.example.openviduandroid.R;
|
||||
import com.example.openviduandroid.activities.SessionActivity;
|
||||
|
||||
public class PermissionsDialogFragment extends DialogFragment {
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.example.openviduandroid.activities.SessionActivity;
|
||||
import com.example.openviduandroid.constants.JsonConstants;
|
||||
import com.example.openviduandroid.observers.CustomPeerConnectionObserver;
|
||||
import com.example.openviduandroid.observers.CustomSdpObserver;
|
||||
import com.example.openviduandroid.websocket.CustomWebSocket;
|
||||
|
||||
@ -17,7 +17,6 @@ import okhttp3.Callback;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class CustomHttpClient {
|
||||
|
||||
@ -89,4 +88,8 @@ public class CustomHttpClient {
|
||||
call.enqueue(callback);
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
this.client.dispatcher().executorService().shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ public class CustomWebSocket extends AsyncTask<SessionActivity, Void, Void> impl
|
||||
|
||||
} else if (rpcId == this.ID_JOINROOM.get()) {
|
||||
// Response to joinRoom
|
||||
activity.enableLeaveButton();
|
||||
activity.viewToConnectedState();
|
||||
|
||||
final LocalParticipant localParticipant = this.session.getLocalParticipant();
|
||||
final String localConnectionId = result.getString(JsonConstants.ID);
|
||||
|
||||
@ -74,7 +74,7 @@
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="5dp"
|
||||
android:layout_marginStart="30dp"
|
||||
android:onClick="joinSession"
|
||||
android:onClick="buttonPressed"
|
||||
android:text="@string/start_button" />
|
||||
|
||||
<LinearLayout
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user