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