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

Update iOS and Android agents to 2.7.0, add sealedResults support #80

Merged
merged 10 commits into from
Dec 3, 2024
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.fingerprint.android:pro:[2.6.0, 3.0.0)"
implementation "com.fingerprint.android:pro:[2.7.0, 3.0.0)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.fingerprintjs.android.fpjs_pro.UnsupportedVersion
import com.fingerprintjs.android.fpjs_pro.InstallationMethodRestricted
import com.fingerprintjs.android.fpjs_pro.ResponseCannotBeParsed
import com.fingerprintjs.android.fpjs_pro.NetworkError
import com.fingerprintjs.android.fpjs_pro.ClientTimeout
import com.fingerprintjs.android.fpjs_pro.UnknownError

import io.flutter.embedding.engine.plugins.FlutterPlugin
Expand Down Expand Up @@ -70,7 +71,8 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
GET_VISITOR_ID -> {
val tags = call.argument<Map<String, Any>>("tags") ?: emptyMap()
val linkedId = call.argument<String>("linkedId") ?: ""
getVisitorId(linkedId, tags, { visitorId ->
val timeoutMillis = call.argument<Int>("timeoutMs")
getVisitorId(timeoutMillis, linkedId, tags, { visitorId ->
result.success(visitorId)
}, { errorCode, errorMessage ->
result.error(errorCode, errorMessage, null)
Expand All @@ -79,7 +81,8 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
GET_VISITOR_DATA -> {
val tags = call.argument<Map<String, Any>>("tags") ?: emptyMap()
val linkedId = call.argument<String>("linkedId") ?: ""
getVisitorData(linkedId, tags, { getVisitorData ->
val timeoutMillis = call.argument<Int>("timeoutMs")
getVisitorData(timeoutMillis, linkedId, tags, { getVisitorData ->
result.success(getVisitorData)
}, { errorCode, errorMessage ->
result.error(errorCode, errorMessage, null)
Expand Down Expand Up @@ -110,31 +113,53 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
}

private fun getVisitorId(
timeoutMillis: Int?,
linkedId: String,
tags: Map<String, Any>,
listener: (String) -> Unit,
errorListener: (String, String) -> (Unit)
) {
fpjsClient.getVisitorId(
tags,
linkedId,
listener = {result -> listener(result.visitorId)},
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString())}
)
if (timeoutMillis != null) {
fpjsClient.getVisitorId(
timeoutMillis,
tags,
linkedId,
listener = { result -> listener(result.visitorId) },
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString()) }
)
} else {
fpjsClient.getVisitorId(
tags,
linkedId,
listener = { result -> listener(result.visitorId) },
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString()) }
)
}
}

private fun getVisitorData(
timeoutMillis: Int?,
linkedId: String,
tags: Map<String, Any>,
listener: (List<Any>) -> Unit,
errorListener: (String, String) -> (Unit)
) {
fpjsClient.getVisitorId(
tags,
linkedId,
listener = {result -> listener(listOf(result.requestId, result.confidenceScore.score, result.asJson))},
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString())}
)
if (timeoutMillis != null) {
fpjsClient.getVisitorId(
timeoutMillis,
tags,
linkedId,
listener = {result -> listener(listOf(result.requestId, result.confidenceScore.score, result.asJson, result.sealedResult ?: ""))},
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString())}
)
} else {
fpjsClient.getVisitorId(
tags,
linkedId,
listener = {result -> listener(listOf(result.requestId, result.confidenceScore.score, result.asJson, result.sealedResult ?: ""))},
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString())}
)
}
}
}

Expand Down Expand Up @@ -170,6 +195,7 @@ private fun getErrorCode(error: Error): String {
is InstallationMethodRestricted -> "InstallationMethodRestricted"
is ResponseCannotBeParsed -> "ResponseCannotBeParsed"
is NetworkError -> "NetworkError"
is ClientTimeout -> "ClientTimeout"
else -> "UnknownError"
}
return errorType
Expand Down
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
PODS:
- FingerprintPro (2.6.0)
- FingerprintPro (2.7.0)
- Flutter (1.0.0)
- fpjs_pro_plugin (3.0.1):
- FingerprintPro (~> 2.6.0)
- fpjs_pro_plugin (3.2.0):
- FingerprintPro (< 3.0.0, >= 2.7.0)
- Flutter

DEPENDENCIES:
Expand All @@ -20,9 +20,9 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/fpjs_pro_plugin/ios"

SPEC CHECKSUMS:
FingerprintPro: 3f06f491c77d871ab543b49fd25fddc52dc34f8c
FingerprintPro: 0c7dbd28fc83751ca64b06328e2fb22bbc7ed118
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
fpjs_pro_plugin: 83f30abadcd58450a80c6ef5837f5e914d7ce238
fpjs_pro_plugin: dd3cab1b0690f7504ee74f6707215c54d030d980

PODFILE CHECKSUM: 2f1a6d2470f392e010cfe7ae5f9f694d8487db82

Expand Down
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import UIKit
import Flutter

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
25 changes: 24 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ class _MyAppState extends State<MyApp> {
const encoder = JsonEncoder.withIndent(' ');
final deviceData = await FpjsProPlugin.getVisitorData(
tags: tags, linkedId: 'some linkedId');
identificationInfo = encoder.convert(deviceData);
final jsonDeviceData = deviceData.toJson();
if (deviceData.sealedResult != null &&
deviceData.sealedResult!.isNotEmpty) {
jsonDeviceData["sealedResult"] = deviceData.sealedResult
?.replaceRange(10, deviceData.sealedResult?.length, '...');
}
identificationInfo = encoder.convert(jsonDeviceData);
} on FingerprintProError catch (error) {
identificationInfo = "Failed to get device info.\n$error";
}
Expand All @@ -130,6 +136,13 @@ class _MyAppState extends State<MyApp> {
FpjsProPlugin.getVisitorId(linkedId: 'checkIdWithTag', tags: tags),
() async => FpjsProPlugin.getVisitorData(
linkedId: 'checkDataWithTag', tags: tags),
() async => FpjsProPlugin.getVisitorId(timeoutMs: 5000),
() async => FpjsProPlugin.getVisitorData(timeoutMs: 5000),
];

var timeoutChecks = [
() async => FpjsProPlugin.getVisitorId(timeoutMs: 5),
() async => FpjsProPlugin.getVisitorData(timeoutMs: 5)
];

for (var check in checks) {
Expand All @@ -138,6 +151,16 @@ class _MyAppState extends State<MyApp> {
_checksResult += '.';
});
}
for (var check in timeoutChecks) {
try {
await check();
throw Exception('Expected timeout error');
} on FingerprintProError {
setState(() {
_checksResult += '!';
});
}
}
setState(() {
_checksResult = 'Success!';
});
Expand Down
14 changes: 7 additions & 7 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ packages:
dependency: "direct main"
description:
name: cupertino_icons
sha256: "1989d917fbe8e6b39806207df5a3fdd3d816cbd090fac2ce26fb45e9a71476e5"
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
url: "https://pub.dev"
source: hosted
version: "1.0.4"
version: "1.0.8"
env_flutter:
dependency: "direct main"
description:
Expand All @@ -74,10 +74,10 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: b543301ad291598523947dc534aaddc5aaad597b709d2426d3a0e0d44c5cb493
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
version: "5.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -131,10 +131,10 @@ packages:
dependency: transitive
description:
name: lints
sha256: a2c3d198cb5ea2e179926622d433331d8b58374ab8f29cdda6e863bd62fd369c
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
url: "https://pub.dev"
source: hosted
version: "1.0.1"
version: "5.0.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -237,5 +237,5 @@ packages:
source: hosted
version: "14.2.5"
sdks:
dart: ">=3.3.0 <4.0.0"
dart: ">=3.5.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ environment:
dependencies:
flutter:
sdk: flutter
env_flutter: ^0.1.3
env_flutter: ^0.1.4

fpjs_pro_plugin:
# When depending on this package from a real application you should use:
Expand All @@ -29,7 +29,7 @@ dependencies:

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
cupertino_icons: ^1.0.8

dev_dependencies:
flutter_test:
Expand All @@ -40,7 +40,7 @@ dev_dependencies:
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^1.0.0
flutter_lints: ^5.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
66 changes: 1 addition & 65 deletions example/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,72 +34,8 @@
<script src="assets/packages/fpjs_pro_plugin/web/index.js" defer></script>
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
var serviceWorkerVersion = null;
var scriptLoaded = false;
function loadMainDartJs() {
if (scriptLoaded) {
return;
}
scriptLoaded = true;
var scriptTag = document.createElement('script');
scriptTag.src = 'main.dart.js';
scriptTag.type = 'application/javascript';
document.body.append(scriptTag);
}

if ('serviceWorker' in navigator) {
// Service workers are supported. Use them.
window.addEventListener('load', function () {
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => {
function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => {
if (serviceWorker.state == 'activated') {
console.log('Installed new service worker.');
loadMainDartJs();
}
});
}
if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing || reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update.
console.log('New service worker available.');
reg.update();
waitForActivation(reg.installing);
} else {
// Existing service worker is still good.
console.log('Loading app from service worker.');
loadMainDartJs();
}
});

// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
});
} else {
// Service workers not supported. Just drop the <script> tag.
loadMainDartJs();
}
{{flutter_bootstrap_js}}
</script>
</body>
</html>
2 changes: 2 additions & 0 deletions ios/Classes/FPJSError+Flutter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ extension FPJSError {
return ("JsonParsingError", jsonParsingError.localizedDescription)
case .invalidResponseType:
return ("InvalidResponseType", description)
case .clientTimeout:
return ("ClientTimeout", description)
case .unknownError:
fallthrough
@unknown default:
Expand Down
Loading
Loading