react-native-flic2 0.3.26 → 2.0.0-alpha.39

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 (243) hide show
  1. package/Flic2.podspec +22 -0
  2. package/{LICENSE.md → LICENSE} +1 -1
  3. package/README.md +17 -523
  4. package/android/build.gradle +64 -132
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +17 -29
  7. package/android/src/main/java/com/flic2/Flic2ButtonListener.kt +132 -0
  8. package/android/src/main/java/com/flic2/Flic2Converter.kt +103 -0
  9. package/android/src/main/java/com/flic2/Flic2Module.kt +480 -0
  10. package/android/src/main/java/com/flic2/Flic2Package.kt +33 -0
  11. package/android/src/main/java/com/flic2/Flic2Service.kt +112 -0
  12. package/ios/Flic2.h +9 -4
  13. package/ios/Flic2.mm +610 -0
  14. package/ios/flic2lib.framework/Headers/FLICButton.h +1 -1
  15. package/ios/flic2lib.framework/Headers/FLICManager.h +1 -1
  16. package/ios/flic2lib.framework/Info.plist +0 -0
  17. package/ios/flic2lib.framework/Modules/module.modulemap +1 -1
  18. package/ios/flic2lib.framework/flic2lib +0 -0
  19. package/lib/module/NativeFlic2.js +14 -0
  20. package/lib/module/NativeFlic2.js.map +1 -0
  21. package/lib/module/index.js +91 -0
  22. package/lib/module/index.js.map +1 -0
  23. package/lib/module/package.json +1 -0
  24. package/lib/typescript/package.json +1 -0
  25. package/lib/typescript/src/NativeFlic2.d.ts +119 -0
  26. package/lib/typescript/src/NativeFlic2.d.ts.map +1 -0
  27. package/lib/typescript/src/index.d.ts +81 -0
  28. package/lib/typescript/src/index.d.ts.map +1 -0
  29. package/package.json +132 -19
  30. package/src/NativeFlic2.ts +157 -0
  31. package/src/index.tsx +159 -0
  32. package/.editorconfig +0 -7
  33. package/.gitattributes +0 -1
  34. package/.idea/codeStyles/Project.xml +0 -116
  35. package/.idea/modules.xml +0 -8
  36. package/.idea/react-native-flic2.iml +0 -9
  37. package/.idea/vcs.xml +0 -6
  38. package/.idea/workspace.xml +0 -140
  39. package/android/.classpath +0 -6
  40. package/android/.gradle/5.4.1/executionHistory/executionHistory.bin +0 -0
  41. package/android/.gradle/5.4.1/executionHistory/executionHistory.lock +0 -0
  42. package/android/.gradle/5.4.1/fileChanges/last-build.bin +0 -0
  43. package/android/.gradle/5.4.1/fileContent/fileContent.lock +0 -0
  44. package/android/.gradle/5.4.1/fileHashes/fileHashes.bin +0 -0
  45. package/android/.gradle/5.4.1/fileHashes/fileHashes.lock +0 -0
  46. package/android/.gradle/5.4.1/fileHashes/resourceHashesCache.bin +0 -0
  47. package/android/.gradle/5.4.1/gc.properties +0 -0
  48. package/android/.gradle/5.4.1/javaCompile/classAnalysis.bin +0 -0
  49. package/android/.gradle/5.4.1/javaCompile/jarAnalysis.bin +0 -0
  50. package/android/.gradle/5.4.1/javaCompile/javaCompile.lock +0 -0
  51. package/android/.gradle/5.4.1/javaCompile/taskHistory.bin +0 -0
  52. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  53. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  54. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  55. package/android/.gradle/vcs-1/gc.properties +0 -0
  56. package/android/.idea/caches/build_file_checksums.ser +0 -0
  57. package/android/.idea/codeStyles/Project.xml +0 -116
  58. package/android/.idea/gradle.xml +0 -18
  59. package/android/.idea/libraries/Gradle__android_arch_core_common_1_1_1_jar.xml +0 -11
  60. package/android/.idea/libraries/Gradle__android_arch_core_runtime_1_1_1_aar.xml +0 -12
  61. package/android/.idea/libraries/Gradle__android_arch_lifecycle_common_1_1_1_jar.xml +0 -11
  62. package/android/.idea/libraries/Gradle__android_arch_lifecycle_livedata_1_1_1_aar.xml +0 -12
  63. package/android/.idea/libraries/Gradle__android_arch_lifecycle_livedata_core_1_1_1_aar.xml +0 -12
  64. package/android/.idea/libraries/Gradle__android_arch_lifecycle_runtime_1_1_1_aar.xml +0 -12
  65. package/android/.idea/libraries/Gradle__android_arch_lifecycle_viewmodel_1_1_1_aar.xml +0 -12
  66. package/android/.idea/libraries/Gradle__com_android_support_animated_vector_drawable_28_0_0_aar.xml +0 -10
  67. package/android/.idea/libraries/Gradle__com_android_support_appcompat_v7_28_0_0_aar.xml +0 -13
  68. package/android/.idea/libraries/Gradle__com_android_support_asynclayoutinflater_28_0_0_aar.xml +0 -10
  69. package/android/.idea/libraries/Gradle__com_android_support_collections_28_0_0_jar.xml +0 -9
  70. package/android/.idea/libraries/Gradle__com_android_support_coordinatorlayout_28_0_0_aar.xml +0 -13
  71. package/android/.idea/libraries/Gradle__com_android_support_cursoradapter_28_0_0_aar.xml +0 -10
  72. package/android/.idea/libraries/Gradle__com_android_support_customview_28_0_0_aar.xml +0 -10
  73. package/android/.idea/libraries/Gradle__com_android_support_documentfile_28_0_0_aar.xml +0 -10
  74. package/android/.idea/libraries/Gradle__com_android_support_drawerlayout_28_0_0_aar.xml +0 -13
  75. package/android/.idea/libraries/Gradle__com_android_support_interpolator_28_0_0_aar.xml +0 -10
  76. package/android/.idea/libraries/Gradle__com_android_support_loader_28_0_0_aar.xml +0 -10
  77. package/android/.idea/libraries/Gradle__com_android_support_localbroadcastmanager_28_0_0_aar.xml +0 -10
  78. package/android/.idea/libraries/Gradle__com_android_support_print_28_0_0_aar.xml +0 -13
  79. package/android/.idea/libraries/Gradle__com_android_support_slidingpanelayout_28_0_0_aar.xml +0 -10
  80. package/android/.idea/libraries/Gradle__com_android_support_support_annotations_28_0_0_jar.xml +0 -9
  81. package/android/.idea/libraries/Gradle__com_android_support_support_compat_28_0_0_aar.xml +0 -13
  82. package/android/.idea/libraries/Gradle__com_android_support_support_core_ui_28_0_0_aar.xml +0 -10
  83. package/android/.idea/libraries/Gradle__com_android_support_support_core_utils_28_0_0_aar.xml +0 -10
  84. package/android/.idea/libraries/Gradle__com_android_support_support_fragment_28_0_0_aar.xml +0 -13
  85. package/android/.idea/libraries/Gradle__com_android_support_support_vector_drawable_28_0_0_aar.xml +0 -10
  86. package/android/.idea/libraries/Gradle__com_android_support_swiperefreshlayout_28_0_0_aar.xml +0 -13
  87. package/android/.idea/libraries/Gradle__com_android_support_versionedparcelable_28_0_0_aar.xml +0 -10
  88. package/android/.idea/libraries/Gradle__com_android_support_viewpager_28_0_0_aar.xml +0 -10
  89. package/android/.idea/libraries/Gradle__com_facebook_fresco_drawee_1_10_0_aar.xml +0 -12
  90. package/android/.idea/libraries/Gradle__com_facebook_fresco_fbcore_1_10_0_aar.xml +0 -15
  91. package/android/.idea/libraries/Gradle__com_facebook_fresco_fresco_1_10_0_aar.xml +0 -15
  92. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_1_10_0_aar.xml +0 -15
  93. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_base_1_10_0_aar.xml +0 -15
  94. package/android/.idea/libraries/Gradle__com_facebook_fresco_imagepipeline_okhttp3_1_10_0_aar.xml +0 -12
  95. package/android/.idea/libraries/Gradle__com_facebook_infer_annotation_infer_annotation_0_11_2_jar.xml +0 -13
  96. package/android/.idea/libraries/Gradle__com_facebook_react_react_native_0_59_10_aar.xml +0 -17
  97. package/android/.idea/libraries/Gradle__com_facebook_soloader_soloader_0_6_0_aar.xml +0 -14
  98. package/android/.idea/libraries/Gradle__com_google_code_findbugs_jsr305_3_0_2_jar.xml +0 -13
  99. package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_3_12_1_jar.xml +0 -13
  100. package/android/.idea/libraries/Gradle__com_squareup_okhttp3_okhttp_urlconnection_3_12_1_jar.xml +0 -13
  101. package/android/.idea/libraries/Gradle__com_squareup_okio_okio_1_15_0_jar.xml +0 -13
  102. package/android/.idea/libraries/Gradle__io_flic_flic2lib_android_1_1_0_aar.xml +0 -14
  103. package/android/.idea/libraries/Gradle__javax_inject_javax_inject_1_jar.xml +0 -13
  104. package/android/.idea/misc.xml +0 -14
  105. package/android/.idea/modules.xml +0 -8
  106. package/android/.idea/runConfigurations.xml +0 -12
  107. package/android/.idea/vcs.xml +0 -6
  108. package/android/.idea/workspace.xml +0 -348
  109. package/android/.project +0 -34
  110. package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
  111. package/android/README.md +0 -14
  112. package/android/android.iml +0 -139
  113. package/android/build/generated/source/buildConfig/debug/nl/xguard/flic2/BuildConfig.java +0 -13
  114. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/AndroidManifest.xml +0 -46
  115. package/android/build/intermediates/aapt_friendly_merged_manifests/debug/aapt/output.json +0 -1
  116. package/android/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +0 -1
  117. package/android/build/intermediates/compile_only_not_namespaced_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
  118. package/android/build/intermediates/incremental/packageDebugResources/compile-file-map.properties +0 -15
  119. package/android/build/intermediates/incremental/packageDebugResources/merged.dir/values/values.xml +0 -4
  120. package/android/build/intermediates/incremental/packageDebugResources/merger.xml +0 -2
  121. package/android/build/intermediates/library_manifest/debug/AndroidManifest.xml +0 -46
  122. package/android/build/intermediates/merged_manifests/debug/output.json +0 -1
  123. package/android/build/intermediates/packaged_res/debug/drawable/ic_launcher_background.xml +0 -74
  124. package/android/build/intermediates/packaged_res/debug/drawable-v24/ic_launcher_foreground.xml +0 -34
  125. package/android/build/intermediates/packaged_res/debug/mipmap-anydpi-v26/ic_launcher.xml +0 -5
  126. package/android/build/intermediates/packaged_res/debug/mipmap-anydpi-v26/ic_launcher_round.xml +0 -5
  127. package/android/build/intermediates/packaged_res/debug/mipmap-hdpi-v4/ic_launcher.png +0 -0
  128. package/android/build/intermediates/packaged_res/debug/mipmap-hdpi-v4/ic_launcher_round.png +0 -0
  129. package/android/build/intermediates/packaged_res/debug/mipmap-mdpi-v4/ic_launcher.png +0 -0
  130. package/android/build/intermediates/packaged_res/debug/mipmap-mdpi-v4/ic_launcher_round.png +0 -0
  131. package/android/build/intermediates/packaged_res/debug/mipmap-xhdpi-v4/ic_launcher.png +0 -0
  132. package/android/build/intermediates/packaged_res/debug/mipmap-xhdpi-v4/ic_launcher_round.png +0 -0
  133. package/android/build/intermediates/packaged_res/debug/mipmap-xxhdpi-v4/ic_launcher.png +0 -0
  134. package/android/build/intermediates/packaged_res/debug/mipmap-xxhdpi-v4/ic_launcher_round.png +0 -0
  135. package/android/build/intermediates/packaged_res/debug/mipmap-xxxhdpi-v4/ic_launcher.png +0 -0
  136. package/android/build/intermediates/packaged_res/debug/mipmap-xxxhdpi-v4/ic_launcher_round.png +0 -0
  137. package/android/build/intermediates/packaged_res/debug/values/values.xml +0 -4
  138. package/android/build/intermediates/res/symbol-table-with-package/debug/package-aware-r.txt +0 -989
  139. package/android/build/intermediates/symbols/debug/R.txt +0 -1302
  140. package/android/build/outputs/logs/manifest-merger-debug-report.txt +0 -95
  141. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  142. package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
  143. package/android/gradlew +0 -172
  144. package/android/gradlew.bat +0 -84
  145. package/android/local.properties +0 -8
  146. package/android/src/main/ic_launcher-web.png +0 -0
  147. package/android/src/main/java/nl/xguard/flic2/Flic2.java +0 -213
  148. package/android/src/main/java/nl/xguard/flic2/Flic2Package.java +0 -28
  149. package/android/src/main/java/nl/xguard/flic2/communication/IReactEvent.java +0 -15
  150. package/android/src/main/java/nl/xguard/flic2/communication/NullReactEvent.java +0 -47
  151. package/android/src/main/java/nl/xguard/flic2/communication/ReactEvent.java +0 -230
  152. package/android/src/main/java/nl/xguard/flic2/model/IReactFlic2Manager.java +0 -27
  153. package/android/src/main/java/nl/xguard/flic2/model/NullReactFlic2Manager.java +0 -70
  154. package/android/src/main/java/nl/xguard/flic2/model/ReactAndroidHandler.java +0 -33
  155. package/android/src/main/java/nl/xguard/flic2/model/ReactFlic2ButtonListener.java +0 -106
  156. package/android/src/main/java/nl/xguard/flic2/model/ReactFlic2Manager.java +0 -168
  157. package/android/src/main/java/nl/xguard/flic2/model/ReactFlic2ScanCallback.java +0 -48
  158. package/android/src/main/java/nl/xguard/flic2/model/ReactLogger.java +0 -14
  159. package/android/src/main/java/nl/xguard/flic2/service/Flic2Service.java +0 -200
  160. package/android/src/main/java/nl/xguard/flic2/service/Flic2ServiceConnection.java +0 -41
  161. package/android/src/main/java/nl/xguard/flic2/service/IFlic2Service.java +0 -13
  162. package/android/src/main/java/nl/xguard/flic2/sharedpreferences/flic2SharedPreferences.java +0 -35
  163. package/android/src/main/java/nl/xguard/flic2/util/ActivityUtil.java +0 -29
  164. package/android/src/main/java/nl/xguard/flic2/util/Consumer.java +0 -12
  165. package/android/src/main/res/drawable/ic_launcher_background.xml +0 -74
  166. package/android/src/main/res/drawable-v24/ic_launcher_foreground.xml +0 -34
  167. package/android/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +0 -5
  168. package/android/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +0 -5
  169. package/android/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
  170. package/android/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
  171. package/android/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
  172. package/android/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
  173. package/android/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
  174. package/android/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
  175. package/android/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
  176. package/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
  177. package/android/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
  178. package/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
  179. package/android/src/main/res/values/ids.xml +0 -5
  180. package/build/generated/source/buildConfig/debug/com/flic2/BuildConfig.java +0 -13
  181. package/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/AndroidManifest.xml +0 -46
  182. package/build/intermediates/aapt_friendly_merged_manifests/debug/processDebugManifest/aapt/output.json +0 -1
  183. package/build/intermediates/annotation_processor_list/debug/annotationProcessors.json +0 -1
  184. package/build/intermediates/annotations_typedef_file/debug/extractDebugAnnotations/typedefs.txt +0 -0
  185. package/build/intermediates/compile_only_not_namespaced_r_class_jar/debug/generateDebugRFile/R.jar +0 -0
  186. package/build/intermediates/incremental/debug-mergeJavaRes/merge-state +0 -0
  187. package/build/intermediates/incremental/debug-mergeJniLibs/merge-state +0 -0
  188. package/build/intermediates/incremental/mergeDebugJniLibFolders/merger.xml +0 -2
  189. package/build/intermediates/incremental/mergeDebugShaders/merger.xml +0 -2
  190. package/build/intermediates/incremental/packageDebugAssets/merger.xml +0 -2
  191. package/build/intermediates/incremental/packageDebugResources/compile-file-map.properties +0 -15
  192. package/build/intermediates/incremental/packageDebugResources/merger.xml +0 -2
  193. package/build/intermediates/intermediate-jars/debug/classes.jar +0 -0
  194. package/build/intermediates/intermediate-jars/debug/res.jar +0 -0
  195. package/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/flic2/BuildConfig.class +0 -0
  196. package/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/flic2/Flic2Module$1.class +0 -0
  197. package/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/flic2/Flic2Module.class +0 -0
  198. package/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/flic2/Flic2Package.class +0 -0
  199. package/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/flic2/callback/flic2ButtonCallback.class +0 -0
  200. package/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/flic2/communication/ReactEvent.class +0 -0
  201. package/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/flic2/service/Flic2Service$BootUpReceiver.class +0 -0
  202. package/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/flic2/service/Flic2Service$UpdateReceiver.class +0 -0
  203. package/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/flic2/service/Flic2Service.class +0 -0
  204. package/build/intermediates/library_manifest/debug/AndroidManifest.xml +0 -46
  205. package/build/intermediates/merged_manifests/debug/output.json +0 -1
  206. package/build/intermediates/packaged-classes/debug/classes.jar +0 -0
  207. package/build/intermediates/packaged_res/debug/drawable/ic_launcher_background.xml +0 -74
  208. package/build/intermediates/packaged_res/debug/drawable-v24/ic_launcher_foreground.xml +0 -34
  209. package/build/intermediates/packaged_res/debug/mipmap-anydpi-v26/ic_launcher.xml +0 -5
  210. package/build/intermediates/packaged_res/debug/mipmap-anydpi-v26/ic_launcher_round.xml +0 -5
  211. package/build/intermediates/packaged_res/debug/mipmap-hdpi-v4/ic_launcher.png +0 -0
  212. package/build/intermediates/packaged_res/debug/mipmap-hdpi-v4/ic_launcher_round.png +0 -0
  213. package/build/intermediates/packaged_res/debug/mipmap-mdpi-v4/ic_launcher.png +0 -0
  214. package/build/intermediates/packaged_res/debug/mipmap-mdpi-v4/ic_launcher_round.png +0 -0
  215. package/build/intermediates/packaged_res/debug/mipmap-xhdpi-v4/ic_launcher.png +0 -0
  216. package/build/intermediates/packaged_res/debug/mipmap-xhdpi-v4/ic_launcher_round.png +0 -0
  217. package/build/intermediates/packaged_res/debug/mipmap-xxhdpi-v4/ic_launcher.png +0 -0
  218. package/build/intermediates/packaged_res/debug/mipmap-xxhdpi-v4/ic_launcher_round.png +0 -0
  219. package/build/intermediates/packaged_res/debug/mipmap-xxxhdpi-v4/ic_launcher.png +0 -0
  220. package/build/intermediates/packaged_res/debug/mipmap-xxxhdpi-v4/ic_launcher_round.png +0 -0
  221. package/build/intermediates/res/symbol-table-with-package/debug/package-aware-r.txt +0 -1290
  222. package/build/intermediates/symbols/debug/R.txt +0 -1764
  223. package/build/intermediates/transforms/mergeJavaRes/debug/0.jar +0 -0
  224. package/build/intermediates/transforms/mergeJavaRes/debug/__content__.json +0 -1
  225. package/build/intermediates/transforms/mergeJniLibs/debug/__content__.json +0 -1
  226. package/build/intermediates/transforms/stripDebugSymbol/debug/__content__.json +0 -1
  227. package/build/outputs/aar/react-native-flic2-debug.aar +0 -0
  228. package/build/outputs/logs/manifest-merger-debug-report.txt +0 -95
  229. package/flic2Button.js +0 -170
  230. package/index.js +0 -430
  231. package/ios/Flic2.m +0 -611
  232. package/ios/Flic2.xcodeproj/project.pbxproj +0 -320
  233. package/ios/Flic2.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
  234. package/ios/Flic2.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  235. package/ios/Flic2.xcodeproj/project.xcworkspace/xcuserdata/wesdewitte.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  236. package/ios/Flic2.xcodeproj/xcshareddata/xcschemes/Flic2.xcscheme +0 -66
  237. package/ios/Flic2.xcodeproj/xcuserdata/wesdewitte.xcuserdatad/xcschemes/xcschememanagement.plist +0 -22
  238. package/ios/Flic2.xcworkspace/contents.xcworkspacedata +0 -7
  239. package/ios/Flic2.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  240. package/ios/Flic2.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +0 -5
  241. package/ios/Flic2.xcworkspace/xcuserdata/wesdewitte.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  242. package/ios/Flic2.xcworkspace/xcuserdata/wesdewitte.xcuserdatad/WorkspaceSettings.xcsettings +0 -14
  243. package/react-native-flic2.podspec +0 -26
package/index.js DELETED
@@ -1,430 +0,0 @@
1
- // get the native module
2
- import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
3
-
4
- // event emitter
5
- import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';
6
-
7
- // local imports
8
- import Flic2Button from './flic2Button.js';
9
-
10
- // we only care about flic 2 here
11
- const Flic2Module = NativeModules.Flic2;
12
-
13
- // constants
14
- const SCAN_RESULT_SUCCESS = 0;
15
- const SCAN_RESULT_ERROR_ALREADY_RUNNING = 1;
16
- const SCAN_RESULT_ERROR_BLUETOOTH_NOT_ACTIVATED = 2;
17
- const SCAN_RESULT_ERROR_UNKNOWN = 3;
18
- const SCAN_RESULT_ERROR_NO_PUBLIC_BUTTON_DISCOVERED = 4;
19
- const SCAN_RESULT_ERROR_ALREADY_CONNECTED_TO_ANOTHER_DEVICE = 5;
20
- const SCAN_RESULT_ERROR_CONNECTION_TIMEOUT = 6;
21
- const SCAN_RESULT_ERROR_INVALID_VERIFIER = 7;
22
- const SCAN_RESULT_ERROR_BLE_PAIRING_FAILED_PREVIOUS_PAIRING_ALREADY_EXISTING = 8;
23
- const SCAN_RESULT_ERROR_BLE_PAIRING_FAILED_USER_CANCELED = 9;
24
- const SCAN_RESULT_ERROR_BLE_PAIRING_FAILED_UNKNOWN_REASON = 10;
25
- const SCAN_RESULT_ERROR_APP_CREDENTIALS_DONT_MATCH = 11;
26
- const SCAN_RESULT_ERROR_USER_CANCELED = 12;
27
- const SCAN_RESULT_ERROR_INVALID_BLUETOOTH_ADDRESS = 13;
28
- const SCAN_RESULT_ERROR_GENUINE_CHECK_FAILED = 14;
29
- const SCAN_RESULT_ERROR_TOO_MANY_APPS = 15;
30
- const SCAN_RESULT_ERROR_COULD_NOT_SET_BLUETOOTH_NOTIFY = 16;
31
- const SCAN_RESULT_ERROR_COULD_NOT_DISCOVER_BLUETOOTH_SERVICES = 17;
32
- const SCAN_RESULT_ERROR_BUTTON_DISCONNECTED_DURING_VERIFICATION = 18;
33
- const SCAN_RESULT_ERROR_FAILED_TO_ESTABLISH = 19;
34
- const SCAN_RESULT_ERROR_CONNECTION_LIMIT_REACHED = 20;
35
- const SCAN_RESULT_ERROR_NOT_IN_PUBLIC_MODE = 21;
36
-
37
- const BUTTON_TRIGGER_MODE_CLICK_AND_HOLD = 0;
38
- const BUTTON_TRIGGER_MODE_CLICK_AND_DOUBLE_CLICK = 1;
39
- const BUTTON_TRIGGER_MODE_CLICK_AND_DOUBLE_CLICK_AND_HOLD = 2;
40
- const BUTTON_TRIGGER_MODE_CLICK = 3;
41
-
42
- /**
43
- * React Native Flic 2
44
- * Exposes the Flic2Module functions to the React Native context.
45
- *
46
- * @version 1.0.0
47
- */
48
- class Flic2 extends EventEmitter {
49
-
50
- /**
51
- * Constructor.
52
- *
53
- * @class
54
- * @version 1.0.0
55
- */
56
- constructor() {
57
-
58
- // extended class initialisation
59
- super();
60
-
61
- this.isFlic2ManagerInitialized = false;
62
-
63
- // define constants
64
- this.constants = {
65
- SCAN_RESULT_SUCCESS: SCAN_RESULT_SUCCESS,
66
- SCAN_RESULT_ERROR_ALREADY_RUNNING: SCAN_RESULT_ERROR_ALREADY_RUNNING,
67
- SCAN_RESULT_ERROR_BLUETOOTH_NOT_ACTIVATED: SCAN_RESULT_ERROR_BLUETOOTH_NOT_ACTIVATED,
68
- SCAN_RESULT_ERROR_UNKNOWN: SCAN_RESULT_ERROR_UNKNOWN,
69
- SCAN_RESULT_ERROR_NO_PUBLIC_BUTTON_DISCOVERED: SCAN_RESULT_ERROR_NO_PUBLIC_BUTTON_DISCOVERED,
70
- SCAN_RESULT_ERROR_ALREADY_CONNECTED_TO_ANOTHER_DEVICE: SCAN_RESULT_ERROR_ALREADY_CONNECTED_TO_ANOTHER_DEVICE,
71
- SCAN_RESULT_ERROR_CONNECTION_TIMEOUT: SCAN_RESULT_ERROR_CONNECTION_TIMEOUT,
72
- SCAN_RESULT_ERROR_INVALID_VERIFIER: SCAN_RESULT_ERROR_INVALID_VERIFIER,
73
- SCAN_RESULT_ERROR_BLE_PAIRING_FAILED_PREVIOUS_PAIRING_ALREADY_EXISTING: SCAN_RESULT_ERROR_BLE_PAIRING_FAILED_PREVIOUS_PAIRING_ALREADY_EXISTING,
74
- SCAN_RESULT_ERROR_BLE_PAIRING_FAILED_USER_CANCELED: SCAN_RESULT_ERROR_BLE_PAIRING_FAILED_USER_CANCELED,
75
- SCAN_RESULT_ERROR_BLE_PAIRING_FAILED_UNKNOWN_REASON: SCAN_RESULT_ERROR_BLE_PAIRING_FAILED_UNKNOWN_REASON,
76
- SCAN_RESULT_ERROR_APP_CREDENTIALS_DONT_MATCH: SCAN_RESULT_ERROR_APP_CREDENTIALS_DONT_MATCH,
77
- SCAN_RESULT_ERROR_USER_CANCELED: SCAN_RESULT_ERROR_USER_CANCELED,
78
- SCAN_RESULT_ERROR_INVALID_BLUETOOTH_ADDRESS: SCAN_RESULT_ERROR_INVALID_BLUETOOTH_ADDRESS,
79
- SCAN_RESULT_ERROR_GENUINE_CHECK_FAILED: SCAN_RESULT_ERROR_GENUINE_CHECK_FAILED,
80
- SCAN_RESULT_ERROR_TOO_MANY_APPS: SCAN_RESULT_ERROR_TOO_MANY_APPS,
81
- SCAN_RESULT_ERROR_COULD_NOT_SET_BLUETOOTH_NOTIFY: SCAN_RESULT_ERROR_COULD_NOT_SET_BLUETOOTH_NOTIFY,
82
- SCAN_RESULT_ERROR_COULD_NOT_DISCOVER_BLUETOOTH_SERVICES: SCAN_RESULT_ERROR_COULD_NOT_DISCOVER_BLUETOOTH_SERVICES,
83
- SCAN_RESULT_ERROR_BUTTON_DISCONNECTED_DURING_VERIFICATION: SCAN_RESULT_ERROR_BUTTON_DISCONNECTED_DURING_VERIFICATION,
84
- SCAN_RESULT_ERROR_FAILED_TO_ESTABLISH: SCAN_RESULT_ERROR_FAILED_TO_ESTABLISH,
85
- SCAN_RESULT_ERROR_CONNECTION_LIMIT_REACHED: SCAN_RESULT_ERROR_CONNECTION_LIMIT_REACHED,
86
- SCAN_RESULT_ERROR_NOT_IN_PUBLIC_MODE: SCAN_RESULT_ERROR_NOT_IN_PUBLIC_MODE,
87
- BUTTON_TRIGGER_MODE_CLICK_AND_HOLD: BUTTON_TRIGGER_MODE_CLICK_AND_HOLD,
88
- BUTTON_TRIGGER_MODE_CLICK_AND_DOUBLE_CLICK: BUTTON_TRIGGER_MODE_CLICK_AND_DOUBLE_CLICK,
89
- BUTTON_TRIGGER_MODE_CLICK_AND_DOUBLE_CLICK_AND_HOLD: BUTTON_TRIGGER_MODE_CLICK_AND_DOUBLE_CLICK_AND_HOLD,
90
- BUTTON_TRIGGER_MODE_CLICK: BUTTON_TRIGGER_MODE_CLICK,
91
- };
92
-
93
- // proxy
94
- this.onScanResultFunction = this.onScanResult.bind(this);
95
- this.didReceiveButtonEventFunction = this.didReceiveButtonEvent.bind(this);
96
- this.onInitializedFunction = this.onInitialized.bind(this);
97
-
98
- // listen to events
99
- this.nativeEvents = new NativeEventEmitter(Flic2Module);
100
-
101
- // button click events
102
- this.nativeEvents.addListener('didReceiveButtonEvent', this.didReceiveButtonEventFunction);
103
-
104
-
105
- this.registerInitializedCallback();
106
-
107
-
108
- // known buttons
109
- this.knownButtons = {};
110
- }
111
-
112
- /**
113
- * Start up the flic module
114
- */
115
- start() {
116
- // start the native context
117
- Flic2Module.startup();
118
- }
119
-
120
- registerInitializedCallback(){
121
- if(Platform.OS === 'android') {
122
- Flic2Module.registerFlic2ManagerInitializedCallback( (result) => {
123
- if(result) {
124
- this.onInitialized();
125
- }
126
- })
127
- } else {
128
- this.nativeEvents.addListener('managerInitialized', this.onInitializedFunction);
129
- }
130
- }
131
-
132
- onInitialized() {
133
- this.isFlic2ManagerInitialized = true;
134
- this.emit('managerInitialized');
135
- }
136
-
137
- isInitialized() {
138
- return this.isFlic2ManagerInitialized;
139
- }
140
-
141
-
142
- /**
143
- * Get a Flic2Button object by UUID.
144
- *
145
- * @version 1.0.0
146
- * @returns {Promise} Promise represents the Flic2Button object.
147
- */
148
- getButton(uuid) {
149
- return new Promise(async (resolve, reject) => {
150
-
151
- // first get all the buttons
152
- const buttons = await this.getButtons();
153
-
154
- // since the list of Flic buttons will never be huge
155
- // we do not bother with not using a loop here to find the button
156
- for (const button of buttons) {
157
-
158
- // check
159
- if (button.getUuid() === uuid) {
160
-
161
- return resolve(button);
162
-
163
- }
164
-
165
- }
166
-
167
- });
168
- }
169
-
170
- /**
171
- * Get an array of Flic2 Buttons.
172
- *
173
- * @version 1.0.0
174
- * @returns {Promise} Promise represents an array of Flic2Button objects.
175
- */
176
- getButtons() {
177
-
178
- return new Promise((resolve, reject) => {
179
-
180
- // proxy
181
- Flic2Module.getButtons((buttons) => {
182
-
183
- // mutate
184
- const exportButtons = [];
185
- for (const button of buttons){
186
-
187
- // button uuid
188
- const buttonUuid = button.uuid;
189
-
190
- // check if we have the button object in memory
191
- if (typeof this.knownButtons[buttonUuid] !== 'undefined'){
192
-
193
- // update
194
- const knownButton = this.knownButtons[buttonUuid];
195
-
196
- knownButton.setData(button);
197
-
198
- if (button.batteryLevelIsOk === false) {
199
- // emit
200
- this.emit('criticalBattery');
201
- }
202
-
203
- // add
204
- exportButtons.push(knownButton);
205
-
206
- } else {
207
-
208
- // create it
209
- this.knownButtons[buttonUuid] = new Flic2Button(button);
210
-
211
- if (button.batteryLevelIsOk === false) {
212
- // emit
213
- this.emit('criticalBattery');
214
- }
215
-
216
- // add
217
- exportButtons.push(this.knownButtons[buttonUuid]);
218
-
219
- }
220
-
221
-
222
- }
223
-
224
- // export all known buttons
225
- return resolve(exportButtons);
226
-
227
- }, reject);
228
-
229
- });
230
- }
231
-
232
- /**
233
- * Starts a scan to find a button.
234
- *
235
- * @version 1.0.0
236
- * @returns {boolean} Returns boolean true when finished.
237
- */
238
- startScan() {
239
-
240
- // listen for scanResult
241
- this.nativeEvents.addListener('scanResult', this.onScanResultFunction);
242
-
243
- // start the scan
244
- Flic2Module.startScan();
245
-
246
- // done
247
- return true;
248
-
249
- }
250
-
251
- /**
252
- * Stops the scan and removes the scanResult listener.
253
- *
254
- * @version 1.0.0
255
- * @returns {boolean} Returns boolean true when finished.
256
- */
257
- stopScan() {
258
-
259
- // listen for scanResult
260
- this.nativeEvents.removeListener('scanResult', this.onScanResultFunction);
261
-
262
- // start the scan
263
- Flic2Module.stopScan();
264
-
265
- // done
266
- return true;
267
-
268
- }
269
-
270
- /**
271
- * Event: scan result.
272
- * Emits a scanResult event to the react native application with a Flic2Button object attached.
273
- *
274
- * @version 1.0.0
275
- */
276
- onScanResult({ event, error, result, button }){
277
-
278
- // check if error
279
- let ButtonObject;
280
- if (event === 'completion') {
281
- // remove listener
282
- this.nativeEvents.removeListener('scanResult', this.onScanResultFunction);
283
-
284
- if (!!error === false) {
285
-
286
- // create button object
287
- ButtonObject = new Flic2Button(button);
288
-
289
- // save to known buttons
290
- this.knownButtons[ButtonObject.getUuid()] = ButtonObject;
291
-
292
- }
293
- }
294
-
295
- // check if error
296
- this.emit('scanResult', {
297
- event: event,
298
- error: !!error,
299
- result: result,
300
- button: ButtonObject,
301
- });
302
-
303
- }
304
-
305
- /**
306
- * Event: did receive button event.
307
- * Emits the event we received from the button.
308
- *
309
- * @version 1.0.0
310
- */
311
- didReceiveButtonEvent(eventData){
312
-
313
- // button uuid
314
- const buttonUuid = eventData.button.uuid;
315
-
316
- // check if we have the button object in memory
317
- if (typeof this.knownButtons[buttonUuid] !== 'undefined'){
318
-
319
- // update
320
- const knownButton = this.knownButtons[buttonUuid];
321
- knownButton.setData(eventData.button);
322
-
323
- // proxy to button for individual listen events
324
- knownButton.didReceiveButtonEvent(eventData);
325
-
326
- } else {
327
-
328
- // create it
329
- this.knownButtons[buttonUuid] = new Flic2Button(eventData.button);
330
-
331
- // we do not call didReceiveButtonEvent because there could
332
- // not be any listeners at this point
333
-
334
- }
335
-
336
- // emit to application
337
- this.emit(eventData.event, {
338
- event: eventData.event,
339
- queued: eventData.queued,
340
- age: eventData.age,
341
- error: eventData.error,
342
- button: this.knownButtons[buttonUuid],
343
- });
344
-
345
- }
346
-
347
-
348
-
349
- connectAllKnownButtons() {
350
-
351
- // pass to native module
352
- Flic2Module.connectAllKnownButtons();
353
-
354
- }
355
-
356
- buttonConnect(uuid){
357
- return new Promise(resolve => {
358
-
359
- // pass to native module
360
- Flic2Module.connectButton(uuid, resolve);
361
-
362
- });
363
- }
364
-
365
- buttonForget(uuid) {
366
- return new Promise(resolve => {
367
-
368
- // remove from known list
369
- delete this.knownButtons[uuid];
370
-
371
- // pass to native module
372
- Flic2Module.forgetButton(uuid, resolve);
373
-
374
- });
375
- }
376
-
377
- buttonDisconnect(uuid) {
378
- return new Promise(resolve => {
379
-
380
- // pass to native module
381
- Flic2Module.disconnectButton(uuid, resolve);
382
-
383
- });
384
- }
385
-
386
- disconnectAllKnownButtons() {
387
-
388
- // pass to native module
389
- Flic2Module.disconnectAllKnownButtons();
390
-
391
- }
392
-
393
- forgetAllButtons() {
394
-
395
- // pass to native module
396
- Flic2Module.forgetAllButtons();
397
- }
398
-
399
- buttonSetName(uuid, name) {
400
- return new Promise(resolve => {
401
-
402
- // pass to native module
403
- Flic2Module.setName(uuid, name, resolve);
404
-
405
- });
406
- }
407
-
408
- buttonSetMode(uuid, mode) {
409
- return new Promise(resolve => {
410
-
411
- // ios only
412
- if (Platform.OS === 'ios') {
413
-
414
- // pass to native module
415
- Flic2Module.setMode(uuid, mode, resolve);
416
-
417
- } else {
418
-
419
- resolve();
420
-
421
- }
422
-
423
-
424
- });
425
- }
426
-
427
- }
428
-
429
- // export as singleton
430
- export default new Flic2();