react-native-move-sdk 0.1.5 → 0.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 +1 -1
- package/android/build.gradle +45 -39
- package/android/gradle/wrapper/gradle-wrapper.properties +4 -1
- package/android/gradle.properties +8 -4
- package/android/src/main/java/in/dolph/move/sdk/MoveExtensions.kt +44 -0
- package/android/src/main/java/in/dolph/move/sdk/MoveNotificationConfig.kt +26 -26
- package/android/src/main/java/in/dolph/move/sdk/MoveSdkConfig.kt +8 -13
- package/android/src/main/java/in/dolph/move/sdk/MoveSdkModule.kt +137 -27
- package/android/src/main/java/in/dolph/move/sdk/MoveSdkPackage.kt +1 -1
- package/android/src/main/java/in/dolph/move/sdk/MoveSdkRepository.kt +171 -162
- package/android/src/main/java/in/dolph/move/sdk/NativeMoveSdkWrapper.kt +184 -84
- package/android/src/test/java/io/dolphin/move/MoveWrapperTest.kt +157 -0
- package/ios/MoveSdk-Bridging-Header.h +1 -0
- package/ios/MoveSdk.xcodeproj/project.pbxproj +6 -8
- package/ios/NativeModule/{DolphinSdk.h → MoveSdk.h} +21 -7
- package/ios/NativeModule/MoveSdk.swift +607 -0
- package/lib/commonjs/index.js +105 -111
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +105 -111
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +38 -38
- package/package.json +1 -1
- package/react-native-move-sdk.podspec +3 -1
- package/src/index.ts +163 -190
- package/ios/NativeModule/DolphinSdk.swift +0 -357
- package/ios/NativeModule/DolphinSdkDemoReactNative-Bridging-Header.h +0 -8
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import DolphinMoveSDK
|
|
3
|
-
|
|
4
|
-
internal protocol DolphinSDKLauncherDelegate: AnyObject {
|
|
5
|
-
func send(event: DolphinSDKLauncher.Event, data: [String: Any])
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
@objc(DolphinSdk)
|
|
9
|
-
class DolphinSdk: RCTEventEmitter {
|
|
10
|
-
private enum CError: String, Error {
|
|
11
|
-
case transformedServices = "Unknown driving service identifier in init parameters"
|
|
12
|
-
case transformedTimelineDetectionServices = "Unknown timeline service identifier in init parameters"
|
|
13
|
-
case transformedWalkingServices = "Unknown walking service identifier in init parameters"
|
|
14
|
-
case transformedOtherServices = "Unknown other service identifier in init parameters"
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
var ERROR_CODE = "DOLPHIN_SDK_ERROR"
|
|
18
|
-
|
|
19
|
-
override init() {
|
|
20
|
-
super.init()
|
|
21
|
-
DolphinSDKLauncher.shared.delegate = self
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
@objc
|
|
25
|
-
func initialize(_ contractId: String,
|
|
26
|
-
accessToken: String,
|
|
27
|
-
refreshToken: String,
|
|
28
|
-
productId: Int64,
|
|
29
|
-
timelineDetectionServices: Array<String>,
|
|
30
|
-
drivingServices: Array<String>,
|
|
31
|
-
walkingServices: Array<String>,
|
|
32
|
-
otherServices: Array<String>,
|
|
33
|
-
resolve: @escaping RCTPromiseResolveBlock,
|
|
34
|
-
reject: @escaping RCTPromiseRejectBlock) {
|
|
35
|
-
|
|
36
|
-
do {
|
|
37
|
-
|
|
38
|
-
let transformedServices: Array<MoveConfig.DrivingService> = try drivingServices.map {(s) -> MoveConfig.DrivingService in
|
|
39
|
-
if(s == "DistractionFreeDriving") {
|
|
40
|
-
return MoveConfig.DrivingService.dfd
|
|
41
|
-
}
|
|
42
|
-
else if(s == "DrivingBehaviour") {
|
|
43
|
-
return MoveConfig.DrivingService.behaviour
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
throw CError.transformedServices
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let transformedTimelineDetectionServices: Array<MoveConfig.TimelineDetectionService> = try! timelineDetectionServices.map {(s) -> MoveConfig.TimelineDetectionService in
|
|
51
|
-
if(s == "DRIVING") {
|
|
52
|
-
return MoveConfig.TimelineDetectionService.driving
|
|
53
|
-
}
|
|
54
|
-
else if(s == "BICYCLE") {
|
|
55
|
-
return MoveConfig.TimelineDetectionService.bicycle
|
|
56
|
-
}
|
|
57
|
-
else if(s == "WALKING") {
|
|
58
|
-
return MoveConfig.TimelineDetectionService.walking
|
|
59
|
-
}
|
|
60
|
-
else if(s == "PUBLIC_TRANSPORT") {
|
|
61
|
-
return MoveConfig.TimelineDetectionService.publicTransport
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
throw CError.transformedTimelineDetectionServices
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let transformedWalkingServices: Array<MoveConfig.WalkingService> = try walkingServices.map {(s) -> MoveConfig.WalkingService in
|
|
69
|
-
if(s == "Location") {
|
|
70
|
-
return MoveConfig.WalkingService.location
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
throw CError.transformedWalkingServices
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let transformedOtherServices: Array<MoveConfig.OtherService> = try otherServices.map {(s) -> MoveConfig.OtherService in
|
|
78
|
-
if(s == "PointsOfInterest") {
|
|
79
|
-
return MoveConfig.OtherService.poi
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
throw CError.transformedOtherServices
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// TODO: Fix wrapper and add config option from RN for walking services (actually only 1 now)
|
|
87
|
-
let sdkConfig = MoveConfig(timelineDetectionService: transformedTimelineDetectionServices, drivingServices: transformedServices, walkingServices: transformedWalkingServices, otherServices: transformedOtherServices)
|
|
88
|
-
let auth = MoveAuth(userToken: accessToken, refreshToken: refreshToken, contractID: contractId, productID: productId)
|
|
89
|
-
|
|
90
|
-
DispatchQueue.main.async {
|
|
91
|
-
DolphinSDKLauncher.shared.initialize(auth: auth, config: sdkConfig)
|
|
92
|
-
}
|
|
93
|
-
resolve("OK")
|
|
94
|
-
} catch {
|
|
95
|
-
reject("DOLPHIN_SDK_ERROR", "\(error)", nil)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
@objc
|
|
100
|
-
func getState(
|
|
101
|
-
_ resolve: RCTPromiseResolveBlock,
|
|
102
|
-
rejecter reject: RCTPromiseRejectBlock
|
|
103
|
-
) {
|
|
104
|
-
resolve("\(DolphinSDKLauncher.shared.sdk.getSDKState())")
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
@objc
|
|
108
|
-
func getAuthState(
|
|
109
|
-
_ resolve: RCTPromiseResolveBlock,
|
|
110
|
-
rejecter reject: RCTPromiseRejectBlock
|
|
111
|
-
) {
|
|
112
|
-
resolve("\(DolphinSDKLauncher.shared.sdk.getAuthState())")
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
@objc
|
|
116
|
-
func updateAuth(
|
|
117
|
-
_ contractId: String,
|
|
118
|
-
accessToken: String,
|
|
119
|
-
refreshToken: String,
|
|
120
|
-
productId: Int64,
|
|
121
|
-
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
122
|
-
rejecter reject: @escaping RCTPromiseRejectBlock
|
|
123
|
-
) {
|
|
124
|
-
let auth = MoveAuth(userToken: accessToken, refreshToken: refreshToken, contractID: contractId, productID: productId)
|
|
125
|
-
|
|
126
|
-
DolphinSDKLauncher.shared.sdk.update(auth: auth) { configurationError in
|
|
127
|
-
if let configurationError = configurationError {
|
|
128
|
-
reject("DolphinSdk-AuthState-ConfigurationError", "\(configurationError)", nil)
|
|
129
|
-
} else {
|
|
130
|
-
DolphinSDKLauncher.shared.sdkAuth = auth
|
|
131
|
-
resolve("OK")
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
@objc
|
|
137
|
-
func getTripState(
|
|
138
|
-
_ resolve: RCTPromiseResolveBlock,
|
|
139
|
-
rejecter reject: RCTPromiseRejectBlock
|
|
140
|
-
) {
|
|
141
|
-
resolve("\(DolphinSDKLauncher.shared.sdk.getTripState())")
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
@objc
|
|
145
|
-
func startAutomaticDetection() {
|
|
146
|
-
DolphinSDKLauncher.shared.startAutomaticDetection()
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
@objc
|
|
150
|
-
func stopAutomaticDetection() {
|
|
151
|
-
DolphinSDKLauncher.shared.stopAutomaticDetection()
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
@objc
|
|
155
|
-
func shutdown() {
|
|
156
|
-
DolphinSDKLauncher.shared.shutdown()
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
@objc
|
|
160
|
-
func forceTripRecognition() {
|
|
161
|
-
DolphinSDKLauncher.shared.sdk.forceTripRecognition()
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
@objc
|
|
165
|
-
func synchronizeUserData(
|
|
166
|
-
_ resolve: @escaping RCTPromiseResolveBlock,
|
|
167
|
-
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
168
|
-
DolphinSDKLauncher.shared.sdk.synchronizeUserData() { success in
|
|
169
|
-
resolve(success)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
@objc
|
|
174
|
-
func ignoreCurrentTrip() {
|
|
175
|
-
DolphinSDKLauncher.shared.sdk.ignoreCurrentTrip()
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
@objc
|
|
179
|
-
func finishCurrentTrip() {
|
|
180
|
-
DolphinSDKLauncher.shared.sdk.finishCurrentTrip()
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
@objc
|
|
184
|
-
func resolveError() {
|
|
185
|
-
DolphinSDKLauncher.shared.sdk.resolveSDKStateError()
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
@objc
|
|
189
|
-
func sendAppEvent(_ eventInfo: NSString) {
|
|
190
|
-
self.sendEvent(withName: "DolphinSdk-AppEvent", body: ["eventInfo": "\(eventInfo)"])
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
@objc public static func initIfPossibleWith(launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
|
|
194
|
-
DolphinSDKLauncher.shared.initIfPossibleWith(launchOptions: launchOptions)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
override func supportedEvents() -> [String]! {
|
|
198
|
-
return ["DolphinSdk-InitError", "DolphinSdk-State", "DolphinSdk-TripState", "DolphinSdk-AuthState", "DolphinSdk-AppEvent"]
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
static override func moduleName() -> String! {
|
|
202
|
-
return "DolphinSdk"
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
static override func requiresMainQueueSetup() -> Bool {
|
|
206
|
-
// To let React Native know if your module needs to be initialized on the main thread, before any JavaScript code executes.
|
|
207
|
-
// Otherwise you will see a warning that in the future your module may be initialized on a background thread unless you explicitly opt out
|
|
208
|
-
return true
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
extension DolphinSdk: DolphinSDKLauncherDelegate {
|
|
213
|
-
func send(event: DolphinSDKLauncher.Event, data: [String: Any]) {
|
|
214
|
-
sendEvent(withName: event.rawValue, body: data)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
internal class DolphinSDKLauncher {
|
|
219
|
-
internal enum Event: String {
|
|
220
|
-
case sdkState = "DolphinSdk-State"
|
|
221
|
-
case tripState = "DolphinSdk-TripState"
|
|
222
|
-
case authState = "DolphinSdk-AuthState"
|
|
223
|
-
case initError = "DolphinSdk-InitError"
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
private enum DefaultsKey: String {
|
|
227
|
-
case auth = "MOVE.WRAPPER.AUTH"
|
|
228
|
-
case config = "MOVE.WRAPPER.CONFIG"
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
weak var delegate: DolphinSDKLauncherDelegate?
|
|
232
|
-
|
|
233
|
-
static let shared = DolphinSDKLauncher()
|
|
234
|
-
|
|
235
|
-
let sdk = MoveSDK.shared
|
|
236
|
-
var launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
|
237
|
-
|
|
238
|
-
/// Persistence
|
|
239
|
-
internal var sdkAuth: DolphinMoveSDK.MoveAuth? {
|
|
240
|
-
didSet { DolphinSDKLauncher.encode(sdkAuth, forKey: .auth) }
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
private var sdkConfig: DolphinMoveSDK.MoveConfig? {
|
|
244
|
-
didSet { DolphinSDKLauncher.encode(sdkConfig, forKey: .config) }
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
private var isInRunningState: Bool {
|
|
248
|
-
didSet {
|
|
249
|
-
UserDefaults.standard.set(isInRunningState, forKey: "MOVE.WRAPPER.RUNNING")
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
init() {
|
|
254
|
-
sdkConfig = DolphinSDKLauncher.decode(.config)
|
|
255
|
-
sdkAuth = DolphinSDKLauncher.decode(.auth)
|
|
256
|
-
|
|
257
|
-
isInRunningState = UserDefaults.standard.bool(forKey: "MOVE.WRAPPER.RUNNING")
|
|
258
|
-
|
|
259
|
-
sdk.setSDKStateListener { state in
|
|
260
|
-
var data = ["state": "\(state)"]
|
|
261
|
-
switch (state) {
|
|
262
|
-
case let .error(stateError):
|
|
263
|
-
data["errorReason"] = "\(stateError)"
|
|
264
|
-
case .ready:
|
|
265
|
-
if self.isInRunningState {
|
|
266
|
-
self.sdk.startAutomaticDetection()
|
|
267
|
-
}
|
|
268
|
-
default:
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
self.delegate?.send(event: .sdkState, data: data)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
sdk.setTripStateListener { state in
|
|
275
|
-
self.delegate?.send(event: .tripState, data: ["state": "\(state)"])
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
sdk.setAuthStateUpdateListener { state in
|
|
279
|
-
var data = ["state": "\(state)"]
|
|
280
|
-
switch (state) {
|
|
281
|
-
case let .valid(auth):
|
|
282
|
-
self.sdkAuth = auth
|
|
283
|
-
data["accessToken"] = "\(auth.userToken)"
|
|
284
|
-
data["refreshToken"] = "\(auth.refreshToken)"
|
|
285
|
-
default:
|
|
286
|
-
break
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
self.delegate?.send(event: .authState, data: data)
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
internal func initIfPossibleWith(launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
|
|
294
|
-
self.launchOptions = launchOptions
|
|
295
|
-
/// warm start SDK
|
|
296
|
-
if isInRunningState, let auth = sdkAuth, let config = sdkConfig {
|
|
297
|
-
MoveSDK.shared.initialize(auth: auth, config: config, launchOptions: launchOptions) { initError in
|
|
298
|
-
if let error = initError {
|
|
299
|
-
self.delegate?.send(event: .initError, data: ["error": "\(error)"])
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
internal func initialize(auth: DolphinMoveSDK.MoveAuth, config: DolphinMoveSDK.MoveConfig) {
|
|
306
|
-
MoveSDK.shared.initialize(auth: auth, config: config, launchOptions: self.launchOptions) { initError in
|
|
307
|
-
if let error = initError {
|
|
308
|
-
self.delegate?.send(event: .initError, data: ["error": "\(error)"])
|
|
309
|
-
} else {
|
|
310
|
-
/// store back config and auth for bg launch
|
|
311
|
-
self.sdkConfig = config
|
|
312
|
-
self.sdkAuth = auth
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
func shutdown() {
|
|
318
|
-
isInRunningState = false
|
|
319
|
-
sdkAuth = nil
|
|
320
|
-
sdk.shutDown()
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
func startAutomaticDetection() {
|
|
324
|
-
if !isInRunningState {
|
|
325
|
-
isInRunningState = true
|
|
326
|
-
sdk.startAutomaticDetection()
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
func stopAutomaticDetection() {
|
|
331
|
-
if isInRunningState {
|
|
332
|
-
isInRunningState = false
|
|
333
|
-
sdk.stopAutomaticDetection()
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
private static func decode<T>(_ key: DefaultsKey) -> T? where T: Decodable {
|
|
338
|
-
let decoder = PropertyListDecoder()
|
|
339
|
-
|
|
340
|
-
if let data = UserDefaults.standard.object(forKey: key.rawValue) as? Data {
|
|
341
|
-
return try? decoder.decode(T.self, from: data)
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return nil
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
private static func encode<T>(_ encodable: T?, forKey key: DefaultsKey) where T: Encodable {
|
|
348
|
-
if let encodable = encodable {
|
|
349
|
-
let encoder = PropertyListEncoder()
|
|
350
|
-
if let data = try? encoder.encode(encodable) {
|
|
351
|
-
UserDefaults.standard.set(data, forKey: key.rawValue)
|
|
352
|
-
}
|
|
353
|
-
} else {
|
|
354
|
-
UserDefaults.standard.removeObject(forKey: key.rawValue)
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|