我需要使用wifi直接连接Windows设备。我们的应用是cordova应用。下面是我写的wifi直接广告的代码。执行m_Publisher
后,完整的代码执行无错误,start()
状态会发生变化。但其他设备仍无法看到WiFi Direct设备。
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 :(得分: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();
}