@os1-platform/dispatch-mobile 2.1.30 → 3.0.1

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.
Files changed (68) hide show
  1. package/README.md +4 -91
  2. package/android/.gradle/7.5/checksums/checksums.lock +0 -0
  3. package/android/.gradle/7.5/checksums/sha1-checksums.bin +0 -0
  4. package/android/.gradle/7.5/fileHashes/fileHashes.lock +0 -0
  5. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  6. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  7. package/android/.idea/{other.xml → caches/deviceStreaming.xml} +98 -21
  8. package/android/build.gradle +1 -0
  9. package/android/src/main/AndroidManifest.xml +1 -0
  10. package/android/src/main/java/com/dispatchsdk/DispatchSdkPackage.kt +5 -1
  11. package/android/src/main/java/com/dispatchsdk/location/LocationModule.kt +79 -0
  12. package/android/src/main/java/com/dispatchsdk/permissions/PermissionModule.kt +90 -0
  13. package/ios/EventEmitter.swift +13 -1
  14. package/ios/LocationManager.swift +143 -0
  15. package/ios/LocationModule.m +19 -0
  16. package/ios/LocationModule.swift +32 -0
  17. package/ios/PermissionsModule.m +21 -0
  18. package/ios/PermissionsModule.swift +24 -0
  19. package/ios/RNEventEmitter.m +2 -8
  20. package/ios/RNEventEmitter.swift +13 -19
  21. package/lib/commonjs/components/executiontasks/doodle/SignatureET.js +5 -3
  22. package/lib/commonjs/components/executiontasks/doodle/SignatureET.js.map +1 -1
  23. package/lib/commonjs/components/executiontasks/imageCapture/ImageCapture.js +5 -3
  24. package/lib/commonjs/components/executiontasks/imageCapture/ImageCapture.js.map +1 -1
  25. package/lib/commonjs/index.js +0 -3
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/commonjs/manager/location/LocationManager.js +91 -46
  28. package/lib/commonjs/manager/location/LocationManager.js.map +1 -1
  29. package/lib/commonjs/native/LocationModule.js +47 -0
  30. package/lib/commonjs/native/LocationModule.js.map +1 -0
  31. package/lib/commonjs/native/PermissionModule.js +21 -0
  32. package/lib/commonjs/native/PermissionModule.js.map +1 -0
  33. package/lib/commonjs/utils/ExecTaskUtils.js +3 -3
  34. package/lib/commonjs/utils/ExecTaskUtils.js.map +1 -1
  35. package/lib/commonjs/utils/SdkUtils.js +12 -4
  36. package/lib/commonjs/utils/SdkUtils.js.map +1 -1
  37. package/lib/module/components/executiontasks/doodle/SignatureET.js +5 -3
  38. package/lib/module/components/executiontasks/doodle/SignatureET.js.map +1 -1
  39. package/lib/module/components/executiontasks/imageCapture/ImageCapture.js +5 -3
  40. package/lib/module/components/executiontasks/imageCapture/ImageCapture.js.map +1 -1
  41. package/lib/module/index.js +0 -3
  42. package/lib/module/index.js.map +1 -1
  43. package/lib/module/manager/location/LocationManager.js +90 -44
  44. package/lib/module/manager/location/LocationManager.js.map +1 -1
  45. package/lib/module/native/LocationModule.js +41 -0
  46. package/lib/module/native/LocationModule.js.map +1 -0
  47. package/lib/module/native/PermissionModule.js +15 -0
  48. package/lib/module/native/PermissionModule.js.map +1 -0
  49. package/lib/module/utils/ExecTaskUtils.js +3 -3
  50. package/lib/module/utils/ExecTaskUtils.js.map +1 -1
  51. package/lib/module/utils/SdkUtils.js +12 -4
  52. package/lib/module/utils/SdkUtils.js.map +1 -1
  53. package/lib/typescript/index.d.ts +0 -4
  54. package/lib/typescript/manager/location/LocationManager.d.ts +4 -2
  55. package/lib/typescript/native/LocationModule.d.ts +14 -0
  56. package/lib/typescript/native/PermissionModule.d.ts +6 -0
  57. package/package.json +3 -5
  58. package/src/components/executiontasks/doodle/SignatureET.tsx +6 -4
  59. package/src/components/executiontasks/imageCapture/ImageCapture.tsx +6 -3
  60. package/src/index.tsx +0 -7
  61. package/src/manager/location/LocationManager.ts +93 -41
  62. package/src/native/LocationModule.ts +52 -0
  63. package/src/native/PermissionModule.ts +21 -0
  64. package/src/utils/ExecTaskUtils.ts +3 -3
  65. package/src/utils/SdkUtils.ts +15 -5
  66. package/android/.gradle/6.8/fileChanges/last-build.bin +0 -0
  67. package/android/.gradle/6.8/fileHashes/fileHashes.lock +0 -0
  68. package/android/.gradle/6.8/gc.properties +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@os1-platform/dispatch-mobile",
3
- "version": "2.1.30",
3
+ "version": "3.0.1",
4
4
  "description": "Dispatch SDK React Native Package",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -51,7 +51,6 @@
51
51
  "author": "Amit Sanvedi <amit.sanvedi@delhivery.com> (https://github.com/FoxtrotPlatform/platform-coreos-dispatch-sdk)",
52
52
  "homepage": "https://github.com/FoxtrotPlatform/platform-coreos-dispatch-sdk/#readme",
53
53
  "devDependencies": {
54
- "@delhivery/platform-coreos-mts-sdk": "2.0.10",
55
54
  "@apollo/client": "^3.5.6",
56
55
  "@babel/core": "^7.12.9",
57
56
  "@babel/preset-env": "^7.15.8",
@@ -129,7 +128,6 @@
129
128
  "typescript": "^4.4.4"
130
129
  },
131
130
  "peerDependencies": {
132
- "@delhivery/platform-coreos-mts-sdk": "2.0.10",
133
131
  "@apollo/client": "^3.5.6",
134
132
  "@expo-google-fonts/ibm-plex-sans": "*",
135
133
  "@react-native-async-storage/async-storage": "^1.15.14",
@@ -258,7 +256,7 @@
258
256
  ]
259
257
  ]
260
258
  },
261
- "dependencies": {
259
+ "dependencies": {
262
260
  "@os1-platform/platform-coreos-execution-engine-sdk": "1.0.17",
263
261
  "@rjsf/core": "^2.0.0",
264
262
  "apollo-link-timeout": "^4.0.0",
@@ -277,4 +275,4 @@
277
275
  "rjsf-native": "^1.0.14",
278
276
  "toggle-switch-react-native": "^3.3.0"
279
277
  }
280
- }
278
+ }
@@ -143,10 +143,12 @@ lineHeight: 24 }}>{props.title}</Text>
143
143
  )) ?? 'NULL';
144
144
  const dateTime = await callbackHandler.getDateTime();
145
145
  console.log('saveAndSubmit:dateTime: ', dateTime);
146
-
147
- let lat = LocationManager.getInstance().getLastLocation().latitude;
148
- let lng = LocationManager.getInstance().getLastLocation().longitude;
149
- let accuracy = LocationManager.getInstance().getLastLocation().accuracy;
146
+ let lastLocation = await LocationManager.getInstance().getLastLocation();
147
+ console.log("signatureET:lastLocation:",JSON.stringify(lastLocation));
148
+
149
+ let lat = lastLocation.latitude;
150
+ let lng = lastLocation.longitude;
151
+ let accuracy = lastLocation.accuracy;
150
152
 
151
153
  let insertID = await insertDocumentInDB(
152
154
  fileName,
@@ -304,6 +304,9 @@ const ImageCapture = (props: any) => {
304
304
  imgArray = imagesDummy;
305
305
  const dateTime = await callbackHandler.getDateTime();
306
306
  console.log('captureImage:dateTime: ', dateTime);
307
+ let lastLocation = await LocationManager.getInstance().getLastLocation();
308
+ console.log("captureImage:lastLocation:",JSON.stringify(lastLocation));
309
+
307
310
  imgArray[index] = {
308
311
  id: CaptureUtils.getImagesFileName(),
309
312
  // @ts-ignore
@@ -311,9 +314,9 @@ const ImageCapture = (props: any) => {
311
314
  url: '',
312
315
  timestamp: Date.now(),
313
316
  dateTime: dateTime,
314
- lat: LocationManager.getInstance().getLastLocation().latitude,
315
- lng: LocationManager.getInstance().getLastLocation().longitude,
316
- accuracy: LocationManager.getInstance().getLastLocation().accuracy,
317
+ lat: lastLocation.latitude,
318
+ lng: lastLocation.longitude,
319
+ accuracy: lastLocation.accuracy,
317
320
  };
318
321
  setImagesDummy([...imgArray])
319
322
  console.log("images211:", JSON.stringify(imgArray));
package/src/index.tsx CHANGED
@@ -1,11 +1,6 @@
1
1
  import Storage from './utils/storage';
2
2
  import type * as ETaskSchema from './components/executiontasks/ExecutionTasksIndex';
3
3
  import * as ExecutionTask from './components/executiontasks/ExecutionTasksIndex';
4
- import type {
5
- MTSInitRequest,
6
- MTSStartRequest,
7
- } from '@delhivery/platform-coreos-mts-sdk';
8
- import * as MtsSdk from '@delhivery/platform-coreos-mts-sdk';
9
4
  import NativeSyncManager from './manager/syncmanager/NativeSyncManager';
10
5
  import type { DocumentRow, EventRow } from './manager/syncmanager/DBConfig';
11
6
  import { SyncMethod, DispatchSyncType } from './manager/syncmanager/DBConfig';
@@ -81,8 +76,6 @@ export type { ETaskSchema };
81
76
  export { ExecutionTask, CancelOrderDialog };
82
77
  export { DispatchSDKManager };
83
78
  //
84
- export type { MTSStartRequest, MTSInitRequest };
85
- export { MtsSdk };
86
79
  export { Helper };
87
80
  //sentry function export
88
81
  export { SentryAnalyticsSingleton, fireEventWithScreenName, SeverityLevelValue, ScreenNameSdkConstants, SentryEventNameSdkConstants, DispatchAndUserData, SentryEvent };
@@ -1,20 +1,37 @@
1
1
  import * as Location from 'expo-location';
2
2
  import { Accuracy, LocationObject } from 'expo-location';
3
3
  import Logger, { LOG_TYPE } from '../../utils/Logger';
4
+ import { EmitterSubscription, Platform } from 'react-native';
5
+ import PermissionModule from '../../native/PermissionModule';
6
+ import LocationModule, { LocationType } from '../../native/LocationModule';
4
7
 
5
8
  export default class LocationManager {
6
9
  private static instance: LocationManager;
7
- private lastLocation: LocationObject | null = null;
10
+ private lastLocationAndroid: LocationType | null = null;
11
+ private lastLocationiOS: LocationType | null = null;
8
12
  private stopUpdate: { remove(): void } | undefined;
13
+ private subscription: EmitterSubscription | null = null;
9
14
 
10
15
  public async checkForLocationPermissions(): Promise<boolean> {
11
- let permissionResponse = await Location.getForegroundPermissionsAsync();
12
- if (permissionResponse.status === 'granted') {
13
- this.startUpdates();
14
- return true;
15
- } else {
16
- let { status } = await Location.requestForegroundPermissionsAsync();
17
- if (status === 'granted') {
16
+ console.log("checkForLocationPermissions");
17
+ if (Platform.OS === 'ios') {
18
+ // old code checking for permissions using expo-location
19
+ // let permissionResponse = await Location.getForegroundPermissionsAsync();
20
+ // if (permissionResponse.status === 'granted') {
21
+ // this.startUpdates();
22
+ // return true;
23
+ // } else {
24
+ // let { status } = await Location.requestForegroundPermissionsAsync();
25
+ // if (status === 'granted') {
26
+ // this.startUpdates();
27
+ // return true;
28
+ // } else {
29
+ // this.stopLocationUpdates();
30
+ // return false;
31
+ // }
32
+ // }
33
+ let foregroundPermission = await PermissionModule.requestForegroundPermissions();
34
+ if (foregroundPermission) {
18
35
  this.startUpdates();
19
36
  return true;
20
37
  } else {
@@ -22,6 +39,17 @@ export default class LocationManager {
22
39
  return false;
23
40
  }
24
41
  }
42
+ if (Platform.OS === 'android') {
43
+ let foregroundPermission = await PermissionModule.requestForegroundPermissions();
44
+ if (foregroundPermission) {
45
+ this.startUpdates();
46
+ return true;
47
+ } else {
48
+ this.stopLocationUpdates();
49
+ return false;
50
+ }
51
+ }
52
+ return true;
25
53
  }
26
54
 
27
55
  public static getInstance(): LocationManager {
@@ -30,50 +58,74 @@ export default class LocationManager {
30
58
  }
31
59
  return LocationManager.instance;
32
60
  }
61
+
33
62
  public startUpdates() {
34
- Location.watchPositionAsync(
35
- {
36
- accuracy: Accuracy.Highest,
37
- timeInterval: 10000, // in millis
38
- distanceInterval: 10, //in metres
39
- },
40
- (location) => {
63
+ if (Platform.OS === 'android') {
64
+ LocationModule.startLocationUpdates();
65
+ this.subscription = LocationModule.addLocationListener((location) => {
66
+ console.log('Location updated:', location);
41
67
  if (location != null) {
42
- this.lastLocation = location;
68
+ this.lastLocationAndroid = location
43
69
  }
44
- }
45
- )
46
- .then((r) => {
47
- this.stopUpdate = r;
48
- })
49
- .catch((error) => {
50
- Logger.getInstance().logEvent(
51
- 'LOCATION_MANAGER',
52
- error.message,
53
- LOG_TYPE.SDK_WARNING
54
- );
55
70
  });
71
+ }
72
+
73
+ if (Platform.OS === 'ios') {
74
+ console.log("startUpdates");
75
+ LocationModule.startLocationUpdates();
76
+ // this.subscription = LocationModule.addLocationListener((location) => {
77
+ // console.log('Location updated:', location);
78
+ // if (location != null) {
79
+ // this.lastLocationiOS = location
80
+ // }
81
+ // });
82
+ }
56
83
  }
57
- public getLastLocation(): DLocation {
58
- if (this.lastLocation != null && this.lastLocation.coords != null) {
59
- let accuracy = '';
60
- if (this.lastLocation.coords.accuracy !== null) {
61
- let accuracyVal = Math.round(this.lastLocation.coords.accuracy);
62
- accuracy = accuracyVal.toString();
63
- }
84
+
85
+ public async getLastLocation(): Promise<DLocation> {
86
+ if (Platform.OS === 'android' && this.lastLocationAndroid != null) {
87
+ console.log("lastLocationAndroid:", this.lastLocationAndroid);
64
88
  return {
65
- latitude: this.lastLocation.coords.latitude.toString(),
66
- longitude: this.lastLocation.coords.longitude.toString(),
67
- accuracy: accuracy,
89
+ latitude: this.lastLocationAndroid.latitude.toString(),
90
+ longitude: this.lastLocationAndroid.longitude.toString(),
91
+ accuracy: this.lastLocationAndroid.accuracy.toString(),
68
92
  };
69
- } else {
70
- return { latitude: 'null', longitude: 'null', accuracy: 'null' };
71
93
  }
94
+ if (Platform.OS === 'ios') {
95
+ this.lastLocationiOS = await LocationModule.getLastLocation();
96
+ console.log("lastLocationiOS:", this.lastLocationiOS);
97
+ if(this.lastLocationiOS){
98
+ return {
99
+ latitude: this.lastLocationiOS.latitude.toString(),
100
+ longitude: this.lastLocationiOS.longitude.toString(),
101
+ accuracy: this.lastLocationiOS.accuracy.toString(),
102
+ };
103
+ }
104
+ }
105
+ return {
106
+ latitude: 'null',
107
+ longitude: 'null',
108
+ accuracy: 'null',
109
+ };
72
110
  }
111
+
112
+
73
113
  public stopLocationUpdates() {
74
114
  try {
75
- if (this.stopUpdate) this.stopUpdate.remove();
76
- } catch (error: any) {}
115
+ // code for android
116
+ if (Platform.OS === 'android') {
117
+ if (this.subscription) {
118
+ LocationModule.removeLocationListener(this.subscription);
119
+ }
120
+ }
121
+
122
+ // code for ios
123
+ if (Platform.OS === 'ios') {
124
+ if (this.subscription) {
125
+ LocationModule.removeLocationListener(this.subscription);
126
+ }
127
+ }
128
+ } catch (error: any) { }
77
129
  }
78
130
  }
79
131
 
@@ -0,0 +1,52 @@
1
+ import { NativeModules, NativeEventEmitter, EmitterSubscription } from 'react-native';
2
+
3
+ const { LocationModule } = NativeModules;
4
+ const locationEventEmitter = new NativeEventEmitter(LocationModule);
5
+
6
+ const startLocationUpdates = async (): Promise<void> => {
7
+ try {
8
+ await LocationModule.startLocationUpdates();
9
+ } catch (error) {
10
+ console.error(error);
11
+ }
12
+ };
13
+
14
+ const stopLocationUpdates = async (): Promise<void> => {
15
+ try {
16
+ await LocationModule.stopLocationUpdates();
17
+ } catch (error) {
18
+ console.error(error);
19
+ }
20
+ };
21
+
22
+ const getLastLocation = async (): Promise<any> => {
23
+ try {
24
+ return LocationModule.getLastLocation();
25
+ } catch (error) {
26
+ console.error(error);
27
+ return null
28
+ }
29
+ }
30
+
31
+
32
+ export interface LocationType {
33
+ latitude: number;
34
+ longitude: number;
35
+ accuracy: number;
36
+ }
37
+
38
+ const addLocationListener = (callback: (location: LocationType) => void): EmitterSubscription => {
39
+ return locationEventEmitter.addListener('locationUpdated', callback);
40
+ };
41
+
42
+ const removeLocationListener = (subscription: EmitterSubscription): void => {
43
+ subscription.remove();
44
+ };
45
+
46
+ export default {
47
+ startLocationUpdates,
48
+ stopLocationUpdates,
49
+ addLocationListener,
50
+ removeLocationListener,
51
+ getLastLocation,
52
+ };
@@ -0,0 +1,21 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ const { PermissionsModule } = NativeModules;
4
+
5
+ interface PermissionsModuleType {
6
+ requestForegroundPermissions: () => Promise<boolean>;
7
+ requestBackgroundPermissions: () => Promise<boolean>;
8
+ }
9
+
10
+ const requestForegroundPermissions = async (): Promise<boolean> => {
11
+ return PermissionsModule.requestForegroundPermissions();
12
+ };
13
+
14
+ const requestBackgroundPermissions = async (): Promise<boolean> => {
15
+ return PermissionsModule.requestBackgroundPermissions();
16
+ };
17
+
18
+ export default {
19
+ requestForegroundPermissions,
20
+ requestBackgroundPermissions,
21
+ } as PermissionsModuleType;
@@ -19,7 +19,7 @@ export async function getBaseETResponse(
19
19
  mergedObjectiveIds: Array<string>,
20
20
  taskId: ExecutionTaskID
21
21
  ): Promise<BaseETResponse> {
22
- let lastLocation = LocationManager.getInstance().getLastLocation();
22
+ let lastLocation = await LocationManager.getInstance().getLastLocation();
23
23
  console.log("getBaseETResponse:lastLocation:",JSON.stringify(lastLocation))
24
24
 
25
25
  let cache = DispatchSdkCache.getInstance();
@@ -146,12 +146,12 @@ export function onTaskStart(
146
146
  const keys = DispatchSdkCache.KEYS;
147
147
  const cache = DispatchSdkCache.getInstance();
148
148
  (async () => {
149
- let lastLocation = LocationManager.getInstance().getLastLocation();
149
+ let lastLocation = await LocationManager.getInstance().getLastLocation();
150
+ console.log("onTaskStart:lastLocation:",JSON.stringify(lastLocation));
150
151
  let location = {
151
152
  latitude: lastLocation.latitude,
152
153
  longitude: lastLocation.longitude,
153
154
  }
154
- console.log("onTaskStart:lastLocation:",location)
155
155
  await cache.setKeyInCache(keys.TASK_START_TIME, Date.now().toString());
156
156
  await cache.setKeyInCache(keys.CURRENT_WORKING_TASK_ID, eventData.taskId);
157
157
  await cache.setObjectInCache(keys.TASK_START_LOCATION, location);
@@ -7,6 +7,7 @@ import * as Location from 'expo-location';
7
7
  import NetworkUtil from './NetworkUtil';
8
8
  import { BaseError } from '../errors/BaseError';
9
9
  import ErrorCodes from '../errors/ErrorCodes';
10
+ import PermissionModule from '../native/PermissionModule';
10
11
 
11
12
  const { DispatchSdkUtils } = NativeModules;
12
13
 
@@ -129,8 +130,16 @@ export default class SdkUtils {
129
130
  }
130
131
 
131
132
  public static async checkMandatory() {
132
- if (Platform.OS === 'ios') return;
133
- // if (Platform.OS === 'ios') return true;
133
+ if (Platform.OS === 'ios'){
134
+ const foregroundLocation = await PermissionModule.requestForegroundPermissions();
135
+ if (!(foregroundLocation)) {
136
+ throw new BaseError(
137
+ ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,
138
+ 'Location or GPS not enabled'
139
+ );
140
+ }
141
+ return;
142
+ }
134
143
  const dateTimeCheck = await (
135
144
  DispatchSdkUtils as DispatchUtilsInterface
136
145
  ).isAutomaticDateTimeEnabled();
@@ -143,9 +152,10 @@ export default class SdkUtils {
143
152
  if (Platform.OS === 'android') {
144
153
  await Location.enableNetworkProviderAsync();
145
154
  let locationServicesCheck = await Location.hasServicesEnabledAsync();
146
- const foregroundLocation =
147
- await Location.requestForegroundPermissionsAsync();
148
- const bgLocation = await Location.requestBackgroundPermissionsAsync();
155
+ const foregroundLocation = await PermissionModule.requestForegroundPermissions();
156
+ // await Location.requestForegroundPermissionsAsync(); //permission code using expo module
157
+ const bgLocation = await PermissionModule.requestBackgroundPermissions();
158
+ // await Location.requestBackgroundPermissionsAsync(); //permission code using expo module
149
159
  if (!(locationServicesCheck && foregroundLocation && bgLocation)) {
150
160
  throw new BaseError(
151
161
  ErrorCodes.LOCATION_OR_GPS_NOT_ENABLED,
File without changes