leap-capacitor 1.0.0 → 1.2.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/README.md +42 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/is/leap/capacitor/LeapPlugin.java +59 -15
- package/dist/docs.json +50 -0
- package/dist/esm/definitions.d.ts +10 -0
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Plugin/LeapPlugin.m +3 -0
- package/ios/Plugin/LeapPlugin.swift +80 -42
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,12 +15,15 @@ npx cap sync
|
|
|
15
15
|
|
|
16
16
|
* [`start(...)`](#start)
|
|
17
17
|
* [`startWithProperties(...)`](#startwithproperties)
|
|
18
|
+
* [`startWithSelfHostedURL(...)`](#startwithselfhostedurl)
|
|
19
|
+
* [`startWithSelfHostedURLAndProperties(...)`](#startwithselfhostedurlandproperties)
|
|
18
20
|
* [`flushProperties(...)`](#flushproperties)
|
|
19
21
|
* [`setUniqueUserId(...)`](#setuniqueuserid)
|
|
20
22
|
* [`startProject(...)`](#startproject)
|
|
21
23
|
* [`embedProject(...)`](#embedproject)
|
|
22
24
|
* [`offlineSync(...)`](#offlinesync)
|
|
23
25
|
* [`disable()`](#disable)
|
|
26
|
+
* [`setAppLocale(...)`](#setapplocale)
|
|
24
27
|
* [`addListener('leapCallbacks', ...)`](#addlistenerleapcallbacks)
|
|
25
28
|
* [`addListener('leapElementActionCallbacks', ...)`](#addlistenerleapelementactioncallbacks)
|
|
26
29
|
* [Interfaces](#interfaces)
|
|
@@ -56,6 +59,32 @@ startWithProperties(options: { apiKey: string; properties: UserProperty; }) => P
|
|
|
56
59
|
--------------------
|
|
57
60
|
|
|
58
61
|
|
|
62
|
+
### startWithSelfHostedURL(...)
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
startWithSelfHostedURL(options: { baseURL: string; }) => Promise<void>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Param | Type |
|
|
69
|
+
| ------------- | --------------------------------- |
|
|
70
|
+
| **`options`** | <code>{ baseURL: string; }</code> |
|
|
71
|
+
|
|
72
|
+
--------------------
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### startWithSelfHostedURLAndProperties(...)
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
startWithSelfHostedURLAndProperties(options: { baseURL: string; properties: UserProperty; }) => Promise<void>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
| Param | Type |
|
|
82
|
+
| ------------- | --------------------------------------------------------------------------------------- |
|
|
83
|
+
| **`options`** | <code>{ baseURL: string; properties: <a href="#userproperty">UserProperty</a>; }</code> |
|
|
84
|
+
|
|
85
|
+
--------------------
|
|
86
|
+
|
|
87
|
+
|
|
59
88
|
### flushProperties(...)
|
|
60
89
|
|
|
61
90
|
```typescript
|
|
@@ -130,6 +159,19 @@ disable() => Promise<void>
|
|
|
130
159
|
--------------------
|
|
131
160
|
|
|
132
161
|
|
|
162
|
+
### setAppLocale(...)
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
setAppLocale(options: { localeCode: string; }) => Promise<void>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| Param | Type |
|
|
169
|
+
| ------------- | ------------------------------------ |
|
|
170
|
+
| **`options`** | <code>{ localeCode: string; }</code> |
|
|
171
|
+
|
|
172
|
+
--------------------
|
|
173
|
+
|
|
174
|
+
|
|
133
175
|
### addListener('leapCallbacks', ...)
|
|
134
176
|
|
|
135
177
|
```typescript
|
package/android/build.gradle
CHANGED
|
@@ -11,7 +11,7 @@ buildscript {
|
|
|
11
11
|
jcenter()
|
|
12
12
|
}
|
|
13
13
|
dependencies {
|
|
14
|
-
classpath 'com.android.tools.build:gradle:4.2.
|
|
14
|
+
classpath 'com.android.tools.build:gradle:4.2.2'
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -51,7 +51,7 @@ repositories {
|
|
|
51
51
|
dependencies {
|
|
52
52
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
53
|
implementation project(':capacitor-android')
|
|
54
|
-
implementation 'is.leap.android:sdk:1.
|
|
54
|
+
implementation 'is.leap.android:sdk:1.7.0'
|
|
55
55
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
56
56
|
testImplementation "junit:junit:$junitVersion"
|
|
57
57
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
@@ -43,6 +43,7 @@ import is.leap.android.core.LeapElementActionCallbacks;
|
|
|
43
43
|
public class LeapPlugin extends Plugin {
|
|
44
44
|
|
|
45
45
|
public static final String API_KEY = "apiKey";
|
|
46
|
+
public static final String SELF_HOSTING_BASE_URL = "baseURL";
|
|
46
47
|
public static final String PROPERTIES = "properties";
|
|
47
48
|
public static final String DATE_TYPE_PREFIX = "Date:";
|
|
48
49
|
public static final String PROJECT_IDS = "projectIds";
|
|
@@ -57,6 +58,8 @@ public class LeapPlugin extends Plugin {
|
|
|
57
58
|
|
|
58
59
|
private static final String FORMAT_SDF = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
|
|
59
60
|
private static final String TIMEZONE_GMT = "GMT";
|
|
61
|
+
public static final String LOCALE_CODE = "localeCode";
|
|
62
|
+
public static final String WFX_CLIENT_UNIQUE_ID = "wfx_user_id";
|
|
60
63
|
|
|
61
64
|
public LeapPlugin() {
|
|
62
65
|
setLeapEventEmitter();
|
|
@@ -70,6 +73,34 @@ public class LeapPlugin extends Plugin {
|
|
|
70
73
|
call.resolve();
|
|
71
74
|
}
|
|
72
75
|
|
|
76
|
+
@PluginMethod
|
|
77
|
+
public void startWithSelfHostedURL(PluginCall call) {
|
|
78
|
+
String baseURL = call.getString(SELF_HOSTING_BASE_URL);
|
|
79
|
+
Leap.withSelfHostedBuilder()
|
|
80
|
+
.setBaseUrl(baseURL)
|
|
81
|
+
.start();
|
|
82
|
+
call.resolve();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@PluginMethod
|
|
86
|
+
public void startWithSelfHostedURLAndProperties(PluginCall call) {
|
|
87
|
+
String baseURL = call.getString(SELF_HOSTING_BASE_URL);
|
|
88
|
+
JSObject propsObj = call.getObject(PROPERTIES);
|
|
89
|
+
Leap.Builder builder = Leap.withSelfHostedBuilder()
|
|
90
|
+
.setBaseUrl(baseURL);
|
|
91
|
+
|
|
92
|
+
if(propsObj == null) {
|
|
93
|
+
builder.start();
|
|
94
|
+
call.resolve();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
startWithProperties(propsObj, builder);
|
|
99
|
+
call.resolve();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
73
104
|
@PluginMethod
|
|
74
105
|
public void startWithProperties(PluginCall call) {
|
|
75
106
|
String apiKey = call.getString(API_KEY);
|
|
@@ -80,10 +111,20 @@ public class LeapPlugin extends Plugin {
|
|
|
80
111
|
return;
|
|
81
112
|
}
|
|
82
113
|
Leap.Builder leapBuilder = Leap.withBuilder(apiKey);
|
|
114
|
+
startWithProperties(propsObj, leapBuilder);
|
|
115
|
+
call.resolve();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private void startWithProperties(JSObject propsObj, Leap.Builder leapBuilder) {
|
|
83
119
|
Iterator<String> iterator = propsObj.keys();
|
|
84
120
|
|
|
85
121
|
while (iterator.hasNext()) {
|
|
86
122
|
String key = iterator.next();
|
|
123
|
+
if(WFX_CLIENT_UNIQUE_ID.equals(key)) {
|
|
124
|
+
String uniqueId = propsObj.getString(key);
|
|
125
|
+
leapBuilder.addUniqueId(uniqueId);
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
87
128
|
Object propValue = null;
|
|
88
129
|
try {
|
|
89
130
|
propValue = propsObj.get(key);
|
|
@@ -105,7 +146,6 @@ public class LeapPlugin extends Plugin {
|
|
|
105
146
|
|
|
106
147
|
}
|
|
107
148
|
leapBuilder.start();
|
|
108
|
-
call.resolve();
|
|
109
149
|
}
|
|
110
150
|
|
|
111
151
|
@PluginMethod
|
|
@@ -193,6 +233,13 @@ public class LeapPlugin extends Plugin {
|
|
|
193
233
|
Leap.disable();
|
|
194
234
|
}
|
|
195
235
|
|
|
236
|
+
@PluginMethod
|
|
237
|
+
public void setAppLocale(PluginCall call) {
|
|
238
|
+
String localeCode = call.getString(LOCALE_CODE);
|
|
239
|
+
Leap.setAppLocale(localeCode);
|
|
240
|
+
call.resolve();
|
|
241
|
+
}
|
|
242
|
+
|
|
196
243
|
public static Date getDate(String dateValue) {
|
|
197
244
|
SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_SDF, Locale.ENGLISH);
|
|
198
245
|
sdf.setTimeZone(TimeZone.getTimeZone(TIMEZONE_GMT));
|
|
@@ -204,22 +251,19 @@ public class LeapPlugin extends Plugin {
|
|
|
204
251
|
}
|
|
205
252
|
|
|
206
253
|
private void setLeapEventEmitter() {
|
|
207
|
-
LeapEventCallbacks leapEventListener =
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
jsObject = new JSObject(ret.toString());
|
|
216
|
-
} catch (JSONException e) {
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
if(jsObject == null) return;
|
|
220
|
-
notifyListeners(LEAP_CALLBACKS, jsObject);
|
|
254
|
+
LeapEventCallbacks leapEventListener = eventValue -> {
|
|
255
|
+
if (eventValue == null)
|
|
256
|
+
return;
|
|
257
|
+
JSONObject ret = new JSONObject(eventValue);
|
|
258
|
+
JSObject jsObject = null;
|
|
259
|
+
try {
|
|
260
|
+
jsObject = new JSObject(ret.toString());
|
|
261
|
+
} catch (JSONException ignored) {
|
|
221
262
|
|
|
222
263
|
}
|
|
264
|
+
if(jsObject == null) return;
|
|
265
|
+
notifyListeners(LEAP_CALLBACKS, jsObject);
|
|
266
|
+
|
|
223
267
|
};
|
|
224
268
|
Leap.setLeapEventCallbacks(leapEventListener);
|
|
225
269
|
}
|
package/dist/docs.json
CHANGED
|
@@ -39,6 +39,40 @@
|
|
|
39
39
|
],
|
|
40
40
|
"slug": "startwithproperties"
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
"name": "startWithSelfHostedURL",
|
|
44
|
+
"signature": "(options: { baseURL: string; }) => Promise<void>",
|
|
45
|
+
"parameters": [
|
|
46
|
+
{
|
|
47
|
+
"name": "options",
|
|
48
|
+
"docs": "",
|
|
49
|
+
"type": "{ baseURL: string; }"
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"returns": "Promise<void>",
|
|
53
|
+
"tags": [],
|
|
54
|
+
"docs": "",
|
|
55
|
+
"complexTypes": [],
|
|
56
|
+
"slug": "startwithselfhostedurl"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "startWithSelfHostedURLAndProperties",
|
|
60
|
+
"signature": "(options: { baseURL: string; properties: UserProperty; }) => Promise<void>",
|
|
61
|
+
"parameters": [
|
|
62
|
+
{
|
|
63
|
+
"name": "options",
|
|
64
|
+
"docs": "",
|
|
65
|
+
"type": "{ baseURL: string; properties: UserProperty; }"
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
"returns": "Promise<void>",
|
|
69
|
+
"tags": [],
|
|
70
|
+
"docs": "",
|
|
71
|
+
"complexTypes": [
|
|
72
|
+
"UserProperty"
|
|
73
|
+
],
|
|
74
|
+
"slug": "startwithselfhostedurlandproperties"
|
|
75
|
+
},
|
|
42
76
|
{
|
|
43
77
|
"name": "flushProperties",
|
|
44
78
|
"signature": "(options: { properties: UserProperty; }) => Promise<void>",
|
|
@@ -133,6 +167,22 @@
|
|
|
133
167
|
"complexTypes": [],
|
|
134
168
|
"slug": "disable"
|
|
135
169
|
},
|
|
170
|
+
{
|
|
171
|
+
"name": "setAppLocale",
|
|
172
|
+
"signature": "(options: { localeCode: string; }) => Promise<void>",
|
|
173
|
+
"parameters": [
|
|
174
|
+
{
|
|
175
|
+
"name": "options",
|
|
176
|
+
"docs": "",
|
|
177
|
+
"type": "{ localeCode: string; }"
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"returns": "Promise<void>",
|
|
181
|
+
"tags": [],
|
|
182
|
+
"docs": "",
|
|
183
|
+
"complexTypes": [],
|
|
184
|
+
"slug": "setapplocale"
|
|
185
|
+
},
|
|
136
186
|
{
|
|
137
187
|
"name": "addListener",
|
|
138
188
|
"signature": "(eventName: 'leapCallbacks', listenerFunc: (event: LeapCallbacks) => void) => Promise<PluginListenerHandle> & PluginListenerHandle",
|
|
@@ -16,6 +16,13 @@ export interface LeapPluginInterface {
|
|
|
16
16
|
apiKey: string;
|
|
17
17
|
properties: UserProperty;
|
|
18
18
|
}): Promise<void>;
|
|
19
|
+
startWithSelfHostedURL(options: {
|
|
20
|
+
baseURL: string;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
startWithSelfHostedURLAndProperties(options: {
|
|
23
|
+
baseURL: string;
|
|
24
|
+
properties: UserProperty;
|
|
25
|
+
}): Promise<void>;
|
|
19
26
|
flushProperties(options: {
|
|
20
27
|
properties: UserProperty;
|
|
21
28
|
}): Promise<void>;
|
|
@@ -33,6 +40,9 @@ export interface LeapPluginInterface {
|
|
|
33
40
|
projectIds: Array<string>;
|
|
34
41
|
}): Promise<void>;
|
|
35
42
|
disable(): Promise<void>;
|
|
43
|
+
setAppLocale(options: {
|
|
44
|
+
localeCode: string;
|
|
45
|
+
}): Promise<void>;
|
|
36
46
|
addListener(eventName: 'leapCallbacks', listenerFunc: (event: LeapCallbacks) => void): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
37
47
|
addListener(eventName: 'leapElementActionCallbacks', listenerFunc: (event: LeapElementActionCallbacks) => void): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
38
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["\nimport type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface UserProperty {\n [key: string]: string | number\n}\n\nexport interface LeapCallbacks {\n [key: string]: string\n}\n\nexport interface LeapElementActionCallbacks {\n [key: string]: any\n}\n\nexport interface LeapPluginInterface {\n start(options: { apiKey: string }): Promise<void>;\n startWithProperties(options: { apiKey: string, properties: UserProperty }): Promise<void>;\n flushProperties(options: { properties: UserProperty }): Promise<void>;\n setUniqueUserId(options: { uniqueUserId: string }): Promise<void>;\n startProject(options: { projectId: string, resetProject?: boolean }): Promise<void>;\n embedProject(options: { projectId: string }): Promise<void>;\n offlineSync(options: { projectIds: Array<string> }): Promise<void>;\n disable(): Promise<void>;\n\n addListener(\n eventName: 'leapCallbacks',\n listenerFunc: (event: LeapCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n addListener(\n eventName: 'leapElementActionCallbacks',\n listenerFunc: (event: LeapElementActionCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["\nimport type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface UserProperty {\n [key: string]: string | number\n}\n\nexport interface LeapCallbacks {\n [key: string]: string\n}\n\nexport interface LeapElementActionCallbacks {\n [key: string]: any\n}\n\nexport interface LeapPluginInterface {\n start(options: { apiKey: string }): Promise<void>;\n startWithProperties(options: { apiKey: string, properties: UserProperty }): Promise<void>;\n startWithSelfHostedURL(options:{baseURL: string}):Promise<void>;\n startWithSelfHostedURLAndProperties(options:{baseURL:string, properties: UserProperty}):Promise<void>;\n flushProperties(options: { properties: UserProperty }): Promise<void>;\n setUniqueUserId(options: { uniqueUserId: string }): Promise<void>;\n startProject(options: { projectId: string, resetProject?: boolean }): Promise<void>;\n embedProject(options: { projectId: string }): Promise<void>;\n offlineSync(options: { projectIds: Array<string> }): Promise<void>;\n disable(): Promise<void>;\n setAppLocale(options: {localeCode: string}): Promise<void>;\n\n addListener(\n eventName: 'leapCallbacks',\n listenerFunc: (event: LeapCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n addListener(\n eventName: 'leapElementActionCallbacks',\n listenerFunc: (event: LeapElementActionCallbacks) => void,\n ): Promise<PluginListenerHandle> & PluginListenerHandle\n\n\n}\n"]}
|
package/ios/Plugin/LeapPlugin.m
CHANGED
|
@@ -6,10 +6,13 @@
|
|
|
6
6
|
CAP_PLUGIN(LeapPlugin, "LeapPlugin",
|
|
7
7
|
CAP_PLUGIN_METHOD(start, CAPPluginReturnPromise);
|
|
8
8
|
CAP_PLUGIN_METHOD(startWithProperties, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(startWithSelfHostedURL, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(startWithSelfHostedURLAndProperties, CAPPluginReturnPromise);
|
|
9
11
|
CAP_PLUGIN_METHOD(flushProperties, CAPPluginReturnPromise);
|
|
10
12
|
CAP_PLUGIN_METHOD(startProject, CAPPluginReturnPromise);
|
|
11
13
|
CAP_PLUGIN_METHOD(embedProject, CAPPluginReturnPromise);
|
|
12
14
|
CAP_PLUGIN_METHOD(setUniqueUserId, CAPPluginReturnPromise);
|
|
15
|
+
CAP_PLUGIN_METHOD(setAppLocale, CAPPluginReturnPromise);
|
|
13
16
|
CAP_PLUGIN_METHOD(offlineSync, CAPPluginReturnPromise);
|
|
14
17
|
CAP_PLUGIN_METHOD(disable, CAPPluginReturnPromise);
|
|
15
18
|
)
|
|
@@ -2,6 +2,20 @@ import Foundation
|
|
|
2
2
|
import Capacitor
|
|
3
3
|
import LeapSDK
|
|
4
4
|
|
|
5
|
+
let API_KEY = "apiKey"
|
|
6
|
+
let PROPERTIES = "properties"
|
|
7
|
+
let DATE_PREFIX = "Date:"
|
|
8
|
+
let BASE_URL = "baseURL"
|
|
9
|
+
let UNIQUE_USER_ID = "uniqueUserId"
|
|
10
|
+
let LOCALE_CODE = "localeCode"
|
|
11
|
+
let PROJECT_ID = "projectId"
|
|
12
|
+
let RESET_PROJECT = "resetProject"
|
|
13
|
+
let PROJECT_IDS = "projectIds"
|
|
14
|
+
let DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
|
|
15
|
+
let DATE_LOCALE = "en_US_POSIX"
|
|
16
|
+
let LEAP_CALLBACKS = "leapCallbacks"
|
|
17
|
+
let WFX_UNIQUE_ID = "wfx_user_id"
|
|
18
|
+
|
|
5
19
|
/**
|
|
6
20
|
* Please read the Capacitor iOS Plugin Development Guide
|
|
7
21
|
* here: https://capacitorjs.com/docs/plugins/ios
|
|
@@ -11,7 +25,7 @@ import LeapSDK
|
|
|
11
25
|
public class LeapPlugin: CAPPlugin {
|
|
12
26
|
|
|
13
27
|
@objc public func start(_ call: CAPPluginCall) {
|
|
14
|
-
let apiKey = call.getString(
|
|
28
|
+
let apiKey = call.getString(API_KEY) ?? ""
|
|
15
29
|
DispatchQueue.main.async {
|
|
16
30
|
Leap.shared.start(apiKey)
|
|
17
31
|
Leap.shared.callback = self
|
|
@@ -20,63 +34,68 @@ public class LeapPlugin: CAPPlugin {
|
|
|
20
34
|
}
|
|
21
35
|
|
|
22
36
|
@objc public func startWithProperties(_ call: CAPPluginCall) {
|
|
23
|
-
let apiKey = call.getString(
|
|
24
|
-
let properties:[String:AnyHashable] = call.getObject(
|
|
25
|
-
DispatchQueue.main.async {
|
|
37
|
+
let apiKey = call.getString(API_KEY) ?? ""
|
|
38
|
+
let properties:[String:AnyHashable] = call.getObject(PROPERTIES) as? [String:AnyHashable] ?? [:]
|
|
39
|
+
DispatchQueue.main.async {[weak self] in
|
|
26
40
|
let leapShared = Leap.shared.withBuilder(apiKey)
|
|
27
|
-
properties
|
|
28
|
-
|
|
29
|
-
if stringValue.hasPrefix("Date:") {
|
|
30
|
-
let dateValue = stringValue.components(separatedBy: "Date:").last ?? ""
|
|
31
|
-
if let date = self.getDateFromISOString(dateString: dateValue) {
|
|
32
|
-
leapShared?.addProperty(key, dateValue: date)
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
leapShared?.addProperty(key, stringValue: stringValue)
|
|
36
|
-
}
|
|
37
|
-
} else if let intValue = value as? Int {
|
|
38
|
-
leapShared?.addProperty(key, intValue: intValue)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
+
if let wfxId = properties[WFX_UNIQUE_ID] as? String { Leap.shared.addUniqueUserId(wfxId) }
|
|
42
|
+
self?.addProperties(properties: properties)
|
|
41
43
|
leapShared?.start()
|
|
42
44
|
}
|
|
43
45
|
call.resolve()
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
@objc public func startWithSelfHostedURL(_ call:CAPPluginCall) {
|
|
49
|
+
if let baseUrl = call.getString(BASE_URL) {
|
|
50
|
+
DispatchQueue.main.async {
|
|
51
|
+
Leap.shared.withSelfHostedBuilder()?.setBaseUrl(baseUrl)?.start()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
call.resolve()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@objc public func startWithSelfHostedURLAndProperties(_ call:CAPPluginCall) {
|
|
58
|
+
if let baseUrl = call.getString(BASE_URL) {
|
|
59
|
+
let properties = call.getObject(PROPERTIES) as? [String:AnyHashable] ?? [:]
|
|
60
|
+
DispatchQueue.main.async {[weak self] in
|
|
61
|
+
Leap.shared.withSelfHostedBuilder()?.setBaseUrl(baseUrl)
|
|
62
|
+
if let wfxId = properties[WFX_UNIQUE_ID] as? String { Leap.shared.addUniqueUserId(wfxId) }
|
|
63
|
+
self?.addProperties(properties: properties)
|
|
64
|
+
Leap.shared.start()
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
call.resolve()
|
|
68
|
+
}
|
|
69
|
+
|
|
46
70
|
@objc public func flushProperties(_ call: CAPPluginCall) {
|
|
47
|
-
let properties:[String:AnyHashable] = call.getObject(
|
|
48
|
-
DispatchQueue.main.async {
|
|
71
|
+
let properties:[String:AnyHashable] = call.getObject(PROPERTIES) as? [String:AnyHashable] ?? [:]
|
|
72
|
+
DispatchQueue.main.async {[weak self] in
|
|
49
73
|
let leapShared = Leap.shared
|
|
50
|
-
properties
|
|
51
|
-
if let stringValue = value as? String {
|
|
52
|
-
if stringValue.hasPrefix("Date:") {
|
|
53
|
-
let dateValue = stringValue.components(separatedBy: "Date:").last ?? ""
|
|
54
|
-
if let date = self.getDateFromISOString(dateString: dateValue) {
|
|
55
|
-
leapShared.addProperty(key, dateValue: date)
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
leapShared.addProperty(key, stringValue: stringValue)
|
|
59
|
-
}
|
|
60
|
-
} else if let intValue = value as? Int {
|
|
61
|
-
leapShared.addProperty(key, intValue: intValue)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
74
|
+
self?.addProperties(properties: properties)
|
|
64
75
|
leapShared.flush()
|
|
65
76
|
}
|
|
66
77
|
call.resolve()
|
|
67
78
|
}
|
|
68
79
|
|
|
69
80
|
@objc public func setUniqueUserId(_ call: CAPPluginCall) {
|
|
70
|
-
let uniqueUserId = call.getString(
|
|
81
|
+
let uniqueUserId = call.getString(UNIQUE_USER_ID) ?? ""
|
|
71
82
|
DispatchQueue.main.async {
|
|
72
83
|
Leap.shared.setUniqueUserId(uniqueUserId)
|
|
73
84
|
}
|
|
74
85
|
call.resolve()
|
|
75
86
|
}
|
|
76
87
|
|
|
88
|
+
@objc public func setAppLocale(_ call: CAPPluginCall) {
|
|
89
|
+
let localeCode = call.getString(LOCALE_CODE) ?? ""
|
|
90
|
+
DispatchQueue.main.async {
|
|
91
|
+
Leap.shared.setAppLocale(localeCode)
|
|
92
|
+
}
|
|
93
|
+
call.resolve()
|
|
94
|
+
}
|
|
95
|
+
|
|
77
96
|
@objc public func startProject(_ call: CAPPluginCall) {
|
|
78
|
-
let projectId = call.getString(
|
|
79
|
-
let resetProject = call.getBool(
|
|
97
|
+
let projectId = call.getString(PROJECT_ID) ?? ""
|
|
98
|
+
let resetProject = call.getBool(RESET_PROJECT) ?? false
|
|
80
99
|
DispatchQueue.main.async {
|
|
81
100
|
Leap.shared.startProject(projectId, resetProject: resetProject)
|
|
82
101
|
}
|
|
@@ -84,7 +103,7 @@ public class LeapPlugin: CAPPlugin {
|
|
|
84
103
|
}
|
|
85
104
|
|
|
86
105
|
@objc public func embedProject(_ call: CAPPluginCall) {
|
|
87
|
-
let projectId = call.getString(
|
|
106
|
+
let projectId = call.getString(PROJECT_ID) ?? ""
|
|
88
107
|
DispatchQueue.main.async {
|
|
89
108
|
Leap.shared.embedProject(projectId)
|
|
90
109
|
}
|
|
@@ -92,7 +111,7 @@ public class LeapPlugin: CAPPlugin {
|
|
|
92
111
|
}
|
|
93
112
|
|
|
94
113
|
@objc public func offlineSync(_ call: CAPPluginCall) {
|
|
95
|
-
let projectIds = call.getArray(
|
|
114
|
+
let projectIds = call.getArray(PROJECT_IDS)?.capacitor.replacingNullValues() as? [String] ?? []
|
|
96
115
|
DispatchQueue.main.async {
|
|
97
116
|
Leap.shared.offlineSync(projectIds)
|
|
98
117
|
}
|
|
@@ -106,10 +125,29 @@ public class LeapPlugin: CAPPlugin {
|
|
|
106
125
|
call.resolve()
|
|
107
126
|
}
|
|
108
127
|
|
|
128
|
+
func addProperties(properties:[String:AnyHashable]) {
|
|
129
|
+
properties.forEach { key, value in
|
|
130
|
+
if key != WFX_UNIQUE_ID {
|
|
131
|
+
if let stringValue = value as? String {
|
|
132
|
+
if stringValue.hasPrefix(DATE_PREFIX) {
|
|
133
|
+
let dateValue = stringValue.components(separatedBy: DATE_PREFIX).last ?? ""
|
|
134
|
+
if let date = self.getDateFromISOString(dateString: dateValue) {
|
|
135
|
+
Leap.shared.addProperty(key, dateValue: date)
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
Leap.shared.addProperty(key, stringValue: stringValue)
|
|
139
|
+
}
|
|
140
|
+
} else if let intValue = value as? Int {
|
|
141
|
+
Leap.shared.addProperty(key, intValue: intValue)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
109
147
|
func getDateFromISOString(dateString:String) -> Date? {
|
|
110
148
|
let formatter = DateFormatter()
|
|
111
|
-
formatter.dateFormat =
|
|
112
|
-
let posix:Locale = Locale(identifier:
|
|
149
|
+
formatter.dateFormat = DATE_FORMAT
|
|
150
|
+
let posix:Locale = Locale(identifier: DATE_LOCALE)
|
|
113
151
|
formatter.locale = posix
|
|
114
152
|
let date = formatter.date(from: dateString)
|
|
115
153
|
return date
|
|
@@ -120,7 +158,7 @@ extension LeapPlugin: LeapCallback {
|
|
|
120
158
|
|
|
121
159
|
public func eventNotification(eventInfo: Dictionary<String, Any>) {
|
|
122
160
|
DispatchQueue.main.async { [weak self] in
|
|
123
|
-
self?.notifyListeners(
|
|
161
|
+
self?.notifyListeners(LEAP_CALLBACKS, data: eventInfo)
|
|
124
162
|
}
|
|
125
163
|
}
|
|
126
164
|
}
|