wifidirectplugin 1.2.9 → 1.3.0
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.
|
@@ -27,6 +27,8 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
27
27
|
private List<WifiP2pDevice> peerWifiDirDevices = new ArrayList<>();
|
|
28
28
|
private static final String TAG = "WifiDirectPlugin";
|
|
29
29
|
|
|
30
|
+
private PluginCall pendingConnectCall = null;
|
|
31
|
+
|
|
30
32
|
private final BroadcastReceiver wifiP2pReceiver = new BroadcastReceiver() {
|
|
31
33
|
@Override
|
|
32
34
|
public void onReceive(Context context, Intent intent) {
|
|
@@ -36,11 +38,21 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
36
38
|
NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
|
|
37
39
|
if (networkInfo != null && networkInfo.isConnected()) {
|
|
38
40
|
Log.d(TAG, "Wi-Fi Direct connected");
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
if (pendingConnectCall != null) {
|
|
42
|
+
manager.requestConnectionInfo(channel, info -> {
|
|
43
|
+
if (info != null && info.groupFormed) {
|
|
44
|
+
Log.d(TAG, "Group formed, resolving connectToDevice");
|
|
45
|
+
pendingConnectCall.resolve();
|
|
46
|
+
pendingConnectCall = null;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
41
50
|
} else {
|
|
42
51
|
Log.d(TAG, "Wi-Fi Direct disconnected");
|
|
43
|
-
|
|
52
|
+
if (pendingConnectCall != null) {
|
|
53
|
+
pendingConnectCall.reject("Wi-Fi Direct connection lost before group formed");
|
|
54
|
+
pendingConnectCall = null;
|
|
55
|
+
}
|
|
44
56
|
}
|
|
45
57
|
}
|
|
46
58
|
}
|
|
@@ -182,18 +194,22 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
182
194
|
manager.connect(channel, config, new WifiP2pManager.ActionListener() {
|
|
183
195
|
@Override
|
|
184
196
|
public void onSuccess() {
|
|
185
|
-
|
|
186
|
-
|
|
197
|
+
// connect request accepted — group formation is async
|
|
198
|
+
// resolve will be called from BroadcastReceiver once group is formed
|
|
199
|
+
Log.d(TAG, "connect onSuccess Called, waiting for group formation");
|
|
200
|
+
pendingConnectCall = call;
|
|
187
201
|
}
|
|
188
202
|
|
|
189
203
|
@Override
|
|
190
204
|
public void onFailure(int reason) {
|
|
191
205
|
Log.e(TAG, "connect onFailure Called");
|
|
206
|
+
pendingConnectCall = null;
|
|
192
207
|
call.reject("Connection failed: " + reason);
|
|
193
208
|
}
|
|
194
209
|
});
|
|
195
210
|
} catch (Exception e) {
|
|
196
211
|
Log.e(TAG, "connect exception", e);
|
|
212
|
+
pendingConnectCall = null;
|
|
197
213
|
call.reject("Connection exception: " + e.getMessage());
|
|
198
214
|
}
|
|
199
215
|
}
|