-
Notifications
You must be signed in to change notification settings - Fork 9
/
nativescript-ibeacon.common.ts
104 lines (77 loc) · 2.58 KB
/
nativescript-ibeacon.common.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {Observable} from 'data/observable';
import * as app from 'application';
import * as dialogs from 'ui/dialogs';
export interface BeaconCallback {
onBeaconManagerReady(): void;
didRangeBeaconsInRegion(region: BeaconRegion, beacons: Beacon[]): void;
didFailRangingBeaconsInRegion(region: BeaconRegion, errorCode: number, errorDescription: string): void;
didEnterRegion?(region: BeaconRegion): void;
didExitRegion?(region: BeaconRegion): void;
}
export enum BeaconLocationOptionsIOSAuthType {
Always, WhenInUse
}
export enum BeaconLocationOptionsAndroidAuthType {
Coarse, Fine
}
export interface BeaconLocationOptions {
iOSAuthorisationType: BeaconLocationOptionsIOSAuthType;
androidAuthorisationType: BeaconLocationOptionsAndroidAuthType;
androidAuthorisationDescription: string;
}
export class Common extends Observable {
protected options: BeaconLocationOptions = {
iOSAuthorisationType: BeaconLocationOptionsIOSAuthType.WhenInUse,
androidAuthorisationType: BeaconLocationOptionsAndroidAuthType.Coarse,
androidAuthorisationDescription: "Location permission needed"
};
constructor(beaconCallback: BeaconCallback, options?: BeaconLocationOptions) {
super();
if (options) {
this.options = options;
}
}
public requestAuthorization(): Promise<any> {
return null;
}
public isAuthorised() : boolean {
return false;
}
public bind() {
}
public unbind() {
}
public startRanging(beaconRegion: BeaconRegion) {
}
public stopRanging(beaconRegion: BeaconRegion) {
}
public startMonitoring(beaconRegion: BeaconRegion) {
}
public stopMonitoring(beaconRegion: BeaconRegion) {
}
}
export class BeaconRegion {
public identifier: string;
public proximityUUID: string;
public major?: number;
public minor?: number;
constructor(identifier: string, proximityUUID: string, major?: number, minor?: number) {
this.identifier = identifier;
this.proximityUUID = proximityUUID;
if (major) this.major = major;
if (minor) this.minor = minor;
}
}
export class Beacon {
public proximityUUID: string;
public major: number;
public minor: number;
public distance_proximity: number; // proximity in iOS
public rssi: number;
public txPower_accuracy: number; // accuracy in iOS
constructor(proximityUUID: string, major: number, minor: number) {
this.proximityUUID = proximityUUID;
this.major = major;
this.minor = minor;
}
}