From 6fab67ca9ff4e4320007bbe40d4974836f9d59e0 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Thu, 5 May 2016 15:50:28 -0700 Subject: [PATCH 1/6] Adding some types to `plugins/hotspot.ts` --- src/plugins/hotspot.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/plugins/hotspot.ts b/src/plugins/hotspot.ts index 95d6d6f7c..9903f3a14 100644 --- a/src/plugins/hotspot.ts +++ b/src/plugins/hotspot.ts @@ -44,16 +44,16 @@ export class Hotspot { static getAllHotspotDevices(): Promise {return; } @Cordova() - static connectToHotspot(ssid, password): Promise {return; } + static connectToHotspot(ssid: string, password: string): Promise {return; } @Cordova() - static connectToWifiAuthEncrypt(ssid, password, authentication, encryption): Promise {return; } + static connectToWifiAuthEncrypt(ssid: string, password: string, authentication, encryption): Promise {return; } @Cordova() - static addWifiNetwork(ssid, mode, password): Promise {return; } + static addWifiNetwork(ssid: string, mode, password): Promise {return; } @Cordova() - static removeWifiNetwork(ssid): Promise {return; } + static removeWifiNetwork(ssid: string): Promise {return; } @Cordova() static isConnectedToInternet(): Promise {return; } @@ -77,7 +77,7 @@ export class Hotspot { static scanWifiByLevel(): Promise {return; } @Cordova() - static startPeriodicallyScan(interval, duration): Promise {return; } + static startPeriodicallyScan(interval: number, duration: number): Promise {return; } @Cordova() static stopPeriodicallyScan(): Promise {return; } @@ -89,16 +89,16 @@ export class Hotspot { static getConnectionInfo(): Promise {return; } @Cordova() - static pingHost(ip): Promise {return; } + static pingHost(ip: string): Promise {return; } @Cordova() - static getMacAddressOfHost(ip): Promise {return; } + static getMacAddressOfHost(ip: string): Promise {return; } @Cordova() - static isDnsLive(ip): Promise {return; } + static isDnsLive(ip: string): Promise {return; } @Cordova() - static isPortLife(ip): Promise {return; } + static isPortLife(ip: string): Promise {return; } @Cordova() static isRooted(): Promise {return; } From b4b131c82af080979c40d9a858a5aaaad22207b7 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Thu, 5 May 2016 17:57:49 -0700 Subject: [PATCH 2/6] Adding more typings for hotspot.ts --- src/plugins/connection-info.model.ts | 27 ++++ src/plugins/hotspot-device.model.ts | 12 ++ src/plugins/hotspot.ts | 198 +++++++++++++++++++++------ src/plugins/network-config.model.ts | 18 +++ src/plugins/network.model.ts | 32 +++++ 5 files changed, 244 insertions(+), 43 deletions(-) create mode 100644 src/plugins/connection-info.model.ts create mode 100644 src/plugins/hotspot-device.model.ts create mode 100644 src/plugins/network-config.model.ts create mode 100644 src/plugins/network.model.ts diff --git a/src/plugins/connection-info.model.ts b/src/plugins/connection-info.model.ts new file mode 100644 index 000000000..572b7a99f --- /dev/null +++ b/src/plugins/connection-info.model.ts @@ -0,0 +1,27 @@ +export class ConnectionInfo { + /** + * @property {string} SSID + * The service set identifier (SSID) of the current 802.11 network. + */ + SSID: string; + /** + * @property {string} BSSID + * The basic service set identifier (BSSID) of the current access point. + */ + BSSID: string; + /** + * @property {string} linkSpeed + * The current link speed in Mbps + */ + linkSpeed: string; + /** + * @property {string} IPAddress + * The IP Address + */ + IPAddress: string; + /** + * @property {string} networkID + * Each configured network has a unique small integer ID, used to identify the network when performing operations on the supplicant. + */ + networkID: string; +} diff --git a/src/plugins/hotspot-device.model.ts b/src/plugins/hotspot-device.model.ts new file mode 100644 index 000000000..ffb727eb8 --- /dev/null +++ b/src/plugins/hotspot-device.model.ts @@ -0,0 +1,12 @@ +export class HotspotDevice { + /** + * @property {string} ip + * Hotspot IP Address + */ + ip: string; + /** + * @property {string} mac + * Hotspot MAC Address + */ + mac: string; +} diff --git a/src/plugins/hotspot.ts b/src/plugins/hotspot.ts index 9903f3a14..d294e208e 100644 --- a/src/plugins/hotspot.ts +++ b/src/plugins/hotspot.ts @@ -1,5 +1,10 @@ import {Plugin, Cordova} from './plugin'; +import {Network} from './network.model'; +import {NetworkConfig} from './network-config.model'; +import {ConnectionInfo} from './connection-info.model'; +import {HotspotDevice} from './hotspot-device.model'; + /** * @name Hotspot * @description @@ -23,58 +28,139 @@ export class Hotspot { static isAvailable(): Promise {return; } @Cordova() - static toggleWifi(): Promise {return; } + static toggleWifi(): Promise {return; } + + /** + * Configures and starts hotspot with SSID and Password + * + * @param {string} SSID - SSID of your new Access Point + * @param {string} mode - encryption mode (Open, WEP, WPA, WPA_PSK) + * @param {string} password - password for your new Access Point + * + * @return {Promise} - Promise to call once hotspot is started, or reject upon failure + */ + @Cordova() + static createHotspot(ssid: string, mode: string, password: string): Promise {return; } + + /** + * Turns on Access Point + * + * @return {Promise} - true if AP is started + */ + @Cordova() + static startHotspot(): Promise {return; } + + /** + * Configures hotspot with SSID and Password + * + * @param {string} SSID - SSID of your new Access Point + * @param {string} mode - encryption mode (Open, WEP, WPA, WPA_PSK) + * @param {string} password - password for your new Access Point + * + * @return {Promise} - Promise to call when hotspot is configured, or reject upon failure + */ + @Cordova() + static configureHotspot(ssid: string, mode: string, password: string): Promise {return; } + + /** + * Turns off Access Point + * + * @return {Promise} - Promise to turn off the hotspot, true on success, false on failure + */ + @Cordova() + static stopHotspot(): Promise {return; } + + /** + * Checks if hotspot is enabled + * + * @return {Promise} - Promise that hotspot is enabled, rejected if it is not enabled + */ + @Cordova() + static isHotspotEnabled(): Promise {return; } @Cordova() - static createHotspot(ssid: string, mode: string, password: string): Promise {return; } + static getAllHotspotDevices(): Promise> {return; } + + /** + * Connect to a WiFi network + * + * @param {string} ssid + * SSID to connect + * @param {string} password + * password to use + * + * @return {Promise} + * Promise that connection to the WiFi network was successfull, rejected if unsuccessful + */ + @Cordova() + static connectToHotspot(ssid: string, password: string): Promise {return; } + + /** + * Connect to a WiFi network + * + * @param {string} ssid + * SSID to connect + * @param {string} password + * Password to use + * @param {string} authentication + * Authentication modes to use (LEAP, SHARED, OPEN) + * @param {string[]} encryption + * Encryption modes to use (CCMP, TKIP, WEP104, WEP40) + * + * @return {Promise} + * Promise that connection to the WiFi network was successfull, rejected if unsuccessful + */ + @Cordova() + static connectToWifiAuthEncrypt(ssid: string, password: string, authentication: string, encryption: Array): Promise {return; } + + /** + * Add a WiFi network + * + * @param {string} ssid + * SSID of network + * @param {string} mode + * Authentication mode of (Open, WEP, WPA, WPA_PSK) + * @param {string} password + * Password for network + * + * @return {Promise} + * Promise that adding the WiFi network was successfull, rejected if unsuccessful + */ + @Cordova() + static addWifiNetwork(ssid: string, mode: string, password: string): Promise {return; } + + /** + * Remove a WiFi network + * + * @param {string} ssid + * SSID of network + * + * @return {Promise} + * Promise that removing the WiFi network was successfull, rejected if unsuccessful + */ + @Cordova() + static removeWifiNetwork(ssid: string): Promise {return; } @Cordova() - static startHotspot(): Promise {return; } + static isConnectedToInternet(): Promise {return; } @Cordova() - static configureHotspot(ssid: string, mode: string, password: string): Promise {return; } + static isConnectedToInternetViaWifi(): Promise {return; } @Cordova() - static stopHotspot(): Promise {return; } + static isWifiOn(): Promise {return; } @Cordova() - static isHotspotEnabled(): Promise {return; } + static isWifiSupported(): Promise {return; } @Cordova() - static getAllHotspotDevices(): Promise {return; } + static isWifiDirectSupported(): Promise {return; } @Cordova() - static connectToHotspot(ssid: string, password: string): Promise {return; } + static scanWifi(): Promise> {return; } @Cordova() - static connectToWifiAuthEncrypt(ssid: string, password: string, authentication, encryption): Promise {return; } - - @Cordova() - static addWifiNetwork(ssid: string, mode, password): Promise {return; } - - @Cordova() - static removeWifiNetwork(ssid: string): Promise {return; } - - @Cordova() - static isConnectedToInternet(): Promise {return; } - - @Cordova() - static isConnectedToInternetViaWifi(): Promise {return; } - - @Cordova() - static isWifiOn(): Promise {return; } - - @Cordova() - static isWifiSupported(): Promise {return; } - - @Cordova() - static isWifiDirectSupported(): Promise {return; } - - @Cordova() - static scanWifi(): Promise {return; } - - @Cordova() - static scanWifiByLevel(): Promise {return; } + static scanWifiByLevel(): Promise> {return; } @Cordova() static startPeriodicallyScan(interval: number, duration: number): Promise {return; } @@ -83,24 +169,50 @@ export class Hotspot { static stopPeriodicallyScan(): Promise {return; } @Cordova() - static getNetConfig(): Promise {return; } + static getNetConfig(): Promise {return; } @Cordova() - static getConnectionInfo(): Promise {return; } + static getConnectionInfo(): Promise {return; } @Cordova() - static pingHost(ip: string): Promise {return; } + static pingHost(ip: string): Promise {return; } + /** + * Gets MAC Address associated with IP Address from ARP File + * + * @param {string} ip - IP Address that you want the MAC Address of + * + * @return {Promise} - A Promise for the MAC Address + */ @Cordova() - static getMacAddressOfHost(ip: string): Promise {return; } + static getMacAddressOfHost(ip: string): Promise {return; } + /** + * Checks if IP is live using DNS + * + * @param {string} ip - IP Address you want to test + * + * @return {Promise} - A Promise for whether the IP Address is reachable + */ @Cordova() - static isDnsLive(ip: string): Promise {return; } + static isDnsLive(ip: string): Promise {return; } + /** + * Checks if IP is live using socket And PORT + * + * @param {string} ip - IP Address you want to test + * + * @return {Promise} - A Promise for whether the IP Address is reachable + */ @Cordova() - static isPortLife(ip: string): Promise {return; } + static isPortLife(ip: string): Promise {return; } + /** + * Checks if device is rooted + * + * @return {Promise} - A Promise for whether the device is rooted + */ @Cordova() - static isRooted(): Promise {return; } + static isRooted(): Promise {return; } } diff --git a/src/plugins/network-config.model.ts b/src/plugins/network-config.model.ts new file mode 100644 index 000000000..c2fafa934 --- /dev/null +++ b/src/plugins/network-config.model.ts @@ -0,0 +1,18 @@ +export class NetworkConfig { + /** + * @property {string} deviceIPAddress - Device IP Address + */ + deviceIPAddress: string; + /** + * @property {string} deviceMacAddress - Device MAC Address + */ + deviceMacAddress: string; + /** + * @property {string} gatewayIPAddress - Gateway IP Address + */ + gatewayIPAddress: string; + /** + * @property {string} gatewayMacAddress - Gateway MAC Address + */ + gatewayMacAddress: string; +} diff --git a/src/plugins/network.model.ts b/src/plugins/network.model.ts new file mode 100644 index 000000000..8260791d8 --- /dev/null +++ b/src/plugins/network.model.ts @@ -0,0 +1,32 @@ +export class Network { + /** + * @property {string} SSID + * Human readable network name + */ + SSID: string; + /** + * @property {string} BSSID + * MAC Address of the access point + */ + BSSID: string; + /** + * @property {number (int)} frequency + * The primary 20 MHz frequency (in MHz) of the channel over which the client is communicating with the access point. + */ + frequency: number; + /** + * @property {number} level + * The detected signal level in dBm, also known as the RSSI. + */ + level: number; + /** + * @property {number} timestamp + * Timestamp in microseconds (since boot) when this result was last seen. + */ + timestamp: number; + /** + * @property {string} capabilities + * Describes the authentication, key management, and encryption schemes supported by the access point. + */ + capabilities: string; +} From 9682ac8f1136baa8abb8ac849daed117177a1510 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Thu, 5 May 2016 18:06:33 -0700 Subject: [PATCH 3/6] Adding some JSDoc definitions --- src/plugins/connection-info.model.ts | 3 +++ src/plugins/hotspot-device.model.ts | 3 +++ src/plugins/hotspot.ts | 8 ++++++-- src/plugins/network-config.model.ts | 3 +++ src/plugins/network.model.ts | 5 +++++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/plugins/connection-info.model.ts b/src/plugins/connection-info.model.ts index 572b7a99f..21c785da9 100644 --- a/src/plugins/connection-info.model.ts +++ b/src/plugins/connection-info.model.ts @@ -1,3 +1,6 @@ +/** + * @name ConnectionInfo + */ export class ConnectionInfo { /** * @property {string} SSID diff --git a/src/plugins/hotspot-device.model.ts b/src/plugins/hotspot-device.model.ts index ffb727eb8..fd9a7f736 100644 --- a/src/plugins/hotspot-device.model.ts +++ b/src/plugins/hotspot-device.model.ts @@ -1,3 +1,6 @@ +/** + * @name HotspotDevice + */ export class HotspotDevice { /** * @property {string} ip diff --git a/src/plugins/hotspot.ts b/src/plugins/hotspot.ts index d294e208e..dfdefe312 100644 --- a/src/plugins/hotspot.ts +++ b/src/plugins/hotspot.ts @@ -10,9 +10,13 @@ import {HotspotDevice} from './hotspot-device.model'; * @description * @usage * ```js - * import {Hotspot} from 'ionic-native'; - * + * import {Hotspot, Network} from 'ionic-native'; * + * ... + * Hotspot.scanWifi().then((networks: Array) => { + * console.log(networks); + * }); + * ... * * ``` */ diff --git a/src/plugins/network-config.model.ts b/src/plugins/network-config.model.ts index c2fafa934..32164cddc 100644 --- a/src/plugins/network-config.model.ts +++ b/src/plugins/network-config.model.ts @@ -1,3 +1,6 @@ +/** + * @name ConnectionInfo + */ export class NetworkConfig { /** * @property {string} deviceIPAddress - Device IP Address diff --git a/src/plugins/network.model.ts b/src/plugins/network.model.ts index 8260791d8..45f930953 100644 --- a/src/plugins/network.model.ts +++ b/src/plugins/network.model.ts @@ -1,3 +1,8 @@ +/** + * @name Network + * @description + * Based on [ScanResult](http://developer.android.com/reference/android/net/wifi/ScanResult.html) + */ export class Network { /** * @property {string} SSID From 116dc1a1b36221898dcd12c1ec7e7521d0ebca37 Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Thu, 5 May 2016 19:01:07 -0700 Subject: [PATCH 4/6] Fixing typos --- src/plugins/hotspot.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/hotspot.ts b/src/plugins/hotspot.ts index dfdefe312..732a57e9a 100644 --- a/src/plugins/hotspot.ts +++ b/src/plugins/hotspot.ts @@ -97,7 +97,7 @@ export class Hotspot { * Promise that connection to the WiFi network was successfull, rejected if unsuccessful */ @Cordova() - static connectToHotspot(ssid: string, password: string): Promise {return; } + static connectToWifi(ssid: string, password: string): Promise {return; } /** * Connect to a WiFi network @@ -167,10 +167,10 @@ export class Hotspot { static scanWifiByLevel(): Promise> {return; } @Cordova() - static startPeriodicallyScan(interval: number, duration: number): Promise {return; } + static startWifiPeriodicallyScan(interval: number, duration: number): Promise {return; } @Cordova() - static stopPeriodicallyScan(): Promise {return; } + static stopWifiPeriodicallyScan(): Promise {return; } @Cordova() static getNetConfig(): Promise {return; } @@ -209,7 +209,7 @@ export class Hotspot { * @return {Promise} - A Promise for whether the IP Address is reachable */ @Cordova() - static isPortLife(ip: string): Promise {return; } + static isPortLive(ip: string): Promise {return; } /** * Checks if device is rooted From 6f50138d9e22292711e4bb3bbba7f2ab9280f55b Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Sun, 8 May 2016 18:56:18 -0700 Subject: [PATCH 5/6] Moving interface files around for organization --- src/plugins/hotspot.ts | 8 ++++---- .../connection-info.interface.ts} | 0 .../hotspot-device.interface.ts} | 0 .../network-config.interface.ts} | 0 .../{network.model.ts => interfaces/network.interface.ts} | 0 5 files changed, 4 insertions(+), 4 deletions(-) rename src/plugins/{connection-info.model.ts => interfaces/connection-info.interface.ts} (100%) rename src/plugins/{hotspot-device.model.ts => interfaces/hotspot-device.interface.ts} (100%) rename src/plugins/{network-config.model.ts => interfaces/network-config.interface.ts} (100%) rename src/plugins/{network.model.ts => interfaces/network.interface.ts} (100%) diff --git a/src/plugins/hotspot.ts b/src/plugins/hotspot.ts index 732a57e9a..27fdbff3a 100644 --- a/src/plugins/hotspot.ts +++ b/src/plugins/hotspot.ts @@ -1,9 +1,9 @@ import {Plugin, Cordova} from './plugin'; -import {Network} from './network.model'; -import {NetworkConfig} from './network-config.model'; -import {ConnectionInfo} from './connection-info.model'; -import {HotspotDevice} from './hotspot-device.model'; +import {Network} from './interfaces/network.interface'; +import {NetworkConfig} from './interfaces/network-config.interface'; +import {ConnectionInfo} from './interfaces/connection-info.interface'; +import {HotspotDevice} from './interfaces/hotspot-device.interface'; /** * @name Hotspot diff --git a/src/plugins/connection-info.model.ts b/src/plugins/interfaces/connection-info.interface.ts similarity index 100% rename from src/plugins/connection-info.model.ts rename to src/plugins/interfaces/connection-info.interface.ts diff --git a/src/plugins/hotspot-device.model.ts b/src/plugins/interfaces/hotspot-device.interface.ts similarity index 100% rename from src/plugins/hotspot-device.model.ts rename to src/plugins/interfaces/hotspot-device.interface.ts diff --git a/src/plugins/network-config.model.ts b/src/plugins/interfaces/network-config.interface.ts similarity index 100% rename from src/plugins/network-config.model.ts rename to src/plugins/interfaces/network-config.interface.ts diff --git a/src/plugins/network.model.ts b/src/plugins/interfaces/network.interface.ts similarity index 100% rename from src/plugins/network.model.ts rename to src/plugins/interfaces/network.interface.ts From b280c052c7f3f56ea58a6004a0c419b32483ed2b Mon Sep 17 00:00:00 2001 From: Louis Orleans Date: Sun, 8 May 2016 18:59:47 -0700 Subject: [PATCH 6/6] Actually exporting an interface instead of a class --- src/plugins/interfaces/connection-info.interface.ts | 2 +- src/plugins/interfaces/hotspot-device.interface.ts | 2 +- src/plugins/interfaces/network-config.interface.ts | 2 +- src/plugins/interfaces/network.interface.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/interfaces/connection-info.interface.ts b/src/plugins/interfaces/connection-info.interface.ts index 21c785da9..37a7c73b6 100644 --- a/src/plugins/interfaces/connection-info.interface.ts +++ b/src/plugins/interfaces/connection-info.interface.ts @@ -1,7 +1,7 @@ /** * @name ConnectionInfo */ -export class ConnectionInfo { +export interface ConnectionInfo { /** * @property {string} SSID * The service set identifier (SSID) of the current 802.11 network. diff --git a/src/plugins/interfaces/hotspot-device.interface.ts b/src/plugins/interfaces/hotspot-device.interface.ts index fd9a7f736..660dbb42c 100644 --- a/src/plugins/interfaces/hotspot-device.interface.ts +++ b/src/plugins/interfaces/hotspot-device.interface.ts @@ -1,7 +1,7 @@ /** * @name HotspotDevice */ -export class HotspotDevice { +export interface HotspotDevice { /** * @property {string} ip * Hotspot IP Address diff --git a/src/plugins/interfaces/network-config.interface.ts b/src/plugins/interfaces/network-config.interface.ts index 32164cddc..ce48444c0 100644 --- a/src/plugins/interfaces/network-config.interface.ts +++ b/src/plugins/interfaces/network-config.interface.ts @@ -1,7 +1,7 @@ /** * @name ConnectionInfo */ -export class NetworkConfig { +export interface NetworkConfig { /** * @property {string} deviceIPAddress - Device IP Address */ diff --git a/src/plugins/interfaces/network.interface.ts b/src/plugins/interfaces/network.interface.ts index 45f930953..16243a1c7 100644 --- a/src/plugins/interfaces/network.interface.ts +++ b/src/plugins/interfaces/network.interface.ts @@ -3,7 +3,7 @@ * @description * Based on [ScanResult](http://developer.android.com/reference/android/net/wifi/ScanResult.html) */ -export class Network { +export interface Network { /** * @property {string} SSID * Human readable network name