leap-capacitor 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LeapCapacitor.podspec +19 -0
- package/README.md +234 -0
- package/android/build.gradle +59 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/is/leap/capacitor/LeapPlugin.java +239 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +1069 -0
- package/dist/esm/definitions.d.ts +38 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/plugin.cjs.js +10 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +13 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/LeapPlugin.h +10 -0
- package/ios/Plugin/LeapPlugin.m +15 -0
- package/ios/Plugin/LeapPlugin.swift +126 -0
- package/package.json +78 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'LeapCapacitor'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '12.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
|
|
18
|
+
s.dependency "LeapSDK"
|
|
19
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# leap-capacitor
|
|
2
|
+
|
|
3
|
+
Plugin for Leap
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install leap-capacitor
|
|
9
|
+
npx cap sync
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## API
|
|
13
|
+
|
|
14
|
+
<docgen-index>
|
|
15
|
+
|
|
16
|
+
* [`start(...)`](#start)
|
|
17
|
+
* [`startWithProperties(...)`](#startwithproperties)
|
|
18
|
+
* [`flushProperties(...)`](#flushproperties)
|
|
19
|
+
* [`setUniqueUserId(...)`](#setuniqueuserid)
|
|
20
|
+
* [`startProject(...)`](#startproject)
|
|
21
|
+
* [`embedProject(...)`](#embedproject)
|
|
22
|
+
* [`offlineSync(...)`](#offlinesync)
|
|
23
|
+
* [`disable()`](#disable)
|
|
24
|
+
* [`addListener('leapCallbacks', ...)`](#addlistenerleapcallbacks)
|
|
25
|
+
* [`addListener('leapElementActionCallbacks', ...)`](#addlistenerleapelementactioncallbacks)
|
|
26
|
+
* [Interfaces](#interfaces)
|
|
27
|
+
|
|
28
|
+
</docgen-index>
|
|
29
|
+
|
|
30
|
+
<docgen-api>
|
|
31
|
+
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
32
|
+
|
|
33
|
+
### start(...)
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
start(options: { apiKey: string; }) => Promise<void>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
| Param | Type |
|
|
40
|
+
| ------------- | -------------------------------- |
|
|
41
|
+
| **`options`** | <code>{ apiKey: string; }</code> |
|
|
42
|
+
|
|
43
|
+
--------------------
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### startWithProperties(...)
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
startWithProperties(options: { apiKey: string; properties: UserProperty; }) => Promise<void>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Param | Type |
|
|
53
|
+
| ------------- | -------------------------------------------------------------------------------------- |
|
|
54
|
+
| **`options`** | <code>{ apiKey: string; properties: <a href="#userproperty">UserProperty</a>; }</code> |
|
|
55
|
+
|
|
56
|
+
--------------------
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### flushProperties(...)
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
flushProperties(options: { properties: UserProperty; }) => Promise<void>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Param | Type |
|
|
66
|
+
| ------------- | ---------------------------------------------------------------------- |
|
|
67
|
+
| **`options`** | <code>{ properties: <a href="#userproperty">UserProperty</a>; }</code> |
|
|
68
|
+
|
|
69
|
+
--------------------
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
### setUniqueUserId(...)
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
setUniqueUserId(options: { uniqueUserId: string; }) => Promise<void>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
| Param | Type |
|
|
79
|
+
| ------------- | -------------------------------------- |
|
|
80
|
+
| **`options`** | <code>{ uniqueUserId: string; }</code> |
|
|
81
|
+
|
|
82
|
+
--------------------
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
### startProject(...)
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
startProject(options: { projectId: string; resetProject?: boolean; }) => Promise<void>
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
| Param | Type |
|
|
92
|
+
| ------------- | ----------------------------------------------------------- |
|
|
93
|
+
| **`options`** | <code>{ projectId: string; resetProject?: boolean; }</code> |
|
|
94
|
+
|
|
95
|
+
--------------------
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
### embedProject(...)
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
embedProject(options: { projectId: string; }) => Promise<void>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
| Param | Type |
|
|
105
|
+
| ------------- | ----------------------------------- |
|
|
106
|
+
| **`options`** | <code>{ projectId: string; }</code> |
|
|
107
|
+
|
|
108
|
+
--------------------
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
### offlineSync(...)
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
offlineSync(options: { projectIds: Array<string>; }) => Promise<void>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
| Param | Type |
|
|
118
|
+
| ------------- | -------------------------------------- |
|
|
119
|
+
| **`options`** | <code>{ projectIds: string[]; }</code> |
|
|
120
|
+
|
|
121
|
+
--------------------
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### disable()
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
disable() => Promise<void>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
--------------------
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
### addListener('leapCallbacks', ...)
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
addListener(eventName: 'leapCallbacks', listenerFunc: (event: LeapCallbacks) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
| Param | Type |
|
|
140
|
+
| ------------------ | --------------------------------------------------------------------------- |
|
|
141
|
+
| **`eventName`** | <code>'leapCallbacks'</code> |
|
|
142
|
+
| **`listenerFunc`** | <code>(event: <a href="#leapcallbacks">LeapCallbacks</a>) => void</code> |
|
|
143
|
+
|
|
144
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
|
145
|
+
|
|
146
|
+
--------------------
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
### addListener('leapElementActionCallbacks', ...)
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
addListener(eventName: 'leapElementActionCallbacks', listenerFunc: (event: LeapElementActionCallbacks) => void) => Promise<PluginListenerHandle> & PluginListenerHandle
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
| Param | Type |
|
|
156
|
+
| ------------------ | ----------------------------------------------------------------------------------------------------- |
|
|
157
|
+
| **`eventName`** | <code>'leapElementActionCallbacks'</code> |
|
|
158
|
+
| **`listenerFunc`** | <code>(event: <a href="#leapelementactioncallbacks">LeapElementActionCallbacks</a>) => void</code> |
|
|
159
|
+
|
|
160
|
+
**Returns:** <code>Promise<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
|
161
|
+
|
|
162
|
+
--------------------
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### Interfaces
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
#### UserProperty
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
#### Array
|
|
172
|
+
|
|
173
|
+
| Prop | Type | Description |
|
|
174
|
+
| ------------ | ------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
175
|
+
| **`length`** | <code>number</code> | Gets or sets the length of the array. This is a number one higher than the highest index in the array. |
|
|
176
|
+
|
|
177
|
+
| Method | Signature | Description |
|
|
178
|
+
| ------------------ | ----------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
179
|
+
| **toString** | () => string | Returns a string representation of an array. |
|
|
180
|
+
| **toLocaleString** | () => string | Returns a string representation of an array. The elements are converted to string using their toLocalString methods. |
|
|
181
|
+
| **pop** | () => T \| undefined | Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
|
|
182
|
+
| **push** | (...items: T[]) => number | Appends new elements to the end of an array, and returns the new length of the array. |
|
|
183
|
+
| **concat** | (...items: <a href="#concatarray">ConcatArray</a><T>[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. |
|
|
184
|
+
| **concat** | (...items: (T \| <a href="#concatarray">ConcatArray</a><T>)[]) => T[] | Combines two or more arrays. This method returns a new array without modifying any existing arrays. |
|
|
185
|
+
| **join** | (separator?: string \| undefined) => string | Adds all the elements of an array into a string, separated by the specified separator string. |
|
|
186
|
+
| **reverse** | () => T[] | Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. |
|
|
187
|
+
| **shift** | () => T \| undefined | Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
|
|
188
|
+
| **slice** | (start?: number \| undefined, end?: number \| undefined) => T[] | Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. |
|
|
189
|
+
| **sort** | (compareFn?: ((a: T, b: T) => number) \| undefined) => this | Sorts an array in place. This method mutates the array and returns a reference to the same array. |
|
|
190
|
+
| **splice** | (start: number, deleteCount?: number \| undefined) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. |
|
|
191
|
+
| **splice** | (start: number, deleteCount: number, ...items: T[]) => T[] | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. |
|
|
192
|
+
| **unshift** | (...items: T[]) => number | Inserts new elements at the start of an array, and returns the new length of the array. |
|
|
193
|
+
| **indexOf** | (searchElement: T, fromIndex?: number \| undefined) => number | Returns the index of the first occurrence of a value in an array, or -1 if it is not present. |
|
|
194
|
+
| **lastIndexOf** | (searchElement: T, fromIndex?: number \| undefined) => number | Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. |
|
|
195
|
+
| **every** | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => this is S[] | Determines whether all the members of an array satisfy the specified test. |
|
|
196
|
+
| **every** | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether all the members of an array satisfy the specified test. |
|
|
197
|
+
| **some** | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => boolean | Determines whether the specified callback function returns true for any element of an array. |
|
|
198
|
+
| **forEach** | (callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any) => void | Performs the specified action for each element in an array. |
|
|
199
|
+
| **map** | <U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any) => U[] | Calls a defined callback function on each element of an array, and returns an array that contains the results. |
|
|
200
|
+
| **filter** | <S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any) => S[] | Returns the elements of an array that meet the condition specified in a callback function. |
|
|
201
|
+
| **filter** | (predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any) => T[] | Returns the elements of an array that meet the condition specified in a callback function. |
|
|
202
|
+
| **reduce** | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
|
|
203
|
+
| **reduce** | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | |
|
|
204
|
+
| **reduce** | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
|
|
205
|
+
| **reduceRight** | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T) => T | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
|
|
206
|
+
| **reduceRight** | (callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue: T) => T | |
|
|
207
|
+
| **reduceRight** | <U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U) => U | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. |
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
#### ConcatArray
|
|
211
|
+
|
|
212
|
+
| Prop | Type |
|
|
213
|
+
| ------------ | ------------------- |
|
|
214
|
+
| **`length`** | <code>number</code> |
|
|
215
|
+
|
|
216
|
+
| Method | Signature |
|
|
217
|
+
| --------- | ------------------------------------------------------------------ |
|
|
218
|
+
| **join** | (separator?: string \| undefined) => string |
|
|
219
|
+
| **slice** | (start?: number \| undefined, end?: number \| undefined) => T[] |
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
#### PluginListenerHandle
|
|
223
|
+
|
|
224
|
+
| Prop | Type |
|
|
225
|
+
| ------------ | ----------------------------------------- |
|
|
226
|
+
| **`remove`** | <code>() => Promise<void></code> |
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
#### LeapCallbacks
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
#### LeapElementActionCallbacks
|
|
233
|
+
|
|
234
|
+
</docgen-api>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.1'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2.0'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.2'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.3.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
jcenter()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:4.2.1'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 30
|
|
22
|
+
defaultConfig {
|
|
23
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 21
|
|
24
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 30
|
|
25
|
+
versionCode 1
|
|
26
|
+
versionName "1.0"
|
|
27
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
28
|
+
}
|
|
29
|
+
buildTypes {
|
|
30
|
+
release {
|
|
31
|
+
minifyEnabled false
|
|
32
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
lintOptions {
|
|
36
|
+
abortOnError false
|
|
37
|
+
}
|
|
38
|
+
compileOptions {
|
|
39
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
40
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
repositories {
|
|
45
|
+
google()
|
|
46
|
+
mavenCentral()
|
|
47
|
+
jcenter()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation 'is.leap.android:sdk:1.5.2'
|
|
55
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
56
|
+
testImplementation "junit:junit:$junitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
58
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
59
|
+
}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
package is.leap.capacitor;
|
|
2
|
+
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
|
|
5
|
+
import com.getcapacitor.JSArray;
|
|
6
|
+
import com.getcapacitor.JSObject;
|
|
7
|
+
import com.getcapacitor.Plugin;
|
|
8
|
+
import com.getcapacitor.PluginCall;
|
|
9
|
+
import com.getcapacitor.PluginMethod;
|
|
10
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
11
|
+
import com.getcapacitor.annotation.Permission;
|
|
12
|
+
|
|
13
|
+
import org.json.JSONException;
|
|
14
|
+
import org.json.JSONObject;
|
|
15
|
+
|
|
16
|
+
import java.text.ParseException;
|
|
17
|
+
import java.text.SimpleDateFormat;
|
|
18
|
+
import java.util.ArrayList;
|
|
19
|
+
import java.util.Date;
|
|
20
|
+
import java.util.Iterator;
|
|
21
|
+
import java.util.List;
|
|
22
|
+
import java.util.Locale;
|
|
23
|
+
import java.util.Map;
|
|
24
|
+
import java.util.TimeZone;
|
|
25
|
+
|
|
26
|
+
import is.leap.android.LeapEventCallbacks;
|
|
27
|
+
import is.leap.android.aui.Leap;
|
|
28
|
+
import is.leap.android.core.LeapElementActionCallbacks;
|
|
29
|
+
|
|
30
|
+
@CapacitorPlugin(
|
|
31
|
+
name = LeapPlugin.PLUGIN_NAME,
|
|
32
|
+
permissions = {
|
|
33
|
+
@Permission(
|
|
34
|
+
alias = LeapPlugin.INTERNET_PERMISSION_ALIAS,
|
|
35
|
+
strings = {Manifest.permission.INTERNET}
|
|
36
|
+
),
|
|
37
|
+
@Permission(
|
|
38
|
+
alias = LeapPlugin.NETWORK_STATE_PERMISSION_ALIAS,
|
|
39
|
+
strings = {Manifest.permission.ACCESS_NETWORK_STATE}
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
)
|
|
43
|
+
public class LeapPlugin extends Plugin {
|
|
44
|
+
|
|
45
|
+
public static final String API_KEY = "apiKey";
|
|
46
|
+
public static final String PROPERTIES = "properties";
|
|
47
|
+
public static final String DATE_TYPE_PREFIX = "Date:";
|
|
48
|
+
public static final String PROJECT_IDS = "projectIds";
|
|
49
|
+
public static final String UNIQUE_USER_ID = "uniqueUserId";
|
|
50
|
+
public static final String PROJECT_ID = "projectId";
|
|
51
|
+
public static final String RESET_PROJECT = "resetProject";
|
|
52
|
+
public static final String LEAP_CALLBACKS = "leapCallbacks";
|
|
53
|
+
public static final String LEAP_ELEMENT_ACTION_CALLBACKS = "leapElementActionCallbacks";
|
|
54
|
+
public static final String PLUGIN_NAME = "LeapPlugin";
|
|
55
|
+
public static final String INTERNET_PERMISSION_ALIAS = "Internet";
|
|
56
|
+
public static final String NETWORK_STATE_PERMISSION_ALIAS = "Network State";
|
|
57
|
+
|
|
58
|
+
private static final String FORMAT_SDF = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
|
59
|
+
private static final String TIMEZONE_GMT = "GMT";
|
|
60
|
+
|
|
61
|
+
public LeapPlugin() {
|
|
62
|
+
setLeapEventEmitter();
|
|
63
|
+
setLeapAUIActionEventEmitter();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@PluginMethod
|
|
67
|
+
public void start(PluginCall call) {
|
|
68
|
+
String apiKey = call.getString(API_KEY);
|
|
69
|
+
Leap.start(apiKey);
|
|
70
|
+
call.resolve();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@PluginMethod
|
|
74
|
+
public void startWithProperties(PluginCall call) {
|
|
75
|
+
String apiKey = call.getString(API_KEY);
|
|
76
|
+
JSObject propsObj = call.getObject(PROPERTIES);
|
|
77
|
+
if(propsObj == null) {
|
|
78
|
+
Leap.start(apiKey);
|
|
79
|
+
call.resolve();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
Leap.Builder leapBuilder = Leap.withBuilder(apiKey);
|
|
83
|
+
Iterator<String> iterator = propsObj.keys();
|
|
84
|
+
|
|
85
|
+
while (iterator.hasNext()) {
|
|
86
|
+
String key = iterator.next();
|
|
87
|
+
Object propValue = null;
|
|
88
|
+
try {
|
|
89
|
+
propValue = propsObj.get(key);
|
|
90
|
+
} catch (JSONException e) {
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
if(propValue instanceof String) {
|
|
94
|
+
String valueStr = (String) propValue;
|
|
95
|
+
if (valueStr.startsWith(DATE_TYPE_PREFIX)) {
|
|
96
|
+
String dateValue = valueStr.split(DATE_TYPE_PREFIX)[1];
|
|
97
|
+
Date date = getDate(dateValue);
|
|
98
|
+
leapBuilder.addProperty(key, date);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
leapBuilder.addProperty(key, String.valueOf(propValue));
|
|
102
|
+
} else if (propValue instanceof Number) {
|
|
103
|
+
leapBuilder.addProperty(key, (long) propValue);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
leapBuilder.start();
|
|
108
|
+
call.resolve();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@PluginMethod
|
|
112
|
+
public void flushProperties(PluginCall call) {
|
|
113
|
+
JSObject propsObj = call.getObject(PROPERTIES);
|
|
114
|
+
Leap.PropertyBuilder leapPropertyBuilder = Leap.withPropertyBuilder();
|
|
115
|
+
Iterator<String> iterator = propsObj.keys();
|
|
116
|
+
|
|
117
|
+
while (iterator.hasNext()) {
|
|
118
|
+
String key = iterator.next();
|
|
119
|
+
Object propValue = null;
|
|
120
|
+
try {
|
|
121
|
+
propValue = propsObj.get(key);
|
|
122
|
+
} catch (JSONException e) {
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
if(propValue instanceof String) {
|
|
126
|
+
String valueStr = (String) propValue;
|
|
127
|
+
if (valueStr.startsWith(DATE_TYPE_PREFIX)) {
|
|
128
|
+
String dateValue = valueStr.split(DATE_TYPE_PREFIX)[1];
|
|
129
|
+
Date date = getDate(dateValue);
|
|
130
|
+
leapPropertyBuilder.addProperty(key, date);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
leapPropertyBuilder.addProperty(key, String.valueOf(propValue));
|
|
134
|
+
} else if (propValue instanceof Number) {
|
|
135
|
+
leapPropertyBuilder.addProperty(key, (long) propValue);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
leapPropertyBuilder.flush();
|
|
140
|
+
call.resolve();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@PluginMethod
|
|
144
|
+
public static void setUniqueUserId(PluginCall call) {
|
|
145
|
+
String uniqueUserId = call.getString(UNIQUE_USER_ID);
|
|
146
|
+
Leap.setUniqueUserId(uniqueUserId);
|
|
147
|
+
call.resolve();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@PluginMethod
|
|
151
|
+
public static void startProject(PluginCall call) {
|
|
152
|
+
String projectID = call.getString(PROJECT_ID);
|
|
153
|
+
boolean resetProject = false;
|
|
154
|
+
if(call.hasOption(RESET_PROJECT)) {
|
|
155
|
+
resetProject = call.getBoolean(RESET_PROJECT, false);
|
|
156
|
+
}
|
|
157
|
+
Leap.startProject(projectID, resetProject);
|
|
158
|
+
call.resolve();
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@PluginMethod
|
|
162
|
+
public static void embedProject(PluginCall call) {
|
|
163
|
+
String projectID = call.getString(PROJECT_ID);
|
|
164
|
+
Leap.embedProject(projectID);
|
|
165
|
+
call.resolve();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@PluginMethod
|
|
169
|
+
public void offlineSync(PluginCall call) {
|
|
170
|
+
JSArray array = call.getArray(PROJECT_IDS);
|
|
171
|
+
List<String> offlineProjList = new ArrayList<>();
|
|
172
|
+
if (array == null || array.length() == 0) {
|
|
173
|
+
//In this case we will delete the previous projects
|
|
174
|
+
Leap.offlineSync(offlineProjList);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
for (int i = 0; i < array.length(); i++) {
|
|
178
|
+
if (array.isNull(i)) continue;
|
|
179
|
+
String offlineProjId = null;
|
|
180
|
+
try {
|
|
181
|
+
offlineProjId = array.getString(i);
|
|
182
|
+
} catch (JSONException e) {
|
|
183
|
+
}
|
|
184
|
+
if(offlineProjId != null)
|
|
185
|
+
offlineProjList.add(offlineProjId);
|
|
186
|
+
}
|
|
187
|
+
Leap.offlineSync(offlineProjList);
|
|
188
|
+
call.resolve();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@PluginMethod
|
|
192
|
+
public void disable() {
|
|
193
|
+
Leap.disable();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
public static Date getDate(String dateValue) {
|
|
197
|
+
SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_SDF, Locale.ENGLISH);
|
|
198
|
+
sdf.setTimeZone(TimeZone.getTimeZone(TIMEZONE_GMT));
|
|
199
|
+
try {
|
|
200
|
+
return sdf.parse(dateValue);
|
|
201
|
+
} catch (ParseException ignored) {
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private void setLeapEventEmitter() {
|
|
207
|
+
LeapEventCallbacks leapEventListener = new LeapEventCallbacks() {
|
|
208
|
+
@Override
|
|
209
|
+
public void onEvent(Map<String, String> eventValue) {
|
|
210
|
+
if (eventValue == null)
|
|
211
|
+
return;
|
|
212
|
+
JSONObject ret = new JSONObject(eventValue);
|
|
213
|
+
JSObject jsObject = null;
|
|
214
|
+
try {
|
|
215
|
+
jsObject = new JSObject(ret.toString());
|
|
216
|
+
} catch (JSONException e) {
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
if(jsObject == null) return;
|
|
220
|
+
notifyListeners(LEAP_CALLBACKS, jsObject);
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
Leap.setLeapEventCallbacks(leapEventListener);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private void setLeapAUIActionEventEmitter() {
|
|
228
|
+
LeapElementActionCallbacks eventActionListener = new LeapElementActionCallbacks() {
|
|
229
|
+
@Override
|
|
230
|
+
public void onEventAction(String actionName, Object value) {
|
|
231
|
+
JSObject jsObject = new JSObject();
|
|
232
|
+
jsObject.put(actionName, value);
|
|
233
|
+
notifyListeners(LEAP_ELEMENT_ACTION_CALLBACKS, jsObject);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
Leap.addLeapElementActionCallbacks(eventActionListener);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
}
|
|
File without changes
|