wifidirectplugin 1.0.9 → 1.1.1

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.
@@ -49,7 +49,7 @@ public class WifiDirectPlugin extends Plugin {
49
49
  JSONArray devicesJson = new JSONArray();
50
50
  for(WifiP2pDevice device: peerWifiDirDevices) {
51
51
  try {
52
- // if(!device.deviceName.toUpperCase().contains("LINKVUE")) continue;
52
+ if(!device.deviceName.toUpperCase().contains("LINKVUE")) continue;
53
53
 
54
54
  JSONObject deviceJson = new JSONObject();
55
55
  deviceJson.put("deviceName", device.deviceName);
@@ -77,31 +77,51 @@ public class WifiDirectPlugin extends Plugin {
77
77
 
78
78
  @PluginMethod
79
79
  public void connectToDevice(PluginCall call) {
80
+ Log.d(TAG, "connectToDevice Called");
81
+ if(manager == null || channel == null) {
82
+ Log.e(TAG, "WifiP2pManager or Channel is null");
83
+ call.reject("WifiP2pManager or Channel not initialized");
84
+ return;
85
+ }
80
86
  String deviceAddress = call.getString("deviceAddress");
87
+ Log.d(TAG, "Device Address: " + deviceAddress);
81
88
  String pin = call.getString("pin");
82
89
 
83
90
  if(deviceAddress == null) {
91
+ Log.e(TAG, "Device address is null");
84
92
  call.reject("Device address is required");
85
93
  return;
86
94
  }
87
95
  WifiP2pConfig config = new WifiP2pConfig();
88
96
  config.deviceAddress = deviceAddress;
89
97
 
90
- if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && pin != null) {
91
- config.wps.setup = WpsInfo.KEYPAD;
92
- config.wps.pin = pin;
93
- }
94
- manager.connect(channel, config, new WifiP2pManager.ActionListener() {
95
- @Override
96
- public void onSuccess() {
97
- call.resolve();
98
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
99
+ if(pin != null && pin.length() == 8 && pin.matches("\\d+")) {
100
+ config.wps.setup = WpsInfo.KEYPAD;
101
+ config.wps.pin = pin;
102
+ } else {
103
+ Log.w(TAG, "Invalid Pin");
98
104
  }
105
+ }
106
+ try {
107
+ manager.connect(channel, config, new WifiP2pManager.ActionListener() {
108
+ @Override
109
+ public void onSuccess() {
110
+ Log.d(TAG, "connect onSuccess Called");
111
+ call.resolve();
112
+ }
113
+
114
+ @Override
115
+ public void onFailure(int reason) {
116
+ Log.e(TAG, "connect onFailure Called");
117
+ call.reject("Connection failed: " + reason);
118
+ }
119
+ });
120
+ } catch (Exception e) {
121
+ Log.e(TAG, "connect exception", e);
122
+ call.reject("Connection exception: " + e.getMessage());
123
+ }
99
124
 
100
- @Override
101
- public void onFailure(int reason) {
102
- call.reject("Connection failed: " + reason);
103
- }
104
- });
105
125
  }
106
126
 
107
127
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wifidirectplugin",
3
- "version": "1.0.9",
3
+ "version": "1.1.1",
4
4
  "description": "HT-Installer Wifi Direct Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",