wifidirectplugin 1.2.6 → 1.2.8
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.
|
@@ -140,6 +140,32 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
140
140
|
call.reject("Device address is required");
|
|
141
141
|
return;
|
|
142
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) {
|
|
143
169
|
WifiP2pConfig config = new WifiP2pConfig();
|
|
144
170
|
config.deviceAddress = deviceAddress;
|
|
145
171
|
|
|
@@ -158,22 +184,18 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
158
184
|
public void onSuccess() {
|
|
159
185
|
Log.d(TAG, "connect onSuccess Called");
|
|
160
186
|
call.resolve();
|
|
161
|
-
// unload();
|
|
162
187
|
}
|
|
163
188
|
|
|
164
189
|
@Override
|
|
165
190
|
public void onFailure(int reason) {
|
|
166
191
|
Log.e(TAG, "connect onFailure Called");
|
|
167
192
|
call.reject("Connection failed: " + reason);
|
|
168
|
-
// unload();
|
|
169
193
|
}
|
|
170
194
|
});
|
|
171
195
|
} catch (Exception e) {
|
|
172
196
|
Log.e(TAG, "connect exception", e);
|
|
173
197
|
call.reject("Connection exception: " + e.getMessage());
|
|
174
|
-
// unload();
|
|
175
198
|
}
|
|
176
|
-
|
|
177
199
|
}
|
|
178
200
|
|
|
179
201
|
@PluginMethod
|
|
@@ -190,4 +212,38 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
190
212
|
});
|
|
191
213
|
}
|
|
192
214
|
|
|
215
|
+
@PluginMethod
|
|
216
|
+
public void disconnect(PluginCall call) {
|
|
217
|
+
if (manager == null || channel == null) {
|
|
218
|
+
Log.e(TAG, "WifiP2pManager or Channel is null");
|
|
219
|
+
call.reject("WifiP2pManager or Channel not initialized");
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
manager.requestConnectionInfo(channel, info -> {
|
|
224
|
+
if (info != null && info.groupFormed) {
|
|
225
|
+
Log.d(TAG, "Wi-Fi Direct group found. Removing group.");
|
|
226
|
+
manager.removeGroup(channel, new WifiP2pManager.ActionListener() {
|
|
227
|
+
@Override
|
|
228
|
+
public void onSuccess() {
|
|
229
|
+
Log.d(TAG, "removeGroup success, disconnected.");
|
|
230
|
+
JSObject ret = new JSObject();
|
|
231
|
+
ret.put("disconnected", true);
|
|
232
|
+
call.resolve(ret);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
@Override
|
|
236
|
+
public void onFailure(int reason) {
|
|
237
|
+
Log.e(TAG, "removeGroup failed: " + reason);
|
|
238
|
+
call.reject("Failed to remove group: " + reason);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
} else {
|
|
242
|
+
Log.d(TAG, "No Wi-Fi Direct group to remove.");
|
|
243
|
+
call.reject("No Wi-Fi P2P group formed");
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
193
249
|
}
|