wifidirectplugin 1.2.5 → 1.2.7
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,8 +26,7 @@ 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
|
-
|
|
30
|
-
private int discoverRetryCount = 0;
|
|
29
|
+
|
|
31
30
|
private final BroadcastReceiver wifiP2pReceiver = new BroadcastReceiver() {
|
|
32
31
|
@Override
|
|
33
32
|
public void onReceive(Context context, Intent intent) {
|
|
@@ -76,7 +75,6 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
76
75
|
}
|
|
77
76
|
@PluginMethod
|
|
78
77
|
public void scanWifiPeers(PluginCall call) {
|
|
79
|
-
discoverRetryCount = 0;
|
|
80
78
|
String targetDeviceName = call.getString("deviceName"); // 앱에서 입력 받은 장치 이름
|
|
81
79
|
Log.d(TAG, "DeviceName: " + targetDeviceName);
|
|
82
80
|
if(manager == null || channel == null) {
|
|
@@ -119,13 +117,8 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
119
117
|
|
|
120
118
|
@Override
|
|
121
119
|
public void onFailure(int reason) {
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
}
|
|
120
|
+
Log.e(TAG, "scanWifi onFailure: " + reason);
|
|
121
|
+
call.reject("Peer discovery failed: " + reason);
|
|
129
122
|
}
|
|
130
123
|
});
|
|
131
124
|
}
|
|
@@ -147,6 +140,32 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
147
140
|
call.reject("Device address is required");
|
|
148
141
|
return;
|
|
149
142
|
}
|
|
143
|
+
|
|
144
|
+
manager.requestConnectionInfo(channel, info -> {
|
|
145
|
+
if(info != null && info.groupFormed) {
|
|
146
|
+
// 기존 그룹 해제
|
|
147
|
+
Log.d(TAG, "Existing Wi-Fi Direct group found. Removing group.");
|
|
148
|
+
manager.removeGroup(channel, new WifiP2pManager.ActionListener() {
|
|
149
|
+
@Override
|
|
150
|
+
public void onSuccess() {
|
|
151
|
+
Log.d(TAG, "removeGroup success, proceed to connect.");
|
|
152
|
+
// 그룹 해제 성공 시 연결 계속 진행
|
|
153
|
+
initiateConnect(deviceAddress, pin, call);
|
|
154
|
+
}
|
|
155
|
+
@Override
|
|
156
|
+
public void onFailure(int reason) {
|
|
157
|
+
Log.w(TAG, "removeGroup failed: " + reason + ". Proceed anyway.");
|
|
158
|
+
// 그룹 해제 실패 시에도 연결 시도(혹은 call.reject로 실패 처리 가능)
|
|
159
|
+
initiateConnect(deviceAddress, pin, call);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
Log.d(TAG, "No existing group, proceed to connect directly.");
|
|
164
|
+
initiateConnect(deviceAddress, pin, call);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
private void initiateConnect(String deviceAddress, String pin, PluginCall call) {
|
|
150
169
|
WifiP2pConfig config = new WifiP2pConfig();
|
|
151
170
|
config.deviceAddress = deviceAddress;
|
|
152
171
|
|
|
@@ -180,7 +199,6 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
180
199
|
call.reject("Connection exception: " + e.getMessage());
|
|
181
200
|
// unload();
|
|
182
201
|
}
|
|
183
|
-
|
|
184
202
|
}
|
|
185
203
|
|
|
186
204
|
@PluginMethod
|