SocketMobile / capturesdk_flutter

Public snapshot for flutter sdk
MIT License
3 stars 1 forks source link

No guid for close event #2

Closed Thembelani closed 1 year ago

Thembelani commented 2 years ago

Hi.

I am successfully receiving the deviceRemoval event however the guid is not set.

Screenshot 2022-06-07 at 04 11 52

Future<void> _closeDeviceHelper(e, handle) async { String guid = e.value.guid; String name = e.value.name; logger.log('Device Removal =>', name + ' ($guid)'); try { dynamic res = await _deviceCapture!.close(); if (res == 0) { List<DeviceInfo> arr = _devices; arr.removeWhere((element) => element.guid == guid); setState(() { _devices = arr; _currentScan = null; _deviceCapture = null; }); } _updateVals('Device Closed', 'Successfully removed "$name"'); } on CaptureException catch (exception) { _updateVals('${exception.code}', 'Unable to remove "$name"', exception.method, exception.details); } }

mcsocket commented 2 years ago

Hi @Thembelani,

When you say the guid is not set I am not sure I follow. Do you mean that you are not able to access the guid with e.value.guid? If you are passing the capture event in deviceRemoval to _closeDeviceHelper then it should be accessible.

Do you have a logger? If so, what does it print for logger.log('Device ${isManager ? 'Manager' : ''} Removal =>', name + ' ($guid)');? If not, try adding one and then share the information in the logger.

Please let us know if the issue persists!

Thembelani commented 2 years ago

Hi @mcsocket The is my code vs the output.

Screenshot 2022-06-08 at 18 39 29 Screenshot 2022-06-08 at 18 38 58

P.S. Thank you for helping me with this issue.

Thembelani commented 2 years ago

Hi @mcsocket

This issue arises when we pair a device that we do not open immediately with the following. dynamic res = await scanner.capture.openDevice(scanner.guid, _capture); or we close a device with the following. dynamic res = await scanner.capture.close();

In both cases, when the device shuts off and deviceRemoval event is fired, e.value.guid returns an empty string.

If we have a system where more than one device is paired, we should be open and close them while they are still paired.

EricGlaenzer commented 2 years ago

I'll have to double check but I think that's expected. When a device is not open in Capture, you will receive a device removal to indicate it's gone, but the guid would be null.