theta-client-react-native 1.3.1 → 1.5.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.
Files changed (154) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/ricoh360/thetaclientreactnative/Converter.kt +441 -1035
  3. package/android/src/main/java/com/ricoh360/thetaclientreactnative/ThetaClientSdkModule.kt +327 -251
  4. package/ios/ConvertUtil.swift +1053 -0
  5. package/ios/ThetaClientReactNative-Bridging-Header.h +3 -0
  6. package/ios/ThetaClientReactNative.m +228 -0
  7. package/ios/ThetaClientReactNative.swift +1608 -0
  8. package/ios/ThetaClientReactNative.xcodeproj/project.pbxproj +15 -57
  9. package/lib/commonjs/capture/index.js +22 -0
  10. package/lib/commonjs/capture/index.js.map +1 -1
  11. package/lib/commonjs/capture/limitless-interval-capture.js +89 -0
  12. package/lib/commonjs/capture/limitless-interval-capture.js.map +1 -0
  13. package/lib/commonjs/capture/photo-capture.js +26 -3
  14. package/lib/commonjs/capture/photo-capture.js.map +1 -1
  15. package/lib/commonjs/capture/shot-count-specified-interval-capture.js +112 -0
  16. package/lib/commonjs/capture/shot-count-specified-interval-capture.js.map +1 -0
  17. package/lib/commonjs/capture/time-shift-capture.js +27 -23
  18. package/lib/commonjs/capture/time-shift-capture.js.map +1 -1
  19. package/lib/commonjs/capture/video-capture.js +33 -5
  20. package/lib/commonjs/capture/video-capture.js.map +1 -1
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/commonjs/theta-repository/notify-controller.js +40 -0
  23. package/lib/commonjs/theta-repository/notify-controller.js.map +1 -0
  24. package/lib/commonjs/theta-repository/options/index.js +88 -0
  25. package/lib/commonjs/theta-repository/options/index.js.map +1 -1
  26. package/lib/commonjs/theta-repository/options/option-face-detect.js +22 -0
  27. package/lib/commonjs/theta-repository/options/option-face-detect.js.map +1 -0
  28. package/lib/commonjs/theta-repository/options/option-function.js +27 -0
  29. package/lib/commonjs/theta-repository/options/option-function.js.map +1 -0
  30. package/lib/commonjs/theta-repository/options/option-gain.js +26 -0
  31. package/lib/commonjs/theta-repository/options/option-gain.js.map +1 -0
  32. package/lib/commonjs/theta-repository/options/option-image-stitching.js +38 -0
  33. package/lib/commonjs/theta-repository/options/option-image-stitching.js.map +1 -0
  34. package/lib/commonjs/theta-repository/options/option-top-bottom-correction-rotation.js +2 -0
  35. package/lib/commonjs/theta-repository/options/option-top-bottom-correction-rotation.js.map +1 -0
  36. package/lib/commonjs/theta-repository/options/option-top-bottom-correction.js +52 -0
  37. package/lib/commonjs/theta-repository/options/option-top-bottom-correction.js.map +1 -0
  38. package/lib/commonjs/theta-repository/options/option-video-stitching.js +24 -0
  39. package/lib/commonjs/theta-repository/options/option-video-stitching.js.map +1 -0
  40. package/lib/commonjs/theta-repository/options/option-visibility-reduction.js +23 -0
  41. package/lib/commonjs/theta-repository/options/option-visibility-reduction.js.map +1 -0
  42. package/lib/commonjs/theta-repository/options/options.js +18 -0
  43. package/lib/commonjs/theta-repository/options/options.js.map +1 -1
  44. package/lib/commonjs/theta-repository/theta-repository.js +26 -4
  45. package/lib/commonjs/theta-repository/theta-repository.js.map +1 -1
  46. package/lib/commonjs/theta-repository/theta-state.js +1 -13
  47. package/lib/commonjs/theta-repository/theta-state.js.map +1 -1
  48. package/lib/module/capture/index.js +2 -0
  49. package/lib/module/capture/index.js.map +1 -1
  50. package/lib/module/capture/limitless-interval-capture.js +81 -0
  51. package/lib/module/capture/limitless-interval-capture.js.map +1 -0
  52. package/lib/module/capture/photo-capture.js +26 -3
  53. package/lib/module/capture/photo-capture.js.map +1 -1
  54. package/lib/module/capture/shot-count-specified-interval-capture.js +104 -0
  55. package/lib/module/capture/shot-count-specified-interval-capture.js.map +1 -0
  56. package/lib/module/capture/time-shift-capture.js +27 -23
  57. package/lib/module/capture/time-shift-capture.js.map +1 -1
  58. package/lib/module/capture/video-capture.js +33 -5
  59. package/lib/module/capture/video-capture.js.map +1 -1
  60. package/lib/module/index.js.map +1 -1
  61. package/lib/module/theta-repository/notify-controller.js +33 -0
  62. package/lib/module/theta-repository/notify-controller.js.map +1 -0
  63. package/lib/module/theta-repository/options/index.js +8 -0
  64. package/lib/module/theta-repository/options/index.js.map +1 -1
  65. package/lib/module/theta-repository/options/option-face-detect.js +15 -0
  66. package/lib/module/theta-repository/options/option-face-detect.js.map +1 -0
  67. package/lib/module/theta-repository/options/option-function.js +20 -0
  68. package/lib/module/theta-repository/options/option-function.js.map +1 -0
  69. package/lib/module/theta-repository/options/option-gain.js +19 -0
  70. package/lib/module/theta-repository/options/option-gain.js.map +1 -0
  71. package/lib/module/theta-repository/options/option-image-stitching.js +31 -0
  72. package/lib/module/theta-repository/options/option-image-stitching.js.map +1 -0
  73. package/lib/module/theta-repository/options/option-top-bottom-correction-rotation.js +2 -0
  74. package/lib/module/theta-repository/options/option-top-bottom-correction-rotation.js.map +1 -0
  75. package/lib/module/theta-repository/options/option-top-bottom-correction.js +45 -0
  76. package/lib/module/theta-repository/options/option-top-bottom-correction.js.map +1 -0
  77. package/lib/module/theta-repository/options/option-video-stitching.js +17 -0
  78. package/lib/module/theta-repository/options/option-video-stitching.js.map +1 -0
  79. package/lib/module/theta-repository/options/option-visibility-reduction.js +16 -0
  80. package/lib/module/theta-repository/options/option-visibility-reduction.js.map +1 -0
  81. package/lib/module/theta-repository/options/options.js +18 -0
  82. package/lib/module/theta-repository/options/options.js.map +1 -1
  83. package/lib/module/theta-repository/theta-repository.js +25 -5
  84. package/lib/module/theta-repository/theta-repository.js.map +1 -1
  85. package/lib/module/theta-repository/theta-state.js +0 -12
  86. package/lib/module/theta-repository/theta-state.js.map +1 -1
  87. package/lib/typescript/capture/index.d.ts +2 -0
  88. package/lib/typescript/capture/index.d.ts.map +1 -1
  89. package/lib/typescript/capture/limitless-interval-capture.d.ts +40 -0
  90. package/lib/typescript/capture/limitless-interval-capture.d.ts.map +1 -0
  91. package/lib/typescript/capture/photo-capture.d.ts +8 -2
  92. package/lib/typescript/capture/photo-capture.d.ts.map +1 -1
  93. package/lib/typescript/capture/shot-count-specified-interval-capture.d.ts +47 -0
  94. package/lib/typescript/capture/shot-count-specified-interval-capture.d.ts.map +1 -0
  95. package/lib/typescript/capture/time-shift-capture.d.ts +4 -7
  96. package/lib/typescript/capture/time-shift-capture.d.ts.map +1 -1
  97. package/lib/typescript/capture/video-capture.d.ts +5 -1
  98. package/lib/typescript/capture/video-capture.d.ts.map +1 -1
  99. package/lib/typescript/theta-repository/notify-controller.d.ts +17 -0
  100. package/lib/typescript/theta-repository/notify-controller.d.ts.map +1 -0
  101. package/lib/typescript/theta-repository/options/index.d.ts +8 -0
  102. package/lib/typescript/theta-repository/options/index.d.ts.map +1 -1
  103. package/lib/typescript/theta-repository/options/option-face-detect.d.ts +15 -0
  104. package/lib/typescript/theta-repository/options/option-face-detect.d.ts.map +1 -0
  105. package/lib/typescript/theta-repository/options/option-function.d.ts +20 -0
  106. package/lib/typescript/theta-repository/options/option-function.d.ts.map +1 -0
  107. package/lib/typescript/theta-repository/options/option-gain.d.ts +19 -0
  108. package/lib/typescript/theta-repository/options/option-gain.d.ts.map +1 -0
  109. package/lib/typescript/theta-repository/options/option-image-stitching.d.ts +30 -0
  110. package/lib/typescript/theta-repository/options/option-image-stitching.d.ts.map +1 -0
  111. package/lib/typescript/theta-repository/options/option-top-bottom-correction-rotation.d.ts +22 -0
  112. package/lib/typescript/theta-repository/options/option-top-bottom-correction-rotation.d.ts.map +1 -0
  113. package/lib/typescript/theta-repository/options/option-top-bottom-correction.d.ts +45 -0
  114. package/lib/typescript/theta-repository/options/option-top-bottom-correction.d.ts.map +1 -0
  115. package/lib/typescript/theta-repository/options/option-video-stitching.d.ts +17 -0
  116. package/lib/typescript/theta-repository/options/option-video-stitching.d.ts.map +1 -0
  117. package/lib/typescript/theta-repository/options/option-visibility-reduction.d.ts +16 -0
  118. package/lib/typescript/theta-repository/options/option-visibility-reduction.d.ts.map +1 -0
  119. package/lib/typescript/theta-repository/options/options.d.ts +47 -0
  120. package/lib/typescript/theta-repository/options/options.d.ts.map +1 -1
  121. package/lib/typescript/theta-repository/theta-repository.d.ts +17 -2
  122. package/lib/typescript/theta-repository/theta-repository.d.ts.map +1 -1
  123. package/lib/typescript/theta-repository/theta-state.d.ts +2 -12
  124. package/lib/typescript/theta-repository/theta-state.d.ts.map +1 -1
  125. package/package.json +17 -9
  126. package/src/capture/index.ts +2 -0
  127. package/src/capture/limitless-interval-capture.ts +99 -0
  128. package/src/capture/photo-capture.ts +27 -5
  129. package/src/capture/shot-count-specified-interval-capture.ts +146 -0
  130. package/src/capture/time-shift-capture.ts +40 -33
  131. package/src/capture/video-capture.ts +49 -6
  132. package/src/theta-repository/notify-controller.ts +50 -0
  133. package/src/theta-repository/options/index.ts +8 -0
  134. package/src/theta-repository/options/option-face-detect.ts +16 -0
  135. package/src/theta-repository/options/option-function.ts +21 -0
  136. package/src/theta-repository/options/option-gain.ts +19 -0
  137. package/src/theta-repository/options/option-image-stitching.ts +32 -0
  138. package/src/theta-repository/options/option-top-bottom-correction-rotation.ts +21 -0
  139. package/src/theta-repository/options/option-top-bottom-correction.ts +46 -0
  140. package/src/theta-repository/options/option-video-stitching.ts +18 -0
  141. package/src/theta-repository/options/option-visibility-reduction.ts +17 -0
  142. package/src/theta-repository/options/options.ts +47 -0
  143. package/src/theta-repository/theta-repository.ts +29 -4
  144. package/src/theta-repository/theta-state.ts +3 -15
  145. package/theta-client-react-native.podspec +2 -2
  146. package/ios/ThetaClientReactNative.h +0 -34
  147. package/ios/ThetaClientReactNative.mm +0 -4087
  148. package/lib/commonjs/capture/notify.js +0 -12
  149. package/lib/commonjs/capture/notify.js.map +0 -1
  150. package/lib/module/capture/notify.js +0 -6
  151. package/lib/module/capture/notify.js.map +0 -1
  152. package/lib/typescript/capture/notify.d.ts +0 -13
  153. package/lib/typescript/capture/notify.d.ts.map +0 -1
  154. package/src/capture/notify.ts +0 -27
@@ -0,0 +1,1608 @@
1
+ import THETAClient
2
+
3
+ let ERROR_CODE_ERROR = "error"
4
+ let MESSAGE_NOT_INIT = "Not initialized."
5
+ let MESSAGE_NO_RESULT = "No result."
6
+ let MESSAGE_NO_ARGUMENT = "No Argument."
7
+ let MESSAGE_NO_PHOTO_CAPTURE = "No photoCapture."
8
+ let MESSAGE_NO_PHOTO_CAPTURE_BUILDER = "no photo capture builder."
9
+ let MESSAGE_NO_TIMESHIFT_CAPTURE = "No timeShiftCapture."
10
+ let MESSAGE_NO_TIMESHIFT_CAPTURE_BUILDER = "no time-shift capture builder."
11
+ let MESSAGE_NO_TIMESHIFT_CAPTURING = "no timeShiftCapturing."
12
+ let MESSAGE_NO_VIDEO_CAPTURE = "No videoCapture."
13
+ let MESSAGE_NO_VIDEO_CAPTURE_BUILDER = "no video capture builder."
14
+ let MESSAGE_NO_VIDEO_CAPTURING = "no videoCapturing."
15
+ let MESSAGE_NO_LIMITLESS_INTERVAL_CAPTURE = "No limitlessIntervalCapture."
16
+ let MESSAGE_NO_LIMITLESS_INTERVAL_CAPTURE_BUILDER = "no limitlessIntervalCaptureBuilder."
17
+ let MESSAGE_NO_LIMITLESS_INTERVAL_CAPTURING = "no limitlessIntervalCapturing."
18
+ let MESSAGE_NO_SHOT_COUNT_SPECIFIED_INTERVAL_CAPTURE = "No shotCountSpecifiedIntervalCapture."
19
+ let MESSAGE_NO_SHOT_COUNT_SPECIFIED_INTERVAL_CAPTURE_BUILDER = "no shotCountSpecifiedIntervalCaptureBuilder."
20
+ let MESSAGE_NO_SHOT_COUNT_SPECIFIED_INTERVAL_CAPTURING = "no shotCountSpecifiedIntervalCapturing."
21
+
22
+ @objc(ThetaClientReactNative)
23
+ class ThetaClientReactNative: RCTEventEmitter {
24
+ var thetaRepository: ThetaRepository?
25
+ var previewing = false
26
+ var photoCaptureBuilder: PhotoCapture.Builder?
27
+ var photoCapture: PhotoCapture?
28
+ var timeShiftCaptureBuilder: TimeShiftCapture.Builder?
29
+ var timeShiftCapture: TimeShiftCapture?
30
+ var timeShiftCapturing: TimeShiftCapturing?
31
+ var videoCaptureBuilder: VideoCapture.Builder?
32
+ var videoCapture: VideoCapture?
33
+ var videoCapturing: VideoCapturing?
34
+ var limitlessIntervalCaptureBuilder: LimitlessIntervalCapture.Builder?
35
+ var limitlessIntervalCapture: LimitlessIntervalCapture?
36
+ var limitlessIntervalCapturing: LimitlessIntervalCapturing?
37
+ var shotCountSpecifiedIntervalCaptureBuilder: ShotCountSpecifiedIntervalCapture.Builder?
38
+ var shotCountSpecifiedIntervalCapture: ShotCountSpecifiedIntervalCapture?
39
+ var shotCountSpecifiedIntervalCapturing: ShotCountSpecifiedIntervalCapturing?
40
+
41
+ static let EVENT_FRAME = "ThetaFrameEvent"
42
+ static let EVENT_NOTIFY = "ThetaNotify"
43
+
44
+ static let NOTIFY_TIMESHIFT_PROGRESS = "TIME-SHIFT-PROGRESS"
45
+ static let NOTIFY_SHOT_COUNT_SPECIFIED_INTERVAL_PROGRESS = "SHOT-COUNT-SPECIFIED-INTERVAL-PROGRESS"
46
+ static let NOTIFY_SHOT_COUNT_SPECIFIED_INTERVAL_STOP_ERROR = "SHOT-COUNT-SPECIFIED-INTERVAL-STOP-ERROR"
47
+ static let NOTIFY_VIDEO_CAPTURE_STOP_ERROR = "VIDEO-CAPTURE-STOP-ERROR"
48
+ static let NOTIFY_LIMITLESS_INTERVAL_CAPTURE_STOP_ERROR = "LIMITLESS-INTERVAL-CAPTURE-STOP-ERROR"
49
+
50
+ @objc
51
+ override func supportedEvents() -> [String]! {
52
+ return [ThetaClientReactNative.EVENT_FRAME, ThetaClientReactNative.EVENT_NOTIFY]
53
+ }
54
+
55
+ @objc
56
+ override static func requiresMainQueueSetup() -> Bool {
57
+ return true
58
+ }
59
+
60
+ @objc
61
+ override func constantsToExport() -> [AnyHashable: Any]! {
62
+ return [
63
+ "DEFAULT_EVENT_NAME": ThetaClientReactNative.EVENT_FRAME,
64
+ ]
65
+ }
66
+
67
+ @objc(initialize:withConfig:withTimeout:withResolver:withRejecter:)
68
+ func initialize(
69
+ endPoint: String?,
70
+ config: [AnyHashable: Any]?,
71
+ timeout: [AnyHashable: Any]?,
72
+ resolve: @escaping RCTPromiseResolveBlock,
73
+ reject: @escaping RCTPromiseRejectBlock
74
+ ) {
75
+ thetaRepository = nil
76
+ photoCaptureBuilder = nil
77
+ photoCapture = nil
78
+ timeShiftCaptureBuilder = nil
79
+ timeShiftCapture = nil
80
+ timeShiftCapturing = nil
81
+ videoCaptureBuilder = nil
82
+ videoCapture = nil
83
+ videoCapturing = nil
84
+ limitlessIntervalCaptureBuilder = nil
85
+ limitlessIntervalCapture = nil
86
+ limitlessIntervalCapturing = nil
87
+ shotCountSpecifiedIntervalCaptureBuilder = nil
88
+ shotCountSpecifiedIntervalCapture = nil
89
+ shotCountSpecifiedIntervalCapturing = nil
90
+ previewing = false
91
+
92
+ Task {
93
+ let configParams: ThetaRepository.Config? = {
94
+ if let config = config as? [String: Any] {
95
+ return toConfig(params: config)
96
+ }
97
+ return nil
98
+ }()
99
+ let timeoutParams: ThetaRepository.Timeout? = {
100
+ if let timeout = timeout as? [String: Any] {
101
+ return toTimeout(params: timeout)
102
+ }
103
+ return nil
104
+ }()
105
+
106
+ let endpoint = endPoint ?? "http://192.168.1.1"
107
+ ThetaRepository.Companion.shared.doNewInstance(
108
+ endpoint: endpoint,
109
+ config: configParams,
110
+ timeout: timeoutParams
111
+ ) { thetaRepository, error in
112
+ if let error {
113
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
114
+ } else {
115
+ self.thetaRepository = thetaRepository
116
+ resolve(true)
117
+ }
118
+ }
119
+ }
120
+ }
121
+
122
+ @objc(isInitialized:withRejecter:)
123
+ func isInitialized(
124
+ resolve: RCTPromiseResolveBlock,
125
+ reject _: RCTPromiseRejectBlock
126
+ ) {
127
+ resolve(thetaRepository != nil)
128
+ }
129
+
130
+ @objc(getThetaModel:withRejecter:)
131
+ func getThetaModel(
132
+ resolve: @escaping RCTPromiseResolveBlock,
133
+ reject: @escaping RCTPromiseRejectBlock
134
+ ) {
135
+ guard let thetaRepository else {
136
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
137
+ return
138
+ }
139
+ resolve(thetaRepository.cameraModel?.name)
140
+ }
141
+
142
+ @objc(getThetaInfo:withRejecter:)
143
+ func getThetaInfo(
144
+ resolve: @escaping RCTPromiseResolveBlock,
145
+ reject: @escaping RCTPromiseRejectBlock
146
+ ) {
147
+ guard let thetaRepository else {
148
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
149
+ return
150
+ }
151
+ thetaRepository.getThetaInfo { response, error in
152
+ if let error {
153
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
154
+ } else if let response {
155
+ var info = convertResult(thetaInfo: response)
156
+ if let cameraModel = thetaRepository.cameraModel {
157
+ info[KEY_THETA_MODEL] = cameraModel.name
158
+ }
159
+ resolve(info)
160
+ } else {
161
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
162
+ }
163
+ }
164
+ }
165
+
166
+ @objc(getThetaState:withRejecter:)
167
+ func getThetaState(
168
+ resolve: @escaping RCTPromiseResolveBlock,
169
+ reject: @escaping RCTPromiseRejectBlock
170
+ ) {
171
+ guard let thetaRepository else {
172
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
173
+ return
174
+ }
175
+ thetaRepository.getThetaState { response, error in
176
+ if let error {
177
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
178
+ } else if let response {
179
+ let state = convertResult(thetaState: response)
180
+ resolve(state)
181
+ } else {
182
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
183
+ }
184
+ }
185
+ }
186
+
187
+ @objc(listFiles:withStartPosition:withEntryCount:withStorage:withResolver:withRejecter:)
188
+ func listFiles(
189
+ fileType: String,
190
+ startPosition: Int,
191
+ entryCount: Int,
192
+ storage: String?,
193
+ resolve: @escaping RCTPromiseResolveBlock,
194
+ reject: @escaping RCTPromiseRejectBlock
195
+ ) {
196
+ guard let thetaRepository else {
197
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
198
+ return
199
+ }
200
+ guard
201
+ let fileTypeVal = getEnumValue(
202
+ values: ThetaRepository.FileTypeEnum.values(), name: fileType
203
+ )
204
+ else {
205
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
206
+ return
207
+ }
208
+
209
+ let storageVal = getEnumValue(
210
+ values: ThetaRepository.StorageEnum.values(), name: storage ?? ""
211
+ )
212
+
213
+ thetaRepository.listFiles(
214
+ fileType: fileTypeVal,
215
+ startPosition: Int32(startPosition),
216
+ entryCount: Int32(entryCount),
217
+ storage: storageVal
218
+ ) { files, error in
219
+ if let error {
220
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
221
+ } else if let files {
222
+ let resultList = convertResult(fileInfoList: files.fileList)
223
+ let resultMap = [
224
+ KEY_FILE_LIST: resultList,
225
+ KEY_TOTAL_ENTRIES: files.totalEntries,
226
+ ]
227
+ resolve(resultMap)
228
+ } else {
229
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
230
+ }
231
+ }
232
+ }
233
+
234
+ @objc(deleteFiles:withResolver:withRejecter:)
235
+ func deleteFiles(
236
+ fileUrls: [Any],
237
+ resolve: @escaping RCTPromiseResolveBlock,
238
+ reject: @escaping RCTPromiseRejectBlock
239
+ ) {
240
+ guard let thetaRepository else {
241
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
242
+ return
243
+ }
244
+ guard let urls = fileUrls as? [String] else {
245
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
246
+ return
247
+ }
248
+
249
+ thetaRepository.deleteFiles(fileUrls: urls) { error in
250
+ if let error {
251
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
252
+ } else {
253
+ resolve(true)
254
+ }
255
+ }
256
+ }
257
+
258
+ @objc(deleteAllFiles:withRejecter:)
259
+ func deleteAllFiles(
260
+ resolve: @escaping RCTPromiseResolveBlock,
261
+ reject: @escaping RCTPromiseRejectBlock
262
+ ) {
263
+ guard let thetaRepository else {
264
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
265
+ return
266
+ }
267
+
268
+ thetaRepository.deleteAllFiles { error in
269
+ if let error {
270
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
271
+ } else {
272
+ resolve(true)
273
+ }
274
+ }
275
+ }
276
+
277
+ @objc(deleteAllImageFiles:withRejecter:)
278
+ func deleteAllImageFiles(
279
+ resolve: @escaping RCTPromiseResolveBlock,
280
+ reject: @escaping RCTPromiseRejectBlock
281
+ ) {
282
+ guard let thetaRepository else {
283
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
284
+ return
285
+ }
286
+
287
+ thetaRepository.deleteAllImageFiles { error in
288
+ if let error {
289
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
290
+ } else {
291
+ resolve(true)
292
+ }
293
+ }
294
+ }
295
+
296
+ @objc(deleteAllVideoFiles:withRejecter:)
297
+ func deleteAllVideoFiles(
298
+ resolve: @escaping RCTPromiseResolveBlock,
299
+ reject: @escaping RCTPromiseRejectBlock
300
+ ) {
301
+ guard let thetaRepository else {
302
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
303
+ return
304
+ }
305
+
306
+ thetaRepository.deleteAllVideoFiles { error in
307
+ if let error {
308
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
309
+ } else {
310
+ resolve(true)
311
+ }
312
+ }
313
+ }
314
+
315
+ @objc(getOptions:withResolver:withRejecter:)
316
+ func getOptions(
317
+ optionNames: [Any],
318
+ resolve: @escaping RCTPromiseResolveBlock,
319
+ reject: @escaping RCTPromiseRejectBlock
320
+ ) {
321
+ guard let thetaRepository else {
322
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
323
+ return
324
+ }
325
+ guard let optionNames = optionNames as? [String] else {
326
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
327
+ return
328
+ }
329
+
330
+ let params = convertGetOptionsParam(params: optionNames)
331
+ thetaRepository.getOptions(
332
+ optionNames: params
333
+ ) { response, error in
334
+ if let error {
335
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
336
+ } else if let response {
337
+ resolve(convertResult(options: response))
338
+ } else {
339
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
340
+ }
341
+ }
342
+ }
343
+
344
+ @objc(setOptions:withResolver:withRejecter:)
345
+ func setOptions(
346
+ options: [AnyHashable: Any],
347
+ resolve: @escaping RCTPromiseResolveBlock,
348
+ reject: @escaping RCTPromiseRejectBlock
349
+ ) {
350
+ guard let thetaRepository else {
351
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
352
+ return
353
+ }
354
+ guard let options = options as? [String: Any] else {
355
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
356
+ return
357
+ }
358
+ let params = convertSetOptionsParam(params: options)
359
+
360
+ thetaRepository.setOptions(
361
+ options: params
362
+ ) { error in
363
+ if let error {
364
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
365
+ } else {
366
+ resolve(true)
367
+ }
368
+ }
369
+ }
370
+
371
+ @objc(getLivePreview:withRejecter:)
372
+ func getLivePreview(
373
+ resolve: @escaping RCTPromiseResolveBlock,
374
+ reject: @escaping RCTPromiseRejectBlock
375
+ ) {
376
+ class FrameHandler: KotlinSuspendFunction1 {
377
+ let thetaClientReactNative: ThetaClientReactNative
378
+ static let FrameInterval = CFTimeInterval(1.0 / 10.0)
379
+ var last: CFTimeInterval = 0
380
+
381
+ init(_ thetaClientReactNative: ThetaClientReactNative) {
382
+ self.thetaClientReactNative = thetaClientReactNative
383
+ }
384
+
385
+ func invoke(p1: Any?) async throws -> Any? {
386
+ let now = CACurrentMediaTime()
387
+ if now - last > Self.FrameInterval {
388
+ autoreleasepool {
389
+ if let frameData = p1 as? KotlinPair<KotlinByteArray, KotlinInt> {
390
+ let nsData = PlatformKt.frameFrom(
391
+ packet: frameData
392
+ )
393
+ let encodeString = nsData.base64EncodedString()
394
+ let dataUrl = "data:image/jpeg;base64," + encodeString
395
+ thetaClientReactNative.sendEvent(
396
+ withName: ThetaClientReactNative.EVENT_FRAME,
397
+ body: ["data": dataUrl]
398
+ )
399
+ }
400
+ }
401
+ }
402
+ return thetaClientReactNative.previewing
403
+ }
404
+ }
405
+
406
+ guard let thetaRepository else {
407
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
408
+ return
409
+ }
410
+ let frameHandler = FrameHandler(self)
411
+ previewing = true
412
+ thetaRepository.getLivePreview(frameHandler: frameHandler) { error in
413
+ if let error {
414
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
415
+ } else {
416
+ resolve(true)
417
+ }
418
+ }
419
+ }
420
+
421
+ @objc(stopLivePreview:withRejecter:)
422
+ func stopLivePreview(
423
+ resolve: RCTPromiseResolveBlock,
424
+ reject _: RCTPromiseRejectBlock
425
+ ) {
426
+ previewing = false
427
+ resolve(nil)
428
+ }
429
+
430
+ @objc(getPhotoCaptureBuilder:withRejecter:)
431
+ func getPhotoCaptureBuilder(
432
+ resolve: RCTPromiseResolveBlock,
433
+ reject: RCTPromiseRejectBlock
434
+ ) {
435
+ guard let thetaRepository else {
436
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
437
+ return
438
+ }
439
+ photoCaptureBuilder = thetaRepository.getPhotoCaptureBuilder()
440
+ resolve(nil)
441
+ }
442
+
443
+ @objc(buildPhotoCapture:withResolver:withRejecter:)
444
+ func buildPhotoCapture(
445
+ options: [AnyHashable: Any]?,
446
+ resolve: @escaping RCTPromiseResolveBlock,
447
+ reject: @escaping RCTPromiseRejectBlock
448
+ ) {
449
+ guard let _ = thetaRepository else {
450
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
451
+ return
452
+ }
453
+ guard let photoCaptureBuilder else {
454
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_PHOTO_CAPTURE_BUILDER, nil)
455
+ return
456
+ }
457
+
458
+ if let options = options as? [String: Any] {
459
+ setCaptureBuilderParams(params: options, builder: photoCaptureBuilder)
460
+ setPhotoCaptureBuilderParams(params: options, builder: photoCaptureBuilder)
461
+ }
462
+ photoCaptureBuilder.build { capture, error in
463
+ if let error {
464
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
465
+ } else if let capture {
466
+ self.photoCapture = capture
467
+ self.photoCaptureBuilder = nil
468
+ resolve(true)
469
+ } else {
470
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_PHOTO_CAPTURE, nil)
471
+ }
472
+ }
473
+ }
474
+
475
+ @objc(takePicture:withRejecter:)
476
+ func takePicture(
477
+ resolve: @escaping RCTPromiseResolveBlock,
478
+ reject: @escaping RCTPromiseRejectBlock
479
+ ) {
480
+ guard let _ = thetaRepository else {
481
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
482
+ return
483
+ }
484
+ guard let photoCapture else {
485
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_PHOTO_CAPTURE, nil)
486
+ return
487
+ }
488
+
489
+ class Callback: PhotoCaptureTakePictureCallback {
490
+ let callback: (_ url: String?, _ error: Error?) -> Void
491
+ init(_ callback: @escaping (_ url: String?, _ error: Error?) -> Void) {
492
+ self.callback = callback
493
+ }
494
+
495
+ func onSuccess(fileUrl: String?) {
496
+ callback(fileUrl, nil)
497
+ }
498
+
499
+ func onProgress(completion _: Float) {}
500
+
501
+ func onError(exception: ThetaRepository.ThetaRepositoryException) {
502
+ callback(nil, exception.asError())
503
+ }
504
+ }
505
+
506
+ photoCapture.takePicture(
507
+ callback: Callback { url, error in
508
+ if let error {
509
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
510
+ } else {
511
+ self.photoCapture = nil
512
+ resolve(url)
513
+ }
514
+ })
515
+ }
516
+
517
+ @objc(getTimeShiftCaptureBuilder:withRejecter:)
518
+ func getTimeShiftCaptureBuilder(
519
+ resolve: RCTPromiseResolveBlock,
520
+ reject: RCTPromiseRejectBlock
521
+ ) {
522
+ guard let thetaRepository else {
523
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
524
+ return
525
+ }
526
+ timeShiftCaptureBuilder = thetaRepository.getTimeShiftCaptureBuilder()
527
+ resolve(nil)
528
+ }
529
+
530
+ @objc(buildTimeShiftCapture:withResolver:withRejecter:)
531
+ func buildTimeShiftCapture(
532
+ options: [AnyHashable: Any]?,
533
+ resolve: @escaping RCTPromiseResolveBlock,
534
+ reject: @escaping RCTPromiseRejectBlock
535
+ ) {
536
+ guard let _ = thetaRepository else {
537
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
538
+ return
539
+ }
540
+ guard let timeShiftCaptureBuilder else {
541
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_TIMESHIFT_CAPTURE_BUILDER, nil)
542
+ return
543
+ }
544
+
545
+ if let options = options as? [String: Any] {
546
+ setCaptureBuilderParams(params: options, builder: timeShiftCaptureBuilder)
547
+ setTimeShiftCaptureBuilderParams(params: options, builder: timeShiftCaptureBuilder)
548
+ }
549
+ timeShiftCaptureBuilder.build { capture, error in
550
+ if let error {
551
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
552
+ } else if let capture {
553
+ self.timeShiftCapture = capture
554
+ self.timeShiftCaptureBuilder = nil
555
+ resolve(true)
556
+ } else {
557
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_TIMESHIFT_CAPTURE, nil)
558
+ }
559
+ }
560
+ }
561
+
562
+ @objc(startTimeShiftCapture:withRejecter:)
563
+ func startTimeShiftCapture(
564
+ resolve: @escaping RCTPromiseResolveBlock,
565
+ reject: @escaping RCTPromiseRejectBlock
566
+ ) {
567
+ guard let _ = thetaRepository else {
568
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
569
+ return
570
+ }
571
+ guard let timeShiftCapture else {
572
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_TIMESHIFT_CAPTURE, nil)
573
+ return
574
+ }
575
+
576
+ class Callback: TimeShiftCaptureStartCaptureCallback {
577
+ let callback: (_ url: String?, _ error: Error?) -> Void
578
+ weak var client: ThetaClientReactNative?
579
+ init(
580
+ _ callback: @escaping (_ url: String?, _ error: Error?) -> Void,
581
+ client: ThetaClientReactNative
582
+ ) {
583
+ self.callback = callback
584
+ self.client = client
585
+ }
586
+
587
+ func onError(exception: ThetaRepository.ThetaRepositoryException) {
588
+ callback(nil, exception.asError())
589
+ }
590
+
591
+ func onProgress(completion: Float) {
592
+ client?.sendEvent(
593
+ withName: ThetaClientReactNative.EVENT_NOTIFY,
594
+ body: toNotify(
595
+ name: ThetaClientReactNative.NOTIFY_TIMESHIFT_PROGRESS,
596
+ params: toCaptureProgressNotifyParam(value: completion)
597
+ )
598
+ )
599
+ }
600
+
601
+ func onSuccess(fileUrl: String?) {
602
+ callback(fileUrl, nil)
603
+ }
604
+ }
605
+
606
+ timeShiftCapturing = timeShiftCapture.startCapture(
607
+ callback: Callback(
608
+ { url, error in
609
+ if let error {
610
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
611
+ } else {
612
+ resolve(url)
613
+ }
614
+ }, client: self
615
+ ))
616
+ }
617
+
618
+ @objc(cancelTimeShiftCapture:withRejecter:)
619
+ func cancelTimeShiftCapture(
620
+ resolve: @escaping RCTPromiseResolveBlock,
621
+ reject: @escaping RCTPromiseRejectBlock
622
+ ) {
623
+ guard let _ = thetaRepository else {
624
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
625
+ return
626
+ }
627
+ guard let timeShiftCapturing else {
628
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_TIMESHIFT_CAPTURING, nil)
629
+ return
630
+ }
631
+ timeShiftCapturing.cancelCapture()
632
+ resolve(nil)
633
+ }
634
+
635
+ @objc(getVideoCaptureBuilder:withRejecter:)
636
+ func getVideoCaptureBuilder(
637
+ resolve: RCTPromiseResolveBlock,
638
+ reject: RCTPromiseRejectBlock
639
+ ) {
640
+ guard let thetaRepository else {
641
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
642
+ return
643
+ }
644
+ videoCaptureBuilder = thetaRepository.getVideoCaptureBuilder()
645
+ resolve(nil)
646
+ }
647
+
648
+ @objc(buildVideoCapture:withResolver:withRejecter:)
649
+ func buildVideoCapture(
650
+ options: [AnyHashable: Any]?,
651
+ resolve: @escaping RCTPromiseResolveBlock,
652
+ reject: @escaping RCTPromiseRejectBlock
653
+ ) {
654
+ guard let _ = thetaRepository else {
655
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
656
+ return
657
+ }
658
+ guard let videoCaptureBuilder else {
659
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_VIDEO_CAPTURE_BUILDER, nil)
660
+ return
661
+ }
662
+
663
+ if let options = options as? [String: Any] {
664
+ setCaptureBuilderParams(params: options, builder: videoCaptureBuilder)
665
+ setVideoCaptureBuilderParams(params: options, builder: videoCaptureBuilder)
666
+ }
667
+ videoCaptureBuilder.build { capture, error in
668
+ if let error {
669
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
670
+ } else if let capture {
671
+ self.videoCapture = capture
672
+ self.videoCaptureBuilder = nil
673
+ resolve(true)
674
+ } else {
675
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_VIDEO_CAPTURE, nil)
676
+ }
677
+ }
678
+ }
679
+
680
+ @objc(startVideoCapture:withRejecter:)
681
+ func startVideoCapture(
682
+ resolve: @escaping RCTPromiseResolveBlock,
683
+ reject: @escaping RCTPromiseRejectBlock
684
+ ) {
685
+ guard let _ = thetaRepository else {
686
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
687
+ return
688
+ }
689
+ guard let videoCapture else {
690
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_VIDEO_CAPTURE, nil)
691
+ return
692
+ }
693
+ class Callback: VideoCaptureStartCaptureCallback {
694
+ let callback: (_ url: String?, _ error: Error?) -> Void
695
+ weak var client: ThetaClientReactNative?
696
+ init(
697
+ _ callback: @escaping (_ url: String?, _ error: Error?) -> Void,
698
+ client: ThetaClientReactNative
699
+ ) {
700
+ self.callback = callback
701
+ self.client = client
702
+ }
703
+
704
+ func onCaptureCompleted(fileUrl: String?) {
705
+ callback(fileUrl, nil)
706
+ }
707
+
708
+ func onCaptureFailed(exception: ThetaRepository.ThetaRepositoryException) {
709
+ callback(nil, exception.asError())
710
+ }
711
+
712
+ func onStopFailed(exception: ThetaRepository.ThetaRepositoryException) {
713
+ let error = exception.asError()
714
+ client?.sendEvent(
715
+ withName: ThetaClientReactNative.EVENT_NOTIFY,
716
+ body: toNotify(
717
+ name: ThetaClientReactNative.NOTIFY_VIDEO_CAPTURE_STOP_ERROR,
718
+ params: toMessageNotifyParam(value: error.localizedDescription)
719
+ )
720
+ )
721
+ }
722
+ }
723
+
724
+ videoCapturing = videoCapture.startCapture(
725
+ callback: Callback(
726
+ { url, error in
727
+ if let error {
728
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
729
+ } else {
730
+ self.videoCapture = nil
731
+ resolve(url)
732
+ }
733
+ }, client: self
734
+ ))
735
+ }
736
+
737
+ @objc(stopVideoCapture:withRejecter:)
738
+ func stopVideoCapture(
739
+ resolve: RCTPromiseResolveBlock,
740
+ reject: RCTPromiseRejectBlock
741
+ ) {
742
+ guard let _ = thetaRepository else {
743
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
744
+ return
745
+ }
746
+ guard let videoCapturing else {
747
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_VIDEO_CAPTURING, nil)
748
+ return
749
+ }
750
+ videoCapturing.stopCapture()
751
+ resolve(nil)
752
+ }
753
+
754
+ @objc(getLimitlessIntervalCaptureBuilder:withRejecter:)
755
+ func getLimitlessIntervalCaptureBuilder(
756
+ resolve: RCTPromiseResolveBlock,
757
+ reject: RCTPromiseRejectBlock
758
+ ) {
759
+ guard let thetaRepository else {
760
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
761
+ return
762
+ }
763
+ print("getLimitlessIntervalCaptureBuilder")
764
+ limitlessIntervalCaptureBuilder = thetaRepository.getLimitlessIntervalCaptureBuilder()
765
+ resolve(nil)
766
+ }
767
+
768
+ @objc(buildLimitlessIntervalCapture:withResolver:withRejecter:)
769
+ func buildLimitlessIntervalCapture(
770
+ options: [AnyHashable: Any]?,
771
+ resolve: @escaping RCTPromiseResolveBlock,
772
+ reject: @escaping RCTPromiseRejectBlock
773
+ ) {
774
+ guard let _ = thetaRepository else {
775
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
776
+ return
777
+ }
778
+ guard let limitlessIntervalCaptureBuilder else {
779
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_LIMITLESS_INTERVAL_CAPTURE_BUILDER, nil)
780
+ return
781
+ }
782
+
783
+ if let options = options as? [String: Any] {
784
+ setCaptureBuilderParams(params: options, builder: limitlessIntervalCaptureBuilder)
785
+ setLimitlessIntervalCaptureBuilderParams(params: options, builder: limitlessIntervalCaptureBuilder)
786
+ }
787
+ limitlessIntervalCaptureBuilder.build { capture, error in
788
+ if let error {
789
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
790
+ } else if let capture {
791
+ self.limitlessIntervalCapture = capture
792
+ self.limitlessIntervalCaptureBuilder = nil
793
+ resolve(true)
794
+ } else {
795
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_LIMITLESS_INTERVAL_CAPTURE, nil)
796
+ }
797
+ }
798
+ }
799
+
800
+ @objc(startLimitlessIntervalCapture:withRejecter:)
801
+ func startLimitlessIntervalCapture(
802
+ resolve: @escaping RCTPromiseResolveBlock,
803
+ reject: @escaping RCTPromiseRejectBlock
804
+ ) {
805
+ guard let _ = thetaRepository else {
806
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
807
+ return
808
+ }
809
+ guard let limitlessIntervalCapture else {
810
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_LIMITLESS_INTERVAL_CAPTURE, nil)
811
+ return
812
+ }
813
+ class Callback: LimitlessIntervalCaptureStartCaptureCallback {
814
+ let callback: (_ urls: [String]?, _ error: Error?) -> Void
815
+ weak var client: ThetaClientReactNative?
816
+ init(
817
+ _ callback: @escaping (_ urls: [String]?, _ error: Error?) -> Void,
818
+ client: ThetaClientReactNative
819
+ ) {
820
+ self.callback = callback
821
+ self.client = client
822
+ }
823
+
824
+ func onCaptureCompleted(fileUrls: [String]?) {
825
+ callback(fileUrls, nil)
826
+ }
827
+
828
+ func onCaptureFailed(exception: ThetaRepository.ThetaRepositoryException) {
829
+ callback(nil, exception.asError())
830
+ }
831
+
832
+ func onStopFailed(exception: ThetaRepository.ThetaRepositoryException) {
833
+ let error = exception.asError()
834
+ client?.sendEvent(
835
+ withName: ThetaClientReactNative.EVENT_NOTIFY,
836
+ body: toNotify(
837
+ name: ThetaClientReactNative.NOTIFY_LIMITLESS_INTERVAL_CAPTURE_STOP_ERROR,
838
+ params: toMessageNotifyParam(value: error.localizedDescription)
839
+ )
840
+ )
841
+ }
842
+ }
843
+
844
+ limitlessIntervalCapturing = limitlessIntervalCapture.startCapture(
845
+ callback: Callback(
846
+ { urls, error in
847
+ if let error {
848
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
849
+ } else {
850
+ self.limitlessIntervalCapture = nil
851
+ resolve(urls)
852
+ }
853
+ }, client: self
854
+ ))
855
+ }
856
+
857
+ @objc(stopLimitlessIntervalCapture:withRejecter:)
858
+ func stopLimitlessIntervalCapture(
859
+ resolve: RCTPromiseResolveBlock,
860
+ reject: RCTPromiseRejectBlock
861
+ ) {
862
+ guard let _ = thetaRepository else {
863
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
864
+ return
865
+ }
866
+ guard let limitlessIntervalCapturing else {
867
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_LIMITLESS_INTERVAL_CAPTURING, nil)
868
+ return
869
+ }
870
+ limitlessIntervalCapturing.stopCapture()
871
+ resolve(nil)
872
+ }
873
+
874
+ @objc(getShotCountSpecifiedIntervalCaptureBuilder:withResolver:withRejecter:)
875
+ func getShotCountSpecifiedIntervalCaptureBuilder(
876
+ shotCount: Int,
877
+ resolve: RCTPromiseResolveBlock,
878
+ reject: RCTPromiseRejectBlock
879
+ ) {
880
+ guard let thetaRepository else {
881
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
882
+ return
883
+ }
884
+ shotCountSpecifiedIntervalCaptureBuilder = thetaRepository.getShotCountSpecifiedIntervalCaptureBuilder(shotCount: Int32(shotCount))
885
+ resolve(nil)
886
+ }
887
+
888
+ @objc(buildShotCountSpecifiedIntervalCapture:withResolver:withRejecter:)
889
+ func buildShotCountSpecifiedIntervalCapture(
890
+ options: [AnyHashable: Any]?,
891
+ resolve: @escaping RCTPromiseResolveBlock,
892
+ reject: @escaping RCTPromiseRejectBlock
893
+ ) {
894
+ guard let _ = thetaRepository else {
895
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
896
+ return
897
+ }
898
+ guard let shotCountSpecifiedIntervalCaptureBuilder else {
899
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_SHOT_COUNT_SPECIFIED_INTERVAL_CAPTURE_BUILDER, nil)
900
+ return
901
+ }
902
+
903
+ if let options = options as? [String: Any] {
904
+ setCaptureBuilderParams(params: options, builder: shotCountSpecifiedIntervalCaptureBuilder)
905
+ setShotCountSpecifiedIntervalCaptureBuilderParams(params: options, builder: shotCountSpecifiedIntervalCaptureBuilder)
906
+ }
907
+ shotCountSpecifiedIntervalCaptureBuilder.build { capture, error in
908
+ if let error {
909
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
910
+ } else if let capture {
911
+ self.shotCountSpecifiedIntervalCapture = capture
912
+ self.shotCountSpecifiedIntervalCaptureBuilder = nil
913
+ resolve(true)
914
+ } else {
915
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_SHOT_COUNT_SPECIFIED_INTERVAL_CAPTURE, nil)
916
+ }
917
+ }
918
+ }
919
+
920
+ @objc(startShotCountSpecifiedIntervalCapture:withRejecter:)
921
+ func startShotCountSpecifiedIntervalCapture(
922
+ resolve: @escaping RCTPromiseResolveBlock,
923
+ reject: @escaping RCTPromiseRejectBlock
924
+ ) {
925
+ guard let _ = thetaRepository else {
926
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
927
+ return
928
+ }
929
+ guard let shotCountSpecifiedIntervalCapture else {
930
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_SHOT_COUNT_SPECIFIED_INTERVAL_CAPTURE, nil)
931
+ return
932
+ }
933
+
934
+ class Callback: ShotCountSpecifiedIntervalCaptureStartCaptureCallback {
935
+ let callback: (_ urls: [String]?, _ error: Error?) -> Void
936
+ weak var client: ThetaClientReactNative?
937
+ init(
938
+ _ callback: @escaping (_ urls: [String]?, _ error: Error?) -> Void,
939
+ client: ThetaClientReactNative
940
+ ) {
941
+ self.callback = callback
942
+ self.client = client
943
+ }
944
+
945
+ func onCaptureFailed(exception: ThetaRepository.ThetaRepositoryException) {
946
+ callback(nil, exception.asError())
947
+ }
948
+
949
+ func onProgress(completion: Float) {
950
+ client?.sendEvent(
951
+ withName: ThetaClientReactNative.EVENT_NOTIFY,
952
+ body: toNotify(
953
+ name: ThetaClientReactNative.NOTIFY_SHOT_COUNT_SPECIFIED_INTERVAL_PROGRESS,
954
+ params: toCaptureProgressNotifyParam(value: completion)
955
+ )
956
+ )
957
+ }
958
+
959
+ func onCaptureCompleted(fileUrls: [String]?) {
960
+ callback(fileUrls, nil)
961
+ }
962
+
963
+ func onStopFailed(exception: ThetaRepository.ThetaRepositoryException) {
964
+ let error = exception.asError()
965
+ client?.sendEvent(
966
+ withName: ThetaClientReactNative.EVENT_NOTIFY,
967
+ body: toNotify(
968
+ name: ThetaClientReactNative.NOTIFY_SHOT_COUNT_SPECIFIED_INTERVAL_STOP_ERROR,
969
+ params: toMessageNotifyParam(value: error.localizedDescription)
970
+ )
971
+ )
972
+ }
973
+ }
974
+
975
+ shotCountSpecifiedIntervalCapturing = shotCountSpecifiedIntervalCapture.startCapture(
976
+ callback: Callback(
977
+ { url, error in
978
+ if let error {
979
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
980
+ } else {
981
+ resolve(url)
982
+ }
983
+ }, client: self
984
+ ))
985
+ }
986
+
987
+ @objc(cancelShotCountSpecifiedIntervalCapture:withRejecter:)
988
+ func cancelShotCountSpecifiedIntervalCapture(
989
+ resolve: @escaping RCTPromiseResolveBlock,
990
+ reject: @escaping RCTPromiseRejectBlock
991
+ ) {
992
+ guard let _ = thetaRepository else {
993
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
994
+ return
995
+ }
996
+ guard let shotCountSpecifiedIntervalCapturing else {
997
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_SHOT_COUNT_SPECIFIED_INTERVAL_CAPTURING, nil)
998
+ return
999
+ }
1000
+ shotCountSpecifiedIntervalCapturing.cancelCapture()
1001
+ resolve(nil)
1002
+ }
1003
+
1004
+ @objc(getMetadata:withResolver:withRejecter:)
1005
+ func getMetadata(
1006
+ fileUrl: String,
1007
+ resolve: @escaping RCTPromiseResolveBlock,
1008
+ reject: @escaping RCTPromiseRejectBlock
1009
+ ) {
1010
+ guard let thetaRepository else {
1011
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1012
+ return
1013
+ }
1014
+
1015
+ thetaRepository.getMetadata(
1016
+ fileUrl: fileUrl
1017
+ ) { response, error in
1018
+ if let error {
1019
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1020
+ } else if let response {
1021
+ resolve(convertResult(metadata: response))
1022
+ } else {
1023
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
1024
+ }
1025
+ }
1026
+ }
1027
+
1028
+ @objc(reset:withRejecter:)
1029
+ func reset(
1030
+ resolve: @escaping RCTPromiseResolveBlock,
1031
+ reject: @escaping RCTPromiseRejectBlock
1032
+ ) {
1033
+ guard let thetaRepository else {
1034
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1035
+ return
1036
+ }
1037
+
1038
+ thetaRepository.reset { error in
1039
+ if let error {
1040
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1041
+ } else {
1042
+ resolve(true)
1043
+ }
1044
+ }
1045
+ }
1046
+
1047
+ @objc(restoreSettings:withRejecter:)
1048
+ func restoreSettings(
1049
+ resolve: @escaping RCTPromiseResolveBlock,
1050
+ reject: @escaping RCTPromiseRejectBlock
1051
+ ) {
1052
+ guard let thetaRepository else {
1053
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1054
+ return
1055
+ }
1056
+
1057
+ thetaRepository.restoreSettings { error in
1058
+ if let error {
1059
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1060
+ } else {
1061
+ resolve(true)
1062
+ }
1063
+ }
1064
+ }
1065
+
1066
+ @objc(stopSelfTimer:withRejecter:)
1067
+ func stopSelfTimer(
1068
+ resolve: @escaping RCTPromiseResolveBlock,
1069
+ reject: @escaping RCTPromiseRejectBlock
1070
+ ) {
1071
+ guard let thetaRepository else {
1072
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1073
+ return
1074
+ }
1075
+
1076
+ thetaRepository.stopSelfTimer { error in
1077
+ if let error {
1078
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1079
+ } else {
1080
+ resolve(true)
1081
+ }
1082
+ }
1083
+ }
1084
+
1085
+ @objc(
1086
+ convertVideoFormats:withToLowResolution:withApplyTopBottomCorrection:withResolver:
1087
+ withRejecter:
1088
+ )
1089
+ func convertVideoFormats(
1090
+ fileUrl: String,
1091
+ toLowResolution: Bool,
1092
+ applyTopBottomCorrection: Bool,
1093
+ resolve: @escaping RCTPromiseResolveBlock,
1094
+ reject: @escaping RCTPromiseRejectBlock
1095
+ ) {
1096
+ guard let thetaRepository else {
1097
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1098
+ return
1099
+ }
1100
+
1101
+ thetaRepository.convertVideoFormats(
1102
+ fileUrl: fileUrl,
1103
+ toLowResolution: toLowResolution,
1104
+ applyTopBottomCorrection: applyTopBottomCorrection
1105
+ ) { fileUrl, error in
1106
+ if let error {
1107
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1108
+ } else if let fileUrl {
1109
+ resolve(fileUrl)
1110
+ } else {
1111
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
1112
+ }
1113
+ }
1114
+ }
1115
+
1116
+ @objc(cancelVideoConvert:withRejecter:)
1117
+ func cancelVideoConvert(
1118
+ resolve: @escaping RCTPromiseResolveBlock,
1119
+ reject: @escaping RCTPromiseRejectBlock
1120
+ ) {
1121
+ guard let thetaRepository else {
1122
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1123
+ return
1124
+ }
1125
+
1126
+ thetaRepository.cancelVideoConvert { error in
1127
+ if let error {
1128
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1129
+ } else {
1130
+ resolve(true)
1131
+ }
1132
+ }
1133
+ }
1134
+
1135
+ @objc(finishWlan:withRejecter:)
1136
+ func finishWlan(
1137
+ resolve: @escaping RCTPromiseResolveBlock,
1138
+ reject: @escaping RCTPromiseRejectBlock
1139
+ ) {
1140
+ guard let thetaRepository else {
1141
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1142
+ return
1143
+ }
1144
+
1145
+ thetaRepository.finishWlan { error in
1146
+ if let error {
1147
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1148
+ } else {
1149
+ resolve(true)
1150
+ }
1151
+ }
1152
+ }
1153
+
1154
+ @objc(listAccessPoints:withRejecter:)
1155
+ func listAccessPoints(
1156
+ resolve: @escaping RCTPromiseResolveBlock,
1157
+ reject: @escaping RCTPromiseRejectBlock
1158
+ ) {
1159
+ guard let thetaRepository else {
1160
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1161
+ return
1162
+ }
1163
+
1164
+ thetaRepository.listAccessPoints { response, error in
1165
+ if let error {
1166
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1167
+ } else if let response {
1168
+ var list = convertResult(accessPointList: response)
1169
+ resolve(list)
1170
+ } else {
1171
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
1172
+ }
1173
+ }
1174
+ }
1175
+
1176
+ @objc(
1177
+ setAccessPointDynamically:
1178
+ withSsidStealth:
1179
+ withAuthMode:
1180
+ withPassword:
1181
+ withConnectionPriority:
1182
+ withProxy:
1183
+ withResolver:
1184
+ withRejecter:
1185
+ )
1186
+ func setAccessPointDynamically(
1187
+ ssid: String,
1188
+ ssidStealth: Bool,
1189
+ authMode: String,
1190
+ password: String,
1191
+ connectionPriority: Int,
1192
+ proxy: [AnyHashable: Any]?,
1193
+ resolve: @escaping RCTPromiseResolveBlock,
1194
+ reject: @escaping RCTPromiseRejectBlock
1195
+ ) {
1196
+ guard let thetaRepository else {
1197
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1198
+ return
1199
+ }
1200
+ guard
1201
+ let authMode = getEnumValue(
1202
+ values: ThetaRepository.AuthModeEnum.values(), name: authMode
1203
+ )
1204
+ else {
1205
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
1206
+ return
1207
+ }
1208
+
1209
+ let proxyParam: ThetaRepository.Proxy? = {
1210
+ if let proxy = proxy as? [String: Any] {
1211
+ return toProxy(params: proxy)
1212
+ }
1213
+ return nil
1214
+ }()
1215
+ thetaRepository.setAccessPointDynamically(
1216
+ ssid: ssid,
1217
+ ssidStealth: ssidStealth,
1218
+ authMode: authMode,
1219
+ password: password,
1220
+ connectionPriority: Int32(connectionPriority),
1221
+ proxy: proxyParam
1222
+ ) { error in
1223
+ if let error {
1224
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1225
+ } else {
1226
+ resolve(true)
1227
+ }
1228
+ }
1229
+ }
1230
+
1231
+ @objc(
1232
+ setAccessPointStatically:
1233
+ withSsidStealth:
1234
+ withAuthMode:
1235
+ withPassword:
1236
+ withConnectionPriority:
1237
+ withIpAddress:
1238
+ withSubnetMask:
1239
+ withDefaultGateway:
1240
+ withProxy:
1241
+ withResolver:
1242
+ withRejecter:
1243
+ )
1244
+ func setAccessPointStatically(
1245
+ ssid: String,
1246
+ ssidStealth: Bool,
1247
+ authMode: String,
1248
+ password: String?,
1249
+ connectionPriority: Int,
1250
+ ipAddress: String,
1251
+ subnetMask: String,
1252
+ defaultGateway: String,
1253
+ proxy: [AnyHashable: Any]?,
1254
+ resolve: @escaping RCTPromiseResolveBlock,
1255
+ reject: @escaping RCTPromiseRejectBlock
1256
+ ) {
1257
+ guard let thetaRepository else {
1258
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1259
+ return
1260
+ }
1261
+ guard
1262
+ let authMode = getEnumValue(
1263
+ values: ThetaRepository.AuthModeEnum.values(), name: authMode
1264
+ )
1265
+ else {
1266
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
1267
+ return
1268
+ }
1269
+
1270
+ let proxyParam: ThetaRepository.Proxy? = {
1271
+ if let proxy = proxy as? [String: Any] {
1272
+ return toProxy(params: proxy)
1273
+ }
1274
+ return nil
1275
+ }()
1276
+ thetaRepository.setAccessPointStatically(
1277
+ ssid: ssid,
1278
+ ssidStealth: ssidStealth,
1279
+ authMode: authMode,
1280
+ password: password,
1281
+ connectionPriority: Int32(connectionPriority),
1282
+ ipAddress: ipAddress,
1283
+ subnetMask: subnetMask,
1284
+ defaultGateway: defaultGateway,
1285
+ proxy: proxyParam
1286
+ ) { error in
1287
+ if let error {
1288
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1289
+ } else {
1290
+ resolve(true)
1291
+ }
1292
+ }
1293
+ }
1294
+
1295
+ @objc(deleteAccessPoint:withResolver:withRejecter:)
1296
+ func deleteAccessPoint(
1297
+ ssid: String,
1298
+ resolve: @escaping RCTPromiseResolveBlock,
1299
+ reject: @escaping RCTPromiseRejectBlock
1300
+ ) {
1301
+ guard let thetaRepository else {
1302
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1303
+ return
1304
+ }
1305
+
1306
+ thetaRepository.deleteAccessPoint(
1307
+ ssid: ssid
1308
+ ) { error in
1309
+ if let error {
1310
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1311
+ } else {
1312
+ resolve(true)
1313
+ }
1314
+ }
1315
+ }
1316
+
1317
+ @objc(getMySetting:withResolver:withRejecter:)
1318
+ func getMySetting(
1319
+ captureMode: String,
1320
+ resolve: @escaping RCTPromiseResolveBlock,
1321
+ reject: @escaping RCTPromiseRejectBlock
1322
+ ) {
1323
+ guard let thetaRepository else {
1324
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1325
+ return
1326
+ }
1327
+ guard
1328
+ let captureMode = getEnumValue(
1329
+ values: ThetaRepository.CaptureModeEnum.values(), name: captureMode
1330
+ )
1331
+ else {
1332
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
1333
+ return
1334
+ }
1335
+ thetaRepository.getMySetting(
1336
+ captureMode: captureMode
1337
+ ) { response, error in
1338
+ if let error {
1339
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1340
+ } else if let response {
1341
+ resolve(convertResult(options: response))
1342
+ } else {
1343
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
1344
+ }
1345
+ }
1346
+ }
1347
+
1348
+ @objc(getMySettingFromOldModel:withResolver:withRejecter:)
1349
+ func getMySettingFromOldModel(
1350
+ optionNames: [Any],
1351
+ resolve: @escaping RCTPromiseResolveBlock,
1352
+ reject: @escaping RCTPromiseRejectBlock
1353
+ ) {
1354
+ guard let thetaRepository else {
1355
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1356
+ return
1357
+ }
1358
+ guard let optionNames = optionNames as? [String] else {
1359
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
1360
+ return
1361
+ }
1362
+
1363
+ let params = convertGetOptionsParam(params: optionNames)
1364
+ thetaRepository.getMySetting(
1365
+ optionNames: params
1366
+ ) { response, error in
1367
+ if let error {
1368
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1369
+ } else if let response {
1370
+ resolve(convertResult(options: response))
1371
+ } else {
1372
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
1373
+ }
1374
+ }
1375
+ }
1376
+
1377
+ @objc(setMySetting:withOptions:withResolver:withRejecter:)
1378
+ func setMySetting(
1379
+ captureMode: String,
1380
+ options: [AnyHashable: Any],
1381
+ resolve: @escaping RCTPromiseResolveBlock,
1382
+ reject: @escaping RCTPromiseRejectBlock
1383
+ ) {
1384
+ guard let thetaRepository else {
1385
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1386
+ return
1387
+ }
1388
+ guard let options = options as? [String: Any],
1389
+ let captureMode = getEnumValue(
1390
+ values: ThetaRepository.CaptureModeEnum.values(), name: captureMode
1391
+ )
1392
+ else {
1393
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
1394
+ return
1395
+ }
1396
+
1397
+ let params = convertSetOptionsParam(params: options)
1398
+ thetaRepository.setMySetting(
1399
+ captureMode: captureMode,
1400
+ options: params
1401
+ ) { error in
1402
+ if let error {
1403
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1404
+ } else {
1405
+ resolve(true)
1406
+ }
1407
+ }
1408
+ }
1409
+
1410
+ @objc(deleteMySetting:withResolver:withRejecter:)
1411
+ func deleteMySetting(
1412
+ captureMode: String,
1413
+ resolve: @escaping RCTPromiseResolveBlock,
1414
+ reject: @escaping RCTPromiseRejectBlock
1415
+ ) {
1416
+ guard let thetaRepository else {
1417
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1418
+ return
1419
+ }
1420
+ guard
1421
+ let captureMode = getEnumValue(
1422
+ values: ThetaRepository.CaptureModeEnum.values(), name: captureMode
1423
+ )
1424
+ else {
1425
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
1426
+ return
1427
+ }
1428
+ thetaRepository.deleteMySetting(
1429
+ captureMode: captureMode
1430
+ ) { error in
1431
+ if let error {
1432
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1433
+ } else {
1434
+ resolve(true)
1435
+ }
1436
+ }
1437
+ }
1438
+
1439
+ @objc(listPlugins:withRejecter:)
1440
+ func listPlugins(
1441
+ resolve: @escaping RCTPromiseResolveBlock,
1442
+ reject: @escaping RCTPromiseRejectBlock
1443
+ ) {
1444
+ guard let thetaRepository else {
1445
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1446
+ return
1447
+ }
1448
+ thetaRepository.listPlugins { pluginList, error in
1449
+ if let error {
1450
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1451
+ } else if let pluginList {
1452
+ resolve(toPluginInfosResult(pluginInfoList: pluginList))
1453
+ } else {
1454
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
1455
+ }
1456
+ }
1457
+ }
1458
+
1459
+ @objc(setPlugin:withResolver:withRejecter:)
1460
+ func setPlugin(
1461
+ packageName: String,
1462
+ resolve: @escaping RCTPromiseResolveBlock,
1463
+ reject: @escaping RCTPromiseRejectBlock
1464
+ ) {
1465
+ guard let thetaRepository else {
1466
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1467
+ return
1468
+ }
1469
+
1470
+ thetaRepository.setPlugin(packageName: packageName) { error in
1471
+ if let error {
1472
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1473
+ } else {
1474
+ resolve(true)
1475
+ }
1476
+ }
1477
+ }
1478
+
1479
+ @objc(startPlugin:withResolver:withRejecter:)
1480
+ func startPlugin(
1481
+ packageName: String,
1482
+ resolve: @escaping RCTPromiseResolveBlock,
1483
+ reject: @escaping RCTPromiseRejectBlock
1484
+ ) {
1485
+ guard let thetaRepository else {
1486
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1487
+ return
1488
+ }
1489
+
1490
+ thetaRepository.startPlugin(packageName: packageName) { error in
1491
+ if let error {
1492
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1493
+ } else {
1494
+ resolve(true)
1495
+ }
1496
+ }
1497
+ }
1498
+
1499
+ @objc(stopPlugin:withRejecter:)
1500
+ func stopPlugin(
1501
+ resolve: @escaping RCTPromiseResolveBlock,
1502
+ reject: @escaping RCTPromiseRejectBlock
1503
+ ) {
1504
+ guard let thetaRepository else {
1505
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1506
+ return
1507
+ }
1508
+
1509
+ thetaRepository.stopPlugin { error in
1510
+ if let error {
1511
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1512
+ } else {
1513
+ resolve(true)
1514
+ }
1515
+ }
1516
+ }
1517
+
1518
+ @objc(getPluginLicense:withResolver:withRejecter:)
1519
+ func getPluginLicense(
1520
+ packageName: String,
1521
+ resolve: @escaping RCTPromiseResolveBlock,
1522
+ reject: @escaping RCTPromiseRejectBlock
1523
+ ) {
1524
+ guard let thetaRepository else {
1525
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1526
+ return
1527
+ }
1528
+
1529
+ thetaRepository.getPluginLicense(
1530
+ packageName: packageName
1531
+ ) { response, error in
1532
+ if let error {
1533
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1534
+ } else if let response {
1535
+ resolve(response)
1536
+ } else {
1537
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
1538
+ }
1539
+ }
1540
+ }
1541
+
1542
+ @objc(getPluginOrders:withRejecter:)
1543
+ func getPluginOrders(
1544
+ resolve: @escaping RCTPromiseResolveBlock,
1545
+ reject: @escaping RCTPromiseRejectBlock
1546
+ ) {
1547
+ guard let thetaRepository else {
1548
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1549
+ return
1550
+ }
1551
+ thetaRepository.getPluginOrders { plugins, error in
1552
+ if let error {
1553
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1554
+ } else if let plugins {
1555
+ resolve(plugins)
1556
+ } else {
1557
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
1558
+ }
1559
+ }
1560
+ }
1561
+
1562
+ @objc(setPluginOrders:withResolver:withRejecter:)
1563
+ func setPluginOrders(
1564
+ plugins: [Any],
1565
+ resolve: @escaping RCTPromiseResolveBlock,
1566
+ reject: @escaping RCTPromiseRejectBlock
1567
+ ) {
1568
+ guard let thetaRepository else {
1569
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1570
+ return
1571
+ }
1572
+ guard let plugins = plugins as? [String] else {
1573
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_ARGUMENT, nil)
1574
+ return
1575
+ }
1576
+
1577
+ thetaRepository.setPluginOrders(
1578
+ plugins: plugins
1579
+ ) { error in
1580
+ if let error {
1581
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1582
+ } else {
1583
+ resolve(true)
1584
+ }
1585
+ }
1586
+ }
1587
+
1588
+ @objc(setBluetoothDevice:withResolver:withRejecter:)
1589
+ func setBluetoothDevice(
1590
+ uuid: String,
1591
+ resolve: @escaping RCTPromiseResolveBlock,
1592
+ reject: @escaping RCTPromiseRejectBlock
1593
+ ) {
1594
+ guard let thetaRepository else {
1595
+ reject(ERROR_CODE_ERROR, MESSAGE_NOT_INIT, nil)
1596
+ return
1597
+ }
1598
+ thetaRepository.setBluetoothDevice(uuid: uuid) { deviceName, error in
1599
+ if let error {
1600
+ reject(ERROR_CODE_ERROR, error.localizedDescription, error)
1601
+ } else if let deviceName {
1602
+ resolve(deviceName)
1603
+ } else {
1604
+ reject(ERROR_CODE_ERROR, MESSAGE_NO_RESULT, nil)
1605
+ }
1606
+ }
1607
+ }
1608
+ }