refactor(ibeacon):

This commit is contained in:
Guille 2016-07-17 19:55:18 +02:00
parent 1eed1a1cb3
commit f21c49e293

View File

@ -1,5 +1,6 @@
import {Plugin, Cordova} from './plugin';
import {Observable} from 'rxjs/Observable';
import { Cordova, Plugin } from './plugin';
import { Observable } from 'rxjs/Observable';
declare var cordova: any;
@ -21,7 +22,7 @@ export interface Beacon {
/**
* The proximity of the beacon relative to the phone.
*
*
* Possible options are:
* ProximityImmediate
* ProximityNear
@ -47,6 +48,7 @@ export interface Beacon {
accuracy: number;
}
export interface BeaconRegion {
/**
* A unique identifier for this region.
@ -76,6 +78,7 @@ export interface BeaconRegion {
*/
notifyEntryStateOnDisplay?: boolean;
}
export interface CircularRegion {
/**
* A unique identifier for this region.
@ -97,6 +100,7 @@ export interface CircularRegion {
*/
radius: number;
}
export type Region = BeaconRegion | CircularRegion;
export interface PluginResult {
@ -131,10 +135,11 @@ export interface PluginResult {
*/
error: string;
}
export interface Delegate {
/**
* An observable that publishes information about the location permission authorization status.
*
*
* @return Returns a string.
*/
didChangeAuthorizationStatus(): Observable<string>;
@ -142,10 +147,10 @@ export interface Delegate {
/**
* An Observable that publishes event data to it's subscribers
* when the native layer is able to determine the device's state.
*
*
* This event is called when the phone begins starts monitoring,
* when requestStateForRegion is called, etc.
*
*
* @return {PluginResult} Returns a PluginResult object with information about the event, region, and beacon(s).
*/
didDetermineStateForRegion(): Observable<PluginResult>;
@ -153,32 +158,32 @@ export interface Delegate {
/**
* An Observable that publishes event data to it's subscribers
* when the phone enters a region that it was asked to monitor.
*
*
* If the user has given the app Always-Location permission, this function
* will be called even when the app is not running on iOS.
* The app will run silently in the background for a small amount of time.
*
*
* @return {PluginResult} Returns a PluginResult object with information about the event, region, and beacon(s).
*/
didEnterRegion(): Observable<PluginResult>;
/**
* An Observable that publishes event data to it's subscribers
* An Observable that publishes event data to it's subscribers
* when the phone exits a region that it was asked to monitor.
*
*
* If the user has given the app Always-Location permission, this function
* will be called even when the app is not running on iOS.
* The app will run silently in the background for a small amount of time.
*
*
* @return {PluginResult} Returns a PluginResult object with information about the event, region, and beacon(s).
*/
didExitRegion(): Observable<PluginResult>;
/**
* An Observable that publishes event data to it's subscribers
* each time that the device ranges beacons. Modern Android and iOS devices range
* each time that the device ranges beacons. Modern Android and iOS devices range
* aproximately once per second.
*
*
* @return {PluginResult} Returns a PluginResult object with information about the event, region, and beacon(s).
*/
didRangeBeaconsInRegion(): Observable<PluginResult>;
@ -186,7 +191,7 @@ export interface Delegate {
/**
* An Observable that publishes event data to it's subscribers
* when the device begins monitoring a region.
*
*
* @return {PluginResult} Returns a PluginResult object with information about the event, region, and beacon(s).
*/
didStartMonitoringForRegion(): Observable<PluginResult>;
@ -194,7 +199,7 @@ export interface Delegate {
/**
* An Observable that publishes event data to it's subscribers
* when the device fails to monitor a region.
*
*
* @return {PluginResult} Returns a PluginResult object with information about the event, region, and beacon(s).
*/
monitoringDidFailForRegionWithError(): Observable<PluginResult>;
@ -202,16 +207,16 @@ export interface Delegate {
/**
* An Observable that publishes event data to it's subscribers
* when the device begins advertising as an iBeacon.
*
*
* @return {PluginResult} Returns a PluginResult object with information about the event, region, and beacon(s).
*/
peripheralManagerDidStartAdvertising(): Observable<PluginResult>;
/**
* An Observable that publishes event data to it's subscribers
* An Observable that publishes event data to it's subscribers
* when the state of the peripheral manager's state updates.
*
*
*
*
* @return {PluginResult} Returns a PluginResult object with information about the event, region, and beacon(s).
*/
peripheralManagerDidUpdateState(): Observable<PluginResult>;
@ -234,7 +239,7 @@ export interface Delegate {
* IBeacon.requestAlwaysAuthorization();
* // create a new delegate and register it with the native layer
* let delegate = IBeacon.Delegate();
*
*
* // Subscribe to some of the delegate's event handlers
* delegate.didRangeBeaconsInRegion()
* .subscribe(
@ -252,9 +257,9 @@ export interface Delegate {
* console.log('didEnterRegion: ', data);
* }
* );
*
*
* let beaconRegion = IBeacon.BeaconRegion('deskBeacon','F7826DA6-ASDF-ASDF-8024-BC5B71E0893E');
*
*
* IBeacon.startMonitoringForRegion(beaconRegion)
* .then(
* () => console.log('Native layer recieved the request to monitoring'),
@ -263,18 +268,17 @@ export interface Delegate {
* ```
*/
@Plugin({
plugin: 'cordova-plugin-ibeacon',
pluginRef: 'cordova.plugins.locationManager',
repo: 'https://github.com/petermetz/cordova-plugin-ibeacon',
platforms: ['Android', 'iOS']
plugin: 'cordova-plugin-ibeacon',
pluginRef: 'cordova.plugins.locationManager',
repo: 'https://github.com/petermetz/cordova-plugin-ibeacon',
platforms: ['Android', 'iOS']
})
export class IBeacon {
/**
* Instances of this class are delegates between the {@link LocationManager} and
* the code that consumes the messages generated on in the native layer.
*
*
* @returns {Delegate} An instance of the type {@type Delegate}.
*/
static Delegate(): Delegate {
@ -367,14 +371,14 @@ export class IBeacon {
/**
* Creates a new BeaconRegion
*
*
* @param {String} identifier @see {CLRegion}
* @param {String} uuid The proximity ID of the beacon being targeted.
* @param {String} uuid The proximity ID of the beacon being targeted.
* This value must not be blank nor invalid as a UUID.
* @param {Number} major The major value that you use to identify one or more beacons.
* @param {Number} minor The minor value that you use to identify a specific beacon.
* @param {BOOL} notifyEntryStateOnDisplay
*
*
* @return Returns the BeaconRegion that was created
*/
static BeaconRegion(identifer: string, uuid: string, major?: number, minor?: number, notifyEntryStateOnDisplay?: boolean): BeaconRegion {
@ -389,7 +393,7 @@ export class IBeacon {
/**
* @param {Delegate} delegate An instance of a delegate to register with the native layer.
*
*
* @return Returns the Delegate
*/
@Cordova()
@ -399,15 +403,15 @@ export class IBeacon {
* Signals the native layer that the client side is ready to consume messages.
* Readiness here means that it has a {Delegate} set by the consumer javascript
* code.
*
*
* The {LocationManager.setDelegate()} will implicitly call this method as well,
* therefore the only case when you have to call this manually is if you don't
* wish to specify a {Delegate} of yours.
*
*
* The purpose of this signaling mechanism is to make the events work when the
* app is being woken up by the Operating System to give it a chance to handle
* region monitoring events for example.
*
*
* If you don't set a {Delegate} and don't call this method manually, an error
* message get emitted in the native runtime and the DOM as well after a certain
* period of time.
@ -447,9 +451,9 @@ export class IBeacon {
/**
* Start monitoring the specified region.
*
* If a region of the same type with the same identifier is already being
* If a region of the same type with the same identifier is already being
* monitored for this application,
* it will be removed from monitoring. For circular regions, the region
* it will be removed from monitoring. For circular regions, the region
* monitoring service will prioritize
* regions by their size, favoring smaller regions over larger regions.
*
@ -457,7 +461,7 @@ export class IBeacon {
*
* @param {Region} region An instance of {Region} which will be monitored
* by the operating system.
*
*
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the monitoring request.
*/
@ -465,16 +469,16 @@ export class IBeacon {
static startMonitoringForRegion(region: BeaconRegion): Promise<string> { return; }
/**
* Stop monitoring the specified region. It is valid to call
* stopMonitoringForRegion: for a region that was registered for monitoring
* with a different location manager object, during this or previous
* Stop monitoring the specified region. It is valid to call
* stopMonitoringForRegion: for a region that was registered for monitoring
* with a different location manager object, during this or previous
* launches of your application.
*
* This is done asynchronously and may not be immediately reflected in monitoredRegions.
*
* @param {Region} region An instance of {Region} which will be monitored
* by the operating system.
*
*
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the request to stop monitoring.
*/
@ -483,14 +487,14 @@ export class IBeacon {
/**
* Request state the for specified region. When result is ready
* didDetermineStateForRegion is triggered. This can be any region,
* also those which is not currently monitored.
* didDetermineStateForRegion is triggered. This can be any region,
* also those which is not currently monitored.
*
* This is done asynchronously and may not be immediately reflected in monitoredRegions.
*
* @param {Region} region An instance of {Region} which will be monitored
* by the operating system.
*
*
* @return Returns a promise which is resolved as soon as the
* native layer acknowledged the dispatch of the request to stop monitoring.
*/
@ -534,8 +538,8 @@ export class IBeacon {
/**
* Queries the native layer to determine the current authorization in effect.
*
* @returns Returns a promise which is resolved with the
*
* @returns Returns a promise which is resolved with the
* requested authorization status.
*/
@Cordova({sync: true})
@ -563,16 +567,16 @@ export class IBeacon {
@Cordova({sync: true})
static requestAlwaysAuthorization(): Promise<void> { return; }
/**
*
/**
*
* @returns Returns a promise which is resolved with an {Array}
* of {Region} instances that are being monitored by the native layer.
*/
@Cordova({sync: true})
static getMonitoredRegions(): Promise<Region[]> { return; }
/**
*
/**
*
* @returns Returns a promise which is resolved with an {Array}
* of {Region} instances that are being ranged by the native layer.
*/
@ -649,7 +653,7 @@ export class IBeacon {
/**
* Disables debug logging in the native layer. Use this method if you want
* to prevent this plugin from writing to the device logs.
*
*
* @returns Returns a promise which is resolved as soon as the
* native layer has set the logging level accordingly.
*/
@ -700,4 +704,4 @@ export class IBeacon {
@Cordova({sync: true})
static appendToDeviceLog(message: string): Promise<void> { return; }
}
}