Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hyper-track): add interfaces to access new cordova plugin APIs #3698

Merged
merged 2 commits into from Aug 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 55 additions & 2 deletions src/@ionic-native/plugins/hyper-track/index.ts
Expand Up @@ -17,7 +17,7 @@ import { error } from 'console';
plugin: 'cordova-plugin-hypertrack-v3',
pluginRef: 'hypertrack',
repo: 'https://github.com/hypertrack/cordova-plugin-hypertrack.git',
platforms: ['Android'],
platforms: ['Android, iOS'],
})
@Injectable()
export class HyperTrackPlugin extends IonicNativePlugin {
Expand All @@ -26,6 +26,11 @@ export class HyperTrackPlugin extends IonicNativePlugin {
return;
}

@Cordova()
getBlockers(): Promise<Set<Blocker>> {
return;
}

@Cordova()
enableDebugLogging(): Promise<any> {
return;
Expand Down Expand Up @@ -59,10 +64,17 @@ interface HyperTrackCordova {
success: SuccessHandler,
error: FailureHandler
): void;
addGeoTag(geotagData: Object, expectedLocation: Coordinates, success: SuccessHandler, error: FailureHandler): void;
addGeoTag(
geotagData: Object,
expectedLocation: Coordinates | undefined,
success: SuccessHandler,
error: FailureHandler
): void;
requestPermissionsIfNecessary(success: SuccessHandler, error: FailureHandler): void;
allowMockLocations(success: SuccessHandler, error: FailureHandler): void;
syncDeviceSettings(success: SuccessHandler, error: FailureHandler): void;
start(success: SuccessHandler, error: FailureHandler): void;
stop(success: SuccessHandler, error: FailureHandler): void;
}

export class CoordinatesValidationError extends Error {}
Expand All @@ -76,6 +88,18 @@ export class Coordinates {
}
}

/** A blocker is an obstacle that needs to be resolved to achieve reliable tracking. */
export interface Blocker {
/** Recommended name for a user action, that needs to be performed to resolve the blocker. */
userActionTitle: String;
/** Recommended name for a button, that will navigate user to the place where he can resolve the blocker */
userActionCTA: String;
/** User action explanation */
userActionExplanation: String;
/** An action that navigates user to the dedicated settings menu. */
resolve: () => void;
}

/**
* @usage
* ```typescript
Expand Down Expand Up @@ -128,6 +152,15 @@ export class HyperTrack {
});
}

/**
* Get the list of blockers that needs to be resolved for reliable tracking.
*
* @see {Blocker}
*/
static getBlockers(): Promise<Set<Blocker>> {
return new HyperTrackPlugin().getBlockers();
}

/** Resolves device ID that could be used to identify the device. */
getDeviceId(): Promise<string> {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -230,5 +263,25 @@ export class HyperTrack {
});
}

/** Start tracking. */
start(): Promise<any> {
return new Promise((resolve, reject) => {
this.cordovaInstanceHandle.start(
() => resolve(),
err => reject(err)
);
});
}

/** Stop tracking. */
stop(): Promise<any> {
return new Promise((resolve, reject) => {
this.cordovaInstanceHandle.stop(
() => resolve(),
err => reject(err)
);
});
}

private constructor(private cordovaInstanceHandle: HyperTrackCordova) {}
}