2017-06-19 111 views
0

我需要使用wifi直接連接Windows設備。我們的應用是科爾多瓦應用。下面是我寫的無線直接廣告的代碼。執行完整的代碼後無錯誤,m_Publisher狀態在執行start()後發生更改。但其他設備仍然無法看到WiFi Direct設備。WiFI Direct for cordova windows平臺

function enableStartWiFiDirect() { 

    var Api_DeviceName = Windows.Networking.Proximity.PeerFinder.displayName; 
    m_Publisher = Windows.Devices.WiFiDirect.WiFiDirectAdvertisementPublisher(); 
    m_Listener = new Windows.Devices.WiFiDirect.WiFiDirectConnectionListener(); 

    m_Listener.addEventListener("onconnectionrequested", onConnectionRequested); 

    m_Publisher.advertisement.IsAutonomousGroupOwnerEnabled = false; 

    m_Publisher.advertisement.ListenStateDiscoverability = 
     Windows.Devices.WiFiDirect.WiFiDirectAdvertisementListenStateDiscoverability.Normal; 

    var IE = new Windows.Devices.WiFiDirect.WiFiDirectInformationElement(); 

    // IE blob 
    var dataWriter = new Windows.Storage.Streams.DataWriter(); 
    dataWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf16LE; 
    dataWriter.writeString(Api_DeviceName); 
    IE.Value = dataWriter.detachBuffer(); 


    // OUI 
    var dataWriterOUI = new Windows.Storage.Streams.DataWriter(); 
    dataWriterOUI.writeBytes([0xAA, 0xBB, 0xCC]);//(Globals.CustomOui); 
    IE.Oui = dataWriterOUI.detachBuffer(); 

    IE.ouiType = 12;//(byte)Api_DeviceName.Length; 

    m_Publisher.advertisement.informationElements.push(IE); 

    m_Publisher.start(); 
    console.log('WiFi Direct Started'); 

    return "Advertisment started sucessfully"; 
} 

希望有人能幫助我解決這些問題。任何幫助將不勝感激

回答

0

我可以在cordova應用程序下面啓動WiFi Direct廣告。

startAdvertisment: function (successCallback, errorCallback, args) { 

     if (publisher === null) { 
      publisher = Windows.Devices.WiFiDirect.WiFiDirectAdvertisementPublisher(); 
     } 

     if (listener===null) { 
      listener = new Windows.Devices.WiFiDirect.WiFiDirectConnectionListener(); 

      listener.onconnectionrequested = OnConnectionRequested; 
     } 
     publisher.advertisement.isAutonomousGroupOwnerEnabled = false; 

     publisher.advertisement.listenStateDiscoverability = 
      Windows.Devices.WiFiDirect.WiFiDirectAdvertisementListenStateDiscoverability.normal; 
publisher.start(); 

    }