UNPKG

22.9 kBJavaScriptView Raw
1"use strict";
2var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6 return c > 3 && r && Object.defineProperty(target, key, r), r;
7};
8var plugin_1 = require('./plugin');
9var Observable_1 = require('rxjs/Observable');
10/**
11 * @name IBeacon
12 * @description
13 * This plugin provides functions for working with iBeacons.
14 *
15 * The plugin's API closely mimics the one exposed through the [CLLocationManager](https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html) introduced in iOS 7.
16 *
17 * @usage
18 *
19 * ```typescript
20 * import { IBeacon } from 'ionic-native';
21 *
22 *
23 * // Request permission to use location on iOS
24 * IBeacon.requestAlwaysAuthorization();
25 * // create a new delegate and register it with the native layer
26 * let delegate = IBeacon.Delegate();
27 *
28 * // Subscribe to some of the delegate's event handlers
29 * delegate.didRangeBeaconsInRegion()
30 * .subscribe(
31 * data => console.log('didRangeBeaconsInRegion: ', data),
32 * error => console.error();
33 * );
34 * delegate.didStartMonitoringForRegion()
35 * .subscribe(
36 * data => console.log('didStartMonitoringForRegion: ', data),
37 * error => console.error();
38 * );
39 * delegate.didEnterRegion()
40 * .subscribe(
41 * data => {
42 * console.log('didEnterRegion: ', data);
43 * }
44 * );
45 *
46 * let beaconRegion = IBeacon.BeaconRegion('deskBeacon','F7826DA6-ASDF-ASDF-8024-BC5B71E0893E');
47 *
48 * IBeacon.startMonitoringForRegion(beaconRegion)
49 * .then(
50 * () => console.log('Native layer recieved the request to monitoring'),
51 * error => console.error('Native layer failed to begin monitoring: ', error)
52 * );
53 * ```
54 * @interfaces
55 * Beacon
56 * BeaconRegion
57 * CircularRegion
58 * IBeaconPluginResult
59 * IBeaconDelegate
60 *
61 */
62var IBeacon = (function () {
63 function IBeacon() {
64 }
65 /**
66 * Instances of this class are delegates between the {@link LocationManager} and
67 * the code that consumes the messages generated on in the native layer.
68 *
69 * @returns {IBeaconDelegate} An instance of the type {@type Delegate}.
70 */
71 IBeacon.Delegate = function () {
72 var delegate = new cordova.plugins.locationManager.Delegate();
73 delegate.didChangeAuthorizationStatus = function (pluginResult) {
74 return new Observable_1.Observable(function (observer) {
75 var cb = function (data) { return observer.next(data); };
76 return delegate.didChangeAuthorizationStatus = cb;
77 });
78 };
79 delegate.didDetermineStateForRegion = function (pluginResult) {
80 return new Observable_1.Observable(function (observer) {
81 var cb = function (data) { return observer.next(data); };
82 return delegate.didDetermineStateForRegion = cb;
83 });
84 };
85 delegate.didEnterRegion = function (pluginResult) {
86 return new Observable_1.Observable(function (observer) {
87 var cb = function (data) { return observer.next(data); };
88 return delegate.didEnterRegion = cb;
89 });
90 };
91 delegate.didExitRegion = function (pluginResult) {
92 return new Observable_1.Observable(function (observer) {
93 var cb = function (data) { return observer.next(data); };
94 return delegate.didExitRegion = cb;
95 });
96 };
97 delegate.didRangeBeaconsInRegion = function (pluginResult) {
98 return new Observable_1.Observable(function (observer) {
99 var cb = function (data) { return observer.next(data); };
100 return delegate.didRangeBeaconsInRegion = cb;
101 });
102 };
103 delegate.didStartMonitoringForRegion = function (pluginResult) {
104 return new Observable_1.Observable(function (observer) {
105 var cb = function (data) { return observer.next(data); };
106 return delegate.didStartMonitoringForRegion = cb;
107 });
108 };
109 delegate.monitoringDidFailForRegionWithError = function (pluginResult) {
110 return new Observable_1.Observable(function (observer) {
111 var cb = function (data) { return observer.next(data); };
112 return delegate.monitoringDidFailForRegionWithError = cb;
113 });
114 };
115 delegate.peripheralManagerDidStartAdvertising = function (pluginResult) {
116 return new Observable_1.Observable(function (observer) {
117 var cb = function (data) { return observer.next(data); };
118 return delegate.peripheralManagerDidStartAdvertising = cb;
119 });
120 };
121 delegate.peripheralManagerDidUpdateState = function (pluginResult) {
122 return new Observable_1.Observable(function (observer) {
123 var cb = function (data) { return observer.next(data); };
124 return delegate.peripheralManagerDidUpdateState = cb;
125 });
126 };
127 cordova.plugins.locationManager.setDelegate(delegate);
128 return delegate;
129 };
130 /**
131 * Creates a new BeaconRegion
132 *
133 * @param {String} identifier @see {CLRegion}
134 * @param {String} uuid The proximity ID of the beacon being targeted.
135 * This value must not be blank nor invalid as a UUID.
136 * @param {Number} major The major value that you use to identify one or more beacons.
137 * @param {Number} minor The minor value that you use to identify a specific beacon.
138 * @param {BOOL} notifyEntryStateOnDisplay
139 *
140 * @returns {BeaconRegion} Returns the BeaconRegion that was created
141 */
142 IBeacon.BeaconRegion = function (identifer, uuid, major, minor, notifyEntryStateOnDisplay) {
143 return new cordova.plugins.locationManager.BeaconRegion(identifer, uuid, major, minor, notifyEntryStateOnDisplay);
144 };
145 /**
146 * @returns {IBeaconDelegate} Returns the IBeaconDelegate
147 */
148 IBeacon.getDelegate = function () { return; };
149 /**
150 * @param {IBeaconDelegate} delegate An instance of a delegate to register with the native layer.
151 *
152 * @returns {IBeaconDelegate} Returns the IBeaconDelegate
153 */
154 IBeacon.setDelegate = function (delegate) { return; };
155 /**
156 * Signals the native layer that the client side is ready to consume messages.
157 * Readiness here means that it has a {IBeaconDelegate} set by the consumer javascript
158 * code.
159 *
160 * The {LocationManager.setDelegate()} will implicitly call this method as well,
161 * therefore the only case when you have to call this manually is if you don't
162 * wish to specify a {IBeaconDelegate} of yours.
163 *
164 * The purpose of this signaling mechanism is to make the events work when the
165 * app is being woken up by the Operating System to give it a chance to handle
166 * region monitoring events for example.
167 *
168 * If you don't set a {IBeaconDelegate} and don't call this method manually, an error
169 * message get emitted in the native runtime and the DOM as well after a certain
170 * period of time.
171 *
172 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
173 * native layer acknowledged the request and started to send events.
174 */
175 IBeacon.onDomDelegateReady = function () { return; };
176 /**
177 * Determines if bluetooth is switched on, according to the native layer.
178 * @returns {Promise<boolean>} Returns a promise which is resolved with a {Boolean}
179 * indicating whether bluetooth is active.
180 */
181 IBeacon.isBluetoothEnabled = function () { return; };
182 /**
183 * Enables Bluetooth using the native Layer. (ANDROID ONLY)
184 *
185 * @returns {Promise<void>} Returns a promise which is resolved when Bluetooth
186 * could be enabled. If not, the promise will be rejected with an error.
187 */
188 IBeacon.enableBluetooth = function () { return; };
189 /**
190 * Disables Bluetooth using the native Layer. (ANDROID ONLY)
191 *
192 * @returns {Promise<void>} Returns a promise which is resolved when Bluetooth
193 * could be enabled. If not, the promise will be rejected with an error.
194 */
195 IBeacon.disableBluetooth = function () { return; };
196 /**
197 * Start monitoring the specified region.
198 *
199 * If a region of the same type with the same identifier is already being
200 * monitored for this application,
201 * it will be removed from monitoring. For circular regions, the region
202 * monitoring service will prioritize
203 * regions by their size, favoring smaller regions over larger regions.
204 *
205 * This is done asynchronously and may not be immediately reflected in monitoredRegions.
206 *
207 * @param {Region} region An instance of {Region} which will be monitored
208 * by the operating system.
209 *
210 * @returns {Promise<string>} Returns a promise which is resolved as soon as the
211 * native layer acknowledged the dispatch of the monitoring request.
212 */
213 IBeacon.startMonitoringForRegion = function (region) { return; };
214 /**
215 * Stop monitoring the specified region. It is valid to call
216 * stopMonitoringForRegion: for a region that was registered for monitoring
217 * with a different location manager object, during this or previous
218 * launches of your application.
219 *
220 * This is done asynchronously and may not be immediately reflected in monitoredRegions.
221 *
222 * @param {Region} region An instance of {Region} which will be monitored
223 * by the operating system.
224 *
225 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
226 * native layer acknowledged the dispatch of the request to stop monitoring.
227 */
228 IBeacon.stopMonitoringForRegion = function (region) { return; };
229 /**
230 * Request state the for specified region. When result is ready
231 * didDetermineStateForRegion is triggered. This can be any region,
232 * also those which is not currently monitored.
233 *
234 * This is done asynchronously and may not be immediately reflected in monitoredRegions.
235 *
236 * @param {Region} region An instance of {Region} which will be monitored
237 * by the operating system.
238 *
239 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
240 * native layer acknowledged the dispatch of the request to stop monitoring.
241 */
242 IBeacon.requestStateForRegion = function (region) { return; };
243 /**
244 * Start ranging the specified beacon region.
245 *
246 * If a region of the same type with the same identifier is already being
247 * monitored for this application, it will be removed from monitoring.
248 *
249 * This is done asynchronously and may not be immediately reflected in rangedRegions.
250 *
251 * @param {Region} region An instance of {BeaconRegion} which will be monitored
252 * by the operating system.
253 *
254 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
255 * native layer acknowledged the dispatch of the monitoring request.
256 */
257 IBeacon.startRangingBeaconsInRegion = function (region) { return; };
258 /**
259 * Stop ranging the specified region. It is valid to call
260 * stopMonitoringForRegion: for a region that was registered for ranging
261 * with a different location manager object, during this or previous
262 * launches of your application.
263 *
264 * This is done asynchronously and may not be immediately reflected in rangedRegions.
265 *
266 * @param {Region} region An instance of {BeaconRegion} which will be monitored
267 * by the operating system.
268 *
269 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
270 * native layer acknowledged the dispatch of the request to stop monitoring.
271 */
272 IBeacon.stopRangingBeaconsInRegion = function (region) { return; };
273 /**
274 * Queries the native layer to determine the current authorization in effect.
275 *
276 * @returns {Promise<IBeaconPluginResult>} Returns a promise which is resolved with the
277 * requested authorization status.
278 */
279 IBeacon.getAuthorizationStatus = function () { return; };
280 /**
281 * For iOS 8 and above only. The permission model has changed by Apple in iOS 8, making it necessary for apps to
282 * explicitly request permissions via methods like these:
283 * <a href="https://developer.apple.com/library/prerelease/iOS/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestWhenInUseAuthorization">requestWhenInUseAuthorization</a>
284 * <a href="https://developer.apple.com/library/prerelease/iOS/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestAlwaysAuthorization">requestAlwaysAuthorization</a>
285 *
286 * If you are using this plugin on Android devices only, you will never have to use this, nor {@code requestAlwaysAuthorization}
287 * @returns {Promise<void>} Returns a promise that is resolved when the request dialog is shown.
288 */
289 IBeacon.requestWhenInUseAuthorization = function () { return; };
290 /**
291 * See the documentation of {@code requestWhenInUseAuthorization} for further details.
292 *
293 * @returns {Promise<void>} Returns a promise which is resolved when the native layer
294 * shows the request dialog.
295 */
296 IBeacon.requestAlwaysAuthorization = function () { return; };
297 /**
298 *
299 * @returns {Promise<Region[]>} Returns a promise which is resolved with an {Array}
300 * of {Region} instances that are being monitored by the native layer.
301 */
302 IBeacon.getMonitoredRegions = function () { return; };
303 /**
304 *
305 * @returns {Promise<Region[]>} Returns a promise which is resolved with an {Array}
306 * of {Region} instances that are being ranged by the native layer.
307 */
308 IBeacon.getRangedRegions = function () { return; };
309 /**
310 * Determines if ranging is available or not, according to the native layer.
311 * @returns {Promise<boolean>} Returns a promise which is resolved with a {Boolean}
312 * indicating whether ranging is available or not.
313 */
314 IBeacon.isRangingAvailable = function () { return; };
315 /**
316 * Determines if region type is supported or not, according to the native layer.
317 *
318 * @param {Region} region An instance of {Region} which will be checked
319 * by the operating system.
320 *
321 * @returns {Promise<boolean>} Returns a promise which is resolved with a {Boolean}
322 * indicating whether the region type is supported or not.
323 */
324 IBeacon.isMonitoringAvailableForClass = function (region) { return; };
325 /**
326 * Start advertising the specified region.
327 *
328 * If a region a different identifier is already being advertised for
329 * this application, it will be replaced with the new identifier.
330 *
331 * This call will accept a valid beacon even when no BlueTooth is available,
332 * and will start when BlueTooth is powered on. See {IBeaconDelegate.}
333 *
334 * @param {Region} region An instance of {Region} which will be advertised
335 * by the operating system.
336 * @param {Integer} measuredPower: Optional parameter, if left empty, the device will
337 * use it's own default value.
338 *
339 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
340 * native layer acknowledged the dispatch of the advertising request.
341 */
342 IBeacon.startAdvertising = function (region, measuredPower) { return; };
343 /**
344 * Stop advertising as a beacon.
345 *
346 * This is done asynchronously and may not be immediately reflected in isAdvertising.
347 *
348 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
349 * native layer acknowledged the dispatch of the request to stop advertising.
350 */
351 IBeacon.stopAdvertising = function (region) { return; };
352 /**
353 * Determines if advertising is available or not, according to the native layer.
354 * @returns {Promise<void>} Returns a promise which is resolved with a {Boolean}
355 * indicating whether advertising is available or not.
356 */
357 IBeacon.isAdvertisingAvailable = function () { return; };
358 /**
359 * Determines if advertising is currently active, according to the native layer.
360 * @returns {Promise<void>} Returns a promise which is resolved with a {Boolean}
361 * indicating whether advertising is active.
362 */
363 IBeacon.isAdvertising = function () { return; };
364 /**
365 * Disables debug logging in the native layer. Use this method if you want
366 * to prevent this plugin from writing to the device logs.
367 *
368 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
369 * native layer has set the logging level accordingly.
370 */
371 IBeacon.disableDebugLogs = function () { return; };
372 /**
373 * Enables the posting of debug notifications in the native layer. Use this method if you want
374 * to allow the plugin the posting local notifications.
375 * This can be very helpful when debugging how to apps behave when launched into the background.
376 *
377 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
378 * native layer has set the flag to enabled.
379 */
380 IBeacon.enableDebugNotifications = function () { return; };
381 /**
382 * Disables the posting of debug notifications in the native layer. Use this method if you want
383 * to prevent the plugin from posting local notifications.
384 *
385 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
386 * native layer has set the flag to disabled.
387 */
388 IBeacon.disableDebugNotifications = function () { return; };
389 /**
390 * Enables debug logging in the native layer. Use this method if you want
391 * a debug the inner workings of this plugin.
392 *
393 * @returns {Promise<void>} Returns a promise which is resolved as soon as the
394 * native layer has set the logging level accordingly.
395 */
396 IBeacon.enableDebugLogs = function () { return; };
397 /**
398 * Appends the provided [message] to the device logs.
399 * Note: If debug logging is turned off, this won't do anything.
400 *
401 * @param {String} message The message to append to the device logs.
402 *
403 * @returns {Promise<void>} Returns a promise which is resolved with the log
404 * message received by the native layer for appending. The returned message
405 * is expected to be equivalent to the one provided in the original call.
406 */
407 IBeacon.appendToDeviceLog = function (message) { return; };
408 __decorate([
409 plugin_1.Cordova()
410 ], IBeacon, "getDelegate", null);
411 __decorate([
412 plugin_1.Cordova()
413 ], IBeacon, "setDelegate", null);
414 __decorate([
415 plugin_1.Cordova({ otherPromise: true })
416 ], IBeacon, "onDomDelegateReady", null);
417 __decorate([
418 plugin_1.Cordova({ otherPromise: true })
419 ], IBeacon, "isBluetoothEnabled", null);
420 __decorate([
421 plugin_1.Cordova({ otherPromise: true })
422 ], IBeacon, "enableBluetooth", null);
423 __decorate([
424 plugin_1.Cordova({ otherPromise: true })
425 ], IBeacon, "disableBluetooth", null);
426 __decorate([
427 plugin_1.Cordova({ otherPromise: true })
428 ], IBeacon, "startMonitoringForRegion", null);
429 __decorate([
430 plugin_1.Cordova({ otherPromise: true })
431 ], IBeacon, "stopMonitoringForRegion", null);
432 __decorate([
433 plugin_1.Cordova({ otherPromise: true })
434 ], IBeacon, "requestStateForRegion", null);
435 __decorate([
436 plugin_1.Cordova({ otherPromise: true })
437 ], IBeacon, "startRangingBeaconsInRegion", null);
438 __decorate([
439 plugin_1.Cordova({ otherPromise: true })
440 ], IBeacon, "stopRangingBeaconsInRegion", null);
441 __decorate([
442 plugin_1.Cordova({ otherPromise: true })
443 ], IBeacon, "getAuthorizationStatus", null);
444 __decorate([
445 plugin_1.Cordova({ otherPromise: true })
446 ], IBeacon, "requestWhenInUseAuthorization", null);
447 __decorate([
448 plugin_1.Cordova({ otherPromise: true })
449 ], IBeacon, "requestAlwaysAuthorization", null);
450 __decorate([
451 plugin_1.Cordova({ otherPromise: true })
452 ], IBeacon, "getMonitoredRegions", null);
453 __decorate([
454 plugin_1.Cordova({ otherPromise: true })
455 ], IBeacon, "getRangedRegions", null);
456 __decorate([
457 plugin_1.Cordova({ otherPromise: true })
458 ], IBeacon, "isRangingAvailable", null);
459 __decorate([
460 plugin_1.Cordova({ otherPromise: true })
461 ], IBeacon, "isMonitoringAvailableForClass", null);
462 __decorate([
463 plugin_1.Cordova({ otherPromise: true })
464 ], IBeacon, "startAdvertising", null);
465 __decorate([
466 plugin_1.Cordova({ otherPromise: true })
467 ], IBeacon, "stopAdvertising", null);
468 __decorate([
469 plugin_1.Cordova({ otherPromise: true })
470 ], IBeacon, "isAdvertisingAvailable", null);
471 __decorate([
472 plugin_1.Cordova({ otherPromise: true })
473 ], IBeacon, "isAdvertising", null);
474 __decorate([
475 plugin_1.Cordova({ otherPromise: true })
476 ], IBeacon, "disableDebugLogs", null);
477 __decorate([
478 plugin_1.Cordova({ otherPromise: true })
479 ], IBeacon, "enableDebugNotifications", null);
480 __decorate([
481 plugin_1.Cordova({ otherPromise: true })
482 ], IBeacon, "disableDebugNotifications", null);
483 __decorate([
484 plugin_1.Cordova({ otherPromise: true })
485 ], IBeacon, "enableDebugLogs", null);
486 __decorate([
487 plugin_1.Cordova({ otherPromise: true })
488 ], IBeacon, "appendToDeviceLog", null);
489 IBeacon = __decorate([
490 plugin_1.Plugin({
491 pluginName: 'IBeacon',
492 plugin: 'cordova-plugin-ibeacon',
493 pluginRef: 'cordova.plugins.locationManager',
494 repo: 'https://github.com/petermetz/cordova-plugin-ibeacon',
495 platforms: ['Android', 'iOS']
496 })
497 ], IBeacon);
498 return IBeacon;
499}());
500exports.IBeacon = IBeacon;
501//# sourceMappingURL=ibeacon.js.map
\No newline at end of file