wifidirectplugin 1.2.3 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -26,7 +26,8 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
26
26
|
private Context context;
|
|
27
27
|
private List<WifiP2pDevice> peerWifiDirDevices = new ArrayList<>();
|
|
28
28
|
private static final String TAG = "WifiDirectPlugin";
|
|
29
|
-
|
|
29
|
+
private static final int MAX_DISCOVER_RETRIES = 3;
|
|
30
|
+
private int discoverRetryCount = 0;
|
|
30
31
|
private final BroadcastReceiver wifiP2pReceiver = new BroadcastReceiver() {
|
|
31
32
|
@Override
|
|
32
33
|
public void onReceive(Context context, Intent intent) {
|
|
@@ -50,10 +51,19 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
50
51
|
public void load() {
|
|
51
52
|
context = getContext();
|
|
52
53
|
manager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
|
|
53
|
-
channel = manager.initialize(context, context.getMainLooper(),
|
|
54
|
-
|
|
54
|
+
channel = manager.initialize(context, context.getMainLooper(), new WifiP2pManager.ChannelListener() {
|
|
55
|
+
@Override
|
|
56
|
+
public void onChannelDisconnected() {
|
|
57
|
+
Log.e(TAG, "P2P Channel disconnected");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
55
61
|
IntentFilter intentFilter = new IntentFilter();
|
|
56
62
|
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
|
|
63
|
+
intentFilter.addAction(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION);
|
|
64
|
+
intentFilter.addAction(WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION);
|
|
65
|
+
intentFilter.addAction(WifiP2pManager.WIFI_P2P_THIS_DEVICE_CHANGED_ACTION);
|
|
66
|
+
|
|
57
67
|
context.registerReceiver(wifiP2pReceiver, intentFilter);
|
|
58
68
|
}
|
|
59
69
|
|
|
@@ -66,6 +76,7 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
66
76
|
}
|
|
67
77
|
@PluginMethod
|
|
68
78
|
public void scanWifiPeers(PluginCall call) {
|
|
79
|
+
discoverRetryCount = 0;
|
|
69
80
|
String targetDeviceName = call.getString("deviceName"); // 앱에서 입력 받은 장치 이름
|
|
70
81
|
Log.d(TAG, "DeviceName: " + targetDeviceName);
|
|
71
82
|
if(manager == null || channel == null) {
|
|
@@ -108,8 +119,13 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
108
119
|
|
|
109
120
|
@Override
|
|
110
121
|
public void onFailure(int reason) {
|
|
111
|
-
|
|
112
|
-
|
|
122
|
+
if (++discoverRetryCount < MAX_DISCOVER_RETRIES) {
|
|
123
|
+
discoverRetryCount = 0;
|
|
124
|
+
Log.e(TAG, "scanWifi onFailure: " + reason);
|
|
125
|
+
new android.os.Handler(Looper.getMainLooper()).postDelayed(() -> discoverPeers(call), 2000);
|
|
126
|
+
} else {
|
|
127
|
+
call.reject("Peer discovery failed after retries: " + reason);
|
|
128
|
+
}
|
|
113
129
|
}
|
|
114
130
|
});
|
|
115
131
|
}
|