Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
niyatim23 committed Apr 9, 2024
1 parent 63f0e7c commit 446a9a2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Base64;
import android.util.DisplayMetrics;
Expand Down Expand Up @@ -277,54 +276,52 @@ public void onException(final Exception e) {
// Step 11. Create SignalingServiceWebSocketClient.
// This is the actual client that is used to send messages over the signaling channel.
// SignalingServiceWebSocketClient will attempt to open the connection in its constructor.
if (wsHost != null) {
try {
client = new SignalingServiceWebSocketClient(wsHost, signalingListener, Executors.newFixedThreadPool(10));

Log.d(TAG, "Client connection " + (client.isOpen() ? "Successful" : "Failed"));
} catch (final Exception e) {
Log.e(TAG, "Exception with websocket client: " + e);
gotException = true;
return;
}
try {
client = new SignalingServiceWebSocketClient(wsHost, signalingListener, Executors.newFixedThreadPool(10));

if (isValidClient()) {

Log.d(TAG, "Client connected to Signaling service " + client.isOpen());

if (master) {

// If webrtc endpoint is non-null ==> Ingest media was checked
if (webrtcEndpoint != null) {
new Thread(() -> {
try {
final AWSKinesisVideoWebRTCStorageClient storageClient =
new AWSKinesisVideoWebRTCStorageClient(
KinesisVideoWebRtcDemoApp.getCredentialsProvider().getCredentials());
storageClient.setRegion(Region.getRegion(mRegion));
storageClient.setSignerRegionOverride(mRegion);
storageClient.setServiceNameIntern("kinesisvideo");
storageClient.setEndpoint(webrtcEndpoint);

Log.i(TAG, "Channel ARN is: " + mChannelArn);
storageClient.joinStorageSession(new JoinStorageSessionRequest()
.withChannelArn(mChannelArn));
Log.i(TAG, "Join storage session request sent!");
} catch (Exception ex) {
Log.e(TAG, "Error sending join storage session request!", ex);
}
}).start();
}
} else {
Log.d(TAG, "Signaling service is connected: " +
"Sending offer as viewer to remote peer"); // Viewer
Log.d(TAG, "Client connection " + (client.isOpen() ? "Successful" : "Failed"));
} catch (final Exception e) {
Log.e(TAG, "Exception with websocket client: " + e);
gotException = true;
return;
}

createSdpOffer();
if (isValidClient()) {

Log.d(TAG, "Client connected to Signaling service " + client.isOpen());

if (master) {

// If webrtc endpoint is non-null ==> Ingest media was checked
if (webrtcEndpoint != null) {
new Thread(() -> {
try {
final AWSKinesisVideoWebRTCStorageClient storageClient =
new AWSKinesisVideoWebRTCStorageClient(
KinesisVideoWebRtcDemoApp.getCredentialsProvider().getCredentials());
storageClient.setRegion(Region.getRegion(mRegion));
storageClient.setSignerRegionOverride(mRegion);
storageClient.setServiceNameIntern("kinesisvideo");
storageClient.setEndpoint(webrtcEndpoint);

Log.i(TAG, "Channel ARN is: " + mChannelArn);
storageClient.joinStorageSession(new JoinStorageSessionRequest()
.withChannelArn(mChannelArn));
Log.i(TAG, "Join storage session request sent!");
} catch (Exception ex) {
Log.e(TAG, "Error sending join storage session request!", ex);
}
}).start();
}
} else {
Log.e(TAG, "Error in connecting to signaling service");
gotException = true;
Log.d(TAG, "Signaling service is connected: " +
"Sending offer as viewer to remote peer"); // Viewer

createSdpOffer();
}
} else {
Log.e(TAG, "Error in connecting to signaling service");
gotException = true;
}
}

Expand Down Expand Up @@ -504,17 +501,15 @@ protected void onCreate(final Bundle savedInstanceState) {
if (mUrisList != null) {
for (int i = 0; i < mUrisList.size(); i++) {
final String turnServer = mUrisList.get(i).toString();
if (turnServer != null) {
assert mUserNames != null;
assert mPasswords != null;
final IceServer iceServer = IceServer.builder(turnServer.replace("[", "").replace("]", ""))
.setUsername(mUserNames.get(i))
.setPassword(mPasswords.get(i))
.createIceServer();

Log.d(TAG, "IceServer details (TURN) = " + iceServer.toString());
peerIceServers.add(iceServer);
}
assert mUserNames != null;
assert mPasswords != null;
final IceServer iceServer = IceServer.builder(turnServer.replace("[", "").replace("]", ""))
.setUsername(mUserNames.get(i))
.setPassword(mPasswords.get(i))
.createIceServer();

Log.d(TAG, "IceServer details (TURN) = " + iceServer.toString());
peerIceServers.add(iceServer);
}
}

Expand Down Expand Up @@ -783,11 +778,7 @@ public void onStateChange() {

if (sendDataChannelButton != null) {
runOnUiThread(() -> {
if (localDataChannel.state() == DataChannel.State.OPEN) {
sendDataChannelButton.setEnabled(true);
} else {
sendDataChannelButton.setEnabled(false);
}
sendDataChannelButton.setEnabled(localDataChannel.state() == DataChannel.State.OPEN);
});
}
}
Expand Down Expand Up @@ -991,30 +982,26 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
}

private void resizeRemoteView() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
final DisplayMetrics displayMetrics = new DisplayMetrics();
final ViewGroup.LayoutParams lp = remoteView.getLayoutParams();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
lp.height = (int) (displayMetrics.heightPixels * 0.75);
lp.width = (int) (displayMetrics.widthPixels * 0.75);
remoteView.setLayoutParams(lp);
localView.bringToFront();
}
final DisplayMetrics displayMetrics = new DisplayMetrics();
final ViewGroup.LayoutParams lp = remoteView.getLayoutParams();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
lp.height = (int) (displayMetrics.heightPixels * 0.75);
lp.width = (int) (displayMetrics.widthPixels * 0.75);
remoteView.setLayoutParams(lp);
localView.bringToFront();
}

private void createNotificationChannel() {
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final CharSequence name = getString(R.string.data_channel_notification);
final String description = getString(R.string.data_channel_notification_description);
final int importance = NotificationManager.IMPORTANCE_HIGH;
final NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
final NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
final CharSequence name = getString(R.string.data_channel_notification);
final String description = getString(R.string.data_channel_notification_description);
final int importance = NotificationManager.IMPORTANCE_HIGH;
final NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
final NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.amazonaws.kinesisvideo.demoapp.fragment;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
Expand All @@ -11,15 +10,13 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CheckedTextView;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -55,7 +52,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class StreamWebRtcConfigurationFragment extends Fragment {
private static final String TAG = StreamWebRtcConfigurationFragment.class.getSimpleName();
Expand Down Expand Up @@ -263,7 +259,7 @@ private Bundle setExtras(boolean isMaster) {
extras.putString(KEY_STREAM_ARN, mStreamArn);
extras.putBoolean(KEY_IS_MASTER, isMaster);

if (mIceServerList.size() > 0) {
if (!mIceServerList.isEmpty()) {
ArrayList<String> userNames = new ArrayList<>(mIceServerList.size());
ArrayList<String> passwords = new ArrayList<>(mIceServerList.size());
ArrayList<Integer> ttls = new ArrayList<>(mIceServerList.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.util.Base64;
import android.util.Log;

import androidx.annotation.NonNull;

import com.google.common.base.Charsets;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand Down Expand Up @@ -143,6 +145,7 @@ public static String parseOfferEvent(Event offerEvent) {
.orElse("");
}

@NonNull
@Override
public String toString() {
return "Event(" +
Expand Down

0 comments on commit 446a9a2

Please sign in to comment.