WiFiDirectDevice ConnectionStatusChanged Not Triggering RRS feed

  • Question

  • I'm trying to expand the WiFiDirect LegacySettings example to detect when a device is disconnected. I am assuming that the WiFiDirectDevice.ConnectionStatusChanged event should be triggered when a connected device is disconnected, so I'm connecting a handler to that even after the connection is made. However, the callback is never called.

    This is how I'm attempting to put it together starting with setting up the listener. For simplicity sake, I'm removing all the error handling and and a lot of superfluous code that is in the example. Should this work, or is there another way to detect that the device disconnected that I should be using.

    void WLanManager_WiFiDirect::StartListener() { HRESULT hr = S_OK; // Create WiFiDirectConnectionListener hr = Windows::Foundation::ActivateInstance(HStringReference(RuntimeClass_Windows_Devices_WiFiDirect_WiFiDirectConnectionListener).Get(), &_connectionListener); hr = _connectionListener->add_ConnectionRequested( Callback<ConnectionRequestedHandler>([this](IWiFiDirectConnectionListener* sender, IWiFiDirectConnectionRequestedEventArgs* args) -> HRESULT { HRESULT hr = S_OK;
            ComPtr<IAsyncOperation<WiFiDirectDevice*>> asyncAction; ... hr = asyncAction->put_Completed(Callback<FromIdAsyncHandler>([this](IAsyncOperation<WiFiDirectDevice*>* pHandler, AsyncStatus status) -> HRESULT { HRESULT hr = S_OK; Device device;

    . ... if (status == AsyncStatus::Completed) { // Get the WiFiDirectDevice object hr = pHandler->GetResults(device.wfdDevice.GetAddressOf()); ... hr = device.wfdDevice->add_ConnectionStatusChanged( Callback<ConnectionStatusChangedHandler>([this](IWiFiDirectDevice* device, IInspectable*) -> HRESULT { !!! This never gets called !!! return S_OK; }).Get(), &device.statusChangedToken); // Store the connected peer _connectedDevices.push_back(device); } else { ... } return hr; }).Get()); return hr; }).Get(), &_connectionRequestedToken); }

    • Edited by thePoet Tuesday, June 28, 2016 11:08 PM
    Tuesday, June 28, 2016 11:07 PM

All replies

  • I have done some additional testing by polling the status of the WiFiDirectDevice after the device is disconnected. The device never reports as having a disconnected state, even an hour after the disconnect occured.
    Wednesday, June 29, 2016 5:21 PM