thali
Version:
983 lines (346 loc) • 21.4 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: ThaliWifiInfrastructure</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: ThaliWifiInfrastructure</h1>
<section>
<header>
<h2>
<span class="ancestors"><a href="module-ThaliWifiInfrastructure.html">ThaliWifiInfrastructure</a>~</span>ThaliWifiInfrastructure</h2>
</header>
<article>
<div class="container-overview">
<h4 class="name" id="ThaliWifiInfrastructure"><span class="type-signature"></span>new ThaliWifiInfrastructure<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>This creates an object to manage a WiFi instance. During production we will
have exactly one instance running but for testing purposes it's very useful
to be able to run multiple instances. So long as the SSDP code uses a
different port to advertise for responses for each instance and as the router
instances are already specified to use whatever ports are available the
different instances should not run into each other.</p>
<p><strong>Open Issue:</strong> We need to confirm that the different instances will see
each other's SSDP advertisements and queries.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NextGeneration_thaliWifiInfrastructure.js.html">NextGeneration/thaliWifiInfrastructure.js</a>, <a href="NextGeneration_thaliWifiInfrastructure.js.html#line42">line 42</a>
</li></ul></dd>
</dl>
<h5>Fires:</h5>
<ul>
<li><a href="module-ThaliWifiInfrastructure.html#~event:wifiPeerAvailabilityChanged">event:wifiPeerAvailabilityChanged</a></li>
<li><a href="module-ThaliWifiInfrastructure.html#~event:networkChangedWifi">event:networkChangedWifi</a></li>
<li><a href="module-ThaliWifiInfrastructure.html#~event:discoveryAdvertisingStateUpdateWifiEvent">event:discoveryAdvertisingStateUpdateWifiEvent</a></li>
</ul>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="start"><span class="type-signature"></span>start<span class="signature">(router)</span><span class="type-signature"> → {Promise.<?Error>}</span></h4>
<div class="description">
<p>This method MUST be called before any other method here other than
registering for events on the emitter. This method only registers the router
object but otherwise doesn't really do anything. It's just here to mirror how
<a href="module-thaliMobileNativeWrapper.html">module:thaliMobileNativeWrapper</a> works.</p>
<p>If the start fails then the object is not in start state.</p>
<p>This method is not idempotent (even though it could be). If called two
times in a row without an intervening stop a "Call Stop!" Error MUST be
returned.</p>
<p>This method can be called after stop since this is a singleton object.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>router</code></td>
<td class="type">
<span class="param-type">Object</span>
</td>
<td class="description last"><p>This is an Express Router object (for example,
express-pouchdb is a router object) that the caller wants the WiFi
connections to be terminated with. This code will put that router at '/' so
make sure your paths are set up appropriately.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NextGeneration_thaliWifiInfrastructure.js.html">NextGeneration/thaliWifiInfrastructure.js</a>, <a href="NextGeneration_thaliWifiInfrastructure.js.html#line66">line 66</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<?Error></span>
</dd>
</dl>
<h4 class="name" id="startListeningForAdvertisements"><span class="type-signature"></span>startListeningForAdvertisements<span class="signature">()</span><span class="type-signature"> → {Promise.<?Error>}</span></h4>
<div class="description">
<p>This will start the local Wi-Fi Infrastructure Mode discovery mechanism
(currently SSDP). Calling this method will trigger <a href="module-ThaliWifiInfrastructure.html#~event:wifiPeerAvailabilityChanged">event:wifiPeerAvailabilityChanged</a> to fire. This method only causes SSDP
queries to be fired and cause us to listen to other service's SSDP:alive and
SSDP:byebye messages. It doesn't advertise the service itself.</p>
<p>This method is idempotent so multiple consecutive calls without an
intervening call to stop will not cause a state change.</p>
<table>
<thead>
<tr>
<th>Error String</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>No Wifi radio</td>
<td>This device doesn't support Wifi</td>
</tr>
<tr>
<td>Radio Turned Off</td>
<td>Wifi is turned off.</td>
</tr>
<tr>
<td>Unspecified Error with Radio infrastructure</td>
<td>Something went wrong trying to use WiFi. Check the logs.</td>
</tr>
<tr>
<td>Call Start!</td>
<td>The object is not in start state.</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NextGeneration_thaliWifiInfrastructure.js.html">NextGeneration/thaliWifiInfrastructure.js</a>, <a href="NextGeneration_thaliWifiInfrastructure.js.html#line104">line 104</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<?Error></span>
</dd>
</dl>
<h4 class="name" id="startUpdateAdvertisingAndListening"><span class="type-signature"></span>startUpdateAdvertisingAndListening<span class="signature">()</span><span class="type-signature"> → {Promise.<?Error>}</span></h4>
<div class="description">
<p>This method will start advertising the peer's presence over the local Wi-Fi
Infrastructure Mode discovery mechanism (currently SSDP). When creating the
UDP socket for SSDP the socket MUST be "udp4". When socket.bind is called to
bind the socket to the SSDP multicast address and port, a random port will
automatically be picked by Node.js to bind the UDP port to locally. This
address is needed in order to set the location header in SSDP messages. This
port can be discovered via socket.address().port in the callback to the
socket.bind call. Note that we MUST make sure that the SSDP local UDP port is
picked randomly so we do not have collisions between multiple instances of
<a href="module-ThaliWifiInfrastructure.html">module:ThaliWifiInfrastructure</a>. Also note that the implementation of
SSDP MUST recognize advertisements from its own instance and ignore them.
However it is possible to have multiple independent instances of
ThaliWiFiInfrastructure on the same device and we MUST process advertisements
from other instances of ThaliWifiInfrastructure on the same device.</p>
<p>This method will also cause the Express app passed in to be hosted in a
HTTP server configured with the device's local IP. In other words, the
externally available HTTP server is not actually started and made externally
available until this method is called. This is different than <a href="module-thaliMobileNative.html">module:thaliMobileNative</a> where the server is started on 127.0.0.1 as soon as
module:thaliMobileNative.start is called but isn't made externally
available over the non-TCP transport until the equivalent of this method is
called. If the device switches access points (e.g. the BSSID changes) or if
WiFi is lost then the server will be shut down. It is up to the caller to
catch the networkChanged event and to call start advertising again.</p>
<p><strong>OPEN ISSUE:</strong> If we have a properly configured multiple AP network then
all the APs will have different BSSID values but identical SSID values and
the device should be able to keep the same IP. In that case do we want to
specify that if the BSSID changes but the SSID does not then we shouldn't
shut down the server?</p>
<p>Each time this method is called it will cause the local advertisement to
change just enough to notify other peers that this peer has new data to
retrieve. No details will be provided about the peer on who the changes are
for. All that is provided is a flag just indicating that something has
changed. It is up to other peer to connect and retrieve details on what has
changed if they are interested.</p>
<ul>
<li>By design this method is intended to be called multiple times without
calling stop as each call causes the currently notification flag to change.</li>
</ul>
<table>
<thead>
<tr>
<th>Error String</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bad Router</td>
<td>router is null or otherwise wasn't accepted by Express</td>
</tr>
<tr>
<td>No Wifi radio</td>
<td>This device doesn't support Wifi</td>
</tr>
<tr>
<td>Radio Turned Off</td>
<td>Wifi is turned off.</td>
</tr>
<tr>
<td>Unspecified Error with Radio infrastructure</td>
<td>Something went wrong trying to use WiFi. Check the logs.</td>
</tr>
<tr>
<td>Call Start!</td>
<td>The object is not in start state.</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NextGeneration_thaliWifiInfrastructure.js.html">NextGeneration/thaliWifiInfrastructure.js</a>, <a href="NextGeneration_thaliWifiInfrastructure.js.html#line183">line 183</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<?Error></span>
</dd>
</dl>
<h4 class="name" id="stop"><span class="type-signature"></span>stop<span class="signature">()</span><span class="type-signature"> → {Promise.<?Error>}</span></h4>
<div class="description">
<p>This method will call all the stop methods and stop the TCP server hosting
the router.</p>
<p>Once called the object is in the stop state.</p>
<p>This method is idempotent and so MUST be able to be called multiple timex
in a row without changing state.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NextGeneration_thaliWifiInfrastructure.js.html">NextGeneration/thaliWifiInfrastructure.js</a>, <a href="NextGeneration_thaliWifiInfrastructure.js.html#line81">line 81</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<?Error></span>
</dd>
</dl>
<h4 class="name" id="stopAdvertisingAndListening"><span class="type-signature"></span>stopAdvertisingAndListening<span class="signature">()</span><span class="type-signature"> → {Promise.<?Error>}</span></h4>
<div class="description">
<p>This method MUST stop advertising the peer's presence over the local Wi-Fi
Infrastructure Mode discovery mechanism (currently SSDP). This method MUST
also stop the HTTP server started by the start method.</p>
<p>So long as the device isn't advertising the peer and the server is stopped
(even if the system was always in that state) then this method MUST succeed.</p>
<table>
<thead>
<tr>
<th>Error String</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Failed</td>
<td>Somehow the stop method couldn't do its job. Check the logs.</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NextGeneration_thaliWifiInfrastructure.js.html">NextGeneration/thaliWifiInfrastructure.js</a>, <a href="NextGeneration_thaliWifiInfrastructure.js.html#line201">line 201</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<?Error></span>
</dd>
</dl>
<h4 class="name" id="stopListeningForAdvertisements"><span class="type-signature"></span>stopListeningForAdvertisements<span class="signature">()</span><span class="type-signature"> → {Promise.<?Error>}</span></h4>
<div class="description">
<p>This will stop the local Wi-Fi Infrastructure Mode discovery mechanism
(currently SSDP). Calling this method will stop <a href="module-ThaliWifiInfrastructure.html#~event:wifiPeerAvailabilityChanged">event:wifiPeerAvailabilityChanged</a> from firing. That is, we will not issue
any further SSDP queries nor will we listen for other service's SSDP:alive or
SSDP:byebye messages.</p>
<p>Note that this method does not affect any existing TCP connections. Not
that we could really do anything with them since they are handled directly by
Node, not us.</p>
<table>
<thead>
<tr>
<th>Error String</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Failed</td>
<td>Somehow the stop method couldn't do its job. Check the logs.</td>
</tr>
</tbody>
</table>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="NextGeneration_thaliWifiInfrastructure.js.html">NextGeneration/thaliWifiInfrastructure.js</a>, <a href="NextGeneration_thaliWifiInfrastructure.js.html#line126">line 126</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<?Error></span>
</dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-TCPServersManager.html">TCPServersManager</a></li><li><a href="module-thaliMobile.html">thaliMobile</a></li><li><a href="module-thaliMobileNative.html">thaliMobileNative</a></li><li><a href="module-thaliMobileNativeWrapper.html">thaliMobileNativeWrapper</a></li><li><a href="module-thaliNotificationAction.html">thaliNotificationAction</a></li><li><a href="module-thaliNotificationBeacons.html">thaliNotificationBeacons</a></li><li><a href="module-thaliNotificationClient.html">thaliNotificationClient</a></li><li><a href="module-thaliNotificationServer.html">thaliNotificationServer</a></li><li><a href="module-thaliPeerAction.html">thaliPeerAction</a></li><li><a href="module-thaliPeerDictionary.html">thaliPeerDictionary</a></li><li><a href="module-thaliPeerPoolInterface.html">thaliPeerPoolInterface</a></li><li><a href="module-ThaliWifiInfrastructure.html">ThaliWifiInfrastructure</a></li><li><a href="module-WifiBasedNativeMock.html">WifiBasedNativeMock</a></li></ul><h3>Externals</h3><ul><li><a href="external-_Mobile(_connect_)_.html">Mobile('connect')</a></li><li><a href="external-_Mobile(_discoveryAdvertisingStateUpdateNonTCP_)_.html">Mobile('discoveryAdvertisingStateUpdateNonTCP')</a></li><li><a href="external-_Mobile(_incomingConnectionToPortNumberFailed_)_.html">Mobile('incomingConnectionToPortNumberFailed')</a></li><li><a href="external-_Mobile(_killConnections_)_.html">Mobile('killConnections')</a></li><li><a href="external-_Mobile(_networkChanged_)_.html">Mobile('networkChanged')</a></li><li><a href="external-_Mobile(_peerAvailabilityChanged_)_.html">Mobile('peerAvailabilityChanged')</a></li><li><a href="external-_Mobile(_startListeningForAdvertisements_)_.html">Mobile('startListeningForAdvertisements')</a></li><li><a href="external-_Mobile(_startUpdateAdvertisingAndListening_)_.html">Mobile('startUpdateAdvertisingAndListening')</a></li><li><a href="external-_Mobile(_stopAdvertisingAndListening_)_.html">Mobile('stopAdvertisingAndListening')</a></li><li><a href="external-_Mobile(_stopListeningForAdvertisements_)_.html">Mobile('stopListeningForAdvertisements')</a></li></ul><h3>Classes</h3><ul><li><a href="ConnectionTable.html">ConnectionTable</a></li><li><a href="module-TCPServersManager-TCPServersManager.html">TCPServersManager</a></li><li><a href="module-thaliNotificationAction-NotificationAction.html">NotificationAction</a></li><li><a href="module-thaliNotificationBeacons-ParseBeaconsResponse.html">ParseBeaconsResponse</a></li><li><a href="module-thaliNotificationClient-ThaliNotificationClient.html">ThaliNotificationClient</a></li><li><a href="module-thaliNotificationServer-ThaliNotificationServer.html">ThaliNotificationServer</a></li><li><a href="module-thaliPeerAction-PeerAction.html">PeerAction</a></li><li><a href="module-thaliPeerDictionary-NotificationPeerDictionaryEntry.html">NotificationPeerDictionaryEntry</a></li><li><a href="module-thaliPeerDictionary-PeerConnectionInformation.html">PeerConnectionInformation</a></li><li><a href="module-thaliPeerDictionary-PeerDictionary.html">PeerDictionary</a></li><li><a href="module-thaliPeerPoolInterface-ThaliPeerPoolInterface.html">ThaliPeerPoolInterface</a></li><li><a href="module-ThaliWifiInfrastructure-ThaliWifiInfrastructure.html">ThaliWifiInfrastructure</a></li><li><a href="module-WifiBasedNativeMock-MobileCallInstance.html">MobileCallInstance</a></li><li><a href="module-WifiBasedNativeMock-WifiBasedNativeMock.html">WifiBasedNativeMock</a></li></ul><h3>Events</h3><ul><li><a href="module-thaliMobileNativeWrapper.html#~event:discoveryAdvertisingStateUpdateNonTCPEvent">discoveryAdvertisingStateUpdateNonTCPEvent</a></li><li><a href="module-ThaliWifiInfrastructure.html#~event:discoveryAdvertisingStateUpdateWifiEvent">discoveryAdvertisingStateUpdateWifiEvent</a></li><li><a href="module-TCPServersManager.html#~event:failedConnection">failedConnection</a></li><li><a href="module-thaliMobileNativeWrapper.html#~event:incomingConnectionToPortNumberFailed">incomingConnectionToPortNumberFailed</a></li><li><a href="module-thaliMobileNativeWrapper.html#~event:networkChangedNonTCP">networkChangedNonTCP</a></li><li><a href="module-ThaliWifiInfrastructure.html#~event:networkChangedWifi">networkChangedWifi</a></li><li><a href="module-thaliMobileNativeWrapper.html#~event:nonTCPPeerAvailabilityChangedEvent">nonTCPPeerAvailabilityChangedEvent</a></li><li><a href="module-TCPServersManager.html#~event:routerPortConnectionFailed">routerPortConnectionFailed</a></li><li><a href="module-ThaliWifiInfrastructure.html#~event:wifiPeerAvailabilityChanged">wifiPeerAvailabilityChanged</a></li><li><a href="module-thaliMobile.html#.event:event:discoveryAdvertisingStateUpdate">discoveryAdvertisingStateUpdate</a></li><li><a href="module-thaliMobile.html#.event:event:networkChanged">networkChanged</a></li><li><a href="module-thaliMobile.html#.event:event:peerAvailabilityChanged">peerAvailabilityChanged</a></li><li><a href="module-thaliNotificationAction-NotificationAction.html#.event:event:Resolved">Resolved</a></li><li><a href="module-thaliNotificationClient.html#.event:event:peerAdvertisesDataForUs">peerAdvertisesDataForUs</a></li></ul><h3>Global</h3><ul><li><a href="global.html#getPKCS12Content">getPKCS12Content</a></li><li><a href="global.html#getPublicKeyHash">getPublicKeyHash</a></li><li><a href="global.html#stopThaliReplicationManager">stopThaliReplicationManager</a></li><li><a href="global.html#ThaliEmitter">ThaliEmitter</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a> on Mon Jan 18 2016 11:19:32 GMT+0200 (EET)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>