-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: android initialization also working
Signed-off-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
4df861e
commit c8b8d56
Showing
7 changed files
with
92 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 28 additions & 6 deletions
34
android/src/main/java/id/animo/ausweissdk/AusweisSdkModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,44 @@ | ||
package id.animo.ausweissdk | ||
|
||
import expo.modules.kotlin.functions.Coroutine | ||
import expo.modules.kotlin.modules.Module | ||
import expo.modules.kotlin.modules.ModuleDefinition | ||
import android.util.Log | ||
|
||
class AusweisSdkModule : Module() { | ||
private var connectionHandler = AusweisSdkConnectionHandler.instance.apply { | ||
this.registerCallback { receivedValue: String? -> | ||
Log.i("AusweisSdk", "Received message $receivedValue") | ||
|
||
sendEvent("onMessage", mapOf( | ||
"value" to receivedValue | ||
)) | ||
} | ||
} | ||
|
||
override fun definition() = ModuleDefinition { | ||
Name("AusweisSdk") | ||
Events("onMessage") | ||
|
||
Function("sendCommand") { command: String -> | ||
|
||
if (!connectionHandler.isInitialized) { | ||
throw IllegalStateException("SDK not initialized. Call initialize before sending commands") | ||
} | ||
|
||
connectionHandler.sendCommand(command) | ||
} | ||
|
||
AsyncFunction("initialize") { value: String -> | ||
// Send an event to JavaScript. | ||
sendEvent("onChange", mapOf( | ||
"value" to value | ||
)) | ||
AsyncFunction("initialize") Coroutine { -> | ||
val context = appContext.reactContext?.applicationContext | ||
?: throw IllegalStateException("React application context is not available") | ||
|
||
if (connectionHandler.isInitialized) { | ||
return@Coroutine | ||
} | ||
|
||
Log.i("AusweisSdk", "Binding Service") | ||
connectionHandler.bindService(context) | ||
return@Coroutine | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters