theta-client-react-native 1.0.0

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.
@@ -0,0 +1,774 @@
1
+ package com.ricoh360.thetaclientreactnative
2
+
3
+ import com.facebook.react.bridge.*
4
+ import com.facebook.react.modules.core.DeviceEventManagerModule
5
+ import com.ricoh360.thetaclient.ThetaRepository
6
+ import com.ricoh360.thetaclient.capture.PhotoCapture
7
+ import com.ricoh360.thetaclient.capture.VideoCapture
8
+ import com.ricoh360.thetaclient.capture.VideoCapturing
9
+ import io.ktor.utils.io.core.*
10
+ import kotlinx.coroutines.*
11
+ import java.io.ByteArrayOutputStream
12
+ import kotlin.coroutines.*
13
+ import java.util.*
14
+ import kotlin.text.String
15
+
16
+ class ThetaClientReactNativeModule(
17
+ reactContext: ReactApplicationContext
18
+ ) : ReactContextBaseJavaModule(reactContext), CoroutineScope {
19
+
20
+ override val coroutineContext: CoroutineContext = Job()
21
+
22
+ override fun getName(): String {
23
+ return NAME
24
+ }
25
+
26
+ var previewing: Boolean = false
27
+ var photoCaptureBuilder: PhotoCapture.Builder? = null
28
+ var photoCapture: PhotoCapture? = null
29
+ var videoCaptureBuilder: VideoCapture.Builder? = null
30
+ var videoCapture: VideoCapture? = null
31
+ var videoCapturing: VideoCapturing? = null
32
+ lateinit var theta: ThetaRepository
33
+ var listenerCount: Int = 0
34
+
35
+ /**
36
+ * add event listener for [eventName]
37
+ */
38
+ @ReactMethod
39
+ fun addListener(eventName: String) {
40
+ // Set up any upstream listeners or background tasks as necessary
41
+ if (eventName.equals(EVENT_NAME)) {
42
+ listenerCount++;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * remove event listener [count]
48
+ */
49
+ @ReactMethod
50
+ fun removeListeners(count: Int) {
51
+ // Remove upstream listeners, stop unnecessary background tasks
52
+ listenerCount -= count
53
+ }
54
+
55
+ /**
56
+ * retreive constant
57
+ */
58
+ override fun getConstants(): MutableMap<String, Any> =
59
+ hashMapOf("DEFAULT_EVENT_NAME" to EVENT_NAME)
60
+
61
+ /**
62
+ * initialize Theta repository with endpoint
63
+ * @param endpoint endpoint to connect THETA
64
+ * @param promise promise to set initialize result
65
+ */
66
+ @ReactMethod
67
+ fun initialize(endpoint: String, promise: Promise) {
68
+ launch {
69
+ try {
70
+ theta = ThetaRepository.newInstance(endpoint)
71
+ promise.resolve(true)
72
+ } catch (t: Throwable) {
73
+ promise.reject(t)
74
+ }
75
+ }
76
+ }
77
+
78
+ /**
79
+ * getThetaInfo - retrieve ThetaInfo from THETA via repository
80
+ * @param promise promise to set result
81
+ */
82
+ @ReactMethod
83
+ fun getThetaInfo(promise: Promise) {
84
+ launch {
85
+ try {
86
+ val info = theta.getThetaInfo()
87
+ val result = Arguments.createMap()
88
+ result.putString("model", info.model)
89
+ result.putString("serialNumber", info.serialNumber)
90
+ result.putString("firmwareVersion", info.firmwareVersion)
91
+ result.putBoolean("hasGps", info.hasGps)
92
+ result.putBoolean("hasGyro", info.hasGyro)
93
+ result.putInt("uptime", info.uptime)
94
+ promise.resolve(result)
95
+ } catch (t: Throwable) {
96
+ promise.reject(t)
97
+ }
98
+ }
99
+ }
100
+
101
+ /**
102
+ * getThetaState - retrieve ThetaState from THETA via repository
103
+ * @param promise promise to set result
104
+ */
105
+ @ReactMethod
106
+ fun getThetaState(promise: Promise) {
107
+ launch {
108
+ try {
109
+ val state = theta.getThetaState()
110
+ val result = Arguments.createMap()
111
+ result.putString("fingerprint", state.fingerprint)
112
+ result.putDouble("batteryLevel", state.batteryLevel.toDouble())
113
+ result.putString("chargingState", state.chargingState.toString())
114
+ result.putBoolean("isSdCard", state.isSdCard)
115
+ result.putInt("recordedTime", state.recordedTime)
116
+ result.putInt("recordableTime", state.recordableTime)
117
+ result.putString("latestFileUrl", state.latestFileUrl)
118
+ promise.resolve(result)
119
+ } catch (t: Throwable) {
120
+ promise.reject(t)
121
+ }
122
+ }
123
+ }
124
+
125
+ /**
126
+ * listFiles - retrieve File list from THETA via repository
127
+ * @param fileType file type to retrieve
128
+ * @param startPosition start position to retrieve
129
+ * @param entryCount count to retrieve
130
+ * @param promise promise to set result
131
+ */
132
+ @ReactMethod
133
+ fun listFiles(fileType: String, startPosition: Int, entryCount: Int, promise: Promise) {
134
+ launch {
135
+ try {
136
+ val response = theta.listFiles(
137
+ ThetaRepository.FileTypeEnum.valueOf(fileType),
138
+ startPosition,
139
+ entryCount
140
+ )
141
+ val resultlist = Arguments.createArray()
142
+ response.forEach {
143
+ val result = Arguments.createMap()
144
+ result.putString("name", it.name)
145
+ result.putDouble("size", it.size.toDouble())
146
+ result.putString("dateTime", it.dateTime)
147
+ result.putString("thumbnailUrl", it.thumbnailUrl)
148
+ result.putString("fileUrl", it.fileUrl)
149
+ resultlist.pushMap(result)
150
+ }
151
+ promise.resolve(resultlist)
152
+ } catch (t: Throwable) {
153
+ promise.reject(t)
154
+ }
155
+ }
156
+ }
157
+
158
+ /**
159
+ * deleteFiles - delete specified files
160
+ * @param fileUrls file url list to delete
161
+ * @param promise promise to set result
162
+ */
163
+ @ReactMethod
164
+ fun deleteFiles(fileUrls: ReadableArray, promise: Promise) {
165
+ val fileList = mutableListOf<String>()
166
+ for (index in 0..(fileUrls.size() - 1)) {
167
+ fileList.add(fileUrls.getString(index))
168
+ }
169
+ launch {
170
+ try {
171
+ theta.deleteFiles(fileList)
172
+ promise.resolve(true)
173
+ } catch (t: Throwable) {
174
+ promise.reject(t)
175
+ }
176
+ }
177
+ }
178
+
179
+ /**
180
+ * deleteAllFiles - delete all files
181
+ * @param promise promise to set result
182
+ */
183
+ @ReactMethod
184
+ fun deleteAllFiles(promise: Promise) {
185
+ launch {
186
+ try {
187
+ theta.deleteAllFiles()
188
+ promise.resolve(true)
189
+ } catch (t: Throwable) {
190
+ promise.reject(t)
191
+ }
192
+ }
193
+ }
194
+
195
+ /**
196
+ * deleteAllImageFiles - delete all image files
197
+ * @param promise promise to set result
198
+ */
199
+ @ReactMethod
200
+ fun deleteAllImageFiles(promise: Promise) {
201
+ launch {
202
+ try {
203
+ theta.deleteAllImageFiles()
204
+ promise.resolve(true)
205
+ } catch (t: Throwable) {
206
+ promise.reject(t)
207
+ }
208
+ }
209
+ }
210
+
211
+ /**
212
+ * deleteAllVideoFiles - delete all video files
213
+ * @param promise promise to set result
214
+ */
215
+ @ReactMethod
216
+ fun deleteAllVideoFiles(promise: Promise) {
217
+ launch {
218
+ try {
219
+ theta.deleteAllVideoFiles()
220
+ promise.resolve(true)
221
+ } catch (t: Throwable) {
222
+ promise.reject(t)
223
+ }
224
+ }
225
+ }
226
+
227
+ /** option converter */
228
+ private val converters = mapOf(
229
+ "aperture" to ApertureConverter(),
230
+ "captureMode" to CaptureModeConverter(),
231
+ "colorTemperature" to ColorTemperatureConverter(),
232
+ "dateTimeZone" to DateTimeZoneConverter(),
233
+ "exposureCompensation" to ExposureCompensationConverter(),
234
+ "exposureDelay" to ExposureDelayConverter(),
235
+ "exposureProgram" to ExposureProgramConverter(),
236
+ "fileFormat" to FileFormatConverter(),
237
+ "filter" to FilterConverter(),
238
+ "gpsInfo" to GpsInfoConverter(),
239
+ "isGpsOn" to IsGpsOnConverter(),
240
+ "iso" to IsoConverter(),
241
+ "isoAutoHighLimit" to IsoAutoHighLimitConverter(),
242
+ "language" to LanguageConverter(),
243
+ "maxRecordableTime" to MaxRecordableTimeConverter(),
244
+ "offDelay" to OffDelayConverter(),
245
+ "sleepDelay" to SleepDelayConverter(),
246
+ "remainingPictures" to RemainingPicturesConverter(),
247
+ "remainingVideoSeconds" to RemainingVideoSecondsConverter(),
248
+ "remainingSpace" to RemainingSpaceConverter(),
249
+ "totalSpace" to TotalSpaceConverter(),
250
+ "shutterVolume" to ShutterVolumeConverter(),
251
+ "whiteBalance" to WhiteBalanceConverter(),
252
+ "_gpsTagRecording" to GpsTagRecordingConverter(),
253
+ )
254
+ /** OptionNameEnum to option */
255
+ private val optionEnumToOption = mapOf(
256
+ "Aperture" to "aperture",
257
+ "Aperture" to "aperture",
258
+ "CaptureMode" to "captureMode",
259
+ "ColorTemperature" to "colorTemperature",
260
+ "DateTimeZone" to "dateTimeZone",
261
+ "ExposureCompensation" to "exposureCompensation",
262
+ "ExposureDelay" to "exposureDelay",
263
+ "ExposureProgram" to "exposureProgram",
264
+ "FileFormat" to "fileFormat",
265
+ "Filter" to "filter",
266
+ "GpsInfo" to "gpsInfo",
267
+ "IsGpsOn" to "isGpsOn",
268
+ "Iso" to "iso",
269
+ "IsoAutoHighLimit" to "isoAutoHighLimit",
270
+ "Language" to "language",
271
+ "MaxRecordableTime" to "maxRecordableTime",
272
+ "OffDelay" to "offDelay",
273
+ "SleepDelay" to "sleepDelay",
274
+ "RemainingPictures" to "remainingPictures",
275
+ "RemainingVideoSeconds" to "remainingVideoSeconds",
276
+ "RemainingSpace" to "remainingSpace",
277
+ "TotalSpace" to "totalSpace",
278
+ "ShutterVolume" to "shutterVolume",
279
+ "WhiteBalance" to "whiteBalance",
280
+ )
281
+
282
+ /**
283
+ * getOptions - get options from THETA via repository
284
+ * @param optionNames option name list to get
285
+ * @param promise promise to set result
286
+ */
287
+ @ReactMethod
288
+ fun getOptions(optionNames: ReadableArray, promise: Promise) {
289
+ launch {
290
+ try {
291
+ val optionNameList = mutableListOf<ThetaRepository.OptionNameEnum>()
292
+ for (index in 0..(optionNames.size() - 1)) {
293
+ val option = optionNames.getString(index)
294
+ optionNameList.add(ThetaRepository.OptionNameEnum.valueOf(option))
295
+ }
296
+ val options = theta.getOptions(optionNameList)
297
+ val result = Arguments.createMap()
298
+ for (index in 0..(optionNames.size() - 1)) {
299
+ val option = optionEnumToOption[optionNames.getString(index)]
300
+ val cvt = converters[option]
301
+ cvt?.setFromTheta(options, result)
302
+ }
303
+ promise.resolve(result)
304
+ } catch (t: Throwable) {
305
+ promise.reject(t)
306
+ }
307
+ }
308
+ }
309
+
310
+ /**
311
+ * setOptions - set options to THETA via repository
312
+ * @param options options to set
313
+ * @param resolve resolver for setOptions
314
+ * @param rejecter rejecter for setOptions
315
+ */
316
+ @ReactMethod
317
+ fun setOptions(options: ReadableMap, promise: Promise) {
318
+ launch {
319
+ try {
320
+ val thetaOptions = ThetaRepository.Options()
321
+ val iterator = options.keySetIterator()
322
+ while (iterator.hasNextKey()) {
323
+ val key = iterator.nextKey()
324
+ val cvt = converters[key]
325
+ cvt?.setToTheta(thetaOptions, options)
326
+ }
327
+ theta.setOptions(thetaOptions)
328
+ promise.resolve(true)
329
+ } catch (t: Throwable) {
330
+ promise.reject(t)
331
+ }
332
+ }
333
+ }
334
+
335
+ /**
336
+ * getLivePreview - retrieve live preview frame from THETA via repository
337
+ * @param promise promise to set result
338
+ */
339
+ @ReactMethod
340
+ fun getLivePreview(promise: Promise) {
341
+ fun ByteArray.toBase64(): String = String(Base64.getEncoder().encode(this))
342
+ suspend fun callFrameHandler(packet: Pair<ByteArray, Int>): Boolean {
343
+ if (listenerCount == 0) {
344
+ return previewing
345
+ }
346
+ val param = Arguments.createMap()
347
+ param.putString("data",
348
+ "data:image/jpeg;base64," +
349
+ packet.first.copyOfRange(0, packet.second).toBase64())
350
+ reactApplicationContext
351
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
352
+ .emit(EVENT_NAME, param)
353
+ return previewing
354
+ }
355
+ previewing = true
356
+ launch {
357
+ try {
358
+ theta.getLivePreview(::callFrameHandler)
359
+ promise.resolve(true)
360
+ } catch (t: Throwable) {
361
+ promise.reject(t)
362
+ }
363
+ }
364
+ }
365
+
366
+ /**
367
+ * stopLivePreview - stop live previewing
368
+ */
369
+ @ReactMethod
370
+ fun stopLivePreview() {
371
+ previewing = false
372
+ }
373
+
374
+ /**
375
+ * getPhotoCaptureBuilder - get photo capture builder from repository
376
+ */
377
+ @ReactMethod
378
+ fun getPhotoCaptureBuilder() {
379
+ photoCaptureBuilder = theta.getPhotoCaptureBuilder()
380
+ }
381
+
382
+ /**
383
+ * buildPhotoCapture - build photo capture
384
+ * @param options option to take picture
385
+ * @param resolve resolver for buildPhotoCapture
386
+ * @param rejecter rejecter for buildPhotoCapture
387
+ */
388
+ @ReactMethod
389
+ fun buildPhotoCapture(options: ReadableMap, promise: Promise) {
390
+ if (photoCaptureBuilder == null) {
391
+ promise.reject(Exception("no photoCaptureBuilder"))
392
+ return
393
+ }
394
+ launch {
395
+ try {
396
+ val iterator = options.keySetIterator()
397
+ while (iterator.hasNextKey()) {
398
+ val key = iterator.nextKey()
399
+ val cvt = converters[key]
400
+ cvt?.setPhotoOption(options, photoCaptureBuilder!!)
401
+ }
402
+ photoCapture = photoCaptureBuilder!!.build()
403
+ promise.resolve(true)
404
+ photoCaptureBuilder = null
405
+ } catch (t: Throwable) {
406
+ promise.reject(t)
407
+ photoCaptureBuilder = null
408
+ }
409
+ }
410
+ }
411
+
412
+ /**
413
+ * takePicture - take a picture with THETA via repository
414
+ * @param promise promise to set result
415
+ */
416
+ @ReactMethod
417
+ fun takePicture(promise: Promise) {
418
+ if (photoCapture == null) {
419
+ promise.reject(Exception("no photoCapture"))
420
+ return
421
+ }
422
+ class TakePictureCallback : PhotoCapture.TakePictureCallback {
423
+ override fun onSuccess(fileUrl: String) {
424
+ promise.resolve(fileUrl)
425
+ photoCapture = null
426
+ }
427
+
428
+ override fun onError(exception: ThetaRepository.ThetaRepositoryException) {
429
+ promise.reject(exception)
430
+ photoCapture = null
431
+ }
432
+ }
433
+ launch {
434
+ photoCapture!!.takePicture(TakePictureCallback())
435
+ }
436
+ }
437
+
438
+ /**
439
+ * getVideoCaptureBuilder - get video capture builder
440
+ */
441
+ @ReactMethod
442
+ fun getVideoCaptureBuilder() {
443
+ videoCaptureBuilder = theta.getVideoCaptureBuilder()
444
+ }
445
+
446
+ /**
447
+ * buildVideoCapture - build video capture
448
+ * @param options option to capture video
449
+ * @param promise promise to set result
450
+ */
451
+ @ReactMethod
452
+ fun buildVideoCapture(options: ReadableMap, promise: Promise) {
453
+ if (videoCaptureBuilder == null) {
454
+ promise.reject(Exception("no videoCaptureBuilder"))
455
+ return
456
+ }
457
+ launch {
458
+ try {
459
+ val iterator = options.keySetIterator()
460
+ while (iterator.hasNextKey()) {
461
+ val key = iterator.nextKey()
462
+ val cvt = converters[key]
463
+ cvt?.setVideoOption(options, videoCaptureBuilder!!)
464
+ }
465
+ videoCapture = videoCaptureBuilder!!.build()
466
+ promise.resolve(true)
467
+ videoCaptureBuilder = null
468
+ } catch (t: Throwable) {
469
+ promise.reject(t)
470
+ videoCaptureBuilder = null
471
+ }
472
+ }
473
+ }
474
+
475
+ /**
476
+ * startCapture - start capture video
477
+ * @param promise promise to set result
478
+ */
479
+ @ReactMethod
480
+ fun startCapture(promise: Promise) {
481
+ if (videoCapture == null) {
482
+ promise.reject(Exception("no videoCapture"))
483
+ return
484
+ }
485
+ class StartCaptureCallback : VideoCapture.StartCaptureCallback {
486
+ override fun onSuccess(fileUrl: String) {
487
+ promise.resolve(fileUrl)
488
+ videoCapture = null
489
+ videoCapturing = null
490
+ }
491
+
492
+ override fun onError(exception: ThetaRepository.ThetaRepositoryException) {
493
+ promise.reject(exception)
494
+ videoCapture = null
495
+ videoCapturing = null
496
+ }
497
+ }
498
+ videoCapturing = videoCapture!!.startCapture(StartCaptureCallback())
499
+ }
500
+
501
+ /**
502
+ * stopCapture - stop capturing video
503
+ */
504
+ @ReactMethod
505
+ fun stopCapture() {
506
+ videoCapturing?.stopCapture()
507
+ }
508
+
509
+ /**
510
+ * getMetadata - retrieve meta data from THETA via repository
511
+ * @param promise promise to set result
512
+ */
513
+ @ReactMethod
514
+ fun getMetadata(fileUrl: String, promise: Promise) {
515
+ launch {
516
+ try {
517
+ val metaData = theta.getMetadata(fileUrl)
518
+ val exif = Arguments.createMap()
519
+ val xmp = Arguments.createMap()
520
+ metaData.first.let {
521
+ exif.putString("exifVersion", it.exifVersion)
522
+ exif.putString("dateTime", it.dateTime)
523
+ it.imageWidth?.let { it1 -> exif.putInt("imageWidth", it1) }
524
+ it.imageLength?.let { it1 -> exif.putInt("imageLength", it1) }
525
+ it.gpsLatitude?.let { it1 -> exif.putDouble("gpsLatitude", it1) }
526
+ it.gpsLongitude?.let { it1 -> exif.putDouble("gpsLongitude", it1) }
527
+ }
528
+ metaData.second.let {
529
+ it.poseHeadingDegrees?.let { it1 -> xmp.putDouble("poseHeadingDegrees", it1) }
530
+ xmp.putInt("fullPanoWidthPixels", it.fullPanoWidthPixels)
531
+ xmp.putInt("fullPanoHeightPixels", it.fullPanoHeightPixels)
532
+ }
533
+ val metaInfo = Arguments.createMap()
534
+ metaInfo.putMap("exif", exif)
535
+ metaInfo.putMap("xmp", xmp)
536
+ promise.resolve(metaInfo)
537
+ } catch (t: Throwable) {
538
+ promise.reject(t)
539
+ }
540
+ }
541
+ }
542
+
543
+ /**
544
+ * reset - reset THETA via repository
545
+ * @param promise promise to set result
546
+ */
547
+ @ReactMethod
548
+ fun reset(promise: Promise) {
549
+ launch {
550
+ try {
551
+ theta.reset()
552
+ promise.resolve(true)
553
+ } catch (t: Throwable) {
554
+ promise.reject(t)
555
+ }
556
+ }
557
+ }
558
+
559
+ /**
560
+ * restoreSettings - restore THETA setting before initialization
561
+ * @param promise promise to set result
562
+ */
563
+ @ReactMethod
564
+ fun restoreSettings(promise: Promise) {
565
+ launch {
566
+ try {
567
+ theta.restoreSettings()
568
+ promise.resolve(true)
569
+ } catch (t: Throwable) {
570
+ promise.reject(t)
571
+ }
572
+ }
573
+ }
574
+
575
+ /**
576
+ * stopSelfTimer - stop self timer of THETA
577
+ * @param promise promise to set result
578
+ */
579
+ @ReactMethod
580
+ fun stopSelfTimer(promise: Promise) {
581
+ launch {
582
+ try {
583
+ theta.stopSelfTimer()
584
+ promise.resolve(true)
585
+ } catch (t: Throwable) {
586
+ promise.reject(t)
587
+ }
588
+ }
589
+ }
590
+
591
+ /**
592
+ * convertVideoFormats - convert video format in THETA
593
+ * @param fileUrl file url to convert
594
+ * @param is4k 4k or not
595
+ * @param applyTopBottomCorrection apply top bottom correction
596
+ * @param promise promise to set result
597
+ */
598
+ @ReactMethod
599
+ fun convertVideoFormats(
600
+ fileUrl: String,
601
+ is4k: Boolean,
602
+ applyTopBottomCorrection: Boolean,
603
+ promise: Promise,
604
+ ) {
605
+ launch {
606
+ try {
607
+ val convertedUrl = theta.convertVideoFormats(fileUrl, is4k, applyTopBottomCorrection)
608
+ promise.resolve(convertedUrl)
609
+ } catch (t: Throwable) {
610
+ promise.reject(t)
611
+ }
612
+ }
613
+
614
+ }
615
+
616
+ /**
617
+ * cancelVideoconvert - cancel converting video format in THETA
618
+ * @param promise promise to set result
619
+ */
620
+ @ReactMethod
621
+ fun cancelVideoConvert(promise: Promise) {
622
+ launch {
623
+ try {
624
+ theta.cancelVideoConvert()
625
+ promise.resolve(true)
626
+ } catch (t: Throwable) {
627
+ promise.reject(t)
628
+ }
629
+ }
630
+ }
631
+
632
+ /**
633
+ * finishWlan - finish wireless lan
634
+ * @param promise promise to set result
635
+ */
636
+ @ReactMethod
637
+ fun finishWlan(promise: Promise) {
638
+ launch {
639
+ try {
640
+ theta.finishWlan()
641
+ promise.resolve(true)
642
+ } catch (t: Throwable) {
643
+ promise.reject(t)
644
+ }
645
+ }
646
+ }
647
+
648
+ /**
649
+ * listAccessPoints - list access points
650
+ * @param promise promise to set result
651
+ */
652
+ @ReactMethod
653
+ fun listAccessPoints(promise: Promise) {
654
+ launch {
655
+ try {
656
+ val result = Arguments.createArray()
657
+ theta.listAccessPoints().forEach {
658
+ val apinfo = Arguments.createMap()
659
+ apinfo.putString("ssid", it.ssid)
660
+ apinfo.putBoolean("ssidStealth", it.ssidStealth)
661
+ apinfo.putString("authMode", it.authMode.toString())
662
+ apinfo.putInt("connectionPriority", it.connectionPriority)
663
+ apinfo.putBoolean("usingDhcp", it.usingDhcp)
664
+ apinfo.putString("ipAddress", it.ipAddress)
665
+ apinfo.putString("subnetMask", it.subnetMask)
666
+ apinfo.putString("defaultGateway", it.defaultGateway)
667
+ result.pushMap(apinfo)
668
+ }
669
+ promise.resolve(result)
670
+ } catch (t: Throwable) {
671
+ promise.reject(t)
672
+ }
673
+ }
674
+ }
675
+
676
+ /**
677
+ * setAccessPointDynamically - set access point with dhcp
678
+ * @param ssid ssid to connect
679
+ * @param ssidStealth ssid is stealth or not
680
+ * @param authMode auth mode to connect
681
+ * @param password password to connect with auth
682
+ * @param connectionPriority connection priority
683
+ * @param promise promise to set result
684
+ */
685
+ @ReactMethod
686
+ fun setAccessPointDynamically(
687
+ ssid: String,
688
+ ssidStealth: Boolean,
689
+ authMode: String,
690
+ password: String,
691
+ connectionPriority: Int,
692
+ promise: Promise
693
+ ) {
694
+ launch {
695
+ try {
696
+ theta.setAccessPointDynamically(
697
+ ssid,
698
+ ssidStealth,
699
+ ThetaRepository.AuthModeEnum.valueOf(authMode),
700
+ password,
701
+ connectionPriority
702
+ )
703
+ promise.resolve(true)
704
+ } catch (t: Throwable) {
705
+ promise.reject(t)
706
+ }
707
+ }
708
+ }
709
+
710
+ /**
711
+ * setAccessPointStatically - set access point with static connection info
712
+ * @param ssid ssid to connect
713
+ * @param ssidStealth ssid is stealth or not
714
+ * @param authMode auth mode to connect
715
+ * @param password password to connect with auth
716
+ * @param connectionPriority connection priority
717
+ * @param ipAddress static ipaddress to connect
718
+ * @param subnetMask subnet mask for ip address
719
+ * @param defaultGateway default gateway address
720
+ * @param promise promise to set result
721
+ */
722
+ @ReactMethod
723
+ fun setAccessPointStatically(
724
+ ssid: String,
725
+ ssidStealth: Boolean,
726
+ authMode: String,
727
+ password: String,
728
+ connectionPriority: Int,
729
+ ipAddress: String,
730
+ subnetMask: String,
731
+ defaultGateway: String,
732
+ promise: Promise
733
+ ) {
734
+ launch {
735
+ try {
736
+ theta.setAccessPointStatically(
737
+ ssid,
738
+ ssidStealth,
739
+ ThetaRepository.AuthModeEnum.valueOf(authMode),
740
+ password,
741
+ connectionPriority,
742
+ ipAddress,
743
+ subnetMask,
744
+ defaultGateway,
745
+ )
746
+ promise.resolve(true)
747
+ } catch (t: Throwable) {
748
+ promise.reject(t)
749
+ }
750
+ }
751
+ }
752
+
753
+ /**
754
+ * deleteAccessPoint - delete access point related ssid
755
+ * @param ssid ssid to delete
756
+ * @param promise promise to set result
757
+ */
758
+ @ReactMethod
759
+ fun deleteAccessPoint(ssid: String, promise: Promise) {
760
+ launch {
761
+ try {
762
+ theta.deleteAccessPoint(ssid)
763
+ promise.resolve(true)
764
+ } catch (t: Throwable) {
765
+ promise.reject(t)
766
+ }
767
+ }
768
+ }
769
+
770
+ companion object {
771
+ const val NAME = "ThetaClientReactNative"
772
+ const val EVENT_NAME = "ThetaFrameEvent"
773
+ }
774
+ }