@@ -24,6 +24,7 @@ import com.fingerprintjs.android.fpjs_pro.UnsupportedVersion
24
24
import com.fingerprintjs.android.fpjs_pro.InstallationMethodRestricted
25
25
import com.fingerprintjs.android.fpjs_pro.ResponseCannotBeParsed
26
26
import com.fingerprintjs.android.fpjs_pro.NetworkError
27
+ import com.fingerprintjs.android.fpjs_pro.ClientTimeout
27
28
import com.fingerprintjs.android.fpjs_pro.UnknownError
28
29
29
30
import io.flutter.embedding.engine.plugins.FlutterPlugin
@@ -70,7 +71,8 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
70
71
GET_VISITOR_ID -> {
71
72
val tags = call.argument<Map <String , Any >>(" tags" ) ? : emptyMap()
72
73
val linkedId = call.argument<String >(" linkedId" ) ? : " "
73
- getVisitorId(linkedId, tags, { visitorId ->
74
+ val timeoutMillis = call.argument<Int >(" timeoutMs" )
75
+ getVisitorId(timeoutMillis, linkedId, tags, { visitorId ->
74
76
result.success(visitorId)
75
77
}, { errorCode, errorMessage ->
76
78
result.error(errorCode, errorMessage, null )
@@ -79,7 +81,8 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
79
81
GET_VISITOR_DATA -> {
80
82
val tags = call.argument<Map <String , Any >>(" tags" ) ? : emptyMap()
81
83
val linkedId = call.argument<String >(" linkedId" ) ? : " "
82
- getVisitorData(linkedId, tags, { getVisitorData ->
84
+ val timeoutMillis = call.argument<Int >(" timeoutMs" )
85
+ getVisitorData(timeoutMillis, linkedId, tags, { getVisitorData ->
83
86
result.success(getVisitorData)
84
87
}, { errorCode, errorMessage ->
85
88
result.error(errorCode, errorMessage, null )
@@ -110,31 +113,53 @@ class FpjsProPlugin: FlutterPlugin, MethodCallHandler {
110
113
}
111
114
112
115
private fun getVisitorId (
116
+ timeoutMillis : Int? ,
113
117
linkedId : String ,
114
118
tags : Map <String , Any >,
115
119
listener : (String ) -> Unit ,
116
120
errorListener : (String , String ) -> (Unit )
117
121
) {
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
+ }
124
138
}
125
139
126
140
private fun getVisitorData (
141
+ timeoutMillis : Int? ,
127
142
linkedId : String ,
128
143
tags : Map <String , Any >,
129
144
listener : (List <Any >) -> Unit ,
130
145
errorListener : (String , String ) -> (Unit )
131
146
) {
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
+ }
138
163
}
139
164
}
140
165
@@ -170,6 +195,7 @@ private fun getErrorCode(error: Error): String {
170
195
is InstallationMethodRestricted -> " InstallationMethodRestricted"
171
196
is ResponseCannotBeParsed -> " ResponseCannotBeParsed"
172
197
is NetworkError -> " NetworkError"
198
+ is ClientTimeout -> " ClientTimeout"
173
199
else -> " UnknownError"
174
200
}
175
201
return errorType
0 commit comments