@@ -13,15 +13,18 @@ import kotlinx.coroutines.withContext
1313
1414class MainActivity : FlutterActivity () {
1515 private val CHANNEL = " plgd.dev/client"
16- private var sdkClient: ocfclient .Ocfclient_ ? = null ;
16+ private var sdkClient: Ocfclient .Ocfclient_ ? = null ;
1717 private val _mainScope = CoroutineScope (Dispatchers .Main )
1818
1919 override fun configureFlutterEngine (@NonNull flutterEngine : FlutterEngine ) {
2020 GeneratedPluginRegistrant .registerWith(flutterEngine)
2121 MethodChannel (flutterEngine.dartExecutor.binaryMessenger, CHANNEL ).setMethodCallHandler { call, result ->
2222 when (call.method) {
2323 " initialize" -> this .initializeOCFClient(call, result)
24+ " close" -> this .closeOCFClient(result)
25+ " getOwnerId" -> this .getOwnerId(result)
2426 " discoverDevices" -> this .discoverDevices(call, result)
27+ " getResource" -> this .getResource(call, result)
2528 " ownDevice" -> this .ownDevice(call, result)
2629 " setAccessForCloud" -> this .setAccessForCloud(call, result)
2730 " onboardDevice" -> this .onboardDevice(call, result)
@@ -34,11 +37,12 @@ class MainActivity: FlutterActivity() {
3437 private fun initializeOCFClient (call : MethodCall , result : MethodChannel .Result ) {
3538 var accessToken = call.argument<String >(" accessToken" );
3639 var cloudConfiguration = call.argument<String >(" cloudConfiguration" )
40+ var signingServerAddress = call.argument<String >(" signingServerAddress" )
3741 _mainScope .launch {
3842 try {
39- sdkClient = ocfclient .Ocfclient_ ()
43+ sdkClient = Ocfclient .Ocfclient_ ()
4044 withContext(Dispatchers .IO ) {
41- sdkClient!! .initialize(accessToken, cloudConfiguration)
45+ sdkClient!! .initialize(accessToken, cloudConfiguration, signingServerAddress )
4246 }
4347 result.success(true )
4448 } catch (e: Exception ) {
@@ -48,6 +52,32 @@ class MainActivity: FlutterActivity() {
4852 }
4953 }
5054
55+ private fun closeOCFClient (result : MethodChannel .Result ) {
56+ _mainScope .launch {
57+ try {
58+ withContext(Dispatchers .IO ) {
59+ sdkClient!! .close()
60+ }
61+ result.success(true )
62+ } catch (e: Exception ) {
63+ result.error(" -1" , e.message, " " )
64+ }
65+ }
66+ }
67+
68+ private fun getOwnerId (result : MethodChannel .Result ) {
69+ _mainScope .launch {
70+ try {
71+ var ownerId = withContext(Dispatchers .IO ) {
72+ sdkClient!! .getOwnerID()
73+ }
74+ result.success(ownerId)
75+ } catch (e: Exception ) {
76+ result.error(" -1" , e.message, " " )
77+ }
78+ }
79+ }
80+
5181 private fun discoverDevices (call : MethodCall , result : MethodChannel .Result ) {
5282 var discoveryTimeout = call.arguments<Int >()
5383 _mainScope .launch {
@@ -62,6 +92,21 @@ class MainActivity: FlutterActivity() {
6292 }
6393 }
6494
95+ private fun getResource (call : MethodCall , result : MethodChannel .Result ) {
96+ var deviceId = call.argument<String >(" deviceID" )
97+ var href = call.argument<String >(" href" )
98+ _mainScope .launch {
99+ try {
100+ var resourceContent = withContext(Dispatchers .IO ) {
101+ sdkClient!! .getResource(deviceId, href)
102+ }
103+ result.success(resourceContent)
104+ } catch (e: Exception ) {
105+ result.error(" -1" , e.message, " " )
106+ }
107+ }
108+ }
109+
65110 private fun ownDevice (call : MethodCall , result : MethodChannel .Result ) {
66111 var deviceId = call.argument<String >(" deviceID" )
67112 var accessToken = call.argument<String >(" accessToken" )
@@ -94,10 +139,12 @@ class MainActivity: FlutterActivity() {
94139 private fun onboardDevice (call : MethodCall , result : MethodChannel .Result ) {
95140 var deviceId = call.argument<String >(" deviceID" )
96141 var authCode = call.argument<String >(" authCode" )
142+ var authorizationProvider = call.argument<String >(" authorizationProvider" )
143+
97144 _mainScope .launch {
98145 try {
99146 withContext(Dispatchers .IO ) {
100- sdkClient!! .onboardDevice(deviceId, authCode)
147+ sdkClient!! .onboardDevice(deviceId, authCode, authorizationProvider )
101148 }
102149 result.success(true )
103150 } catch (e: Exception ) {
0 commit comments