Skip to content

Commit cf511b9

Browse files
authored
Merge pull request #80 from fingerprintjs/update-agents-INTER-992
Update iOS and Android agents to 2.7.0, add sealedResults support
2 parents ecd97bf + 4bc4cc1 commit cf511b9

22 files changed

+254
-162
lines changed

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ android {
5353

5454
dependencies {
5555
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
56-
implementation "com.fingerprint.android:pro:[2.6.0, 3.0.0)"
56+
implementation "com.fingerprint.android:pro:[2.7.0, 3.0.0)"
5757
}

android/src/main/kotlin/com/fingerprintjs/flutter/fpjs_pro/fpjs_pro_plugin/FpjsProPlugin.kt

+40-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.fingerprintjs.android.fpjs_pro.UnsupportedVersion
2424
import com.fingerprintjs.android.fpjs_pro.InstallationMethodRestricted
2525
import com.fingerprintjs.android.fpjs_pro.ResponseCannotBeParsed
2626
import com.fingerprintjs.android.fpjs_pro.NetworkError
27+
import com.fingerprintjs.android.fpjs_pro.ClientTimeout
2728
import com.fingerprintjs.android.fpjs_pro.UnknownError
2829

2930
import io.flutter.embedding.engine.plugins.FlutterPlugin
@@ -70,7 +71,8 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
7071
GET_VISITOR_ID -> {
7172
val tags = call.argument<Map<String, Any>>("tags") ?: emptyMap()
7273
val linkedId = call.argument<String>("linkedId") ?: ""
73-
getVisitorId(linkedId, tags, { visitorId ->
74+
val timeoutMillis = call.argument<Int>("timeoutMs")
75+
getVisitorId(timeoutMillis, linkedId, tags, { visitorId ->
7476
result.success(visitorId)
7577
}, { errorCode, errorMessage ->
7678
result.error(errorCode, errorMessage, null)
@@ -79,7 +81,8 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
7981
GET_VISITOR_DATA -> {
8082
val tags = call.argument<Map<String, Any>>("tags") ?: emptyMap()
8183
val linkedId = call.argument<String>("linkedId") ?: ""
82-
getVisitorData(linkedId, tags, { getVisitorData ->
84+
val timeoutMillis = call.argument<Int>("timeoutMs")
85+
getVisitorData(timeoutMillis, linkedId, tags, { getVisitorData ->
8386
result.success(getVisitorData)
8487
}, { errorCode, errorMessage ->
8588
result.error(errorCode, errorMessage, null)
@@ -110,31 +113,53 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
110113
}
111114

112115
private fun getVisitorId(
116+
timeoutMillis: Int?,
113117
linkedId: String,
114118
tags: Map<String, Any>,
115119
listener: (String) -> Unit,
116120
errorListener: (String, String) -> (Unit)
117121
) {
118-
fpjsClient.getVisitorId(
119-
tags,
120-
linkedId,
121-
listener = {result -> listener(result.visitorId)},
122-
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString())}
123-
)
122+
if (timeoutMillis != null) {
123+
fpjsClient.getVisitorId(
124+
timeoutMillis,
125+
tags,
126+
linkedId,
127+
listener = { result -> listener(result.visitorId) },
128+
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString()) }
129+
)
130+
} else {
131+
fpjsClient.getVisitorId(
132+
tags,
133+
linkedId,
134+
listener = { result -> listener(result.visitorId) },
135+
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString()) }
136+
)
137+
}
124138
}
125139

126140
private fun getVisitorData(
141+
timeoutMillis: Int?,
127142
linkedId: String,
128143
tags: Map<String, Any>,
129144
listener: (List<Any>) -> Unit,
130145
errorListener: (String, String) -> (Unit)
131146
) {
132-
fpjsClient.getVisitorId(
133-
tags,
134-
linkedId,
135-
listener = {result -> listener(listOf(result.requestId, result.confidenceScore.score, result.asJson))},
136-
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString())}
137-
)
147+
if (timeoutMillis != null) {
148+
fpjsClient.getVisitorId(
149+
timeoutMillis,
150+
tags,
151+
linkedId,
152+
listener = {result -> listener(listOf(result.requestId, result.confidenceScore.score, result.asJson, result.sealedResult ?: ""))},
153+
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString())}
154+
)
155+
} else {
156+
fpjsClient.getVisitorId(
157+
tags,
158+
linkedId,
159+
listener = {result -> listener(listOf(result.requestId, result.confidenceScore.score, result.asJson, result.sealedResult ?: ""))},
160+
errorListener = { error -> errorListener(getErrorCode(error), error.description.toString())}
161+
)
162+
}
138163
}
139164
}
140165

@@ -170,6 +195,7 @@ private fun getErrorCode(error: Error): String {
170195
is InstallationMethodRestricted -> "InstallationMethodRestricted"
171196
is ResponseCannotBeParsed -> "ResponseCannotBeParsed"
172197
is NetworkError -> "NetworkError"
198+
is ClientTimeout -> "ClientTimeout"
173199
else -> "UnknownError"
174200
}
175201
return errorType

example/ios/Podfile.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
PODS:
2-
- FingerprintPro (2.6.0)
2+
- FingerprintPro (2.7.0)
33
- Flutter (1.0.0)
4-
- fpjs_pro_plugin (3.0.1):
5-
- FingerprintPro (~> 2.6.0)
4+
- fpjs_pro_plugin (3.2.0):
5+
- FingerprintPro (< 3.0.0, >= 2.7.0)
66
- Flutter
77

88
DEPENDENCIES:
@@ -20,9 +20,9 @@ EXTERNAL SOURCES:
2020
:path: ".symlinks/plugins/fpjs_pro_plugin/ios"
2121

2222
SPEC CHECKSUMS:
23-
FingerprintPro: 3f06f491c77d871ab543b49fd25fddc52dc34f8c
23+
FingerprintPro: 0c7dbd28fc83751ca64b06328e2fb22bbc7ed118
2424
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
25-
fpjs_pro_plugin: 83f30abadcd58450a80c6ef5837f5e914d7ce238
25+
fpjs_pro_plugin: dd3cab1b0690f7504ee74f6707215c54d030d980
2626

2727
PODFILE CHECKSUM: 2f1a6d2470f392e010cfe7ae5f9f694d8487db82
2828

example/ios/Runner/AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22
import Flutter
33

4-
@UIApplicationMain
4+
@main
55
@objc class AppDelegate: FlutterAppDelegate {
66
override func application(
77
_ application: UIApplication,

example/lib/main.dart

+24-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ class _MyAppState extends State<MyApp> {
107107
const encoder = JsonEncoder.withIndent(' ');
108108
final deviceData = await FpjsProPlugin.getVisitorData(
109109
tags: tags, linkedId: 'some linkedId');
110-
identificationInfo = encoder.convert(deviceData);
110+
final jsonDeviceData = deviceData.toJson();
111+
if (deviceData.sealedResult != null &&
112+
deviceData.sealedResult!.isNotEmpty) {
113+
jsonDeviceData["sealedResult"] = deviceData.sealedResult
114+
?.replaceRange(10, deviceData.sealedResult?.length, '...');
115+
}
116+
identificationInfo = encoder.convert(jsonDeviceData);
111117
} on FingerprintProError catch (error) {
112118
identificationInfo = "Failed to get device info.\n$error";
113119
}
@@ -130,6 +136,13 @@ class _MyAppState extends State<MyApp> {
130136
FpjsProPlugin.getVisitorId(linkedId: 'checkIdWithTag', tags: tags),
131137
() async => FpjsProPlugin.getVisitorData(
132138
linkedId: 'checkDataWithTag', tags: tags),
139+
() async => FpjsProPlugin.getVisitorId(timeoutMs: 5000),
140+
() async => FpjsProPlugin.getVisitorData(timeoutMs: 5000),
141+
];
142+
143+
var timeoutChecks = [
144+
() async => FpjsProPlugin.getVisitorId(timeoutMs: 5),
145+
() async => FpjsProPlugin.getVisitorData(timeoutMs: 5)
133146
];
134147

135148
for (var check in checks) {
@@ -138,6 +151,16 @@ class _MyAppState extends State<MyApp> {
138151
_checksResult += '.';
139152
});
140153
}
154+
for (var check in timeoutChecks) {
155+
try {
156+
await check();
157+
throw Exception('Expected timeout error');
158+
} on FingerprintProError {
159+
setState(() {
160+
_checksResult += '!';
161+
});
162+
}
163+
}
141164
setState(() {
142165
_checksResult = 'Success!';
143166
});

example/pubspec.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ packages:
4545
dependency: "direct main"
4646
description:
4747
name: cupertino_icons
48-
sha256: "1989d917fbe8e6b39806207df5a3fdd3d816cbd090fac2ce26fb45e9a71476e5"
48+
sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6
4949
url: "https://pub.dev"
5050
source: hosted
51-
version: "1.0.4"
51+
version: "1.0.8"
5252
env_flutter:
5353
dependency: "direct main"
5454
description:
@@ -74,10 +74,10 @@ packages:
7474
dependency: "direct dev"
7575
description:
7676
name: flutter_lints
77-
sha256: b543301ad291598523947dc534aaddc5aaad597b709d2426d3a0e0d44c5cb493
77+
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
7878
url: "https://pub.dev"
7979
source: hosted
80-
version: "1.0.4"
80+
version: "5.0.0"
8181
flutter_test:
8282
dependency: "direct dev"
8383
description: flutter
@@ -131,10 +131,10 @@ packages:
131131
dependency: transitive
132132
description:
133133
name: lints
134-
sha256: a2c3d198cb5ea2e179926622d433331d8b58374ab8f29cdda6e863bd62fd369c
134+
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
135135
url: "https://pub.dev"
136136
source: hosted
137-
version: "1.0.1"
137+
version: "5.0.0"
138138
matcher:
139139
dependency: transitive
140140
description:
@@ -237,5 +237,5 @@ packages:
237237
source: hosted
238238
version: "14.2.5"
239239
sdks:
240-
dart: ">=3.3.0 <4.0.0"
240+
dart: ">=3.5.0 <4.0.0"
241241
flutter: ">=3.18.0-18.0.pre.54"

example/pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ environment:
1717
dependencies:
1818
flutter:
1919
sdk: flutter
20-
env_flutter: ^0.1.3
20+
env_flutter: ^0.1.4
2121

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

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

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

4545
# For information on the generic Dart part of this file, see the
4646
# following page: https://dart.dev/tools/pub/pubspec

example/web/index.html

+1-65
Original file line numberDiff line numberDiff line change
@@ -34,72 +34,8 @@
3434
<script src="assets/packages/fpjs_pro_plugin/web/index.js" defer></script>
3535
</head>
3636
<body>
37-
<!-- This script installs service_worker.js to provide PWA functionality to
38-
application. For more information, see:
39-
https://developers.google.com/web/fundamentals/primers/service-workers -->
4037
<script>
41-
var serviceWorkerVersion = null;
42-
var scriptLoaded = false;
43-
function loadMainDartJs() {
44-
if (scriptLoaded) {
45-
return;
46-
}
47-
scriptLoaded = true;
48-
var scriptTag = document.createElement('script');
49-
scriptTag.src = 'main.dart.js';
50-
scriptTag.type = 'application/javascript';
51-
document.body.append(scriptTag);
52-
}
53-
54-
if ('serviceWorker' in navigator) {
55-
// Service workers are supported. Use them.
56-
window.addEventListener('load', function () {
57-
// Wait for registration to finish before dropping the <script> tag.
58-
// Otherwise, the browser will load the script multiple times,
59-
// potentially different versions.
60-
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
61-
navigator.serviceWorker.register(serviceWorkerUrl)
62-
.then((reg) => {
63-
function waitForActivation(serviceWorker) {
64-
serviceWorker.addEventListener('statechange', () => {
65-
if (serviceWorker.state == 'activated') {
66-
console.log('Installed new service worker.');
67-
loadMainDartJs();
68-
}
69-
});
70-
}
71-
if (!reg.active && (reg.installing || reg.waiting)) {
72-
// No active web worker and we have installed or are installing
73-
// one for the first time. Simply wait for it to activate.
74-
waitForActivation(reg.installing || reg.waiting);
75-
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
76-
// When the app updates the serviceWorkerVersion changes, so we
77-
// need to ask the service worker to update.
78-
console.log('New service worker available.');
79-
reg.update();
80-
waitForActivation(reg.installing);
81-
} else {
82-
// Existing service worker is still good.
83-
console.log('Loading app from service worker.');
84-
loadMainDartJs();
85-
}
86-
});
87-
88-
// If service worker doesn't succeed in a reasonable amount of time,
89-
// fallback to plaint <script> tag.
90-
setTimeout(() => {
91-
if (!scriptLoaded) {
92-
console.warn(
93-
'Failed to load app from service worker. Falling back to plain <script> tag.',
94-
);
95-
loadMainDartJs();
96-
}
97-
}, 4000);
98-
});
99-
} else {
100-
// Service workers not supported. Just drop the <script> tag.
101-
loadMainDartJs();
102-
}
38+
{{flutter_bootstrap_js}}
10339
</script>
10440
</body>
10541
</html>

ios/Classes/FPJSError+Flutter.swift

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ extension FPJSError {
1919
return ("JsonParsingError", jsonParsingError.localizedDescription)
2020
case .invalidResponseType:
2121
return ("InvalidResponseType", description)
22+
case .clientTimeout:
23+
return ("ClientTimeout", description)
2224
case .unknownError:
2325
fallthrough
2426
@unknown default:

0 commit comments

Comments
 (0)