capacitor-didit-plugin 0.1.0 → 0.1.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.
@@ -6,12 +6,21 @@ import com.getcapacitor.Plugin
6
6
  import com.getcapacitor.PluginCall
7
7
  import com.getcapacitor.PluginMethod
8
8
  import com.getcapacitor.annotation.CapacitorPlugin
9
+ import kotlinx.coroutines.CoroutineScope
10
+ import kotlinx.coroutines.Dispatchers
11
+ import kotlinx.coroutines.Job
12
+ import kotlinx.coroutines.SupervisorJob
13
+ import kotlinx.coroutines.launch
9
14
  import me.didit.sdk.DiditSdk
15
+ import me.didit.sdk.DiditSdkState
10
16
  import me.didit.sdk.VerificationResult
11
17
 
12
18
  @CapacitorPlugin(name = "DiditVerification")
13
19
  class DiditVerificationPlugin : Plugin() {
14
20
 
21
+ private val mainScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
22
+ private var stateJob: Job? = null
23
+
15
24
  @Volatile
16
25
  private var activeCallbackId: String? = null
17
26
 
@@ -20,6 +29,7 @@ class DiditVerificationPlugin : Plugin() {
20
29
  }
21
30
 
22
31
  override fun handleOnDestroy() {
32
+ stateJob?.cancel()
23
33
  activeCallbackId = null
24
34
  }
25
35
 
@@ -49,6 +59,8 @@ class DiditVerificationPlugin : Plugin() {
49
59
 
50
60
  currentActivity.runOnUiThread {
51
61
  DiditSdk.startVerification(token = sessionToken) { result ->
62
+ stateJob?.cancel()
63
+
52
64
  // Clear the busy flag before the null-guard: a WebView reload
53
65
  // resets the bridge and drops saved calls, and the guard must
54
66
  // not leave the plugin permanently locked in that case.
@@ -75,6 +87,43 @@ class DiditVerificationPlugin : Plugin() {
75
87
  }
76
88
  }
77
89
  }
90
+
91
+ // startVerification only prepares the session — unlike iOS, the
92
+ // Android SDK never shows its UI on its own. Watch the state flow
93
+ // and launch the UI once the session is ready.
94
+ var launched = false
95
+ stateJob?.cancel()
96
+ stateJob = mainScope.launch {
97
+ DiditSdk.state.collect { state ->
98
+ when (state) {
99
+ is DiditSdkState.Ready -> {
100
+ if (!launched) {
101
+ launched = true
102
+ DiditSdk.launchVerificationUI(currentActivity)
103
+ }
104
+ }
105
+ is DiditSdkState.Error -> {
106
+ // Session preparation failed before the UI ever
107
+ // launched (bad token, network error) — the result
108
+ // callback won't fire, so settle the call here and
109
+ // stop watching, otherwise a later Ready emission
110
+ // could open the UI with no active call.
111
+ if (!launched) {
112
+ activeCallbackId = null
113
+ val savedCall = bridge.getSavedCall(call.callbackId)
114
+ if (savedCall != null) {
115
+ bridge.releaseCall(savedCall)
116
+ savedCall.reject(state.message, "FAILED")
117
+ }
118
+ stateJob?.cancel()
119
+ }
120
+ }
121
+ else -> {
122
+ // Idle / CreatingSession / Loading — keep waiting
123
+ }
124
+ }
125
+ }
126
+ }
78
127
  }
79
128
  }
80
129
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-didit-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Capacitor plugin wrapping the native Didit identity verification (KYC) SDKs for iOS and Android",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",