Revision 120451 of Monitoring WiFi access points

  • Revision slug: Monitoring_WiFi_access_points
  • Revision title: Monitoring WiFi access points
  • Revision id: 120451
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment no wording changes
Tags: 

Revision Content

{{ gecko_minversion_header("1.9.1") }}

Code with UniversalXPConnect privileges can monitor the list of available WiFi access points to obtain information about them including their SSID, MAC address, and signal strength.  This capability was introduced primarily to allow WiFi-based location services to be used by geolocation services.

Example

This example simply displays a list of the available access points.

<html>
<head>
<title>WiFi Monitor Example</title>
<script>

var count = 0;

function test() {
}

test.prototype =
{
  onChange: function (accessPoints)
  {
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    var d = document.getElementById("d");
    d.innerHTML = "";

    for (var i=0; i<accessPoints.length; i++) {
      var a = accessPoints[i];
      d.innerHTML = d.innerHTML + "<p>" + a.mac + " " + a.ssid + " " + a.signal + "</p>";
    }

    var c = document.getElementById("c");
    c.innerHTML = "<p>" + count++ + "</p>";

  },

  onError: function (value) {
     alert("error: " +value);
  },

  QueryInterface: function(iid) {
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        if (iid.equals(Components.interfaces.nsIWifiListener) ||
            iid.equals(Components.interfaces.nsISupports))
            return this;
        throw Components.results.NS_ERROR_NO_INTERFACE;
   },
}

  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

  var listener = new test();
  var wifi_service = Components.classes["@mozilla.org/wifi/monitor;1"].getService(Components.interfaces.nsIWifiMonitor);

  wifi_service.startWatching(listener);

</script>
</head>

<body>
<div id="d"><p></p></div>
<div id="c"><p></p></div>
</body>
</html>

foo

Revision Source

<p>{{ gecko_minversion_header("1.9.1") }}</p>
<p>Code with UniversalXPConnect privileges can monitor the list of available WiFi access points to obtain information about them including their SSID, MAC address, and signal strength.  This capability was introduced primarily to allow WiFi-based location services to be used by <a class="internal" href="/En/Using_geolocation" title="En/Using geolocation">geolocation</a> services.</p>
<h2>Example</h2>
<p>This example simply displays a list of the available access points.</p>
<pre class="brush: html">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;WiFi Monitor Example&lt;/title&gt;
&lt;script&gt;

var count = 0;

function test() {
}

test.prototype =
{
  onChange: function (accessPoints)
  {
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    var d = document.getElementById("d");
    d.innerHTML = "";

    for (var i=0; i&lt;accessPoints.length; i++) {
      var a = accessPoints[i];
      d.innerHTML = d.innerHTML + "&lt;p&gt;" + a.mac + " " + a.ssid + " " + a.signal + "&lt;/p&gt;";
    }

    var c = document.getElementById("c");
    c.innerHTML = "&lt;p&gt;" + count++ + "&lt;/p&gt;";

  },

  onError: function (value) {
     alert("error: " +value);
  },

  QueryInterface: function(iid) {
        netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
        if (iid.equals(Components.interfaces.nsIWifiListener) ||
            iid.equals(Components.interfaces.nsISupports))
            return this;
        throw Components.results.NS_ERROR_NO_INTERFACE;
   },
}

  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

  var listener = new test();
  var wifi_service = Components.classes["@mozilla.org/wifi/monitor;1"].getService(Components.interfaces.nsIWifiMonitor);

  wifi_service.startWatching(listener);

&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id="d"&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;
&lt;div id="c"&gt;&lt;p&gt;&lt;/p&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre><h2>foo</h2>
Revert to this revision