Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support connection between robot phone and controller phone using one of them as Wifi AP #388

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object ConnectionSelector {
}

fun getConnection(): ILocalConnection {
val connected = isConnectedViaWifi(context)
val connected = isConnectedViaWifi(context) || isWifiApEnabled(context)
return if (connected) NetworkServiceConnection else NearbyConnection
}

Expand All @@ -30,4 +30,14 @@ object ConnectionSelector {

return networkId > 0
}

private fun isWifiApEnabled(context: Context): Boolean {
val wifiManager = context.getSystemService(WIFI_SERVICE) as WifiManager
return try {
val method = wifiManager.javaClass.getDeclaredMethod("isWifiApEnabled")
method.invoke(wifiManager) as? Boolean == true
} catch (ignored: Throwable) {
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,15 @@ class VideoViewWebRTC @JvmOverloads constructor(
val initializationOptions = PeerConnectionFactory.InitializationOptions.builder(context)
.createInitializationOptions()
PeerConnectionFactory.initialize(initializationOptions)

val options = PeerConnectionFactory.Options().apply {
networkIgnoreMask = 16
disableEncryption = false
disableNetworkMonitor = true
}
factory = PeerConnectionFactory.builder().setVideoEncoderFactory(encoderFactory)
.setVideoDecoderFactory(decoderFactory).createPeerConnectionFactory()
.setVideoDecoderFactory(decoderFactory)
.setOptions(options).createPeerConnectionFactory()
}

private fun initializePeerConnections() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

import java.lang.reflect.Method;

public class ConnectionSelector {
private static final String TAG = "ConnectionManager";
Expand Down Expand Up @@ -37,7 +40,7 @@ ILocalConnection getConnection() {
return connection;
}

if (isConnectedViaWifi()) {
if (isConnectedViaWifi() || isWifiApEnabled()) {
connection = networkConnection;
} else {
connection = nearbyConnection;
Expand All @@ -52,4 +55,17 @@ private boolean isConnectedViaWifi() {
NetworkInfo mWifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return mWifi.isConnected();
}

private boolean isWifiApEnabled() {
WifiManager wifiManager =
(WifiManager) _context.getSystemService(Context.WIFI_SERVICE);
try {
final Method method =
wifiManager.getClass().getDeclaredMethod("isWifiApEnabled");
Boolean result = (Boolean) method.invoke(wifiManager);
return Boolean.TRUE.equals(result);
} catch (final Throwable ignored) {}

return false;
}
}
6 changes: 6 additions & 0 deletions android/robot/src/main/java/org/openbot/env/WebRtcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,16 @@ private void initializePeerConnectionFactory() {
PeerConnectionFactory.InitializationOptions.builder(context).createInitializationOptions();
PeerConnectionFactory.initialize(initializationOptions);

PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
options.networkIgnoreMask = 16;
options.disableEncryption = false;
options.disableNetworkMonitor = true;

factory =
PeerConnectionFactory.builder()
.setVideoEncoderFactory(encoderFactory)
.setVideoDecoderFactory(decoderFactory)
.setOptions(options)
.createPeerConnectionFactory();
}

Expand Down
Loading